feat: 基本完成通信帧主机写操作接口
This commit is contained in:
@@ -1,5 +1,54 @@
|
||||
#include "by_tiny_frame_master_write.h"
|
||||
|
||||
#if defined(BY_TF_DEVICE_MASTER)
|
||||
|
||||
#include "by_tiny_frame_pack.h"
|
||||
#include "by_tiny_frame_parse.h"
|
||||
|
||||
uint8_t write_processing_flag;
|
||||
|
||||
void by_tiny_frame_write_run(void)
|
||||
{
|
||||
}
|
||||
// nothing
|
||||
}
|
||||
|
||||
void by_tiny_frame_write(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_WRITE_CMD_CODE;
|
||||
frame_s.reg_addr = reg_addr;
|
||||
frame_s.data = data;
|
||||
|
||||
// 发送写请求
|
||||
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_write_handle);
|
||||
// 开启响应监听
|
||||
by_tiny_frame_parse_start_listen();
|
||||
|
||||
write_processing_flag = 1;
|
||||
}
|
||||
|
||||
void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
||||
{
|
||||
write_processing_flag = 0;
|
||||
|
||||
#if (BY_TF_DEBUG)
|
||||
printf("****** WRITE 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("write operation failed!!!\r\n");
|
||||
|
||||
} else {
|
||||
printf("write operation successful!!!\r\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user