1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +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().
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) {
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"));

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 parameterCount=0;
int runningValue=0;
const char * remainingCmd=cmd+1; // skips the opcode
const byte * remainingCmd=cmd+1; // skips the opcode
bool signNegative=false;
// clear all parameters in case not enough found
for (int i=0;i<MAX_PARAMS;i++) result[i]=0;
while(parameterCount<MAX_PARAMS) {
char hot=*remainingCmd;
byte hot=*remainingCmd;
switch (state) {
@ -109,7 +109,7 @@ void DCCEXParser::setFilter(FILTER_CALLBACK filter) {
}
// 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);
(void) EEPROM; // tell compiler not to warn thi is unused
int p[MAX_PARAMS];
@ -133,7 +133,7 @@ void DCCEXParser::parse(Print & stream, const char *com) {
break;
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);
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);
else if (p[1]==223) funcmap(p[0],p[2],21,28);
}
// NO RESPONSE
(void)stream;// NO RESPONSE
return true;
}
void DCCEXParser::funcmap(int cab, byte value, byte fstart, byte fstop) {
for (int i=fstart;i<=fstop;i++) {
DCC::setFn(cab, i, value & 1);
value>>1;
value>>=1;
}
}

View File

@ -8,7 +8,7 @@ struct DCCEXParser
{
DCCEXParser();
void loop(Stream & pstream);
void parse(Print & stream, const char * command);
void parse(Print & stream, const byte * command);
void flush();
static void setFilter(FILTER_CALLBACK filter);
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
byte bufferLength=0;
bool inCommandPayload=false;
char buffer[MAX_BUFFER+2];
int splitValues( int result[MAX_PARAMS],char * command);
byte buffer[MAX_BUFFER+2];
int splitValues( int result[MAX_PARAMS], const byte * command);
bool parseT(Print & stream, int params, int p[]);
bool parseZ(Print & stream, int params, int p[]);

View File

@ -1,8 +1,9 @@
#include "HTTPParser.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!
// You must get everything you need from it before using StringFormatter::send!

View File

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

View File

@ -46,7 +46,7 @@ public:
operator const uint8_t *() const { return _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; }
void end() {}

View File

@ -47,7 +47,7 @@ WiThrottle::WiThrottle(Print & stream, int wificlientid) {
firstThrottle= this;
clientid=wificlientid;
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){
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();
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);
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...
// should we create one or just send the DCC message.
Turnout::activate(getInt(cmd+4),cmd[3]=='T');
@ -96,7 +96,7 @@ void WiThrottle::parse(Print & stream, char * cmd) {
break;
}
}
int WiThrottle::getInt(char * cmd) {
int WiThrottle::getInt(byte * cmd) {
int i=0;
while (cmd[0]>='0' && cmd[0]<='9') {
i=i*10 + (cmd[0]-'0');
@ -105,15 +105,15 @@ int WiThrottle::getInt(char * cmd) {
return i;
}
int WiThrottle::getLocoId(char * cmd) {
int WiThrottle::getLocoId(byte * cmd) {
if (cmd[0]=='*') return -1; // match all locos
if (cmd[0]!='L' && cmd[0]!='S') return 0; // should not match any locos
return getInt(cmd+1);
}
void WiThrottle::multithrottle(Print & stream, char* cmd){
void WiThrottle::multithrottle(Print & stream, byte * cmd){
char throttleChar=cmd[1];
int locoid=getLocoId(cmd+3); // -1 for *
char * aval=cmd;
byte * aval=cmd;
while(*aval !=';' && *aval !='\0') 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.
switch (aval[0]) {

View File

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

View File

@ -53,9 +53,9 @@ bool WifiInterface::setup2(Stream & wifiStream, const __FlashStringHelper* SSid,
return true;
}
bool WifiInterface::checkForOK(Stream & wifiStream, const int timeout, const char * waitfor, bool echo) {
long int startTime = millis();
char *locator=waitfor;
bool WifiInterface::checkForOK(Stream & wifiStream, const unsigned int timeout, const char * waitfor, bool echo) {
unsigned long startTime = millis();
char const *locator=waitfor;
DIAG(F("\nWifi setup Check: %S\n"),waitfor);
while( millis()-startTime < timeout) {
while(wifiStream.available()) {
@ -75,6 +75,26 @@ bool WifiInterface::checkForOK(Stream & wifiStream, const int timeout, const cha
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) {
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
bool closeAfter=false;
// Intercept HTTP requests
if (strstr(buffer," HTTP/1.1")) {
if (isHTML()) {
HTTPParser::parse(streamer,buffer);
closeAfter=true;
}

View File

@ -16,7 +16,8 @@ class WifiInterface {
static DCCEXParser parser;
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 byte loopstate;
static int datalength;