Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion radio/src/targets/common/arm/stm32/flysky_gimbal_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ enum
GET_ID,
GET_LENGTH,
GET_DATA,
GET_STATE,
GET_CHECKSUM,
CHECKSUM,
};
Expand Down