55from .events import Event , EventType
66from cayennelpp import LppFrame , LppData
77from cayennelpp .lpp_type import LppType
8- from meshcore .lpp_json_encoder import lpp_json_encoder , my_lpp_types
8+ from meshcore .lpp_json_encoder import lpp_json_encoder , my_lpp_types , lpp_format_val
99
1010logger = logging .getLogger ("meshcore" )
1111
1212class BinaryReqType (Enum ):
1313 TELEMETRY = 3
14- AMM = 4
14+ MMA = 4
1515
1616def lpp_parse (buf ):
1717 """Parse a given byte string and return as a LppFrame object."""
@@ -24,7 +24,7 @@ def lpp_parse(buf):
2424
2525 return json .loads (json .dumps (LppFrame (lpp_data_list ), default = lpp_json_encoder ))
2626
27- def lpp_parse_amm (buf ):
27+ def lpp_parse_mma (buf ):
2828 i = 0
2929 res = []
3030 while i < len (buf ) and buf [i ] != 0 :
@@ -34,17 +34,17 @@ def lpp_parse_amm(buf):
3434 lpp_type = LppType .get_lpp_type (type )
3535 size = lpp_type .size
3636 i = i + 1
37- min = lpp_type .decode (buf [i :i + size ])
37+ min = lpp_format_val ( lpp_type , lpp_type .decode (buf [i :i + size ]) )
3838 i = i + size
39- max = lpp_type .decode (buf [i :i + size ])
39+ max = lpp_format_val ( lpp_type , lpp_type .decode (buf [i :i + size ]) )
4040 i = i + size
41- avg = lpp_type .decode (buf [i :i + size ])
41+ avg = lpp_format_val ( lpp_type , lpp_type .decode (buf [i :i + size ]) )
4242 i = i + size
4343 res .append ({"channel" :chan ,
4444 "type" :my_lpp_types [type ][0 ],
45- "avg" : avg [ 0 ] ,
46- "min" : min [ 0 ] ,
47- "max" : max [ 0 ] ,
45+ "min" : min ,
46+ "max" : max ,
47+ "avg" : avg ,
4848 })
4949 return res
5050
@@ -74,16 +74,16 @@ async def req_binary (self, contact, request) :
7474 return res2 .payload
7575
7676 async def req_telemetry (self , contact ) :
77- code = BinaryReqType .TELEMETRY
77+ code = BinaryReqType .TELEMETRY . value
7878 req = code .to_bytes (1 , 'little' , signed = False )
7979 res = await self .req_binary (contact , req )
8080 if (res is None ) :
8181 return None
8282 else :
8383 return lpp_parse (bytes .fromhex (res ["data" ]))
8484
85- async def req_amm (self , contact , start , end ) :
86- code = 4
85+ async def req_mma (self , contact , start , end ) :
86+ code = BinaryReqType . MMA . value
8787 req = code .to_bytes (1 , 'little' , signed = False )\
8888 + start .to_bytes (4 , 'little' , signed = False )\
8989 + end .to_bytes (4 , 'little' , signed = False )\
@@ -92,4 +92,4 @@ async def req_amm (self, contact, start, end) :
9292 if (res is None ) :
9393 return None
9494 else :
95- return lpp_parse_amm (bytes .fromhex (res ["data" ])[4 :])
95+ return lpp_parse_mma (bytes .fromhex (res ["data" ])[4 :])
0 commit comments