Created
June 5, 2019 11:20
-
-
Save FLamparski/c11a2817351ede4b6c3f2f81d0cd99ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Computes the checksum of a SDS011 message. | |
* | |
* This checksum is the low 8 bits of the sum of the data bytes. | |
* The sensor will not react to commands with invalid checksum. | |
*/ | |
byte sds011_checksum(byte* msg, size_t msg_size) { | |
int sum = 0; | |
for (int i = 2; i < msg_size - 2; i++) { | |
sum += msg[i]; | |
} | |
return (byte) 0xff & sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment