-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Claudio Micheli <[email protected]>
- Loading branch information
Showing
2 changed files
with
57 additions
and
48 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,10 +128,7 @@ USHORT usMBCRC16(UCHAR* pucFrame, USHORT usLen) { | |
int isl2950_parser(uint8_t c, uint8_t *parserbuf, ISL2950_PARSE_STATE *state, uint16_t *crc16, int *dist) | ||
{ | ||
int ret = -1; | ||
// int bytes_processed = 0; | ||
|
||
|
||
// uint8_t b = buffer[bytes_processed++]; // Can be removed | ||
// printf("parse byte 0x%02X \n", b); | ||
|
||
switch (*state) { | ||
|
@@ -147,10 +144,10 @@ int isl2950_parser(uint8_t c, uint8_t *parserbuf, ISL2950_PARSE_STATE *state, ui | |
*state = TFS_GOT_SFD2; | ||
//printf("Got SFD2 \n"); | ||
} | ||
// @NOTE ([email protected]): Strange thing, if second byte is wrong we skip all the frame !! | ||
// @NOTE: ([email protected]): Strange thing, if second byte is wrong we skip all the frame and restart parsing !! | ||
else if (c == TOF_SFD1) { | ||
*state = TFS_GOT_SFD1; | ||
// printf("Discard previous SFD1, Got new SFD1 \n"); | ||
//printf("Discard previous SFD1, Got new SFD1 \n"); | ||
} else { | ||
*state = TFS_NOT_STARTED; | ||
} | ||
|
@@ -172,34 +169,36 @@ int isl2950_parser(uint8_t c, uint8_t *parserbuf, ISL2950_PARSE_STATE *state, ui | |
*crc16 = (*crc16 >> 8) | (*crc16 << 8); | ||
break; | ||
|
||
/* @NOTE ([email protected]) : Since data that not pass this crc check seems to be valid anyway, it will be published discard the bad high CRC*/ | ||
case TFS_GOT_DATA2: | ||
if (c == (*crc16 >> 8)) { | ||
*state = TFS_GOT_CHECKSUM1; | ||
} else { | ||
printf("Checksum invalid on high byte: 0x%02X, calculated: 0x%04X \n",c, *crc16); | ||
//*state = TFS_NOT_STARTED; | ||
*state = TFS_GOT_CHECKSUM1; // Forcing to print the value anyway | ||
//*dist = (parserbuf[TOF_DISTANCE_MSB_POS] << 8) | parserbuf[TOF_DISTANCE_LSB_POS]; | ||
//return OK; | ||
} | ||
else { | ||
printf("Checksum invalid on high byte: 0x%02X, calculated: 0x%04X \n",c, *crc16); | ||
*state = TFS_NOT_STARTED; | ||
//*state = TFS_GOT_CHECKSUM1; // Forcing to print the value anyway | ||
} | ||
break; | ||
|
||
case TFS_GOT_CHECKSUM1: | ||
case TFS_GOT_CHECKSUM1: | ||
// Here, reset state to `NOT-STARTED` no matter crc ok or not | ||
*state = TFS_NOT_STARTED; | ||
/*if (c == (*crc16 & 0xFF)) { | ||
//printf("Checksum verified \n"); | ||
if (c == (*crc16 & 0xFF)) { | ||
printf("Checksum verified \n"); | ||
*dist = (parserbuf[TOF_DISTANCE_MSB_POS] << 8) | parserbuf[TOF_DISTANCE_LSB_POS]; | ||
return OK; | ||
}*/ | ||
*dist = (parserbuf[TOF_DISTANCE_MSB_POS] << 8) | parserbuf[TOF_DISTANCE_LSB_POS]; | ||
return OK; | ||
|
||
} else { | ||
//printf("Checksum invalidon low byte: 0x%02X, calculated: 0x%04X \n",c, *crc16); | ||
} | ||
break; | ||
|
||
default: | ||
printf("This should never happen. \n"); | ||
break; | ||
} | ||
|
||
// SOME STUFFS | ||
return ret; | ||
} |