diff --git a/pyxcp/examples/conf_can.json b/pyxcp/examples/conf_can.json index 2b58798..543fe08 100644 --- a/pyxcp/examples/conf_can.json +++ b/pyxcp/examples/conf_can.json @@ -7,6 +7,9 @@ "BAUDRATE_PRESET": true, "CAN_ID_MASTER": 257, "CAN_ID_SLAVE": 258, + "CAN_ID_DAQ0": 5, + "CAN_ID_DAQ1": 6, + "CAN_ID_DAQ2": 7, "CAN_ID_BROADCAST": 256, "MAX_DLC_REQUIRED": false, "BITRATE": 250000, diff --git a/pyxcp/examples/conf_can.toml b/pyxcp/examples/conf_can.toml index 1172d14..461343f 100644 --- a/pyxcp/examples/conf_can.toml +++ b/pyxcp/examples/conf_can.toml @@ -5,6 +5,9 @@ CHANNEL = "0" ACCEPT_VIRTUAL = true CAN_ID_MASTER = 257 CAN_ID_SLAVE = 258 +CAN_ID_DAQ0 = 5 +CAN_ID_DAQ1 = 6 +CAN_ID_DAQ2 = 7 CAN_ID_BROADCAST = 256 MAX_DLC_REQUIRED = false BITRATE = 250000 diff --git a/pyxcp/transport/base.py b/pyxcp/transport/base.py index cdcbcd0..f86fd77 100644 --- a/pyxcp/transport/base.py +++ b/pyxcp/transport/base.py @@ -181,6 +181,9 @@ def __init__(self, config=None, policy: FrameAcquisitionPolicy = None): self.timer_restart_event = threading.Event() self.timing = Timing() self.resQueue = deque() + self.daqQueue = deque() + self.evQueue = deque() + self.servQueue = deque() self.listener = threading.Thread( target=self.listen, args=(), diff --git a/pyxcp/transport/can.py b/pyxcp/transport/can.py index 5464f45..36743c9 100644 --- a/pyxcp/transport/can.py +++ b/pyxcp/transport/can.py @@ -307,6 +307,17 @@ def __init__(self, config=None, policy=None): self.useDefaultListener = self.config.get("CAN_USE_DEFAULT_LISTENER") self.can_id_master = Identifier(self.config.get("CAN_ID_MASTER")) self.can_id_slave = Identifier(self.config.get("CAN_ID_SLAVE")) + self.daq_list_can_ids = [] + # Start from DAQ0 and go upwards + n = 0 + while True: + daq_identifier = self.config.get(f"CAN_ID_DAQ{n}") + if daq_identifier is None: + # Break the loop if no more DAQ identifiers are found + break + self.daq_list_can_ids.append(Identifier(daq_identifier)) + n += 1 # Increment to check for the next DAQ + self.canInterface.loadConfig(config) self.canInterface.init(self, self.dataReceived) # diff --git a/pyxcp/transport/candriver/python_can.py b/pyxcp/transport/candriver/python_can.py index 81b8392..eab4833 100644 --- a/pyxcp/transport/candriver/python_can.py +++ b/pyxcp/transport/candriver/python_can.py @@ -86,8 +86,12 @@ def read(self): except CanError: return None else: - if frame is None or frame.arbitration_id != self.parent.can_id_master.id or not len(frame.data): - return None # Timeout condition. + if frame is None: + return None # Timeout or other condition causing a None frame + + if frame.arbitration_id not in [self.parent.can_id_master.id] + [id_.id for id_ in self.parent.daq_list_can_ids]: + self.parent.logger.debug("Received frame with unexpected arbitration ID: {}".format(frame.arbitration_id)) + return None extended = frame.is_extended_id identifier = can.Identifier.make_identifier(frame.arbitration_id, extended) return can.Frame(