Skip to content

Commit 5f22ea3

Browse files
committed
Merge pull request arduino#9 from mysensors/ethernet-improvement-feature
Added a-lurkers proposed changes to speed up message porcessing.
2 parents 75fd62e + 04b0da5 commit 5f22ea3

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

Diff for: EthernetGateway/EthernetGateway.ino

+31-26
Original file line numberDiff line numberDiff line change
@@ -127,35 +127,40 @@ void processEthernetMessages()
127127
// bytes available to read via the client object
128128
EthernetClient client = server.available();
129129

130-
if (client)
130+
if (client)
131131
{
132-
// read the bytes incoming from the client
133-
char inChar = client.read();
134-
135-
// echo the bytes to the serial port
136-
Serial.print(inChar);
137-
138-
if (inputPos<MAX_RECEIVE_LENGTH-1) {
139-
// if newline then command is complete
140-
if (inChar == '\n')
141-
{ // a command was issued by the client
142-
// we will now try to send it to the actuator
143-
inputString[inputPos] = 0;
144-
gw.parseAndSend(inputString);
145-
146-
// clear the string:
132+
// if got 1 or more bytes
133+
if (client.available())
134+
{
135+
// read the bytes incoming from the client
136+
char inChar = client.read();
137+
138+
if (inputPos<MAX_RECEIVE_LENGTH-1) {
139+
// if newline then command is complete
140+
if (inChar == '\n')
141+
{ // a command was issued by the client
142+
// we will now try to send it to the actuator
143+
inputString[inputPos] = 0;
144+
145+
// echo the string to the serial port
146+
Serial.print(inputString);
147+
148+
gw.parseAndSend(inputString);
149+
150+
// clear the string:
151+
inputPos = 0;
152+
}
153+
else
154+
{ // add it to the inputString:
155+
inputString[inputPos] = inChar;
156+
inputPos++;
157+
}
158+
} else {
159+
// Incoming message too long. Throw away
147160
inputPos = 0;
148161
}
149-
else
150-
{ // add it to the inputString:
151-
inputString[inputPos] = inChar;
152-
inputPos++;
153-
}
154-
} else {
155-
// Incoming message too long. Throw away
156-
inputPos = 0;
157-
}
158-
}
162+
}
163+
}
159164
}
160165

161166

0 commit comments

Comments
 (0)