Ejemplo n.º 1
0
 def __init__(self, device, quiet=True):
     self.loop = gobject.MainLoop()
     self.pollMaxRetries = 3
     self.quiet = quiet
     self.requestedMessageTypes = None
     self.message = None
     if device is not None:
         self.parser = ubx.Parser(self._waitForMessage, device=device)
     else:
         self.parser = ubx.Parser(self._waitForMessage)
Ejemplo n.º 2
0
Archivo: stream.py Proyecto: jkua/ubx

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--device', '-d', default=None)
    group.add_argument('--file', '-f', default=None)
    parser.add_argument('--output', '-o', default=None)
    parser.add_argument('--raw', action='store_true')
    args = parser.parse_args()

    logging.basicConfig(level=logging.WARNING)

    if args.output is not None:
        outputFile = open(args.output, 'wb')

    if args.device:
        t = ubx.Parser(callback, device=args.device, rawCallback=rawCallback)
        try:
            gobject.MainLoop().run()
        except KeyboardInterrupt:
            gobject.MainLoop().quit()
            if outputFile is not None:
                outputFile.close()
    else:
        t = ubx.Parser(callback, device=False)
        binFile = args.file
        data = open(binFile, 'r').read()
        t.parse(data)
Ejemplo n.º 3
0
import calendar
import os
import gobject
import logging
import sys
import socket
import time


def callback(ty, packet):
    print("callback %s" % repr([ty, packet]))


if __name__ == "__main__":
    assert len(sys.argv) == 2
    t = ubx.Parser(callback)
    if sys.argv[1] == "on":
        t.send(
            "CFG-MSG", 3, {
                "Class": ubx.CLIDPAIR["RXM-RAW"][0],
                "MsgID": ubx.CLIDPAIR["RXM-RAW"][1],
                "Rate": 1
            })
        t.send(
            "CFG-MSG", 3, {
                "Class": ubx.CLIDPAIR["RXM-SFRB"][0],
                "MsgID": ubx.CLIDPAIR["RXM-SFRB"][1],
                "Rate": 1
            })
    else:
        t.send(
Ejemplo n.º 4
0
import logging
import sys
import time


def callback(ty, *args):
    if ty == 'RXM-RAW':
        NSV = args[0][0]["NSV"]
        ITOW = args[0][0]["ITOW"]
        #print(repr(NSV))
        for i in xrange(NSV):
            block = args[0][1 + i]
            # {'MesQI': 7, 'DOMes': -947.04443359375, 'SV': 16, 'LLI': 0, 'CPMes': 127712782.07132973, 'CNO': 38, 'PRMes': 24302931.671289716}
            print("%d %s %s %s" %
                  (block["SV"], ITOW, block["PRMes"], block["CPMes"]))


if __name__ == "__main__":
    print("""<?xml version="1.0" encoding="UTF-8"?>
<gpx
  version="1.0"
  creator="GPSBabel - http://www.gpsbabel.org"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://www.topografix.com/GPX/1/0"
  xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">"""
          )
    t = ubx.Parser(callback, device=False)
    data = sys.stdin.read()
    t.parse(data)
    print("</gpx>")
Ejemplo n.º 5
0
            poll_nav_posllh()
        else:
            #print("poll scheduled")
            gobject.timeout_add(1000, poll_nav_status)
    elif state == 1 and ty == "NAV-POSLLH":
        print("%s %s %s %s %s %s" %
              (d["NAV-STATUS"][0][0]["GPSfix"],
               d["NAV-STATUS"][0][0]["TTFF"] * 10**-3,
               int(time.time() - start),
               d["NAV-POSLLH"][0][0]["LAT"] * 10**-7,
               d["NAV-POSLLH"][0][0]["LON"] * 10**-7,
               d["NAV-POSLLH"][0][0]["Hacc"] * 10**-3))
               
        #print("done")
        loop.quit()

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--device', '-d', help='Specify the serial port device to communicate with. e.g. /dev/ttyO5')
    args = parser.parse_args()

    if args.device is not None:
        t = ubx.Parser(callback, device=args.device)
    else:
        t = ubx.Parser(callback)
    print('Polling NAV-STATUS... press CTRL-C to stop')
    poll_nav_status()
    # gobject.timeout_add(TIMEOUT * 1000, timeout)
    loop.run()
Ejemplo n.º 6
0
        itow = packet[0]["ITOW"]

def cbUbxRaw(payload):
    #print("cbUbxRaw %s" % " ".join("%02x" % ord(x) for x in payload))
    ubxfile.write(payload)

def cbButtonPress(source, condition):
    print("cbButtonPress %s %s" % (source, condition))
    data = os.read(source, 512)
    events = [ data[i:i+input_event_size] for i in range(0, len(data), input_event_size) ]
    for e in events:
        timestamp, microseconds, typ, code, value = struct.unpack( input_event_struct, e )
        # We need more then just second accuracy
        timestamp = timestamp + microseconds/1000000.0
        if typ != 0x00: # ignore EV_SYN (synchronization event)
            print("event %s %s %s %s %s %s" % (week, itow, timestamp, typ, code, value))
            keyfile.write("event %s %s %s %s %s %s\n" % (week, itow, timestamp, typ, code, value))
            keyfile.flush()
            if code == 169 and value == 1:
                pass
            if code == 116 and value == 1:
                pass
    return True

if __name__ == "__main__":
    fd = os.open("/dev/input/event4", os.O_NONBLOCK | os.O_RDONLY)
    fcntl.ioctl(fd, 0x40044590, 1) # EVIOCGRAB
    gobject.io_add_watch(fd, gobject.IO_IN, cbButtonPress)
    ubx.Parser(cbUbxPacket, rawCallback = cbUbxRaw)
    gobject.MainLoop().run()
Ejemplo n.º 7
0
def main(argv):
    # Usage
    if len(sys.argv) <= 1:
        print >> sys.stderr, 'Usage python ' + sys.argv[0] + ' [port]'
        # Exit with error code
        sys.exit(1)

    port = argv[0]

    #Create logging file and logger
    out_path = "generated/"
    if not os.path.exists(out_path):
        os.makedirs(out_path)

    # get the root logger
    logger = logging.getLogger()
    # set overall level to debug, default is warning for root logger
    logger.setLevel(logging.DEBUG)

    log_file = "generated/coordinates"

    # setup logging to file, rotating at midnight
    filelog = logging.handlers.TimedRotatingFileHandler(log_file,
                                                        when='midnight',
                                                        interval=1,
                                                        backupCount=0,
                                                        utc=True)
    filelog.setLevel(logging.DEBUG)
    logger.addHandler(filelog)

    # setup logging to console
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    logger.addHandler(console)
    '''logger = logging.getLogger("Coordinates Log")
    logger.setLevel(logging.INFO)
    handler = TimedRotatingFileHandler(log_file, when="m",interval=1,backupCount=0, utc=True)
    handler.setLevel(logging.DEBUG)
    logger.addHandler(handler)'''

    # Create directory if not exists and open file
    # TODO send CTRL-C to this script at midnight and create a new file (from bash)
    '''global out_file
    timestamp = time.time()
    out_file_name = "coordinates_" + \
                    datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d') + ".txt"
    out_path = "generated/"
    if not os.path.exists(out_path):
        os.makedirs(out_path)
    if not os.path.exists(out_path + out_file_name):
        out_file = open(out_path + out_file_name, "w")
    else:
        out_file = open(out_path + out_file_name, "a")
        out_file.write("\n")
    print "Script started...\nFile Opened...\nStarting parser...."
    '''

    # Assignment at the start
    global ecef_string, llh_string, ecef_itow, llh_itow, old_time
    ecef_string = llh_string = ""
    ecef_itow = llh_itow = old_time = 0

    # Register handler Ctrl-C
    signal.signal(signal.SIGINT, signal_handler)

    # Start the parser
    t = ubx.Parser(callback, '/dev/' + port, logger=logger)
    print "Parser Started...\n"
    t.parsedevice()