this was what the OP posted
FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC00680008000800080000000000000000000000000
008000000000000000000000000000000020AB78324242982B0DEF01FFFFFFFF0200825E1F56592A3ED8D9674201F900000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000056CEF01FFFFFFFF0200820
3015E169700FFFEFFFEFFFEFF1EC006C002C0008000000000000000000000000000000000000000000000000
000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845E59B2DC5E4
5B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F2AF9EF0
1FFFFFFFF08008239C306376297D71C659B2C7C2E3944160000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000618FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
as the output of his request. in that blurb or data we can recognize 3 frames starting with EF01
I color coded the format of a frame as:
data to be ignored
EF01
ADDER --> Default value is 0xFFFFFFFF
package identifier --> describe what type of information is in the package
length --> length of package
The actual data
check sum
FFFFFFFFFFFFFFFFFF0165159200FFFEFFFEFFFEFFFEF80EC006800080008000800000000000000
00000000000008000000000000000000000000000000020AB78324242982B0D
EF01FFFFFFFF020082
5E1F56592A3ED8D9674201F9000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
056C
EF01FFFFFFFF020082
03015E169700FFFEFFFEFFFEFF1EC006C002C000800000000000000000000000000000000000000
0000000000000FFFFFFFFFFFFFFFFFFFFFF98415E1BA41ADE49A4431E6BA481FE2E26047E60AB033E0AAD845
E59B2DC5E45B39ADE0AB604BE09BADC5E1F3D9ABE553F04FE48C29ADE3898031F26AD843F53AF44FF71B81F9F
2AF9
EF01FFFFFFFF080082
39C306376297D71C659B2C7C2E394416000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000
0618
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
so we see we have 3 frames, the first two are of type 02, meaning 'Data packet' and the last one is of type 08 which means 'End of Data packet'. (01 would be a "Command packet", 07 would be an "Acknowledge packet")
we then see that the length of package is 0x0082(hex) which is 130 in decimal
The length of the packet is composed of the length of the data + the 2 bytes for the checksum --> 128 bytes + 2 for checksum = 130 --> so we have 128 bytes of data, which will be represented as 256 ASCII symbols for the data and 2 bytes for the checksum represented by 4 ASCII symbols (theoretical Max length is 256 bytes so the library creates large buffers just in case but here we get the 128 byte frames).
we then have the data followed by the checksum on 16 bits
To calculate the checksum the documentation states it's the arithmetic sum of package identifier, package length and all package content with Overflowing bits being omitted
package ID = 1 byte
package length = 2 bytes
package content = we have seen above it's 128 bytes
so to run the checksum we need 128+2+1 = 131 bytes, or 262 characters starting at the package ID
So you need to take the package ID, length and content and sum all the numeric value represented by each byte, so you need to read 2 ASCII symbols, high side first, build a byte value and add to the sum in a 16 bit unsigned variable ignoring overflow.
In the first example above this would be the stream of data
0200825E1F56592A3ED8D9674201F90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
if you dump that into this test code
void getHexBufferCKSum()
{
uint16_t cksum = 0;
uint16_t lsb = 0, hsb = 0;
boolean waitingForHigh = true;
Serial.println(F("Enter HexBuffer (0..9 or A..F all caps):"));
unsigned int nbBytes = 0;
unsigned int nbCars = 0;
while (1) {
if (Serial.available()) {
int r = Serial.read();
if ((r != -1) && (r != '\n')) { // ignore and terminates on '\n'
if ((r != '\r') && (((r >= '0') && (r <= '9')) || ((r >= 'A') && (r <= 'F')))) { // ignore '\r', handle only 0 to 9 and A to F
uint8_t v;
if ((r >= '0') && (r <= '9')) v = r - '0';
else v = r - 'A' + 10;
if (waitingForHigh) {
hsb = v;
} else {
lsb = v;
cksum += 16 * hsb + lsb;
nbBytes++; // got a full byte
}
waitingForHigh = !waitingForHigh;
nbCars++;
}
} else break;
}
}
Serial.print(F("received ")); Serial.print(nbCars);
Serial.print(F(" characters (")); Serial.print(nbBytes);
Serial.print(F(" bytes), cksum is ")); Serial.println(cksum, HEX);
if (nbCars != 2 * nbBytes) Serial.println(F("*** received weird number of characters, check input ***"));
Serial.println(F("-------------------"));
}
void setup() {
Serial.begin(115200);
}
void loop() {
getHexBufferCKSum();
}
you will see in your Serial console (set at 115200 bauds / sending NL to terminate)
[color=purple]Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 56C[/color]
So you can see that there is ineed 262 characters received and 56C(hex) is indeed the check sum 056C we had received for the first package
if you run the data for the third package you will see in your Serial console
[color=purple]Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 618
[/color]
So you can see that there is ineed 262 characters received and 618(hex) is indeed the check sum 0618 we had received for the third package
but if you run that for the second package, you will see in your Serial console
[color=purple]Enter HexBuffer (0..9 or A..F all caps):
received 262 characters (131 bytes), cksum is 359D[/color]
So you can see that there is ineed 262 characters received BUT 359D(hex) is NOT the check sum 2AF9 we had received for the third package.. So something weird there...