Beispiel #1
0
 def HandleButtonPress(self):
     # when a button is used to start a log, the text of that button changes to "Stop".
     # starting any other log will stop the current one (changing it's text back to normal)
     button = self.sender()
     if "logtag" in button.options:
         if button == self.activeLogButton:
             self.CloseLogFile()
             button.setText(button.label)
             self.activeLogButton = None
         else:
             if self.activeLogButton != None:
                 self.activeLogButton.setText(self.activeLogButton.label)
             self.CreateLogFile(button.options["logtag"][0])
             button.setText("Stop")
             self.activeLogButton = button
     if "send" in button.options:
         for opts in button.options['send']:
             msgname = opts.split("[")[0]
             fields = opts.split("[")[1].replace("]", "").split(",")
             msgClass = Messaging.MsgClassFromName[msgname]
             msg = msgClass()
             for field in fields:
                 parts = field.split("=")
                 name = parts[0]
                 value = parts[1]
                 Messaging.set(
                     msg, Messaging.findFieldInfo(msgClass.fields, name),
                     value)
             self.SendMsg(msg)
 def HandleButtonPress(self):
     # when a button is used to start a log, the text of that button changes to "Stop".
     # starting any other log will stop the current one (changing it's text back to normal)
     button = self.sender()
     if "logtag" in button.options:
         if button == self.activeLogButton:
             self.CloseLogFile()
             button.setText(button.label)
             self.activeLogButton = None
         else:
             if self.activeLogButton != None:
                 self.activeLogButton.setText(self.activeLogButton.label)
             self.CreateLogFile(button.options["logtag"][0])
             button.setText("Stop")
             self.activeLogButton = button
     if "send" in button.options:
         for opts in button.options['send']:
             msgname = opts.split("[")[0]
             fields = opts.split("[")[1].replace("]","").split(",")
             msgClass = Messaging.MsgClassFromName[msgname]
             msg = msgClass()
             for field in fields:
                 parts = field.split("=")
                 name = parts[0]
                 value = parts[1]
                 Messaging.set(msg, Messaging.findFieldInfo(msgClass.fields, name), value)
             self.SendMsg(msg)
    def sendMsg(self, msgClass):
        msg = msgClass()
        if self.timeInfo:
            hdr = Messaging.hdr(msg.rawBuffer())
            t = self.currentTime
            maxTime = self.timeInfo.maxVal
            # if the timestamp field is small, assume the user wants relative times since midnight.
            if maxTime != "DBL_MAX" and (maxTime == 'FLT_MAX' or float(maxTime) <= 2**32):
                t = (datetime.fromtimestamp(self.currentTime) - datetime.fromtimestamp(self.currentTime).replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds()
            if self.timeInfo.units == "ms":
                t = t * 1000.0
            if self.timeInfo.type == "int":
                t = int(t)
            hdr.SetTime(t)

        for fieldInfo in msgClass.fields:
            if fieldInfo.units == 'ASCII':
                Messaging.set(msg, fieldInfo, 's'+str(self.fieldValue(fieldInfo)))
            else:
                if(fieldInfo.count == 1):
                    Messaging.set(msg, fieldInfo, str(self.fieldValue(fieldInfo)))
                    for bitInfo in fieldInfo.bitfieldInfo:
                        Messaging.set(msg, bitInfo, str(self.fieldValue(bitInfo)))
                else:
                    for i in range(0,fieldInfo.count):
                        Messaging.set(msg, fieldInfo, self.fieldValue(fieldInfo), i)
        self.SendMsg(msg)
Beispiel #4
0
    def test_accessors(self):
        msgclass = Messaging.MsgClassFromName["Network.Connect"]
        sameMsgClass = Messaging.Messages.Network.Connect
        self.assertEqual(msgclass, sameMsgClass)

        expected = "Testing"
        testMsg = msgclass()
        Messaging.set(testMsg, msgclass.fields[0], expected)
        observed = testMsg.GetName()
        self.assertMultiLineEqual(expected, observed)
        
        expected="MoreTesting"
        testMsg.SetName(expected)
        observed=Messaging.get(testMsg, msgclass.fields[0])
        self.assertMultiLineEqual(expected, observed)
Beispiel #5
0
    def test_accessors(self):
        msgclass = Messaging.MsgClassFromName["Network.Connect"]
        sameMsgClass = Messaging.Messages.Network.Connect
        self.assertEqual(msgclass, sameMsgClass)

        expected = "Testing"
        testMsg = msgclass()
        Messaging.set(testMsg, msgclass.fields[0], expected)
        observed = testMsg.GetName()
        self.assertMultiLineEqual(expected, observed)

        expected = "MoreTesting"
        testMsg.SetName(expected)
        observed = Messaging.get(testMsg, msgclass.fields[0])
        self.assertMultiLineEqual(expected, observed)
Beispiel #6
0
    def setData(self, column, role, value):
        if self.index == None:
            return

        if column != 2:
            return

        if self.fieldInfo.name == "ID":
            return

        if self.fieldInfo.type == "int" and value.startswith("0x"):
            value = str(int(value, 0))

        # set the value in the message/header buffer
        Messaging.set(self.msg, self.fieldInfo, value, int(self.index))

        # get the value back from the message/header buffer and pass on to super-class' setData
        super(EditableFieldArrayItem, self).setData(column, role, Messaging.get(self.msg, self.fieldInfo, int(self.index)))
Beispiel #7
0
    def setData(self, column, role, value):
        if not column == 2:
            return

        if self.fieldInfo.name == "ID":
            return
        
        if self.fieldInfo.type == "int" and value.startswith("0x"):
            value = str(int(value, 0))

        # if user deletes the value, for anything besides a string,
        # return without setting the new value
        if self.fieldInfo.type != "string" and value == "":
            return

        # set the value in the message/header buffer
        Messaging.set(self.msg, self.fieldInfo, value)

        # get the value back from the message/header buffer and pass on to super-class' setData
        super(FieldItem, self).setData(column, role, Messaging.get(self.msg, self.fieldInfo))
Beispiel #8
0
    def sendMsg(self, msgClass):
        msg = msgClass()
        try:
            hdr = Messaging.hdr(msg.rawBuffer())
            hdr.SetTime(self.currentTime)
        except AttributeError:
            pass
        for fieldInfo in msgClass.fields:

            if fieldInfo.units == 'ASCII':
                Messaging.set(msg, fieldInfo,
                              's' + str(self.fieldValue(fieldInfo)))
            else:
                if (fieldInfo.count == 1):
                    Messaging.set(msg, fieldInfo,
                                  str(self.fieldValue(fieldInfo)))
                    for bitInfo in fieldInfo.bitfieldInfo:
                        Messaging.set(msg, bitInfo,
                                      str(self.fieldValue(bitInfo)))
                else:
                    for i in range(0, fieldInfo.count):
                        Messaging.set(msg, fieldInfo,
                                      self.fieldValue(fieldInfo), i)
        self.SendMsg(msg)
Beispiel #9
0
 def overrideWidgetValueChanged(self, value):
     valueAsString = self.overrideWidget.itemText(value)
     # set the value in the message/header buffer
     Messaging.set(self.msg, self.fieldInfo, valueAsString)