コード例 #1
0
 def __init__(self, serial, config, sleepPin=[]):
     Radio.__init__(self, serial, config)
     self.sleepPin = sleepPin
     # Setup sleep pin
     if self.sleepPin:
         GPIO.setup(self.sleepPin, "out")
         self.setOff()  # default to off mode
     pass
コード例 #2
0
    def setup_method(self, method):
        self.serialPort = serial.Serial(port=testSerialPort,
                                        baudrate=57600,
                                        timeout=0)

        self.nodeParams = NodeParams(configFile=configFilePath)
        self.radio = Radio(
            self.serialPort, {
                'uartNumBytesToRead':
                self.nodeParams.config.uartNumBytesToRead,
                'rxBufferSize': 2000
            })
コード例 #3
0
ファイル: udpRadio.py プロジェクト: sqf-ice/meshNetwork
    def __init__(self, config):
        Radio.__init__(self, [], config)

        # Read port
        self.sockRead = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sockRead.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.sockRead.bind((config['ipAddr'], config['readPort']))
        self.sockRead.setblocking(0)  # non-blocking to prevent hanging thread

        # Write port
        self.sockWrite = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sockWrite.setblocking(0)
        self.sockWriteIp = config['ipAddr']
        self.sockWritePort = config['writePort']
コード例 #4
0
    def setup_method(self, method):

        if testSerialPort:
            serialPort = serial.Serial(port=testSerialPort,
                                       baudrate=57600,
                                       timeout=0)
        else:
            serialPort = []

        self.nodeParams = NodeParams(configFile=configFilePath)
        self.nodeParams.commStartTime = time.time()
        self.nodeParams.config.commConfig['transmitSlot'] = 1
        self.radio = Radio(
            serialPort, {
                'uartNumBytesToRead':
                self.nodeParams.config.uartNumBytesToRead,
                'rxBufferSize': 2000
            })
        commProcessor = CommProcessor([TDMACmdProcessor, TestCmdProcessor],
                                      self.nodeParams)
        msgParser = SLIPMsgParser(
            {'parseMsgMax': self.nodeParams.config.parseMsgMax})
        self.tdmaComm = TDMAComm(commProcessor, self.radio, msgParser,
                                 self.nodeParams)
        self.tdmaComm.nodeParams.frameStartTime = time.time()
コード例 #5
0
    def setup_method(self, method):

        self.nodeParams = NodeParams(configFile=configFilePath)
        self.nodeParams.config.commConfig['transmitSlot'] = 1
        self.radio = Radio(None, {'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead, 'rxBufferSize': 2000})
        msgParser = MsgParser({'parseMsgMax': self.nodeParams.config.parseMsgMax}, HDLCMsg(256))
        self.tdmaComm = TDMAComm([TDMACmdProcessor], self.radio, msgParser, self.nodeParams)
    
        # Test article
        self.meshController = MeshController(self.nodeParams, self.tdmaComm)
コード例 #6
0
 def setup_method(self, method):
     self.nodeStatus = [NodeState(i + 1) for i in range(5)]
     self.nodeParams = NodeParams(configFile=configFilePath)
     radio = Radio(
         [], {
             'uartNumBytesToRead':
             self.nodeParams.config.uartNumBytesToRead,
             'rxBufferSize': 2000
         })
     self.comm = SerialComm([GndCmdProcessor], self.nodeParams, radio, [])
コード例 #7
0
    def test_processNodeCommands(self):
        """Test processNodeCommands method of NodeController."""
        # Test processing of ConfigRequest command
        configHash = self.nodeController.nodeParams.config.calculateHash()
        radio = Radio([], {'uartNumBytesToRead': 100, 'rxBufferSize': 100})
        comm = SerialComm([], self.nodeController.nodeParams, radio, [])
        comm.cmdQueue[NodeCmds['ConfigRequest']] = configHash

        assert (self.nodeController.nodeParams.configConfirmed == False)
        self.nodeController.processNodeCommands(comm)
        assert (self.nodeController.nodeParams.configConfirmed == True)
コード例 #8
0
 def setup_method(self, method):
     self.nodeStatus = [NodeState(i + 1) for i in range(5)]
     self.nodeParams = NodeParams(configFile=configFilePath)
     msgParser = MsgParser(
         {'parseMsgMax': self.nodeParams.config.parseMsgMax}, SLIPMsg(256))
     radio = Radio(
         [], {
             'uartNumBytesToRead':
             self.nodeParams.config.uartNumBytesToRead,
             'rxBufferSize': 2000
         })
     self.comm = TDMAComm([TDMACmdProcessor], radio, msgParser,
                          self.nodeParams)
コード例 #9
0
 def setup_method(self, method):
     self.nodeParams = NodeParams(configFile=configFilePath)
     self.serialPort = serial.Serial(port=testSerialPort,
                                     baudrate=57600,
                                     timeout=0)
     self.radio = Radio(
         self.serialPort, {
             'uartNumBytesToRead':
             self.nodeParams.config.uartNumBytesToRead,
             'rxBufferSize': 2000
         })
     msgParser = SLIPMsgParser(
         {'parseMsgMax': self.nodeParams.config.parseMsgMax})
     self.comm = SerialComm([], self.nodeParams, self.radio, msgParser)
コード例 #10
0
    def setup_method(self, method):

        if testSerialPort:
            serialPort = serial.Serial(port=testSerialPort, baudrate=57600, timeout=0)
        else:
            serialPort = []

        self.nodeParams = NodeParams(configFile=configFilePath)
        self.nodeParams.config.commConfig['transmitSlot'] = 1
        self.radio = Radio(serialPort, {'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead, 'rxBufferSize': 2000})
        msgParser = MsgParser({'parseMsgMax': self.nodeParams.config.parseMsgMax}, HDLCMsg(256))
        self.tdmaComm = TDMAComm([TDMACmdProcessor], self.radio, msgParser, self.nodeParams)
  
        # Flush radio
        self.radio.serial.read(100)
コード例 #11
0
 def setup_method(self, method):
     self.nodeParams = NodeParams(configFile=configFilePath)
     self.serialPort = serial.Serial(port=testSerialPort,
                                     baudrate=57600,
                                     timeout=0)
     commProcessor = CommProcessor([PixhawkCmdProcessor], self.nodeParams)
     radio = Radio(
         self.serialPort, {
             'uartNumBytesToRead':
             self.nodeParams.config.uartNumBytesToRead,
             'rxBufferSize': 2000
         })
     msgParser = SLIPMsgParser(
         {'parseMsgMax': self.nodeParams.config.parseMsgMax})
     self.nodeComm = NodeComm(commProcessor, radio, msgParser,
                              self.nodeParams)
     pass
コード例 #12
0
    def setup_method(self, method):
        self.nodeParams = NodeParams(configFile=configFilePath)

        # Setup comms
        self.serialConfig = {
            'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead,
            'rxBufferSize': self.nodeParams.config.rxBufferSize
        }
        self.serialPort = serial.Serial(port=testSerialPort,
                                        baudrate=57600,
                                        timeout=0)
        radio = Radio(self.serialPort, self.serialConfig)
        nodeComm = SerialComm([], radio, [])

        #self.FCSerialPort = serial.Serial(port=testSerialPort, baudrate=57600, timeout=0)
        #radio = Radio(self.FCSerialPort, serialConfig)
        FCComm = SerialComm([], radio, [])

        # Create executive
        self.nodeExecutive = NodeExecutive(self.nodeParams, None, [nodeComm],
                                           FCComm, [])
コード例 #13
0
    def test_executeNodeSoftware(self):
        """Test executeNodeSoftware method of NodeExecutive."""
        # Populate comm instances for test
        FCSerialPort = serial.Serial(port=testSerialPort2,
                                     baudrate=57600,
                                     timeout=0)
        radio = Radio(FCSerialPort, self.serialConfig)
        self.nodeExecutive.FCComm.radio = radio
        FCCommOutMsg = b'12345'
        FCCommInMsg = b'67890'
        self.nodeExecutive.FCComm.sendMsg(FCCommInMsg)
        self.nodeExecutive.FCComm.bufferTxMsg(FCCommOutMsg)

        nodeCommOutMsg = b'ABCDE'
        nodeCommInMsg = b'FGHIJ'
        self.nodeExecutive.nodeComm[0].sendMsg(nodeCommInMsg)
        self.nodeExecutive.nodeComm[0].bufferTxMsg(nodeCommOutMsg)

        # Execute method and check for message transmission and reception
        time.sleep(0.1)
        self.nodeExecutive.executeNodeSoftware()
        time.sleep(0.1)
        assert (
            self.nodeExecutive.FCComm.msgParser.parsedMsgs[0] == FCCommInMsg
        )  # test incoming message received
        self.nodeExecutive.FCComm.readBytes()
        assert (self.nodeExecutive.FCComm.radio.rxBuffer[
            0:self.nodeExecutive.FCComm.radio.bytesInRxBuffer] == FCCommOutMsg
                )  # check that transmitted bytes received via loopback
        assert (self.nodeExecutive.nodeComm[0].msgParser.parsedMsgs[0] ==
                nodeCommInMsg)
        self.nodeExecutive.FCComm.readBytes()
        assert (
            self.nodeExecutive.nodeComm[0].radio.
            rxBuffer[0:self.nodeExecutive.nodeComm[0].radio.bytesInRxBuffer] ==
            nodeCommOutMsg
        )  # check that transmitted bytes received via loopback
コード例 #14
0
    def __init__(self, serial, config):
        Radio.__init__(self, serial, config)

        self.crc16 = crcmod.predefined.mkCrcFun('crc16')
コード例 #15
0
    def __init__(self, configFile, runFlag):
        super().__init__(name="NodeControlProcess", )

        # Run flag
        self.runFlag = runFlag

        # Configuration
        nodeParams = NodeParams(configFile=configFile)

        # Flight computer serial port
        FCSer = serial.Serial(port=nodeParams.config.FCCommDevice,
                              baudrate=nodeParams.config.FCBaudrate,
                              timeout=0)

        # Create radios
        radios = []
        radioConfig = {
            'uartNumBytesToRead': nodeParams.config.uartNumBytesToRead,
            'rxBufferSize': nodeParams.config.rxBufferSize,
            'ipAddr': nodeParams.config.interface['nodeCommIntIP'],
            'readPort': nodeParams.config.interface['commWrPort'],
            'writePort': nodeParams.config.interface['commRdPort']
        }
        for i in range(nodeParams.config.numMeshNetworks):
            radios.append(
                UDPRadio(radioConfig))  # connection to communication processes
        FCRadio = Radio(FCSer, radioConfig)

        # Create message parsers
        msgParsers = []
        parserConfig = {'parseMsgMax': nodeParams.config.parseMsgMax}
        for i in range(nodeParams.config.numMeshNetworks):
            if nodeParams.config.msgParsers[i] == "SLIP":
                msgParsers.append(SLIPMsgParser(parserConfig))
            elif nodeParams.config.msgParsers[i] == "standard":
                msgParsers.append(MsgParser(parserConfig))
        FCMsgParser = SLIPMsgParser(parserConfig)

        # Open logfiles
        currentTime = str(time.time())
        FCLogFilename = 'fc_' + currentTime + '.log'
        self.FCLogFile = open(FCLogFilename, 'w')
        nodeCommLogFilename = 'node_' + currentTime + '.log'
        self.nodeCommLogFile = open(nodeCommLogFilename, 'w')

        # Failsafe LED interval
        failsafeLEDTime = 1.0  # seconds
        failsafeLEDOnTime = -1.0
        failsafeLEDOn = False

        # Initialize node and flight computer communication variables
        nodeComm = [[]] * nodeParams.config.numMeshNetworks
        FCComm = []

        # Instantiate specific node software
        self.nodeController = []
        self.nodeExecutive = []
        for case in switch(nodeParams.config.platform
                           ):  # Platform specific initializations
            if case("SpecificNode"):
                pass
            else:  # generic node
                from mesh.generic.nodeComm import NodeComm
                from mesh.generic.nodeController import NodeController
                from mesh.generic.nodeExecutive import NodeExecutive

                print("Initializing generic node")

                # Initialize communication variables
                for i in range(nodeParams.config.numMeshNetworks):
                    nodeComm[i] = NodeComm([], radios[i], msgParsers[i],
                                           nodeParams)
                FCComm = NodeComm([], FCRadio, FCMsgParser, nodeParams)

                # Node controller
                self.nodeController = NodeController(nodeParams,
                                                     self.nodeCommLogFile)

                # Node executive
                self.nodeExecutive = NodeExecutive(nodeParams,
                                                   self.nodeController,
                                                   nodeComm, FCComm,
                                                   self.FCLogFile)
コード例 #16
0
class TestRadio:
    def setup_method(self, method):
        self.serialPort = serial.Serial(port=testSerialPort,
                                        baudrate=57600,
                                        timeout=0)

        self.nodeParams = NodeParams(configFile=configFilePath)
        self.radio = Radio(
            self.serialPort, {
                'uartNumBytesToRead':
                self.nodeParams.config.uartNumBytesToRead,
                'rxBufferSize': 2000
            })

    def test_setMode(self):
        """Test setMode method of RadioInterface."""
        assert (self.radio.mode == RadioMode.off)

        # Set mode to receive
        self.changeMode(RadioMode.receive)

        # Set mode to off
        self.changeMode(RadioMode.off)

        # Set mode to transmit
        self.changeMode(RadioMode.transmit)

        # Set mode to sleep
        self.changeMode(RadioMode.sleep)

    def changeMode(self, mode):
        self.radio.setMode(mode)
        assert (self.radio.mode == mode)

    def test_clearRxBuffer(self):
        """Test clearRxBuffer method of Radio."""
        self.radio.rxBuffer = [1, 2, 3, 4, 5]
        self.radio.clearRxBuffer()
        assert (self.radio.rxBuffer == bytearray(self.radio.rxBufferSize))
        assert (self.radio.bytesInRxBuffer == 0)

    def test_bufferRxMsg(self):
        """Test bufferRxMsg method of Radio."""
        # Test without buffer
        assert (self.radio.bytesInRxBuffer == 0)
        testMsg = b'1234567890'
        self.radio.bufferRxMsg(testMsg, False)
        assert (self.radio.bytesInRxBuffer == len(testMsg))
        assert (self.radio.rxBuffer[0:len(testMsg)] == testMsg)

        # Test buffering
        self.radio.bufferRxMsg(testMsg, True)
        assert (self.radio.bytesInRxBuffer == len(testMsg) * 2)
        assert (self.radio.rxBuffer[0:2 * len(testMsg)] == testMsg + testMsg)

        # Test buffer overflow
        self.radio.rxBufferSize = 10
        self.radio.clearRxBuffer()  # update buffer size

        self.radio.bufferRxMsg(testMsg, True)
        assert (self.radio.rxBuffer == testMsg)
        self.radio.bufferRxMsg(b'99999',
                               True)  # confirm that bytes are not buffered
        assert (self.radio.rxBuffer == testMsg)

    def test_getRxBytes(self):
        """Test getRxBytes method of Radio."""
        msg = b'12345'
        self.radio.bufferRxMsg(msg, True)
        assert (self.radio.getRxBytes() == msg)

    def test_processRxBytes(self):
        """Test processRxBytes method of Radio."""
        # Base class method just buffers bytes
        testMsg = b'1234567890'
        assert (self.radio.bytesInRxBuffer == 0)
        self.radio.processRxBytes(testMsg, True)
        assert (self.radio.getRxBytes() == testMsg)

    def test_sendMsg(self):
        """Test sendMsg method of Radio."""
        # Send test message
        testMsg = b'123456789'
        msgBytes = testMsg
        self.radio.sendMsg(testMsg)
        time.sleep(0.1)
        self.radio.readBytes(True)
        readBytes = self.radio.getRxBytes()
        assert (readBytes == msgBytes)

    def test_bufferTxMsg(self):
        """Test bufferTxMsg method of Radio."""
        msg = b'12345'
        self.radio.bufferTxMsg(msg)
        assert (self.radio.txBuffer == msg)

        # Confirm that buffer appends and doesn't overwrite
        msg2 = b'67890'
        self.radio.bufferTxMsg(msg2)
        assert (self.radio.txBuffer == msg + msg2)

    def test_createMsg(self):
        """Test createMsg method of Radio."""
        msg = b'12345'
        assert (self.radio.createMsg(msg) == msg)

    def test_sendCommand(self):
        pass

    def test_readBytes(self):
        """Test readBytes method of Radio."""
        # Write bytes and read
        msgBytes = b'ABC'
        self.serialPort.write(msgBytes)
        time.sleep(0.1)
        numBytesRead = self.radio.readBytes(False)
        assert (numBytesRead == len(msgBytes))
        assert (self.radio.bytesInRxBuffer == len(msgBytes))
        serBytes = self.radio.getRxBytes()
        assert (serBytes == msgBytes)

        # Write again and confirm buffer is not kept
        msgBytes = b'DEF'
        self.serialPort.write(msgBytes)
        time.sleep(0.1)
        self.radio.readBytes(False)
        assert (self.radio.bytesInRxBuffer == len(msgBytes))
        serBytes = self.radio.getRxBytes()
        assert (serBytes == msgBytes)

        # Write again and confirm buffer is kept
        msgBytes = b'ABC'
        self.serialPort.write(msgBytes)
        time.sleep(0.1)
        self.radio.readBytes(True)
        assert (self.radio.bytesInRxBuffer == 2 * len(msgBytes))
        serBytes = self.radio.getRxBytes()
        assert (serBytes == b'DEFABC')

        # Test exception raising
        self.radio.serial = []
        with pytest.raises(NoSerialConnection):
            self.radio.readBytes(False)

    def test_sendBuffer(self):
        """Test sendBuffer method of Radio."""
        msg = b'12345'
        self.radio.bufferTxMsg(msg)
        self.radio.sendBuffer()
        assert (len(self.radio.txBuffer) == 0
                )  # buffer should clear after data sent
        time.sleep(0.1)
        self.radio.readBytes(True)
        assert (self.radio.getRxBytes() == msg)

        # Test maximum bytes sent
        self.radio.clearRxBuffer()
        msg = b'1' * 100
        self.radio.bufferTxMsg(msg)
        self.radio.sendBuffer(50)
        time.sleep(0.1)
        self.radio.readBytes(True)
        assert (len(self.radio.txBuffer) == 50)
        assert (self.radio.bytesInRxBuffer == 50)
コード例 #17
0
 def __init__(self, serial, config):
     Radio.__init__(self, serial, config)
     self.cmdRxBuffer = bytearray()