modify: IN2 DI 输入监听
This commit is contained in:
@@ -10,6 +10,7 @@ AI Box Sophon Adapter 插件
|
||||
6. 视频上传接口 — 盒子告警时录制视频上传(FORM-DATA)
|
||||
7. 告警上报接口 — 违规事件 JSON 报文字动解析入库
|
||||
8. 告警查询接口 — 告警列表/详情查询
|
||||
9. IN2 任务启停开关 — DI 输入有电启动全部任务,断电停止全部任务
|
||||
|
||||
心跳超时机制:
|
||||
- 设备按配置间隔(默认 5 秒)上报心跳
|
||||
@@ -129,6 +130,9 @@ class AiboxSophonAdapterPlugin(Plugin):
|
||||
alarm_fwd_video_url = alarm_fwd_cfg.get("video_upload_url", "http://dg.datagoo.cn:60014/open-api/event-alarm/receiveVideoUpload")
|
||||
alarm_fwd_timeout = alarm_fwd_cfg.get("timeout", 10.0)
|
||||
|
||||
# IN2 数字输入控制任务启停
|
||||
switch_cfg = config.get("task_switch", {})
|
||||
|
||||
# 数据库已由基类初始化(data_dir/aibox_sophon_adapter.db)
|
||||
db = self.db
|
||||
|
||||
@@ -174,6 +178,24 @@ class AiboxSophonAdapterPlugin(Plugin):
|
||||
"[aibox_sophon_adapter] 未检测到 ffmpeg,设备正常通道的 RTSP 拉流将跳过"
|
||||
)
|
||||
|
||||
# IN2 任务启停开关(DI 有电 → 启动全部任务;断电 → 停止全部任务)
|
||||
# 找不到 IN2 状态文件(非盒子环境)时降级为 None,仅警告
|
||||
task_switch = None
|
||||
if switch_cfg.get("enabled", False):
|
||||
from .task_switch import In2TaskSwitch
|
||||
|
||||
task_switch = In2TaskSwitch(
|
||||
api_base=switch_cfg.get("api_base", "http://127.0.0.1"),
|
||||
start_command=switch_cfg.get("start_command", 1),
|
||||
stop_command=switch_cfg.get("stop_command", 0),
|
||||
poll_interval=switch_cfg.get("poll_interval", 0.05),
|
||||
debounce=switch_cfg.get("debounce", 3),
|
||||
active_low=switch_cfg.get("active_low", False),
|
||||
)
|
||||
if not task_switch.start(asyncio.get_running_loop()):
|
||||
task_switch = None
|
||||
set_global_var("task_switch", task_switch)
|
||||
|
||||
logger.info(
|
||||
"[aibox_sophon_adapter] 已初始化: "
|
||||
f"心跳间隔={hb_interval}s, 超时={hb_timeout}s, 检查间隔={check_interval}s"
|
||||
@@ -183,9 +205,10 @@ class AiboxSophonAdapterPlugin(Plugin):
|
||||
self.spawn_task(_check_offline_devices(check_interval))
|
||||
|
||||
async def on_cleanup(self):
|
||||
"""cleanup 时调用:关闭流控制器与外部 MQTT 客户端(db 与后台任务由基类处理)。"""
|
||||
"""cleanup 时调用:关闭流控制器、外部 MQTT 客户端与任务启停开关(db 与后台任务由基类处理)。"""
|
||||
from .global_var import (
|
||||
stream_manager, mqtt_forward, mqtt_subscribe, internal_mqtt,
|
||||
task_switch,
|
||||
)
|
||||
|
||||
if stream_manager is not None:
|
||||
@@ -200,6 +223,9 @@ class AiboxSophonAdapterPlugin(Plugin):
|
||||
if internal_mqtt is not None:
|
||||
await internal_mqtt.stop()
|
||||
|
||||
if task_switch is not None:
|
||||
task_switch.stop()
|
||||
|
||||
logger.info("[aibox_sophon_adapter] 清理完成")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user