|
2 | 2 | import threading |
3 | 3 | import math |
4 | 4 | from typing import Callable, Dict, Iterable, List, Optional, Union, TYPE_CHECKING |
5 | | -try: |
6 | | - from collections.abc import Mapping |
7 | | -except ImportError: |
8 | | - from collections import Mapping |
| 5 | +from collections.abc import Mapping |
9 | 6 | import logging |
10 | 7 | import binascii |
11 | 8 | import asyncio |
@@ -140,7 +137,7 @@ def stop(self): |
140 | 137 | pdo_map.stop() |
141 | 138 |
|
142 | 139 |
|
143 | | -class PdoMaps(Mapping[int, "PdoMap"]): |
| 140 | +class PdoMaps(Mapping): |
144 | 141 | """A collection of transmit or receive maps.""" |
145 | 142 |
|
146 | 143 | def __init__(self, com_offset, map_offset, pdo_node: PdoBase, cob_base=None): |
@@ -212,7 +209,7 @@ def __init__(self, pdo_node: PdoBase, com_record, map_array): |
212 | 209 | self._task = None |
213 | 210 |
|
214 | 211 | def __repr__(self) -> str: |
215 | | - return f"<{type(self).__qualname__} {self.name!r} at COB-ID 0x{self.cob_id}>" |
| 212 | + return f"<{type(self).__qualname__} {self.name!r} at COB-ID 0x{self.cob_id:X}>" |
216 | 213 |
|
217 | 214 | def __getitem_by_index(self, value): |
218 | 215 | valid_values = [] |
@@ -316,7 +313,7 @@ def on_message(self, can_id, data, timestamp): |
316 | 313 | # NOTE: Callback. Called from another thread unless async |
317 | 314 | is_transmitting = self._task is not None |
318 | 315 | if can_id == self.cob_id and not is_transmitting: |
319 | | - # NOTE: Blocking call |
| 316 | + # NOTE: Blocking lock |
320 | 317 | with self.receive_condition: |
321 | 318 | self.is_received = True |
322 | 319 | self.data = data |
@@ -413,8 +410,8 @@ def read(self, from_od=False) -> None: |
413 | 410 | value = var.od.default |
414 | 411 | else: |
415 | 412 | # Get value from SDO |
416 | | - # NOTE: Blocking |
417 | | - value = var.get_raw() |
| 413 | + # NOTE: Blocking call |
| 414 | + value = var.raw |
418 | 415 | try: |
419 | 416 | # Deliver value into read_generator and wait for next object |
420 | 417 | var = gen.send(value) |
@@ -507,10 +504,10 @@ def save(self) -> None: |
507 | 504 | for sdo, value in self.save_generator(): |
508 | 505 | if value == '@@get': |
509 | 506 | # NOTE: Sync implementation of the WORKAROUND in save_generator() |
510 | | - # NOTE: Blocking |
511 | | - self._fill_map(sdo.get_raw()) |
| 507 | + # NOTE: Blocking call |
| 508 | + self._fill_map(sdo.raw) |
512 | 509 | else: |
513 | | - # NOTE: Blocking |
| 510 | + # NOTE: Blocking call |
514 | 511 | sdo.set_raw(value) |
515 | 512 |
|
516 | 513 | async def asave(self) -> None: |
@@ -630,7 +627,7 @@ def wait_for_reception(self, timeout: float = 10) -> float: |
630 | 627 | :param float timeout: Max time to wait in seconds. |
631 | 628 | :return: Timestamp of message received or None if timeout. |
632 | 629 | """ |
633 | | - # NOTE: Blocking call |
| 630 | + # NOTE: Blocking lock |
634 | 631 | with self.receive_condition: |
635 | 632 | self.is_received = False |
636 | 633 | # NOTE: Blocking call |
@@ -692,7 +689,7 @@ def get_data(self) -> bytes: |
692 | 689 | return data |
693 | 690 |
|
694 | 691 | async def aget_data(self) -> bytes: |
695 | | - # As long as get_data() is not making any IO, it can be called |
| 692 | + # Since get_data() is not making any IO, it can be called |
696 | 693 | # directly with no special async variant |
697 | 694 | return self.get_data() |
698 | 695 |
|
@@ -730,7 +727,7 @@ def set_data(self, data: bytes): |
730 | 727 | self.pdo_parent.update() |
731 | 728 |
|
732 | 729 | async def aset_data(self, data: bytes): |
733 | | - # As long as get_data() is not making any IO, it can be called |
| 730 | + # Since get_data() is not making any IO, it can be called |
734 | 731 | # directly with no special async variant |
735 | 732 | return self.set_data(data) |
736 | 733 |
|
|
0 commit comments