1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Cleaning up warnings (some of which were actually fatal)

This commit is contained in:
Asbelos 2020-06-29 11:37:05 +01:00
parent 68f47dae17
commit 6a923c4302
10 changed files with 57 additions and 34 deletions

View File

@ -14,7 +14,8 @@
// //
// The filter must be enabled by calling the DCC EXParser::setFilter method, see use in setup(). // The filter must be enabled by calling the DCC EXParser::setFilter method, see use in setup().
void myFilter(Stream & stream, byte & opcode, byte & paramCount, int p[]) { void myFilter(Print & stream, byte & opcode, byte & paramCount, int p[]) {
(void)stream; // avoid compiler warning if we don't access this parameter
switch (opcode) { switch (opcode) {
case 'F': // Invent new command to call the new Loco Function API <F cab func 1|0> case 'F': // Invent new command to call the new Loco Function API <F cab func 1|0>
DIAG(F("Setting loco %d F%d %S"),p[0],p[1],p[2]?F("ON"):F("OFF")); DIAG(F("Setting loco %d F%d %S"),p[0],p[1],p[2]?F("ON"):F("OFF"));

View File

@ -54,18 +54,18 @@ void DCCEXParser::loop(Stream & stream) {
} }
} }
int DCCEXParser::splitValues( int result[MAX_PARAMS], char * cmd) { int DCCEXParser::splitValues( int result[MAX_PARAMS], const byte * cmd) {
byte state=1; byte state=1;
byte parameterCount=0; byte parameterCount=0;
int runningValue=0; int runningValue=0;
const char * remainingCmd=cmd+1; // skips the opcode const byte * remainingCmd=cmd+1; // skips the opcode
bool signNegative=false; bool signNegative=false;
// clear all parameters in case not enough found // clear all parameters in case not enough found
for (int i=0;i<MAX_PARAMS;i++) result[i]=0; for (int i=0;i<MAX_PARAMS;i++) result[i]=0;
while(parameterCount<MAX_PARAMS) { while(parameterCount<MAX_PARAMS) {
char hot=*remainingCmd; byte hot=*remainingCmd;
switch (state) { switch (state) {
@ -109,7 +109,7 @@ void DCCEXParser::setFilter(FILTER_CALLBACK filter) {
} }
// See documentation on DCC class for info on this section // See documentation on DCC class for info on this section
void DCCEXParser::parse(Print & stream, const char *com) { void DCCEXParser::parse(Print & stream, const byte *com) {
DIAG(F("\nPARSING:%s\n"),com); DIAG(F("\nPARSING:%s\n"),com);
(void) EEPROM; // tell compiler not to warn thi is unused (void) EEPROM; // tell compiler not to warn thi is unused
int p[MAX_PARAMS]; int p[MAX_PARAMS];
@ -133,7 +133,7 @@ void DCCEXParser::parse(Print & stream, const char *com) {
break; break;
case 'a': // ACCESSORY <a ADDRESS SUBADDRESS ACTIVATE> case 'a': // ACCESSORY <a ADDRESS SUBADDRESS ACTIVATE>
if(p[2] != p[2] & 1) return; if(p[2] != (p[2] & 1)) return;
DCC::setAccessory(p[0],p[1],p[2]==1); DCC::setAccessory(p[0],p[1],p[2]==1);
return; return;
@ -286,14 +286,14 @@ bool DCCEXParser::parsef(Print & stream, int params, int p[]) {
if (p[1]==222) funcmap(p[0],p[2],13,20); if (p[1]==222) funcmap(p[0],p[2],13,20);
else if (p[1]==223) funcmap(p[0],p[2],21,28); else if (p[1]==223) funcmap(p[0],p[2],21,28);
} }
// NO RESPONSE (void)stream;// NO RESPONSE
return true; return true;
} }
void DCCEXParser::funcmap(int cab, byte value, byte fstart, byte fstop) { void DCCEXParser::funcmap(int cab, byte value, byte fstart, byte fstop) {
for (int i=fstart;i<=fstop;i++) { for (int i=fstart;i<=fstop;i++) {
DCC::setFn(cab, i, value & 1); DCC::setFn(cab, i, value & 1);
value>>1; value>>=1;
} }
} }

View File

@ -8,7 +8,7 @@ struct DCCEXParser
{ {
DCCEXParser(); DCCEXParser();
void loop(Stream & pstream); void loop(Stream & pstream);
void parse(Print & stream, const char * command); void parse(Print & stream, const byte * command);
void flush(); void flush();
static void setFilter(FILTER_CALLBACK filter); static void setFilter(FILTER_CALLBACK filter);
static const int MAX_PARAMS=10; // Must not exceed this static const int MAX_PARAMS=10; // Must not exceed this
@ -18,8 +18,8 @@ struct DCCEXParser
static const int MAX_BUFFER=50; // longest command sent in static const int MAX_BUFFER=50; // longest command sent in
byte bufferLength=0; byte bufferLength=0;
bool inCommandPayload=false; bool inCommandPayload=false;
char buffer[MAX_BUFFER+2]; byte buffer[MAX_BUFFER+2];
int splitValues( int result[MAX_PARAMS],char * command); int splitValues( int result[MAX_PARAMS], const byte * command);
bool parseT(Print & stream, int params, int p[]); bool parseT(Print & stream, int params, int p[]);
bool parseZ(Print & stream, int params, int p[]); bool parseZ(Print & stream, int params, int p[]);

View File

@ -1,8 +1,9 @@
#include "HTTPParser.h" #include "HTTPParser.h"
#include "StringFormatter.h" #include "StringFormatter.h"
void HTTPParser::parse(Print & stream, char * cmd) { void HTTPParser::parse(Print & stream, byte * cmd) {
(void)cmd; // Avoid compiler warning because this example doesnt use this parameter
// BEWARE - As soon as you start responding, the cmd buffer is trashed! // BEWARE - As soon as you start responding, the cmd buffer is trashed!
// You must get everything you need from it before using StringFormatter::send! // You must get everything you need from it before using StringFormatter::send!

View File

@ -3,6 +3,6 @@
#include <Arduino.h> #include <Arduino.h>
class HTTPParser { class HTTPParser {
public: public:
static void parse(Print & stream, char * cmd); static void parse(Print & stream, byte * cmd);
}; };
#endif #endif

View File

@ -46,7 +46,7 @@ public:
operator const uint8_t *() const { return _buffer; } operator const uint8_t *() const { return _buffer; }
operator const char *() const { return (const char*)_buffer; } operator const char *() const { return (const char*)_buffer; }
const uint16_t current_length() const { return _pos_write; } uint16_t current_length() const { return _pos_write; }
bool listen() { return true; } bool listen() { return true; }
void end() {} void end() {}

View File

@ -47,7 +47,7 @@ WiThrottle::WiThrottle(Print & stream, int wificlientid) {
firstThrottle= this; firstThrottle= this;
clientid=wificlientid; clientid=wificlientid;
for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0'; for (int loco=0;loco<MAX_MY_LOCO; loco++) myLocos[loco].throttle='\0';
StringFormatter::send(stream,F("VN2.0\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\PTL"), DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON); StringFormatter::send(stream,F("VN2.0\nRL0\nPPA%x\nPTT]\\[Turnouts}|{Turnout]\\[Closed}|{2]\\[Thrown}|{4\\PTL"), DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON);
for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){ for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){
StringFormatter::send(stream,F("]\\[LT&d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE)); StringFormatter::send(stream,F("]\\[LT&d}|{%d}|{%d"), tt->data.id, tt->data.id, (bool)(tt->data.tStatus & STATUS_ACTIVE));
@ -68,7 +68,7 @@ WiThrottle::~WiThrottle() {
} }
} }
void WiThrottle::parse(Print & stream, char * cmd) { void WiThrottle::parse(Print & stream, byte * cmd) {
heartBeat=millis(); heartBeat=millis();
DIAG(F("\nWiThrottle parse (%d) %s"),clientid, cmd); DIAG(F("\nWiThrottle parse (%d) %s"),clientid, cmd);
@ -82,7 +82,7 @@ void WiThrottle::parse(Print & stream, char * cmd) {
DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF); DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
StringFormatter::send(stream, F("PPA%c"),cmd[3]); StringFormatter::send(stream, F("PPA%c"),cmd[3]);
} }
else if (cmd[1]='T' && cmd[2]=='A') { // PTA accessory toggle else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle
// TODO... if we are given an address that is not a known Turnout... // TODO... if we are given an address that is not a known Turnout...
// should we create one or just send the DCC message. // should we create one or just send the DCC message.
Turnout::activate(getInt(cmd+4),cmd[3]=='T'); Turnout::activate(getInt(cmd+4),cmd[3]=='T');
@ -96,7 +96,7 @@ void WiThrottle::parse(Print & stream, char * cmd) {
break; break;
} }
} }
int WiThrottle::getInt(char * cmd) { int WiThrottle::getInt(byte * cmd) {
int i=0; int i=0;
while (cmd[0]>='0' && cmd[0]<='9') { while (cmd[0]>='0' && cmd[0]<='9') {
i=i*10 + (cmd[0]-'0'); i=i*10 + (cmd[0]-'0');
@ -105,15 +105,15 @@ int WiThrottle::getInt(char * cmd) {
return i; return i;
} }
int WiThrottle::getLocoId(char * cmd) { int WiThrottle::getLocoId(byte * cmd) {
if (cmd[0]=='*') return -1; // match all locos if (cmd[0]=='*') return -1; // match all locos
if (cmd[0]!='L' && cmd[0]!='S') return 0; // should not match any locos if (cmd[0]!='L' && cmd[0]!='S') return 0; // should not match any locos
return getInt(cmd+1); return getInt(cmd+1);
} }
void WiThrottle::multithrottle(Print & stream, char* cmd){ void WiThrottle::multithrottle(Print & stream, byte * cmd){
char throttleChar=cmd[1]; char throttleChar=cmd[1];
int locoid=getLocoId(cmd+3); // -1 for * int locoid=getLocoId(cmd+3); // -1 for *
char * aval=cmd; byte * aval=cmd;
while(*aval !=';' && *aval !='\0') aval++; while(*aval !=';' && *aval !='\0') aval++;
if (*aval) aval++; if (*aval) aval++;
@ -164,7 +164,7 @@ void locoAdd(String th, String actionKey, int i) {
} }
*********/ *********/
void WiThrottle::locoAction(Print & stream, char* aval, char throttleChar, int cab){ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int cab){
// Note cab=-1 for all cabs in the consist called throttleChar. // Note cab=-1 for all cabs in the consist called throttleChar.
switch (aval[0]) { switch (aval[0]) {

View File

@ -10,7 +10,7 @@ struct MYLOCO {
class WiThrottle { class WiThrottle {
public: public:
static void loop(); static void loop();
void parse(Print & stream, char * cmd); void parse(Print & stream, byte * cmd);
static WiThrottle* getThrottle(Print & stream, int wifiClient); static WiThrottle* getThrottle(Print & stream, int wifiClient);
private: private:
@ -20,8 +20,8 @@ class WiThrottle {
static const int MAX_MY_LOCO=10; static const int MAX_MY_LOCO=10;
static const int HEARTBEAT_TIMEOUT=10; static const int HEARTBEAT_TIMEOUT=10;
static WiThrottle* firstThrottle; static WiThrottle* firstThrottle;
static int getInt(char * cmd); static int getInt(byte * cmd);
static int getLocoId(char * cmd); static int getLocoId(byte * cmd);
WiThrottle* nextThrottle; WiThrottle* nextThrottle;
int clientid; int clientid;
@ -30,9 +30,9 @@ class WiThrottle {
bool heartBeatEnable; bool heartBeatEnable;
unsigned long heartBeat; unsigned long heartBeat;
void multithrottle(Print & stream, char* cmd); void multithrottle(Print & stream, byte * cmd);
void locoAction(Print & stream, char* aval, char throttleChar, int cab); void locoAction(Print & stream, byte* aval, char throttleChar, int cab);
void accessory(Print & stream, char* cmd); void accessory(Print & stream, byte* cmd);
void checkHeartbeat(); void checkHeartbeat();
}; };
#endif #endif

View File

@ -53,9 +53,9 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid,
return true; return true;
} }
bool WifiInterface::checkForOK(Stream & wifiStream, const int timeout, const char * waitfor, bool echo) { bool WifiInterface::checkForOK(Stream & wifiStream, const unsigned int timeout, const char * waitfor, bool echo) {
long int startTime = millis(); unsigned long startTime = millis();
char *locator=waitfor; char const *locator=waitfor;
DIAG(F("\nWifi setup Check: %S\n"),waitfor); DIAG(F("\nWifi setup Check: %S\n"),waitfor);
while( millis()-startTime < timeout) { while( millis()-startTime < timeout) {
while(wifiStream.available()) { while(wifiStream.available()) {
@ -75,6 +75,26 @@ bool WifiInterface::checkForOK(Stream & wifiStream, const int timeout, const cha
return false; return false;
} }
bool WifiInterface::isHTML() {
// POST GET PUT PATCH DELETE
// You may think a simple strstr() is better... but not when ram & time is in short supply
switch (buffer[0]) {
case 'P':
if (buffer[1]=='U' && buffer[2]=='T' && buffer[3]==' ' ) return true;
if (buffer[1]=='O' && buffer[2]=='S' && buffer[3]=='T' && buffer[4]==' ') return true;
if (buffer[1]=='A' && buffer[2]=='T' && buffer[3]=='C' && buffer[4]=='H' && buffer[5]==' ') return true;
return false;
case 'G':
if (buffer[1]=='E' && buffer[2]=='T' && buffer[3]==' ' ) return true;
return false;
case 'D':
if (buffer[1]=='E' && buffer[2]=='L' && buffer[3]=='E' && buffer[4]=='T' && buffer[5]=='E' && buffer[6]==' ') return true;
return false;
default:
return false;
}
}
void WifiInterface::loop(Stream & wifiStream) { void WifiInterface::loop(Stream & wifiStream) {
if (!connected) return; if (!connected) return;
@ -129,7 +149,7 @@ void WifiInterface::loop(Stream & wifiStream) {
// TODO ... tell JMRI parser that callbacks are diallowed because we dont want to handle the async // TODO ... tell JMRI parser that callbacks are diallowed because we dont want to handle the async
bool closeAfter=false; bool closeAfter=false;
// Intercept HTTP requests // Intercept HTTP requests
if (strstr(buffer," HTTP/1.1")) { if (isHTML()) {
HTTPParser::parse(streamer,buffer); HTTPParser::parse(streamer,buffer);
closeAfter=true; closeAfter=true;
} }

View File

@ -16,7 +16,8 @@ class WifiInterface {
static DCCEXParser parser; static DCCEXParser parser;
static bool setup2(Stream & wifiStream, const __FlashStringHelper* SSSid, const __FlashStringHelper* password, int port); static bool setup2(Stream & wifiStream, const __FlashStringHelper* SSSid, const __FlashStringHelper* password, int port);
static bool checkForOK(Stream & wifiStream, const int timeout, const char* waitfor, bool echo); static bool checkForOK(Stream & wifiStream, const unsigned int timeout, const char* waitfor, bool echo);
static bool isHTML();
static bool connected; static bool connected;
static byte loopstate; static byte loopstate;
static int datalength; static int datalength;