@@ -66,20 +66,32 @@ class Pylontech:
66
66
)
67
67
68
68
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
+ ),
75
88
)
76
89
77
90
module_serial_number_fmt = construct .Struct (
78
91
"CommandValue" / construct .Byte ,
79
92
"ModuleSerialNumber" / JoinBytes (construct .Array (16 , construct .Byte )),
80
93
)
81
94
82
-
83
95
get_values_fmt = construct .Struct (
84
96
"NumberOfModules" / construct .Byte ,
85
97
"Module" / construct .Array (construct .this .NumberOfModules , construct .Struct (
@@ -246,14 +258,14 @@ def get_system_parameters(self, dev_id=None):
246
258
f = self .read_frame ()
247
259
return self .system_parameters_fmt .parse (f .info [1 :])
248
260
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 )
252
264
f = self .read_frame ()
253
265
254
266
print (f .info )
255
267
print (len (f .info ))
256
- ff = self .management_info_fmt .parse (f .info )
268
+ ff = self .management_info_fmt .parse (f .info [ 1 :] )
257
269
print (ff )
258
270
return ff
259
271
0 commit comments