diff --git a/RBcore/drv_interface.c b/RBcore/drv_interface.c index 8c29a06..2cf970b 100644 --- a/RBcore/drv_interface.c +++ b/RBcore/drv_interface.c @@ -227,15 +227,21 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) 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); + } +} + +void Read_PV(void *argument) +{ + char pcBuffer[64] = {0}; + + while(1) + { + rd_ComRead(g_ptlpuart, pcBuffer, 64); + Rd_Delay(10); } } @@ -265,9 +271,16 @@ void Drv_InterfaceInit(void) }; (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); + 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 Read_PV_attributes = { + .name = "Read_PV", + .stack_size = 2048, + .priority = (osPriority_t) osPriorityHigh6, + }; + (void)osThreadNew(Read_PV, NULL, &Read_PV_attributes); // // const osThreadAttr_t Send_PV_attributes = { // .name = "Send_PV", diff --git a/RBcore/include/drv_interface.h b/RBcore/include/drv_interface.h index 5355109..99c3d3b 100644 --- a/RBcore/include/drv_interface.h +++ b/RBcore/include/drv_interface.h @@ -82,10 +82,10 @@ extern TComCtrl *g_ptrs485_4; extern TComCtrl *g_ptlte_7S0; extern TComCtrl *g_ptSbus; extern TComCtrl *g_ptInterCall; +extern TComCtrl *g_ptlpuart; extern TComCtrl *g_ptCAN1; extern TComCtrl *g_ptCAN2; - /*==============================================* * routines' or functions' implementations * *----------------------------------------------*/ diff --git a/project/paint_robot_new/paint_robot_new.c b/project/paint_robot_new/paint_robot_new.c index 12e43a5..3d23b95 100644 --- a/project/paint_robot_new/paint_robot_new.c +++ b/project/paint_robot_new/paint_robot_new.c @@ -18,6 +18,9 @@ ******************************************************************************/ #include "paint_robot_new.h" #include "BHBF.h" +#include "pb.h" +#include "pb_decode.h" +#include "../Protobuf/PSource/bsp_PV.pb.h" /*----------------------------------------------* * 外部变量说明 * @@ -31,10 +34,12 @@ * 内部函数原型说明 * *----------------------------------------------*/ static MSP_MK32_Button RB_MK32; -static int RB_Mode = 0; //0表示手动,1表示自动 + /*----------------------------------------------* * 全局变量 * *----------------------------------------------*/ +PV_struct_define decoded_PV_variable = { 0 }; +PV_struct_define decoded_PV = { 0 }; /*----------------------------------------------* * 模块级变量 * @@ -159,9 +164,32 @@ int check_PV(char *_pBuffer, uint32_t _iSize) } } -void decode_PV(const char *buf, uint32_t _iSize) +void decode_PV(const char *_pBuffer, uint32_t _iSize) { - RB_Mode = 0; + if (_pBuffer[2] == 0x01 && _pBuffer[3] == 0x01) //01 01 设置PV + { + pb_istream_t i_pv_stream; + + i_pv_stream = pb_istream_from_buffer((const pb_byte_t *)&_pBuffer[4], _iSize - 6); + pb_decode(&i_pv_stream, PV_struct_define_fields, &decoded_PV_variable); + + if(decoded_PV_variable.TimeStamp>decoded_PV.TimeStamp) + { + decoded_PV=decoded_PV_variable; + } + } + else if (*(_pBuffer + 2) == 0x02 && *(_pBuffer + 3) == 0x01) //设置PV + { + + } + else if (*(_pBuffer + 2) == 0x03 && *(_pBuffer + 3) == 0x01) //返回IV + { + + } + else + { + + } // Motor_CmdData_t tMotor_CmdData_t = {0}; // tMotor_CmdData_t.m_ucMotorIndex = 1; // tMotor_CmdData_t.m_iValue = 10;