mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
Wifi Interface WORKING
This commit is contained in:
parent
2a36ad365c
commit
8538aa1624
|
@ -51,11 +51,11 @@ void DCCEXParser::loop(Stream & stream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int DCCEXParser::splitValues( int result[MAX_PARAMS]) {
|
int DCCEXParser::splitValues( int result[MAX_PARAMS], char * cmd) {
|
||||||
byte state=1;
|
byte state=1;
|
||||||
byte parameterCount=0;
|
byte parameterCount=0;
|
||||||
int runningValue=0;
|
int runningValue=0;
|
||||||
const char * remainingCmd=buffer+1; // skips the opcode
|
const char * 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
|
||||||
|
@ -96,11 +96,12 @@ void DCCEXParser::loop(Stream & stream) {
|
||||||
|
|
||||||
// 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 char *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];
|
||||||
int params=splitValues(p);
|
int params=splitValues(p, com);
|
||||||
|
|
||||||
|
if (com[0]=='<') com++;
|
||||||
|
|
||||||
// Functions return from this switch if complete, break from switch implies error <X> to send
|
// Functions return from this switch if complete, break from switch implies error <X> to send
|
||||||
switch(com[0]) {
|
switch(com[0]) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct DCCEXParser
|
||||||
byte bufferLength=0;
|
byte bufferLength=0;
|
||||||
bool inCommandPayload=false;
|
bool inCommandPayload=false;
|
||||||
char buffer[MAX_BUFFER+2];
|
char buffer[MAX_BUFFER+2];
|
||||||
int splitValues( int result[MAX_PARAMS]);
|
int splitValues( int result[MAX_PARAMS],char * 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[]);
|
||||||
|
|
|
@ -78,6 +78,7 @@ void WifiInterface::loop() {
|
||||||
// read anything into a buffer, collecting info on the way
|
// read anything into a buffer, collecting info on the way
|
||||||
while (loopstate!=99 && Serial1.available()) {
|
while (loopstate!=99 && Serial1.available()) {
|
||||||
int ch=Serial1.read();
|
int ch=Serial1.read();
|
||||||
|
Serial.write(ch);
|
||||||
switch (loopstate) {
|
switch (loopstate) {
|
||||||
case 0: // looking for +
|
case 0: // looking for +
|
||||||
connectionId=0;
|
connectionId=0;
|
||||||
|
@ -105,6 +106,7 @@ void WifiInterface::loop() {
|
||||||
else datalength=datalength*10 + (ch-'0');
|
else datalength=datalength*10 + (ch-'0');
|
||||||
break;
|
break;
|
||||||
case 7: // reading data
|
case 7: // reading data
|
||||||
|
streamer.write(ch);
|
||||||
datalength--;
|
datalength--;
|
||||||
if (datalength==0) loopstate=99;
|
if (datalength==0) loopstate=99;
|
||||||
break;
|
break;
|
||||||
|
@ -113,13 +115,19 @@ void WifiInterface::loop() {
|
||||||
if (loopstate!=99) return;
|
if (loopstate!=99) return;
|
||||||
// TODO remove > in data
|
// TODO remove > in data
|
||||||
streamer.write('\0');
|
streamer.write('\0');
|
||||||
streamer.flush(); // reset write position to start of buffer
|
|
||||||
|
DIAG(F("\nWifiRead:%d:%s\n"),connectionId,buffer);
|
||||||
|
streamer.setBufferContentPosition(0,0); // reset write position to start of buffer
|
||||||
// SIDE EFFECT WARNING:::
|
// SIDE EFFECT WARNING:::
|
||||||
// We know that parser will read the entire buffer before starting to write to it.
|
// We know that parser will read the entire buffer before starting to write to it.
|
||||||
// Otherwise we would have to copy the buffer elsewhere and RAM is in short supply.
|
// Otherwise we would have to copy the buffer elsewhere and RAM is in short supply.
|
||||||
|
|
||||||
// TODO ... tell parser that callbacks are diallowed because we dont want to handle the async
|
// TODO ... tell parser that callbacks are diallowed because we dont want to handle the async
|
||||||
parser.parse(streamer,buffer+1);
|
parser.parse(streamer,buffer);
|
||||||
StringFormatter::send(Serial1,F("AT+CIPSEND=%d,%d\r\n>%s"),connectionId,streamer.available(),buffer);
|
if (streamer.available()) { // there is a reply to send
|
||||||
loopstate=0;
|
StringFormatter::send(Serial1,F("AT+CIPSEND=%d,%d\r\n"),connectionId,streamer.available());
|
||||||
|
streamer.write('\0');
|
||||||
|
if (checkForOK(1000,">")) Serial1.print((char *) buffer);
|
||||||
|
}
|
||||||
|
loopstate=0; // go back to looking for +IPD
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user