63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
#include "by_tiny_frame_slave_read_write.h"
|
|
|
|
#if defined(BY_TF_DEVICE_SLAVE)
|
|
|
|
#include "by_tiny_frame_config.h"
|
|
#include "by_tiny_frame_parse.h"
|
|
#include "by_tiny_frame_pack.h"
|
|
|
|
#include "jj_motion.h"
|
|
#include "jj_param.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; //it's useless just now
|
|
by_tiny_frame_pack_send(&frame_pack_s);
|
|
break;
|
|
case 0x06:
|
|
// 添加写入接口,操作完成后应答
|
|
switch (frame_pack_s.reg_addr) {
|
|
case 0x0000:
|
|
temp_frame_param[0].u32 = frame_s.data;
|
|
in_angle=temp_frame_param[0].f32;
|
|
break;
|
|
case 0x0001:
|
|
in_pos = (float)frame_s.data;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
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);
|
|
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);
|
|
#endif
|
|
}
|
|
#endif
|