2024-02-23 21:25:55 +08:00
|
|
|
#include "by_tiny_frame_slave_read_write.h"
|
|
|
|
|
|
2024-02-24 18:32:52 +08:00
|
|
|
#if defined(BY_TF_DEVICE_SLAVE)
|
|
|
|
|
|
|
|
|
|
#include "by_tiny_frame_config.h"
|
2024-02-23 22:25:47 +08:00
|
|
|
#include "by_tiny_frame_parse.h"
|
|
|
|
|
#include "by_tiny_frame_pack.h"
|
|
|
|
|
|
|
|
|
|
void by_tiny_frame_read_write_run(void)
|
|
|
|
|
{
|
|
|
|
|
// empty
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void by_tiny_frame_read_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
|
|
|
|
{
|
|
|
|
|
by_tf_pack_frame_t frame_pack_s;
|
|
|
|
|
|
|
|
|
|
frame_pack_s.slave_id = BY_TF_DEVICE_SLAVE_ADDRESS;
|
|
|
|
|
frame_pack_s.cmd = frame_s.cmd;
|
|
|
|
|
frame_pack_s.reg_addr = frame_s.reg_addr;
|
|
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
|
// 接收出错,一般为 CRC 校验错误
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (frame_s.cmd) {
|
|
|
|
|
case 0x03:
|
|
|
|
|
// 添加查询接口,操作完成后应答
|
|
|
|
|
frame_pack_s.data = 0XFFFFFFFF; // 示例
|
|
|
|
|
by_tiny_frame_pack_send(&frame_pack_s);
|
|
|
|
|
break;
|
|
|
|
|
case 0x06:
|
|
|
|
|
// 添加写入接口,操作完成后应答
|
|
|
|
|
frame_pack_s.data = frame_s.data;
|
|
|
|
|
by_tiny_frame_pack_send(&frame_pack_s);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if (BY_TF_DEBUG)
|
|
|
|
|
printf("****** EXECUTE CMD SUCCESSFUL ******\r\n");
|
|
|
|
|
printf("Device ID: 0x%0.2X\r\n", BY_TF_DEVICE_SLAVE_ADDRESS);
|
2024-02-24 18:32:52 +08:00
|
|
|
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);
|
2024-02-23 22:25:47 +08:00
|
|
|
#endif
|
|
|
|
|
}
|
2024-02-24 18:32:52 +08:00
|
|
|
#endif
|