Skip to content

Commit

Permalink
add timeout while waiting for arb response
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkucera committed Mar 24, 2023
1 parent 0097513 commit 9b57ef6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/enhanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ int pushEnhClient(WiFiClient* client, uint8_t B){
if (arbitration_client == client) {
Serial.write(arbitration_address);

while (Serial.available() == 0);
while (Serial.available() == 0) {
if (millis() > arbitration_start + ARBITRATION_TIMEOUT_MS) {
send_res(client, FAILED, 0x3f);
arbitration_client = NULL;
return 1;
}
}

if (Serial.read() == arbitration_address){ // arbitration success
send_res(client, STARTED, arbitration_address);
arbitration_client = NULL;
} else { // arbitration fail

// do nothing, arbitration will retry on next SYN until timeout or cancel
}
return 1;
}
Expand Down

0 comments on commit 9b57ef6

Please sign in to comment.