@@ -66,20 +66,32 @@ class Pylontech:
6666 )
6767
6868 management_info_fmt = construct .Struct (
69- "CommandValue" / construct .Byte ,
70- "ChargeVoltageLimit" / construct .Array (2 , construct .Byte ),
71- "DischargeVoltageLimit" / construct .Array (2 , construct .Byte ),
72- "ChargeCurrentLimit" / construct .Array (2 , construct .Byte ),
73- "DishargeCurrentLimit" / construct .Array (2 , construct .Byte ),
74- "Status" / construct .Byte ,
69+ "ChargeVoltageLimit" / DivideBy1000 (construct .Int16sb ),
70+ "DischargeVoltageLimit" / DivideBy1000 (construct .Int16sb ),
71+ "ChargeCurrentLimit" / ToAmp (construct .Int16sb ),
72+ "DischargeCurrentLimit" / ToAmp (construct .Int16sb ),
73+ "status"
74+ / construct .BitStruct (
75+ "ChargeEnable" / construct .Flag ,
76+ "DischargeEnable" / construct .Flag ,
77+ "ChargeImmediately2" / construct .Flag ,
78+ "ChargeImmediately1" / construct .Flag ,
79+ "FullChargeRequest" / construct .Flag ,
80+ "ShouldCharge"
81+ / construct .Computed (
82+ lambda this : this .ChargeImmediately2
83+ | this .ChargeImmediately1
84+ | this .FullChargeRequest
85+ ),
86+ "_padding" / construct .BitsInteger (3 ),
87+ ),
7588 )
7689
7790 module_serial_number_fmt = construct .Struct (
7891 "CommandValue" / construct .Byte ,
7992 "ModuleSerialNumber" / JoinBytes (construct .Array (16 , construct .Byte )),
8093 )
8194
82-
8395 get_values_fmt = construct .Struct (
8496 "NumberOfModules" / construct .Byte ,
8597 "Module" / construct .Array (construct .this .NumberOfModules , construct .Struct (
@@ -246,14 +258,14 @@ def get_system_parameters(self, dev_id=None):
246258 f = self .read_frame ()
247259 return self .system_parameters_fmt .parse (f .info [1 :])
248260
249- def get_management_info (self ):
250- raise Exception ( 'Dont touch this for now' )
251- self .send_cmd (2 , 0x92 )
261+ def get_management_info (self , dev_id ):
262+ bdevid = "{:02X}" . format ( dev_id ). encode ( )
263+ self .send_cmd (dev_id , 0x92 , bdevid )
252264 f = self .read_frame ()
253265
254266 print (f .info )
255267 print (len (f .info ))
256- ff = self .management_info_fmt .parse (f .info )
268+ ff = self .management_info_fmt .parse (f .info [ 1 :] )
257269 print (ff )
258270 return ff
259271
0 commit comments