feat(wits): 添加WITS数据包字符串转换功能

- 实现to_string方法将WITS对象转换为字符串格式
- 根据通道映射配置格式化不同类型的字段值
- 支持string、int和float6格式的数据类型转换
- 移除调试日志代码行
This commit is contained in:
2026-03-12 17:27:38 +08:00
parent dc8aed8156
commit e62dda7aed
2 changed files with 27 additions and 0 deletions

View File

@@ -90,6 +90,32 @@ class WitsData:
def __post_init__(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 = [
("0101", "wellid", "string"),