def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.timeline = self.engine.timeline self.frequency = self.FREQUENCY self.maxDrift = self.MAXDRIFT # local variables self.drift = float(random.uniform(-self.maxDrift, +self.maxDrift)) # the duration of one tick. Since it is constant, it is only calculated # once by _getPeriod(). Therefore, do not use directly, rather use # _getPeriod() self._period = None # tsTick is a timestamp associated with any tick in the past. Since the # period is constant, it is used to ensure alignement of timestamps # to an integer number of ticks. self.tsTick = None # initialize the parent HwModule.HwModule.__init__(self, 'HwCrystal')
def __init__(self,motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.timeline = self.engine.timeline self.propagation = self.engine.propagation self.radiotimer = self.motehandler.bspRadiotimer # local variables self.frequency = None # frequency the radio is tuned to self.isRfOn = False # radio is off self.txBuf = [] self.rxBuf = [] self.delayTx = 0.000214 # initialize the parents BspModule.BspModule.__init__(self,'BspRadio') eventBusClient.eventBusClient.__init__( self, name = 'BspRadio_{0}'.format(self.motehandler.getId()), registrations = [], ) # set initial state self._changeState(RadioState.STOPPED)
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.timeline = self.engine.timeline self.interruptsEnabled = False self.txInterruptFlag = False self.rxInterruptFlag = False self.uartRxBuffer = [] self.uartRxBufferSem = threading.Semaphore() self.uartRxBufferSem.acquire() self.uartRxBufferLock = threading.Lock() self.uartTxBuffer = [] # the bytes to be sent over UART self.uartTxNext = None # the byte that was just signaled to mote self.uartTxBufferLock = threading.Lock() self.waitForDoneReading = threading.Lock() self.waitForDoneReading.acquire() self.fXonXoffEscaping = False self.xonXoffEscapedByte = 0 # initialize the parent BspModule.BspModule.__init__(self, 'BspUart')
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables # initialize the parent BspModule.BspModule.__init__(self, 'BspEui64')
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.moteOn = False # initialize the parent HwModule.HwModule.__init__(self, 'HwSupply')
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.timeline = self.engine.timeline # initialize the parent BspModule.BspModule.__init__(self, 'BspBoard')
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.errorLedOn = False self.radioLedOn = False self.syncLedOn = False self.debugLedOn = False # initialize the parent BspModule.BspModule.__init__(self, 'BspLeds')
def __init__(self, app, websrv, roverMode): ''' :param app: OpenVisualizerApp :param websrv: Web server ''' log.info('Creating OpenVisualizerWeb') # store params self.app = app self.engine = SimEngine.SimEngine() self.websrv = websrv self.roverMode = roverMode # command support Cmd.__init__(self) self.doc_header = 'Commands (type "help all" or "help <topic>"):' self.prompt = '> ' self.intro = '\nOpenVisualizer (type "help" for commands)' #used for remote motes : if roverMode: self.roverMotes = {} self.client = coap.coap() self.client.respTimeout = 2 self.client.ackTimeout = 2 self.client.maxRetransmit = 1 self._defineRoutes() # To find page templates bottle.TEMPLATE_PATH.append('{0}/web_files/templates/'.format( self.app.datadir)) # initialize parent class eventBusClient.eventBusClient.__init__( self, name='OpenVisualizerWeb', registrations=[], ) # Set DAGroots imported if app.DAGrootList: #Wait the end of the mote threads creation time.sleep(1) for moteid in app.DAGrootList: self._showMoteview(moteid) self._getMoteData(moteid) self._toggleDAGroot(moteid)
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.timeline = self.engine.timeline self.hwCrystal = self.motehandler.hwCrystal self.running = False # whether the counter is currently running self.timeLastReset = None # time at last counter reset self.period = None # counter period self.compareArmed = False # whether the compare is armed # initialize the parent BspModule.BspModule.__init__(self, 'BspRadiotimer')
def __init__(self, motehandler): # store params self.engine = SimEngine.SimEngine() self.motehandler = motehandler # local variables self.timeline = self.engine.timeline self.framePinHigh = False self.slotPinHigh = False self.fsmPinHigh = False self.taskPinHigh = False self.isrPinHigh = False self.radioPinHigh = False self.kaPinHigh = False self.syncPacketPinHigh = False self.syncAckPinHigh = False self.debugPinHigh = False self.vcdLogger = VcdLogger.VcdLogger() # initialize the parent BspModule.BspModule.__init__(self, 'BspDebugpins')
def __init__(self, app, websrv): ''' :param app: OpenVisualizerApp :param websrv: Web server ''' log.info('Creating OpenVisualizerWeb') # store params self.app = app self.engine = SimEngine.SimEngine() self.websrv = websrv self._defineRoutes() # To find page templates bottle.TEMPLATE_PATH.append('{0}/web_files/templates/'.format( self.app.datadir)) # initialize parent class eventBusClient.eventBusClient.__init__( self, name='OpenVisualizerWeb', registrations=[], )
def __init__(self, confdir, datadir, logdir, simulatorMode, numMotes, trace, debug, usePageZero, simTopology, iotlabmotes, pathTopo): # store params self.confdir = confdir self.datadir = datadir self.logdir = logdir self.simulatorMode = simulatorMode self.numMotes = numMotes self.trace = trace self.debug = debug self.usePageZero = usePageZero self.iotlabmotes = iotlabmotes self.pathTopo = pathTopo # local variables self.eventBusMonitor = eventBusMonitor.eventBusMonitor() self.openLbr = openLbr.OpenLbr(usePageZero) self.rpl = RPL.RPL() self.jrc = JRC.JRC() self.topology = topology.topology() self.udpInject = UDPInject.UDPInject() self.DAGrootList = [] # create openTun call last since indicates prefix self.openTun = openTun.create() if self.simulatorMode: from openvisualizer.SimEngine import SimEngine, MoteHandler self.simengine = SimEngine.SimEngine(simTopology) self.simengine.start() # import the number of motes from json file given by user (if the pathTopo option is enabled) if self.pathTopo and self.simulatorMode: try: topoConfig = open(pathTopo) topo = json.load(topoConfig) self.numMotes = len(topo['motes']) except Exception as err: print err app.close() os.kill(os.getpid(), signal.SIGTERM) # create a moteProbe for each mote if self.simulatorMode: # in "simulator" mode, motes are emulated sys.path.append(os.path.join(self.datadir, 'sim_files')) import oos_openwsn MoteHandler.readNotifIds( os.path.join(self.datadir, 'sim_files', 'openwsnmodule_obj.h')) self.moteProbes = [] for _ in range(self.numMotes): moteHandler = MoteHandler.MoteHandler(oos_openwsn.OpenMote()) self.simengine.indicateNewMote(moteHandler) self.moteProbes += [ moteProbe.moteProbe(emulatedMote=moteHandler) ] elif self.iotlabmotes: # in "IoT-LAB" mode, motes are connected to TCP ports self.moteProbes = [ moteProbe.moteProbe(iotlabmote=p) for p in self.iotlabmotes.split(',') ] else: # in "hardware" mode, motes are connected to the serial port self.moteProbes = [ moteProbe.moteProbe(serialport=p) for p in moteProbe.findSerialPorts() ] # create a moteConnector for each moteProbe self.moteConnectors = [ moteConnector.moteConnector(mp.getPortName()) for mp in self.moteProbes ] # create a moteState for each moteConnector self.moteStates = [ moteState.moteState(mc) for mc in self.moteConnectors ] self.remoteConnectorServer = remoteConnectorServer.remoteConnectorServer( ) # boot all emulated motes, if applicable if self.simulatorMode: self.simengine.pause() now = self.simengine.timeline.getCurrentTime() for rank in range(self.simengine.getNumMotes()): moteHandler = self.simengine.getMoteHandler(rank) self.simengine.timeline.scheduleEvent( now, moteHandler.getId(), moteHandler.hwSupply.switchOn, moteHandler.hwSupply.INTR_SWITCHON) self.simengine.resume() # import the topology from the json file if self.pathTopo and self.simulatorMode: # delete each connections automatically established during motes creation ConnectionsToDelete = self.simengine.propagation.retrieveConnections( ) for co in ConnectionsToDelete: fromMote = int(co['fromMote']) toMote = int(co['toMote']) self.simengine.propagation.deleteConnection(fromMote, toMote) motes = topo['motes'] for mote in motes: mh = self.simengine.getMoteHandlerById(mote['id']) mh.setLocation(mote['lat'], mote['lon']) # implements new connections connect = topo['connections'] for co in connect: fromMote = int(co['fromMote']) toMote = int(co['toMote']) pdr = float(co['pdr']) self.simengine.propagation.createConnection(fromMote, toMote) self.simengine.propagation.updateConnection( fromMote, toMote, pdr) # store DAGroot moteids in DAGrootList DAGrootL = topo['DAGrootList'] for DAGroot in DAGrootL: hexaDAGroot = hex(DAGroot) hexaDAGroot = hexaDAGroot[2:] prefixLen = 4 - len(hexaDAGroot) prefix = "" for i in range(prefixLen): prefix += "0" moteid = prefix + hexaDAGroot self.DAGrootList.append(moteid) # start tracing threads if self.trace: import openvisualizer.OVtracer logging.config.fileConfig( os.path.join(self.confdir, 'trace.conf'), {'logDir': _forceSlashSep(self.logdir, self.debug)}) OVtracer.OVtracer()
def __init__(self, mote): # store params self.engine = SimEngine.SimEngine() self.mote = mote #=== local variables self.loghandler = self.engine.loghandler # unique identifier of the mote self.id = self.engine.idmanager.getId() # position of the mote self.location = self.engine.locationmanager.getLocation() # written by erfan!! #To read topology from file f = open('_mote_positions.txt') locations = f.readlines() f.close() self.setLocation(float(locations[(self.id - 1)].split()[0]), float(locations[(self.id - 1)].split()[1])) # end of erfan !!! # stats self.numRxCommands = 0 self.numTxCommands = 0 # hw self.hwSupply = HwSupply.HwSupply(self) self.hwCrystal = HwCrystal.HwCrystal(self) # bsp self.bspBoard = BspBoard.BspBoard(self) self.bspBsp_timer = BspBsp_timer.BspBsp_timer(self) self.bspDebugpins = BspDebugpins.BspDebugpins(self) self.bspEui64 = BspEui64.BspEui64(self) self.bspLeds = BspLeds.BspLeds(self) self.bspRadiotimer = BspRadiotimer.BspRadiotimer(self) self.bspRadio = BspRadio.BspRadio(self) self.bspUart = BspUart.BspUart(self) # status self.booted = False self.cpuRunning = threading.Lock() self.cpuRunning.acquire() self.cpuDone = threading.Lock() self.cpuDone.acquire() #=== install callbacks # board mote.set_callback(notifId('board_init'), self.bspBoard.cmd_init) mote.set_callback(notifId('board_sleep'), self.bspBoard.cmd_sleep) # bsp_timer mote.set_callback(notifId('bsp_timer_init'), self.bspBsp_timer.cmd_init) mote.set_callback(notifId('bsp_timer_reset'), self.bspBsp_timer.cmd_reset) mote.set_callback(notifId('bsp_timer_scheduleIn'), self.bspBsp_timer.cmd_scheduleIn) mote.set_callback(notifId('bsp_timer_cancel_schedule'), self.bspBsp_timer.cmd_cancel_schedule) mote.set_callback(notifId('bsp_timer_get_currentValue'), self.bspBsp_timer.cmd_get_currentValue) # debugpins mote.set_callback(notifId('debugpins_init'), self.bspDebugpins.cmd_init) mote.set_callback(notifId('debugpins_frame_toggle'), self.bspDebugpins.cmd_frame_toggle) mote.set_callback(notifId('debugpins_frame_clr'), self.bspDebugpins.cmd_frame_clr) mote.set_callback(notifId('debugpins_frame_set'), self.bspDebugpins.cmd_frame_set) mote.set_callback(notifId('debugpins_slot_toggle'), self.bspDebugpins.cmd_slot_toggle) mote.set_callback(notifId('debugpins_slot_clr'), self.bspDebugpins.cmd_slot_clr) mote.set_callback(notifId('debugpins_slot_set'), self.bspDebugpins.cmd_slot_set) mote.set_callback(notifId('debugpins_fsm_toggle'), self.bspDebugpins.cmd_fsm_toggle) mote.set_callback(notifId('debugpins_fsm_clr'), self.bspDebugpins.cmd_fsm_clr) mote.set_callback(notifId('debugpins_fsm_set'), self.bspDebugpins.cmd_fsm_set) mote.set_callback(notifId('debugpins_task_toggle'), self.bspDebugpins.cmd_task_toggle) mote.set_callback(notifId('debugpins_task_clr'), self.bspDebugpins.cmd_task_clr) mote.set_callback(notifId('debugpins_task_set'), self.bspDebugpins.cmd_task_set) mote.set_callback(notifId('debugpins_isr_toggle'), self.bspDebugpins.cmd_isr_toggle) mote.set_callback(notifId('debugpins_isr_clr'), self.bspDebugpins.cmd_isr_clr) mote.set_callback(notifId('debugpins_isr_set'), self.bspDebugpins.cmd_isr_set) mote.set_callback(notifId('debugpins_radio_toggle'), self.bspDebugpins.cmd_radio_toggle) mote.set_callback(notifId('debugpins_radio_clr'), self.bspDebugpins.cmd_radio_clr) mote.set_callback(notifId('debugpins_radio_set'), self.bspDebugpins.cmd_radio_set) mote.set_callback(notifId('debugpins_ka_clr'), self.bspDebugpins.cmd_ka_clr) mote.set_callback(notifId('debugpins_ka_set'), self.bspDebugpins.cmd_ka_set) mote.set_callback(notifId('debugpins_syncPacket_clr'), self.bspDebugpins.cmd_syncPacket_clr) mote.set_callback(notifId('debugpins_syncPacket_set'), self.bspDebugpins.cmd_syncPacket_set) mote.set_callback(notifId('debugpins_syncAck_clr'), self.bspDebugpins.cmd_syncAck_clr) mote.set_callback(notifId('debugpins_syncAck_set'), self.bspDebugpins.cmd_syncAck_set) mote.set_callback(notifId('debugpins_debug_clr'), self.bspDebugpins.cmd_debug_clr) mote.set_callback(notifId('debugpins_debug_set'), self.bspDebugpins.cmd_debug_set) # eui64 mote.set_callback(notifId('eui64_get'), self.bspEui64.cmd_get) # leds mote.set_callback(notifId('leds_init'), self.bspLeds.cmd_init) mote.set_callback(notifId('leds_error_on'), self.bspLeds.cmd_error_on) mote.set_callback(notifId('leds_error_off'), self.bspLeds.cmd_error_off) mote.set_callback(notifId('leds_error_toggle'), self.bspLeds.cmd_error_toggle) mote.set_callback(notifId('leds_error_isOn'), self.bspLeds.cmd_error_isOn) mote.set_callback(notifId('leds_radio_on'), self.bspLeds.cmd_radio_on) mote.set_callback(notifId('leds_radio_off'), self.bspLeds.cmd_radio_off) mote.set_callback(notifId('leds_radio_toggle'), self.bspLeds.cmd_radio_toggle) mote.set_callback(notifId('leds_radio_isOn'), self.bspLeds.cmd_radio_isOn) mote.set_callback(notifId('leds_sync_on'), self.bspLeds.cmd_sync_on) mote.set_callback(notifId('leds_sync_off'), self.bspLeds.cmd_sync_off) mote.set_callback(notifId('leds_sync_toggle'), self.bspLeds.cmd_sync_toggle) mote.set_callback(notifId('leds_sync_isOn'), self.bspLeds.cmd_sync_isOn) mote.set_callback(notifId('leds_debug_on'), self.bspLeds.cmd_debug_on) mote.set_callback(notifId('leds_debug_off'), self.bspLeds.cmd_debug_off) mote.set_callback(notifId('leds_debug_toggle'), self.bspLeds.cmd_debug_toggle) mote.set_callback(notifId('leds_debug_isOn'), self.bspLeds.cmd_debug_isOn) mote.set_callback(notifId('leds_all_on'), self.bspLeds.cmd_all_on) mote.set_callback(notifId('leds_all_off'), self.bspLeds.cmd_all_off) mote.set_callback(notifId('leds_all_toggle'), self.bspLeds.cmd_all_toggle) mote.set_callback(notifId('leds_circular_shift'), self.bspLeds.cmd_circular_shift) mote.set_callback(notifId('leds_increment'), self.bspLeds.cmd_increment) # radio mote.set_callback(notifId('radio_init'), self.bspRadio.cmd_init) mote.set_callback(notifId('radio_reset'), self.bspRadio.cmd_reset) mote.set_callback(notifId('radio_startTimer'), self.bspRadio.cmd_startTimer) mote.set_callback(notifId('radio_getTimerValue'), self.bspRadio.cmd_getTimerValue) mote.set_callback(notifId('radio_setTimerPeriod'), self.bspRadio.cmd_setTimerPeriod) mote.set_callback(notifId('radio_getTimerPeriod'), self.bspRadio.cmd_getTimerPeriod) mote.set_callback(notifId('radio_setFrequency'), self.bspRadio.cmd_setFrequency) mote.set_callback(notifId('radio_rfOn'), self.bspRadio.cmd_rfOn) mote.set_callback(notifId('radio_rfOff'), self.bspRadio.cmd_rfOff) mote.set_callback(notifId('radio_loadPacket'), self.bspRadio.cmd_loadPacket) mote.set_callback(notifId('radio_txEnable'), self.bspRadio.cmd_txEnable) mote.set_callback(notifId('radio_txNow'), self.bspRadio.cmd_txNow) mote.set_callback(notifId('radio_rxEnable'), self.bspRadio.cmd_rxEnable) mote.set_callback(notifId('radio_rxNow'), self.bspRadio.cmd_rxNow) mote.set_callback(notifId('radio_getReceivedFrame'), self.bspRadio.cmd_getReceivedFrame) # radiotimer mote.set_callback(notifId('radiotimer_init'), self.bspRadiotimer.cmd_init) mote.set_callback(notifId('radiotimer_start'), self.bspRadiotimer.cmd_start) mote.set_callback(notifId('radiotimer_getValue'), self.bspRadiotimer.cmd_getValue) mote.set_callback(notifId('radiotimer_setPeriod'), self.bspRadiotimer.cmd_setPeriod) mote.set_callback(notifId('radiotimer_getPeriod'), self.bspRadiotimer.cmd_getPeriod) mote.set_callback(notifId('radiotimer_schedule'), self.bspRadiotimer.cmd_schedule) mote.set_callback(notifId('radiotimer_cancel'), self.bspRadiotimer.cmd_cancel) mote.set_callback(notifId('radiotimer_getCapturedTime'), self.bspRadiotimer.cmd_getCapturedTime) # uart mote.set_callback(notifId('uart_init'), self.bspUart.cmd_init) mote.set_callback(notifId('uart_enableInterrupts'), self.bspUart.cmd_enableInterrupts) mote.set_callback(notifId('uart_disableInterrupts'), self.bspUart.cmd_disableInterrupts) mote.set_callback(notifId('uart_clearRxInterrupts'), self.bspUart.cmd_clearRxInterrupts) mote.set_callback(notifId('uart_clearTxInterrupts'), self.bspUart.cmd_clearTxInterrupts) mote.set_callback(notifId('uart_writeByte'), self.bspUart.cmd_writeByte) mote.set_callback(notifId('uart_writeCircularBuffer_FASTSIM'), self.bspUart.cmd_writeCircularBuffer_FASTSIM) mote.set_callback(notifId('uart_writeBufferByLen_FASTSIM'), self.bspUart.uart_writeBufferByLen_FASTSIM) mote.set_callback(notifId('uart_readByte'), self.bspUart.cmd_readByte) # logging this module self.log = logging.getLogger('MoteHandler_' + str(self.id)) self.log.setLevel(logging.INFO) self.log.addHandler(logging.NullHandler()) # logging this mote's modules for loggerName in [ 'MoteHandler_' + str(self.id), # hw 'HwSupply_' + str(self.id), 'HwCrystal_' + str(self.id), # bsp 'BspBoard_' + str(self.id), 'BspBsp_timer_' + str(self.id), 'BspDebugpins_' + str(self.id), 'BspEui64_' + str(self.id), 'BspLeds_' + str(self.id), 'BspRadiotimer_' + str(self.id), 'BspRadio_' + str(self.id), 'BspUart_' + str(self.id), ]: temp = logging.getLogger(loggerName) temp.setLevel(logging.INFO) temp.addHandler(self.loghandler) # initialize parent class threading.Thread.__init__(self) # give this thread a name self.setName('MoteHandler_' + str(self.id)) # thread daemon mode self.setDaemon(True) # log self.log.info('thread initialized')
def __init__(self, confdir, datadir, logdir, simulatorMode, numMotes, trace, debug, simTopology): # store params self.confdir = confdir self.datadir = datadir self.logdir = logdir self.simulatorMode = simulatorMode self.numMotes = numMotes self.trace = trace self.debug = debug # local variables self.eventBusMonitor = eventBusMonitor.eventBusMonitor() self.openLbr = openLbr.OpenLbr() self.rpl = RPL.RPL() self.topology = topology.topology() self.udpLatency = UDPLatency.UDPLatency() self.openTun = openTun.create() # call last since indicates prefix if self.simulatorMode: from openvisualizer.SimEngine import SimEngine, MoteHandler self.simengine = SimEngine.SimEngine(simTopology) self.simengine.start() # create a moteProbe for each mote if not self.simulatorMode: # in "hardware" mode, motes are connected to the serial port self.moteProbes = [ moteProbe.moteProbe(serialport=sp) for sp in moteProbe.findSerialPorts() ] else: # in "simulator" mode, motes are emulated sys.path.append(os.path.join(self.datadir, 'sim_files')) import oos_openwsn MoteHandler.readNotifIds( os.path.join(self.datadir, 'sim_files', 'openwsnmodule_obj.h')) self.moteProbes = [] for _ in range(self.numMotes): moteHandler = MoteHandler.MoteHandler(oos_openwsn.OpenMote()) self.simengine.indicateNewMote(moteHandler) self.moteProbes += [ moteProbe.moteProbe(emulatedMote=moteHandler) ] # create a moteConnector for each moteProbe self.moteConnectors = [ moteConnector.moteConnector(mp.getSerialPortName()) for mp in self.moteProbes ] # create a moteState for each moteConnector self.moteStates = [ moteState.moteState(mc) for mc in self.moteConnectors ] # boot all emulated motes, if applicable if self.simulatorMode: self.simengine.pause() now = self.simengine.timeline.getCurrentTime() for rank in range(self.simengine.getNumMotes()): moteHandler = self.simengine.getMoteHandler(rank) self.simengine.timeline.scheduleEvent( now, moteHandler.getId(), moteHandler.hwSupply.switchOn, moteHandler.hwSupply.INTR_SWITCHON) self.simengine.resume() # start tracing threads if self.trace: import openvisualizer.OVtracer logging.config.fileConfig( os.path.join(self.confdir, 'trace.conf'), {'logDir': _forceSlashSep(self.logdir, self.debug)}) OVtracer.OVtracer()