diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index d1d79c6..2ca51c0 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/BASE/Inc/BSP/bsp_UDP.h b/BASE/Inc/BSP/bsp_UDP.h index d982b4e..860d54f 100644 --- a/BASE/Inc/BSP/bsp_UDP.h +++ b/BASE/Inc/BSP/bsp_UDP.h @@ -8,10 +8,17 @@ #ifndef INC_BSP_BSP_UDP_H_ #define INC_BSP_BSP_UDP_H_ +#include "lwip/udp.h" +extern void udp_client_init(void); + + +extern void udp_dlt_send_back(char *pData,uint16_t Size); +extern void udp_cmd_send_back(char *pData, uint16_t Size); + +typedef void (*DLT_DecodeFuncPtr)(uint8_t*, uint16_t); +extern void udp_send_by_pcb(struct udp_pcb * upcb,char *pData, uint16_t Size); +// 再用该类型声明变量 +extern DLT_DecodeFuncPtr UDP_DLT_ReceivedCallback; +extern int8_t is_udp_GV_update_loop_enalbed; -void udp_printf_CmdBack(char *pData); -void udp_client_init(void); -void GF_UDP_Send(uint8_t *pData,uint16_t Size,uint16_t UDP_port); -void GF_UDP_long_Send_Server(void); -void GF_UpdataPos_Send(uint8_t *pData,uint32_t Size); #endif /* INC_BSP_BSP_UDP_H_ */ diff --git a/BASE/Inc/MSP/msp_485_android.h b/BASE/Inc/MSP/msp_485_android.h index 5b4662b..f861179 100644 --- a/BASE/Inc/MSP/msp_485_android.h +++ b/BASE/Inc/MSP/msp_485_android.h @@ -13,10 +13,10 @@ - +extern int isOnLineCount; extern int16_t read_android_holidng_register_count; -void android_485_intialize_with_slaveID(struct UARTHandler *Handler, +extern void android_485_intialize_with_slaveID(struct UARTHandler *Handler, int slave_id); -void android_485_intialize(struct UARTHandler *Handler); +extern void android_485_intialize(struct UARTHandler *Handler); #endif /* BASE_INC_MSP_MSP_485_ANDROID_H_ */ diff --git a/BASE/Inc/MSP/msp_U7.h b/BASE/Inc/MSP/msp_U7.h index dbfbd15..6295de4 100644 --- a/BASE/Inc/MSP/msp_U7.h +++ b/BASE/Inc/MSP/msp_U7.h @@ -12,7 +12,7 @@ void Sbus_Data_Count_U7(uint8_t *buf, int32_t *But_Value); extern SP_MSP_U7_Button *P_U7; void Robot_ResetCheck_Loop(void); - +extern uint8_t IsRemoteAtInitialPosition(void); // extern void U7_Sbus_UART_Handler_intialize(struct UARTHandler* Handler); uint8_t IsRemoteAtInitialPosition(void); diff --git a/BASE/Src/BSP/bsp_UART.c b/BASE/Src/BSP/bsp_UART.c index 8479587..d840a4b 100644 --- a/BASE/Src/BSP/bsp_UART.c +++ b/BASE/Src/BSP/bsp_UART.c @@ -1,7 +1,7 @@ #include "bsp_UART.h" #include "main.h" #include -#include "DLT/DLTuc.h" +#include "DLTuc.h" void GF_UART_Send_List_Send(struct UARTHandler *handler); void Dispatcher_List_Add(struct UARTHandler *uartHandler, diff --git a/BASE/Src/BSP/bsp_UDP.c b/BASE/Src/BSP/bsp_UDP.c index 4695a0d..024ab50 100644 --- a/BASE/Src/BSP/bsp_UDP.c +++ b/BASE/Src/BSP/bsp_UDP.c @@ -10,72 +10,168 @@ #include "udp.h" #include "string.h" #include "bsp_UDP.h" - +#include "bsp_DLT_Log.h" +#include +#include "bsp_GPIO.h" +void UDP_GV_Dispatch(); +void UDP_IV_Dispatch(); +void udp_cmd_send_GV(char *pData, uint16_t Size); /* 定义端口号 */ -#define UDP_REMOTE_PORT 8881 /* 远端端口 */ -#define UDP_LOCAL_PORT 8880 /* 本地端口 */ -#define UDP_Send_LOCAL_PORT 9880 /* 本地端口 */ +#define UDP_DLT_LOCAL_PORT 8000 /* 本地端口 */ +#define UDP_CMD_LOCAL_PORT 8002 /* 本地端口 */ +#define UDP_CMD_LOCAL_Android_Listen_PORT 8006 /* 本地端口 接收安卓 */ + +#define UDP_DLT_Send_LOCAL_PORT 7000 /* 本地端口 */ +#define UDP_CMD_Send_LOCAL_PORT 7002 /* 本地端口 */ +#define UDP_GV_Send_LOCAL_PORT 7004 /* 本地端口 */ +#define UDP_Android_Send_LOCAL_PORT 7006 /* 本地端口 发给安卓*/ +/*32从7006发往安卓9006*/ +/*安卓从9006发往32的8006*/ +#define UDP_REMOTE_DLT_PORT 9000 /* 远端端口 */ +#define UDP_REMOTE_CMD_PORT 9002 /* 远端端口 */ +#define UDP_REMOTE_GV_PORT 9004 /* 远端端口 */ +#define UDP_REMOTE_Android_PORT 9006 /* 远端端口 */ -#define UDP_Printf_PORT 8881 -#define UDP_Long_PORT 8882 -#define UDP_UpdataPos_PORT 8883 +int8_t is_udp_GV_update_loop_enalbed = 0; unsigned char received_data[1000]; /* udp控制块 */ -static struct udp_pcb *upcb; -static struct udp_pcb *upcb_send; +static struct udp_pcb *upcb_Rx_DLT; +static struct udp_pcb *upcb_Rx_Cmd; +static struct udp_pcb *upcb_Rx_From_Android; + +static struct udp_pcb *upcb_Tx_DLT; +static struct udp_pcb *upcb_Tx_Cmd; +static struct udp_pcb *upcb_Tx_GV; +static struct udp_pcb *upcb_Tx_Android; + ip_addr_t serverIP; + +ip_addr_t Android_ServerIP; + +DLT_DecodeFuncPtr UDP_DLT_ReceivedCallback; + /****************************************************************************** * 描述 : 接收回调函数 * 参数 : - * 返回 : 无 ******************************************************************************/ static void udp_receive_callback(void *arg, struct udp_pcb *upcb, - struct pbuf *p, const ip_addr_t *addr, u16_t port) + struct pbuf *p, const ip_addr_t *addr, u16_t port) { + if (p == NULL) return; + memcpy(received_data, p->payload, p->len); - if (p != NULL) + if (upcb->local_port == UDP_DLT_LOCAL_PORT) { - memcpy(received_data, p->payload, p->len); - //err_t t = udp_sendto(upcb_send, p, &serverIP, 8000); - pbuf_free(p); - } else + UDP_DLT_ReceivedCallback(received_data, p->len); + //DLT_DataReceiveEndCallback(received_data, p->len); + } + else if (upcb->local_port == UDP_CMD_LOCAL_PORT) { - pbuf_free(p); + + if (*received_data == 0x55 && *(received_data + 1) == 0x55 + && p->len >= 3) + { + decode_command_and_feedback(received_data + 2, p->len - 2, 2, + NULL); //0代表UDP + } + else if (*received_data == 0x66 && *(received_data + 1) == 0x66 + && p->len >= 3) + { + GF_BSP_GPIO_SetIO(received_data[3], received_data[2]); + + } + else + { + udp_cmd_send_back(received_data, p->len); + } } + else if (upcb->local_port == UDP_CMD_LOCAL_Android_Listen_PORT) + { + //对PV数据进行修改 + //if (*buffer == 0x55 && *(buffer + 1) == 0x55 && length >= 4) + if (received_data[0] != 0x55 || received_data[1] != 0x55 || p->len < 4) + { + return; + } + + uint16_t crc_check = ((received_data[p->len - 1] << 8) + | received_data[p->len - 2]); + uint16_t crc_check1 = MB_CRC16(received_data, p->len - 2); + /* CRC 校验正确 */ + if (crc_check != MB_CRC16(received_data, p->len - 2)) return; + + if (received_data[2] != 0x01 || received_data[3] != 0x01) return; + + pb_istream_t i_pv_stream = + { 0 }; + + i_pv_stream = pb_istream_from_buffer(&received_data[4], p->len - 4); + pb_decode(&i_pv_stream, PV_struct_define_fields, &_decoded_PV_temp); + if (_decoded_PV_temp.TimeStamp > decoded_PV.TimeStamp) + { + decoded_PV = _decoded_PV_temp; + } + + } + pbuf_free(p); } //char UDPprintf[100]; -void udp_printf_CmdBack(char *pData) +void udp_dlt_send_back(char *pData, uint16_t Size) { struct pbuf *p; /* 分配缓冲区空间 */ - p = pbuf_alloc(PBUF_TRANSPORT, strlen(pData), PBUF_POOL); - + p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); if (p != NULL) { /* 填充缓冲区数据 */ - pbuf_take(p, pData, strlen(pData)); + pbuf_take(p, pData, Size); /* 发送udp数据 */ - udp_send(upcb, p); - //err_t t = udp_sendto(upcb, p, &serverIP, UDP_Printf_PORT); + //udp_send(upcb_DLT, p); + err_t t = udp_sendto(upcb_Tx_DLT, p, &serverIP, + UDP_REMOTE_DLT_PORT); + /* 释放缓冲区空间 */ + pbuf_free(p); + } +} +void udp_cmd_send_back(char *pData, uint16_t Size) +{ + struct pbuf *p; + + /* 分配缓冲区空间 */ + p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); + + if (p != NULL) + { + /* 填充缓冲区数据 */ + pbuf_take(p, pData, Size); + + /* 发送udp数据 */ + err_t err = udp_send(upcb_Tx_Cmd, p); + if (err != ERR_OK) + { + // 发送失败 + printf("Failed to send UDP data: %d\n", err); + } /* 释放缓冲区空间 */ pbuf_free(p); } } -void GF_UDP_Send(uint8_t *pData, uint16_t Size, uint16_t UDP_port) +void udp_cmd_send_GV(char *pData, uint16_t Size) { struct pbuf *p; /* 分配缓冲区空间 */ - p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_POOL); + p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); if (p != NULL) { @@ -83,16 +179,39 @@ void GF_UDP_Send(uint8_t *pData, uint16_t Size, uint16_t UDP_port) pbuf_take(p, pData, Size); /* 发送udp数据 */ - //udp_send(upcb, p); - err_t t = udp_sendto(upcb, p, &serverIP, UDP_port); + err_t err = udp_send(upcb_Tx_GV, p); + if (err != ERR_OK) + { + // 发送失败 + //printf("Failed to send UDP data: %d\n", err); + } /* 释放缓冲区空间 */ pbuf_free(p); } } -void GF_UpdataPos_Send(uint8_t *pData, uint32_t Size) +void udp_send_by_pcb(struct udp_pcb *upcb, char *pData, uint16_t Size) { - GF_UDP_Send(pData, Size, UDP_UpdataPos_PORT); + struct pbuf *p; + + /* 分配缓冲区空间 */ + p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); + + if (p != NULL) + { + /* 填充缓冲区数据 */ + pbuf_take(p, pData, Size); + + /* 发送udp数据 */ + err_t err = udp_send(upcb, p); + if (err != ERR_OK) + { + // 发送失败 + //printf("Failed to send UDP data: %d\n", err); + } + /* 释放缓冲区空间 */ + pbuf_free(p); + } } /****************************************************************************** @@ -102,54 +221,212 @@ void GF_UpdataPos_Send(uint8_t *pData, uint32_t Size) ******************************************************************************/ void udp_client_init(void) { + + GF_BSP_Interrupt_Add_CallBack( + DF_BSP_InterCall_TIM8_2ms_PeriodElapsedCallback, UDP_GV_Dispatch); + //将UDP上传IV关闭 + GF_BSP_Interrupt_Add_CallBack( + DF_BSP_InterCall_TIM8_2ms_PeriodElapsedCallback, UDP_IV_Dispatch); + //Timer intialize(); err_t err; - IP4_ADDR(&serverIP, 192, 168, 1, 102); + IP4_ADDR(&serverIP, 192, 168, 144, 255); + IP4_ADDR(&Android_ServerIP, 192, 168, 144, 20); + /* 创建udp控制块 */ - upcb = udp_new(); + upcb_Rx_DLT = udp_new(); - if (upcb != NULL) + if (upcb_Rx_DLT != NULL) { /* 配置本地端口 */ - upcb->local_port = UDP_LOCAL_PORT; + //upcb_DLT->local_port = UDP_DLT_LOCAL_PORT; + /* 配置服务器IP和端口 */ + //upcb_DLT->so_options |= SOF_BROADCAST; + //err = udp_connect(upcb_DLT, &serverIP, UDP_REMOTE_DLT_PORT); + err = udp_bind(upcb_Rx_DLT, IP_ADDR_ANY, UDP_DLT_LOCAL_PORT); + if (err == ERR_OK) + { + /* 注册接收回调函数 */ + /* 注册接收回调函数 */ + udp_recv(upcb_Rx_DLT, udp_receive_callback, NULL); + } + else + { + udp_remove(upcb_Rx_DLT); + + } + } + upcb_Rx_From_Android = udp_new(); + + if (upcb_Rx_From_Android != NULL) + { + /* 配置本地端口 */ + //upcb_DLT->local_port = UDP_DLT_LOCAL_PORT; /* 配置服务器IP和端口 */ - err= udp_connect(upcb, &serverIP, UDP_REMOTE_PORT); - // err = udp_bind(upcb, IP_ADDR_ANY, UDP_LOCAL_PORT); - upcb->so_options |= SOF_BROADCAST; + //upcb_DLT->so_options |= SOF_BROADCAST; + //err = udp_connect(upcb_DLT, &serverIP, UDP_REMOTE_DLT_PORT); + err = udp_bind(upcb_Rx_From_Android, IP_ADDR_ANY, + UDP_CMD_LOCAL_Android_Listen_PORT); if (err == ERR_OK) { /* 注册接收回调函数 */ - udp_recv(upcb, udp_receive_callback, NULL); + /* 注册接收回调函数 */ + udp_recv(upcb_Rx_From_Android, udp_receive_callback, NULL); + } + else + { + udp_remove(upcb_Rx_From_Android); + + } + } + + upcb_Rx_Cmd = udp_new(); - /* 发送udp数据 */ - //printf("udp client connected\r\n"); - } else + if (upcb_Rx_Cmd != NULL) + { + /* 配置本地端口 */ + //upcb_Cmd->local_port = UDP_CMD_LOCAL_PORT; + /* 配置服务器IP和端口 */ + //upcb_Cmd->so_options |= SOF_BROADCAST; + //err = udp_connect(upcb_Cmd, &serverIP, UDP_REMOTE_CMD_PORT); + err = udp_bind(upcb_Rx_Cmd, IP_ADDR_ANY, UDP_CMD_LOCAL_PORT); + if (err == ERR_OK) + { + /* 注册接收回调函数 */ + udp_recv(upcb_Rx_Cmd, udp_receive_callback, NULL); + } + else { - udp_remove(upcb); + udp_remove(upcb_Rx_Cmd); + } + } + + upcb_Tx_Cmd = udp_new(); - //printf("can not connect udp pcb\r\n"); + if (upcb_Tx_Cmd != NULL) + { + /* 配置本地端口 */ + upcb_Tx_Cmd->local_port = UDP_CMD_Send_LOCAL_PORT; + + /* 配置服务器IP和端口 */ + //upcb_Cmd->so_options |= SOF_BROADCAST; + err = udp_connect(upcb_Tx_Cmd, &serverIP, UDP_REMOTE_CMD_PORT); + + if (err == ERR_OK) + { + /* 注册接收回调函数 */ + //udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL); + } + else + { + udp_remove(upcb_Tx_Cmd); } } -// upcb_send = udp_new(); -// -// if (upcb_send != NULL) -// { -// /* 配置本地端口 */ -// upcb_send->local_port = UDP_Send_LOCAL_PORT; -// -// /* 配置服务器IP和端口 */ -// upcb_send->so_options |= SOF_BROADCAST; -// err = udp_bind(upcb_send, IP_ADDR_ANY, UDP_Send_LOCAL_PORT); -// if (err == ERR_OK) -// { -// -// } else -// { -// udp_remove(upcb_send); -// -// } -// } + upcb_Tx_DLT = udp_new(); + + if (upcb_Tx_DLT != NULL) + { + /* 配置本地端口 */ + upcb_Tx_Cmd->local_port = UDP_DLT_Send_LOCAL_PORT; + /* 配置服务器IP和端口 */ + //upcb_Cmd->so_options |= SOF_BROADCAST; + err = udp_connect(upcb_Tx_DLT, &serverIP, UDP_REMOTE_DLT_PORT); + + if (err == ERR_OK) + { + /* 注册接收回调函数 */ + //udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL); + } + else + { + udp_remove(upcb_Tx_DLT); + } + } + + upcb_Tx_GV = udp_new(); + + if (upcb_Tx_GV != NULL) + { + /* 配置本地端口 */ + upcb_Tx_Cmd->local_port = UDP_GV_Send_LOCAL_PORT; + /* 配置服务器IP和端口 */ + //upcb_Cmd->so_options |= SOF_BROADCAST; + err = udp_connect(upcb_Tx_GV, &serverIP, UDP_REMOTE_GV_PORT); + + if (err == ERR_OK) + { + /* 注册接收回调函数 */ + //udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL); + } + else + { + udp_remove(upcb_Tx_GV); + } + } + + upcb_Tx_Android = udp_new(); + + if (upcb_Tx_Android != NULL) + { + /* 配置本地端口 */ + upcb_Tx_Android->local_port = UDP_Android_Send_LOCAL_PORT; + /* 配置服务器IP和端口 */ + //upcb_Cmd->so_options |= SOF_BROADCAST; + err = udp_connect(upcb_Tx_Android, &Android_ServerIP, + UDP_REMOTE_Android_PORT); + + if (err == ERR_OK) + { + /* 注册接收回调函数 */ + //udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL); + } + else + { + udp_remove(upcb_Tx_Android); + } + } + +} +int counter_index = 0; +int iv_counter_index = 0; +void UDP_GV_Dispatch() +{ + counter_index++; + if (counter_index <= 50) return; + if (is_udp_GV_update_loop_enalbed == 0) return; + counter_index = 0; + pb_ostream_t GV_o_stream = + { 0 }; + char buf[1024]; + GV_o_stream = pb_ostream_from_buffer(&buf[2], sizeof(buf)); + pb_encode(&GV_o_stream, GV_struct_define_fields, &GV); + buf[1] = 0xfe; + buf[0] = 0xfe; + //memcpy(&wh_LTE_7S0_Handler->Tx_Buf[2], buf, GV_o_stream.bytes_written); + udp_cmd_send_GV(buf, GV_o_stream.bytes_written + 2); + +} +//现在是每一百ms执行一次 +void UDP_IV_Dispatch() +{ + iv_counter_index++; + if (iv_counter_index <= 50) return; + iv_counter_index = 0; + char Tx_Buf[1024]; + pb_ostream_t IV_o_stream = pb_ostream_from_buffer(&Tx_Buf[2], + sizeof(Tx_Buf) - 2); + pb_encode(&IV_o_stream, IV_struct_define_fields, &IV); + + Tx_Buf[0] = 0x55; + Tx_Buf[1] = 0x55; + int32_t TxCount = IV_o_stream.bytes_written + 4; + uint16_t crc = MB_CRC16(Tx_Buf, IV_o_stream.bytes_written + 2); + + Tx_Buf[IV_o_stream.bytes_written + 2] = (crc >> 8) & 0xff; + Tx_Buf[IV_o_stream.bytes_written + 3] = crc & 0xff; + + udp_send_by_pcb(upcb_Tx_Android, Tx_Buf, IV_o_stream.bytes_written + 4); } diff --git a/BASE/Src/BSP/bsp_client_setting.c b/BASE/Src/BSP/bsp_client_setting.c index 7e8b36a..00ee4b1 100644 --- a/BASE/Src/BSP/bsp_client_setting.c +++ b/BASE/Src/BSP/bsp_client_setting.c @@ -36,7 +36,7 @@ void client_setting_intialize(struct UARTHandler *Handler) void UpdateIV() //往安卓发的 { - + return; // 若485线存在,能够读写数据,则不进行解析,直接return; if (Get_BIT(SystemErrorCode, ComError_Android_485) == CONNECTED) { @@ -66,7 +66,7 @@ void UpdateIV() //往安卓发的 void decode_received_data_from_client(uint8_t *buffer, uint16_t length) { - + return; // 若485线存在,能够读写数据,则不进行解析,直接return; if (Get_BIT(SystemErrorCode, ComError_Android_485) == CONNECTED) { diff --git a/BASE/Src/MSP/msp_485_android.c b/BASE/Src/MSP/msp_485_android.c index 08810a0..ac9fbd1 100644 --- a/BASE/Src/MSP/msp_485_android.c +++ b/BASE/Src/MSP/msp_485_android.c @@ -4,26 +4,25 @@ * Created on: 2025年12月1日 * Author: akeguo */ +#include "robot_state.h" #include "msp_485_android.h" #include "msp_U7.h" +#include "bsp_Error_Detect.h" void decode_android_485(uint8_t *buffer, uint16_t length); +void decode_android_PV(uint8_t *buffer, uint16_t length); void android_485_loop(); //inqure data from the, in fact this is a modbus 03 function; - struct UARTHandler *android_handler; DispacherController *androidr_dispacherController; int android_slave_id = 0x40; - +int time_to_adapt = 100; int8_t android_slave_iv_start_holiding_register = 100; int16_t android_slave_iv_holiding_register_num = 0; //这个数据要随时改变 - //最多读取多少个字节 -int16_t read_android_holidng_register_count = 19 + 1 - + PV_struct_define_size / 2; //16个subs通道 1个PV数据长度, - +int16_t read_android_holidng_register_count = 20; + //+ PV_struct_define_size / 2; //16个subs通道 1个PV数据长度, uint16_t Decoded_Android_HoldingReg_Value[100]; //用来对Android的Sbus /PV /IV 的操作 uint16_t send_pv_android_holdingReg_Value[100]; // /PV /IV 的操作 - void android_485_intialize(struct UARTHandler *Handler) { android_handler = Handler; @@ -53,27 +52,14 @@ void android_485_loop() MB_ReadHoldingReg(&android_handler->Tx_Buf, &android_handler->TxCount, android_slave_id, 0, read_android_holidng_register_count); android_handler->AddSendList(android_handler, android_handler->Tx_Buf, - android_handler->TxCount, 120, decode_android_485); - - //设定安卓数据 - pb_ostream_t IV_o_stream = pb_ostream_from_buffer( - &send_pv_android_holdingReg_Value[1], - sizeof(send_pv_android_holdingReg_Value) - 1); - pb_encode(&IV_o_stream, IV_struct_define_fields, &IV); - - android_slave_iv_holiding_register_num = (IV_o_stream.bytes_written + 1) / 2 - + 1; - send_pv_android_holdingReg_Value[0] = SWAP_ENDIAN_16( - IV_o_stream.bytes_written); - MB_WriteNumHoldingReg(&android_handler->Tx_Buf, &android_handler->TxCount, - android_slave_id, android_slave_iv_start_holiding_register, - android_slave_iv_holiding_register_num, - send_pv_android_holdingReg_Value); - android_handler->AddSendList(android_handler, android_handler->Tx_Buf, - android_handler->TxCount, 120, NULL); + android_handler->TxCount, time_to_adapt, decode_android_485); } int PMK32Index = 0; + +int received_android_counter = 0; +int received_counter_max = 10/2;// 每次读取多少次遥控器然后读取PV/写IV + int32_t *p_mk32_pointer; //读取 的寄存器 void decode_android_485(uint8_t *buffer, uint16_t length) @@ -91,8 +77,7 @@ void decode_android_485(uint8_t *buffer, uint16_t length) { p_mk32_pointer = (int32_t*) P_U7; //Sbus 设定 - - for (int PMK32Index = 0; PMK32Index < 19; PMK32Index++) + for (int PMK32Index = 0; PMK32Index < 18; PMK32Index++) { //此处必须加类型转换 *p_mk32_pointer = @@ -100,28 +85,85 @@ void decode_android_485(uint8_t *buffer, uint16_t length) p_mk32_pointer++; } + received_android_counter++; + + //读取遥控器 + MB_ReadHoldingReg(&android_handler->Tx_Buf, &android_handler->TxCount, android_slave_id, 0, read_android_holidng_register_count); + android_handler->AddSendList(android_handler, android_handler->Tx_Buf, android_handler->TxCount, time_to_adapt, + decode_android_485); + + if (received_android_counter % received_counter_max != 0) return; + switch (received_android_counter / received_counter_max % 2) + { + case 0: + { + //设定安卓数据 + pb_ostream_t IV_o_stream = pb_ostream_from_buffer( + &send_pv_android_holdingReg_Value[1], + sizeof(send_pv_android_holdingReg_Value) - 1); + pb_encode(&IV_o_stream, IV_struct_define_fields, &IV); + + android_slave_iv_holiding_register_num = (IV_o_stream.bytes_written + 1) / 2 + + 1; + send_pv_android_holdingReg_Value[0] = SWAP_ENDIAN_16( + IV_o_stream.bytes_written); + MB_WriteNumHoldingReg(&android_handler->Tx_Buf, &android_handler->TxCount, + android_slave_id, android_slave_iv_start_holiding_register, + android_slave_iv_holiding_register_num, + send_pv_android_holdingReg_Value); + android_handler->AddSendList(android_handler, android_handler->Tx_Buf, + android_handler->TxCount, 150, NULL); + received_android_counter = 0; + break; + } + case 1: + { //读取安卓数据 03 PV + MB_ReadHoldingReg(&android_handler->Tx_Buf, &android_handler->TxCount, android_slave_id, 19, + (Decoded_Android_HoldingReg_Value[18] + 1) / 2); + android_handler->AddSendList(android_handler, android_handler->Tx_Buf, android_handler->TxCount, + time_to_adapt, decode_android_PV); + + break; + } + } + } else + { + LOGFF(DL_ERROR, "Android_485 decoding failed"); + } +} +/*****/ +void decode_android_PV(uint8_t *buffer, uint16_t length) +{ +// uint8_t data1[1000]; +// memcpy(data1, buffer, length); + if (length <= 5) + { + return; + } + int decoded_result = MB_Decode_HoldingRegs(buffer, length, (Decoded_Android_HoldingReg_Value[18] + 1) / 2, + &Decoded_Android_HoldingReg_Value[19]); + if (decoded_result == 1) + { //PV解析 pb_istream_t i_pv_stream = { 0 }; - i_pv_stream = pb_istream_from_buffer( - &Decoded_Android_HoldingReg_Value[20], - Decoded_Android_HoldingReg_Value[19]); - pb_decode(&i_pv_stream, PV_struct_define_fields, &_decoded_PV_temp); -// if (decoded_PV.TimeStamp <= _decoded_PV_temp.TimeStamp) -// { -// decoded_PV = _decoded_PV_temp; -// } - - if (GV.PV.TimeStamp <= _decoded_PV_temp.TimeStamp) + i_pv_stream = pb_istream_from_buffer(&Decoded_Android_HoldingReg_Value[19], + Decoded_Android_HoldingReg_Value[18]); + int checkreturn = pb_decode(&i_pv_stream, PV_struct_define_fields, &_decoded_PV_temp); + if (checkreturn == 1) { - GV.PV = _decoded_PV_temp; + if (GV.PV.TimeStamp <= _decoded_PV_temp.TimeStamp) + { + GV.PV = _decoded_PV_temp; + } + } - HardWareErrorController->Set_PCOMHardWare(HardWareErrorController, - "Android_485", 1); + HardWareErrorController->Set_PCOMHardWare(HardWareErrorController, "Android_485", 1); - } else + } + else { LOGFF(DL_ERROR, "Android_485 decoding failed"); } diff --git a/BASE/Src/MSP/msp_TI5MOTOR.c b/BASE/Src/MSP/msp_TI5MOTOR.c index 82d2c6b..8ed4b72 100644 --- a/BASE/Src/MSP/msp_TI5MOTOR.c +++ b/BASE/Src/MSP/msp_TI5MOTOR.c @@ -28,11 +28,13 @@ CSP tempCSP; int32_t Function_code = 0; uint8_t ID_A_T; - +uint8_t data1[20]; void DecodeTi5MotorCAN(uint32_t canID, uint8_t *buffer, uint32_t length) { ID_A_T = canID; + memcpy(data1, buffer, length); + if (ID_A_T >= DF_MSP_Ti5Motor_StartID && ID_A_T < DF_MSP_Ti5Motor_StartID + 3) { diff --git a/BASE/Src/MSP/msp_U7.c b/BASE/Src/MSP/msp_U7.c index 289fe6b..99854ce 100644 --- a/BASE/Src/MSP/msp_U7.c +++ b/BASE/Src/MSP/msp_U7.c @@ -16,6 +16,7 @@ SP_MSP_U7_Button *P_U7; struct UARTHandler *U7_Sbus_Controller; void decode_U7Data(uint8_t *buffer, uint16_t length) { + return; if (Get_BIT(SystemErrorCode, ComError_Android_485) == CONNECTED) { return; diff --git a/BHBF_NewFiveWheel3.0.ioc b/BHBF_NewFiveWheel3.0.ioc index a5823df..fdd77ae 100644 --- a/BHBF_NewFiveWheel3.0.ioc +++ b/BHBF_NewFiveWheel3.0.ioc @@ -858,7 +858,7 @@ UART5.IPParameters=BaudRate,WordLength,Parity,OverrunDisableParam,DMADisableonRx UART5.OverrunDisableParam=UART_ADVFEATURE_OVERRUN_DISABLE UART5.Parity=PARITY_EVEN UART5.WordLength=WORDLENGTH_9B -UART7.BaudRate=38400 +UART7.BaudRate=115200 UART7.DMADisableonRxErrorParam=UART_ADVFEATURE_DMA_DISABLEONRXERROR UART7.IPParameters=OverrunDisableParam,BaudRate,DMADisableonRxErrorParam UART7.OverrunDisableParam=UART_ADVFEATURE_OVERRUN_DISABLE diff --git a/Core/Protobuf/PSource/bsp_GV.pb.h b/Core/Protobuf/PSource/bsp_GV.pb.h index 783c3c5..2620cb0 100644 --- a/Core/Protobuf/PSource/bsp_GV.pb.h +++ b/Core/Protobuf/PSource/bsp_GV.pb.h @@ -107,7 +107,7 @@ extern const pb_msgdesc_t GV_struct_define_msg; /* Maximum encoded size of messages (where known) */ #define BSP_GV_PB_H_MAX_SIZE GV_struct_define_size -#define GV_struct_define_size 963 +#define GV_struct_define_size 951 #ifdef __cplusplus } /* extern "C" */ diff --git a/Core/Protobuf/PSource/msp_U7.pb.h b/Core/Protobuf/PSource/msp_U7.pb.h index ea38280..a29a22a 100644 --- a/Core/Protobuf/PSource/msp_U7.pb.h +++ b/Core/Protobuf/PSource/msp_U7.pb.h @@ -26,10 +26,9 @@ typedef struct _SP_MSP_U7_Button { int32_t M2; int32_t M6; int32_t S3; - int32_t IsOnline; + int32_t M4; int32_t S4; - int32_t S5; - int32_t S6; + int32_t IsOnline; } SP_MSP_U7_Button; @@ -38,8 +37,8 @@ extern "C" { #endif /* Initializer values for message structs */ -#define SP_MSP_U7_Button_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -#define SP_MSP_U7_Button_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define SP_MSP_U7_Button_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define SP_MSP_U7_Button_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define SP_MSP_U7_Button_RxIndex_tag 1 @@ -57,10 +56,9 @@ extern "C" { #define SP_MSP_U7_Button_M2_tag 13 #define SP_MSP_U7_Button_M6_tag 14 #define SP_MSP_U7_Button_S3_tag 15 -#define SP_MSP_U7_Button_IsOnline_tag 16 +#define SP_MSP_U7_Button_M4_tag 16 #define SP_MSP_U7_Button_S4_tag 17 -#define SP_MSP_U7_Button_S5_tag 18 -#define SP_MSP_U7_Button_S6_tag 19 +#define SP_MSP_U7_Button_IsOnline_tag 18 /* Struct field encoding specification for nanopb */ #define SP_MSP_U7_Button_FIELDLIST(X, a) \ @@ -79,10 +77,9 @@ X(a, STATIC, SINGULAR, INT32, RU_Single, 12) \ X(a, STATIC, SINGULAR, INT32, M2, 13) \ X(a, STATIC, SINGULAR, INT32, M6, 14) \ X(a, STATIC, SINGULAR, INT32, S3, 15) \ -X(a, STATIC, SINGULAR, INT32, IsOnline, 16) \ +X(a, STATIC, SINGULAR, INT32, M4, 16) \ X(a, STATIC, SINGULAR, INT32, S4, 17) \ -X(a, STATIC, SINGULAR, INT32, S5, 18) \ -X(a, STATIC, SINGULAR, INT32, S6, 19) +X(a, STATIC, SINGULAR, INT32, IsOnline, 18) #define SP_MSP_U7_Button_CALLBACK NULL #define SP_MSP_U7_Button_DEFAULT NULL @@ -93,7 +90,7 @@ extern const pb_msgdesc_t SP_MSP_U7_Button_msg; /* Maximum encoded size of messages (where known) */ #define MSP_U7_PB_H_MAX_SIZE SP_MSP_U7_Button_size -#define SP_MSP_U7_Button_size 213 +#define SP_MSP_U7_Button_size 201 #ifdef __cplusplus } /* extern "C" */ diff --git a/Core/Protobuf/Proto/msp_U7.proto b/Core/Protobuf/Proto/msp_U7.proto index 0b8ba1c..66d297b 100644 --- a/Core/Protobuf/Proto/msp_U7.proto +++ b/Core/Protobuf/Proto/msp_U7.proto @@ -16,8 +16,7 @@ message SP_MSP_U7_Button { int32 M2 = 13; int32 M6 = 14; int32 S3 = 15; - int32 IsOnline= 16; + int32 M4 = 16; int32 S4 = 17; - int32 S5= 18; - int32 S6= 19; + int32 IsOnline= 18; } diff --git a/Core/Src/FSM.c b/Core/Src/FSM.c index 8a31d98..9271de8 100644 --- a/Core/Src/FSM.c +++ b/Core/Src/FSM.c @@ -669,6 +669,10 @@ void Emergency() void GF_Dispatch() //2ms调用一次 给车体速度等赋值 { + + + + // 如果处于复位模式,直接停车,不再执行运动逻辑 if (system_mode == SYSTEM_RESET) { diff --git a/Core/Src/main.c b/Core/Src/main.c index 25488a9..10f0cec 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -59,7 +59,7 @@ int can2_DispacherPeriod = 20; #define RS485_1_WaitTime 8 #define RS485_2_WaitTime 8 #define RS485_3_WaitTime 8 -#define RS485_4_WaitTime 8 +#define RS485_4_WaitTime 10 #define LTE_7S0_Serial_WaitTime 8 #define InterCall_DEBUG_WaitTime 8 #define E28_SBUS_WaitTime 6 @@ -156,12 +156,12 @@ int main(void) /* USER CODE BEGIN 2 */ SystemTimer_Intialize(); //加数数定时器 - GF_BSP_GPIO_SetIO(0, 0); //0�?????????????? 1�?????????????? + GF_BSP_GPIO_SetIO(0, 0); //0�??????????????? 1�??????????????? GF_BSP_GPIO_SetIO(1, 1); HAL_Delay(5000); ////////////////////////////延时5s DLT_LOG_ENABLE_LEVEL = 0; //7 send all information 0 send nothing - Error_Detect_Intialzie(1000); //every 1 seconds + Error_Detect_Intialzie(2000); //every 1 seconds GF_Robot_Init(); GV.Move_Speed = 3000; //186.9 * m/min // udp_client_init(); @@ -258,10 +258,10 @@ void CV_GV_Init() CV.SwingMoveSpeedBase = 1000; CV.TiltMoveSpeedBase = 1000; - Motor[1] = &GV.LeftFrontMotor; //Motor[1]指向GV的电机参�?????????????? + Motor[1] = &GV.LeftFrontMotor; //Motor[1]指向GV的电机参�??????????????? Motor[2] = &GV.RightFrontMotor; -// Motor[2] = &GV.LeftFrontMotor; //Motor[1]指向GV的电机参�?????????????? +// Motor[2] = &GV.LeftFrontMotor; //Motor[1]指向GV的电机参�??????????????? // Motor[1] = &GV.RightFrontMotor; RobotSpeed = &GV.Move_Speed; //RobotSpeed指向GV的移动车体�?�度 这是整体车�?? 不是单个轮的 @@ -336,11 +336,11 @@ void GF_Robot_Init() TankWashing_Motor_Controller_intialize(&FD_CAN_1_Handler); - Fsm_Init(); //把遥控器指令绑定定时�?????????????? + Fsm_Init(); //把遥控器指令绑定定时�??????????????? uint8_t _state = 1; - _state = _state & GF_BSP_TIMER_Init(); //定时器最后启�??????????????????? + _state = _state & GF_BSP_TIMER_Init(); //定时器最后启�???????????????????? } /* USER CODE END 4 */ diff --git a/Core/Src/motors.c b/Core/Src/motors.c index ef91094..2ef0207 100644 --- a/Core/Src/motors.c +++ b/Core/Src/motors.c @@ -42,9 +42,9 @@ void MotorCommandsLoop() { for (int i = 1; i < 3; i++) { - Motor_ClearFault(i, FiveWheel_Motor_Controller, 4); - Motor_GetFaultState(i, FiveWheel_Motor_Controller, 4); - GetCSPByCommand(i, FiveWheel_Motor_Controller, 4); +// Motor_ClearFault(i, FiveWheel_Motor_Controller, 4); +// Motor_GetFaultState(i, FiveWheel_Motor_Controller, 4); +// GetCSPByCommand(i, FiveWheel_Motor_Controller, 4); } for (int i = 1; i < 3; i++) @@ -54,6 +54,7 @@ void MotorCommandsLoop() FiveWheel_Motor_Controller, 4); ReadPosition(i, FiveWheel_Motor_Controller, 4); Motor_GetFaultState(i, FiveWheel_Motor_Controller, 4); + GetCSPByCommand(i, FiveWheel_Motor_Controller, 4); } } diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 3bd9d85..4df89d5 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -188,7 +188,7 @@ void MX_UART7_Init(void) /* USER CODE END UART7_Init 1 */ huart7.Instance = UART7; - huart7.Init.BaudRate = 38400; + huart7.Init.BaudRate = 115200; huart7.Init.WordLength = UART_WORDLENGTH_8B; huart7.Init.StopBits = UART_STOPBITS_1; huart7.Init.Parity = UART_PARITY_NONE; diff --git a/readme.txt b/readme.txt index 543eb63..4f35bb9 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +1,2 @@ -BHBF_NewFiveWheel3.0(2510) +BHBF_NewFiveWheel3.0(02042026) +优化为拉毛的有线程序