|
|
|
|
@ -38,14 +38,47 @@ class DeviceInfoPage(BasePage):
|
|
|
|
|
"""将整数转换为16进制字符串"""
|
|
|
|
|
return f"{value:X}"
|
|
|
|
|
|
|
|
|
|
def format_date(self, date_int):
|
|
|
|
|
"""格式化日期"""
|
|
|
|
|
if date_int == 0:
|
|
|
|
|
def format_timestamp(self, timestamp):
|
|
|
|
|
"""将mktime()生成的时间戳转换为格式化日期时间"""
|
|
|
|
|
if timestamp == 0:
|
|
|
|
|
return "未知"
|
|
|
|
|
year = (date_int >> 16) & 0xFFFF
|
|
|
|
|
month = (date_int >> 8) & 0xFF
|
|
|
|
|
day = date_int & 0xFF
|
|
|
|
|
return f"{year:04d}-{month:02d}-{day:02d}"
|
|
|
|
|
try:
|
|
|
|
|
# mktime()生成的是本地时间的Unix时间戳
|
|
|
|
|
# 使用localtime()转换为本地时间结构
|
|
|
|
|
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
|
|
|
|
|
except (ValueError, OverflowError, OSError):
|
|
|
|
|
return f"无效时间({timestamp})"
|
|
|
|
|
|
|
|
|
|
def parse_datetime_to_timestamp(self, datetime_str):
|
|
|
|
|
"""将日期时间字符串解析为时间戳"""
|
|
|
|
|
if not datetime_str or datetime_str == "未知":
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# 支持多种日期时间格式
|
|
|
|
|
formats = [
|
|
|
|
|
"%Y-%m-%d %H:%M:%S",
|
|
|
|
|
"%Y/%m/%d %H:%M:%S",
|
|
|
|
|
"%Y-%m-%d",
|
|
|
|
|
"%Y/%m/%d"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for fmt in formats:
|
|
|
|
|
try:
|
|
|
|
|
time_struct = time.strptime(datetime_str, fmt)
|
|
|
|
|
return int(time.mktime(time_struct))
|
|
|
|
|
except ValueError:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# 如果所有格式都失败,尝试解析为纯数字(时间戳)
|
|
|
|
|
try:
|
|
|
|
|
return int(datetime_str)
|
|
|
|
|
except ValueError:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"解析日期时间失败: {e}")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def format_runtime(self, seconds):
|
|
|
|
|
"""格式化运行时间"""
|
|
|
|
|
@ -107,6 +140,8 @@ class DeviceInfoPage(BasePage):
|
|
|
|
|
{"label": "网关", "attr": "gw", "type": "entry", "readonly": False},
|
|
|
|
|
{"label": "后台端口", "attr": "csg_port", "type": "spin", "args": (1, 65535), "readonly": False},
|
|
|
|
|
{"label": "后台IP", "attr": "csg_ipv4", "type": "entry", "readonly": False},
|
|
|
|
|
{"label": "出厂日期", "attr": "factory_date", "type": "entry", "readonly": False},
|
|
|
|
|
{"label": "部署日期", "attr": "deployment_date", "type": "entry", "readonly": False},
|
|
|
|
|
|
|
|
|
|
# 右列 - 只读字段
|
|
|
|
|
{"label": "MAC地址", "attr": "mac", "type": "entry", "readonly": True},
|
|
|
|
|
@ -114,8 +149,6 @@ class DeviceInfoPage(BasePage):
|
|
|
|
|
{"label": "编译时间", "attr": "app_compile_time", "type": "entry", "readonly": True},
|
|
|
|
|
{"label": "硬件版本", "attr": "hardware_version", "type": "entry", "readonly": True},
|
|
|
|
|
{"label": "FPGA版本", "attr": "fpga_version", "type": "entry", "readonly": True},
|
|
|
|
|
{"label": "出厂日期", "attr": "factory_date", "type": "entry", "readonly": True},
|
|
|
|
|
{"label": "部署日期", "attr": "deployment_date", "type": "entry", "readonly": True},
|
|
|
|
|
{"label": "运行时间", "attr": "running_time", "type": "entry", "readonly": True}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
@ -125,6 +158,12 @@ class DeviceInfoPage(BasePage):
|
|
|
|
|
|
|
|
|
|
# 创建按钮
|
|
|
|
|
self.create_buttons()
|
|
|
|
|
|
|
|
|
|
# 添加工厂日期和部署日期的输入提示
|
|
|
|
|
ttk.Label(left_frame, text="格式: YYYY-MM-DD HH:MM:SS",
|
|
|
|
|
font=('Arial', 8), foreground='gray').grid(row=9, column=2, sticky='w', padx=5)
|
|
|
|
|
ttk.Label(left_frame, text="格式: YYYY-MM-DD HH:MM:SS",
|
|
|
|
|
font=('Arial', 8), foreground='gray').grid(row=10, column=2, sticky='w', padx=5)
|
|
|
|
|
|
|
|
|
|
def create_field_controls(self, parent, fields):
|
|
|
|
|
"""创建字段控件"""
|
|
|
|
|
@ -192,6 +231,12 @@ class DeviceInfoPage(BasePage):
|
|
|
|
|
info.csg_port = self.csg_port_var.get()
|
|
|
|
|
info.csg_ipv4 = ip_to_int(self.csg_ipv4_var.get())
|
|
|
|
|
|
|
|
|
|
# 设置时间戳字段
|
|
|
|
|
info.factory_date = self.parse_datetime_to_timestamp(self.factory_date_var.get())
|
|
|
|
|
info.deployment_date = self.parse_datetime_to_timestamp(self.deployment_date_var.get())
|
|
|
|
|
|
|
|
|
|
print(f"设置时间戳 - 出厂日期: {info.factory_date}, 部署日期: {info.deployment_date}")
|
|
|
|
|
|
|
|
|
|
self.tcp_client.send_packet(Cmd.DEVICE_INFO_SET, info.to_bytes())
|
|
|
|
|
|
|
|
|
|
def on_data_received(self, header, body):
|
|
|
|
|
@ -218,10 +263,16 @@ class DeviceInfoPage(BasePage):
|
|
|
|
|
self.app_compile_time_var.set(self.bytes_to_string(info.app_compile_time))
|
|
|
|
|
self.hardware_version_var.set(self.bytes_to_string(info.hardware_version))
|
|
|
|
|
self.fpga_version_var.set(self.bytes_to_string(info.fpga_version))
|
|
|
|
|
self.factory_date_var.set(self.format_date(info.factory_date))
|
|
|
|
|
self.deployment_date_var.set(self.format_date(info.deployment_date))
|
|
|
|
|
|
|
|
|
|
# 使用时间戳转换函数显示mktime()生成的时间
|
|
|
|
|
self.factory_date_var.set(self.format_timestamp(info.factory_date))
|
|
|
|
|
self.deployment_date_var.set(self.format_timestamp(info.deployment_date))
|
|
|
|
|
|
|
|
|
|
self.running_time_var.set(self.format_runtime(info.running_time))
|
|
|
|
|
|
|
|
|
|
# 调试信息,显示原始时间戳值
|
|
|
|
|
print(f"原始时间戳 - 出厂日期: {info.factory_date}, 部署日期: {info.deployment_date}")
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"解析设备信息失败: {e}")
|
|
|
|
|
self.show_error("解析设备信息失败")
|
|
|
|
|
|