From 5499633715291d520a9515caae9e96b6cfaa46fb Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 11 Aug 2024 22:16:06 +0200 Subject: [PATCH] Print more errors --- components/jk_bms_ble/jk_bms_ble.cpp | 42 ++++++++++++++++++++++++++++ components/jk_bms_ble/jk_bms_ble.h | 1 + 2 files changed, 43 insertions(+) diff --git a/components/jk_bms_ble/jk_bms_ble.cpp b/components/jk_bms_ble/jk_bms_ble.cpp index 49b04064..2a86dea2 100644 --- a/components/jk_bms_ble/jk_bms_ble.cpp +++ b/components/jk_bms_ble/jk_bms_ble.cpp @@ -43,6 +43,26 @@ static const char *const ERRORS[ERRORS_SIZE] = { "Charge short circuit", // 1000 0000 0000 0000 }; +static const uint8_t ERRORS2_SIZE = 16; +static const char *const ERRORS2[ERRORS_SIZE] = { + "Charge MOS", // 0000 0001 0000 0000 + "Discharge MOS", // 0000 0010 0000 0000 + "GPS Disconnected", // 0000 0100 0000 0000 + "Modify password in time", // 0000 1000 0000 0000 + "Discharge On failed", // 0001 0000 0000 0000 + "Battery overtemperature", // 0010 0000 0000 0000 + "Temperature sensor anomaly", // 0100 0000 0000 0000 + "PLC module anomaly", // 1000 0000 0000 0000 + "Reserved", // 0000 0000 0000 0001 + "Reserved", // 0000 0000 0000 0010 + "Reserved", // 0000 0000 0000 0100 + "Reserved", // 0000 0000 0000 1000 + "Reserved", // 0000 0000 0001 0000 + "Reserved", // 0000 0000 0010 0000 + "Reserved", // 0000 0000 0100 0000 + "Reserved", // 0000 0000 1000 0000 +}; + uint8_t crc(const uint8_t data[], const uint16_t len) { uint8_t crc = 0; for (uint16_t i = 0; i < len; i++) { @@ -453,6 +473,8 @@ void JkBmsBle::decode_jk02_cell_info_(const std::vector &data) { uint16_t raw_errors_bitmask = (uint16_t(data[134 + offset]) << 8) | (uint16_t(data[134 + 1 + offset]) << 0); this->publish_state_(this->errors_bitmask_sensor_, (float) raw_errors_bitmask); this->publish_state_(this->errors_text_sensor_, this->error_bits_to_string_(raw_errors_bitmask)); + ESP_LOGI(TAG, "Errors2: %s (%d)", this->error2_bits_to_string_(jk_get_16bit(136 + offset)).c_str(), + jk_get_16bit(136 + offset)); } else { this->publish_state_(this->power_tube_temperature_sensor_, (float) ((int16_t) jk_get_16bit(134 + offset)) * 0.1f); } @@ -1551,6 +1573,26 @@ std::string JkBmsBle::error_bits_to_string_(const uint16_t mask) { return errors_list; } +std::string JkBmsBle::error2_bits_to_string_(const uint16_t mask) { + bool first = true; + std::string errors_list = ""; + + if (mask) { + for (int i = 0; i < ERRORS2_SIZE; i++) { + if (mask & (1 << i)) { + if (first) { + first = false; + } else { + errors_list.append(";"); + } + errors_list.append(ERRORS2[i]); + } + } + } + + return errors_list; +} + } // namespace jk_bms_ble } // namespace esphome diff --git a/components/jk_bms_ble/jk_bms_ble.h b/components/jk_bms_ble/jk_bms_ble.h index d61ab4da..2530cc05 100644 --- a/components/jk_bms_ble/jk_bms_ble.h +++ b/components/jk_bms_ble/jk_bms_ble.h @@ -386,6 +386,7 @@ class JkBmsBle : public esphome::ble_client::BLEClientNode, public PollingCompon void reset_online_status_tracker_(); void track_online_status_(); std::string error_bits_to_string_(uint16_t bitmask); + std::string error2_bits_to_string_(uint16_t bitmask); std::string format_total_runtime_(const uint32_t value) { int seconds = (int) value;