import struct from dataclasses import dataclass from typing import Optional from config import * @dataclass class PacketHeader: head: int = PKT_HEAD len: int = 0 dev_type_m: int = 0 dev_type_s: int = 0 dev_id: int = 0 cmd_type: int = 0 cmd: int = 0 pkt_id: int = 0 reserve: bytes = bytes(18) HEAD_FORMAT = '> 8) & 0xFF}.{(ip_int >> 16) & 0xFF}.{(ip_int >> 24) & 0xFF}" def ip_to_int(ip_str): parts = ip_str.split('.') return int(parts[0]) | (int(parts[1]) << 8) | (int(parts[2]) << 16) | (int(parts[3]) << 24) def bytes_to_mac(mac_bytes): return ':'.join(f'{b:02x}' for b in mac_bytes) @dataclass class CsgRealImage: channel_id: int = 0 # 通道编号 reserved1: int = 0 # 保留 channel_type: int = 0 # 通道类型 (1: UHF) unit: int = 0 # 单位 (1: dBm; 2: mV) sample_rate: int = 0 # 采样率 (Msps) record_points: int = 0 # 采样点数 century_second: int = 0 # 采样时间世纪秒 nanosecond: int = 0 # 纳秒 cycle_count: int = 0 # 周期数 frequency: int = 0 # 频率 noise: int = 0 # 噪声 sampling_time: int = 0 # 采样时长 reserved3: bytes = bytes(20) # 预留 FORMAT = '