feat: 为通信帧解析完成回调函数添加帧信息入参(以便命令函数校验成功与否)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
lwrb_t lwrb_struct;
|
||||
uint8_t buffer_rb[BY_TF_PARSE_BUFFER_SIZE];
|
||||
uint8_t buffer_out;
|
||||
uint8_t listern_slave_id;
|
||||
uint8_t listern_flag;
|
||||
uint16_t listern_timeout;
|
||||
uint16_t listern_timevia;
|
||||
@@ -95,6 +96,10 @@ void by_tiny_frame_parse_timer_handle(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void by_tiny_frame_parse_run(void)
|
||||
{
|
||||
|
||||
@@ -104,7 +109,7 @@ void by_tiny_frame_parse_run(void)
|
||||
} else {
|
||||
if (listern_timeout <= listern_timevia) {
|
||||
// 接收超时,停止监听
|
||||
parse_done_handle(1);
|
||||
parse_done_handle(frame_now, 1);
|
||||
by_tiny_frame_parse_end_listern();
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("by_tf_listern timeout\r\n");
|
||||
@@ -119,15 +124,20 @@ void by_tiny_frame_parse_run(void)
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO 目前接收校验错误也会等待直至超时
|
||||
// TODO 待结合 read&wirte 部分修改监听的从机地址
|
||||
if (!by_tiny_frame_parse_listening(&frame_now, 0x0D, buffer_out)) {
|
||||
// TODO 目前接收校验错误也会等待直至超时
|
||||
// TODO 待结合 read&wirte 部分修改监听的从机地址
|
||||
#if defined(BY_TF_DEVICE_SLAVE)
|
||||
if (!by_tiny_frame_parse_listening(&frame_now, BY_TF_DEVICE_SLAVE_ADDRESS, buffer_out))
|
||||
#else
|
||||
if (!by_tiny_frame_parse_listening(&frame_now, listern_slave_id, buffer_out))
|
||||
#endif
|
||||
{
|
||||
if (!by_tiny_frame_parse_crc(&frame_now)) {
|
||||
|
||||
// 接收成功后停止监听
|
||||
by_tiny_frame_parse_end_listern();
|
||||
// 解析成功回调
|
||||
parse_done_handle(0);
|
||||
parse_done_handle(frame_now, 0);
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("frame parsed!\r\n");
|
||||
#endif
|
||||
@@ -158,11 +168,16 @@ uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 校验错误则直接结束监听
|
||||
by_tiny_frame_parse_end_listern();
|
||||
parse_done_handle(frame_now, 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_handle_register(by_tf_parse_done_handle_func func)
|
||||
{
|
||||
// FIXME 未校验是否传入非空值,另外假设未执行注册,也会产生非法访问
|
||||
parse_done_handle = func;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef struct by_tf_parse_frame_t {
|
||||
uint32_t data;
|
||||
} by_tf_parse_frame_t;
|
||||
|
||||
typedef void (*by_tf_parse_done_handle_func)(uint8_t);
|
||||
typedef void (*by_tf_parse_done_handle_func)(by_tf_parse_frame_t, uint8_t);
|
||||
|
||||
extern void by_tiny_frame_parse_init(void);
|
||||
extern void by_tiny_frame_parse_uart_handle(uint8_t buff);
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
#ifndef _BY_TINY_FRAME_WRITE_H__
|
||||
#define _BY_TINY_FRAME_WRITE_H__
|
||||
|
||||
#include "by_tiny_frame_config.h"
|
||||
#include "by_tiny_frame_parse.h"
|
||||
#include "by_tiny_frame_pack.h"
|
||||
|
||||
#define BY_TINY_FRAME_WRITE_CMD_CODE (0x06)
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
extern void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data);
|
||||
#elif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user