V1.5: 485查询1秒无应答打WARN日志(每次查询有无结果都有日志)

This commit is contained in:
helei 2026-08-22 11:41:14 +08:00
parent 69f698b701
commit caf406d146
2 changed files with 14 additions and 0 deletions

View File

@ -32,6 +32,7 @@ static uint16_t zero_weight = 0; /* ȥƤ
static uint32_t last_query_tick = 0; static uint32_t last_query_tick = 0;
static uint32_t feed_start_tick = 0; /* 投喂开始时刻,用于超时保护 */ static uint32_t feed_start_tick = 0; /* 投喂开始时刻,用于超时保护 */
static uint8_t first_query_sent = 0; /* 首次上电查询已发送 */ static uint8_t first_query_sent = 0; /* 首次上电查询已发送 */
static uint32_t await_reply_tick = 0; /* 查询发出时刻0=无等待中的查询 */
static uint8_t first_query_reported = 0; /* 首次上电有效重量已上报 */ static uint8_t first_query_reported = 0; /* 首次上电有效重量已上报 */
/* 重量异常增加计数 */ /* 重量异常增加计数 */
@ -385,15 +386,27 @@ void feedScaleProcess(void)
if (first_query_sent == 0 || (HAL_GetTick() - last_query_tick) >= query_interval) { if (first_query_sent == 0 || (HAL_GetTick() - last_query_tick) >= query_interval) {
last_query_tick = HAL_GetTick(); last_query_tick = HAL_GetTick();
feed_scale_send_query(); feed_scale_send_query();
await_reply_tick = HAL_GetTick(); /* 标记等待应答1s 无帧打日志 */
if (first_query_sent == 0) { if (first_query_sent == 0) {
first_query_sent = 1; first_query_sent = 1;
log_info("> FEED: 首次查询已发送"); log_info("> FEED: 首次查询已发送");
} }
} }
/* 查询发出后 1s 仍无任何应答帧:打日志(有无应答一目了然) */
if (await_reply_tick && (HAL_GetTick() - await_reply_tick) > 1000u) {
await_reply_tick = 0;
log_warn("> FEED: 查询无应答(秤未接/线序/波特率/站号不对)");
s_last_err = 1;
}
/* 读取 485 返回 */ /* 读取 485 返回 */
len = feed_scale_read_frame(rx_buf, sizeof(rx_buf)); len = feed_scale_read_frame(rx_buf, sizeof(rx_buf));
if (len > 0) { if (len > 0) {
if (!(len == sizeof(RS485_WEIGHT_CMD) &&
memcmp(rx_buf, RS485_WEIGHT_CMD, sizeof(RS485_WEIGHT_CMD)) == 0)) {
await_reply_tick = 0; /* 收到非回声帧:本次查询有应答 */
}
int prc = feed_scale_parse_weight(rx_buf, len, &cur_weight); int prc = feed_scale_parse_weight(rx_buf, len, &cur_weight);
if (prc != -7) { /* -7=回声帧:不影响状态显示 */ if (prc != -7) { /* -7=回声帧:不影响状态显示 */
s_last_err = (prc == 0) ? 0 : (prc == -1 ? 2 : (prc == -2 ? 3 : (prc == -4 ? 4 : (prc == -6 ? 6 : 5)))); s_last_err = (prc == 0) ? 0 : (prc == -1 ? 2 : (prc == -2 ? 3 : (prc == -4 ? 4 : (prc == -6 ? 6 : 5))));

View File

@ -187,3 +187,4 @@
- 修正 485 修复方案:去掉 TX 后清缓冲(会吃掉快速回复的前几个字节), - 修正 485 修复方案:去掉 TX 后清缓冲(会吃掉快速回复的前几个字节),
改为回声帧按内容识别静默丢弃(与查询命令完全一致的帧),合并帧靠 01 03 04 帧头搜索解析 改为回声帧按内容识别静默丢弃(与查询命令完全一致的帧),合并帧靠 01 03 04 帧头搜索解析
- 485 首次查询延迟 3s避开上电窗口防止首个应答被开机繁忙期撞坏 - 485 首次查询延迟 3s避开上电窗口防止首个应答被开机繁忙期撞坏
- 485 查询日志增强:查询发出 1s 无任何应答帧打 WARN无应答有应答则原有 hex/解析日志覆盖