/* * msp_T_F4.c * * Created on: Jun 18, 2025 * Author: akeguo */ #include "msp_T_F4.h" #include "BHBF_ROBOT.h" #include "string.h" char Is_T_F4_All_Button_Reset = 0; void read_T_F4_Data(void); void Write_T_F4_Data(void); void decode_T_F4(uint8_t *buffer, uint16_t length); DispacherController *T_F4_dispacherController; T_F4_Value Current_T_F4_Value; T_F4_Value_2 Current_T_F4_Value_2; struct UARTHandler *T_F4_Remote_Controller_UART_Handler; void T_F4_Remote_Controller_intialize(struct UARTHandler *Handler) { T_F4_Remote_Controller_UART_Handler = Handler; T_F4_Remote_Controller_UART_Handler->Wait_time = 20; //等待10ms 最低不要低于4; T_F4_dispacherController = Handler->dispacherController; T_F4_dispacherController->DispacherCallTime = 200; T_F4_dispacherController->Dispacher_Enable = 1; T_F4_dispacherController->Add_Dispatcher_List(T_F4_dispacherController, read_T_F4_Data); T_F4_dispacherController->Add_Dispatcher_List(T_F4_dispacherController, Write_T_F4_Data); // HardWareErrorController->Add_PCOMHardWare(HardWareErrorController, // "T_F4_Remote", 0, ComError_T_F4_Remote); LOG(DL_ERROR, "angle encoder decoding failed"); } uint8_t Write_T_F4[10]; uint16_t Data[5]; uint8_t Flag; void read_T_F4_Data(void) { LOGFF(DL_ERROR, "read data from DeChi"); T_F4_Remote_Controller_UART_Handler->UART_Decode = decode_T_F4; MB_ReadInputReg(&T_F4_Remote_Controller_UART_Handler->Tx_Buf, &T_F4_Remote_Controller_UART_Handler->TxCount, 1, 0, 6); //addr 3 reg 0 读取6 个 T_F4_Remote_Controller_UART_Handler->UART_Tx( T_F4_Remote_Controller_UART_Handler); } void Write_T_F4_Data(void) { Data[0] = GV.Left_Compensation * 100; Data[1] = GV.Right_Compensation * 100; Data[2] = abs(GV.Robot_Angle.RF_Angle_Roll); Data[3] = GV.Robot_Speed_mpm * 100; Data[4] = abs(GV.Robot_PaintThickness); for (int i = 0; i < 5; i++) { Write_T_F4[2*i] = ((Data[i] / 256));//高位 Write_T_F4[2*i+1] = ((Data[i] % 256));//低维 } T_F4_Remote_Controller_UART_Handler->UART_Decode = NULL; MB_WriteNumHoldingReg(&T_F4_Remote_Controller_UART_Handler->Tx_Buf, &T_F4_Remote_Controller_UART_Handler->TxCount, 1, 5, 5, &Write_T_F4); T_F4_Remote_Controller_UART_Handler->UART_Tx( T_F4_Remote_Controller_UART_Handler); } uint16_t Decoded_Reg_Value[6]; void decode_T_F4(uint8_t *buffer, uint16_t length) { uint16_t crc_check = ((buffer[length - 1] << 8) | buffer[length - 2]); /* CRC 校验正确 */ if (buffer[0] == 0x01 && buffer[1] == 0x04 && crc_check == MB_CRC16(buffer, length - 2)) { memcpy(&Current_T_F4_Value, &buffer[3], 6 * 2); HardWareErrorController->Set_PCOMHardWare(HardWareErrorController, "T_F4_Remote", 1); } else { LOGFF(DL_ERROR, "DeChi decoding failed"); } }