コード例 #1
0
    def startRemoteConnector(self, PCip, PCport, roverID):
        '''Start the remote connection when infos received by coap server

        :param PCip : ip of the central computer
        :param PCport : port of the connection
        '''
        for probe in self.moteProbes:
            probe.close()
        # in "hardware" mode, motes are connected to the serial port
        self.moteProbes = [
            moteProbe.moteProbe(serialport=p) for p in moteProbe.findSerialPorts(True)
        ]

        if self.remoteConnector :
            self.remoteConnector.close()
            #leave it time to timeout
            time.sleep(2)
            self.remoteConnector=None
        self.remoteConnector = remoteConnectorRover.remoteConnectorRover(app=self, PCip=PCip, PCport=PCport, roverID=roverID)
コード例 #2
0
ファイル: openRoverApp.py プロジェクト: dnshp/openwsn-mod
    def startRemoteConnector(self, PCip, PCport, roverID):
        '''Start the remote connection when infos received by coap server

        :param PCip : ip of the central computer
        :param PCport : port of the connection
        '''
        for probe in self.moteProbes:
            probe.close()
        # in "hardware" mode, motes are connected to the serial port
        self.moteProbes = [
            moteProbe.moteProbe(serialport=p)
            for p in moteProbe.findSerialPorts()
        ]

        if self.remoteConnector:
            self.remoteConnector.close()
            #leave it time to timeout
            time.sleep(1)
            self.remoteConnector = None
        self.remoteConnector = remoteConnectorRover.remoteConnectorRover(
            app=self, PCip=PCip, PCport=PCport, roverID=roverID)
コード例 #3
0
    def __init__(self,confdir,datadir,logdir,simulatorMode,numMotes,trace,debug,usePageZero,simTopology,iotlabmotes, testbedmotes, 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.testbedmotes         = testbedmotes
        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.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(',')
            ]
        elif self.testbedmotes:
            motesfinder = moteProbe.OpentestbedMoteFinder()
            self.moteProbes       = [
                moteProbe.moteProbe(testbedmote_eui64=p) for p in motesfinder.get_opentestbed_motelist()
            ]
            
        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()
コード例 #4
0
    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()
コード例 #5
0
    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()
コード例 #6
0
 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()