Skip to content

Commit a5de223

Browse files
committed
Comments and notes update
1 parent 8260d7b commit a5de223

File tree

11 files changed

+31
-31
lines changed

11 files changed

+31
-31
lines changed

canopen/emcy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def __init__(self):
2626
self.emcy_received = threading.Condition()
2727
self.aemcy_received = asyncio.Condition()
2828

29+
# @callback # NOTE: called from another thread
2930
@ensure_not_async # NOTE: Safeguard for accidental async use
3031
def on_emcy(self, can_id, data, timestamp):
31-
# NOTE: Callback. Called from another thread unless async
3232
code, register, data = EMCY_STRUCT.unpack(data)
3333
entry = EmcyError(code, register, data, timestamp)
3434

@@ -46,6 +46,7 @@ def on_emcy(self, can_id, data, timestamp):
4646
# FIXME: Assert if callback is a coroutine?
4747
callback(entry)
4848

49+
# @callback
4950
async def aon_emcy(self, can_id, data, timestamp):
5051
code, register, data = EMCY_STRUCT.unpack(data)
5152
entry = EmcyError(code, register, data, timestamp)
@@ -79,8 +80,6 @@ def reset(self):
7980
self.log = []
8081
self.active = []
8182

82-
# FIXME: Implement "await" function. (Other name is needed here)
83-
8483
@ensure_not_async # NOTE: Safeguard for accidental async use
8584
def wait(
8685
self, emcy_code: Optional[int] = None, timeout: float = 10

canopen/lss.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,13 @@ def __send_command(self, message):
410410

411411
return response
412412

413+
# @callback # NOTE: called from another thread
413414
@ensure_not_async # NOTE: Safeguard for accidental async use
414415
def on_message_received(self, can_id, data, timestamp):
415-
# NOTE: Callback. Called from another thread
416416
# NOTE: Blocking call
417417
self.responses.put(bytes(data))
418418

419+
# @callback
419420
async def aon_message_received(self, can_id, data, timestamp):
420421
await self.aresponses.put(bytes(data))
421422

canopen/network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def send_periodic(
249249
"""
250250
return PeriodicMessageTask(can_id, data, period, self.bus, remote)
251251

252+
# @callback # NOTE: called from another thread
252253
def notify(self, can_id: int, data: bytearray, timestamp: float) -> None:
253254
"""Feed incoming message to this library.
254255
@@ -262,7 +263,6 @@ def notify(self, can_id: int, data: bytearray, timestamp: float) -> None:
262263
:param timestamp:
263264
Timestamp of the message, preferably as a Unix timestamp
264265
"""
265-
# NOTE: Callback. Called from another thread unless async
266266
callbacks = self.subscribers.get(can_id)
267267
if callbacks is not None:
268268
for callback in callbacks:
@@ -390,8 +390,8 @@ class MessageListener(Listener):
390390
def __init__(self, network: Network):
391391
self.network = network
392392

393+
# @callback # NOTE: called from another thread
393394
def on_message_received(self, msg):
394-
# NOTE: Callback. Called from another thread unless async
395395
if msg.is_error_frame or msg.is_remote_frame:
396396
return
397397

@@ -425,8 +425,8 @@ def __init__(self, network: Optional[Network] = None):
425425
#: A :class:`list` of nodes discovered
426426
self.nodes: List[int] = []
427427

428+
# @callback # NOTE: called from another thread
428429
def on_message_received(self, can_id: int):
429-
# NOTE: Callback. Called from another thread unless async
430430
service = can_id & 0x780
431431
node_id = can_id & 0x7F
432432
if node_id not in self.nodes and node_id != 0 and service in self.SERVICES:

canopen/nmt.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def __init__(self, node_id: int):
5656
self.network: canopen.network.Network = canopen.network._UNINITIALIZED_NETWORK
5757
self._state = 0
5858

59+
# @callback - NOTE: called from another thread
5960
def on_command(self, can_id, data, timestamp):
60-
# NOTE: Callback. Called from another thread unless async
6161
cmd, node_id = struct.unpack_from("BB", data)
6262
if node_id in (self.id, 0):
6363
logger.info("Node %d received command %d", self.id, cmd)
@@ -124,9 +124,9 @@ def __init__(self, node_id: int):
124124
self.astate_update = asyncio.Condition()
125125
self._callbacks = []
126126

127+
# @callback # NOTE: called from another thread
127128
@ensure_not_async # NOTE: Safeguard for accidental async use
128129
def on_heartbeat(self, can_id, data, timestamp):
129-
# NOTE: Callback. Called from another thread unless async
130130
# NOTE: Blocking lock
131131
with self.state_update:
132132
self.timestamp = timestamp
@@ -145,6 +145,7 @@ def on_heartbeat(self, can_id, data, timestamp):
145145
self._state_received = new_state
146146
self.state_update.notify_all()
147147

148+
# @callback
148149
async def aon_heartbeat(self, can_id, data, timestamp):
149150
async with self.astate_update:
150151
self.timestamp = timestamp
@@ -265,8 +266,8 @@ def __init__(self, node_id: int, local_node):
265266
self._heartbeat_time_ms = 0
266267
self._local_node = local_node
267268

269+
# @callback # NOTE: called from another thread
268270
def on_command(self, can_id, data, timestamp):
269-
# NOTE: Callback. Called from another thread unless async
270271
super(NmtSlave, self).on_command(can_id, data, timestamp)
271272
self.update_heartbeat()
272273

@@ -287,7 +288,7 @@ def send_command(self, code: int) -> None:
287288
# between INITIALIZING and PRE-OPERATIONAL state
288289
if old_state == 0 and self._state == 127:
289290
if self._heartbeat_time_ms == 0:
290-
# NOTE: Blocking - OK. Protected in SdoClient
291+
# NOTE: Blocking - protected in SdoClient
291292
heartbeat_time_ms = self._local_node.sdo[0x1017].raw
292293
else:
293294
heartbeat_time_ms = self._heartbeat_time_ms

canopen/node/base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def __init__(
2727

2828
self.id = node_id or self.object_dictionary.node_id
2929

30-
# FIXME: Should associate_network() and remove_network() be a part of the base API?
31-
3230
def has_network(self) -> bool:
3331
"""Check whether the node has been associated to a network."""
3432
return not isinstance(self.network, canopen.network._UninitializedNetwork)

canopen/node/remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def __load_configuration_helper(self, index, subindex, name, value):
136136
if subindex is not None:
137137
logger.info('SDO [0x%04X][0x%02X]: %s: %#06x',
138138
index, subindex, name, value)
139-
# NOTE: Blocking call - OK. Protected in SdoClient
139+
# NOTE: Blocking - protected in SdoClient
140140
self.sdo[index][subindex].raw = value
141141
else:
142-
# NOTE: Blocking call - OK. Protected in SdoClient
142+
# NOTE: Blocking - protected in SdoClient
143143
self.sdo[index].raw = value
144144
logger.info('SDO [0x%04X]: %s: %#06x',
145145
index, name, value)

canopen/pdo/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ def is_periodic(self) -> bool:
322322
# Unknown transmission type, assume non-periodic
323323
return False
324324

325+
# @callback # NOTE: called from another thread
325326
@ensure_not_async # NOTE: Safeguard for accidental async use
326327
def on_message(self, can_id, data, timestamp):
327-
# NOTE: Callback. Called from another thread unless async
328328
is_transmitting = self._task is not None
329329
if can_id == self.cob_id and not is_transmitting:
330330
# NOTE: Blocking lock
@@ -339,6 +339,7 @@ def on_message(self, can_id, data, timestamp):
339339
# FIXME: Assert on couroutines?
340340
callback(self)
341341

342+
# @callback
342343
async def aon_message(self, can_id, data, timestamp):
343344
is_transmitting = self._task is not None
344345
if can_id == self.cob_id and not is_transmitting:
@@ -434,7 +435,7 @@ def read(self, from_od=False) -> None:
434435
value = param.od.default
435436
else:
436437
# Get value from SDO
437-
# NOTE: Blocking call
438+
# NOTE: Blocking - protected in SdoClient
438439
value = param.raw
439440
try:
440441
# Deliver value into read_generator and wait for next object
@@ -542,7 +543,7 @@ def save(self) -> None:
542543
for sdo, value in self.save_generator():
543544
if value == '@@get':
544545
# NOTE: Sync implementation of the WORKAROUND in save_generator()
545-
# NOTE: Blocking call
546+
# NOTE: Blocking - protected in SdoClient
546547
self._fill_map(sdo.raw)
547548
else:
548549
# NOTE: Blocking call

canopen/profiles/p402.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def op_mode(self):
432432
code = self.tpdo_values[0x6061]
433433
except KeyError:
434434
logger.warning('The object 0x6061 is not a configured TPDO, fallback to SDO')
435-
# NOTE: Blocking - OK. Protected in SdoClient
435+
# NOTE: Blocking - protected in SdoClient
436436
code = self.sdo[0x6061].raw
437437
return OperationMode.CODE2NAME[code]
438438

@@ -445,13 +445,13 @@ def op_mode(self, mode):
445445
f'Operation mode {mode} not suppported on node {self.id}.')
446446
# Update operation mode in RPDO if possible, fall back to SDO
447447
if 0x6060 in self.rpdo_pointers:
448-
# NOTE: Blocking - OK. Protected in SdoClient
448+
# NOTE: Blocking - protected in SdoClient
449449
self.rpdo_pointers[0x6060].raw = OperationMode.NAME2CODE[mode]
450450
pdo = self.rpdo_pointers[0x6060].pdo_parent
451451
if not pdo.is_periodic:
452452
pdo.transmit()
453453
else:
454-
# NOTE: Blocking - OK. Protected in SdoClient
454+
# NOTE: Blocking - protected in SdoClient
455455
self.sdo[0x6060].raw = OperationMode.NAME2CODE[mode]
456456
timeout = time.monotonic() + self.TIMEOUT_SWITCH_OP_MODE
457457
# NOTE: Blocking getter
@@ -470,7 +470,7 @@ def _clear_target_values(self):
470470
# [target velocity, target position, target torque]
471471
for target_index in [0x60FF, 0x607A, 0x6071]:
472472
if target_index in self.sdo.keys():
473-
# NOTE: Blocking - OK. Protected in SdoClient
473+
# NOTE: Blocking - protected in SdoClient
474474
self.sdo[target_index].raw = 0
475475

476476
# NOTE: Blocking
@@ -486,7 +486,7 @@ def is_op_mode_supported(self, mode):
486486
"""
487487
if not hasattr(self, '_op_mode_support'):
488488
# Cache value only on first lookup, this object should never change.
489-
# NOTE: Blocking - OK. Protected in SdoClient
489+
# NOTE: Blocking - protected in SdoClient
490490
self._op_mode_support = self.sdo[0x6502].raw
491491
logger.info('Caching node %s supported operation modes 0x%04X',
492492
self.id, self._op_mode_support)
@@ -502,7 +502,7 @@ def on_TPDOs_update_callback(self, mapobject: PdoMap):
502502
# NOTE: Callback. Called from another thread unless async
503503
for obj in mapobject:
504504
# FIXME: Is this thread-safe?
505-
# NOTE: Blocking - OK. Protected in SdoClient
505+
# NOTE: Blocking - protected in SdoClient
506506
self.tpdo_values[obj.index] = obj.raw
507507

508508
# NOTE: Blocking getter on errors
@@ -517,7 +517,7 @@ def statusword(self):
517517
return self.tpdo_values[0x6041]
518518
except KeyError:
519519
logger.warning('The object 0x6041 is not a configured TPDO, fallback to SDO')
520-
# NOTE: Blocking - OK. Protected in SdoClient
520+
# NOTE: Blocking - protected in SdoClient
521521
return self.sdo[0x6041].raw
522522

523523
# NOTE: Blocking, conditional
@@ -540,7 +540,7 @@ def check_statusword(self, timeout=None):
540540
if timestamp is None:
541541
raise RuntimeError('Timeout waiting for updated statusword')
542542
else:
543-
# NOTE: Blocking - OK. Protected in SdoClient
543+
# NOTE: Blocking - protected in SdoClient
544544
return self.sdo[0x6041].raw
545545
# NOTE: Blocking getter on errors
546546
return self.statusword
@@ -558,13 +558,13 @@ def controlword(self):
558558
@controlword.setter
559559
def controlword(self, value):
560560
if 0x6040 in self.rpdo_pointers:
561-
# NOTE: Blocking - OK. Protected in SdoClient
561+
# NOTE: Blocking - protected in SdoClient
562562
self.rpdo_pointers[0x6040].raw = value
563563
pdo = self.rpdo_pointers[0x6040].pdo_parent
564564
if not pdo.is_periodic:
565565
pdo.transmit()
566566
else:
567-
# NOTE: Blocking - OK. Protected in SdoClient
567+
# NOTE: Blocking - protected in SdoClient
568568
self.sdo[0x6040].raw = value
569569

570570
# NOTE: Blocking getter on errors

canopen/sdo/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __aiter__(self):
163163
return self.aiter()
164164

165165
def __len__(self) -> int:
166-
# NOTE: Blocking - OK. Protected in SdoClient
166+
# NOTE: Blocking - protected in SdoClient
167167
return self[0].raw
168168

169169
async def alen(self) -> int:

canopen/sdo/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def __init__(self, rx_cobid, tx_cobid, od):
4545
self.responses = queue.Queue()
4646
self.lock = asyncio.Lock()
4747

48+
# @callback # NOTE: called from another thread
4849
def on_response(self, can_id, data, timestamp):
49-
# NOTE: Callback. Will be called from another thread
5050
self.responses.put_nowait(bytes(data))
5151

5252
def send_request(self, request):

0 commit comments

Comments
 (0)