generated from hulk/gd32f4xx_template_cmake_vscode
Add M1 single-shot temp query command; NTC trimmed-mean filter
This commit is contained in:
+24
-1
@@ -15,6 +15,7 @@
|
||||
#include "rs485.h"
|
||||
#include "uart.h"
|
||||
#include "systick.h"
|
||||
#include "ntc.h"
|
||||
#include "board_config.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -326,7 +327,8 @@ static bool __attribute__((unused)) find_parameter_value(const uint8_t *cmd, uin
|
||||
* - 无参数命令:M<数字>(如 M999、M888)
|
||||
* - 带参数命令:M<数字>S<参数>(如 M100S123,参数为十进制)
|
||||
*
|
||||
* 支持的命令(FilmForge 通用骨架):
|
||||
* 支持的命令(FilmForge):
|
||||
* - M1: 单次查询温度值(payload 为 ASCII 摄氏度,如 "23.8";OPEN/SHRT=故障)
|
||||
* - M888: 软件复位
|
||||
* - M999: 输出固件版本号(v<板卡码>.<主>.<次>.<修订>)
|
||||
* - M9999: 进入 OTA 模式(复位进 Bootloader)
|
||||
@@ -368,6 +370,27 @@ void handle_command(const uint8_t *frame, uint8_t len) {
|
||||
cmd_index = (uint8_t)(cmd_index + used_base_cmd); // 更新索引到命令后
|
||||
|
||||
switch (base_cmd) {
|
||||
/* ==========================================
|
||||
* M1 单次查询温度值
|
||||
* ========================================== */
|
||||
case 1u: // M1: 查询当前 NTC 温度,响应 payload 为 ASCII 摄氏度(如 "23.8")
|
||||
{
|
||||
float temp = ntc_read_temperature();
|
||||
char temp_str[8];
|
||||
uint8_t n;
|
||||
|
||||
if (temp <= -274.0f) {
|
||||
n = (uint8_t)sprintf(temp_str, "SHRT"); // PC5 被拉到 GND(短路)
|
||||
} else if (temp <= -273.0f) {
|
||||
n = (uint8_t)sprintf(temp_str, "OPEN"); // PC5 被拉到 VREF(NTC 未连通)
|
||||
} else {
|
||||
n = (uint8_t)sprintf(temp_str, "%.1f", temp);
|
||||
}
|
||||
send_response(RESP_TYPE_OK, (const uint8_t *)temp_str, n);
|
||||
COMMAND_DEBUG("M1 temp query: %s", temp_str);
|
||||
}
|
||||
return;
|
||||
|
||||
/* ==========================================
|
||||
* M888 软件重启命令
|
||||
* ========================================== */
|
||||
|
||||
Reference in New Issue
Block a user