diff --git a/CMakeLists.txt b/CMakeLists.txt index bef24da..3417205 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,7 @@ add_module(lua lua OFF ON) add_module(bspMCU bspMCU OFF OFF) add_module(RBcore RBcore OFF OFF) add_module(motor motor OFF OFF) -add_module(optional optional OFF OFF) +add_module(controller controller OFF OFF) add_module(Spoolend project/Spoolend OFF OFF) add_module(paint_robot_new project/paint_robot_new OFF OFF) add_module(Spoolold project_old/Spoolold OFF OFF) diff --git a/RBcore/drv_interface.c b/RBcore/drv_interface.c index dc86928..8d033b7 100644 --- a/RBcore/drv_interface.c +++ b/RBcore/drv_interface.c @@ -226,16 +226,6 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) } } -void Read_MK32(void *argument) -{ - char pcBuffer[52] = {0}; - - while(1) - { - rd_ComRead(g_ptSbus, pcBuffer, 25); - } -} - void Read_PV(void *argument) { char pcBuffer[64] = {0}; @@ -257,8 +247,6 @@ void Read_motor(void *argument) } extern void MotorTask(void *argument); -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); extern void ground_manger_init(void); @@ -266,6 +254,7 @@ extern void Custom_Task(void *argument); void SendIV_Init(void); void TL720D_Init(void); void RBcore_Init(void); +void controller_init(void); void Drv_InterfaceInit(void) { @@ -300,16 +289,7 @@ void Drv_InterfaceInit(void) RBcore_Init(); - 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 = 2048, - .priority = (osPriority_t) osPriorityRealtime1, - }; - (void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes); + controller_init(); TUartUserData *ptUartUserData = UART_userdata_init(0, -1, 512); g_ptlpuart = rd_ComCreate(check_PV, decode_PV, LPUART_PV_Send, ptUartUserData->m_buf_size, ptUartUserData); diff --git a/controller/CMakeLists.txt b/controller/CMakeLists.txt new file mode 100644 index 0000000..d904896 --- /dev/null +++ b/controller/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.10) + +get_filename_component(TARGET_NAME "${CMAKE_CURRENT_SOURCE_DIR}" NAME) +set(COMMON_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../library/CMakeLists.txt") + +if(EXISTS ${COMMON_CMAKE_PATH}) + include(${COMMON_CMAKE_PATH}) +else() + message(FATAL_ERROR "Cannot find common build logic at ${COMMON_CMAKE_PATH}") +endif() + +if(TARGET peripheral) + target_link_libraries(${TARGET_NAME} PUBLIC peripheral) +else() + message(FATAL_ERROR "[${TARGET_NAME}] Dependency 'peripheral' not found.") +endif() + +if(TARGET RBcore) + target_link_libraries(${TARGET_NAME} PUBLIC RBcore) +else() + message(FATAL_ERROR "[${TARGET_NAME}] Dependency 'RBcore' not found.") +endif() \ No newline at end of file diff --git a/controller/msp_MK32.c b/controller/msp_MK32.c new file mode 100644 index 0000000..3a8c7d2 --- /dev/null +++ b/controller/msp_MK32.c @@ -0,0 +1,144 @@ +/****************************************************************************** + + 版权所有 (C), 2018-2099, Radkil + + ****************************************************************************** + 文 件 名 : msp_MK32.c + 版 本 号 : 初稿 + 作 者 : radkil + 生成日期 : 2026年9月10日 + 最近修改 : + 功能描述 : MK32驱动文件 + + 修改历史 : + 1.日 期 : 2026年9月10日 + 作 者 : radkil + 修改内容 : 创建文件 + +******************************************************************************/ +#include "BHBF.h" +#include "msg_center.h" +#include "msp_MK32.pb.h" +#include "rd_time.h" + +/*----------------------------------------------* + * 外部变量说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 外部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 内部函数原型说明 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 全局变量 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 模块级变量 * + *----------------------------------------------*/ +static SP_MSP_MK32_Button RB_MK32; +/*----------------------------------------------* + * 常量定义 * + *----------------------------------------------*/ + +/*----------------------------------------------* + * 宏定义 * + *----------------------------------------------*/ + +int check_MK32(char *_pBuffer, uint32_t _iSize) +{ + if (_iSize < 25) + return 0; // 数据不足25字节,不读[24]不误判,等下一包 + if (_pBuffer[0] != 0x0f) + return -1; + if (_pBuffer[24] != 0x00) + return -1; + return 25; +} + +void decode_MK32(const char *buf, uint32_t _iSize) +{ + static uint32_t uiLastSendTick = 0; + + int32_t CH[16]; + int Start_byte = 0; + + 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[2] = ((buf[Start_byte + 3] >> 6 | buf[Start_byte + 4] << 2 | + buf[Start_byte + 5] << 10) & + 0x07FF); + CH[3] = ((buf[Start_byte + 5] >> 1 | buf[Start_byte + 6] << 7) & 0x07FF); + CH[4] = ((buf[Start_byte + 6] >> 4 | buf[Start_byte + 7] << 4) & 0x07FF); + CH[5] = ((buf[Start_byte + 7] >> 7 | buf[Start_byte + 8] << 1 | + buf[Start_byte + 9] << 9) & + 0x07FF); + CH[6] = ((buf[Start_byte + 9] >> 2 | buf[Start_byte + 10] << 6) & 0x07FF); + CH[7] = ((buf[Start_byte + 10] >> 5 | buf[Start_byte + 11] << 3) & 0x07FF); + CH[8] = ((buf[Start_byte + 12] | buf[Start_byte + 13] << 8) & 0x07FF); + CH[9] = ((buf[Start_byte + 13] >> 3 | buf[Start_byte + 14] << 5) & 0x07FF); + CH[10] = ((buf[Start_byte + 14] >> 6 | buf[Start_byte + 15] << 2 | + buf[Start_byte + 16] << 10) & + 0x07FF); + CH[11] = ((buf[Start_byte + 16] >> 1 | buf[Start_byte + 17] << 7) & 0x07FF); + CH[12] = ((buf[Start_byte + 17] >> 4 | buf[Start_byte + 18] << 4) & 0x07FF); + CH[13] = ((buf[Start_byte + 18] >> 7 | buf[Start_byte + 19] << 1 | + buf[Start_byte + 20] << 9) & + 0x07FF); + CH[14] = ((buf[Start_byte + 20] >> 2 | buf[Start_byte + 21] << 6) & 0x07FF); + CH[15] = ((buf[Start_byte + 21] >> 5 | buf[Start_byte + 22] << 3) & 0x07FF); + + // 按键数值转换:1050为中间值,272-1712 + for (int i = 0; i < 16; i++) + { + CH[i] = (int32_t)((CH[i] - 992) * 1.388889); + } + + RD_MEMCPY(&(RB_MK32.CH0_RY_H), CH, sizeof(CH)); + + if (buf[23] == 0) + { + RB_MK32.IsOnline = 1; + } + else + { + RB_MK32.IsOnline = 0; + } + RB_MK32.RxIndex++; + + uint32_t uiNowTick = Rd_GetTime(); + if ((int32_t)(uiNowTick - uiLastSendTick) >= 50) + { + uiLastSendTick = uiNowTick; + MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_GET_MK32, (void *)&RB_MK32, + sizeof(RB_MK32)); + } +} + +void Read_MK32(void *argument) +{ + char pcBuffer[52] = {0}; + + while (1) + { + rd_ComRead(g_ptSbus, pcBuffer, 25); + } +} + +void controller_init(void) +{ + 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 = 2048, + .priority = (osPriority_t) osPriorityRealtime1, + }; + (void)osThreadNew(Read_MK32, NULL, &MK32_Task_attributes); +} \ No newline at end of file diff --git a/project/paint_robot_new/paint_robot_new_MK32.c b/project/paint_robot_new/paint_robot_new_MK32.c deleted file mode 100644 index 8c49958..0000000 --- a/project/paint_robot_new/paint_robot_new_MK32.c +++ /dev/null @@ -1,113 +0,0 @@ -/****************************************************************************** - - 版权所有 (C), 2018-2099, Radkil - - ****************************************************************************** - 文 件 名 : paint_robot_new_MK32.c - 版 本 号 : 初稿 - 作 者 : radkil - 生成日期 : 2026年8月21日 - 最近修改 : - 功能描述 : 新喷涂机器人遥控器逻辑 - - 修改历史 : - 1.日 期 : 2026年8月21日 - 作 者 : radkil - 修改内容 : 创建文件 - -******************************************************************************/ -#include "BHBF.h" -#include "Protobuf/PSource/msp_MK32.pb.h" -#include "msg_center.h" -#include "rd_time.h" - -/*----------------------------------------------* - * 外部变量说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 外部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 内部函数原型说明 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 全局变量 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 模块级变量 * - *----------------------------------------------*/ -static SP_MSP_MK32_Button RB_MK32; - -/*----------------------------------------------* - * 常量定义 * - *----------------------------------------------*/ - -/*----------------------------------------------* - * 宏定义 * - *----------------------------------------------*/ - -int check_MK32(char *_pBuffer, uint32_t _iSize) -{ - if (_iSize < 25) return 0; // 数据不足25字节,不读[24]不误判,等下一包 - if (_pBuffer[0] != 0x0f) return -1; - if (_pBuffer[24] != 0x00) return -1; - return 25; -} - -void decode_MK32(const char *buf, uint32_t _iSize) -{ - static uint32_t uiLastSendTick = 0; - - int32_t CH[16]; - int Start_byte = 0; - - 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[2] = ((buf[Start_byte + 3] >> 6 | buf[Start_byte + 4] << 2 - | buf[Start_byte + 5] << 10) & 0x07FF); - CH[3] = ((buf[Start_byte + 5] >> 1 | buf[Start_byte + 6] << 7) & 0x07FF); - CH[4] = ((buf[Start_byte + 6] >> 4 | buf[Start_byte + 7] << 4) & 0x07FF); - CH[5] = ((buf[Start_byte + 7] >> 7 | buf[Start_byte + 8] << 1 - | buf[Start_byte + 9] << 9) & 0x07FF); - CH[6] = ((buf[Start_byte + 9] >> 2 | buf[Start_byte + 10] << 6) & 0x07FF); - CH[7] = ((buf[Start_byte + 10] >> 5 | buf[Start_byte + 11] << 3) & 0x07FF); - CH[8] = ((buf[Start_byte + 12] | buf[Start_byte + 13] << 8) & 0x07FF); - CH[9] = ((buf[Start_byte + 13] >> 3 | buf[Start_byte + 14] << 5) & 0x07FF); - CH[10] = ((buf[Start_byte + 14] >> 6 | buf[Start_byte + 15] << 2 - | buf[Start_byte + 16] << 10) & 0x07FF); - CH[11] = ((buf[Start_byte + 16] >> 1 | buf[Start_byte + 17] << 7) & 0x07FF); - CH[12] = ((buf[Start_byte + 17] >> 4 | buf[Start_byte + 18] << 4) & 0x07FF); - CH[13] = ((buf[Start_byte + 18] >> 7 | buf[Start_byte + 19] << 1 - | buf[Start_byte + 20] << 9) & 0x07FF); - CH[14] = ((buf[Start_byte + 20] >> 2 | buf[Start_byte + 21] << 6) & 0x07FF); - CH[15] = ((buf[Start_byte + 21] >> 5 | buf[Start_byte + 22] << 3) & 0x07FF); - - // 按键数值转换:1050为中间值,272-1712 - for (int i = 0; i < 16; i++) - { - CH[i] = (int32_t)((CH[i] - 992) * 1.388889); - } - - RD_MEMCPY(&(RB_MK32.CH0_RY_H), CH, sizeof(CH)); - - if (buf[23] == 0) - { - RB_MK32.IsOnline = 1; - } - else - { - RB_MK32.IsOnline = 0; - } - RB_MK32.RxIndex++; - - uint32_t uiNowTick = Rd_GetTime(); - if ((int32_t)(uiNowTick - uiLastSendTick) >= 50) - { - uiLastSendTick = uiNowTick; - MsgCenter_SendTo(MODULE_NAME_CUSTOM, CUSTOM_GET_MK32, (void *)&RB_MK32, sizeof(RB_MK32)); - } -}