@@ -57,7 +57,7 @@ def __init__(self, node_id: int):
5757 self ._state = 0
5858
5959 def on_command (self , can_id , data , timestamp ):
60- # NOTE: Callback. Will be called from another thread
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 )
@@ -66,7 +66,7 @@ def on_command(self, can_id, data, timestamp):
6666 if new_state != self ._state :
6767 logger .info ("New NMT state %s, old state %s" ,
6868 NMT_STATES [new_state ], NMT_STATES [self ._state ])
69- # NOTE: Assume thread-safe
69+ # FIXME: Is this thread-safe?
7070 self ._state = new_state
7171
7272 def send_command (self , code : int ):
@@ -125,20 +125,20 @@ def __init__(self, node_id: int):
125125 self ._node_guarding_producer = None
126126 #: Timestamp of last heartbeat message
127127 self .timestamp : Optional [float ] = None
128- self .state_update = threading .Condition () # FIXME
128+ self .state_update = threading .Condition ()
129129 self .astate_update = asyncio .Condition ()
130130 self ._callbacks = []
131131
132132 def on_heartbeat (self , can_id , data , timestamp ):
133- # NOTE: Callback. Will be called from another thread
134- with self .state_update : # FIXME : Blocking
133+ # NOTE: Callback. Called from another thread unless async
134+ with self .state_update : # NOTE : Blocking call
135135 self .timestamp = timestamp
136136 new_state , = struct .unpack_from ("B" , data )
137137 # Mask out toggle bit
138138 new_state &= 0x7F
139139 logger .debug ("Received heartbeat can-id %d, state is %d" , can_id , new_state )
140140 for callback in self ._callbacks :
141- callback (new_state ) # FIXME: Assert on coroutines ?
141+ callback (new_state ) # FIXME: Assert if callback is coroutine ?
142142 if new_state == 0 :
143143 # Boot-up, will go to PRE-OPERATIONAL automatically
144144 self ._state = 127
@@ -179,9 +179,9 @@ def send_command(self, code: int):
179179
180180 def wait_for_heartbeat (self , timeout : float = 10 ):
181181 """Wait until a heartbeat message is received."""
182- with self .state_update : # FIXME : Blocking
182+ with self .state_update : # NOTE : Blocking call
183183 self ._state_received = None
184- self .state_update .wait (timeout ) # FIXME : Blocking
184+ self .state_update .wait (timeout ) # NOTE : Blocking call
185185 if self ._state_received is None :
186186 raise NmtError ("No boot-up or heartbeat received" )
187187 return self .state
@@ -191,9 +191,9 @@ def wait_for_bootup(self, timeout: float = 10) -> None:
191191 end_time = time .time () + timeout
192192 while True :
193193 now = time .time ()
194- with self .state_update : # FIXME : Blocking
194+ with self .state_update : # NOTE : Blocking call
195195 self ._state_received = None
196- self .state_update .wait (end_time - now + 0.1 ) # FIXME : Blocking
196+ self .state_update .wait (end_time - now + 0.1 ) # NOTE : Blocking call
197197 if now > end_time :
198198 raise NmtError ("Timeout waiting for boot-up message" )
199199 if self ._state_received == 0 :
@@ -235,7 +235,7 @@ def __init__(self, node_id: int, local_node):
235235 self ._local_node = local_node
236236
237237 def on_command (self , can_id , data , timestamp ):
238- # NOTE: Callback. Will be called from another thread
238+ # NOTE: Callback. Called from another thread unless async
239239 super (NmtSlave , self ).on_command (can_id , data , timestamp )
240240 self .update_heartbeat ()
241241
@@ -291,9 +291,9 @@ def stop_heartbeat(self):
291291 self ._send_task = None
292292
293293 def update_heartbeat (self ):
294- # NOTE: Called from callback. Might be called from another thread
294+ # NOTE: Called from callback. Called from another thread unless async
295295 if self ._send_task is not None :
296- # FIXME: Check if network.PeriodicMessageTask() is thread-safe
296+ # FIXME: Make this thread-safe
297297 self ._send_task .update ([self ._state ])
298298
299299
0 commit comments