diff --git a/CMakeLists.txt b/CMakeLists.txt index 80350d7..387e40c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,8 +88,7 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE modules/imu/BMI088Middleware.c modules/imu/ins_task.c # modules - communication - modules/master_machine/master_process.c - modules/master_machine/seasky_protocol.c + modules/master_machine/master_machine.c modules/remote/remote_control.c modules/timachine/board_comm.c # modules - motor @@ -100,7 +99,6 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE modules/daemon/daemon.c modules/alarm/buzzer.c modules/vofa/vofa.c - modules/opencv/opencv.c # application application/gimbal/gimbal.c @@ -143,7 +141,6 @@ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE modules/daemon modules/alarm modules/vofa - modules/opencv modules/timachine modules diff --git a/application/cmd/robot_cmd.c b/application/cmd/robot_cmd.c index 6e92988..2c7bfc3 100644 --- a/application/cmd/robot_cmd.c +++ b/application/cmd/robot_cmd.c @@ -8,7 +8,7 @@ #include "message_center.h" #include "general_def.h" #include "kalman_filter.h" -#include "opencv.h" +#include "master_machine.h" /* bsp */ #include "bsp_dwt.h" #include "bsp_log.h" diff --git a/application/robot_def.h b/application/robot_def.h index 435a2b2..7f16d58 100644 --- a/application/robot_def.h +++ b/application/robot_def.h @@ -3,7 +3,6 @@ #define ROBOT_DEF_H #include "ins_task.h" -#include "master_process.h" #include "stdint.h" /* 开发板类型定义 */ diff --git a/modules/imu/ins_task.c b/modules/imu/ins_task.c index 7a4df5d..f53e0cf 100644 --- a/modules/imu/ins_task.c +++ b/modules/imu/ins_task.c @@ -18,7 +18,6 @@ #include "tim.h" #include "user_lib.h" #include "general_def.h" -#include "master_process.h" #include "arm_math.h" static INS_t INS; @@ -168,7 +167,6 @@ void INS_Task(void) INS.Roll = QEKF_INS.Roll; INS.YawTotalAngle = QEKF_INS.YawTotalAngle; - VisionSetAltitude(INS.Yaw, INS.Pitch, INS.Roll); } // temperature control diff --git a/modules/opencv/opencv.c b/modules/master_machine/master_machine.c similarity index 98% rename from modules/opencv/opencv.c rename to modules/master_machine/master_machine.c index 58deda4..7774478 100644 --- a/modules/opencv/opencv.c +++ b/modules/master_machine/master_machine.c @@ -1,4 +1,4 @@ -#include "opencv.h" +#include "master_machine.h" VisionData_t vision_data; diff --git a/modules/opencv/opencv.h b/modules/master_machine/master_machine.h similarity index 96% rename from modules/opencv/opencv.h rename to modules/master_machine/master_machine.h index 5c76bf5..2c4fcb1 100644 --- a/modules/opencv/opencv.h +++ b/modules/master_machine/master_machine.h @@ -1,5 +1,5 @@ -#ifndef OPENCV_H -#define OPENCV_H +#ifndef MASTER_MACHINE_H +#define MASTER_MACHINE_H #include "bsp_usart.h" #include "bsp_dwt.h" @@ -72,4 +72,4 @@ extern VisionData_t vision_data; void Vision_Uart_Init(UART_HandleTypeDef *_handle); -#endif // OPENCV_H +#endif // MASTER_MACHINE_H diff --git a/modules/master_machine/master_process.c b/modules/master_machine/master_process.c deleted file mode 100644 index eee32c8..0000000 --- a/modules/master_machine/master_process.c +++ /dev/null @@ -1,157 +0,0 @@ -/** - * @file master_process.c - * @author neozng - * @brief module for recv&send vision data - * @version beta - * @date 2022-11-03 - * @todo 增加对串口调试助手协议的支持,包括vofa和serial debug - * @copyright Copyright (c) 2022 - * - */ -#include "master_process.h" -#include "seasky_protocol.h" -#include "daemon.h" -#include "bsp_log.h" -#include "robot_def.h" - -static USARTInstance *vision_usart_instance; - -static Vision_Recv_s recv_data; -static Vision_Send_s send_data; -static DaemonInstance *vision_daemon_instance; - -void VisionSetFlag(Enemy_Color_e enemy_color, Work_Mode_e work_mode, Bullet_Speed_e bullet_speed) -{ - send_data.enemy_color = enemy_color; - send_data.work_mode = work_mode; - send_data.bullet_speed = bullet_speed; -} - -void VisionSetAltitude(float yaw, float pitch, float roll) -{ - send_data.yaw = yaw; - send_data.pitch = pitch; - send_data.roll = roll; -} - -/** - * @brief 离线回调函数,将在daemon.c中被daemon task调用 - * @attention 由于HAL库的设计问题,串口开启DMA接收之后同时发送有概率出现__HAL_LOCK()导致的死锁,使得无法 - * 进入接收中断.通过daemon判断数据更新,重新调用服务启动函数以解决此问题. - * - * @param id vision_usart_instance的地址,此处没用. - */ -static void VisionOfflineCallback(void *id) -{ -#ifdef VISION_USE_UART - USARTServiceInit(vision_usart_instance); -#endif // !VISION_USE_UART - LOGWARNING("[vision] vision offline, restart communication."); -} - -#ifdef VISION_USE_UART - -#include "bsp_usart.h" - - - -/** - * @brief 接收解包回调函数,将在bsp_usart.c中被usart rx callback调用 - * @todo 1.提高可读性,将get_protocol_info的第四个参数增加一个float类型buffer - * 2.添加标志位解码 - */ -static void DecodeVision() -{ - uint16_t flag_register; - DaemonReload(vision_daemon_instance); // 喂狗 - get_protocol_info(vision_usart_instance->recv_buff, &flag_register, (uint8_t *)&recv_data.pitch); - // TODO: code to resolve flag_register; -} - -Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle) -{ - USART_Init_Config_s conf; - conf.module_callback = DecodeVision; - conf.recv_buff_size = VISION_RECV_SIZE; - conf.usart_handle = _handle; - vision_usart_instance = USARTRegister(&conf); - - // 为master process注册daemon,用于判断视觉通信是否离线 - Daemon_Init_Config_s daemon_conf = { - .callback = VisionOfflineCallback, // 离线时调用的回调函数,会重启串口接收 - .owner_id = vision_usart_instance, - .reload_count = 10, - }; - vision_daemon_instance = DaemonRegister(&daemon_conf); - - return &recv_data; -} - -/** - * @brief 发送函数 - * - * @param send 待发送数据 - * - */ -void VisionSend() -{ - // buff和txlen必须为static,才能保证在函数退出后不被释放,使得DMA正确完成发送 - // 析构后的陷阱需要特别注意! - static uint16_t flag_register; - static uint8_t send_buff[VISION_SEND_SIZE]; - static uint16_t tx_len; - // TODO: code to set flag_register - flag_register = 30 << 8 | 0b00000001; - // 将数据转化为seasky协议的数据包 - get_protocol_send_data(0x02, flag_register, &send_data.yaw, 3, send_buff, &tx_len); - USARTSend(vision_usart_instance, send_buff, tx_len, USART_TRANSFER_DMA); // 和视觉通信使用IT,防止和接收使用的DMA冲突 - // 此处为HAL设计的缺陷,DMASTOP会停止发送和接收,导致再也无法进入接收中断. - // 也可在发送完成中断中重新启动DMA接收,但较为复杂.因此,此处使用IT发送. - // 若使用了daemon,则也可以使用DMA发送. -} - -#endif // VISION_USE_UART - -#ifdef VISION_USE_VCP - -#include "bsp_usb.h" -static uint8_t *vis_recv_buff; - -static void DecodeVision(uint16_t recv_len) -{ - uint16_t flag_register; - get_protocol_info(vis_recv_buff, &flag_register, (uint8_t *)&recv_data.pitch); - // TODO: code to resolve flag_register; -} - -/* 视觉通信初始化 */ -Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle) -{ - UNUSED(_handle); // 仅为了消除警告 - USB_Init_Config_s conf = {.rx_cbk = DecodeVision}; - vis_recv_buff = USBInit(conf); - - // 为master process注册daemon,用于判断视觉通信是否离线 - Daemon_Init_Config_s daemon_conf = { - .callback = VisionOfflineCallback, // 离线时调用的回调函数,会重启串口接收 - .owner_id = NULL, - .reload_count = 5, // 50ms - }; - vision_daemon_instance = DaemonRegister(&daemon_conf); - - return &recv_data; -} - -void VisionSend() -{ - static uint16_t flag_register; - static uint8_t send_buff[VISION_SEND_SIZE]; - static uint16_t tx_len; - // TODO: code to set flag_register - flag_register = 30 << 8 | 0b00000001; - // 将数据转化为seasky协议的数据包 - get_protocol_send_data(0x02, flag_register, &send_data.yaw, 3, send_buff, &tx_len); - USBTransmit(send_buff, tx_len); -} - -#endif // VISION_USE_VCP diff --git a/modules/master_machine/master_process.h b/modules/master_machine/master_process.h deleted file mode 100644 index e8668be..0000000 --- a/modules/master_machine/master_process.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef MASTER_PROCESS_H -#define MASTER_PROCESS_H - -#include "bsp_usart.h" -#include "seasky_protocol.h" - -#define VISION_RECV_SIZE 18u // 当前为固定值,36字节 -#define VISION_SEND_SIZE 36u - -#pragma pack(1) -typedef enum -{ - NO_FIRE = 0, - AUTO_FIRE = 1, - AUTO_AIM = 2 -} Fire_Mode_e; - -typedef enum -{ - NO_TARGET = 0, - TARGET_CONVERGING = 1, - READY_TO_FIRE = 2 -} Target_State_e; - -typedef enum -{ - NO_TARGET_NUM = 0, - HERO1 = 1, - ENGINEER2 = 2, - INFANTRY3 = 3, - INFANTRY4 = 4, - INFANTRY5 = 5, - OUTPOST = 6, - SENTRY = 7, - BASE = 8 -} Target_Type_e; - -typedef struct -{ - Fire_Mode_e fire_mode; - Target_State_e target_state; - Target_Type_e target_type; - - float pitch; - float yaw; -} Vision_Recv_s; - -typedef enum -{ - COLOR_NONE = 0, - COLOR_BLUE = 1, - COLOR_RED = 2, -} Enemy_Color_e; - -typedef enum -{ - VISION_MODE_AIM = 0, - VISION_MODE_SMALL_BUFF = 1, - VISION_MODE_BIG_BUFF = 2 -} Work_Mode_e; - -typedef enum -{ - BULLET_SPEED_NONE = 0, - BIG_AMU_10 = 10, - SMALL_AMU_15 = 15, - BIG_AMU_16 = 16, - SMALL_AMU_18 = 18, - SMALL_AMU_30 = 30, -} Bullet_Speed_e; - -typedef struct -{ - Enemy_Color_e enemy_color; - Work_Mode_e work_mode; - Bullet_Speed_e bullet_speed; - - float yaw; - float pitch; - float roll; -} Vision_Send_s; -#pragma pack() - -/** - * @brief 调用此函数初始化和视觉的串口通信 - * - * @param handle 用于和视觉通信的串口handle(C板上一般为USART1,丝印为USART2,4pin) - */ -Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle); - -/** - * @brief 发送视觉数据 - * - */ -void VisionSend(); - -/** - * @brief 设置视觉发送标志位 - * - * @param enemy_color - * @param work_mode - * @param bullet_speed - */ -void VisionSetFlag(Enemy_Color_e enemy_color, Work_Mode_e work_mode, Bullet_Speed_e bullet_speed); - -/** - * @brief 设置发送数据的姿态部分 - * - * @param yaw - * @param pitch - */ -void VisionSetAltitude(float yaw, float pitch, float roll); - -#endif // !MASTER_PROCESS_H \ No newline at end of file diff --git a/modules/master_machine/master_process.md b/modules/master_machine/master_process.md deleted file mode 100644 index e81e949..0000000 --- a/modules/master_machine/master_process.md +++ /dev/null @@ -1,133 +0,0 @@ -# master_process - - - -

neozng1@hnu.edu.cn

- -> TODO: -> -> 1. 补全标志位解析和发送设置的代码 -> 2. 增加发送给视觉数据的时间戳用于数据对齐 - - - -## 总览和封装说明 - -模块包含了和视觉通信的初始化、向上位机发送信息的接口和模块的串口的回调处理。接口的定义统一,可以方便的替换成其他通信方式,如CAN。 - -## 代码结构 - -.h文件内包括了外部接口和与**视觉上位机通信的数据结构定义**,以及模块对应的宏。c文件内为私有函数和外部接口的定义。 - -本模块主要是对协议解析的处理和协议发送的封装,实际内容不多。协议相关内容都在`seasky_protocol.h`中。 - -## 类型定义 - -和视觉通信所必须的标志位和数据。包括开火模式,目标状态,目标类型,接收/发送数据结构体。 - -```c -typedef enum -{ - NO_FIRE = 0, - AUTO_FIRE = 1, - AUTO_AIM = 2 -} Fire_Mode_e; - -typedef enum -{ - NO_TARGET = 0, - TARGET_CONVERGING = 1, - READY_TO_FIRE = 2 -} Target_State_e; - -typedef enum -{ - NO_TARGET_NUM = 0, - HERO1 = 1, - ENGINEER2 = 2, - INFANTRY3 = 3, - INFANTRY4 = 4, - INFANTRY5 = 5, - OUTPOST = 6, - SENTRY = 7, - BASE = 8 -} Target_Type_e; - -typedef struct -{ - Fire_Mode_e fire_mode; - Target_State_e target_state; - Target_Type_e target_type; - - float pitch; - float yaw; -} Vision_Recv_s; - -typedef enum -{ - BLUE = 0, - RED = 1 -} Enemy_Color_e; - -typedef enum -{ - MODE_AIM = 0, - MODE_SMALL_BUFF = 1, - MODE_BIG_BUFF = 2 -} Work_Mode_e; - -typedef enum -{ - BIG_AMU_10 = 10, - SMALL_AMU_15 = 15, - BIG_AMU_16 = 16, - SMALL_AMU_18 = 18, - SMALL_AMU_30 = 30, -} Bullet_Speed_e; - -typedef struct -{ - Enemy_Color_e enemy_color; - Work_Mode_e work_mode; - Bullet_Speed_e bullet_speed; - - float yaw; - float pitch; - float roll; -} Vision_Send_s; -``` - -## 外部接口 - -```c -Vision_Recv_s *VisionInit(UART_HandleTypeDef *_handle); - -void VisionSend(Vision_Send_s *send); -``` - -给`VisionInit()`传入串口handle,将初始化一个视觉通信模块,返回值是接收数据的结构体指针。拥有视觉模块的应用应该在初始化中调用此函数,并保存返回值的指针。 - -调用`VisionSend`并传入填好发送数据的结构体,会通过底层的通信模块向视觉发送一帧报文。 - -## 私有函数和变量 - -```c -static Vision_Recv_s recv_data; - -static usart_instance *vision_usart_instance; - -static void DecodeVision() -{ - static uint16_t flag_register; - get_protocol_info(vision_usart_instance->recv_buff, &flag_register, (uint8_t*)&recv_data.pitch); - // TODO: code to resolve flag_register; -} -``` - -第一个是保存接收数据的结构体,其指针将会在初始化的时候返回给拥有者。目前最多只能配置一个视觉模块。 - -第二个是该模块拥有的串口实例指针,用于调度其底层的发送和接收。如果要换成CAN/SPI等,替换成对应实例,并修改初始化和发送的实现即可。 - -`DecodeVision()`是解析视觉接收数据的回调函数,会在串口接收回调中被调用。如果修改通信协议,只需要更改 - -`get_protocol_info()`。 \ No newline at end of file diff --git a/modules/master_machine/seasky_protocol.c b/modules/master_machine/seasky_protocol.c deleted file mode 100644 index 85304dd..0000000 --- a/modules/master_machine/seasky_protocol.c +++ /dev/null @@ -1,133 +0,0 @@ -/** - * @file seasky_protocol.c - * @author Liu Wei - * @author modified by Neozng - * @brief 湖南大学RoBoMatster串口通信协议 - * @version 0.1 - * @date 2022-11-03 - * - * @copyright Copyright (c) 2022 - * - */ - -#include "seasky_protocol.h" -#include "crc8.h" -#include "crc16.h" -#include "memory.h" - -/*获取CRC8校验码*/ -uint8_t Get_CRC8_Check(uint8_t *pchMessage,uint16_t dwLength) -{ - return crc_8(pchMessage,dwLength); -} -/*检验CRC8数据段*/ -static uint8_t CRC8_Check_Sum(uint8_t *pchMessage, uint16_t dwLength) -{ - uint8_t ucExpected = 0; - if ((pchMessage == 0) || (dwLength <= 2)) - return 0; - ucExpected = crc_8(pchMessage, dwLength - 1); - return (ucExpected == pchMessage[dwLength - 1]); -} - -/*获取CRC16校验码*/ -uint16_t Get_CRC16_Check(uint8_t *pchMessage,uint32_t dwLength) -{ - return crc_16(pchMessage,dwLength); -} - -/*检验CRC16数据段*/ -static uint16_t CRC16_Check_Sum(uint8_t *pchMessage, uint32_t dwLength) -{ - uint16_t wExpected = 0; - if ((pchMessage == 0) || (dwLength <= 2)) - { - return 0; - } - wExpected = crc_16(pchMessage, dwLength - 2); - return (((wExpected & 0xff) == pchMessage[dwLength - 2]) && (((wExpected >> 8) & 0xff) == pchMessage[dwLength - 1])); -} - -/*检验数据帧头*/ -static uint8_t protocol_heade_Check(protocol_rm_struct *pro, uint8_t *rx_buf) -{ - if (rx_buf[0] == PROTOCOL_CMD_ID) - { - pro->header.sof = rx_buf[0]; - if (CRC8_Check_Sum(&rx_buf[0], 4)) - { - pro->header.data_length = (rx_buf[2] << 8) | rx_buf[1]; - pro->header.crc_check = rx_buf[3]; - pro->cmd_id = (rx_buf[5] << 8) | rx_buf[4]; - return 1; - } - } - return 0; -} - -/* - 此函数根据待发送的数据更新数据帧格式以及内容,实现数据的打包操作 - 后续调用通信接口的发送函数发送tx_buf中的对应数据 -*/ -void get_protocol_send_data(uint16_t send_id, // 信号id - uint16_t flags_register, // 16位寄存器 - float *tx_data, // 待发送的float数据 - uint8_t float_length, // float的数据长度 - uint8_t *tx_buf, // 待发送的数据帧 - uint16_t *tx_buf_len) // 待发送的数据帧长度 -{ - static uint16_t crc16; - static uint16_t data_len; - - data_len = float_length * 4 + 2; - /*帧头部分*/ - tx_buf[0] = PROTOCOL_CMD_ID; - tx_buf[1] = data_len & 0xff; // 低位在前 - tx_buf[2] = (data_len >> 8) & 0xff; // 低位在前 - tx_buf[3] = crc_8(&tx_buf[0], 3); // 获取CRC8校验位 - - /*数据的信号id*/ - tx_buf[4] = send_id & 0xff; - tx_buf[5] = (send_id >> 8) & 0xff; - - /*建立16位寄存器*/ - tx_buf[6] = flags_register & 0xff; - tx_buf[7] = (flags_register >> 8) & 0xff; - - /*float数据段*/ - for (int i = 0; i < 4 * float_length; i++) - { - tx_buf[i + 8] = ((uint8_t *)(&tx_data[i / 4]))[i % 4]; - } - - /*整包校验*/ - crc16 = crc_16(&tx_buf[0], data_len + 6); - tx_buf[data_len + 6] = crc16 & 0xff; - tx_buf[data_len + 7] = (crc16 >> 8) & 0xff; - - *tx_buf_len = data_len + 8; -} -/* - 此函数用于处理接收数据, - 返回数据内容的id -*/ -uint16_t get_protocol_info(uint8_t *rx_buf, // 接收到的原始数据 - uint16_t *flags_register, // 接收数据的16位寄存器地址 - uint8_t *rx_data) // 接收的float数据存储地址 -{ - // 放在静态区,避免反复申请栈上空间 - static protocol_rm_struct pro; - static uint16_t date_length; - - if (protocol_heade_Check(&pro, rx_buf)) - { - date_length = OFFSET_BYTE + pro.header.data_length; - if (CRC16_Check_Sum(&rx_buf[0], date_length)) - { - *flags_register = (rx_buf[7] << 8) | rx_buf[6]; - memcpy(rx_data, rx_buf + 8, pro.header.data_length - 2); - return pro.cmd_id; - } - } - return 0; -} diff --git a/modules/master_machine/seasky_protocol.h b/modules/master_machine/seasky_protocol.h deleted file mode 100644 index 5c24c43..0000000 --- a/modules/master_machine/seasky_protocol.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef __SEASKY_PROTOCOL_H -#define __SEASKY_PROTOCOL_H - -#include -#include - -#define PROTOCOL_CMD_ID 0XA5 -#define OFFSET_BYTE 8 // 出数据段外,其他部分所占字节数 - -typedef struct -{ - struct - { - uint8_t sof; - uint16_t data_length; - uint8_t crc_check; // 帧头CRC校验 - } header; // 数据帧头 - uint16_t cmd_id; // 数据ID - uint16_t frame_tail; // 帧尾CRC校验 -} protocol_rm_struct; - - -/*更新发送数据帧,并计算发送数据帧长度*/ -void get_protocol_send_data(uint16_t send_id, // 信号id - uint16_t flags_register, // 16位寄存器 - float *tx_data, // 待发送的float数据 - uint8_t float_length, // float的数据长度 - uint8_t *tx_buf, // 待发送的数据帧 - uint16_t *tx_buf_len); // 待发送的数据帧长度 - -/*接收数据处理*/ -uint16_t get_protocol_info(uint8_t *rx_buf, // 接收到的原始数据 - uint16_t *flags_register, // 接收数据的16位寄存器地址 - uint8_t *rx_data); // 接收的float数据存储地址 - -#endif diff --git a/modules/master_machine/湖南大学RoboMaster电控组通信协议.md b/modules/master_machine/湖南大学RoboMaster电控组通信协议.md deleted file mode 100644 index 6cb3b38..0000000 --- a/modules/master_machine/湖南大学RoboMaster电控组通信协议.md +++ /dev/null @@ -1,73 +0,0 @@ -# 湖南大学RoboMaster电控组通信协议 - -

Seasky LIUWei

- -

modified by neozng1@hnu.edu.cn

- -可用于视觉,以及其他自研模块(仅限串口通信) - -> TODO: -> -> 1. 利用F4自带的硬件CRC模块计算校验码,提高速度 -> 2. 增加更多的数据类型支持,使得数据类型也为可配置的 - -## 一、串口配置 - -通信方式是串口,配置为波特率 921600,8 位数据位,1 位停止位,无硬件流控,无校验位。 - -## 二、数据帧说明 - -以下所有低位在前发送,数据长度可变。 - -1. 通信协议格式 - - | 帧头 | 数据ID | 数据 | 帧尾 | - | ----------------------- | -------------- | ------------- | :---------------------------------- | - | protocol_header(4-byte) | cmd_id(2-byte) | data (n-byte) | frame_tail(2-byte,CRC16,整包校验) | - -2. 帧头详细定义 - - | 帧头 | 偏移位置 | 字节大小 | 内容 | - | ----------- | -------- | -------- | ----------------------------- | - | sof(CMD) | 0 | 1 | 数据帧起始字节,固定值为 0xA5 | - | data_length | 1 | 2 | 数据帧中 data 的长度 | - | crc_check | 3 | 1 | 帧头CRC校验 | - -3. cmd_id 命令码 ID 说明 **(字节偏移 4,字节大小 2)** - - | 命令码 | 数据段长度 | 功能说明 | - | -------------- | --------------- | -------- | - | 0x0001(可修改) | 2 byte (16-bit) | 视觉数据 | - | ....... | | | - -4. 数据段data (n-byte) - - | 数据 | 偏移位置 | 字节大小 | 内容 | - | -------------- | -------- | --------------- | ------------------------------------- | - | flags_register | 6 | 2 | 16位标志置位寄存器 | - | float_data | 8 | 4 * data_length | float数据内容(4 * data_length-byte) | - -5. frame_tail(CRC16,整包校验) - -## 三、协议接口说明 - -```c -/*更新发送数据帧,并计算发送数据帧长度*/ -void get_protocol_send_data(uint16_t send_id, //信号id - uint16_t flags_register, // 16位寄存器 - float *tx_data, //待发送的float数据 - uint8_t float_length, // float的数据长度 - uint8_t *tx_buf, //待发送的数据帧 - uint16_t *tx_buf_len); //待发送的数据帧长度 -``` - -将float_data字段准备好放入`tx_data[]`并设置好标志位`flags_register`之后,调用此函数。它将计算循环冗余校验码,并把数据转换成串口发送的格式,放在`tx_buf[]`中。 - -```c -/*接收数据处理*/ -uint16_t get_protocol_info(uint8_t *rx_buf, //接收到的原始数据 - uint16_t *flags_register, //接收数据的16位寄存器地址 - float *rx_data); //接收的float数据存储地址 -``` - -将收到的一包原始数据buff地址传入,若校验通过,会把收到的标志位和float数据解析出来,保存在`flags_register*`和 `rx_data[]`中。 \ No newline at end of file