[P176] Fix checksum validation, was ignoring the first line after receiving a valid checksum

This commit is contained in:
Ton Huisman
2024-11-02 15:09:51 +01:00
parent 21ff328715
commit 7de795e2e8
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -91,7 +91,7 @@ This example shows the data as can be received from a VE.Direct device.
The *Name* column is what should be used in the Values fields, or when as a ``<ValueName>`` from rules or in a display configuration. The exact meaning and unit of each field can be found in the VE.Direct protocol documentation, available from Victron Energy.
The *Data* column shows the actual data as received.
The *Data* column shows the actual data as received. If the checksum validation is enabled, this column may be empty if the checksum could not be verified, like the first (possibly incomplete) packet, but as the frequency of packets is rather high, this column should not often (or long) be empty.
The *Value* column shows a factored result based on the value, as mV is not always very useful, so that's converted to V, mA to A, Wh to kWh, etc.
+9 -3
View File
@@ -272,7 +272,7 @@ bool P176_data_struct::handleSerial() {
if (Checksum_state_e::ValidateNext == _checksumState) {
_checksumState = Checksum_state_e::Validating;
} else
if (Checksum_state_e::Starting == _checksumState) { // Start counting after a Checksum was received
if (Checksum_state_e::Starting == _checksumState) { // Start counting after a Checksum (aka 'end of packet') was received
_checksumState = Checksum_state_e::Counting;
_checksum = 0;
# if P176_DEBUG
@@ -298,6 +298,10 @@ bool P176_data_struct::handleSerial() {
# endif // if P176_DEBUG
} else {
_checksumState = Checksum_state_e::Starting;
# if P176_FAIL_CHECKSUM
commitTempData(!_failChecksum); // Discard any data received so far, as we don't know their checksum status
# endif // if P176_FAIL_CHECKSUM
}
}
# endif // if P176_HANDLE_CHECKSUM
@@ -317,10 +321,11 @@ bool P176_data_struct::handleSerial() {
_checksumDelta = 0;
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
addLog(LOG_LEVEL_ERROR, strformat(F("Victron: Checksum error, expected 0 but got %d"), _checksum));
addLog(LOG_LEVEL_ERROR, strformat(F("Victron: Checksum error, expected 0 but got %d (success: %d errors: %d)"),
_checksum, _successCounter, _checksumErrors));
}
} else {
_checksumState = Checksum_state_e::Starting;
_checksumState = Checksum_state_e::Counting; // New packet is expected, start counting immediately
_successCounter++;
_checksumDelta++;
result = true;
@@ -334,6 +339,7 @@ bool P176_data_struct::handleSerial() {
addLog(LOG_LEVEL_INFO, F("Victron: Checksum validated Ok"));
}
}
_checksum = 0; // Clean start
# if P176_FAIL_CHECKSUM