feat(DBNMQTTool): 查询响应自动回填输入框 + 主动上报配置
- _on_message 中 ssc_net/iot_net/iot_topic/report_config 查询结果 不再仅显示 JSON,改为调用 _apply_* 方法回填到对应输入框 - 新增「主动上报配置」GroupBox(sensor_type / interval / timeout + 4 开关),支持查询/设置 CMD_REPORT_CONFIG - import 增加 CMD_REPORT_CONFIG / data_report_config
This commit is contained in:
+99
-3
@@ -27,13 +27,13 @@ from dbn_mqtt_tool.mqtt_client import MqttClient, BrokerConfig
|
|||||||
from dbn_mqtt_tool.device_manager import DeviceManager
|
from dbn_mqtt_tool.device_manager import DeviceManager
|
||||||
from dbn_mqtt_tool.protocol import (
|
from dbn_mqtt_tool.protocol import (
|
||||||
CMD_DEV_INFO_QUERY, CMD_SSC_NET_QUERY, CMD_IOT_NET_QUERY,
|
CMD_DEV_INFO_QUERY, CMD_SSC_NET_QUERY, CMD_IOT_NET_QUERY,
|
||||||
CMD_IOT_TOPIC_QUERY, CMD_LOOP_PARAM_QUERY,
|
CMD_IOT_TOPIC_QUERY, CMD_LOOP_PARAM_QUERY, CMD_REPORT_CONFIG,
|
||||||
CMD_SSC_NET_SET, CMD_IOT_NET_SET, CMD_IOT_TOPIC_SET,
|
CMD_SSC_NET_SET, CMD_IOT_NET_SET, CMD_IOT_TOPIC_SET,
|
||||||
CMD_PWD_VERIFY, CMD_PWD_SET, CMD_FACTORY_RESET, CMD_DEVICE_RESET,
|
CMD_PWD_VERIFY, CMD_PWD_SET, CMD_FACTORY_RESET, CMD_DEVICE_RESET,
|
||||||
CMD_LOOP_DATA, CMD_EVENT_REPORT, CMD_HEARTBEAT,
|
CMD_LOOP_DATA, CMD_EVENT_REPORT, CMD_HEARTBEAT,
|
||||||
ERROR_MSGS, FREQ_LEVELS, OUTPUT_MODES, EVENT_TYPES,
|
ERROR_MSGS, FREQ_LEVELS, OUTPUT_MODES, EVENT_TYPES,
|
||||||
data_ssc_net_set, data_iot_net_set, data_iot_topic_set,
|
data_ssc_net_set, data_iot_net_set, data_iot_topic_set,
|
||||||
data_pwd_verify, data_pwd_set,
|
data_pwd_verify, data_pwd_set, data_report_config,
|
||||||
build_request, next_msg_id,
|
build_request, next_msg_id,
|
||||||
topic_down, topic_up,
|
topic_down, topic_up,
|
||||||
)
|
)
|
||||||
@@ -281,6 +281,51 @@ class MainWindow(QMainWindow):
|
|||||||
g4_layout.addLayout(btn_row4, 1, 0, 1, 4)
|
g4_layout.addLayout(btn_row4, 1, 0, 1, 4)
|
||||||
layout.addWidget(g4)
|
layout.addWidget(g4)
|
||||||
|
|
||||||
|
# -- 主动上报 --
|
||||||
|
g5 = QGroupBox("主动上报配置 (report_config)")
|
||||||
|
g5_layout = QGridLayout(g5)
|
||||||
|
|
||||||
|
g5_layout.addWidget(QLabel("传感器类型:"), 0, 0)
|
||||||
|
self._edit_report_sensor_type = QSpinBox()
|
||||||
|
self._edit_report_sensor_type.setRange(0, 255)
|
||||||
|
self._edit_report_sensor_type.setValue(12)
|
||||||
|
g5_layout.addWidget(self._edit_report_sensor_type, 0, 1)
|
||||||
|
|
||||||
|
g5_layout.addWidget(QLabel("上报间隔(s):"), 0, 2)
|
||||||
|
self._edit_report_interval = QSpinBox()
|
||||||
|
self._edit_report_interval.setRange(0, 86400)
|
||||||
|
self._edit_report_interval.setValue(5)
|
||||||
|
g5_layout.addWidget(self._edit_report_interval, 0, 3)
|
||||||
|
|
||||||
|
g5_layout.addWidget(QLabel("超时(ms):"), 0, 4)
|
||||||
|
self._edit_report_timeout = QSpinBox()
|
||||||
|
self._edit_report_timeout.setRange(0, 60000)
|
||||||
|
g5_layout.addWidget(self._edit_report_timeout, 0, 5)
|
||||||
|
|
||||||
|
self._chk_report_enable = QCheckBox("启用上报")
|
||||||
|
self._chk_report_enable.setChecked(True)
|
||||||
|
g5_layout.addWidget(self._chk_report_enable, 1, 0)
|
||||||
|
|
||||||
|
self._chk_report_once = QCheckBox("单次上报")
|
||||||
|
g5_layout.addWidget(self._chk_report_once, 1, 1)
|
||||||
|
|
||||||
|
self._chk_report_env = QCheckBox("环境评估")
|
||||||
|
g5_layout.addWidget(self._chk_report_env, 1, 2)
|
||||||
|
|
||||||
|
self._chk_report_ack = QCheckBox("需应答")
|
||||||
|
g5_layout.addWidget(self._chk_report_ack, 1, 3)
|
||||||
|
|
||||||
|
btn_row5 = QHBoxLayout()
|
||||||
|
b7 = QPushButton("查询")
|
||||||
|
b7.clicked.connect(self._query_report_config)
|
||||||
|
b8 = QPushButton("设置")
|
||||||
|
b8.clicked.connect(self._set_report_config)
|
||||||
|
btn_row5.addWidget(b7)
|
||||||
|
btn_row5.addWidget(b8)
|
||||||
|
btn_row5.addStretch()
|
||||||
|
g5_layout.addLayout(btn_row5, 2, 0, 1, 6)
|
||||||
|
layout.addWidget(g5)
|
||||||
|
|
||||||
layout.addStretch()
|
layout.addStretch()
|
||||||
return w
|
return w
|
||||||
|
|
||||||
@@ -780,8 +825,16 @@ class MainWindow(QMainWindow):
|
|||||||
if cmd == CMD_DEV_INFO_QUERY:
|
if cmd == CMD_DEV_INFO_QUERY:
|
||||||
self._devmgr.update_from_dev_info(dev_serial, data)
|
self._devmgr.update_from_dev_info(dev_serial, data)
|
||||||
self._show_json(data)
|
self._show_json(data)
|
||||||
elif cmd in (CMD_SSC_NET_QUERY, CMD_IOT_NET_QUERY, CMD_IOT_TOPIC_QUERY, CMD_LOOP_PARAM_QUERY):
|
elif cmd == CMD_SSC_NET_QUERY:
|
||||||
|
self._apply_ssc_net_data(data)
|
||||||
|
elif cmd == CMD_IOT_NET_QUERY:
|
||||||
|
self._apply_iot_net_data(data)
|
||||||
|
elif cmd == CMD_IOT_TOPIC_QUERY:
|
||||||
|
self._apply_iot_topic_data(data)
|
||||||
|
elif cmd == CMD_LOOP_PARAM_QUERY:
|
||||||
self._show_json({cmd: data})
|
self._show_json({cmd: data})
|
||||||
|
elif cmd == CMD_REPORT_CONFIG:
|
||||||
|
self._apply_report_config_data(data)
|
||||||
else:
|
else:
|
||||||
self._show_json({"error": f"code={code} {pmsg} ({ERROR_MSGS.get(code, '?')})"})
|
self._show_json({"error": f"code={code} {pmsg} ({ERROR_MSGS.get(code, '?')})"})
|
||||||
|
|
||||||
@@ -903,6 +956,35 @@ class MainWindow(QMainWindow):
|
|||||||
topic_sub=self._edit_topic_sub.text(),
|
topic_sub=self._edit_topic_sub.text(),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def _apply_ssc_net_data(self, data: dict):
|
||||||
|
self._edit_ssc_ip.setText(str(data.get("dev_ip", "")))
|
||||||
|
self._edit_ssc_mask.setText(str(data.get("subnet_mask", "")))
|
||||||
|
self._edit_ssc_gw.setText(str(data.get("route_ip", "")))
|
||||||
|
self._edit_ssc_lssc.setText(str(data.get("lssc_ip", "")))
|
||||||
|
self._edit_ssc_dns.setText(str(data.get("dns", "")))
|
||||||
|
self._edit_ssc_port.setText(str(data.get("port", "")))
|
||||||
|
|
||||||
|
def _apply_iot_net_data(self, data: dict):
|
||||||
|
self._edit_iot_host.setText(str(data.get("host", "")))
|
||||||
|
self._edit_iot_port.setText(str(data.get("port", "")))
|
||||||
|
self._edit_iot_cid.setText(str(data.get("client_id", "")))
|
||||||
|
self._edit_iot_user.setText(str(data.get("username", "")))
|
||||||
|
self._edit_iot_pass.setText(str(data.get("password", "")))
|
||||||
|
|
||||||
|
def _apply_iot_topic_data(self, data: dict):
|
||||||
|
self._chk_cid.setChecked(bool(data.get("client_id_enable", True)))
|
||||||
|
self._edit_topic_pub.setText(str(data.get("topic_pub", "")))
|
||||||
|
self._edit_topic_sub.setText(str(data.get("topic_sub", "")))
|
||||||
|
|
||||||
|
def _apply_report_config_data(self, data: dict):
|
||||||
|
self._edit_report_sensor_type.setValue(int(data.get("sensor_type", 12)))
|
||||||
|
self._edit_report_interval.setValue(int(data.get("interval", 5)))
|
||||||
|
self._edit_report_timeout.setValue(int(data.get("timeout", 0)))
|
||||||
|
self._chk_report_enable.setChecked(bool(data.get("enable", True)))
|
||||||
|
self._chk_report_once.setChecked(bool(data.get("once", False)))
|
||||||
|
self._chk_report_env.setChecked(bool(data.get("env_eval", False)))
|
||||||
|
self._chk_report_ack.setChecked(bool(data.get("ack_required", False)))
|
||||||
|
|
||||||
def _do_pwd_verify(self):
|
def _do_pwd_verify(self):
|
||||||
pwd = self._edit_pwd.text()
|
pwd = self._edit_pwd.text()
|
||||||
if not pwd:
|
if not pwd:
|
||||||
@@ -930,6 +1012,20 @@ class MainWindow(QMainWindow):
|
|||||||
if r == QMessageBox.Yes:
|
if r == QMessageBox.Yes:
|
||||||
self._send_cmd(CMD_DEVICE_RESET)
|
self._send_cmd(CMD_DEVICE_RESET)
|
||||||
|
|
||||||
|
def _query_report_config(self):
|
||||||
|
self._send_cmd(CMD_REPORT_CONFIG)
|
||||||
|
|
||||||
|
def _set_report_config(self):
|
||||||
|
self._send_cmd(CMD_REPORT_CONFIG, data_report_config(
|
||||||
|
sensor_type=self._edit_report_sensor_type.value(),
|
||||||
|
enable=self._chk_report_enable.isChecked(),
|
||||||
|
once=self._chk_report_once.isChecked(),
|
||||||
|
env_eval=self._chk_report_env.isChecked(),
|
||||||
|
interval=self._edit_report_interval.value(),
|
||||||
|
ack_required=self._chk_report_ack.isChecked(),
|
||||||
|
timeout=self._edit_report_timeout.value(),
|
||||||
|
))
|
||||||
|
|
||||||
# ================================================================
|
# ================================================================
|
||||||
# UI 更新
|
# UI 更新
|
||||||
# ================================================================
|
# ================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user