From 59500635d0d04dc332aba8052de8e8399db2cc48 Mon Sep 17 00:00:00 2001 From: kyz Date: Tue, 27 Oct 2026 20:25:56 +0800 Subject: [PATCH] add shell cmd to disp realtime data --- APP/BSP/dev_uart.h | 2 +- APP/shell/shell.c | 93 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/APP/BSP/dev_uart.h b/APP/BSP/dev_uart.h index 04627e4..31f92d3 100644 --- a/APP/BSP/dev_uart.h +++ b/APP/BSP/dev_uart.h @@ -25,7 +25,7 @@ #include "SWM341.h" -#define SHELL_ENABLE 0 +#define SHELL_ENABLE 1 /* ============================ Shell 总开关 ============================ * 启用 Shell(SHELL_ENABLE=1) 后, UART1 作为 Shell 交互串口: diff --git a/APP/shell/shell.c b/APP/shell/shell.c index 2d1c5d7..d8f8bc4 100644 --- a/APP/shell/shell.c +++ b/APP/shell/shell.c @@ -19,6 +19,8 @@ #include "csh.h" #include "shell.h" #include "dev_uart.h" +#include "device_model.h" +#include "user_mb.h" #include "SWM341.h" /* 输入环形缓冲大小 (须为 2 的幂) */ @@ -303,4 +305,93 @@ static int cmd_ledoff(int argc, char **argv) return 0; } CSH_SCMD_EXPORT_FULL(cmd_ledoff, "turn off LED (param 1~5)", - "ledoff <1~5>\r\n - turn off the specified LED\r\n"); \ No newline at end of file + "ledoff <1~5>\r\n - turn off the specified LED\r\n"); + +/* ======================== 遥测遥信区打印 ======================== + * 打印"遥测遥信"数据区(寄存器 0~77, realtime_telemetry_t) 全部解析后的值。 + * float 默认按 1 位小数; 电流/功率因数/参考电压等小数位较多字段单独多给几位。 + */ +static int cmd_dump_realtime_telemetry(int argc, char **argv) +{ + realtime_telemetry_t t; + int i; + + (void)argc; + (void)argv; + + if (!user_mb_get_realtime_telemetry(&t)) { + csh_printf(&s_csh, "no telemetry data\r\n"); + return -1; + } + + csh_printf(&s_csh, "==== 遥测遥信 (reg 0~77) ====\r\n"); + csh_printf(&s_csh, "开入状态 : 0x%04X\r\n", t.di); + csh_printf(&s_csh, "开出状态 : 0x%04X\r\n", t.do_); + csh_printf(&s_csh, "事件遥信 : 0x%08lX\r\n", (unsigned long)t.event); + csh_printf(&s_csh, "其它状态 : 0x%04X\r\n", t.other_state); + csh_printf(&s_csh, "自检信息 : 0x%04X\r\n", t.info); + csh_printf(&s_csh, "Ua : %.1f V\r\n", t.ua); + csh_printf(&s_csh, "Ub : %.1f V\r\n", t.ub); + csh_printf(&s_csh, "Uc : %.1f V\r\n", t.uc); + csh_printf(&s_csh, "Ia : %.4f A\r\n", t.ia); + csh_printf(&s_csh, "Ib : %.4f A\r\n", t.ib); + csh_printf(&s_csh, "Ic : %.4f A\r\n", t.ic); + csh_printf(&s_csh, "Il(漏电流) : %.4f A\r\n", t.il); + csh_printf(&s_csh, "I0(零序) : %.4f A\r\n", t.i0); + csh_printf(&s_csh, "U1(正序) : %.1f V\r\n", t.u1); + csh_printf(&s_csh, "U2(负序) : %.1f V\r\n", t.u2); + csh_printf(&s_csh, "I1(正序) : %.4f A\r\n", t.i1); + csh_printf(&s_csh, "I2(负序) : %.4f A\r\n", t.i2); + csh_printf(&s_csh, "功率因数cos : %.3f\r\n", t.cos); + csh_printf(&s_csh, "有功功率P : %d W\r\n", t.p); + csh_printf(&s_csh, "无功功率Q : %d Var\r\n", t.q); + csh_printf(&s_csh, "有功电度Ph : %lu 度\r\n", (unsigned long)t.ph); + csh_printf(&s_csh, "无功电度Qh : %lu 度\r\n", (unsigned long)t.qh); + csh_printf(&s_csh, "动作报告总数 : %u\r\n", t.act_report_total); + csh_printf(&s_csh, "动作报告指针 : %u\r\n", t.act_report_ptr); + csh_printf(&s_csh, "变位报告总数 : %u\r\n", t.chg_report_total); + csh_printf(&s_csh, "变位报告指针 : %u\r\n", t.chg_report_ptr); + csh_printf(&s_csh, "故障录波总数 : %u\r\n", t.fault_wave_total); + csh_printf(&s_csh, "故障录波指针 : %u\r\n", t.fault_wave_ptr); + csh_printf(&s_csh, "PT变比 : %.1f\r\n", t.pt_ratio); + csh_printf(&s_csh, "CT额定电流 : %u A\r\n", t.ct_ratio); + csh_printf(&s_csh, "累计运行时间 : %u h\r\n", t.run_hours); + csh_printf(&s_csh, "KM合闸次数 : %u\r\n", t.km_hz_cnt); + csh_printf(&s_csh, "KM分闸次数 : %u\r\n", t.km_fz_cnt); + csh_printf(&s_csh, "电机运行状态 : %u\r\n", t.motor_state); + csh_printf(&s_csh, "电机起动时间 : %.1f s\r\n", t.motor_start_time); + csh_printf(&s_csh, "起动最大电流 : %.4f A\r\n", t.iq); + csh_printf(&s_csh, "起动次数 : %u\r\n", t.st); + csh_printf(&s_csh, "电流不平衡度 : %.1f %%\r\n", t.i_unbalance); + csh_printf(&s_csh, "最大相频率 : %.2f Hz\r\n", t.max_freq); + csh_printf(&s_csh, "Ia相位 : %u°\r\n", t.ia_phase); + csh_printf(&s_csh, "Ib相位 : %u°\r\n", t.ib_phase); + csh_printf(&s_csh, "Ic相位 : %u°\r\n", t.ic_phase); + csh_printf(&s_csh, "Ua相位 : %u°\r\n", t.ua_phase); + csh_printf(&s_csh, "Ub相位 : %u°\r\n", t.ub_phase); + csh_printf(&s_csh, "Uc相位 : %u°\r\n", t.uc_phase); + csh_printf(&s_csh, "最大相滑差 : %.1f Hz/s\r\n", t.max_slip); + csh_printf(&s_csh, "CPU温度 : %.1f °\r\n", t.cpu_temp); + csh_printf(&s_csh, "参考电压 : %.2f V\r\n", t.vref); + csh_printf(&s_csh, "协议类型码 : %u\r\n", t.proto_type); + csh_printf(&s_csh, "热容量 : %.1f %%\r\n", t.thermal_cap); + csh_printf(&s_csh, "最大温度 : %.1f °\r\n", t.max_temp); + csh_printf(&s_csh, "Ua频率 : %.2f Hz\r\n", t.ua_freq); + csh_printf(&s_csh, "Ub频率 : %.2f Hz\r\n", t.ub_freq); + csh_printf(&s_csh, "Uc频率 : %.2f Hz\r\n", t.uc_freq); + csh_printf(&s_csh, "温度计数值 : %u\r\n", t.temp_cnt_val); + csh_printf(&s_csh, "选配功能 : 0x%08lX\r\n", (unsigned long)t.option.raw); + csh_printf(&s_csh, "起动模式 : %u\r\n", t.start_mode); + csh_printf(&s_csh, "密码 : %u\r\n", t.password); + csh_printf(&s_csh, "显示对比度 : %u\r\n", t.contrast); + csh_printf(&s_csh, "语言 : %u\r\n", t.language); + csh_printf(&s_csh, "电压输入方式 : %u\r\n", t.v_input_mode); + csh_printf(&s_csh, "USB状态 : 0x%08lX\r\n", (unsigned long)t.usb_state); + csh_printf(&s_csh, "重启次数 : %u\r\n", t.reboot_cnt); + for (i = 0; i < 9; i++) + csh_printf(&s_csh, "温度通道[%d] : %.1f °\r\n", i + 1, t.temp_ch[i]); + csh_printf(&s_csh, "最大温度通道数: %u\r\n", t.max_temp_channels); + return 0; +} +CSH_SCMD_EXPORT_ALIAS_FULL(cmd_dump_realtime_telemetry, teli, "dump telemetry data (reg 0~77)", + "teli\r\n - print realtime telemetry data (reg 0~77)\r\n"); \ No newline at end of file -- 2.34.1