mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +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 parameterCount=0;
|
||||
int runningValue=0;
|
||||
const char * remainingCmd=buffer+1; // skips the opcode
|
||||
const char * remainingCmd=cmd+1; // skips the opcode
|
||||
bool signNegative=false;
|
||||
|
||||
// clear all parameters in case not enough found
|
||||
|
@ -96,12 +96,13 @@ void DCCEXParser::loop(Stream & stream) {
|
|||
|
||||
// See documentation on DCC class for info on this section
|
||||
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
|
||||
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
|
||||
switch(com[0]) {
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ struct DCCEXParser
|
|||
byte bufferLength=0;
|
||||
bool inCommandPayload=false;
|
||||
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 parseZ(Print & stream, int params, int p[]);
|
||||
|
|
|
@ -78,6 +78,7 @@ void WifiInterface::loop() {
|
|||
// read anything into a buffer, collecting info on the way
|
||||
while (loopstate!=99 && Serial1.available()) {
|
||||
int ch=Serial1.read();
|
||||
Serial.write(ch);
|
||||
switch (loopstate) {
|
||||
case 0: // looking for +
|
||||
connectionId=0;
|
||||
|
@ -105,6 +106,7 @@ void WifiInterface::loop() {
|
|||
else datalength=datalength*10 + (ch-'0');
|
||||
break;
|
||||
case 7: // reading data
|
||||
streamer.write(ch);
|
||||
datalength--;
|
||||
if (datalength==0) loopstate=99;
|
||||
break;
|
||||
|
@ -113,13 +115,19 @@ void WifiInterface::loop() {
|
|||
if (loopstate!=99) return;
|
||||
// TODO remove > in data
|
||||
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:::
|
||||
// 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.
|
||||
|
||||
// TODO ... tell parser that callbacks are diallowed because we dont want to handle the async
|
||||
parser.parse(streamer,buffer+1);
|
||||
StringFormatter::send(Serial1,F("AT+CIPSEND=%d,%d\r\n>%s"),connectionId,streamer.available(),buffer);
|
||||
loopstate=0;
|
||||
parser.parse(streamer,buffer);
|
||||
if (streamer.available()) { // there is a reply to send
|
||||
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