generated from hulk/gd32f4xx_template_cmake_vscode
M2 protocol: replace toggle with idempotent explicit control
This commit is contained in:
+24
-9
@@ -336,6 +336,8 @@ static bool __attribute__((unused)) find_parameter_value(const uint8_t *cmd, uin
|
||||
*
|
||||
* 支持的命令(FilmForge):
|
||||
* - M1: 单次查询温度值(payload 为 ASCII 摄氏度,如 "23.8";OPEN/SHRT=故障)
|
||||
* - M2: 查询连续上报状态(payload: "ON <ms>" 或 "OFF")
|
||||
* - M2S<ms>: 设置连续上报间隔(100~60000)并开启;M2S0 停止
|
||||
* - M888: 软件复位
|
||||
* - M999: 输出固件版本号(v<板卡码>.<主>.<次>.<修订>)
|
||||
* - M9999: 进入 OTA 模式(复位进 Bootloader)
|
||||
@@ -399,18 +401,26 @@ void handle_command(const uint8_t *frame, uint8_t len) {
|
||||
return;
|
||||
|
||||
/* ==========================================
|
||||
* M2 连续温度上报开关(画曲线用)
|
||||
* M2 : 切换连续上报 使能/停止(默认间隔 500ms)
|
||||
* M2S<ms> : 设置上报间隔(100~60000,10ms 步进)并开启上报
|
||||
* M2 连续温度上报控制(画曲线用,全部幂等可重发)
|
||||
* M2 : 查询上报状态(payload: "ON <ms>" 或 "OFF")
|
||||
* M2S<ms> : 100~60000 设置上报间隔(10ms 步进)并开启
|
||||
* M2S0 : 停止上报
|
||||
* 上报帧格式与 M1 响应相同:B5 F0 LEN [ASCII 摄氏度] CRC
|
||||
* 注意:勿用"翻转"语义——链路 ack 丢失重发时翻转类命令会状态错乱,
|
||||
* 本命令族全部为幂等的显式设置。
|
||||
* ========================================== */
|
||||
case 2u:
|
||||
{
|
||||
uint32_t period = 0;
|
||||
|
||||
if (find_parameter_value(&cmd[cmd_index], (uint8_t)(cmd_len - cmd_index), 'S', &period)) {
|
||||
/* 带参数:设置间隔并开启 */
|
||||
if (period >= 100U && period <= 60000U) {
|
||||
if (period == 0U) {
|
||||
/* M2S0: 停止上报 */
|
||||
s_temp_report_enabled = false;
|
||||
s_temp_report_counter = 0;
|
||||
send_response(RESP_TYPE_OK, s_report_status_ok, sizeof(s_report_status_ok));
|
||||
} else if (period >= 100U && period <= 60000U) {
|
||||
/* M2S<ms>: 设置间隔并开启 */
|
||||
s_temp_report_period_ms = (uint16_t)period;
|
||||
s_temp_report_enabled = true;
|
||||
s_temp_report_counter = 0;
|
||||
@@ -419,10 +429,15 @@ void handle_command(const uint8_t *frame, uint8_t len) {
|
||||
send_response(RESP_TYPE_PARAM_ERR, s_report_status_err, sizeof(s_report_status_err));
|
||||
}
|
||||
} else {
|
||||
/* 无参数:切换使能 */
|
||||
s_temp_report_enabled = !s_temp_report_enabled;
|
||||
s_temp_report_counter = 0;
|
||||
send_response(RESP_TYPE_OK, s_report_status_ok, sizeof(s_report_status_ok));
|
||||
/* M2: 查询上报状态 */
|
||||
char state_str[12];
|
||||
uint8_t n;
|
||||
if (s_temp_report_enabled) {
|
||||
n = (uint8_t)sprintf(state_str, "ON %u", s_temp_report_period_ms);
|
||||
} else {
|
||||
n = (uint8_t)sprintf(state_str, "OFF");
|
||||
}
|
||||
send_response(RESP_TYPE_OK, (const uint8_t *)state_str, n);
|
||||
}
|
||||
COMMAND_DEBUG("M2 report %s, period=%ums",
|
||||
s_temp_report_enabled ? "ON" : "OFF", s_temp_report_period_ms);
|
||||
|
||||
Reference in New Issue
Block a user