Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "update (#133)" #138

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 45 additions & 43 deletions components/victron/victron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,59 +93,61 @@ void VictronComponent::loop() {
ESP_LOGW(TAG, "Last transmission too long ago");
state_ = 0;
}

if (!available())
return;

last_transmission_ = now;
uint8_t c;
read_byte(&c);
if (state_ == 0) {
if (c == '\r' || c == '\n') {
return;
}
label_.clear();
value_.clear();
state_ = 1;
begin_frame_ = now;
}
if (state_ == 1) {
// Start of a ve.direct hex frame
if (c == ':') {
state_ = 3;
return;
}
if (c == '\t') {
state_ = 2;
} else {
label_.push_back(c);
while (available()) {
uint8_t c;
read_byte(&c);
if (state_ == 0) {
if (c == '\r' || c == '\n') {
continue;
}
label_.clear();
value_.clear();
state_ = 1;
}
return;
}
if (state_ == 2) {
if (label_ == "Checksum") {
state_ = 0;
// The checksum is used as end of frame indicator
if (begin_frame_ - this->last_publish_ >= this->throttle_) {
this->last_publish_ = begin_frame_;
this->publishing_ = true;
if (state_ == 1) {
// Start of a ve.direct hex frame
if (c == ':') {
state_ = 3;
continue;
}
if (c == '\t') {
state_ = 2;
} else {
this->publishing_ = false;
label_.push_back(c);
}
return;
continue;
}
if (c == '\r' || c == '\n') {
if (this->publishing_) {
handle_value_();
if (state_ == 2) {
if (label_ == "Checksum") {
state_ = 0;
// The checksum is used as end of frame indicator
if (now - this->last_publish_ >= this->throttle_) {
this->last_publish_ = now;
this->publishing_ = true;
} else {
this->publishing_ = false;
}
continue;
}
if (c == '\r' || c == '\n') {
if (this->publishing_) {
handle_value_();
}
state_ = 0;
} else {
value_.push_back(c);
}
state_ = 0;
} else {
value_.push_back(c);
}
}
// Discard ve.direct hex frame
if (state_ == 3) {
if (c == '\r' || c == '\n') {
state_ = 0;
// Discard ve.direct hex frame
if (state_ == 3) {
if (c == '\r' || c == '\n') {
state_ = 0;
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion components/victron/victron.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ class VictronComponent : public uart::UARTDevice, public Component {
int state_{0};
std::string label_;
std::string value_;
uint32_t begin_frame_{0};
uint32_t last_transmission_{0};
uint32_t last_publish_{0};
uint32_t throttle_{0};
Expand Down
Loading