Exemplo n.º 1
0
    def _on_send_cfg_msg(self):
        '''
        CFG-MSG command send button has been clicked.
        '''

        msg = UBXMessage.key_from_val(UBX_CONFIG_MESSAGES,
                                      self._cfg_msg_command)
        msgClass = int.from_bytes(msg[0:1], 'little', signed=False)
        msgID = int.from_bytes(msg[1:2], 'little', signed=False)
        rateDDC = int(self._ddc_rate.get())
        rateUART1 = int(self._uart1_rate.get())
        rateUSB = int(self._usb_rate.get())
        rateSPI = int(self._spi_rate.get())
        data = UBXMessage('CFG',
                          'CFG-MSG',
                          SET,
                          msgClass=msgClass,
                          msgID=msgID,
                          rateDDC=rateDDC,
                          rateUART1=rateUART1,
                          rateUSB=rateUSB,
                          rateSPI=rateSPI)
        self.__app.serial_handler.serial_write(data.serialize())
        data = UBXMessage('CFG', 'CFG-MSG', POLL,
                          payload=msg)  # poll for a response
        self.__app.serial_handler.serial_write(data.serialize())

        self.set_status("CFG-MSG command sent")
        self._awaiting_cfgmsg = True
        self._lbl_send_cfg_msg.config(image=self._img_pending)
Exemplo n.º 2
0
    def _do_factory_reset(self) -> bool:
        """
        Restore to factory defaults stored in battery-backed RAM
        but display confirmation message box first.

        :return boolean signifying whether OK was pressed
        :rtype bool
        """

        if messagebox.askokcancel(DLGRESET, DLGRESETCONFIRM):
            clearMask = b"\x1f\x1f\x00\x00"
            loadMask = b"\x1f\x1f\x00\x00"
            deviceMask = b"\x07"  # target RAM, Flash and EEPROM
            msg = UBXMessage(
                "CFG",
                "CFG-CFG",
                SET,
                clearMask=clearMask,
                loadMask=loadMask,
                deviceMask=deviceMask,
            )
            self.__app.serial_handler.serial_write(msg.serialize())
            return True

        return False
Exemplo n.º 3
0
    def _on_send_port(self, *args, **kwargs):
        '''
        Handle Send port config button press.
        '''

        portID = b'\x03'
        reserved0 = b'\x00'
        reserved4 = b'\x00\00'
        reserved5 = b'\x00\00'
        txReady = b'\x00\x00'
        mode = b'\x00\x00\x00\x00'
        baudRate = int.to_bytes(int(self._ubx_baudrate.get()),
                                4,
                                'little',
                                signed=False)
        inProtoMask = int.to_bytes(self._ubx_inprot.get(),
                                   2,
                                   'little',
                                   signed=False)
        outProtoMask = int.to_bytes(self._ubx_outprot.get(),
                                    2,
                                    'little',
                                    signed=False)
        payload = portID + reserved0 + txReady + mode + baudRate + inProtoMask \
                  +outProtoMask + reserved4 + reserved5
        msg = UBXMessage('CFG', 'CFG-PRT', SET, payload=payload)
        self.__app.serial_handler.serial_write(msg.serialize())

        self._do_poll_prt()  # poll for confirmation
        self._lbl_send_port.config(image=self._img_pending)
        self.set_status("CFG-PRT configuration message(s) sent")
Exemplo n.º 4
0
    def _do_poll_prt(self):
        '''
        Poll PRT message configuration
        '''

        msg = UBXMessage('CFG', 'CFG-PRT', POLL)
        self.__app.serial_handler.serial_write(msg.serialize())
Exemplo n.º 5
0
    def _do_cfgmsg(self, msgtype: str, msgrate: int):
        """
        Set rate for specified message type via CFG-MSG.

        NB A rate of n means 'for every nth position solution',
        so values > 1 mean the message is sent less often.

        :param str msgtype: type of config message
        :param int msgrate: message rate (i.e. every nth position solution)
        """

        msgClass = int.from_bytes(msgtype[0:1], "little", signed=False)
        msgID = int.from_bytes(msgtype[1:2], "little", signed=False)
        msg = UBXMessage(
            "CFG",
            "CFG-MSG",
            SET,
            msgClass=msgClass,
            msgID=msgID,
            rateDDC=msgrate,
            rateUART1=msgrate,
            rateUSB=msgrate,
            rateSPI=msgrate,
        )
        self.__app.serial_handler.serial_write(msg.serialize())
Exemplo n.º 6
0
 def testFill_CFGGNSS_NOBITFIELD(
     self, ):  #  test CFG-GNSS SET with parsebitfield = False
     EXPECTED_RESULT = "<UBX(CFG-GNSS, msgVer=0, numTrkChHw=2, numTrkChUse=4, numConfigBlocks=2, gnssId_01=GPS, resTrkCh_01=4, maxTrkCh_01=32, reserved0_01=0, flags_01=b'\\x01\\x00\\x04\\x00', gnssId_02=GLONASS, resTrkCh_02=3, maxTrkCh_02=24, reserved0_02=0, flags_02=b'\\x00\\x00@\\x00')>"
     EXPECTED_RESULT2 = "<UBX(CFG-GNSS, msgVer=0, numTrkChHw=2, numTrkChUse=4, numConfigBlocks=2, gnssId_01=GPS, resTrkCh_01=4, maxTrkCh_01=32, reserved0_01=0, enable_01=1, sigCfMask_01=4, gnssId_02=GLONASS, resTrkCh_02=3, maxTrkCh_02=24, reserved0_02=0, enable_02=0, sigCfMask_02=64)>"
     res = UBXMessage(
         "CFG",
         "CFG-GNSS",
         SET,
         parsebitfield=False,
         numTrkChHw=2,
         numTrkChUse=4,
         numConfigBlocks=2,
         gnssId_01=0,
         resTrkCh_01=4,
         maxTrkCh_01=32,
         flags_01=b"\x01\x00\x04\x00",
         gnssId_02=6,
         resTrkCh_02=3,
         maxTrkCh_02=24,
         flags_02=b"\x00\x00\x40\x00",
     )
     self.assertEqual(str(res), EXPECTED_RESULT)
     res2 = UBXReader.parse(res.serialize(
     ))  # reconstruct message and parse again with parsebitfield = True
     self.assertEqual(str(res2), EXPECTED_RESULT2)
Exemplo n.º 7
0
 def testFill_CFGNMEAPARSE(
     self,
 ):  # check that raw payload is correctly populated and parses back to original message
     EXPECTED_RESULT = "<UBX(CFG-NMEA, posFilt=0, mskPosFilt=0, timeFilt=0, dateFilt=0, gpsOnlyFilter=0, trackFilt=0, nmeaVersion=35, numSV=1, compat=0, consider=0, limit82=0, highPrec=0, gps=0, sbas=0, galileo=0, qzss=0, glonass=0, beidou=0, svNumbering=0, mainTalkerId=0, gsvTalkerId=0, version=0, bdsTalkerId=b'\\x00\\x00', reserved1=0)>"
     res = UBXMessage("CFG", "CFG-NMEA", SET, nmeaVersion=35, numSV=1)
     res2 = UBXReader.parse(res.serialize())
     self.assertEqual(str(res2), EXPECTED_RESULT)
Exemplo n.º 8
0
    def _do_set_inf(self, onoff: int):
        """
        Turn on device information messages INF.

        :param int onoff: on/off boolean
        """

        if onoff:
            mask = b"\x1f"  # all INF msgs
        else:
            mask = b"\x01"  # errors only
        for protocolID in (b"\x00", b"\x01"):  # UBX and NMEA
            reserved1 = b"\x00\x00\x00"
            infMsgMaskDDC = mask
            infMsgMaskUART1 = mask
            infMsgMaskUART2 = mask
            infMsgMaskUSB = mask
            infMsgMaskSPI = mask
            reserved2 = b"\x00"
            payload = (protocolID + reserved1 + infMsgMaskDDC +
                       infMsgMaskUART1 + infMsgMaskUART2 + infMsgMaskUSB +
                       infMsgMaskSPI + reserved2)
            msg = UBXMessage("CFG", "CFG-INF", SET, payload=payload)
            self.__app.serial_handler.serial_write(msg.serialize())
            self._do_poll_inf()  # poll results
Exemplo n.º 9
0
    def _on_send_rate(self, *args, **kwargs):  # pylint: disable=unused-argument
        """
        Handle Send rate config button press.
        """

        tref = 0
        for (key, val) in TIMEREFS.items():
            if val == self._timeref.get():
                tref = key
                break

        msg = UBXMessage(
            "CFG",
            "CFG-RATE",
            SET,
            measRate=self._measint.get(),
            navRate=self._navrate.get(),
            timeRef=tref,
        )
        self.__app.serial_handler.serial_write(msg.serialize())
        self._lbl_send_command.config(image=self._img_pending)
        self.__container.set_status("CFG-RATE SET message sent", "blue")
        self.__container.set_pending(UBX_CFGRATE, ("ACK-ACK", "ACK-NAK"))

        self._do_poll_rate()
Exemplo n.º 10
0
    def config_msg(self, config):
        """
        Creates a series of CFG-MSG configuration messages and
        sends them to the receiver.
        """

        try:

            msgs = []

            # compile all the UBX-NAV config message types
            for key, val in UBX_MSGIDS.items():
                if val == "NAV-PVT":
                    # if val[0:3] == "NAV":
                    msgs.append(key)

            # send each UBX-NAV config message in turn
            for msgtype in msgs:
                payload = msgtype + config
                msg = UBXMessage("CFG", "CFG-MSG", SET, payload=payload)
                print(f"Sending {msg}")
                self._send(msg.serialize())
                sleep(1)

        except (ube.UBXMessageError, ube.UBXTypeError,
                ube.UBXParseError) as err:
            print(f"Something went wrong {err}")
Exemplo n.º 11
0
    def _on_send_cfg_msg(self, *args, **kwargs):  # pylint: disable=unused-argument
        """
        CFG-MSG command send button has been clicked.
        """

        msg = key_from_val(UBX_CONFIG_MESSAGES, self._cfg_msg_command)
        msgClass = int.from_bytes(msg[0:1], "little", signed=False)
        msgID = int.from_bytes(msg[1:2], "little", signed=False)
        rateDDC = int(self._ddc_rate.get())
        rateUART1 = int(self._uart1_rate.get())
        rateUSB = int(self._usb_rate.get())
        rateSPI = int(self._spi_rate.get())
        data = UBXMessage(
            "CFG",
            "CFG-MSG",
            SET,
            msgClass=msgClass,
            msgID=msgID,
            rateDDC=rateDDC,
            rateUART1=rateUART1,
            rateUSB=rateUSB,
            rateSPI=rateSPI,
        )
        self.__app.serial_handler.serial_write(data.serialize())
        self._lbl_send_command.config(image=self._img_pending)
        self.__container.set_status("CFG-MSG SET message sent", "green")
        self.__container.set_pending(UBX_CFGMSG, ("ACK-ACK", "ACK-NAK"))

        self._do_poll_msg(msg)
Exemplo n.º 12
0
    def send_configuration(self, config):
        '''
        Creates a series of CFG-MSG configuration messages and
        sends them to the receiver.
        '''

        try:

            msgs = []

            # compile all the UBX-NAV config message types
            for key, val in UBX_CONFIG_MESSAGES.items():
                if val[0:3] == 'NAV':
                    msgs.append(key)

            # send each UBX-NAV config message in turn
            for msgtype in msgs:
                payload = msgtype + config
                msg = UBXMessage('CFG', 'CFG-MSG', SET, payload=payload)
                print(f"Sending {msg}")
                self._send(msg.serialize())
                sleep(1)

        except (ube.UBXMessageError, ube.UBXTypeError, ube.UBXParseError) as err:
            print(f"Something went wrong {err}")
Exemplo n.º 13
0
def send_sol(stream):
    itow = 172399
    lat = 423362230
    lon = -710865380
    while True:
        nav_sol = UBXMessage(
            "NAV",
            "NAV-SOL",
            GET,
            iTOW=itow,
            fTOW=0,
            week=2150,
            gpsFix=3,
            numSV=12
            # ecefx=1530567000,
            # ecefy=-4466994000,
            # ecefz=273291000
        )
        nav_pvt = UBXMessage("NAV",
                             "NAV-PVT",
                             GET,
                             iTOW=itow,
                             lat=lat,
                             lon=lon,
                             hMSL=1000,
                             fixType=3)
        # print("Sending NAV-SOL...")
        # stream.write(nav_sol.serialize())
        print("Sending NAV-PVT...")
        stream.write(nav_pvt.serialize())
        itow += 200
        lat += 200
        lon += 200
        time.sleep(.2)
Exemplo n.º 14
0
 def testFill_CFGNMEAPARSE(
     self
 ):  # check that raw payload is correctly populated and parses back to original message
     EXPECTED_RESULT = "<UBX(CFG-NMEA, filter=b'\\x00', nmeaVersion=2.3, numSV=1, flags=b'\\x00', gnssToFilter=b'\\x00\\x00\\x00\\x00', svNumbering=0, mainTalkerId=0, gsvTalkerId=0, version=0, bdsTalkerId=b'\\x00\\x00', reserved1=0)>"
     res = UBXMessage('CFG', 'CFG-NMEA', SET, nmeaVersion=35, numSV=1)
     res2 = UBXMessage.parse(res.serialize())
     self.assertEqual(str(res2), EXPECTED_RESULT)
Exemplo n.º 15
0
    def _do_user_defined(self, command: str):
        """
        Parse and send user-defined command(s).

        This could result in any number of errors if the
        uxbpresets file contains garbage, so there's a broad
        catch-all-exceptions in the calling routine.

        :param str command: user defined message constructor(s)
        """

        try:
            seg = command.split(",")
            for i in range(1, len(seg), 4):
                ubx_class = seg[i].strip()
                ubx_id = seg[i + 1].strip()
                payload = seg[i + 2].strip()
                mode = int(seg[i + 3].rstrip("\r\n"))
                if payload != "":
                    payload = bytes(bytearray.fromhex(payload))
                    msg = UBXMessage(ubx_class, ubx_id, mode, payload=payload)
                else:
                    msg = UBXMessage(ubx_class, ubx_id, mode)
                self.__app.serial_handler.serial_write(msg.serialize())
        except Exception as err:  # pylint: disable=broad-except
            self.__app.set_status(f"Error {err}", "red")
            self._lbl_send_command.config(image=self._img_warn)
Exemplo n.º 16
0
    def _do_poll_inf(self):
        """
        Poll INF message configuration.
        """

        for payload in (b"\x00", b"\x01"):  # UBX & NMEA
            msg = UBXMessage("CFG", "CFG-INF", POLL, payload=payload)
            self.__app.serial_handler.serial_write(msg.serialize())
Exemplo n.º 17
0
    def _do_poll_prt(self):
        """
        Poll PRT message configuration for each port.
        """

        for portID in range(5):
            msg = UBXMessage("CFG", "CFG-PRT", POLL, portID=portID)
            self.__app.serial_handler.serial_write(msg.serialize())
Exemplo n.º 18
0
    def _do_poll_inf(self):
        '''
        Poll INF message configuration
        '''

        for payload in (b'\x00', b'\x01'):  # UBX & NMEA
            msg = UBXMessage('CFG', 'CFG-INF', POLL, payload=payload)
            self.__app.serial_handler.serial_write(msg.serialize())
Exemplo n.º 19
0
    def _do_poll_all(self):
        '''
        Poll INF message configuration
        '''

        for msgtype in UBX_PAYLOADS_POLL:
            if msgtype[0:3] == 'CFG' and \
                msgtype not in ('CFG-INF', 'CFG-MSG', 'CFG-PRT-IO', 'CFG-TP5-TPX'):
                msg = UBXMessage('CFG', msgtype, POLL)
                self.__app.serial_handler.serial_write(msg.serialize())
Exemplo n.º 20
0
    def _do_poll_msg(self, msg):
        """
        Poll message rate.
        """

        data = UBXMessage("CFG", "CFG-MSG", POLL, payload=msg)  # poll for a response
        self.__app.serial_handler.serial_write(data.serialize())
        self._lbl_send_command.config(image=self._img_pending)
        self.__container.set_status("CFG-MSG POLL message sent", "blue")
        self.__container.set_pending(UBX_CFGMSG, ("CFG-MSG", "ACK-NAK"))
Exemplo n.º 21
0
    def _do_poll_rate(self, *args, **kwargs):  # pylint: disable=unused-argument
        """
        Poll RATE message configuration.
        """

        msg = UBXMessage("CFG", "CFG-RATE", POLL)
        self.__app.serial_handler.serial_write(msg.serialize())
        self._lbl_send_command.config(image=self._img_pending)
        self.__container.set_status("CFG-RATE POLL message sent", "blue")
        self.__container.set_pending(UBX_CFGRATE, ("CFG-RATE", "ACK-NAK"))
Exemplo n.º 22
0
    def _do_poll_ver(self, *args, **kwargs):  # pylint: disable=unused-argument
        """
        Poll MON-VER & MON-HW
        """

        for msgtype in ("MON-VER", "MON-HW"):
            msg = UBXMessage(msgtype[0:3], msgtype, POLL)
            self.__app.serial_handler.serial.write(msg.serialize())
            self.__container.set_status(f"{msgtype} POLL message sent", "blue")
        self.__container.set_pending(UBX_MONVER, ("MON-VER",))
        self.__container.set_pending(UBX_MONHW, ("MON-HW",))
Exemplo n.º 23
0
 def testFill_ESFMEASSETCT(
     self, ):  #  test ESF_MEAS GET constructor with calibTtagValid = 1
     EXPECTED_RESULT = "<UBX(ESF-MEAS, timeTag=0, timeMarkSent=0, timeMarkEdge=0, calibTtagValid=1, numMeas=0, id=0)>"
     res = UBXMessage("ESF",
                      "ESF-MEAS",
                      GET,
                      timeTag=0,
                      flags=b"\x18\x00",
                      parsebitfield=0)
     res2 = UBXReader.parse(res.serialize())
     self.assertEqual(str(res2), EXPECTED_RESULT)
Exemplo n.º 24
0
    def _do_poll_prt(self):
        """
        Poll PRT message configuration.
        """

        portID = int(self._portid.get()[0:1])
        msg = UBXMessage("CFG", "CFG-PRT", POLL, portID=portID)
        self.__app.serial_handler.serial_write(msg.serialize())
        self._lbl_send_command.config(image=self._img_pending)
        self.__container.set_status("CFG-PRT POLL message sent", "blue")
        self.__container.set_pending(UBX_CFGPRT, ("CFG-PRT", "ACK-NAK"))
Exemplo n.º 25
0
 def testFill_CFGDATPARSE2(
     self,
 ):  # check that raw payload is correctly populated and parses back to original message
     EXPECTED_RESULT = "<UBX(CFG-DAT, majA=0.0, flat=0.0, dX=-1.2345677614212036, dY=27.406539916992188, dZ=0.0, rotX=0.0, rotY=0.0, rotZ=0.0, scale=0.0)>"
     res = UBXMessage(
         "CFG",
         "CFG-DAT",
         SET,
         dX=-1.2345678,
         dY=27.40654,
     )
     res2 = UBXReader.parse(res.serialize(), msgmode=SET)
     self.assertEqual(str(res2), EXPECTED_RESULT)
Exemplo n.º 26
0
    def poll_ubx_config(serial):
        '''
        POLL current UBX device configuration (port protocols
        and software version).

        NB: The responses and acknowledgements to these polls
        may take several seconds to arrive, particularly in
        heavy traffic.
        '''

        for msgtype in ('CFG-PRT', 'MON-VER'):
            msg = UBXMessage(msgtype[0:3], msgtype, POLL)
            serial.write(msg.serialize())
Exemplo n.º 27
0
 def testFill_CFGDATPARSE2(
     self
 ):  # check that raw payload is correctly populated and parses back to original message
     EXPECTED_RESULT = "<UBX(CFG-DAT, datumNum=4, datumName=b'WGS-84', majA=0.0, flat=0.0, dX=-1.2345677614212036, dY=27.406539916992188, dZ=0.0, rotX=0.0, rotY=0.0, rotZ=0.0, scale=0.0)>"
     res = UBXMessage('CFG',
                      'CFG-DAT',
                      SET,
                      datumNum=4,
                      datumName=b'WGS-84',
                      dX=-1.2345678,
                      dY=27.40654)
     res2 = UBXMessage.parse(res.serialize())
     self.assertEqual(str(res2), EXPECTED_RESULT)
Exemplo n.º 28
0
    def send_configuration(self):
        '''
        Creates a CFG-CFG configuration message and
        sends it to the receiver.
        '''

        try:
            msg = UBXMessage('CFG', 'CFG-CFG', SET,
                             clearMask=b'\x1f\x1f\x00\x00',  # clear everything
                             loadMask=b'\x1f\x1f\x00\x00',  # reload everything
                             devicerMask=b'\x07')  # target battery-backed RAM, Flash and EEPROM
            self._send(msg.serialize())
        except (ube.UBXMessageError, ube.UBXTypeError, ube.UBXParseError) as err:
            print(f"Something went wrong {err}")
Exemplo n.º 29
0
    def send_configuration(self, outProtoMask):
        '''
        Creates a CFG-PRT configuration message and
        sends it to the receiver.
        '''

        try:
            msg = UBXMessage('CFG', 'CFG-PRT', SET, portID=3,
                             baudRate=0, inProtoMask=b'\x07\x00',
                             outProtoMask=outProtoMask)
            print(f"Sending {msg}")
            self._send(msg.serialize())
        except (ube.UBXMessageError, ube.UBXTypeError, ube.UBXParseError) as err:
            print(f"Something went wrong {err}")
Exemplo n.º 30
0
    def _do_poll_all(self):
        """
        Poll INF message configuration.
        """

        for msgtype in UBX_PAYLOADS_POLL:
            if msgtype[0:3] == "CFG" and msgtype not in (
                    "CFG-INF",
                    "CFG-MSG",
                    "CFG-PRT-IO",
                    "CFG-TP5-TPX",
            ):
                msg = UBXMessage("CFG", msgtype, POLL)
                self.__app.serial_handler.serial_write(msg.serialize())