def on_tx_message_send(self, msg): if not self.connected: self.OpenConnection() text = msg.MsgName() + " " + msgcsv.toCsv(msg) self.debugWidget.textEntryWidget.addText(text + " -> Msg\n> ") self.debugWidget.textEntryWidget.addToHistory(text) self.SendMsg(msg)
def on_tx_message_send(self, msg): if not self.connected: self.OpenConnection() text = msgcsv.toCsv(msg) self.debugWidget.textEntryWidget.addText(text + " -> Msg\n> ") self.debugWidget.textEntryWidget.addToHistory(text) self.SendMsg(msg)
def do_send(self, line): # this translates the input command from CSV to a message, and sends it. msg = msgcsv.csvToMsg(line) if msg: self._connection.send(msg) print("sent " + msg.MsgName() + " " + msgcsv.toCsv(msg)) else: print("ERROR! Invalid msg [%s]!" % (line))
def do_send(self, line): # this translates the input command from CSV to a message, and sends it. msg = msgcsv.csvToMsg(line) if msg: self._connection.send(msg) print("sent " + msgcsv.toCsv(msg)) else: print("ERROR! Invalid msg [%s]!" % (line))
def ProcessMessage(self, msg): self.messageCount += 1 id = msg.hdr.GetMessageID() # if we write CSV to multiple files, we'd probably look up a hash table for this message id, # and open it and write a header if (id in self.outputFiles): outputFile = self.outputFiles[id] else: # create a new file outputFile = open( self.outputName + "/" + msg.MsgName().replace("/", "_") + ".csv", 'w') # store a pointer to it, so we can find it next time (instead of creating it again) self.outputFiles[id] = outputFile # add table header, one column for each message field tableHeader = msgcsv.csvHeader( msg, nameColumn=False, timeColumn=True) + '\n' outputFile.write(tableHeader) try: # \todo Detect time rolling. this only matters when we're processing a log file # with insufficient timestamp size, such that time rolls over from a large number # to a small one, during the log. thisTimestamp = msg.hdr.GetTime() if thisTimestamp < self._lastTimestamp: self._timestampOffset += 1 self._lastTimestamp = thisTimestamp timeSizeInBits = int( round( math.log( int( Messaging.findFieldInfo(msg.hdr.fields, "Time").maxVal), 2))) timestamp = ( self._timestampOffset << timeSizeInBits) + thisTimestamp if Messaging.findFieldInfo(msg.hdr.fields, "Time").units == "ms": timestamp = timestamp / 1000.0 text = str(timestamp) + ", " except AttributeError: text = "unknown, " text += msgcsv.toCsv(msg, nameColumn=False, timeColumn=False) text += '\n' outputFile.write(text) # This is not efficient, but if we don't flush during socket processing # and the user hits Ctrl-C, we'll drop a bunch of data and end up with empty files. # So flush each message as it comes in. if self.connectionType != 'file': outputFile.flush()
def ProcessMessage(self, msg): self.messageCount += 1 id = msg.hdr.GetMessageID() # if we write CSV to multiple files, we'd probably look up a hash table for this message id, # and open it and write a header if(id in self.outputFiles): outputFile = self.outputFiles[id] else: # create a new file outputFile = open(self.outputName + "/" + msg.MsgName().replace("/","_") + ".csv", 'w') # store a pointer to it, so we can find it next time (instead of creating it again) self.outputFiles[id] = outputFile # add table header, one column for each message field tableHeader = msgcsv.csvHeader(msg, nameColumn=False, timeColumn=True) + '\n' outputFile.write(tableHeader) try: # \todo Detect time rolling. this only matters when we're processing a log file # with insufficient timestamp size, such that time rolls over from a large number # to a small one, during the log. thisTimestamp = msg.hdr.GetTime() if thisTimestamp < self._lastTimestamp: self._timestampOffset+=1 self._lastTimestamp = thisTimestamp timeSizeInBits = int(round(math.log(int(Messaging.findFieldInfo(msg.hdr.fields, "Time").maxVal), 2))) timestamp = (self._timestampOffset << timeSizeInBits) + thisTimestamp if Messaging.findFieldInfo(msg.hdr.fields, "Time").units == "ms": timestamp = timestamp / 1000.0 text = str(timestamp) + ", " except AttributeError: text = "unknown, " text += msgcsv.toCsv(msg, nameColumn=False, timeColumn=False) text += '\n' outputFile.write(text) # This is not efficient, but if we don't flush during socket processing # and the user hits Ctrl-C, we'll drop a bunch of data and end up with empty files. # So flush each message as it comes in. if self.connectionType !='file': outputFile.flush()
def toCsv(self, nameColumn=True, timeColumn=False): return msgcsv.toCsv(self, nameColumn=nameColumn, timeColumn=timeColumn)