向各位大佬求教个问题:
1、我的程序用串口接收PC端的数据,发现接收到第四个时就无法在接收;仿真发现进入了HardFault_Handle()函数中;
2、command里面显示:
3、我的代码中是将接收到的串口数据保存到一个队列中,用到了动态内存分配:
结构体定义:
typedef union
{
float fv;
uint8_t cv[4];
}float_union;
typedef struct
{
unsigned char start_code1; //起始码1
unsigned char start_code2; //起始码2
unsigned char func_code; //功能码
unsigned char sending_num;
unsigned char this_sending_num;
float_union joint_pos[6];
float_union joint_vel[6];
float_union joint_acc[6];
float_union joint_t;
unsigned char crc_code;
}RosDataNodeStruct;
typedef struct RosData
{
RosDataNodeStruct data;
struct RosData *next;
}RosDataNode;
初始化:
RosDataNode* RosQueueInit()
{
RosDataNode* queue = (RosDataNode*)malloc(sizeof(RosDataNode));
queue->data = RosDataQueueNodeInit;
queue->next = NULL;
return queue;
}
/*数据入队列,返回队列新的尾指针*/
RosDataNode* RosDataEnterQueue(RosDataNode* rear,RosDataNodeStruct rosdata)
{
RosDataNode* enElem = (RosDataNode*)malloc(sizeof(RosDataNode)); //分配节点空间(动态内存分配)
enElem->data = rosdata; //节点数据保存
enElem->next = NULL; //节点指针指向NULL
rear->next = enElem; //新节点放到rear节点后
rear = enElem; //得到新的队尾
return rear; //返回新的队尾指针
}
/*数据出队列,返回队列新的头指针*/
RosDataNodeStruct RosDataOutQueue(RosDataNode* top,RosDataNode* rear)
{
RosDataNodeStruct temp = {0};
RosDataNode *p = {0};
if(top->next == NULL) //队列为空
{
printf("queue is empty"); //????????????
return temp;
}
p = top->next;
temp = p->data;
top->next = p->next; //头指针指向下一个节点
if(rear == p) //出队后只剩一个节点则rear=top
{
ros_rear = top;
}
free(p); //释放节点内存
return temp;
}
ros_queue=ros_top=ros_rear=RosQueueInit();
初始化后仿真发现rear->next有很多
问题:1、仿真出现的问题是越界了吗?2、为什么初始化后会有如此多的rear->next,不是应该只有一个空指针吗?会不会是这种情况导致的内存不够?谢谢!
stm32链式队列问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
悬赏问题
- ¥15 帮我写一个c++工程
- ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
- ¥15 关于smbclient 库的使用
- ¥15 微信小程序协议怎么写
- ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
- ¥20 怎么用dlib库的算法识别小麦病虫害
- ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
- ¥15 java写代码遇到问题,求帮助
- ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
- ¥15 有了解d3和topogram.js库的吗?有偿请教