diff --git a/pyproject.toml b/pyproject.toml index 0fbfbb0..6a66322 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "meshcore" -version = "2.2.11" +version = "2.2.12" authors = [ { name="Florent de Lamotte", email="florent@frizoncorrea.fr" }, { name="Alex Wolden", email="awolden@gmail.com" }, diff --git a/src/meshcore/lpp_json_encoder.py b/src/meshcore/lpp_json_encoder.py index 47634a9..0ff67f1 100644 --- a/src/meshcore/lpp_json_encoder.py +++ b/src/meshcore/lpp_json_encoder.py @@ -35,6 +35,25 @@ my_lpp_types = { def lpp_format_val(type, val): + + # Fix signed wrap for LPP Current (type 117) + if type.type == 117 and len(val) >= 1: + v = val[0] + # LPP current resolution is typically 0.001 A over uint16 range (0..65.535 A) + # Reinterpret values above signed max as negative + if v > 32.767: + v -= 65.536 + return round(v, 3) + + # Same for voltage (type 116) + if type.type == 116 and len(val) >= 1: + v = val[0] + # LPP voltage resolution is typically 0.01 V over uint16 range (0..65.535 A) + # Reinterpret values above signed max as negative + if v > 327.67: + v -= 655.36 + return round(v, 2) + if my_lpp_types[type.type][1] is None: return val