Patches: Removed critical delay and reduced the error rate.

This commit is contained in:
paul nehlich 2024-07-11 10:55:33 +02:00
parent 2d5ac0b16b
commit 0ebc73ad66

View File

@ -77,7 +77,7 @@ void setup() {
void loop() {
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
delay(5); // Small delay to make communication more interesting
//delay(5); // Small delay to make communication more interesting
handleCommand(command);
}
}
@ -105,7 +105,9 @@ void handleCommand(String command) {
} else if (parts[0] == "RESET_SENSORS" && size == 1) {
resetSensors();
} else {
Serial.println("ERROR: UNKNOWN COMMAND");
Serial.println("ERROR: UNKNOWN COMMAND:\n");
// PATCH: Print the unknown command in a new line.
Serial.println(parts[0]);
}
delete[] parts;
@ -115,8 +117,10 @@ void handleCommand(String command) {
void handleGetSensor(String command, String sensor) {
if (command == "REQUEST") { // request data from the RUI (which will request it from the sensor)
if (!commState.requestConfirmed && randomFailure(0.1)) {
Serial.println("ERROR");
if (!commState.requestConfirmed && randomFailure(0.01)) {
// PATCH: Reduce all failure rates by 90%
Serial.println("ERROR-01 ");
// PATCH: "ERROR" is very generic. Let's call it ERROR-01
return;
}
lastSensorValue = getRawSensorData(sensor);
@ -124,7 +128,8 @@ void handleGetSensor(String command, String sensor) {
commState.requestConfirmed = true;
} else if (command == "CONFIRM") { // did you request the data from the sensor?
if (!commState.confirmConfirmed && randomFailure(0.1)) {
// PATCH: Reduce all failure rates by 90%
if (!commState.confirmConfirmed && randomFailure(0.01)) {
Serial.println("FALSE");
return;
}
@ -135,7 +140,8 @@ void handleGetSensor(String command, String sensor) {
Serial.println("FALSE");
}
} else if (command == "CHECK") { // did you get the data from the sensor?
if (!commState.checkConfirmed && randomFailure(0.5)) {
// PATCH: Reduce all failure rates by 90%
if (!commState.checkConfirmed && randomFailure(0.05)) {
Serial.println("FALSE");
} else {
if (commState.requestConfirmed) {