Skip to content

Commit

Permalink
New improvement and a v14 vs v15 comparation pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
txubelaxu committed Jun 28, 2024
1 parent f9f2d88 commit 3d1895b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions components/jk_rs485_bms/jk_rs485_bms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ void JkRS485Bms::decode_jk02_cell_info_(const std::vector<uint8_t> &data) {
this->publish_state_(this->battery_total_alarms_active_sensor_, (float) this->battery_total_alarms_active_);
}
this->status_notification_received_ = true;
this->trigger_event("WORKING ! ######################################################################################",02);
this->trigger_event("WORKING ! #####",02);
}

void JkRS485Bms::decode_jk02_settings_(const std::vector<uint8_t> &data) {
Expand Down Expand Up @@ -923,7 +923,7 @@ void JkRS485Bms::decode_jk02_settings_(const std::vector<uint8_t> &data) {
// 294 4 0x00 0x00 0x00 0x00
// 298 1 0x00
// 299 1 0x40 CHECKSUM
this->trigger_event("WORKING ! ######################################################################################",01);
this->trigger_event("WORKING ! #####",01);
}

void JkRS485Bms::update() { this->track_status_online_(); }
Expand Down Expand Up @@ -1022,7 +1022,7 @@ void JkRS485Bms::decode_device_info_(const std::vector<uint8_t> &data) {
this->publish_state_(this->cell_request_charge_voltage_time_sensor_, (float) data[266]*0.1f);
this->publish_state_(this->cell_request_float_voltage_time_sensor_, (float) data[267]*0.1f);

this->trigger_event("WORKING ! ######################################################################################",03);
this->trigger_event("WORKING ! #####",03);
}

void JkRS485Bms::track_status_online_() {
Expand Down
27 changes: 15 additions & 12 deletions components/jk_rs485_sniffer/jk_rs485_sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static const uint32_t TIME_BETWEEN_DEVICE_INFO_REQUESTS_MILLISECONDS = 3600000;

static const uint16_t SILENCE_BEFORE_ACTING_AS_MASTER = 2000;
static const uint16_t SILENCE_BEFORE_REUSING_NETWORK_ACTING_AS_MASTER=400;
static const uint16_t TIME_BEFORE_NEXT_POOLING_MILLISENCONDS=750;
static const uint16_t TIME_BETWEEN_CONSECUTIVE_REQUEST_SENDINGS_TO_SAME_SLAVE=2500;


Expand Down Expand Up @@ -108,24 +109,25 @@ void JkRS485Sniffer::handle_bms_event(int address, std::string event, std::uint8
void JkRS485Sniffer::send_request_to_slave(uint8_t address, uint8_t frame_type){

uint8_t frame[11];
frame[0] = address ; // start sequence
frame[1] = 0x10; // start sequence
frame[2] = 0x16; // start sequence
frame[0] = address ; // start sequence
frame[1] = 0x10; // start sequence
frame[2] = 0x16; // start sequence

if (frame_type==1){
frame[3] = 0x1E; // start sequence
frame[3] = 0x1E; // start sequence
} else if (frame_type==2){
frame[3] = 0x20; // start sequence
frame[3] = 0x20; // start sequence
} else if (frame_type==3){
frame[3] = 0x1C; // start sequence
frame[3] = 0x1C; // start sequence
} else {
return;
}
frame[4] = 0x00; // holding register
frame[5] = 0x01; // size of the value in byte
frame[6] = 0x02;
}
frame[4] = 0x00; // holding register
frame[5] = 0x01; // size of the value in byte
frame[6] = 0x02; // command word: 0x01 (activation), 0x02 (write), 0x03 (read), 0x05 (password), 0x06 (read all)
frame[7] = 0x00;
frame[8] = 0x00;

uint16_t computed_checksum = crc16_c(frame, 9);
frame[9] = ((computed_checksum & 0xFF00)>>8);
frame[10] = ((computed_checksum & 0x00FF)>>0);
Expand Down Expand Up @@ -364,9 +366,10 @@ void JkRS485Sniffer::loop() {
}

if (scan_sent==false){
if (this->nodes_available_number>0){
if (this->nodes_available_number>0 && now-this->last_jk_rs485_pooling_trial_>TIME_BEFORE_NEXT_POOLING_MILLISENCONDS){
this->last_jk_rs485_pooling_trial_=now;
//NORMAL POOLING LOOP AS MASTER
if (this->calculate_next_pooling()==true && now-this->last_jk_rs485_network_activity_>SILENCE_BEFORE_REUSING_NETWORK_ACTING_AS_MASTER){
if (this->calculate_next_pooling()==true){
//ESP_LOGI(TAG, "CALCULATED NEXT POOLING...0x%02X @ %d",this->pooling_index.node_address,this->pooling_index.frame_type);
this->send_request_to_slave(this->pooling_index.node_address,this->pooling_index.frame_type);

Expand Down
1 change: 1 addition & 0 deletions components/jk_rs485_sniffer/jk_rs485_sniffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class JkRS485Sniffer : public uart::UARTDevice, public output::TalkPin, public C
std::vector<uint8_t> rx_buffer_;
uint16_t rx_timeout_{50};
uint32_t last_jk_rs485_network_activity_{0};
uint32_t last_jk_rs485_pooling_trial_{0};
std::vector<JkRS485SnifferDevice *> devices_;

void write_state(bool state) override { this->talk_pin_->digital_write(state); }
Expand Down
Binary file not shown.

0 comments on commit 3d1895b

Please sign in to comment.