- Kód: Vybrat vše
//Calculate checksum
if ( chkpos != string::npos ) {
for (auto c = possible_command.cbegin(); *c != '*' && c != possible_command.cend(); c++)
cs = cs ^ *c;
cs &= 0xff; // Defensive programming...
cs -= chksum;
}
Tady mas jeste citaci z Repetieru:
- With higher speeds, the serial connection is more likely to produce communication failures.
The standard method is to transfer a checksum at the end of the line. This checksum is the
XORd value of all characters send. The value is limited to a range between 0 and 127. It can
not detect two identical missing characters or a wrong order. Therefore the new protocol
uses Fletchers checksum, which overcomes these shortcommings.
- Kód: Vybrat vše
uint8_t checksum_given = parseLongValue(pos);
uint8_t checksum = 0;
while(line != (pos - 1)) checksum ^= *line++;
#if FEATURE_CHECKSUM_FORCED
Printer::flag0 |= PRINTER_FLAG0_FORCE_CHECKSUM;
#endif
if(checksum != checksum_given)
{
if(Printer::debugErrors())
{
Com::printErrorFLN(Com::tWrongChecksum);
}
return false; // mismatch
}
hasChecksum = true;
break;