Skip to content

Commit

Permalink
[codec] Hook vendor commands during WpanApi initialization (openthrea…
Browse files Browse the repository at this point in the history
…d#106)

There's no need to join VendorSpinelPropertyHandler class with
SpinelPropertyHandler since the methods in SPINEL_PROP_DISPATCH are
located in different objects anyway. This allows to move vendor
properties initialization into WpanApi class initializator, therefore
allowing to use custom Vendor module based on the command line argument.

Signed-off-by: Robert Lubos <[email protected]>
  • Loading branch information
rlubos authored and jwhui committed Nov 24, 2020
1 parent fb41c36 commit 01270cc
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions spinel/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,15 +822,7 @@ def PROP_VALUE_REMOVED(self, wpan_api, payload, tid):
SPINEL.RSP_PROP_VALUE_REMOVED: WPAN_CMD_HANDLER.PROP_VALUE_REMOVED,
}

try:
codec = importlib.import_module('vendor.codec')
cls = type(codec.VendorSpinelPropertyHandler.__name__,
(SpinelPropertyHandler, codec.VendorSpinelPropertyHandler),
{'__name__': codec.VendorSpinelPropertyHandler.__name__})
WPAN_PROP_HANDLER = cls()
except ImportError:
codec = None
WPAN_PROP_HANDLER = SpinelPropertyHandler()
WPAN_PROP_HANDLER = SpinelPropertyHandler()

SPINEL_PROP_DISPATCH = {
SPINEL.PROP_LAST_STATUS:
Expand Down Expand Up @@ -1023,9 +1015,6 @@ def PROP_VALUE_REMOVED(self, wpan_api, payload, tid):
WPAN_PROP_HANDLER.NEST_STREAM_MFG
}

if codec is not None:
SPINEL_PROP_DISPATCH.update(codec.VENDOR_SPINEL_PROP_DISPATCH)


class WpanApi(SpinelCodec):
""" Helper class to format wpan command packets """
Expand All @@ -1044,6 +1033,13 @@ def __init__(self,
if self.use_hdlc:
self.hdlc = Hdlc(self.stream)

# Hook vendor properties
try:
codec = importlib.import_module('vendor.codec')
SPINEL_PROP_DISPATCH.update(codec.VENDOR_SPINEL_PROP_DISPATCH)
except ImportError:
pass

# PARSER state
self.rx_pkt = []
self.callback = defaultdict(list) # Map prop_id to list of callbacks.
Expand Down

0 comments on commit 01270cc

Please sign in to comment.