Skip to content

Commit

Permalink
Merge pull request #163 from SaxElectronics/fix_can_filters
Browse files Browse the repository at this point in the history
Fix can filters
  • Loading branch information
christoph2 authored Jul 26, 2024
2 parents 48de168 + 755d390 commit c378bae
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pyxcp/examples/conf_can.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions pyxcp/examples/conf_can.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyxcp/transport/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(),
Expand Down
11 changes: 11 additions & 0 deletions pyxcp/transport/can.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
Expand Down
8 changes: 6 additions & 2 deletions pyxcp/transport/candriver/python_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c378bae

Please sign in to comment.