Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gekkekoe committed Nov 27, 2024
1 parent d0b1608 commit 0514f5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions components/ecodan/ecodan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace ecodan

if (proxy_uart_ && proxy_uart_->available() > 0) {
proxy_ping();
if (serial_rx(proxy_uart_, proxy_buffer_))
if (serial_rx(proxy_uart_, proxy_buffer_, true))
{
// forward cmds from slave to master
if (uart_)
Expand All @@ -96,7 +96,7 @@ namespace ecodan
}

// if we could not get the sync byte after 4*packet size attemp, we are probably using the wrong baud rate
if (proxy_rx_sync_fail_count > 4*16) {
if (rx_sync_fail_count > 4*16) {
//swap 9600 <-> 2400
int current_baud = proxy_uart_->get_baud_rate();
int new_baud = current_baud == 2400 ? 9600 : 2400;
Expand All @@ -106,7 +106,7 @@ namespace ecodan
proxy_uart_->load_settings();

// reset fail count
proxy_rx_sync_fail_count = 0;
rx_sync_fail_count = 0;
}
}

Expand Down
5 changes: 2 additions & 3 deletions components/ecodan/ecodan.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace ecodan
uart::UARTComponent *proxy_uart_ = nullptr;
Message res_buffer_;
Message proxy_buffer_;
int proxy_rx_sync_fail_count = 0;
int rx_sync_fail_count = 0;

Status status;
float temperatureStep = 0.5f;
Expand All @@ -85,8 +85,7 @@ namespace ecodan

std::queue<Message> cmdQueue;

void resync_rx();
bool serial_rx(uart::UARTComponent *uart, Message& msg);
bool serial_rx(uart::UARTComponent *uart, Message& msg, bool count_sync_errors = false);
bool serial_tx(uart::UARTComponent *uart, Message& msg);

bool dispatch_next_status_cmd();
Expand Down
8 changes: 5 additions & 3 deletions components/ecodan/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ecodan
return true;
}

bool EcodanHeatpump::serial_rx(uart::UARTComponent *uart, Message& msg)
bool EcodanHeatpump::serial_rx(uart::UARTComponent *uart, Message& msg, bool count_sync_errors)
{
uint8_t data;
bool skipping = false;
Expand All @@ -28,15 +28,17 @@ namespace ecodan
// Discard bytes until we see one that might reasonably be
// the first byte of a packet, complaining only once.
if (msg.get_write_offset() == 0 && data != HEADER_MAGIC_A && data != HEADER_MAGIC_B) {
proxy_rx_sync_fail_count++;
if (count_sync_errors)
rx_sync_fail_count++;
if (!skipping) {
ESP_LOGE(TAG, "Dropping serial data '%02X', header magic mismatch", data);
skipping = true;
}
continue;
}
skipping = false;
proxy_rx_sync_fail_count = 0;
if (count_sync_errors)
rx_sync_fail_count = 0;

// Add the byte to the packet.
msg.append_byte(data);
Expand Down

0 comments on commit 0514f5d

Please sign in to comment.