feat: 基本完成通信帧主机读操作接口

This commit is contained in:
bmy
2024-02-24 18:53:02 +08:00
parent 85ccbea2f8
commit 785f674ada
3 changed files with 53 additions and 2 deletions

View File

@@ -33,6 +33,7 @@
/** 测试完成后移除 **/ /** 测试完成后移除 **/
#include "by_tiny_frame_parse.h" #include "by_tiny_frame_parse.h"
#include "by_tiny_frame_pack.h" #include "by_tiny_frame_pack.h"
uint32_t data_test;
/** 测试完成后移除 **/ /** 测试完成后移除 **/
void test(by_tf_parse_frame_t frame_s, uint8_t status) void test(by_tf_parse_frame_t frame_s, uint8_t status)
@@ -82,7 +83,8 @@ int main(void)
frame_now.slave_id = 0x0D; frame_now.slave_id = 0x0D;
/** 测试完成后移除 **/ /** 测试完成后移除 **/
by_tiny_frame_write(0x0D, 0x4059, 0x19260817); // by_tiny_frame_write(0x0D, 0x4059, 0x19260817);
by_tiny_frame_read(0x0D, 0x4059, &data_test);
while (1) { while (1) {
Page_Run(); Page_Run();
by_buzzer_run(); by_buzzer_run();

View File

@@ -2,8 +2,52 @@
#if defined(BY_TF_DEVICE_MASTER) #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_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 #endif

View File

@@ -5,9 +5,14 @@
#if defined(BY_TF_DEVICE_MASTER) #if defined(BY_TF_DEVICE_MASTER)
#define BY_TINY_FRAME_READ_CMD_CODE (0x03) #include "by_tiny_frame_parse.h"
#include "by_tiny_frame_pack.h"
#define BY_TINY_FRAME_READ_CMD_CODE (0x03)
extern void by_tiny_frame_read(uint8_t slave_id, uint16_t reg_addr, uint32_t *data);
extern void by_tiny_frame_read_run(void); extern void by_tiny_frame_read_run(void);
extern void by_tiny_frame_read_handle(by_tf_parse_frame_t frame_s, uint8_t status);
#endif #endif
#endif #endif