Parser: disallow duplicate message checks (#930)

This commit is contained in:
Justin Newberry 2023-08-29 10:09:43 -07:00 committed by GitHub
parent 783a892751
commit 034ca989bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -67,7 +67,7 @@ cdef extern from "common.h":
cdef cppclass CANParser:
bool can_valid
bool bus_timeout
CANParser(int, string, vector[pair[uint32_t, int]])
CANParser(int, string, vector[pair[uint32_t, int]]) except +
void update_strings(vector[string]&, vector[SignalValue]&, bool) except +
cdef cppclass CANPacker:

View File

@ -2,6 +2,8 @@
#include <cassert>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <sstream>
#include <unistd.h>
#include <fcntl.h>
@ -98,6 +100,13 @@ CANParser::CANParser(int abus, const std::string& dbc_name, const std::vector<st
bus_timeout_threshold = std::numeric_limits<uint64_t>::max();
for (const auto& [address, frequency] : messages) {
// disallow duplicate message checks
if (message_states.find(address) != message_states.end()) {
std::stringstream is;
is << "Duplicate Message Check: " << address;
throw std::runtime_error(is.str());
}
MessageState &state = message_states[address];
state.address = address;
// state.check_frequency = op.check_frequency,

View File

@ -309,6 +309,15 @@ class TestCanParserPacker(unittest.TestCase):
"CHECKSUM": 0,
})
def test_disallow_duplicate_messages(self):
CANParser("toyota_nodsu_pt_generated", [("ACC_CONTROL", 5)])
with self.assertRaises(RuntimeError):
CANParser("toyota_nodsu_pt_generated", [("ACC_CONTROL", 5), ("ACC_CONTROL", 10)])
with self.assertRaises(RuntimeError):
CANParser("toyota_nodsu_pt_generated", [("ACC_CONTROL", 10), ("ACC_CONTROL", 10)])
if __name__ == "__main__":
unittest.main()