示例#1
0
def main():
    # Parse arguments
    parser = argparse.ArgumentParser(
        description='Detects current UART bitrate of GNSS modem')

    parser.add_argument(
        '-v', '--verbose',
        action='store_true',
        dest='verbose',
        help='be verbose, show debug output')

    parser.add_argument(
        'current',
        help="current bitrate of receiver", type=int)

    parser.add_argument(
        'new',
        help="new bitrate to set", type=int)

    args = parser.parse_args()
    logger.setLevel(logging.INFO)
    if args.verbose:
        logger.setLevel(logging.DEBUG)

    # Create UBX library
    # Note: tty and baudrate must match current receiver configuration
    ubx = GnssUBlox(TTY, args.current)
    ubx.setup()

    # Register the frame types we use
    ubx.register_frame(UbxCfgPrtUart)

    # Get current tty port settings from modem
    poll_cfg = UbxCfgPrtPoll()
    poll_cfg.f.PortId = UbxCfgPrtPoll.PORTID_Uart

    port_cfg = ubx.poll(poll_cfg)
    if port_cfg:
        print(f'Current port config is\n{port_cfg}')
        print(f'Current modem bitrate is {port_cfg.f.baudRate} bps')

        assert args.current == port_cfg.f.baudRate

        # Set new bitrate
        print(f'Changing bitrate to {args.new}')
        port_cfg.f.baudRate = args.new

        # Note: usually we would use ubx.set() to send the request and wait for an ack
        # Unfortunately the modem changes the bitrate immediately so the ACK is not
        # received.
        ubx.fire_and_forget(port_cfg)

        print('Done, please use detect_bitrate.py to check')
    else:
        print("No answer from modem. Is current bitrate correct?")
        # No answer...
        pass

    ubx.cleanup()
示例#2
0
    def _cfg_port(self):
        if not self.__msg_cfg_port:
            logger.debug('rereading __msg_cfg_port')
            m = UbxCfgPrtPoll()
            m.f.PortId = UbxCfgPrtPoll.PORTID_Uart
            self.__msg_cfg_port = self.ubx.poll(m)

        return self.__msg_cfg_port
示例#3
0
def detect_bitrate_active(ubx):
    logger.info('active scan')

    ubx.register_frame(UbxCfgPrtUart)

    baud_detected = None
    retries = ubx.set_retries(1)
    delay = ubx.set_retry_delay(1500)

    # Try to query current port settings.
    # If bitrate matches we should get a response, reporting the current bitrate.
    # Otherwise the request will timeout.
    poll_cfg = UbxCfgPrtPoll()
    poll_cfg.f.PortId = UbxCfgPrtPoll.PORTID_Uart

    for baud in BIT_RATES:
        logger.info(f'checking {baud} bps')

        ubx.set_baudrate(baud)

        res = ubx.poll(poll_cfg)
        if res:
            if res.f.baudRate == baud:
                logger.debug('bitrate matches')
                baud_detected = baud
                break
            else:
                logger.warning(
                    'bitrate reported ({res.f.baudrate} bps) does not match')
        else:
            logger.debug(f'bitrate {baud} not working')

        # Throttle transmission in order not to trigger receiver frame error detection
        time.sleep(1.0)

    ubx.set_retries(retries)
    ubx.set_retry_delay(delay)

    return baud_detected
示例#4
0
from ubxlib.ubx_cfg_prt import UbxCfgPrtPoll, UbxCfgPrtUart

FORMAT = '%(asctime)-15s %(levelname)-8s %(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('gnss_tool')
logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)

# Create UBX library
# Note: tty is only used to address modem in gpsd.
#       the library does not use the tty directly
ubx = GnssUBlox('/dev/ttyS3')
ubx.setup()

# Register the frame types we use
ubx.register_frame(UbxCfgPrtUart)

# Poll version from modem
poll_cfg = UbxCfgPrtPoll()
poll_cfg.f.PortId = UbxCfgPrtPoll.PORTID_Uart
res = ubx.poll(poll_cfg)

# Simple print of received answer frame
print(f'Received answer from modem\n{res}')

# Get out protocol as value and string
print(res.get('outProtoMask').value)
print(res.get('outProtoMask').protocols)

ubx.cleanup()