107 lines
3.7 KiB
C
107 lines
3.7 KiB
C
|
|
#include "app_manager.h"
|
|||
|
|
#include "xtell.h"
|
|||
|
|
#include "event.h"
|
|||
|
|
#include "database.h"
|
|||
|
|
#include "system.h"
|
|||
|
|
#include "../Drivers/rf.h"
|
|||
|
|
|
|||
|
|
// 外部全局变量引用
|
|||
|
|
extern SystemState current_state;
|
|||
|
|
extern u32 captured_addr;
|
|||
|
|
extern u8 alarm_sensor_slot;
|
|||
|
|
extern Sensor_Slot xdata sensor_list[16];
|
|||
|
|
|
|||
|
|
// 声明本应用的生命周期回调函数
|
|||
|
|
static void RfMonitorApp_OnStart(void);
|
|||
|
|
static void RfMonitorApp_onRun(void);
|
|||
|
|
static void RfMonitorApp_onClose(void);
|
|||
|
|
static EventResult RfMonitorApp_onEvent(SystemEvent *evt);
|
|||
|
|
|
|||
|
|
// 实体化定义后台射频监控应用控制块
|
|||
|
|
WristbandApp rf_monitor_app = {
|
|||
|
|
0xFE, // 后台应用 ID 设为 0xFE
|
|||
|
|
"RF_Monitor",
|
|||
|
|
RfMonitorApp_OnStart,
|
|||
|
|
RfMonitorApp_onRun,
|
|||
|
|
RfMonitorApp_onClose,
|
|||
|
|
RfMonitorApp_onEvent
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief RfMonitorApp 启动回调
|
|||
|
|
*/
|
|||
|
|
static void RfMonitorApp_OnStart(void)
|
|||
|
|
{
|
|||
|
|
RF_SetMode(1); // 开启天线并设为接收模式
|
|||
|
|
XTELL_LOG("[RF_Monitor] Background RF monitor started.\r\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief RfMonitorApp 轮询主回调
|
|||
|
|
* @details 负责在后台静默轮询物理射频 EV1527 解码器。
|
|||
|
|
* 解码成功后在本地传感器数据库中匹配,并执行布撤防及防区过滤逻辑,
|
|||
|
|
* 匹配通过后一键拉起前台报警应用。
|
|||
|
|
*/
|
|||
|
|
static void RfMonitorApp_onRun(void)
|
|||
|
|
{
|
|||
|
|
u32 rx_addr;
|
|||
|
|
u8 rx_data;
|
|||
|
|
u8 slot;
|
|||
|
|
|
|||
|
|
// 常态对待机下的射频检测与触发过滤逻辑
|
|||
|
|
if (EV1527_Decode(&rx_addr, &rx_data)) {
|
|||
|
|
XTELL_LOG("[RF_Monitor] Decoded Addr=");
|
|||
|
|
XTELL_LOG_HEX32(rx_addr);
|
|||
|
|
XTELL_LOG(", Data=");
|
|||
|
|
XTELL_LOG_HEX8(rx_data);
|
|||
|
|
XTELL_LOG("\r\n");
|
|||
|
|
|
|||
|
|
// 比对收到的 24 位射频源地址是否合法注册在手环本地数据库中
|
|||
|
|
if (Check_Sensor_ID(rx_addr, &slot)) {
|
|||
|
|
u8 sensor_type = sensor_list[slot].type; // 获取注册的设备类型
|
|||
|
|
if (sensor_type < 5) {
|
|||
|
|
// 防区分类过滤与布撤防过滤逻辑:
|
|||
|
|
// - zone == 0,或者烟感(2)、气感(3)、水浸(4) 为 24小时紧急防区,不受当前布防状态影响,强制触发报警;
|
|||
|
|
// - 门磁(0)和红外(1)为普通边界入侵防区,只有当系统处于 STATE_ARMED (布防) 状态时,才触发警报。
|
|||
|
|
if (sensor_list[slot].zone == 0 ||
|
|||
|
|
sensor_type == 2 ||
|
|||
|
|
sensor_type == 3 ||
|
|||
|
|
sensor_type == 4 ||
|
|||
|
|
current_state == STATE_ARMED)
|
|||
|
|
{
|
|||
|
|
// 只有在前台不为紧急 SOS 呼救且当前不处于报警状态时,才执行报警调起
|
|||
|
|
if (AppManager_GetActiveAppID() != APP_ID_SOS &&
|
|||
|
|
AppManager_GetActiveAppID() != APP_ID_ALARM)
|
|||
|
|
{
|
|||
|
|
captured_addr = rx_addr; // 缓存报警地址
|
|||
|
|
alarm_sensor_slot = slot; // 缓存报警槽位号
|
|||
|
|
XTELL_LOG("[RF_Monitor] Intruder ALERT! Waking up alarm app...\r\n");
|
|||
|
|
AppManager_SwitchToForeground(&alarm_app); // 动态切入警报前台
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
XTELL_LOG("[RF_Monitor] Ignored due to DISARMED state.\r\n");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
XTELL_LOG("[RF_Monitor] Unregistered sensor address.\r\n");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief RfMonitorApp 退出清理
|
|||
|
|
*/
|
|||
|
|
static void RfMonitorApp_onClose(void)
|
|||
|
|
{
|
|||
|
|
XTELL_LOG("[RF_Monitor] Background RF monitor closed.\r\n");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief RfMonitorApp 事件处理 (后台应用暂不拦截处理按键事件)
|
|||
|
|
*/
|
|||
|
|
static EventResult RfMonitorApp_onEvent(SystemEvent *evt)
|
|||
|
|
{
|
|||
|
|
(void)evt;
|
|||
|
|
return EVENT_IGNORED;
|
|||
|
|
}
|