Skip to content

Commit

Permalink
improve update()
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Aug 2, 2024
1 parent 010302e commit 071b620
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions opendbc/can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CANParser {
std::set<uint32_t> update(const std::vector<CanData> &can_data);

protected:
void clearAllValues();
void updateCans(const CanData &can, std::set<uint32_t> &updated_addresses);
void UpdateValid(uint64_t nanos);
};
Expand Down
27 changes: 18 additions & 9 deletions opendbc/can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,34 @@ CANParser::CANParser(int abus, const std::string& dbc_name, bool ignore_checksum
}

std::set<uint32_t> CANParser::update(const std::vector<CanData> &can_data) {
// Clear all_vals in message_states
for (auto &[_, state] : message_states) {
for (auto &vals : state.all_vals) {
vals.clear();
}
clearAllValues();
std::set<uint32_t> updated_addresses;

if (can_data.empty()) {
return updated_addresses;
}

if (first_nanos == 0) {
first_nanos = can_data.front().nanos;
}

std::set<uint32_t> updated_addresses;
for (const auto &c : can_data) {
if (first_nanos == 0) {
first_nanos = c.nanos;
}
last_nanos = std::max(last_nanos, c.nanos);
updateCans(c, updated_addresses);
UpdateValid(last_nanos);
}

return updated_addresses;
}

void CANParser::clearAllValues() {
for (auto &[_, state] : message_states) {
for (auto &vals : state.all_vals) {
vals.clear();
}
}
}

void CANParser::updateCans(const CanData &can, std::set<uint32_t> &updated_addresses) {
//DEBUG("got %zu messages\n", can.frames.size());

Expand Down

0 comments on commit 071b620

Please sign in to comment.