refactor(flysky_gimbal_driver): remove inefficiences in packet parsing function (#7443)
This commit is contained in:
@@ -105,12 +105,14 @@ static void _fs_parse(STRUCT_HALL *hallBuffer, unsigned char ch)
|
||||
case GET_LENGTH:
|
||||
hallBuffer->length = ch;
|
||||
hallBuffer->dataIndex = 0;
|
||||
hallBuffer->status = GET_DATA;
|
||||
if(hallBuffer->length > HALLSTICK_BUFF_SIZE - 5) { // buffer size - header size (1 byte header + 1 byte ID + 1 byte length + 2 bytes CRC = 5 bytes)
|
||||
|
||||
if (hallBuffer->length > HALLSTICK_BUFF_SIZE - 5) { // buffer size - header size (1 byte header + 1 byte ID + 1 byte length + 2 bytes CRC = 5 bytes)
|
||||
hallBuffer->status = GET_START;
|
||||
} else if (0 == hallBuffer->length) {
|
||||
hallBuffer->status = GET_CHECKSUM;
|
||||
hallBuffer->checkSum = 0;
|
||||
} else {
|
||||
hallBuffer->status = GET_DATA; // length is in a valid range, next state should extract data
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -119,16 +121,10 @@ static void _fs_parse(STRUCT_HALL *hallBuffer, unsigned char ch)
|
||||
if (hallBuffer->dataIndex >= hallBuffer->length) {
|
||||
hallBuffer->checkSum = 0;
|
||||
hallBuffer->dataIndex = 0;
|
||||
hallBuffer->status = GET_STATE;
|
||||
hallBuffer->status = GET_CHECKSUM;
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_STATE:
|
||||
hallBuffer->checkSum = 0;
|
||||
hallBuffer->dataIndex = 0;
|
||||
hallBuffer->status = GET_CHECKSUM;
|
||||
// fall through!
|
||||
|
||||
case GET_CHECKSUM:
|
||||
hallBuffer->checkSum |= ch << ((hallBuffer->dataIndex++) * 8);
|
||||
if (hallBuffer->dataIndex >= 2) {
|
||||
|
||||
@@ -107,7 +107,6 @@ enum
|
||||
GET_ID,
|
||||
GET_LENGTH,
|
||||
GET_DATA,
|
||||
GET_STATE,
|
||||
GET_CHECKSUM,
|
||||
CHECKSUM,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user