For Hepta-Sat Lite
Diff: HeptaXbee.cpp
- Revision:
- 10:9c8433d32d11
- Parent:
- 9:96ed36bbc9dd
- Child:
- 11:a5a0ab9949f3
diff -r 96ed36bbc9dd -r 9c8433d32d11 HeptaXbee.cpp --- a/HeptaXbee.cpp Wed Aug 08 11:01:54 2018 +0000 +++ b/HeptaXbee.cpp Tue Aug 21 05:35:44 2018 +0000 @@ -39,6 +39,8 @@ { char OutputData[255]; int output_num,numA,numB,numC,numD,numE,numF,numG,numH,numI,numJ,numK,numL,numM,numN; + int sum = 0; + int check; numA = sizeof(dataA) / sizeof(dataA[0]); numB = sizeof(dataB) / sizeof(dataB[0]); numC = sizeof(dataC) / sizeof(dataC[0]); @@ -110,10 +112,25 @@ for(i = 0; i <= numN-1; i++) { OutputData[N+i] = dataN[i]; } + //check sum for(ii=0; ii<output_num; ii++) { - xbee.putc(OutputData[ii]); + sum = sum + OutputData[ii]; } - xbee.putc(0x0a); + check = (~sum)&0xFF; + char check_sum[2],flame[2]; + sprintf( check_sum, "%02X", check); + sprintf( flame, "%02X", output_num); + // transmit data + for(int i = 0;i<2;i++){ + xbee.putc(flame[i]);//frame length + } + for(ii=0; ii<output_num; ii++) { + xbee.putc(OutputData[ii]);//data + } + for(int i = 0;i<2;i++){ + xbee.putc(check_sum[i]); + } + xbee.putc(0x0a);//endcode } void HeptaXbee::puts( char *s ) {