|
12 | 12 | import os
|
13 | 13 | import tempfile
|
14 | 14 | from collections import Counter, defaultdict, deque
|
| 15 | +from functools import partial |
15 | 16 | from itertools import cycle
|
16 | 17 | from threading import Event
|
17 | 18 | from warnings import warn
|
@@ -317,7 +318,8 @@ def _process_msg_queue(self, timeout=0.1):
|
317 | 318 | except ics.RuntimeError:
|
318 | 319 | return
|
319 | 320 | for ics_msg in messages:
|
320 |
| - if ics_msg.NetworkID not in self.channels: |
| 321 | + channel = ics_msg.NetworkID | (ics_msg.NetworkID2 << 8) |
| 322 | + if channel not in self.channels: |
321 | 323 | continue
|
322 | 324 |
|
323 | 325 | is_tx = bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG)
|
@@ -364,50 +366,37 @@ def _get_timestamp_for_msg(self, ics_msg):
|
364 | 366 | def _ics_msg_to_message(self, ics_msg):
|
365 | 367 | is_fd = ics_msg.Protocol == ics.SPY_PROTOCOL_CANFD
|
366 | 368 |
|
| 369 | + message_from_ics = partial( |
| 370 | + Message, |
| 371 | + timestamp=self._get_timestamp_for_msg(ics_msg), |
| 372 | + arbitration_id=ics_msg.ArbIDOrHeader, |
| 373 | + is_extended_id=bool(ics_msg.StatusBitField & ics.SPY_STATUS_XTD_FRAME), |
| 374 | + is_remote_frame=bool(ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME), |
| 375 | + is_error_frame=bool(ics_msg.StatusBitField2 & ics.SPY_STATUS2_ERROR_FRAME), |
| 376 | + channel=ics_msg.NetworkID | (ics_msg.NetworkID2 << 8), |
| 377 | + dlc=ics_msg.NumberBytesData, |
| 378 | + is_fd=is_fd, |
| 379 | + is_rx=not bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG), |
| 380 | + ) |
| 381 | + |
367 | 382 | if is_fd:
|
368 | 383 | if ics_msg.ExtraDataPtrEnabled:
|
369 | 384 | data = ics_msg.ExtraDataPtr[: ics_msg.NumberBytesData]
|
370 | 385 | else:
|
371 | 386 | data = ics_msg.Data[: ics_msg.NumberBytesData]
|
372 | 387 |
|
373 |
| - return Message( |
374 |
| - timestamp=self._get_timestamp_for_msg(ics_msg), |
375 |
| - arbitration_id=ics_msg.ArbIDOrHeader, |
| 388 | + return message_from_ics( |
376 | 389 | data=data,
|
377 |
| - dlc=ics_msg.NumberBytesData, |
378 |
| - is_extended_id=bool(ics_msg.StatusBitField & ics.SPY_STATUS_XTD_FRAME), |
379 |
| - is_fd=is_fd, |
380 |
| - is_rx=not bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG), |
381 |
| - is_remote_frame=bool( |
382 |
| - ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME |
383 |
| - ), |
384 |
| - is_error_frame=bool( |
385 |
| - ics_msg.StatusBitField2 & ics.SPY_STATUS2_ERROR_FRAME |
386 |
| - ), |
387 | 390 | error_state_indicator=bool(
|
388 | 391 | ics_msg.StatusBitField3 & ics.SPY_STATUS3_CANFD_ESI
|
389 | 392 | ),
|
390 | 393 | bitrate_switch=bool(
|
391 | 394 | ics_msg.StatusBitField3 & ics.SPY_STATUS3_CANFD_BRS
|
392 | 395 | ),
|
393 |
| - channel=ics_msg.NetworkID, |
394 | 396 | )
|
395 | 397 | else:
|
396 |
| - return Message( |
397 |
| - timestamp=self._get_timestamp_for_msg(ics_msg), |
398 |
| - arbitration_id=ics_msg.ArbIDOrHeader, |
| 398 | + return message_from_ics( |
399 | 399 | data=ics_msg.Data[: ics_msg.NumberBytesData],
|
400 |
| - dlc=ics_msg.NumberBytesData, |
401 |
| - is_extended_id=bool(ics_msg.StatusBitField & ics.SPY_STATUS_XTD_FRAME), |
402 |
| - is_fd=is_fd, |
403 |
| - is_rx=not bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG), |
404 |
| - is_remote_frame=bool( |
405 |
| - ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME |
406 |
| - ), |
407 |
| - is_error_frame=bool( |
408 |
| - ics_msg.StatusBitField2 & ics.SPY_STATUS2_ERROR_FRAME |
409 |
| - ), |
410 |
| - channel=ics_msg.NetworkID, |
411 | 400 | )
|
412 | 401 |
|
413 | 402 | def _recv_internal(self, timeout=0.1):
|
@@ -479,12 +468,16 @@ def send(self, msg, timeout=0):
|
479 | 468 | message.StatusBitField2 = 0
|
480 | 469 | message.StatusBitField3 = flag3
|
481 | 470 | if msg.channel is not None:
|
482 |
| - message.NetworkID = msg.channel |
| 471 | + network_id = msg.channel |
483 | 472 | elif len(self.channels) == 1:
|
484 |
| - message.NetworkID = self.channels[0] |
| 473 | + network_id = self.channels[0] |
485 | 474 | else:
|
486 | 475 | raise ValueError("msg.channel must be set when using multiple channels.")
|
487 | 476 |
|
| 477 | + message.NetworkID, message.NetworkID2 = int(network_id & 0xFF), int( |
| 478 | + (network_id >> 8) & 0xFF |
| 479 | + ) |
| 480 | + |
488 | 481 | if timeout != 0:
|
489 | 482 | msg_desc_id = next(description_id)
|
490 | 483 | message.DescriptionID = msg_desc_id
|
|
0 commit comments