fix(rs485): 频率从原始 capvd 直接计算,不再依赖 BLE 报告通道

rs485_get_freq(): 用 g_loop_acs_info.loop_capvd + loop1_LPCNT 直接算
freq = FREQ_SYS * LPCNT / capvd + 360

之前 g_loop_acs_info.frequent 只在 usart_packet_processing_acs_loop
里赋值,该路径被 g_dbn_ble_state_acs_enable.enable 门控,
BLE 断开时 freq 永远为 0
This commit is contained in:
wangfq
2026-07-24 09:46:02 +08:00
parent cd42b75f53
commit c8d1bfa4e8
+12 -2
View File
@@ -13,6 +13,7 @@
#include "cmcng.h" #include "cmcng.h"
#include "rs485_700bs.h" #include "rs485_700bs.h"
#include "storage.h" #include "storage.h"
#include "dbn_ble_srv.h"
#include <string.h> #include <string.h>
/*=========================================================================== /*===========================================================================
@@ -86,6 +87,15 @@ static void rs485_send(const uint8_t *data, uint8_t len)
* 命令处理 * 命令处理
*===========================================================================*/ *===========================================================================*/
/* 直接从原始测量值计算线圈频率 (Hz),不依赖 BLE 报告通道 */
static uint32_t rs485_get_freq(void)
{
uint32_t capvd = g_loop_acs_info.loop_capvd; // TMR0 捕获累加值
if (capvd == 0 || loop1_LPCNT == 0) return 0;
/* freq = FREQ_SYS / (capvd / LPCNT) + 360 (补偿值) */
return (uint32_t)((uint64_t)FREQ_SYS * loop1_LPCNT / capvd) + 360;
}
/* 0xFA — 查询有车状态 + 线圈好坏 */ /* 0xFA — 查询有车状态 + 线圈好坏 */
static void handle_query_status(uint8_t addr) static void handle_query_status(uint8_t addr)
{ {
@@ -100,7 +110,7 @@ static void handle_query_status(uint8_t addr)
/* 0x1B — 查询线圈频率 */ /* 0x1B — 查询线圈频率 */
static void handle_query_freq(uint8_t addr) static void handle_query_freq(uint8_t addr)
{ {
uint32_t freq = g_loop_acs_info.frequent; // Hz uint32_t freq = rs485_get_freq(); // Hz
uint8_t buf[6]; uint8_t buf[6];
buf[0] = RSP_FREQ; buf[0] = RSP_FREQ;
buf[1] = (uint8_t)((freq >> 16) & 0xFF); // Fre_1 (MSB) buf[1] = (uint8_t)((freq >> 16) & 0xFF); // Fre_1 (MSB)
@@ -166,7 +176,7 @@ static uint8_t calc_freq_err(uint32_t freq)
static void rs485_send_heartbeat(void) static void rs485_send_heartbeat(void)
{ {
extern uint8_t loop1_LOOP_OK; extern uint8_t loop1_LOOP_OK;
uint32_t freq = g_loop_acs_info.frequent; uint32_t freq = rs485_get_freq();
uint8_t st = g_rs485_id & 0x1F; uint8_t st = g_rs485_id & 0x1F;
if (g_loop_acs_info.car_state) st |= 0x80; // bit7=有车 if (g_loop_acs_info.car_state) st |= 0x80; // bit7=有车