cube crc 16
Dependents: CEBF746_Master CEBF746_Slave_withTPM CEBF746_Master_New
Revision 1:e30d6ab46e27, committed 2016-10-17
- Comitter:
- gandol2
- Date:
- Mon Oct 17 07:10:53 2016 +0000
- Parent:
- 0:0fd8f2287db9
- Commit message:
- commit
;
Changed in this revision
lib_crc.cpp | Show annotated file Show diff for this revision Revisions of this file |
lib_crc.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0fd8f2287db9 -r e30d6ab46e27 lib_crc.cpp --- a/lib_crc.cpp Fri Oct 14 01:16:02 2016 +0000 +++ b/lib_crc.cpp Mon Oct 17 07:10:53 2016 +0000 @@ -6,7 +6,7 @@ * @param[in] data pointer to data * @param[out] 2byte crc pointer to calculated CRC (high byte at crc[0]) */ -void cube_crc_16(uint8_t length, uint8_t *data, uint8_t *crc) +void cube_crc_16(uint16_t length, uint8_t *data, uint16_t *crc) { uint8_t counter; uint8_t crcLow = 0, crcHigh = 0, crcCarry; @@ -28,8 +28,10 @@ } } } - crc[0] = crcHigh; - crc[1] = crcLow; + + *crc = (crcHigh << 8) | crcLow; + //crc[0] = crcHigh; + //crc[1] = crcLow; } /** @brief compare 2byte crc pointer @@ -38,10 +40,10 @@ * @param[in] crc2 second 2byte crc pointer * @return same is true, other is false */ -bool cube_crc_compare(uint8_t *crc1, uint8_t *crc2) +bool cube_crc_compare(uint16_t crc1, uint16_t crc2) { bool ret = false; - if( (crc1[0] == crc2[0]) && (crc1[1] == crc2[1]) ) + if( crc1 == crc2 ) { ret = true; } @@ -55,13 +57,13 @@ */ bool test_cube_crc_16(void) { - bool ret = false; - uint8_t validateCrc[] = {0xF9, 0x60}; + bool ret = false; uint8_t testData[] = {0x09, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00}; - uint8_t outCrc[2] = {0, 0}; + uint16_t validateCrc = 0xF960; + uint16_t outCrc = 0; - cube_crc_16(sizeof(testData), testData, outCrc); - if( (validateCrc[0] == outCrc[0]) && (validateCrc[1] == outCrc[1]) ) + cube_crc_16(sizeof(testData), testData, &outCrc); + if( validateCrc == outCrc ) { ret = true; }
diff -r 0fd8f2287db9 -r e30d6ab46e27 lib_crc.h --- a/lib_crc.h Fri Oct 14 01:16:02 2016 +0000 +++ b/lib_crc.h Mon Oct 17 07:10:53 2016 +0000 @@ -1,8 +1,8 @@ #ifndef _CUBE_CRC_H_ #define _CUBE_CRC_H_ -void cube_crc_16(uint8_t length, uint8_t *data, uint8_t *crc); -bool cube_crc_compare(uint8_t *crc1, uint8_t *crc2); +void cube_crc_16(uint16_t length, uint8_t *data, uint16_t *crc); +bool cube_crc_compare(uint16_t crc1, uint16_t crc2); bool test_cube_crc_16(void); #endif /* _CUBE_CRC_H_ */