Added a-lurkers proposed changes to speed up message porcessing.

This commit is contained in:
Henrik Ekblad
2014-03-25 23:47:14 +01:00
parent 01d06cd034
commit 04b0da5f5a
+29 -24
View File
@@ -127,35 +127,40 @@ void processEthernetMessages()
// bytes available to read via the client object
EthernetClient client = server.available();
if (client)
if (client)
{
// read the bytes incoming from the client
char inChar = client.read();
// if got 1 or more bytes
if (client.available())
{
// read the bytes incoming from the client
char inChar = client.read();
// echo the bytes to the serial port
Serial.print(inChar);
if (inputPos<MAX_RECEIVE_LENGTH-1) {
// if newline then command is complete
if (inChar == '\n')
{ // a command was issued by the client
// we will now try to send it to the actuator
inputString[inputPos] = 0;
if (inputPos<MAX_RECEIVE_LENGTH-1) {
// if newline then command is complete
if (inChar == '\n')
{ // a command was issued by the client
// we will now try to send it to the actuator
inputString[inputPos] = 0;
gw.parseAndSend(inputString);
// clear the string:
// echo the string to the serial port
Serial.print(inputString);
gw.parseAndSend(inputString);
// clear the string:
inputPos = 0;
}
else
{ // add it to the inputString:
inputString[inputPos] = inChar;
inputPos++;
}
} else {
// Incoming message too long. Throw away
inputPos = 0;
}
else
{ // add it to the inputString:
inputString[inputPos] = inChar;
inputPos++;
}
} else {
// Incoming message too long. Throw away
inputPos = 0;
}
}
}
}
}