Files
protocol_convert_software_BD3/processor/telem_processor.py

65 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import struct
import math
"""
2026/3/30 停用
"""
# ===================== 模型配置表 =====================
MODEL_MAP = {
0x00110000: "energy",
0x00440000: "sada",
0x00330000: "ttc",
0x00550000: "intersat",
}
# 内部实现所有拟合/公式,状态量只返回原值不处理
def process_value(value: float, method: str, param: str, ref_cache: dict) -> float:
try:
x = value
if not method:
return x
# 数值拟合 y = ax + b
if method == "数值拟合":
a, b = map(float, param.split(","))
return a * x + b
# 电压1: V = D/255*5.1 D无符号int
elif method == "电压1":
D = int(x)
return D / 255.0 * 5.1
# 电压6: V = D*20/65535 D有符号int
elif method == "电压6":
D = int(x)
return D * 20.0 / 65535.0
# 电压3: V = D*0.000305185 D有符号int
elif method == "电压3":
D = int(x)
return D * 0.000305185
# 电阻拟合1: Rr=1e4; V=D/255*5.1; R=V*Rr/(Vref-V)
elif method == "电阻拟合1":
D = int(x)
V = D / 255.0 * 5.1
ref_name = param.strip()
Vref = ref_cache.get(ref_name, 5.1)
if abs(Vref - V) < 1e-9:
return 0.0
Rr = 10000.0
return V * Rr / (Vref - V)
# 特殊公式8按你文档实现
elif method == "特殊公式8":
# 简化示例:返回原值,可按需求扩展
return x
# 状态量 / 10进制不处理
elif method in ["状态量", "10进制"]:
return x
return x
except:
return value