def sendRequest(self, event): # Check connected if not commsConnectWarning.confirmConnected(gui.frame): return protocols.getProtocol().sendUtilitySoftResetRequest()
def __init__(self, parent): '''Setup UI elements''' wx.BoxSizer.__init__(self, wx.HORIZONTAL) self.text = wx.StaticText(parent, -1, 'Payload ID', style=wx.ALIGN_CENTER) self.options = protocols.getProtocol().getMemoryRequestPayloadIdList() self.input = wx.Choice(parent, -1, choices=self.options) self.text2 = wx.StaticText(parent, -1, 'Block ID', style=wx.ALIGN_CENTER) self.options2 = protocols.getProtocol().getMemoryRequestBlockIdList() self.input2 = wx.Choice(parent, -1, choices=self.options2) self.send = wx.Button(parent, self.ID_SEND_REQUEST, 'Send Request') self.send.Bind(wx.EVT_BUTTON, self.sendRequest, id=self.ID_SEND_REQUEST) sizer4 = wx.BoxSizer(wx.HORIZONTAL) sizer4.Add((0,0), 1) sizer4.Add(self.send, 18, wx.EXPAND) sizer4.Add((0,0), 1) sizer5 = wx.BoxSizer(wx.VERTICAL) sizer5.Add((0,0), 1) sizer5.Add(sizer4, 18, wx.EXPAND) sizer5.Add((0,0), 1) sizer3 = wx.BoxSizer(wx.VERTICAL) sizer3.Add((0,0), 1) sizer3.Add(self.text2, 3, wx.EXPAND) sizer3.Add((0,0), 1) sizer3.Add(self.input2, 5, wx.EXPAND) sizer3.Add((0,0), 1) sizer2 = wx.BoxSizer(wx.VERTICAL) sizer2.Add((0,0), 1) sizer2.Add(self.text, 3, wx.EXPAND) sizer2.Add((0,0), 1) sizer2.Add(self.input, 5, wx.EXPAND) sizer2.Add((0,0), 1) sizer1 = wx.BoxSizer(wx.HORIZONTAL) sizer1.Add((0,0), 1) sizer1.Add(sizer2, 6, wx.EXPAND) sizer1.Add((0,0), 1) sizer1.Add(sizer3, 10, wx.EXPAND) sizer1.Add((0,0), 1) sizer1.Add(sizer5, 6, wx.EXPAND) sizer1.Add((0,0), 1) self.Add(sizer1)
def sendRequest(self, event): '''Send utility request''' # Check connected if not commsConnectWarning.confirmConnected(gui.frame): return selection = self.input.GetSelection() # Correct small bug where selection will be -1 if input has not # been in focus if selection < 0: selection = 0 protocols.getProtocol().sendUtilityRequest(selection)
def insertRow(self, packet): '''Insert row into grid''' time = datetime.datetime.time(datetime.datetime.now()) header = self.getHeaderFlags(packet) payload_hex = packet.getPayloadBytes() #Format stuff before printing payload_id = packet.getPayloadIdInt() payload_id_hum = protocols.getProtocol().getPacketType(payload_id) payload_hex_hum = self.formatPayloadHex(payload_hex) self.AppendRows() self.SetCellValue(self.row, 0, str(time)) self.SetCellValue(self.row, 1, str(header)) self.SetCellValue(self.row, 2, str(payload_id) + ":" + payload_id_hum) self.SetCellValue(self.row, 3, payload_hex_hum) # Make sure entire row is visible if self.GetCellOverflow(self.row, 3): lines = payload_hex_hum.count('\n') + 1 self.SetRowSize(self.row, (lines * 15) + 3) self.MakeCellVisible(self.row + 1, 1) self.ForceRefresh() self.row += 1
def recieve(self): '''Check for and recieve packets waiting in the connection''' conn = self.getConnection() buffer_size = conn.inWaiting() # If nothing in serial buffer, and nothing unprocessed # don't hold up the UI any longer than we have to if not buffer_size and not len(self._buffer): return # If anything new in the buffer, convert to bytes and # append to what we have left unprocessed if buffer_size: buffer = conn.read(buffer_size) for char in buffer: self._buffer.append(ord(char)) # Get protocol protocol = protocols.getProtocol() # Check for any complete packets try: cache = copy.copy(self._buffer) packet = protocol.processRecieveBuffer(self._buffer) except Exception, msg: logger.error(msg) logger.error('processRecieveBuffer failed to parse packet from buffer: %s' % join(protocols.toHex(cache))) self._buffer = [] return
def __init__(self, parent): '''Setup UI elements''' wx.BoxSizer.__init__(self, wx.VERTICAL) # Get payload id's options = protocols.getProtocol().getMemoryRequestPayloadIdList() for id in options.keys(): self._p_options.append('%s (%d)' % (options[id], id)) self._p_ids.append(id) self._p_text = wx.StaticText(parent, -1, 'Payload ID', style = wx.ALIGN_CENTER) self._p_input = wx.Choice(parent, -1, choices = self._p_options) # Get block id's try: locations = data.loadProtocolDataFile('location_ids')['FreeEMSLocationIDs'] location_keys = [] for key in locations.keys(): location_keys.append(int(key)) location_keys.sort() options = {} for location in location_keys: self._b_options.append('%s (%d)' % (locations[str(location)], location)) self._b_ids.append(location) except KeyError, e: # Data file appears to be formed incorrectly logger.error('Data location ids data file appears to be formed incorrectly: %s' % e) self._b_options = [] self._b_ids = []
def getProtocol(self): ''' Return (and load if necessary) protocol interface ''' if not self._protocol: self._protocol = protocols.getProtocol(self._controller) return self._protocol
def sendRequest(self, event): '''Send memory request''' # Check connected if not commsConnectWarning.confirmConnected(gui.frame): return payload_id = self._p_input.GetSelection() block_id = self._b_input.GetSelection() # Correct small bug where selection will be -1 if input has not # been in focus if payload_id < 0: payload_id = 0 if block_id < 0: block_id = 0 payload_id = self._p_ids[payload_id] block_id = self._b_ids[block_id] protocols.getProtocol().sendMemoryRequest(payload_id, block_id)
def send(self, packet): # Get protocol protocol = protocols.getProtocol() # Get return packet hex = protocol.getTestResponse(packet.getPayloadIdInt()) # Append to input buffer # In this fake comms plugin, all sent packets # are reflected back at the moment self._buffer.extend(hex) # Log packet hex logger.debug('Packet sent to test comms connection: %s' % ','.join(packet.getPacketHex())) for watcher in self._send_watchers: watcher(packet)
def __init__(self, parent): '''Setup UI elements''' wx.BoxSizer.__init__(self, wx.VERTICAL) self.text = wx.StaticText(parent, -1, 'Data to request', style=wx.ALIGN_CENTER) self.options = protocols.getProtocol().getUtilityRequestList() self.input = wx.Choice(parent, -1, choices=self.options) self.send = wx.Button(parent, self.ID_SEND_REQUEST, 'Send Request') self.Add((0,0), 1) self.Add(self.text, 3, wx.EXPAND) self.Add((0,0), 1) self.Add(self.input, 5, wx.EXPAND) self.Add((0,0), 1) self.Add(self.send, 5, wx.EXPAND) self.Add((0,0), 1) self.send.Bind(wx.EVT_BUTTON, self.sendRequest, id=self.ID_SEND_REQUEST)
def recieve(self): '''Check for and recieve packets waiting in the connection''' # If nothing in buffer if not len(self._buffer): return # Get protocol protocol = protocols.getProtocol() # Check for any complete packets cache = copy.copy(self._buffer) try: packet = protocol.processRecieveBuffer(self._buffer) except Exception, msg: raise logger.error(msg) logger.error('processRecieveBuffer failed to parse packet from buffer: %s' % join(protocols.toHex(cache))) self._buffer = [] return