How to use the sbp.client.Handler function in sbp

To help you get started, we’ve selected a few sbp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swift-nav / libsbp / python / sbp / client / examples / pusher_client.py View on Github external
def main():
    args = get_args()
    app = args.app[0]
    key = args.key[0]
    secret = args.secret[0]
    port = args.port[0]
    baud = args.baud[0]
    rx_channel, rx_event = args.rx_channel_event[0].split(':')
    tx_channel, tx_event = args.tx_channel_event[0].split(':')
    push = pusher.Pusher(
        app_id=app, key=key, secret=secret, ssl=True, port=443)
    push_client = pusherclient.Pusher(key, secret=secret)
    with PySerialDriver(port, baud) as driver:
        with Handler(Framer(driver.read, driver.write)) as handler:

            def push_it(sbp_msg):
                push.trigger(tx_channel, tx_event, sbp_msg.to_json_dict())

            def pull_it(data):
                handler(SBP.from_json(data))

            def connect_it(data):
                push_client.subscribe(rx_channel).bind(rx_event, pull_it)

            push_client.connection.bind('pusher:connection_established',
                                        connect_it)
            push_client.connect()

            try:
                for msg, metadata in handler.filter(OBS_MSG_LIST):
github swift-nav / libsbp / python / sbp / client / util / settingmonitor.py View on Github external
parser.add_argument(
            "-H",
            "--host",
            required=True,
            help="specify the host address.")
        parser.add_argument(
            "-p",
            "--port",
            default=55556,
            help="specify the port to use.")
        args = parser.parse_args()

        monitor = SettingMonitor()

        with TCPDriver(args.host, args.port) as driver:
            with Handler(Framer(driver.read, driver.write, verbose=True)) as link:
                driver.flush()
                time.sleep(2)

                # Capture setting messages
                link.add_callback(monitor.capture_setting,
                                  SBP_MSG_SETTINGS_READ_RESP)

                link.add_callback(print_setting, SBP_MSG_SETTINGS_READ_RESP)

                # Disable spectrum analyzer
                link(MsgSettingsWrite(setting=b'%s\0%s\0%s\0' % (
                    b'system_monitor', b'spectrum_analyzer', b'False')))

                # Request the value of the system_monitor:spectrum_analyzer setting
                link(MsgSettingsReadReq(setting=b'%s\0%s\0' % (
                     b'system_monitor', b'spectrum_analyzer')))
github swift-nav / libsbp / python / sbp / client / examples / tcp.py View on Github external
description="Swift Navigation SBP Example.")
    parser.add_argument(
        "-a",
        "--host",
        default='localhost',
        help="specify the host address.")
    parser.add_argument(
        "-p",
        "--port",
        default=55555,
        help="specify the port to use.")
    args = parser.parse_args()

    # Open a connection to Piksi using TCP
    with TCPDriver(args.host, args.port) as driver:
        with Handler(Framer(driver.read, None, verbose=True)) as source:
            try:
                for msg, metadata in source.filter(SBP_MSG_BASELINE_NED):
                    # Print out the N, E, D coordinates of the baseline
                    print("%.4f,%.4f,%.4f" % (msg.n * 1e-3, msg.e * 1e-3,
                                              msg.d * 1e-3))
            except KeyboardInterrupt:
                pass
github swift-nav / libsbp / python / sbp / client / examples / udp.py View on Github external
def main():
    args = get_args()
    address = args.address[0]
    udp_port = args.udp_port[0]

    with PySerialDriver(args.serial_port[0], args.baud[0]) as driver:
        with Handler(Framer(driver.read, driver.write)) as handler:
            with UdpLogger(address, udp_port) as udp:
                handler.add_callback(udp)

                try:
                    while True:
                        time.sleep(0.1)
                except KeyboardInterrupt:
                    pass
github swift-nav / libsbp / python / sbp / client / util / fftmonitor.py View on Github external
default=1,
        help="specify the channel to monitor.")
    parser.add_argument(
        "-o",
        "--output",
        type=str,
        default="fftmonitor",
        help="specify the output filename.")
    args = parser.parse_args()

    monitor = FFTMonitor()
    ch = args.channel
    samples = args.num_ffts

    with TCPDriver(args.host, args.port) as driver:
        with Handler(Framer(driver.read, driver.write, verbose=True)) as link:
            driver.flush()
            link.add_callback(monitor.capture_fft, [SBP_MSG_SPECAN, SBP_MSG_SPECAN_DEP])

            # Capture 5 FFTs from channel 1
            monitor.enable_channel(ch)
            while monitor.num_ffts(ch) < samples:
                time.sleep(1)
            print("Captured %d ffts from channel %d" % (samples, ch))
            ffts = monitor.get_ffts(ch)
            #monitor.disable_channel(ch)

            with open('%s.pickle' % args.output, 'wb') as handle:
                pickle.dump(ffts, handle, protocol=pickle.HIGHEST_PROTOCOL)
github swift-nav / libsbp / python / sbp / client / examples / simple.py View on Github external
def main():
    parser = argparse.ArgumentParser(
        description="Swift Navigation SBP Example.")
    parser.add_argument(
        "-p",
        "--port",
        default=['/dev/ttyUSB0'],
        nargs=1,
        help="specify the serial port to use.")
    args = parser.parse_args()

    # Open a connection to Piksi using the default baud rate (1Mbaud)
    with PySerialDriver(args.port[0], baud=1000000) as driver:
        with Handler(Framer(driver.read, None, verbose=True)) as source:
            try:
                for msg, metadata in source.filter(SBP_MSG_BASELINE_NED):
                    # Print out the N, E, D coordinates of the baseline
                    print("%.4f,%.4f,%.4f" % (msg.n * 1e-3, msg.e * 1e-3,
                                              msg.d * 1e-3))
            except KeyboardInterrupt:
                pass