feat(opt): 光耦输出模式升级 — DLD_OUTPUT_MODE 枚举 + direction_mode 低四位取值

- 新增 DLD_OUTPUT_MODE 枚举: 7种模式(复位/纯地感/纯雷达/或/与/人车混行/ETC)
- g_fm_radar_input_disable → g_output_radar_mode: 从 function_mode bit1 改为 direction_mode & 0x0F
- 仅模式0(复位)已实现, 1~6 暂为 no-op
- BLE 回读字段改为 direction_mode 完整字节
- rs485_700bs.c: 注释块重排(无功能变更)
- docs: 更新开发日志
This commit is contained in:
wangfq
2026-07-28 09:26:09 +08:00
parent ffaa5cd733
commit f5edab43c2
6 changed files with 391 additions and 325 deletions
@@ -430,7 +430,7 @@ static void unpack_pkg_set_cjq_param(uint8_t *pkg, uint8_t len)
g_function_mode = (g_loop_cng_unit.direction_mode >> 4) & 0x0F;
g_fm_700bs_disable = g_function_mode & 0x01;
g_fm_radar_input_disable = (g_function_mode >> 1) & 0x01;
g_output_radar_mode = g_loop_cng_unit.direction_mode & 0x0F;
g_hold_time = g_loop_cng_unit.exist_mode * 20 * 5;
g_freq_sens = (g_loop_cng_unit.sensitvity > 0) ? (g_loop_cng_unit.sensitvity - 1) : 0;
@@ -634,7 +634,7 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len)
tmp_ble_buf[i++] = g_loop_sens_list.total << 4;
tmp_ble_buf[i++] = (g_loop_power_up_state == 0) ? 1 : ((uint8_t)(g_loop_cut_amount));
tmp_ble_buf[i++] = (uint8_t)(g_loop_cut_amount >> 8);
tmp_ble_buf[i++] = g_function_mode;
tmp_ble_buf[i++] = g_loop_cng_unit.direction_mode;
set_response_buf(&g_buf_ble_response, MAGIC_BYTE_DBN_DEFAULT, _cmd, tmp_ble_buf, i);
// PRINT("\nGet_Cjq_param\n");
@@ -42,7 +42,7 @@ extern uint8_t g_loop_power_up_state;
extern uint8_t g_function_mode;
extern uint8_t g_fm_700bs_disable ; //0: 700bs protocol; 1 Modbus protocol
extern uint8_t g_fm_radar_input_disable; //0: radar input enable; 1 reset
extern uint8_t g_output_radar_mode;
/* 新算法状? (DLD154V4B 移植) */
extern uint8_t g_loop_stable; // 稳定期结束标? (0=收敛?, 1=稳定)
@@ -177,6 +177,17 @@ typedef struct _LOOP_ACS_INFO
} Loop_ACS_Info;
extern Loop_ACS_Info g_loop_acs_info;
typedef enum _DLD_OUTPUT_MODE
{
OUTPUT_MODE_LOOP_X_RESET = 0, // 光耦输入为 设备 复位信号,仅地感检测 输出
OUTPUT_MODE_LOOP_ONLY, // 仅地感输出 有效,光耦输入 无效
OUTPUT_MODE_RADAR_ONLY, // 仅光耦输入有效,雷达的输出信号接光耦输入,雷达有输出,车检器的继电器输出;地感信号 无效。
OUTPUT_MODE_LOOP_OR_RADAR, // 地感或雷达,雷达的输出信号接光耦输入,雷达或地感有信号,车检器的继电器输出。
OUTPUT_MODE_LOOP_AND_RADAR, // 地感和雷达,雷达的输出信号接光耦输入,雷达 并且 地感都有信号,车检器继电器才输出。
OUTPUT_MODE_HUMAN_VD_MIX, // 人车混行,雷达的输出信号接光耦输入,刚开始屏蔽雷达信号,当地感检测有车、车检器继电器输出后,车检器对地感 或雷达信号都有效(或的关系),车辆离开地感与雷达检测区域后,三秒内雷达检测有效,车检器继电器立即输出,起到防砸人的效果,连续进入持续防砸、人走落杆。
OUTPUT_MODE_ETC, // ETC模式,雷达的输出信号接光耦输入,刚开始屏蔽雷达信号,当地感检测有车、车检器继电器输出后,车检器对地感 或雷达信号都有效(或的关系),雷达输出断开后会有500ms的防抖超时时间,超时时间结束后,车检器才确定释放继电器。
}DLD_OUTPUT_MODE;
#pragma pack()
@@ -35,7 +35,7 @@
uint8_t g_flag_bt_state = 0; // 0 蓝牙没有连接,1 有蓝牙连接
uint8_t g_function_mode = 0;
uint8_t g_fm_700bs_disable = 0; //0: 700bs protocol; 1 Modbus protocol
uint8_t g_fm_radar_input_disable = 0; //0: radar input enable; 1 reset
uint8_t g_output_radar_mode = 0;
uint32_t g_sys_freq = 0;
uint8_t g_storage_uart_num = 0;
uint32_t g_storage_uart_baud = 19200;//9600;
@@ -340,7 +340,7 @@ void para_store_init(void)
g_freq_level = g_loop_cng_unit.loopFreq_Level - 1;
g_function_mode = g_loop_cng_unit.direction_mode >> 4;
g_fm_700bs_disable = g_function_mode & 0x01;
g_fm_radar_input_disable = (g_function_mode >> 1) & 0x01;
g_output_radar_mode = g_loop_cng_unit.direction_mode & 0x0F;
g_freq_sens = (g_loop_cng_unit.sensitvity > 0) ? (g_loop_cng_unit.sensitvity - 1) : 0;
#ifdef DEBUG
@@ -850,8 +850,8 @@ void cjq_srv(void){
/*===========================================================================
* opt_input_poll — 光耦输入处理
*
* g_fm_radar_input_disable == 0: 雷达输入模式 (暂未实现)
* g_fm_radar_input_disable == 1: 光耦复位模式
* g_output_radar_mode == 0: 光耦复位模式 + 地感模式
* g_output_radar_mode >= 1: 雷达输入模式 (暂未实现)
* 外部干接点接通 → PB10=0 → 计时; 保持 ≥500ms 后断开 → 上升沿 → 芯片复位
*===========================================================================*/
static void opt_input_poll(void)
@@ -859,7 +859,7 @@ static void opt_input_poll(void)
static uint32_t _opt_low_since = 0; // PB10 变低的时刻
static uint8_t _opt_armed = 0; // 低电平已保持 ≥500ms, 等待上升沿
if (g_fm_radar_input_disable == 0) {
if (g_output_radar_mode) {
_opt_low_since = 0;
_opt_armed = 0;
return;
@@ -868,7 +868,7 @@ static void opt_input_poll(void)
if (OPT_IN1 == 0) { // 干接点接通 → 低电平
if (_opt_low_since == 0) {
_opt_low_since = mstick();
} else if (!_opt_armed && (mstick() - _opt_low_since >= 100)) { // 100 tick × 5ms = 500ms
} else if (!_opt_armed && (mstick() - _opt_low_since >= 80)) { // 100 tick × 5ms = 500ms
_opt_armed = 1; // 满足 500ms, 等待上升沿
}
} else { // 干接点断开 → 高电平
@@ -197,6 +197,9 @@ static void rs485_send_heartbeat(void)
rs485_send(buf, 9);
}
void tmp_send(void){
rs485_send_heartbeat();
}
/*===========================================================================
* 帧解析 & 主循环
+52
View File
@@ -4,6 +4,58 @@
---
## 2026-07-28 — 光耦输出模式升级:`DLD_OUTPUT_MODE` 枚举 + `direction_mode` 低四位取值
### 背景
光耦输入功能从原来的「二值化开关」(使能/复位)升级为 **7 种输出模式**
`direction_mode` 字节的低四位选择。`g_fm_radar_input_disable`(来自 `function_mode` bit1
更名为 `g_output_radar_mode`,语义从布尔值变为枚举值。
### `DLD_OUTPUT_MODE` 枚举
```c
typedef enum _DLD_OUTPUT_MODE
{
OUTPUT_MODE_LOOP_X_RESET = 0, // 光耦输入为复位信号,仅地感检测输出
OUTPUT_MODE_LOOP_ONLY, // 仅地感,光耦输入无效
OUTPUT_MODE_RADAR_ONLY, // 仅光耦(雷达输出接光耦输入),地感无效
OUTPUT_MODE_LOOP_OR_RADAR, // 地感或雷达
OUTPUT_MODE_LOOP_AND_RADAR, // 地感和雷达
OUTPUT_MODE_HUMAN_VD_MIX, // 人车混行防砸:有车后光耦/地感"或",离场 3s 内光耦有效持续防砸
OUTPUT_MODE_ETC, // ETC:有车后光耦/地感"或",光耦断开需 500ms 防抖才释放继电器
}DLD_OUTPUT_MODE;
```
### 变量与取值变更
| 项目 | 旧 | 新 |
|------|-----|-----|
| 全局变量名 | `g_fm_radar_input_disable` | `g_output_radar_mode` |
| 符号类型 | bit (0/1) | `uint8_t` (0~6) |
| 取值来源 | `(function_mode >> 1) & 0x01` | `direction_mode & 0x0F` |
| 解析位置 | `peripheral_main.c:para_store_init()` + `dbn_ble_srv.c:unpack_pkg_set_cjq_param()` | 同上 |
| BLE 回读字段 | `g_function_mode` | `g_loop_cng_unit.direction_mode` (完整 8 位) |
| `opt_input_poll` 门控 | `if (g_fm_radar_input_disable == 0)` → 雷达模式 return | `if (g_output_radar_mode)` → 非 0 模式 return |
### 实现状态
| 模式 | 状态 | 说明 |
|------|------|------|
| 0 — LOOP_X_RESET | ✅ 已实现 | PB10 低电平 ≥400ms80 tick×5ms)后上升沿 `SYS_ResetExecute()` 芯片复位 |
| 1~6 | ❌ 未实现 | `opt_input_poll()` 中直接 return |
### 文件变更
| 文件 | 变更 |
|------|------|
| `storage.h` | +`DLD_OUTPUT_MODE` 枚举 (7 种模式) |
| `cmcng.h` | `g_fm_radar_input_disable``g_output_radar_mode` |
| `peripheral_main.c` | 变量更名 + 解析路径改 `direction_mode & 0x0F` |
| `dbn_ble_srv.c` | 同上 + BLE 回读改用 `direction_mode` 完整字段 |
---
## 2026-07-22 — BLE 新增 RS485 地址/波特率读写 + 空闲关蓝牙超时 + 功能码细分
### 新增 BLE 命令