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()
def setup_method(self, method): self.nodeStatus = [NodeState(i + 1) for i in range(5)] self.nodeParams = NodeParams(configFile=configFilePath) msgParser = SLIPMsgParser( {'parseMsgMax': self.nodeParams.config.parseMsgMax}) radio = Radio( [], { 'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead, 'rxBufferSize': 2000 }) self.comm = SerialComm([NodeCmdProcessor], self.nodeParams, radio, msgParser)
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)
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
def test_processFCMsg(self): """Test processFCMsg method of NodeExecutive.""" # Create a message parser to test parsing of multiple messages msgParser = SLIPMsgParser( {'parseMsgMax': self.nodeParams.config.parseMsgMax}) self.nodeExecutive.FCComm.msgParser = msgParser # Confirm that messages correctly read testMsg1 = b'ABCDE' testMsg2 = b'FGHJI' self.nodeExecutive.FCComm.sendMsg(testMsg1) self.nodeExecutive.FCComm.sendMsg(testMsg2) time.sleep(0.1) self.nodeExecutive.processFCMsg() assert (len(self.nodeExecutive.FCComm.msgParser.parsedMsgs) == 2) assert (self.nodeExecutive.FCComm.msgParser.parsedMsgs[0] == testMsg1) assert (self.nodeExecutive.FCComm.msgParser.parsedMsgs[1] == testMsg2)
class TestSLIPMsgParser: def setup_method(self, method): # Create SLIPMsgParser instance self.msgParser = SLIPMsgParser({'parseMsgMax': 10}) def test_parseSerialMsg(self): """Test parseSerialMessage method of SLIPMsgParser.""" # Check rejection of message with invalid CRC self.msgParser.parseSerialMsg(truthSLIPMsg, 0) assert(self.msgParser.slipMsg.msgFound == True) # slip msg found assert(self.msgParser.slipMsg.msgEnd != 1) # message end found assert(self.msgParser.parsedMsgs == []) # message rejected # Check acceptance of message with valid CRC crc = self.msgParser.crc16(testMsg) slipMsg = SLIPmsg(256) slipMsg.encodeSLIPmsg(testMsg + pack('H',crc)) # re-encode slip with CRC self.msgParser.parseSerialMsg(slipMsg.slip, 0) assert(self.msgParser.slipMsg.msgFound == True) # slip msg found assert(self.msgParser.slipMsg.msgEnd != 1) # message end found assert(self.msgParser.parsedMsgs[0] == testMsg) # message rejected # Check that proper message end position is returned self.msgParser.parsedMsgs = [] paddedMsg = slipMsg.slip + b'989898' msgEnd = self.msgParser.parseSerialMsg(paddedMsg, 0) assert(self.msgParser.parsedMsgs[0] == testMsg) assert(msgEnd == len(slipMsg.slip)-1) def test_encodeMsg(self): """Test encodeMsg method of SLIPMsgParser.""" crc = self.msgParser.crc16(testMsg) slipMsg = SLIPmsg(256) slipMsg.encodeSLIPmsg(testMsg + pack('H',crc)) encodedMsg = self.msgParser.encodeMsg(testMsg) assert(encodedMsg == slipMsg.slip)
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)
def __init__(self, configFile, meshNum, runFlag): super().__init__(name="CommProcess") # Node control run flag self.nodeControlRunFlag = runFlag # Configuration self.nodeParams = NodeParams(configFile=configFile) # Node/Comm interface interfaceConfig = { 'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead, 'rxBufferSize': self.nodeParams.config.rxBufferSize, 'ipAddr': self.nodeParams.config.interface['nodeCommIntIP'], 'readPort': self.nodeParams.config.interface['commRdPort'], 'writePort': self.nodeParams.config.interface['commWrPort'] } self.interface = SerialComm( [], UDPRadio(interfaceConfig), SLIPMsgParser({'parseMsgMax': self.nodeParams.config.parseMsgMax})) # Interprocess data package self.dataPackage = NodeThreadMsg() self.cmdTxLog = {} self.lastNodeCmdTime = [] ## Create comm object # Serial connection ser = serial.Serial(port=self.nodeParams.config.meshDevices[meshNum], baudrate=self.nodeParams.config.meshBaudrate, timeout=0) # Radio radioConfig = { 'uartNumBytesToRead': self.nodeParams.config.uartNumBytesToRead, 'rxBufferSize': self.nodeParams.config.rxBufferSize } if (self.nodeParams.config.commConfig['fpga'] == True): from mesh.generic.fpgaRadio import FPGARadio radio = FPGARadio(ser, radioConfig) else: if self.nodeParams.config.radios[meshNum] == "Xbee": radio = XbeeRadio(ser, radioConfig, "P8_12") elif self.nodeParams.config.radios[meshNum] == "Li-1": radio = Li1Radio(ser, radioConfig) # Message parser parserConfig = {'parseMsgMax': self.nodeParams.config.parseMsgMax} if self.nodeParams.config.msgParsers[meshNum] == "SLIP": msgParser = SLIPMsgParser(parserConfig) elif self.nodeParams.config.msgParsers[meshNum] == "standard": msgParser = MsgParser(parserConfig) # Create comm if (self.nodeParams.config.commConfig['fpga'] == True): from mesh.generic.tdmaComm_fpga import TDMAComm_FPGA as TDMAComm else: from mesh.generic.tdmaComm import TDMAComm self.comm = TDMAComm([], radio, msgParser, self.nodeParams) # Node control run time bounds if (self.nodeParams.config.commConfig['fpga'] == False): if self.comm.transmitSlot == 1: self.maxNodeControlTime = self.comm.frameLength - self.comm.slotLength self.minNodeControlTime = self.comm.transmitSlot * self.comm.slotLength else: self.minNodeControlTime = ( self.comm.transmitSlot - 2 ) * self.comm.slotLength # don't run within 1 slot of transmit self.maxNodeControlTime = self.comm.transmitSlot * self.comm.slotLength
def setup_method(self, method): # Create SLIPMsgParser instance self.msgParser = SLIPMsgParser({'parseMsgMax': 10})
def setup_method(self, method): self.nodeParams = NodeParams(configFile=configFilePath) self.commProcessor = CommProcessor([], self.nodeParams) msgParser = SLIPMsgParser( {'parseMsgMax': self.nodeParams.config.parseMsgMax}) self.comm = TDMAComm([], [], msgParser, self.nodeParams)