feat(wits): 添加WITS数据包字符串转换功能
- 实现to_string方法将WITS对象转换为字符串格式 - 根据通道映射配置格式化不同类型的字段值 - 支持string、int和float6格式的数据类型转换 - 移除调试日志代码行
This commit is contained in:
@@ -232,6 +232,7 @@ def run_wits_sender(args, deps):
|
|||||||
packet = load_packet_from_file(source_file)
|
packet = load_packet_from_file(source_file)
|
||||||
else:
|
else:
|
||||||
packet = build_wits_packet(build_random_wits_data(deps.config.tms.device_code))
|
packet = build_wits_packet(build_random_wits_data(deps.config.tms.device_code))
|
||||||
|
# logging.info(f"packet: {packet}")
|
||||||
send_packet(sock, packet)
|
send_packet(sock, packet)
|
||||||
logger.info("TX WITS #%s -> %s:%s", seq, host, port)
|
logger.info("TX WITS #%s -> %s:%s", seq, host, port)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
|
|||||||
@@ -90,6 +90,32 @@ class WitsData:
|
|||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
validate_required_wits_fields(self)
|
validate_required_wits_fields(self)
|
||||||
|
|
||||||
|
def to_string(self) -> str:
|
||||||
|
parts = []
|
||||||
|
|
||||||
|
for channel, field_name, field_type in WITS_CHANNEL_MAPPING:
|
||||||
|
value = getattr(self, field_name, None)
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if field_type == "string":
|
||||||
|
formatted = str(value)
|
||||||
|
|
||||||
|
elif field_type == "int":
|
||||||
|
formatted = str(int(value))
|
||||||
|
|
||||||
|
elif field_type == "float6":
|
||||||
|
formatted = f"{float(value):.6f}"
|
||||||
|
|
||||||
|
else:
|
||||||
|
formatted = str(value)
|
||||||
|
|
||||||
|
parts.append(f"{channel}{formatted}")
|
||||||
|
|
||||||
|
return "".join(parts)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WITS_CHANNEL_MAPPING = [
|
WITS_CHANNEL_MAPPING = [
|
||||||
("0101", "wellid", "string"),
|
("0101", "wellid", "string"),
|
||||||
|
|||||||
Reference in New Issue
Block a user