@@ -82,14 +82,6 @@ uint8_t crc(const uint8_t data[], const uint16_t len) {
82
82
return crc;
83
83
}
84
84
85
- uint8_t checksum_xor (const uint8_t data[], const uint16_t len) {
86
- uint8_t checksum = 0 ;
87
- for (uint16_t i = 0 ; i < len; i++) {
88
- checksum = checksum ^ data[i];
89
- }
90
- return checksum;
91
- }
92
-
93
85
void HeltecBalancerBle::dump_config () { // NOLINT(google-readability-function-size,readability-function-size)
94
86
ESP_LOGCONFIG (TAG, " HeltecBalancerBle" );
95
87
LOG_SENSOR (" " , " Minimum Cell Voltage" , this ->min_cell_voltage_sensor_ );
@@ -173,6 +165,30 @@ void HeltecBalancerBle::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt
173
165
this ->parent_ ->address_str ().c_str ());
174
166
break ;
175
167
}
168
+
169
+ // Services and characteristic of a GW-24S4EB, HW-2.8.0, SW-1.1.0, V1.0.0, 20210915 (3C:A5:51:XX:XX:XX)
170
+ //
171
+ // Service UUID: 0x1800
172
+ // start_handle: 0x1 end_handle: 0x7
173
+ // Service UUID: 0xFFE0
174
+ // start_handle: 0x8 end_handle: 0xffff
175
+ // Connected
176
+ // characteristic 0xFFE1, handle 0xa, properties 0x1c
177
+ // characteristic 0xFFE2, handle 0xd, properties 0x1c
178
+ // characteristic 0xFFE3, handle 0x10, properties 0xc
179
+ // cfg_mtu status 0, mtu 244
180
+
181
+ // Services and characteristic of a EK-24S4EB, HW-3.2.0, ZH-1.2.9, V1.2.9, 20230608 (3C:A5:51:XX:XX:XX)
182
+ //
183
+ // Service UUID: 0x1800
184
+ // start_handle: 0x1 end_handle: 0x7
185
+ // Service UUID: 0xFFE0
186
+ // start_handle: 0x8 end_handle: 0xffff
187
+ // Connected
188
+ // characteristic 0xFFE1, handle 0xa, properties 0x1c
189
+ // characteristic 0xFFE2, handle 0xd, properties 0x1c
190
+ // characteristic 0xFFE3, handle 0x10, properties 0xc
191
+ // cfg_mtu status 0, mtu 244
176
192
this ->char_handle_ = chr->handle ;
177
193
178
194
auto status = esp_ble_gattc_register_for_notify (this ->parent ()->get_gattc_if (), this ->parent ()->get_remote_bda (),
@@ -689,23 +705,41 @@ void HeltecBalancerBle::decode_device_info_(const std::vector<uint8_t> &data) {
689
705
690
706
bool HeltecBalancerBle::send_command (uint8_t function, uint8_t command, uint8_t register_address, uint32_t value) {
691
707
// Request device info:
708
+ //
709
+ // (GW-24S4EB, checksum_xor)
692
710
// 0xAA 0x55 0x11 0x01 0x01 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFA 0xFF
711
+ // 0xAA 0x55 0x11 0x01 0x01 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x26 0xFF
712
+ // (EK-24S4EB, crc)
693
713
//
694
714
// Request cell info:
715
+ //
716
+ // (GW-24S4EB, checksum_xor, wrong data_len position)
695
717
// 0xAA 0x55 0x11 0x01 0x02 0x00 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xF9 0xFF
718
+ // 0xAA 0x55 0x11 0x01 0x02 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x27 0xFF
719
+ // (EK-24S4EB, crc)
696
720
//
697
721
// Request factory settings:
722
+ //
723
+ // (GW-24S4EB, checksum_xor)
698
724
// 0xAA 0x55 0x11 0x01 0x03 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xF8 0xFF
699
725
//
700
726
// Request settings:
727
+ //
728
+ // (GW-24S4EB, checksum_xor)
701
729
// 0xAA 0x55 0x11 0x01 0x04 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF
730
+ // 0xAA 0x55 0x11 0x01 0x04 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x29 0xFF
731
+ // (EK-24S4EB, crc)
702
732
//
703
733
// Enable balancer:
734
+ //
735
+ // (GW-24S4EB, checksum_xor)
704
736
// 0xAA 0x55 0x11 0x00 0x05 0x0D 0x14 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xF3 0xFF
705
737
//
706
738
// Disable balancer:
739
+ //
740
+ // (GW-24S4EB, checksum_xor)
707
741
// 0xAA 0x55 0x11 0x00 0x05 0x0D 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xF2 0xFF
708
- uint16_t length = (command == COMMAND_CELL_INFO) ? 0x1400 : 0x0014 ; // Replicate behavior or bug of the android app
742
+ uint16_t length = 0x0014 ;
709
743
710
744
uint8_t frame[20 ];
711
745
frame[0 ] = SOF_REQUEST_BYTE1; // Start sequence
@@ -726,7 +760,7 @@ bool HeltecBalancerBle::send_command(uint8_t function, uint8_t command, uint8_t
726
760
frame[15 ] = 0x00 ; // Data Byte 8
727
761
frame[16 ] = 0x00 ; // Data Byte 9
728
762
frame[17 ] = 0x00 ; // Data Byte 10
729
- frame[18 ] = checksum_xor (frame, sizeof (frame) - 2 );
763
+ frame[18 ] = crc (frame, sizeof (frame) - 2 );
730
764
frame[19 ] = END_OF_FRAME; // End sequence
731
765
732
766
ESP_LOGD (TAG, " Write register: %s" , format_hex_pretty (frame, sizeof (frame)).c_str ());
0 commit comments