修改解决多个帧头以及错误处理

This commit is contained in:
2025-10-21 21:10:21 +08:00
parent c3f6375140
commit c7bed50170
12 changed files with 247 additions and 2546 deletions

54
UART.C
View File

@@ -211,7 +211,10 @@ void UART_viIsr(void) interrupt UARTINT
static uint8_t state = 0;
static uint8_t receive = 0;
static uint8_t sbus_buff[25];
SBusData *tmp_sbus_data;
uint8_t i = 0;
uint8_t start_index = 0;
// SBusData *tmp_sbus_data;
// USER CODE END
SFR_PAGE(_su0, SST0); // switch to page 0
if (TI)
@@ -249,22 +252,39 @@ void UART_viIsr(void) interrupt UARTINT
case 1:
if(cnt_sbus >= 24)
{
if(0x0 == char_data[0])
{
cnt_sbus = 0;
receive = 0;
sbus_buff[cnt_sbus] = char_data[0];
state = 0;
tmp_sbus_data = parseSBusData(sbus_buff);
}
}
else if( (0x0f == char_data[0]) && (10 != cnt_sbus) )//<2F><>Ϊ<EFBFBD><CEAA>10<31><30><EFBFBD>ֽ<EFBFBD>Ϊ0x0F<30><46><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD>0
{
receive = 0;
cnt_sbus = 0;
sbus_buff[cnt_sbus] = char_data[0];
cnt_sbus++;
state = 1;
if(0x0 == char_data[0])
{
cnt_sbus = 0;
receive = 0;
sbus_buff[cnt_sbus] = char_data[0];
state = 0;
parseSBusData(sbus_buff);
}
else
{
sbus_buff[cnt_sbus] = char_data[0];
for (i = 1; i < cnt_sbus; i++)
{
if (sbus_buff[i] == 0x0f)
{
start_index = i;
break;
}
}
/* we found a second start marker */
if (start_index != 0)
{
/* shift everything in the buffer and reset the state machine */
for (i = 0; i < cnt_sbus - start_index; i++) {
sbus_buff[i] = sbus_buff[i + start_index];
}
cnt_sbus -= start_index;
state = 1;
}
}
}
else
{