|
发表于 2023-12-20 15:38:11
|
显示全部楼层
本帖最后由 Stm32Motor 于 2023-12-20 15:46 编辑
经过一天努力,终于可以在版言主的GUI界面显示CSA的信息,主要问题是bool定义为uint8_t时与t_name(expr)里的uint8_t,把t_name(expr)里的bool删除t就好。
以下为是发数据的关键代码:
void _dprintf(char* format, ...)
{
va_list arg;
va_start (arg, format);
uint8_t length=vsnprintf((char *)&infobuf[4], 250,format,arg);
va_end (arg);
infobuf[0]=0x84;
infobuf[1]=0x09;
infobuf[2]=0x09;
infobuf[3]=0x40;
CdBusSendData(0x0c,0x00,infobuf,length+4);
}
版言主的github里面各种找,终于打印出来了。
以下为打印CSA的相关代码:
#define t_name(expr) (_Generic((expr),int8_t: "b",uint8_t: "B",int16_t: "h",uint16_t: "H",int32_t: "i", uint32_t: "I",float: "f", char *: "[c]",uint8_t *: "[B]",regr_t: "H,H",regr_t *: "{H,H}",default: "-"))
#define CSA_SHOW(_p, _x, _desc) \
d_debug(" [ 0x%04x, %d, \"%s\", " #_p ", \"" #_x "\", \"%s\" ],\n", \
offsetof(csa_t, _x), sizeof(csa._x), t_name(csa._x), _desc);
#define CSA_SHOW_SUB(_p, _x, _y_t, _y, _desc) \
d_debug(" [ 0x%04x, %d, \"%s\", " #_p ", \"" #_x "_" #_y "\", \"%s\" ],\n", \
offsetof(csa_t, _x) + offsetof(_y_t, _y), sizeof(csa._x._y), t_name(csa._x._y), _desc);
void csa_list_show(void)
{
d_debug("csa_list_show:\n\n");
CSA_SHOW(1, magic_code, "Magic code: 0xcdcd");
CSA_SHOW(1, conf_ver, "Config version");
CSA_SHOW(1, conf_from, "0: default config, 1: all from flash, 2: partly from flash");
CSA_SHOW(0, do_reboot, "Write 1 to reboot");
CSA_SHOW(0, save_conf, "Write 1 to save current config to flash");
d_debug("\n");
CSA_SHOW_SUB(1, bus_cfg, cdctl_cfg_t, mac, "RS-485 port id, range: 0~254");
CSA_SHOW_SUB(0, bus_cfg, cdctl_cfg_t, baud_l, "RS-485 baud rate for first byte");
CSA_SHOW_SUB(0, bus_cfg, cdctl_cfg_t, baud_h, "RS-485 baud rate for follow bytes");
CSA_SHOW_SUB(1, bus_cfg, cdctl_cfg_t, filter_m, "Multicast address");
CSA_SHOW_SUB(0, bus_cfg, cdctl_cfg_t, mode, "0: Arbitration, 1: Break Sync");
CSA_SHOW_SUB(0, bus_cfg, cdctl_cfg_t, tx_permit_len, "Allow send wait time");
CSA_SHOW_SUB(0, bus_cfg, cdctl_cfg_t, max_idle_len, "Max idle wait time for BS mode");
CSA_SHOW_SUB(0, bus_cfg, cdctl_cfg_t, tx_pre_len, " Active TX_EN before TX");
d_debug("\n");
CSA_SHOW(0, dbg_en, "1: Report debug message to host, 0: do not report");
CSA_SHOW_SUB(2, dbg_dst, cdn_sockaddr_t, addr, "Send debug message to this address");
CSA_SHOW_SUB(1, dbg_dst, cdn_sockaddr_t, port, "Send debug message to this port");
d_debug("\n");
CSA_SHOW(1, qxchg_mcast, "Quick-exchange multicast data slice");
CSA_SHOW(1, qxchg_set, "Config the write data components for quick-exchange channel");
CSA_SHOW(1, qxchg_ret, "Config the return data components for quick-exchange channel");
CSA_SHOW(1, qxchg_ro, "Config the return data components for the read only quick-exchange channel");
d_debug("\n");
CSA_SHOW_SUB(2, dbg_raw_dst, cdn_sockaddr_t, addr, "Send raw debug data to this address");
CSA_SHOW_SUB(1, dbg_raw_dst, cdn_sockaddr_t, port, "Send raw debug data to this port");
CSA_SHOW(1, dbg_raw_msk, "Config which raw debug data to be send");
CSA_SHOW(0, dbg_raw_th, "Config raw debug data package size");
CSA_SHOW(1, dbg_raw[0], "Config raw debug for plot0");
CSA_SHOW(1, dbg_raw[1], "Config raw debug for plot1");
d_debug("\n");
CSA_SHOW(0, ref_volt, "Motor driver reference voltage, unit: mV");
CSA_SHOW(0, md_val, "Motor driver md[2:0] pin value");
CSA_SHOW(0, set_home, "Write 1 set home position");
CSA_SHOW(0, drv_mo, "MO pin state of drv chip, for debug");
CSA_SHOW(0, lim_en, "Enable limit switch");
d_debug("\n");
CSA_SHOW(0, tc_pos, "Set target position");
CSA_SHOW(0, tc_speed, "Set target speed");
CSA_SHOW(0, tc_accel, "Set target accel");
CSA_SHOW(0, tc_accel_emg, "Set emergency accel");
d_debug("\n");
CSA_SHOW_SUB(0, pid_pos, pid_i_t, kp, "");
CSA_SHOW_SUB(0, pid_pos, pid_i_t, ki, "");
CSA_SHOW_SUB(0, pid_pos, pid_i_t, kd, "");
CSA_SHOW_SUB(0, pid_pos, pid_i_t, out_min, "");
CSA_SHOW_SUB(0, pid_pos, pid_i_t, out_max, "");
CSA_SHOW(0, cal_pos, "PID input position");
CSA_SHOW(0, cal_speed, "PID output speed");
d_debug("\n");
CSA_SHOW(0, state, "0: disable drive, 1: enable drive");
d_debug("\n");
d_debug(" // --------------- Follows are not writable: -------------------\n");
CSA_SHOW(0, tc_state, "t_curve: 0: stop, 1: run");
CSA_SHOW(0, cur_pos, "Motor current position");
CSA_SHOW(0, tc_vc, "Motor current speed");
CSA_SHOW(0, tc_ac, "Motor current accel");
d_debug("\n");
CSA_SHOW(0, loop_cnt, "Count for plot");
CSA_SHOW(0, string_test, "String test");
d_debug("\n");
}
//编辑原因,修改描述错误 |
|