feat: 基本完成通信帧主机写操作接口
This commit is contained in:
@@ -6,17 +6,17 @@
|
||||
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;
|
||||
uint8_t listen_slave_id;
|
||||
uint8_t listen_flag;
|
||||
uint16_t listen_timeout;
|
||||
uint16_t listen_timevia;
|
||||
by_tf_parse_frame_t frame_now;
|
||||
by_tf_parse_done_handle_func parse_done_handle;
|
||||
|
||||
void by_tiny_frame_parse_init(void)
|
||||
{
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
listern_timeout = BY_TF_PARSE_TIMEOUT;
|
||||
listen_timeout = BY_TF_PARSE_TIMEOUT;
|
||||
#endif
|
||||
|
||||
/** 初始化环形缓冲区 **/
|
||||
@@ -88,10 +88,10 @@ void by_tiny_frame_parse_uart_handle(uint8_t buff)
|
||||
void by_tiny_frame_parse_timer_handle(void)
|
||||
{
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
if (listern_flag) {
|
||||
listern_timevia++;
|
||||
if (listen_flag) {
|
||||
listen_timevia++;
|
||||
} else {
|
||||
listern_timevia = 0;
|
||||
listen_timevia = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -104,15 +104,15 @@ void by_tiny_frame_parse_run(void)
|
||||
{
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
if (0 == listern_flag) {
|
||||
if (0 == listen_flag) {
|
||||
return;
|
||||
} else {
|
||||
if (listern_timeout <= listern_timevia) {
|
||||
if (listen_timeout <= listen_timevia) {
|
||||
// 接收超时,停止监听
|
||||
parse_done_handle(frame_now, 1);
|
||||
by_tiny_frame_parse_end_listern();
|
||||
by_tiny_frame_parse_end_listen();
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("by_tf_listern timeout\r\n");
|
||||
printf("by_tf_listen timeout\r\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -129,13 +129,13 @@ void by_tiny_frame_parse_run(void)
|
||||
#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))
|
||||
if (!by_tiny_frame_parse_listening(&frame_now, listen_slave_id, buffer_out))
|
||||
#endif
|
||||
{
|
||||
if (!by_tiny_frame_parse_crc(&frame_now)) {
|
||||
|
||||
// 接收成功后停止监听
|
||||
by_tiny_frame_parse_end_listern();
|
||||
by_tiny_frame_parse_end_listen();
|
||||
// 解析成功回调
|
||||
parse_done_handle(frame_now, 0);
|
||||
#if (BY_TF_DEBUG)
|
||||
@@ -169,7 +169,7 @@ uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s)
|
||||
}
|
||||
|
||||
// 校验错误则直接结束监听
|
||||
by_tiny_frame_parse_end_listern();
|
||||
by_tiny_frame_parse_end_listen();
|
||||
parse_done_handle(frame_now, 1);
|
||||
|
||||
return 1;
|
||||
@@ -177,16 +177,22 @@ uint8_t by_tiny_frame_parse_crc(by_tf_parse_frame_t *frame_s)
|
||||
|
||||
void by_tiny_frame_parse_handle_register(by_tf_parse_done_handle_func func)
|
||||
{
|
||||
// FIXME 监听过程中应不允许更改
|
||||
// FIXME 未校验是否传入非空值,另外假设未执行注册,也会产生非法访问
|
||||
parse_done_handle = func;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_start_listern(void)
|
||||
void by_tiny_frame_parse_start_listen(void)
|
||||
{
|
||||
listern_flag = 1;
|
||||
listen_flag = 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_end_listern(void)
|
||||
void by_tiny_frame_parse_end_listen(void)
|
||||
{
|
||||
listern_flag = 0;
|
||||
listen_flag = 0;
|
||||
}
|
||||
|
||||
void by_tiny_frame_parse_set_listen_slave_id(uint8_t slave_id)
|
||||
{
|
||||
listen_slave_id = slave_id;
|
||||
}
|
||||
Reference in New Issue
Block a user