feat: 移植从机通信帧协议
This commit is contained in:
53
app/tiny_frame/by_tiny_frame_master_read.c
Normal file
53
app/tiny_frame/by_tiny_frame_master_read.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "by_tiny_frame_master_read.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
|
||||
uint8_t read_processing_flag;
|
||||
uint32_t *data_p;
|
||||
|
||||
void by_tiny_frame_read_run(void)
|
||||
{
|
||||
}
|
||||
|
||||
void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data)
|
||||
{
|
||||
// 填充数据
|
||||
by_tf_pack_frame_t frame_s;
|
||||
frame_s.slave_id = slave_id;
|
||||
frame_s.cmd = BY_TINY_FRAME_READ_CMD_CODE;
|
||||
frame_s.reg_addr = reg_addr;
|
||||
frame_s.data = 0;
|
||||
|
||||
// 发送写请求
|
||||
by_tiny_frame_pack_send(&frame_s);
|
||||
// 设置响应监听 id
|
||||
by_tiny_frame_parse_set_listen_slave_id(slave_id);
|
||||
// 注册响应监听回调
|
||||
by_tiny_frame_parse_handle_register(by_tiny_frame_read_handle);
|
||||
// 开启响应监听
|
||||
by_tiny_frame_parse_start_listen();
|
||||
|
||||
read_processing_flag = 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
||||
{
|
||||
|
||||
read_processing_flag = 0;
|
||||
if (!status) {
|
||||
*data_p = frame_s.data;
|
||||
}
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("****** READ REGISTER DONE ******\r\n");
|
||||
printf("SLAVE ID: 0x%0.2X\r\n", frame_s.frame[0]);
|
||||
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
||||
if (status) {
|
||||
printf("read operation failed!!!\r\n");
|
||||
} else {
|
||||
printf("read operation successful!!!\r\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user