mirror of
https://gitee.com/dlmu-cone/bf_original_balance_chassis
synced 2026-07-24 03:27:45 +08:00
增加了hardfault调试支持,修复了消息队列在发布者先于订阅者创建话题时野指针的错误
This commit is contained in:
@@ -33,11 +33,6 @@ float RefTemp = 40; // 恒温设定温度
|
||||
|
||||
static void IMU_Param_Correction(IMU_Param_t *param, float gyro[3], float accel[3]);
|
||||
|
||||
/* 调用此函数获得姿态数据指针 */
|
||||
attitude_t *GetINSptr()
|
||||
{
|
||||
return (attitude_t *)&INS.Roll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 温度控制
|
||||
@@ -49,7 +44,7 @@ static void IMU_Temperature_Ctrl(void)
|
||||
imu_pwm_set(float_constrain(float_rounding(TempCtrl.Output), 0, UINT32_MAX));
|
||||
}
|
||||
|
||||
void INS_Init(void)
|
||||
attitude_t* INS_Init(void)
|
||||
{
|
||||
while (BMI088Init(&hspi1, 1) != BMI088_NO_ERROR);
|
||||
IMU_Param.scale[X] = 1;
|
||||
|
||||
@@ -71,18 +71,11 @@ typedef struct
|
||||
float Roll;
|
||||
} IMU_Param_t;
|
||||
|
||||
/**
|
||||
* @brief 反馈位姿结构体指针,apps通过初始化时保存该指针以实现数据访问
|
||||
*
|
||||
* @return attitude_t*
|
||||
*/
|
||||
attitude_t *GetINSptr();
|
||||
|
||||
/**
|
||||
* @brief 初始化惯导解算系统
|
||||
*
|
||||
*/
|
||||
void INS_Init(void);
|
||||
attitude_t *INS_Init(void);
|
||||
|
||||
/**
|
||||
* @brief 此函数放入实时系统中,以1kHz频率运行
|
||||
|
||||
@@ -72,19 +72,21 @@ static Publisher_t message_center = {
|
||||
.first_subs = NULL,
|
||||
.next_event_node = NULL};
|
||||
|
||||
static void CheckName(char* name)
|
||||
static void CheckName(char *name)
|
||||
{
|
||||
if(strnlen(name,MAX_EVENT_NAME_LEN+1)>=MAX_EVENT_NAME_LEN)
|
||||
if (strnlen(name, MAX_EVENT_NAME_LEN + 1) >= MAX_EVENT_NAME_LEN)
|
||||
{
|
||||
while (1); // 进入这里说明事件名超出长度限制
|
||||
while (1)
|
||||
; // 进入这里说明事件名超出长度限制
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckLen(uint8_t len1,uint8_t len2)
|
||||
static void CheckLen(uint8_t len1, uint8_t len2)
|
||||
{
|
||||
if(len1!=len2)
|
||||
if (len1 != len2)
|
||||
{
|
||||
while(1); // 相同事件的消息长度不同
|
||||
while (1)
|
||||
; // 相同事件的消息长度不同
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,14 +99,8 @@ Subscriber_t *SubRegister(char *name, uint8_t data_len)
|
||||
node = node->next_event_node; // 指向下一个发布者(发布者发布的事件)
|
||||
if (strcmp(name, node->event_name) == 0) // 如果事件名相同就订阅这个事件
|
||||
{
|
||||
CheckLen(data_len,node->data_len);
|
||||
Subscriber_t *sub = node->first_subs; // 指向订阅了该事件的第一个订阅者
|
||||
while (sub->next_subs_queue) // 遍历订阅了该事件的链表
|
||||
{
|
||||
sub = sub->next_subs_queue; // 移动到下一个订阅者
|
||||
} // 遇到空指针停下,说明到了链表尾部,创建新的订阅节点
|
||||
|
||||
// 申请内存,注意要memset因为新空间不一定是空的,可能有之前留存的垃圾值
|
||||
CheckLen(data_len, node->data_len);
|
||||
// 创建新的订阅者结点,申请内存,注意要memset因为新空间不一定是空的,可能有之前留存的垃圾值
|
||||
Subscriber_t *ret = (Subscriber_t *)malloc(sizeof(Subscriber_t));
|
||||
memset(ret, 0, sizeof(Subscriber_t));
|
||||
// 对新建的Subscriber进行初始化
|
||||
@@ -113,11 +109,22 @@ Subscriber_t *SubRegister(char *name, uint8_t data_len)
|
||||
{ // 给消息队列的每一个元素分配空间,queue里保存的实际上是数据执指针,这样可以兼容不同的数据长度
|
||||
ret->queue[i] = malloc(sizeof(data_len));
|
||||
}
|
||||
|
||||
sub->next_subs_queue = ret; // 接到链表尾部,延长该订阅该事件的subs链表
|
||||
//如果之前没有订阅者,特殊处理一下
|
||||
if(node->first_subs==NULL)
|
||||
{
|
||||
node->first_subs=ret;
|
||||
return ret;
|
||||
}
|
||||
// 遍历订阅者链表,直到到达尾部
|
||||
Subscriber_t *sub = node->first_subs; // iterator
|
||||
while (sub->next_subs_queue) // 遍历订阅了该事件的订阅者链表
|
||||
{
|
||||
sub = sub->next_subs_queue; // 移动到下一个订阅者,遇到空指针停下,说明到了链表尾部
|
||||
}
|
||||
sub->next_subs_queue = ret; // 把刚刚创建的订阅者接上
|
||||
return ret;
|
||||
}
|
||||
// 时间名不同,在下一轮循环访问下一个结点
|
||||
// 事件名不同,在下一轮循环访问下一个结点
|
||||
}
|
||||
// 遍历完,发现尚未注册事件(还没有发布者);那么创建一个事件,此时node是publisher链表的最后一个结点
|
||||
node->next_event_node = (Publisher_t *)malloc(sizeof(Publisher_t));
|
||||
@@ -146,7 +153,7 @@ Publisher_t *PubRegister(char *name, uint8_t data_len)
|
||||
node = node->next_event_node; // 切换到下一个发布者(事件)结点
|
||||
if (strcmp(node->event_name, name) == 0) // 如果已经注册了相同的事件,直接返回结点指针
|
||||
{
|
||||
CheckLen(data_len,node->data_len);
|
||||
CheckLen(data_len, node->data_len);
|
||||
return node;
|
||||
}
|
||||
} // 遍历完发现尚未创建name对应的事件
|
||||
|
||||
@@ -11,22 +11,23 @@
|
||||
static usart_instance* referee_usart_instance;
|
||||
|
||||
/**************裁判系统数据******************/
|
||||
referee_info_t referee_info;
|
||||
uint8_t Judge_Self_ID; // 当前机器人的ID
|
||||
uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID
|
||||
static referee_info_t referee_info;
|
||||
static uint8_t Judge_Self_ID; // 当前机器人的ID
|
||||
static uint16_t Judge_SelfClient_ID; // 发送者机器人对应的客户端ID
|
||||
|
||||
static void ReceiveCallback()
|
||||
{
|
||||
JudgeReadData(referee_usart_instance->recv_buff);
|
||||
}
|
||||
|
||||
void RefereeInit(UART_HandleTypeDef *referee_usart_handle)
|
||||
referee_info_t* RefereeInit(UART_HandleTypeDef *referee_usart_handle)
|
||||
{
|
||||
USART_Init_Config_s conf;
|
||||
conf.module_callback = ReceiveCallback;
|
||||
conf.usart_handle = referee_usart_handle;
|
||||
conf.recv_buff_size = RE_RX_BUFFER_SIZE;
|
||||
referee_usart_instance=USARTRegister(&conf);
|
||||
return &referee_info;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,15 +121,4 @@ void JudgeReadData(uint8_t *ReadFromUsart)
|
||||
JudgeReadData(ReadFromUsart + sizeof(xFrameHeader) + LEN_CMDID + referee_info.FrameHeader.DataLength + LEN_TAIL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取瞬时功率
|
||||
* @param void
|
||||
* @retval 实时功率值
|
||||
* @attention
|
||||
*/
|
||||
float JudgeGetChassisPower(void)
|
||||
{
|
||||
return (referee_info.PowerHeatData.chassis_power);
|
||||
}
|
||||
}
|
||||
@@ -340,11 +340,17 @@ typedef struct
|
||||
ext_CommunatianData_t CommuData; // 队友通信信息
|
||||
} referee_info_t;
|
||||
|
||||
extern referee_info_t referee_info;
|
||||
|
||||
void RefereeInit(UART_HandleTypeDef *referee_usart_handle);
|
||||
void JudgeReadData(uint8_t *ReadFromUsart);
|
||||
float JudgeGetChassisPower(void);
|
||||
|
||||
#pragma pack()
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param referee_usart_handle
|
||||
* @return referee_info_t*
|
||||
*/
|
||||
referee_info_t* RefereeInit(UART_HandleTypeDef *referee_usart_handle);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !REFEREE_H
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <stdint-gcc.h>
|
||||
#include "main.h"
|
||||
#include "usart.h"
|
||||
|
||||
#define RC_CH_VALUE_MIN ((uint16_t)364)
|
||||
#define RC_CH_VALUE_OFFSET ((uint16_t)1024)
|
||||
|
||||
Reference in New Issue
Block a user