mirror of https://github.com/rusefi/opendbc.git
Parser: disallow duplicate message checks (#930)
This commit is contained in:
parent
783a892751
commit
034ca989bd
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue