Browse Source

paint_robot_new v1.0【MK32串口接收调通】

master
Lizongdi 1 day ago
parent
commit
8a7c89d5ba
  1. 38
      RBcore/drv_interface.c
  2. 6
      bspMCU/bsp_uart.c
  3. 23
      project/paint_robot_new/paint_robot_new.c

38
RBcore/drv_interface.c

@ -227,15 +227,15 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
void Read_MK32(void *argument) void Read_MK32(void *argument)
{ {
char pcBuffer[52] = {0}; char pcBuffer[52] = {0};
char pcBuffer2[52] = {0}; //char pcBuffer2[52] = {0};
while(1) while(1)
{ {
__disable_irq(); //__disable_irq();
rd_ComRead(g_ptSbus, pcBuffer, 25); rd_ComRead(g_ptSbus, pcBuffer, 25);
rd_ComRead(g_ptlpuart, pcBuffer2, 25); //rd_ComRead(g_ptlpuart, pcBuffer2, 25);
__enable_irq(); //__enable_irq();
Rd_Delay(1); //Rd_Delay(1);
} }
} }
@ -250,9 +250,9 @@ void ground_manger_init(void);
void Drv_InterfaceInit(void) void Drv_InterfaceInit(void)
{ {
MsgCenter_Init(); MsgCenter_Init();
ground_manger_init(); // ground_manger_init();
MotorInit(); // MotorInit();
RBcore_Init(); // RBcore_Init();
TUartUserData *ptSbus = UART_userdata_init(5, -1, 512); TUartUserData *ptSbus = UART_userdata_init(5, -1, 512);
g_ptSbus = rd_ComCreate(check_MK32, decode_MK32, E28_SBUS_Send, ptSbus->m_buf_size, ptSbus); g_ptSbus = rd_ComCreate(check_MK32, decode_MK32, E28_SBUS_Send, ptSbus->m_buf_size, ptSbus);
@ -260,19 +260,19 @@ void Drv_InterfaceInit(void)
const osThreadAttr_t MK32_Task_attributes = { const osThreadAttr_t MK32_Task_attributes = {
.name = "Read_MK32", .name = "Read_MK32",
.stack_size = 512, .stack_size = 2048,
.priority = (osPriority_t) osPriorityHigh6, .priority = (osPriority_t) osPriorityHigh6,
}; };
(void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes); (void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes);
TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512); // TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512);
g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData); // g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData);
UART_IT_init(g_ptlpuart); // UART_IT_init(g_ptlpuart);
//
const osThreadAttr_t Send_PV_attributes = { // const osThreadAttr_t Send_PV_attributes = {
.name = "Send_PV", // .name = "Send_PV",
.stack_size = 512, // .stack_size = 1024,
.priority = (osPriority_t) osPriorityHigh4, // .priority = (osPriority_t) osPriorityHigh4,
}; // };
(void)osThreadNew(Send_PV, NULL, &Send_PV_attributes); // (void)osThreadNew(Send_PV, NULL, &Send_PV_attributes);
} }

6
bspMCU/bsp_uart.c

@ -121,7 +121,7 @@ void UART_DMA_RX_IRQHandler(TComCtrl *_ptComCtrl)
data_len = current_pos - ptUartUserData->m_last_dma_pos; data_len = current_pos - ptUartUserData->m_last_dma_pos;
if (data_len > 0) if (data_len > 0)
{ {
SCB_InvalidateDCache_by_Addr((uint32_t*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], data_len); //SCB_InvalidateDCache_by_Addr((uint32_t*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], data_len);
rd_ComRecvProc(_ptComCtrl, (const char*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], data_len); rd_ComRecvProc(_ptComCtrl, (const char*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], data_len);
} }
} }
@ -134,12 +134,12 @@ void UART_DMA_RX_IRQHandler(TComCtrl *_ptComCtrl)
if (part1 > 0) if (part1 > 0)
{ {
SCB_InvalidateDCache_by_Addr((uint32_t*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], part1); //SCB_InvalidateDCache_by_Addr((uint32_t*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], part1);
rd_ComRecvProc(_ptComCtrl, (const char*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], part1); rd_ComRecvProc(_ptComCtrl, (const char*)&ptUartUserData->m_dma_rx_buf[ptUartUserData->m_last_dma_pos], part1);
} }
if (part2 > 0) if (part2 > 0)
{ {
SCB_InvalidateDCache_by_Addr((uint32_t*)&ptUartUserData->m_dma_rx_buf[0], part2); //SCB_InvalidateDCache_by_Addr((uint32_t*)&ptUartUserData->m_dma_rx_buf[0], part2);
rd_ComRecvProc(_ptComCtrl, (const char*)&ptUartUserData->m_dma_rx_buf[0], part2); rd_ComRecvProc(_ptComCtrl, (const char*)&ptUartUserData->m_dma_rx_buf[0], part2);
} }
} }

23
project/paint_robot_new/paint_robot_new.c

@ -50,24 +50,16 @@ static int RB_Mode = 0; //0表示手动,1表示自动
int check_MK32(char *_pBuffer, uint32_t _iSize) int check_MK32(char *_pBuffer, uint32_t _iSize)
{ {
if (_pBuffer[0] != 0x0f) if (_iSize < 25) return 0; // 数据不足25字节,不读[24]不误判,等下一包
{ if (_pBuffer[0] != 0x0f) return -1;
return -1; if (_pBuffer[24] != 0x00) return -1;
}
if (_pBuffer[24] != 0x0f)
{
return -1;
}
else
{
return 25; return 25;
}
} }
void decode_MK32(const char *buf, uint32_t _iSize) void decode_MK32(const char *buf, uint32_t _iSize)
{ {
int16_t CH[16]; int16_t CH[16];
int Start_byte = -1; int Start_byte = 0;
CH[0] = ((buf[Start_byte + 1] | buf[Start_byte + 2] << 8) & 0x07FF); CH[0] = ((buf[Start_byte + 1] | buf[Start_byte + 2] << 8) & 0x07FF);
CH[1] = ((buf[Start_byte + 2] >> 3 | buf[Start_byte + 3] << 5) & 0x07FF); CH[1] = ((buf[Start_byte + 2] >> 3 | buf[Start_byte + 3] << 5) & 0x07FF);
@ -105,8 +97,8 @@ void decode_MK32(const char *buf, uint32_t _iSize)
*channel_ptrs[i] = (int32_t)((CH[i] - 992) * 1.388889); *channel_ptrs[i] = (int32_t)((CH[i] - 992) * 1.388889);
} }
// 【核心修改】:通过具体的成员名访问 IsOnline,替代原来的 RB_MK32[17] // buf[23] 才是在线标志字节,对应老工程 Sbus_Data_Count(&buffer[1]) 中的 buf[22]==buffer[23]
if (buf[22] == 0) if (buf[23] == 0)
{ {
RB_MK32.IsOnline = 1; RB_MK32.IsOnline = 1;
} }
@ -153,7 +145,6 @@ void decode_MK32(const char *buf, uint32_t _iSize)
MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0); MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0);
} }
} }
Rd_Delay(1);
} }
int check_PV(char *_pBuffer, uint32_t _iSize) int check_PV(char *_pBuffer, uint32_t _iSize)
@ -163,7 +154,7 @@ int check_PV(char *_pBuffer, uint32_t _iSize)
if (_pBuffer[1] != 0x55) return -1; if (_pBuffer[1] != 0x55) return -1;
uint16_t crc_check = ((_pBuffer[_iSize - 1] << 8) | _pBuffer[_iSize - 2]); uint16_t crc_check = ((_pBuffer[_iSize - 1] << 8) | _pBuffer[_iSize - 2]);
uint16_t crc_check1 = Rd_modbusCRC16(_pBuffer, _iSize - 2); uint16_t crc_check1 = Rd_modbusCRC16((uint8_t *)_pBuffer, _iSize - 2);
if (crc_check == crc_check1) if (crc_check == crc_check1)
{ {
return _iSize - 2; return _iSize - 2;

Loading…
Cancel
Save