feat(wits): 添加WITS数据包字符串转换功能
- 实现to_string方法将WITS对象转换为字符串格式 - 根据通道映射配置格式化不同类型的字段值 - 支持string、int和float6格式的数据类型转换 - 移除调试日志代码行
This commit is contained in:
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user