Go to most recent revision | Blame | Last modification | View Log | SVN | RSS feed
############################################################# CanStim interface, used to emulate connected can nodes############################################################import logging as logfrom NodeIfBase import NodeIfBasefrom threading import Threadimport time''' Generic dummy node '''class DummyNode():pass''' Temperature sensor node '''class TempNode(DummyNode):pass''' Relay node, controls switches '''class RelayNode(DummyNode):pass''' View node, controls an LCD or similar '''class ViewNode(DummyNode):pass''' IO Node, a bridge to some other protocol over can '''class IONode(DummyNode):passclass CanStimThread(Thread):dummyList = []numDummies = 0terminated = Falsedef __init__ (self):Thread.__init__(self)def run(self):log.debug('CanStimThread.run')while not self.terminated:time.sleep(0.1)def terminate(self):self.terminated = Trueclass NodeIfCanStim(NodeIfBase):DEFAULT_CONFIG = {'DummyNodes':[]}stimThread = Nonedef __init__ (self, cfg = None, pktHandler = None):if cfg is None:self.config = DEFAULT_CONFIGNodeIfBase.__init__(self, cfg, pktHandler)def start(self):stimThread = CanStimThread()stimThread.start()def stop(self):stimThread.dummyList.clear()def removeDummy(self, DummyNode):''' if possible'''stimThread.dummyList.remove(DummyNode)DummyNode.terminate()def addDummy(self, DummyNode):'''if possible'''stimThread.dummyList.add(DummyNode)DummyNode.start()