Skip to content

Commit

Permalink
Add JK balancer support
Browse files Browse the repository at this point in the history
Closes: #16
  • Loading branch information
syssi committed Mar 28, 2022
1 parent bae6958 commit 37070de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/jk_bms/jk_bms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void JkBms::on_status_data_(const std::vector<uint8_t> &data) {
}

void JkBms::update() {
this->read_registers(FUNCTION_READ_ALL, ADDRESS_READ_ALL);
this->query_balancer_status();

if (this->enable_fake_traffic_) {
// Start: 0x4E, 0x57, 0x01, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01
Expand Down
17 changes: 17 additions & 0 deletions components/jk_modbus/jk_modbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ bool JkModbus::parse_jk_modbus_byte_(uint8_t byte) {
this->rx_buffer_.push_back(byte);
const uint8_t *raw = &this->rx_buffer_[0];

// @FIXME
return false;

// Byte 0: Start sequence (0x4E)
if (at == 0)
return true;
Expand Down Expand Up @@ -152,5 +155,19 @@ void JkModbus::read_registers(uint8_t function, uint8_t address) {
this->flush();
}

void JkModbus::query_balancer_status() {
uint8_t frame[7];
frame[0] = 0x55;
frame[1] = 0xAA;
frame[2] = 0x01;
frame[3] = 0xFF;
frame[4] = 0x00;
frame[5] = 0x00;
frame[6] = 0xFF;

this->write_array(frame, 7);
this->flush();
}

} // namespace jk_modbus
} // namespace esphome
2 changes: 2 additions & 0 deletions components/jk_modbus/jk_modbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JkModbus : public uart::UARTDevice, public Component {

void send(uint8_t function, uint8_t address, uint8_t value);
void read_registers(uint8_t function, uint8_t address);
void query_balancer_status();

protected:
bool parse_jk_modbus_byte_(uint8_t byte);
Expand All @@ -39,6 +40,7 @@ class JkModbusDevice {

void send(int8_t function, uint8_t address, uint8_t value) { this->parent_->send(function, address, value); }
void read_registers(uint8_t function, uint8_t address) { this->parent_->read_registers(function, address); }
void query_balancer_status() { this->parent_->query_balancer_status(); }

protected:
friend JkModbus;
Expand Down

0 comments on commit 37070de

Please sign in to comment.