diff --git a/templates/listener_tcp.py.tpl b/templates/listener_tcp.py.tpl index 1e3cba5..96531c0 100644 --- a/templates/listener_tcp.py.tpl +++ b/templates/listener_tcp.py.tpl @@ -33,6 +33,9 @@ COMMAND_MAPPINGS = {command_mappings} def process_command(buf): """处理接收到的命令,返回对应的操作指令""" buf = buf.strip() + # 状态查询或心跳检测,返回特殊标记 + if buf == "state=?" or buf == "": + return "status_check" if buf in COMMAND_MAPPINGS: return COMMAND_MAPPINGS[buf] return "nodata" @@ -68,7 +71,13 @@ def main(): operation = process_command(buf) - if operation == "nodata": + if operation == "status_check": + # 状态查询或心跳检测,直接回复 ok + logstr = "===" + datetime_str + " 状态查询/心跳检测,回复 ok" + logging.info(logstr) + print(logstr) + connection.send(b'ok') + elif operation == "nodata": logstr = "===" + datetime_str + " 未知指令: '" + str(buf) + "'" logging.warning(logstr) print(logstr)