mirror of
https://github.com/syssi/esphome-votronic.git
synced 2025-07-23 04:23:02 +02:00
Fix preamble synchronization (#42)
This commit is contained in:
committed by
GitHub
parent
634964be80
commit
467af8f150
@@ -23,6 +23,7 @@ static const uint8_t VOTRONIC_FRAME_TYPE_BATTERY_COMPUTER_INFO3 = 0xFA;
|
||||
|
||||
static const uint8_t VOTRONIC_FRAME_TYPE_CONTROL_CHARGER = 0x7A; // Incorrect protocol description?
|
||||
static const uint8_t VOTRONIC_FRAME_TYPE_CONTROL_CHARGING_CONVERTER = 0x3A; // Incorrect protocol description?
|
||||
static const uint8_t VOTRONIC_FRAME_TYPE_CONTROL_CHARGING_CONVERTER2 = 0x4A;
|
||||
static const uint8_t VOTRONIC_FRAME_TYPE_CONTROL_BATTERY_COMPUTER = 0xEA;
|
||||
|
||||
static const uint8_t BATTERY_STATUS_SIZE = 8;
|
||||
@@ -65,6 +66,8 @@ void Votronic::loop() {
|
||||
const uint32_t now = millis();
|
||||
|
||||
if (now - this->last_byte_ > this->rx_timeout_) {
|
||||
ESP_LOGVV(TAG, "Buffer cleared due to timeout: %s",
|
||||
format_hex_pretty(&this->rx_buffer_.front(), this->rx_buffer_.size()).c_str());
|
||||
this->rx_buffer_.clear();
|
||||
this->last_byte_ = now;
|
||||
}
|
||||
@@ -75,6 +78,8 @@ void Votronic::loop() {
|
||||
if (this->parse_votronic_byte_(byte)) {
|
||||
this->last_byte_ = now;
|
||||
} else {
|
||||
ESP_LOGVV(TAG, "Buffer cleared due to reset: %s",
|
||||
format_hex_pretty(&this->rx_buffer_.front(), this->rx_buffer_.size()).c_str());
|
||||
this->rx_buffer_.clear();
|
||||
}
|
||||
}
|
||||
@@ -88,11 +93,8 @@ bool Votronic::parse_votronic_byte_(uint8_t byte) {
|
||||
const uint8_t *raw = &this->rx_buffer_[0];
|
||||
const uint8_t frame_len = VOTRONIC_FRAME_LENGTH;
|
||||
|
||||
if (at == 0)
|
||||
return true;
|
||||
|
||||
if (raw[0] != VOTRONIC_FRAME_START) {
|
||||
ESP_LOGW(TAG, "Invalid header");
|
||||
if (at == 0 && raw[0] != VOTRONIC_FRAME_START) {
|
||||
ESP_LOGW(TAG, "Invalid header (0x%02X)", raw[0]);
|
||||
|
||||
// return false to reset buffer
|
||||
return false;
|
||||
@@ -143,6 +145,12 @@ void Votronic::on_votronic_data(const std::vector<uint8_t> &data) {
|
||||
case VOTRONIC_FRAME_TYPE_BATTERY_COMPUTER_INFO3:
|
||||
this->decode_battery_computer_info3_data_(data);
|
||||
break;
|
||||
case VOTRONIC_FRAME_TYPE_CONTROL_CHARGING_CONVERTER2:
|
||||
// Skip empty frame silently
|
||||
// 0xAA 0x4A 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x4A
|
||||
if (data[VOTRONIC_FRAME_LENGTH - 1] == VOTRONIC_FRAME_TYPE_CONTROL_CHARGING_CONVERTER2) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ESP_LOGW(TAG, "Your device is probably not supported. Please create an issue here: "
|
||||
"https://github.com/syssi/esphome-votronic/issues");
|
||||
|
59
tests/esp8266-fake-charger-vbcs-triple.yaml
Normal file
59
tests/esp8266-fake-charger-vbcs-triple.yaml
Normal file
@@ -0,0 +1,59 @@
|
||||
# Battery Charger VBCS 60/40/430 Triple-CI (3246)
|
||||
# See https://github.com/syssi/esphome-votronic/issues/41
|
||||
|
||||
substitutions:
|
||||
name: fake-charger
|
||||
device_description: "Emulate the Display-Link port traffic of a Votronic Charger"
|
||||
tx_pin: GPIO4
|
||||
rx_pin: GPIO5
|
||||
|
||||
esphome:
|
||||
name: ${name}
|
||||
comment: ${device_description}
|
||||
project:
|
||||
name: "syssi.esphome-votronic"
|
||||
version: 2.0.0
|
||||
|
||||
esp8266:
|
||||
board: d1_mini
|
||||
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
|
||||
ota:
|
||||
|
||||
logger:
|
||||
level: DEBUG
|
||||
|
||||
api:
|
||||
reboot_timeout: 0s
|
||||
|
||||
uart:
|
||||
baud_rate: 1000
|
||||
tx_pin: ${tx_pin}
|
||||
rx_pin: ${rx_pin}
|
||||
debug:
|
||||
direction: BOTH
|
||||
dummy_receiver: true
|
||||
|
||||
interval:
|
||||
- interval: 10s
|
||||
then:
|
||||
- uart.write: [0xAA, 0x3A, 0x67, 0x05, 0xDD, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0xA6, 0x56, 0x28, 0x00, 0x58]
|
||||
- uart.write: [0xAA, 0x7A, 0x68, 0x05, 0xDD, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6, 0x56, 0x28, 0x00, 0x16]
|
||||
- uart.write: [0xAA, 0x1A, 0x68, 0x05, 0x74, 0x08, 0x00, 0x00, 0x00, 0xE0, 0xA6, 0x1F, 0x56, 0x22, 0x19, 0x3F]
|
||||
- uart.write: [0xAA, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A]
|
||||
- delay: 2s
|
||||
|
||||
- uart.write: [0xAA, 0x7A, 0x68, 0x05, 0xDE, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6, 0x56, 0x28, 0x00, 0x15]
|
||||
- uart.write: [0xAA, 0x1A, 0x67, 0x05, 0x72, 0x08, 0x00, 0x00, 0x00, 0xE0, 0xA6, 0x1F, 0x56, 0x22, 0x19, 0x36]
|
||||
- uart.write: [0xAA, 0x3A, 0x68, 0x05, 0xDE, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0xA6, 0x56, 0x28, 0x00, 0x54]
|
||||
- uart.write: [0xAA, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A]
|
||||
- delay: 2s
|
||||
|
||||
- uart.write: [0xAA, 0x7A, 0x67, 0x05, 0xDD, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6, 0x56, 0x28, 0x00, 0x19]
|
||||
- uart.write: [0xAA, 0x1A, 0x68, 0x05, 0x72, 0x08, 0x00, 0x00, 0x00, 0xE0, 0xA6, 0x1F, 0x56, 0x22, 0x19, 0x39]
|
||||
- uart.write: [0xAA, 0x3A, 0x67, 0x05, 0xDD, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0xA6, 0x56, 0x28, 0x00, 0x58]
|
||||
- uart.write: [0xAA, 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A]
|
||||
- delay: 2s
|
Reference in New Issue
Block a user