|
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 |
@@ -310,7 +311,8 @@ def _process_msg_queue(self, timeout=0.1): |
310 | 311 | except ics.RuntimeError: |
311 | 312 | return |
312 | 313 | for ics_msg in messages: |
313 | | - if ics_msg.NetworkID not in self.channels: |
| 314 | + channel = ics_msg.NetworkID | (ics_msg.NetworkID2 << 8) |
| 315 | + if channel not in self.channels: |
314 | 316 | continue |
315 | 317 |
|
316 | 318 | is_tx = bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG) |
@@ -357,50 +359,37 @@ def _get_timestamp_for_msg(self, ics_msg): |
357 | 359 | def _ics_msg_to_message(self, ics_msg): |
358 | 360 | is_fd = ics_msg.Protocol == ics.SPY_PROTOCOL_CANFD |
359 | 361 |
|
| 362 | + message_from_ics = partial( |
| 363 | + Message, |
| 364 | + timestamp=self._get_timestamp_for_msg(ics_msg), |
| 365 | + arbitration_id=ics_msg.ArbIDOrHeader, |
| 366 | + is_extended_id=bool(ics_msg.StatusBitField & ics.SPY_STATUS_XTD_FRAME), |
| 367 | + is_remote_frame=bool(ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME), |
| 368 | + is_error_frame=bool(ics_msg.StatusBitField2 & ics.SPY_STATUS2_ERROR_FRAME), |
| 369 | + channel=ics_msg.NetworkID | (ics_msg.NetworkID2 << 8), |
| 370 | + dlc=ics_msg.NumberBytesData, |
| 371 | + is_fd=is_fd, |
| 372 | + is_rx=not bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG), |
| 373 | + ) |
| 374 | + |
360 | 375 | if is_fd: |
361 | 376 | if ics_msg.ExtraDataPtrEnabled: |
362 | 377 | data = ics_msg.ExtraDataPtr[: ics_msg.NumberBytesData] |
363 | 378 | else: |
364 | 379 | data = ics_msg.Data[: ics_msg.NumberBytesData] |
365 | 380 |
|
366 | | - return Message( |
367 | | - timestamp=self._get_timestamp_for_msg(ics_msg), |
368 | | - arbitration_id=ics_msg.ArbIDOrHeader, |
| 381 | + return message_from_ics( |
369 | 382 | data=data, |
370 | | - dlc=ics_msg.NumberBytesData, |
371 | | - is_extended_id=bool(ics_msg.StatusBitField & ics.SPY_STATUS_XTD_FRAME), |
372 | | - is_fd=is_fd, |
373 | | - is_rx=not bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG), |
374 | | - is_remote_frame=bool( |
375 | | - ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME |
376 | | - ), |
377 | | - is_error_frame=bool( |
378 | | - ics_msg.StatusBitField2 & ics.SPY_STATUS2_ERROR_FRAME |
379 | | - ), |
380 | 383 | error_state_indicator=bool( |
381 | 384 | ics_msg.StatusBitField3 & ics.SPY_STATUS3_CANFD_ESI |
382 | 385 | ), |
383 | 386 | bitrate_switch=bool( |
384 | 387 | ics_msg.StatusBitField3 & ics.SPY_STATUS3_CANFD_BRS |
385 | 388 | ), |
386 | | - channel=ics_msg.NetworkID, |
387 | 389 | ) |
388 | 390 | else: |
389 | | - return Message( |
390 | | - timestamp=self._get_timestamp_for_msg(ics_msg), |
391 | | - arbitration_id=ics_msg.ArbIDOrHeader, |
| 391 | + return message_from_ics( |
392 | 392 | data=ics_msg.Data[: ics_msg.NumberBytesData], |
393 | | - dlc=ics_msg.NumberBytesData, |
394 | | - is_extended_id=bool(ics_msg.StatusBitField & ics.SPY_STATUS_XTD_FRAME), |
395 | | - is_fd=is_fd, |
396 | | - is_rx=not bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG), |
397 | | - is_remote_frame=bool( |
398 | | - ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME |
399 | | - ), |
400 | | - is_error_frame=bool( |
401 | | - ics_msg.StatusBitField2 & ics.SPY_STATUS2_ERROR_FRAME |
402 | | - ), |
403 | | - channel=ics_msg.NetworkID, |
404 | 393 | ) |
405 | 394 |
|
406 | 395 | def _recv_internal(self, timeout=0.1): |
@@ -472,12 +461,16 @@ def send(self, msg, timeout=0): |
472 | 461 | message.StatusBitField2 = 0 |
473 | 462 | message.StatusBitField3 = flag3 |
474 | 463 | if msg.channel is not None: |
475 | | - message.NetworkID = msg.channel |
| 464 | + network_id = msg.channel |
476 | 465 | elif len(self.channels) == 1: |
477 | | - message.NetworkID = self.channels[0] |
| 466 | + network_id = self.channels[0] |
478 | 467 | else: |
479 | 468 | raise ValueError("msg.channel must be set when using multiple channels.") |
480 | 469 |
|
| 470 | + message.NetworkID, message.NetworkID2 = int(network_id & 0xFF), int( |
| 471 | + (network_id >> 8) & 0xFF |
| 472 | + ) |
| 473 | + |
481 | 474 | if timeout != 0: |
482 | 475 | msg_desc_id = next(description_id) |
483 | 476 | message.DescriptionID = msg_desc_id |
|
0 commit comments