Selaa lähdekoodia

1. 支持调试命令

nifangxu 1 kuukausi sitten
vanhempi
commit
e175f3c5c0
8 muutettua tiedostoa jossa 62 lisäystä ja 14 poistoa
  1. 5 1
      LAS.py
  2. 2 2
      common/sys_comm.py
  3. 1 1
      core/alarm_plan.py
  4. 2 2
      db/db_process.py
  5. 1 0
      mqtt/mqtt_process.py
  6. 39 0
      mqtt/mqtt_recv.py
  7. 7 7
      mqtt/mqtt_send.py
  8. 5 1
      mqtt/mqtt_topics.py

+ 5 - 1
LAS.py

@@ -22,7 +22,9 @@ from mqtt.mqtt_process import (
 import db.db_process as db_process
 from db.db_process import db_req_que
 from db.db_process import DBRequest_Async
-from db.db_process import (db_execute_sync, db_execute_async)
+from db.db_process import (
+    db_execute_sync, db_execute_async
+)
 import db.db_sqls as sqls
 
 import device.dev_mng as g_Dev
@@ -107,6 +109,7 @@ def sys_init():
                 sys_comm.g_sys_conf["ssh_host"]    = str(config["windows"]["ssh_host"])
                 sys_comm.g_sys_conf["ssh_port"]    = int(config["windows"]["ssh_port"])
                 mp.MQTT_BROKER = sys_comm.g_sys_conf["server_ip"]
+
             # linux 服务器
             elif sys_comm.g_sys_conf["platform"] == 1:
                 sys_comm.g_sys_conf["host_ip"]     = str(config["linux"]["host_ip"])
@@ -114,6 +117,7 @@ def sys_init():
 
         sys_comm.g_sys_conf["sp_id"] = sys_comm.g_sys_conf["module_name"] + "_" + str(get_utc_time_ms())
 
+
         # 报警配置
         sys_comm.g_sys_conf["alarm_conf"] = sys_comm.alarm_conf
 

+ 2 - 2
common/sys_comm.py

@@ -27,13 +27,13 @@ g_sys_conf = {
     # 数据库相关参数
     "db_host": "localhost",
     "db_username": "root",
-    "db_password": "Hfln@1024",
+    "db_password": "Hfln@147888",
 
     # ssh
     "ssh_host": "119.45.12.173",
     "ssh_port": 22,
     "ssh_username": "root",
-    "ssh_password": "Hfln@667788",
+    "ssh_password": "Hfln@147888",
 }
 
 # 日志配置

+ 1 - 1
core/alarm_plan.py

@@ -236,10 +236,10 @@ class AlarmPlan:
         self.status_update_ts_ = -1   # 状态更新时间,初始值为-1
 
         # 事件触发参数
+        self.event_type_    = event_type    # 事件类型
         self.rect_          = rect        # 检测区域  [left, top, width, height]
         self.threshold_time_    = threshold_time    # 触发时间阈值
         self.merge_time_    = merge_time    # 归并时间窗口
-        self.event_type_    = event_type    # 事件类型
         self.event_attr_    = self.init_event_attr()    # 事件属性
         if self.event_attr_ is None:
             raise ValueError(f"Invalid event_type: {event_type}")

+ 2 - 2
db/db_process.py

@@ -25,7 +25,7 @@ ssh_conf = {
     "ssh_host": "119.45.12.173",
     "ssh_port": 22,
     "ssh_user": "root",
-    "ssh_pwd": "Hfln@667788",
+    "ssh_pwd": "Hfln@147888",
 
 }
 
@@ -34,7 +34,7 @@ db_config = {
     # 数据库相关参数
     "host": "localhost",
     "user": "root",
-    "password": "Hfln@1024",
+    "password": "Hfln@147888",
     "database": "lnxx_dev"
 }
 

+ 1 - 0
mqtt/mqtt_process.py

@@ -236,6 +236,7 @@ class RobustMQTTClient(threading.Thread):
             client.subscribe(TOPICS.dev_tracker_targets)
             client.subscribe(TOPICS.las_alarm_plan_update, qos=2)
             client.subscribe(TOPICS.las_test, qos=2)
+            client.subscribe(TOPICS.las_get_debug_info, qos=0)
             self.connected.set()
         else:
             LOGERR(f"MQTT failed to connect, rc={rc}")

+ 39 - 0
mqtt/mqtt_recv.py

@@ -24,6 +24,7 @@ import device.dev_mng as g_Dev
 from device.dev_mng import (
     Device,
 )
+from core.alarm_plan import AlarmPlan
 
 import core.g_LAS as g_las
 
@@ -213,6 +214,39 @@ def deal_las_test(msg:mqtt.MQTTMessage):
             LOGERR(f"[{frame.filename}:{frame.lineno}] @{frame.name}(), error: {e}")
 
 
+# 获取调试信息
+def deal_get_debug_info(msg:mqtt.MQTTMessage):
+    try:
+        plans_info: list = []
+        plan: AlarmPlan = None
+        plans = g_las.g_alarm_plan_mgr.list_all_plan()
+        for plan in plans:
+            item = {
+                "plan_uuid"     : plan.plan_uuid_,
+                "name"          : plan.name_,
+                "dev_id"        : plan.dev_id_,
+                "dev_name"      : plan.dev_name_,
+                "enable"        : plan.enable_,
+                "event_type"    : plan.event_type_,
+                "threshold_time"    : plan.threshold_time_,
+                "rect"          : plan.rect_,
+                "rect"          : plan.rect_,
+                "param"         : plan.param_
+            }
+            plans_info.append(item)
+
+        mqtt_send.las_debug_info(plans_info)
+
+    except json.JSONDecodeError as e:
+        tb_info = traceback.extract_tb(e.__traceback__)
+        for frame in tb_info:
+            LOGERR(f"[{frame.filename}:{frame.lineno}] @{frame.name}(), error:{e}, {e.doc}")
+    except Exception as e:
+        tb_info = traceback.extract_tb(e.__traceback__)
+        for frame in tb_info:
+            LOGERR(f"[{frame.filename}:{frame.lineno}] @{frame.name}(), error: {e}")
+
+
 # 设备消息分发处理:/dev/#
 def deal_dev_msg(client:mqtt.Client, userdaata, msg:mqtt.MQTTMessage):
     try:
@@ -287,9 +321,14 @@ def deal_las_msg(client:mqtt.Client, userdaata, msg:mqtt.MQTTMessage):
         if (check_topic(topic,Topic_Pattern.las_alarm_plan_update)):
             deal_alarm_plan_update(msg)
 
+        # 测试
         elif (check_topic(topic,Topic_Pattern.las_test)):
             deal_las_test(msg)
 
+        # 获取调试信息
+        elif (check_topic(topic,Topic_Pattern.las_get_debug_info)):
+            deal_get_debug_info(msg)
+
     except json.JSONDecodeError as e:
         tb_info = traceback.extract_tb(e.__traceback__)
         for frame in tb_info:

+ 7 - 7
mqtt/mqtt_send.py

@@ -23,12 +23,6 @@ class MSG_TYPE(Enum):
     MSG_EVENT_EXIST         = 4     # 存在事件
 
 
-def get_target_point(point_cloud:list):
-    return numpy.mean(point_cloud, axis=0).tolist()
-
-
-# 创建消息相关  START
-
 # 准备将消息通过 MQTT 发送
 def send_msg(topic:str, format_json:dict, qos:int=0):
     try:
@@ -94,5 +88,11 @@ def las_test_resp():
     send_msg(TOPICS.las_test_resp, format_json, 2)
 
 
+# 测试
+def las_debug_info(plans_info:list):
+    sp_id   = sys_comm.g_sys_conf["sp_id"]
+    format_json = dict()
+    format_json["plans_info"]       = plans_info
+    format_json["sp_id"]            = sp_id
+    send_msg(TOPICS.las_test_resp, format_json, 2)
 
-# 创建消息相关  END

+ 5 - 1
mqtt/mqtt_topics.py

@@ -52,6 +52,8 @@ class TOPICS(str):
     las_alarm_event         = "/las/alarm_event"            # 上报告警事件
     las_test                = "/las/test"                   # 测试
     las_test_resp           = "/las/test_resp"              # 测试响应
+    las_get_debug_info      = "/las/get_debug_info"         # 获取调试信息
+    las_debug_info          = "/las/debug_info"             # 上报调试信息
 
 
 # topic匹配规则
@@ -112,4 +114,6 @@ class Topic_Pattern(str):
     las_alarm_plan_update   = r"^/las/alarm_plan_update$"       # 告警计划变更
     las_alarm_event         = r"^/las/alarm_eventr$"            # 上报告警事件
     las_test                = r"^/las/test$"                    # 测试
-    las_test_resp           = r"^/las/test_resp$"               # 测试响应
+    las_test_resp           = r"^/las/test_resp$"               # 测试响应
+    las_get_debug_info      = r"^/las/get_debug_info$"          # 测试响应
+    las_debug_info          = r"^/las/debug_info$"              # 测试响应