@@ -65,6 +65,18 @@ static const char *const ERRORS[ERRORS_SIZE] = {
65
65
" Unknown (0x0F)" , // 0x0F
66
66
};
67
67
68
+ static const uint8_t OPERATION_STATUS_SIZE = 8 ;
69
+ static const char *const OPERATION_STATUS[OPERATION_STATUS_SIZE] = {
70
+ " Charging" , // 0x01
71
+ " Discharging" , // 0x02
72
+ " Unknown (0x04)" , // 0x04
73
+ " Unknown (0x08)" , // 0x08
74
+ " Unknown (0x10)" , // 0x10
75
+ " Unknown (0x20)" , // 0x20
76
+ " Unknown (0x40)" , // 0x40
77
+ " Unknown (0x80)" , // 0x80
78
+ };
79
+
68
80
static const uint8_t ROOT_PASSWORD[] = {0x4a , 0x42 , 0x44 , 0x62 , 0x74 , 0x70 , 0x77 , 0x64 ,
69
81
0x21 , 0x40 , 0x23 , 0x32 , 0x30 , 0x32 , 0x33 };
70
82
static const size_t ROOT_PASSWORD_LENGTH = sizeof (ROOT_PASSWORD);
@@ -534,7 +546,7 @@ void JbdBmsBle::on_hardware_info_data_(const std::vector<uint8_t> &data) {
534
546
// 16 2 0x00 0x00 Protection Status
535
547
uint16_t errors_bitmask = jbd_get_16bit (16 );
536
548
this ->publish_state_ (this ->errors_bitmask_sensor_ , (float ) errors_bitmask);
537
- this ->publish_state_ (this ->errors_text_sensor_ , this ->error_bits_to_string_ ( errors_bitmask));
549
+ this ->publish_state_ (this ->errors_text_sensor_ , this ->bitmask_to_string_ (ERRORS, ERRORS_SIZE, errors_bitmask));
538
550
539
551
// 18 1 0x80 Version 0x10 = 1.0, 0x80 = 8.0
540
552
this ->publish_state_ (this ->software_version_sensor_ , (data[18 ] >> 4 ) + ((data[18 ] & 0x0f ) * 0 .1f ));
@@ -546,6 +558,8 @@ void JbdBmsBle::on_hardware_info_data_(const std::vector<uint8_t> &data) {
546
558
uint8_t operation_status = data[20 ];
547
559
this ->mosfet_status_ = operation_status;
548
560
this ->publish_state_ (this ->operation_status_bitmask_sensor_ , operation_status);
561
+ this ->publish_state_ (this ->operation_status_text_sensor_ ,
562
+ this ->bitmask_to_string_ (OPERATION_STATUS, OPERATION_STATUS_SIZE, operation_status));
549
563
this ->publish_state_ (this ->charging_binary_sensor_ , operation_status & JBD_MOS_CHARGE);
550
564
this ->publish_state_ (this ->charging_switch_ , operation_status & JBD_MOS_CHARGE);
551
565
this ->publish_state_ (this ->discharging_binary_sensor_ , operation_status & JBD_MOS_DISCHARGE);
@@ -839,12 +853,13 @@ bool JbdBmsBle::send_command(uint8_t action, uint8_t function) {
839
853
return (status == 0 );
840
854
}
841
855
842
- std::string JbdBmsBle::error_bits_to_string_ (const uint16_t mask) {
856
+ std::string JbdBmsBle::bitmask_to_string_ (const char *const messages[], const uint8_t &messages_size,
857
+ const uint16_t &mask) {
843
858
std::string values = " " ;
844
859
if (mask) {
845
- for (int i = 0 ; i < ERRORS_SIZE ; i++) {
860
+ for (int i = 0 ; i < messages_size ; i++) {
846
861
if (mask & (1 << i)) {
847
- values.append (ERRORS [i]);
862
+ values.append (messages [i]);
848
863
values.append (" ;" );
849
864
}
850
865
}
0 commit comments