Package ckbot :: Module nobus
[hide private]
[frames] | no frames]

Source Code for Module ckbot.nobus

 1  from time import time as now 
 2  from ckmodule import AbstractProtocol, AbstractBus, AbstractNodeAdaptor, MissingModule 
 3   
 4  # If you want to use non-default MissingModule replacements, first 
 5  #   map their NIDs to their module classes, e.g. 
 6  #   >>> import nobus as NB, dynamixel as DX 
 7  #   >>> NB.NID_CLASS[0x32] = DX.MissingDynamixel 
 8  NID_CLASS = {} 
 9   
10 -class Protocol( AbstractProtocol ):
11 """abstract superclass of all Protocol classes 12 13 AbstractProtocol subclasses must implement the following methods: 14 p.update() 15 p.hintNodes(nodes) 16 p.generatePNA( nid ) 17 18 AbstractProtocol instances must have the following data attributes: 19 p.heartbeats -- dict -- nid to last heartbeat 20 """
21 - def __init__(self,*args,**kw):
22 AbstractProtocol.__init__(self,*args,**kw) 23 self.hintNodes([])
24
25 - def update(self):
26 self._ts[0] = now()
27
28 - def hintNodes( self, nodes ):
29 self._ts = [now(),"No message"] 30 h = {} 31 for nd in nodes: 32 h[nd] = self._ts 33 self.heartbeats = h
34
35 - def generatePNA( self, nid ):
36 return NodeAdaptor( nid )
37
38 -class Bus( AbstractBus ):
39 """abstract superclass of all Bus classes 40 41 """
42 - def __init__(self,*args,**kw):
43 AbstractBus.__init__(self,*args,**kw)
44
45 -class NodeAdaptor( AbstractNodeAdaptor ):
46 """abstract superclass of all ProtocolNodeAdaptor classes 47 48 AbstractNodeAdaptor subclasses must implement the get_typecode() 49 method, returning the module's type identification string 50 """
51 - def __init__(self,nid):
52 AbstractNodeAdaptor.__init__(self) 53 self.nid = nid
54
55 - def get_typecode( self ):
56 cls = NID_CLASS.get(self.nid,MissingModule) 57 return cls.TYPECODE
58