serialhdl: Use register_response() for both registering and unregistering

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-06-26 10:31:15 -04:00 committed by KevinOConnor
parent b2c778b931
commit a116fa9054
1 changed files with 5 additions and 5 deletions

View File

@ -139,10 +139,10 @@ class SerialReader:
# Serial response callbacks # Serial response callbacks
def register_response(self, callback, name, oid=None): def register_response(self, callback, name, oid=None):
with self.lock: with self.lock:
self.handlers[name, oid] = callback if callback is None:
def unregister_response(self, name, oid=None):
with self.lock:
del self.handlers[name, oid] del self.handlers[name, oid]
else:
self.handlers[name, oid] = callback
# Command sending # Command sending
def raw_send(self, cmd, minclock, reqclock, cmd_queue): def raw_send(self, cmd, minclock, reqclock, cmd_queue):
self.ffi_lib.serialqueue_send( self.ffi_lib.serialqueue_send(
@ -217,7 +217,7 @@ class SerialRetryCommand:
retry_time = self.first_query_time + self.RETRY_TIME retry_time = self.first_query_time + self.RETRY_TIME
self.send_timer = reactor.register_timer(self.send_event, retry_time) self.send_timer = reactor.register_timer(self.send_event, retry_time)
def unregister(self): def unregister(self):
self.serial.unregister_response(self.name, self.oid) self.serial.register_response(None, self.name, self.oid)
self.serial.reactor.unregister_timer(self.send_timer) self.serial.reactor.unregister_timer(self.send_timer)
def send_event(self, eventtime): def send_event(self, eventtime):
if self.response is not None: if self.response is not None: