generated from hulk/gd32f4xx_template_cmake_vscode
Protocol v1.0: add M3 heater switch / M4 target temp (reserved); protocols.md
This commit is contained in:
+77
-2
@@ -63,11 +63,27 @@ static const uint8_t s_report_status_err[] = { 'e','r','r' }; /**< 错误响应
|
||||
|
||||
/** @name M2 连续温度上报状态
|
||||
* @{ */
|
||||
static bool s_temp_report_enabled = false; /**< 连续上报使能(M2 切换) */
|
||||
static uint16_t s_temp_report_period_ms = 500; /**< 上报间隔(ms),M2S<ms> 设置,100~60000 */
|
||||
static bool s_temp_report_enabled = false; /**< 连续上报使能(M2S<ms> 设置) */
|
||||
static uint16_t s_temp_report_period_ms = 500; /**< 上报间隔(ms),100~60000 */
|
||||
static uint16_t s_temp_report_counter = 0; /**< 主循环 10ms 圈计数 */
|
||||
/** @} */
|
||||
|
||||
/** @name M3/M4 加热控制状态(预留:当前仅软件状态,硬件执行体待接入)
|
||||
* @{ */
|
||||
static bool s_heater_on = false; /**< 加热开关状态 */
|
||||
static float s_heater_target = 0.0f; /**< 目标温度(摄氏度,M4S 设定) */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief 加热输出执行体(按开关状态与目标温度驱动加热器件)。
|
||||
* @note TODO: 加热驱动(MOS/PWM/继电器)接入后在此实现真实输出;
|
||||
* 当前 M3/M4 仅维护软件状态(GUI 可先行联调协议)。
|
||||
*/
|
||||
static void heater_apply(void)
|
||||
{
|
||||
/* 占位:接入加热驱动后替换为真实硬件输出 */
|
||||
}
|
||||
|
||||
void system_software_reset(void)
|
||||
{
|
||||
// 确保所有待处理的内存访问完成
|
||||
@@ -338,9 +354,14 @@ static bool __attribute__((unused)) find_parameter_value(const uint8_t *cmd, uin
|
||||
* - M1: 单次查询温度值(payload 为 ASCII 摄氏度,如 "23.8";OPEN/SHRT=故障)
|
||||
* - M2: 查询连续上报状态(payload: "ON <ms>" 或 "OFF")
|
||||
* - M2S<ms>: 设置连续上报间隔(100~60000)并开启;M2S0 停止
|
||||
* - M3: 查询加热状态(payload: "ON" / "OFF")
|
||||
* - M3S1/M3S0: 开启/关闭加热(预留,当前仅软件状态)
|
||||
* - M4: 查询目标温度(payload: ASCII 摄氏度)
|
||||
* - M4S<temp>: 设定目标温度(整数摄氏度,0~200;预留,当前仅软件状态)
|
||||
* - M888: 软件复位
|
||||
* - M999: 输出固件版本号(v<板卡码>.<主>.<次>.<修订>)
|
||||
* - M9999: 进入 OTA 模式(复位进 Bootloader)
|
||||
* 权威帧示例见工程根 protocols.md(脚本生成,勿手算 CRC)。
|
||||
*
|
||||
* 具体业务命令(加热/测温/控温等)待定,在 switch 中按需扩展。
|
||||
*
|
||||
@@ -444,6 +465,60 @@ void handle_command(const uint8_t *frame, uint8_t len) {
|
||||
}
|
||||
return;
|
||||
|
||||
/* ==========================================
|
||||
* M3 加热开关(预留,当前仅软件状态)
|
||||
* M3 : 查询加热状态(payload: "ON" / "OFF")
|
||||
* M3S1 : 开启加热
|
||||
* M3S0 : 关闭加热
|
||||
* 注意:上电默认关闭;看门狗/异常处理策略待控温闭环设计时补充。
|
||||
* ========================================== */
|
||||
case 3u:
|
||||
{
|
||||
uint32_t onoff = 0;
|
||||
|
||||
if (find_parameter_value(&cmd[cmd_index], (uint8_t)(cmd_len - cmd_index), 'S', &onoff)) {
|
||||
if (onoff == 0U || onoff == 1U) {
|
||||
s_heater_on = (onoff == 1U);
|
||||
heater_apply();
|
||||
send_response(RESP_TYPE_OK, s_report_status_ok, sizeof(s_report_status_ok));
|
||||
} else {
|
||||
send_response(RESP_TYPE_PARAM_ERR, s_report_status_err, sizeof(s_report_status_err));
|
||||
}
|
||||
} else {
|
||||
send_response(RESP_TYPE_OK,
|
||||
s_heater_on ? (const uint8_t *)"ON" : (const uint8_t *)"OFF",
|
||||
s_heater_on ? 2U : 3U);
|
||||
}
|
||||
COMMAND_DEBUG("M3 heater %s", s_heater_on ? "ON" : "OFF");
|
||||
}
|
||||
return;
|
||||
|
||||
/* ==========================================
|
||||
* M4 温度设定(预留,当前仅软件状态)
|
||||
* M4 : 查询目标温度(payload: ASCII 摄氏度,如 "120.0")
|
||||
* M4S<temp> : 设定目标温度(整数摄氏度,HEATER_TEMP_MIN~MAX)
|
||||
* ========================================== */
|
||||
case 4u:
|
||||
{
|
||||
uint32_t target = 0;
|
||||
|
||||
if (find_parameter_value(&cmd[cmd_index], (uint8_t)(cmd_len - cmd_index), 'S', &target)) {
|
||||
if (target >= HEATER_TEMP_MIN && target <= HEATER_TEMP_MAX) {
|
||||
s_heater_target = (float)target;
|
||||
heater_apply();
|
||||
send_response(RESP_TYPE_OK, s_report_status_ok, sizeof(s_report_status_ok));
|
||||
} else {
|
||||
send_response(RESP_TYPE_PARAM_ERR, s_report_status_err, sizeof(s_report_status_err));
|
||||
}
|
||||
} else {
|
||||
char target_str[8];
|
||||
uint8_t n = (uint8_t)sprintf(target_str, "%.1f", s_heater_target);
|
||||
send_response(RESP_TYPE_OK, (const uint8_t *)target_str, n);
|
||||
}
|
||||
COMMAND_DEBUG("M4 target: %.1f", s_heater_target);
|
||||
}
|
||||
return;
|
||||
|
||||
/* ==========================================
|
||||
* M888 软件重启命令
|
||||
* ========================================== */
|
||||
|
||||
Reference in New Issue
Block a user