diff --git a/RBcore/drv_interface.c b/RBcore/drv_interface.c index 1084de2..d19caf8 100644 --- a/RBcore/drv_interface.c +++ b/RBcore/drv_interface.c @@ -44,6 +44,7 @@ TComCtrl *g_ptrs485_4; TComCtrl *g_ptlte_7S0; TComCtrl *g_ptSbus; TComCtrl *g_ptInterCall; +TComCtrl *g_ptlpuart; TComCtrl *g_ptCAN1; TComCtrl *g_ptCAN2; @@ -116,6 +117,13 @@ int RS485_4_Send(char *_pBuffer, uint32_t _iSize) return iRet; } +int LPUART_PV_Send(char *_pBuffer, uint32_t _iSize) +{ + TUartUserData *ptUartUserData = (TUartUserData *)g_ptlpuart->m_pUserData; + int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100); + return iRet; +} + int FDCAN1_Send(char *_pBuffer, uint32_t _iSize) { return CAN_TX_FIFOQ(g_ptCAN1, _pBuffer, _iSize); @@ -161,6 +169,10 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { UART_RX_IRQHandler(g_ptrs485_4); } + else if (huart->Instance == LPUART1) + { + UART_RX_IRQHandler(g_ptlpuart); + } } #endif @@ -212,33 +224,55 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) } } -void Read_Sbus(void *argument) +void Read_MK32(void *argument) { char pcBuffer[52] = {0}; + char pcBuffer2[52] = {0}; while(1) { __disable_irq(); rd_ComRead(g_ptSbus, pcBuffer, 25); + rd_ComRead(g_ptlpuart, pcBuffer2, 25); __enable_irq(); Rd_Delay(1); } } extern void MotorInit(void); -extern void Mlogic_Init(void); +extern int check_MK32(char *_pBuffer, uint32_t _iSize); +extern void decode_MK32(const char *buf, uint32_t _iSize); +extern int check_PV(char *_pBuffer, uint32_t _iSize); +extern void decode_PV(const char *buf, uint32_t _iSize); +void Send_PV(void *argument); +void ground_manger_init(void); void Drv_InterfaceInit(void) { MsgCenter_Init(); + ground_manger_init(); MotorInit(); RBcore_Init(); - Mlogic_Init(); - const osThreadAttr_t Read_Sbus_attributes = { - .name = "Sbus", + TUartUserData *ptSbus = UART_userdata_init(5, -1, 512); + g_ptSbus = rd_ComCreate(check_MK32, decode_MK32, E28_SBUS_Send, ptSbus->m_buf_size, ptSbus); + UART_IT_init(g_ptSbus); + + const osThreadAttr_t MK32_Task_attributes = { + .name = "Read_MK32", .stack_size = 512, .priority = (osPriority_t) osPriorityHigh6, }; - (void)osThreadNew(Read_Sbus, NULL, &Read_Sbus_attributes); + (void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes); + + TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512); + g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData); + UART_IT_init(g_ptlpuart); + + const osThreadAttr_t Send_PV_attributes = { + .name = "Send_PV", + .stack_size = 512, + .priority = (osPriority_t) osPriorityHigh4, + }; + (void)osThreadNew(Send_PV, NULL, &Send_PV_attributes); } diff --git a/RBcore/ground_manger.c b/RBcore/ground_manger.c new file mode 100644 index 0000000..d582f9b --- /dev/null +++ b/RBcore/ground_manger.c @@ -0,0 +1,70 @@ +/****************************************************************************** + + 版权所有 (C), 2018-2099, Radkil + + ****************************************************************************** + 文 件 名 : ground_manger.c + 版 本 号 : 初稿 + 作 者 : radkil + 生成日期 : 2026年8月17日 + 最近修改 : + 功能描述 : 地面端心跳包控制 + + 修改历史 : + 1.日 期 : 2026年8月17日 + 作 者 : radkil + 修改内容 : 创建文件 + +******************************************************************************/ +#include "BHBF.h" + +/*----------------------------------------------* + * 外部变量说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 外部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 内部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 全局变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 模块级变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 常量定义 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 宏定义 * + *----------------------------------------------*/ + +void Send_ground(void *argument) +{ + while(1) + { + + Rd_Delay(1); + } +} + +void ground_manger_init(void) +{ + TUartUserData *ptUartUserData = UART_userdata_init(7, -1, 512); + g_ptrs485_4 = rd_ComCreate(NULL, NULL, RS485_4_Send, ptUartUserData->m_buf_size, ptUartUserData); + UART_IT_init(g_ptrs485_4); + + const osThreadAttr_t Send_ground_attributes = { + .name = "Send_ground", + .stack_size = 512, + .priority = (osPriority_t) osPriorityRealtime2, + }; + (void)osThreadNew(Send_ground, NULL, &Send_ground_attributes); +} diff --git a/project/paint_robot_new/paint_robot_new.c b/project/paint_robot_new/paint_robot_new.c index 5df1f91..c108cea 100644 --- a/project/paint_robot_new/paint_robot_new.c +++ b/project/paint_robot_new/paint_robot_new.c @@ -31,6 +31,7 @@ * 内部函数原型说明 * *----------------------------------------------*/ static MSP_MK32_Button RB_MK32; +static int RB_Mode = 0; //0表示手动,1表示自动 /*----------------------------------------------* * 全局变量 * *----------------------------------------------*/ @@ -47,7 +48,7 @@ static MSP_MK32_Button RB_MK32; * 宏定义 * *----------------------------------------------*/ -static int check_MK32Data(char *_pBuffer, uint32_t _iSize) +int check_MK32(char *_pBuffer, uint32_t _iSize) { if (_pBuffer[0] != 0x0f) { @@ -63,7 +64,7 @@ static int check_MK32Data(char *_pBuffer, uint32_t _iSize) } } -static void decode_MK32Data(const char *buf, uint32_t _iSize) +void decode_MK32(const char *buf, uint32_t _iSize) { int16_t CH[16]; int Start_byte = -1; @@ -114,66 +115,79 @@ static void decode_MK32Data(const char *buf, uint32_t _iSize) RB_MK32.IsOnline = 0; } RB_MK32.RxIndex++; -} -void MK32_Init(void) -{ - TUartUserData *ptUartUserData = UART_userdata_init(5, 115200, 512); - g_ptSbus = rd_ComCreate(check_MK32Data, decode_MK32Data, E28_SBUS_Send, ptUartUserData->m_buf_size, ptUartUserData); - UART_IT_init(g_ptSbus); -} - -void MK32_Task(void *argument) -{ - while(1) - { - int angle; - angle = atan2(RB_MK32.CH1_RY_V, RB_MK32.CH0_RY_H) * 180 / M_PI; + int angle; + angle = atan2(RB_MK32.CH1_RY_V, RB_MK32.CH0_RY_H) * 180 / M_PI; - if(RB_MK32.CH5_SB == 0) + if(RB_MK32.CH5_SB == 0) + { + // 前进 + if((angle >= 45) && (angle <= 135)) + { + MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0); + } + // 后退 + else if((angle >= -135) && (angle < -45)) { - // 前进 - if((angle >= 45) && (angle <= 135)) - { - MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0); - } - // 后退 - else if((angle >= -135) && (angle < -45)) - { - MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0); - } - else - { - MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0); - } + MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0); } else { - // 前进 - if((angle >= 45) && (angle <= 135)) - { - MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0); - } - // 后退 - else if((angle >= -135) && (angle < -45)) - { - MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0); - } - else - { - 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); + } + else + { + // 前进 + if((angle >= 45) && (angle <= 135)) + { + MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_FORWARD, NULL, 0); + } + // 后退 + else if((angle >= -135) && (angle < -45)) + { + MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_MANUAL_BACKWARD, NULL, 0); + } + else + { + MsgCenter_SendTo(MODULE_NAME_RBCORE, RBCORE_CMD_STOP_ALL, NULL, 0); + } + } + Rd_Delay(1); +} + +int check_PV(char *_pBuffer, uint32_t _iSize) +{ + if (_iSize < 4) return -1; + if (_pBuffer[0] != 0x55) return -1; + if (_pBuffer[1] != 0x55) return -1; + + uint16_t crc_check = ((_pBuffer[_iSize - 1] << 8) | _pBuffer[_iSize - 2]); + uint16_t crc_check1 = Rd_modbusCRC16(_pBuffer, _iSize - 2); + if (crc_check == crc_check1) + { + return _iSize - 2; + } + else + { + return -1; } } -void Mlogic_Init(void) +void decode_PV(const char *buf, uint32_t _iSize) +{ + RB_Mode = 0; +// Motor_CmdData_t tMotor_CmdData_t = {0}; +// tMotor_CmdData_t.m_ucMotorIndex = 1; +// tMotor_CmdData_t.m_iValue = 10; +// MsgCenter_SendTo(MODULE_NAME_MOTOR, MOTOR_CMD_SET_SPEED, (void *)&tMotor_CmdData_t, sizeof(Motor_CmdData_t)); +} + +void Send_PV(void *argument) { - const osThreadAttr_t logic_attributes = { - .name = "main_logic", - .stack_size = 1024, - .priority = (osPriority_t) osPriorityRealtime2, - }; - (void)osThreadNew(MK32_Task, NULL, &logic_attributes); + while(1) + { + + Rd_Delay(1); + } }