Example #1
20
def get_GPS_array():    
    com = UART(1,pins=(config.TX, config.RX),  baudrate=9600) 
    my_gps = MicropyGPS()
    time.sleep(2)
    if com.any():
        my_sentence = com.readline()
        for x in my_sentence:
            my_gps.update(chr(x)) 
        gps_array = convert_latlon(my_gps.latitude[0] + (my_gps.latitude[1] / 60), my_gps.longitude[0] + (my_gps.longitude[1] / 60))
        return gps_array
Example #2
1
def start_GPS():    
    com = UART(1,pins=("P11","P12"),  baudrate=9600) 
    my_gps = MicropyGPS()
    if config.LOG == 1:
        mount_sd()
        my_gps.start_logging('/sd/log.txt')
        my_gps.write_log('Restarted logging')

    while True:
        if com.any():
            my_sentence = com.readline()
            for x in my_sentence:
                my_gps.update(chr(x))
            print('Latitude: ' + my_gps.latitude_string() + ' Longitude: ' + my_gps.longitude_string() + ' Altitude: ' + str(my_gps.altitude))
            print('Lat / Lon: ' + str(my_gps.latitude[0] + (my_gps.latitude[1] / 60)) + ', ' + str(my_gps.longitude[0] + (my_gps.longitude[1] / 60)))
Example #3
1
def gps():

    new_data = False

    # Callback Function
    def pps_callback(line):
        global new_data  # Use Global to trigger update
        new_data = True

    # Instantiate the micropyGPS object
    my_gps = MicropyGPS()

    # Setup the connection to your GPS here
    # This example uses UART 3 with RX on pin Y10
    # Baudrate is 9600bps, with the standard 8 bits, 1 stop bit, no parity
    # Also made the buffer size very large (1000 chars) to accommodate all the characters that stack up
    # each second
    uart = pyb.UART(sys_config['pmod']['p3']['uart'], 9600, read_buf_len=1000)

    # Release Reset
    reset = pyb.Pin(sys_config['pmod']['p3']['reset'], pyb.Pin.OUT_PP)
    reset.high()

    # Create an external interrupt on pin X8
    pps_pin = pyb.Pin(sys_config['pmod']['p3']['one_pps'],
                      pyb.Pin.IN,
                      pull=pyb.Pin.PULL_UP)
    extint = pyb.ExtInt(pps_pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP,
                        pps_callback)

    # Main Infinite Loop
    while 1:
        # Do Other Stuff Here.......

        # Update the GPS Object when flag is tripped
        if new_data:
            while uart.any():
                my_gps.update(
                    chr(uart.readchar())
                )  # Note the conversion to to chr, UART outputs ints normally
            #print('UTC Timestamp:', my_gps.timestamp)
            print('Date:', my_gps.date_string('long'))
            print('Latitude:', my_gps.latitude_string())
            print('Longitude:', my_gps.longitude_string())
            print('Horizontal Dilution of Precision:', my_gps.hdop)
            print('Satellites in use:', my_gps.satellites_in_use)
            print()
            new_data = False  # Clear the flag
Example #4
0
    def parse_log_file(self, filename):
        # instances of a class
        gnss_nmea_sentence = MicropyGPS()
        glo_nmea_sentence = MicropyGPS()
        bdo_nmea_sentence = MicropyGPS()

        # open file as utf8
        with open(filename, encoding="utf8") as f:
            for line in f:
                if "# Version:" in line:
                    self.parse_info_line(line)
                # This section below is commented because non of our log files had enough raw data for computation
                # gnss solution. Only one smartphone has it, and it was analysed by gnss-measurement-tool by Google(c)
                # elif "Raw" in line:
                #     raw_list = (line.split(','))
                #     del raw_list[0]
                #     if raw_list[-1] == '\n':
                #         raw_list[-1] = ''
                #     if not raw_data:
                #         emp = raw._make(raw_list)
                #         print("first")
                #         for fld in emp._fields:
                #             if (not getattr(emp, fld)) or (float(getattr(emp, fld)) == 0.0):
                #                 bad_cal.append(fld)
                #             else:
                #                 good_col.append(fld)
                #         raw_fixed = namedtuple('raw_fixed', good_col)
                #     for i, list in enumerate(raw_list):
                #         if not list or float(list) == 0.0:
                #             del_list.append(i)
                #     raw_list = [v for i, v in enumerate(raw_list) if i not in del_list]
                #     emp = raw_fixed._make(raw_list)
                #     raw_data.append(emp)
                elif "Fix" in line:
                    fix_list = (line.split(','))
                    del fix_list[0]
                    if fix_list[-1] == '\n':
                        del fix_list[-1]
                    emp = fix._make(fix_list)
                    self.fix_data.append(emp)
                elif "NMEA" in line:
                    timestamp_local = gnss_nmea_sentence.timestamp
                    if line[6:8] == 'GP' or line[6:8] == 'GN':
                        for y in line[5:-1]:
                            gnss_nmea_sentence.update(y)
                    # This section below is commented because not all logs files have equal nmea string format
                    # Because of this not all constellations can be parsed. Either you except some log files
                    # (for us it was PIE log file) and uncomment section below or you leave it commented
                    # elif line[6:8] == 'GL':
                    #     for y in line[5:-1]:
                    #         glo_nmea_sentence.update(y)
                    # elif line[6:8] == 'BD':
                    #     for y in line[5:-1]:
                    #         bdo_nmea_sentence.update(y)
                    if gnss_nmea_sentence.timestamp != timestamp_local:
                        self.gnss_data.append(deepcopy(gnss_nmea_sentence))
                        self.glo_data.append(deepcopy(glo_nmea_sentence))
                        self.bdo_data.append(deepcopy(bdo_nmea_sentence))
        return self
Example #5
0
    def __init__(self):
        #initialize state from saved file
        try:
            file = open('state.csv', 'r')
            s = file.read().strip(',')
            if len(s) == 6:
                for i in range(len(s)):
                    s[i] = eval(s[i])
            file.close()
        except:
            self.X = np.array([0, 0, 0, 0, 0, 0]).reshape([6, 1])
        self.P = np.ones([6, 6]) * 1000
        self.Y = np.array([0, 0, 0, 0, 0, 0]).reshape([6, 1])
        self.time = 0
        self.alt = 0
        self.dt = 1
        self.burstCount = 0
        self.burst = False

        self.windSpeed = []
        for i in range(1, 311):
            #wind vector: [alt, vx, vy, sum_vx, sum_vy, N]
            self.windSpeed.append([i * 100, 0, 0, 0, 0, 0])

        #initialize IMU and GPS objects
        self.mpu = MPU9250.MPU9250()
        self.gps = MicropyGPS(
            -6)  #-6 for Central Time; input is time zone offset

        #destination coordinates
        self.target = csvReadMat('target.csv').reshape([2])

        #set instrument variance
        self.R = csvReadMat('instVariance.csv')
Example #6
0
def test_gll_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    print('')
    for sentence_count, GLL_sentence in enumerate(test_GLL):
        for y in GLL_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPGLL"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == gll_parsed_string[sentence_count]
                print('Parsed Strings', my_gps.gps_segments)
                assert my_gps.crc_xor == gll_crc_values[sentence_count]
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.longitude == gll_longitude[sentence_count]
                print('Longitude:', my_gps.longitude)
                assert my_gps.latitude == gll_latitude[sentence_count]
                print('Latitude', my_gps.latitude)
                assert my_gps.timestamp == gll_timestamp[sentence_count]
                print('UTC Timestamp:', my_gps.timestamp)
                assert my_gps.valid == gll_valid[sentence_count]
                print('Data is Valid:', my_gps.valid)
    assert my_gps.clean_sentences == len(test_GLL)
    assert my_gps.parsed_sentences == len(test_GLL)
    assert my_gps.crc_fails == 0
Example #7
0
def test_vtg_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    sentence_count = 0
    print('')
    for VTG_sentence in test_VTG:
        for y in VTG_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPVTG"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == [
                    'GPVTG', '232.9', 'T', '', 'M', '002.3', 'N', '004.3', 'K',
                    'A', '01'
                ]
                print('Parsed Strings', my_gps.gps_segments)
                assert my_gps.crc_xor == 0x1
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.speed == (2.3, 2.6473, 4.2596)
                print('Speed:', my_gps.speed)
                assert my_gps.course == 232.9
                print('Course', my_gps.course)
                assert my_gps.compass_direction() == 'SW'
                print('Compass Direction:', my_gps.compass_direction())
                sentence_count += 1
    assert my_gps.clean_sentences == len(test_VTG)
    assert my_gps.parsed_sentences == len(test_VTG)
    assert my_gps.crc_fails == 0
Example #8
0
def run():
    """Run the program."""
    uart = UART(1)
    uart.init(config.baudrate,
              bits=8,
              parity=None,
              stop=1,
              rx=config.rx,
              tx=config.tx)
    gps = MicropyGPS()
    s = screen.Screen()

    kph = None
    start = utime.ticks_ms()
    while kph is None and utime.ticks_diff(utime.ticks_ms(), start) < 1000:
        if uart.any():
            try:
                stat = gps.update(chr(uart.read(1)[0]))
            except:
                pass
            if stat == 'GNRMC':
                print(stat)
                kph = gps.speed[2]

    if kph is not None:
        s.update(kph)

    machine.deepsleep(5000)
Example #9
0
def test_pretty_print():
    my_gps = MicropyGPS()
    for RMC_sentence in test_RMC[5]:
        for y in RMC_sentence:
            my_gps.update(y)
    for GGA_sentence in test_GGA[2]:
        for y in GGA_sentence:
            my_gps.update(y)
    for VTG_sentence in test_VTG:
        for y in VTG_sentence:
            my_gps.update(y)
    print('')
    assert my_gps.latitude_string() == "37° 49.1802' N"
    print('Latitude:', my_gps.latitude_string())
    assert my_gps.longitude_string() == "83° 38.7865' W"
    print('Longitude:', my_gps.longitude_string())
    assert my_gps.speed_string('kph') == '4.2596 km/h'
    print('Speed:', my_gps.speed_string('kph'), 'or', my_gps.speed_string('mph'), 'or', my_gps.speed_string('knot'))
    assert my_gps.speed_string('mph') == '2.6473 mph'
    assert my_gps.speed_string('knot') == '2.3 knots'
    assert my_gps.date_string('long') == 'May 28th, 2011'
    print('Date (Long Format):', my_gps.date_string('long'))
    assert my_gps.date_string('s_dmy') == '28/05/11'
    print('Date (Short D/M/Y Format):', my_gps.date_string('s_dmy'))
    assert my_gps.date_string('s_mdy') == '05/28/11'
    print('Date (Short M/D/Y Format):', my_gps.date_string('s_mdy'))
Example #10
0
def test_gsv_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    print('')
    for sentence_count, GSV_sentence in enumerate(test_GSV):
        for y in GSV_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPGSV"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == gsv_parsed_string[sentence_count]
                print('Parsed Strings', my_gps.gps_segments)
                assert my_gps.crc_xor == gsv_crc_values[sentence_count]
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.last_sv_sentence == gsv_sv_setence[sentence_count]
                print('SV Sentences Parsed', my_gps.last_sv_sentence)
                assert my_gps.total_sv_sentences == gsv_total_sentence[sentence_count]
                print('SV Sentences in Total', my_gps.total_sv_sentences)
                assert my_gps.satellites_in_view == gsv_num_sats_in_view[sentence_count]
                print('# of Satellites in View:', my_gps.satellites_in_view)
                assert my_gps.satellite_data_updated() == gsv_data_valid[sentence_count]
                data_valid = my_gps.satellite_data_updated()
                print('Is Satellite Data Valid?:', data_valid)
                if data_valid:
                    print('Complete Satellite Data:', my_gps.satellite_data)
                    print('Complete Satellites Visible:', my_gps.satellites_visible())
                else:
                    print('Current Satellite Data:', my_gps.satellite_data)
                    print('Current Satellites Visible:', my_gps.satellites_visible())
                assert my_gps.satellite_data == gsv_sat_data[sentence_count]
                assert my_gps.satellites_visible() == gsv_sats_in_view[sentence_count]
    assert my_gps.clean_sentences == len(test_GSV)
    assert my_gps.parsed_sentences == len(test_GSV)
    assert my_gps.crc_fails == 0
Example #11
0
 def __init__(self):
     self._gps_uart = machine.UART(1, 9600)
     self.cfg = ConfigRepository()
     self._gps_uart.init(tx=self.cfg.get("gps_uart_tx"),
                         rx=self.cfg.get("gps_uart_rx"))
     self._gps = MicropyGPS()
     self._model = None
Example #12
0
def test_gga_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    print('')
    for sentence_count, GGA_sentence in enumerate(test_GGA):
        for y in GGA_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPGGA"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == gga_parsed_strings[sentence_count]
                print('Parsed Strings', my_gps.gps_segments)
                assert my_gps.crc_xor == gga_crc_xors[sentence_count]
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.longitude == gga_longitudes[sentence_count]
                print('Longitude', my_gps.longitude)
                assert my_gps.latitude == gga_latitudes[sentence_count]
                print('Latitude', my_gps.latitude)
                assert my_gps.timestamp == gga_timestamps[sentence_count]
                print('UTC Timestamp:', my_gps.timestamp)
                assert my_gps.fix_stat == gga_fixes[sentence_count]
                print('Fix Status:', my_gps.fix_stat)
                assert my_gps.altitude == gga_altitudes[sentence_count]
                print('Altitude:', my_gps.altitude)
                assert my_gps.geoid_height == gga_geoid_heights[sentence_count]
                print('Height Above Geoid:', my_gps.geoid_height)
                assert my_gps.hdop == gga_hdops[sentence_count]
                print('Horizontal Dilution of Precision:', my_gps.hdop)
                assert my_gps.satellites_in_use == gga_satellites_in_uses[sentence_count]
                print('Satellites in Use by Receiver:', my_gps.satellites_in_use)
    assert my_gps.clean_sentences == len(test_GGA)
    assert my_gps.parsed_sentences == len(test_GGA)
    assert my_gps.crc_fails == 0
Example #13
0
def test_gsa_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    print('')
    for sentence_count, GSA_sentence in enumerate(test_GSA):
        for y in GSA_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPGSA"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == gsa_parsed_strings[sentence_count]
                print('Parsed Strings', my_gps.gps_segments)
                assert my_gps.crc_xor == gsa_crc_values[sentence_count]
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.satellites_used == gsa_sats_used[sentence_count]
                print('Satellites Used', my_gps.satellites_used)
                assert my_gps.fix_type == 3
                print('Fix Type Code:', my_gps.fix_type)
                assert my_gps.hdop == gsa_hdop[sentence_count]
                print('Horizontal Dilution of Precision:', my_gps.hdop)
                assert my_gps.vdop == gsa_vdop[sentence_count]
                print('Vertical Dilution of Precision:', my_gps.vdop)
                assert my_gps.pdop == gsa_pdop[sentence_count]
                print('Position Dilution of Precision:', my_gps.pdop)
    assert my_gps.clean_sentences == len(test_GSA)
    assert my_gps.parsed_sentences == len(test_GSA)
    assert my_gps.crc_fails == 0
Example #14
0
def test_rmc_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    print('')
    for sentence_count, RMC_sentence in enumerate(test_RMC):
        for y in RMC_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPRMC"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == rmc_parsed_strings[sentence_count]
                print('Parsed Strings:', my_gps.gps_segments)
                assert my_gps.crc_xor == rmc_crc_values[sentence_count]
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.longitude == rmc_longitude[sentence_count]
                print('Longitude:', my_gps.longitude)
                assert my_gps.latitude == rmc_latitude[sentence_count]
                print('Latitude', my_gps.latitude)
                assert my_gps.timestamp == rmc_utc[sentence_count]
                print('UTC Timestamp:', my_gps.timestamp)
                assert my_gps.speed == rmc_speed[sentence_count]
                print('Speed:', my_gps.speed)
                assert my_gps.date == rmc_date[sentence_count]
                print('Date Stamp:', my_gps.date)
                assert my_gps.course == rmc_course[sentence_count]
                print('Course', my_gps.course)
                assert my_gps.valid
                print('Data is Valid:', my_gps.valid)
                assert my_gps.compass_direction() == rmc_compass[sentence_count]
                print('Compass Direction:', my_gps.compass_direction())
    assert my_gps.clean_sentences == len(test_RMC)
    assert my_gps.parsed_sentences == len(test_RMC)
    assert my_gps.crc_fails == 0
    def read_next(self):
        buf = ['\0']
        var = True

        iNeedDollar = '$'
        while iNeedDollar != self._fd.read():
            pass
        #buf.append(iNeedDollar)
        buf = [iNeedDollar] + buf

        while var:
            #buf[len(buf)-1]=iNeedDollar
            buf[len(buf) - 1] = self._fd.read()
            if buf[len(buf) - 1] == '\r':
                buf[len(buf) - 1] = '\n'
            buf.append('\0')
            if (len(buf) > 2 and buf[len(buf) - 2] == '\n'
                    and buf[len(buf) - 3] == '\n'):
                self._my_gps = MicropyGPS()
                my_sentence = ''.join(buf)
                for x in my_sentence:
                    self._my_gps.update(x)
                var = False
            #print(self._fd.read())
        print(''.join(buf))
 def __init__(self, uart_channel: int):
     """
     Begin reading data from the GPS over UART.
     :param uart_channel: The UART channel that the GPS is connected to.
     """
     self.gps = MicropyGPS(location_formatting="dd")
     asyncio.create_task(self.uart_rx(uart_channel))
Example #17
0
    def __init__(self,num_sentences=3,timeout=5):
        p_pwr2.value(1)  # turn on power to the GPS
        p_pwr3.value(1)  # the GPS requires power from multiple GPIOs
        p_pwr4.value(1)

        self.num_sentences=num_sentences
        self.timeout=timeout
        self.my_gps = MicropyGPS()  # create GPS parser object
Example #18
0
 def __init__(self):
     self.timestamp = [0, 0, 0.0]
     self.timestamp_string = ''
     self.latitude = 0.0
     self.longitude = 0.0
     self.altitude = 0.0
     self.speed = []
     self.course = 0.0
     self.satellites_used = []
     self.satellite_data = {}
     self.gps = MicropyGPS(9, 'dd')
     self.gpsthread = threading.Thread(target=self.runGps, args=())
     self.gpsthread.daemon = True
     self.gpsthread.start()
Example #19
0
def test_coordinate_representations():
    my_gps = MicropyGPS(location_formatting='dd')
    for RMC_sentence in test_RMC[5]:
        for y in RMC_sentence:
            my_gps.update(y)
    print('')
    assert my_gps.latitude_string() == '53.361336666666666° N'
    print('Decimal Degrees Latitude:', my_gps.latitude_string())
    assert my_gps.longitude_string() == '6.5056183333333335° W'
    print('Decimal Degrees Longitude:', my_gps.longitude_string())
    my_gps.coord_format = 'dms'
    print('Degrees Minutes Seconds Latitude:', my_gps.latitude_string())
    assert my_gps.latitude_string() == """53° 21' 41" N"""
    assert my_gps.longitude_string() == """6° 30' 20" W"""
    print('Degrees Minutes Seconds Longitude:', my_gps.longitude_string())
Example #20
0
def setup():
    global gps
    global uart
    global x1
    global x2
    global y1
    global y2

    gps = MicropyGPS()
    uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=30)

    x1 = gps.longitude[1]
    y1 = gps.latitude[1]

    x2 = float(input("Enter Latitude"))
    y2 = float(input("Enter Longitude"))
Example #21
0
def set_date_time():    
    com = UART(1,pins=(config.TX, config.RX),  baudrate=9600) 
    my_gps = MicropyGPS()
    time.sleep(2)
    if com.any():
        my_sentence = com.readline()
        for x in my_sentence:
            my_gps.update(chr(x)) 
        date = my_gps.date
        timestamp = my_gps.timestamp
        hour = timestamp[0]
        hour = hour + config.TIMEZONE
        if config.DAYLIGHT == 1:
            hour = hour + 1
        rtc = RTC(datetime=(int(date[2])+2000, int(date[1]), int(date[0]), int(timestamp[0]), int(timestamp[1]), int(timestamp[2]), 0, None)) 
        return rtc      
Example #22
0
 def __init__(self, module):
     super().__init__(module, 9)  # 9 byte data packet
     self.param = {
         # must be params
         'NAME': PNAME,
         'ENABLE': False,
         'TIMER': 0,
         'PORT': '',
         # instance specific params
         'RespVarPos': 'GPS.Position',
         'RespVarLat': 'GPS.Latitude',
         'RespVarLon': 'GPS.Longitude',
         'RespVarCrs': 'GPS.Course',
         'RespVarAlt': 'GPS.Altitude',
         'RespVarSpd': 'GPS.Speed',
     }
     self._gps = MicropyGPS(local_offset=0, location_formatting='ddm')
 def __init__(self):
     self.timestamp = [0, 0, 0.0]
     self.timestamp_string = ""
     self.latitude = 0.0
     self.longitude = 0.0
     self.altitude = 0.0
     self.speed = []
     self.course = 0.0
     self.satellites_used = []
     self.satellite_data = {}
     try:
         self.serial = Serial("/dev/serial0", 9600, timeout=10)
     except:
         self.serial = Serial("/dev/ttyACM0", 9600, timeout=10)
         print(
             "Exception occurred in receiving GPS data. Switching to another serial port."
         )
     self.gps = MicropyGPS(9, "dd")
     self.gpsthread = threading.Thread(target=self.run_gps, args=())
     self.gpsthread.daemon = True
     self.gpsthread.start()
Example #24
0
def test_logging():
    my_gps = MicropyGPS()
    assert my_gps.start_logging('test.txt', mode="new")
    assert my_gps.write_log('micropyGPS test log\n')
    for RMC_sentence in test_RMC:
        for y in RMC_sentence:
            my_gps.update(y)
    assert my_gps.stop_logging()
    with open('test.txt', 'rb') as log_file:
        log_hash = hashlib.md5()
        log_hash.update(log_file.read())
        assert log_hash.digest() == b'\x33\xa7\x5e\xae\xeb\x8d\xf8\xe8\xad\x5e\x54\xa2\xfd\x6a\x11\xa3'
    assert my_gps.start_logging('test.txt', mode="append")
    for GSV_sentence in test_GSV:
        for y in GSV_sentence:
            my_gps.update(y)
    assert my_gps.stop_logging()
    with open('test.txt', 'rb') as log_file:
        log_hash = hashlib.md5()
        log_hash.update(log_file.read())
        assert log_hash.digest() == b'\xa4\x16\x79\xe1\xf9\x30\x0e\xd9\x73\xc8\x43\xc4\xa4\x0f\xe4\x3b'
Example #25
0
def test_gga_sentences():
    my_gps = MicropyGPS()
    sentence = ''
    sentence_count = 0
    print('')
    for GGA_sentence in test_GGA:
        for y in GGA_sentence:
            sentence = my_gps.update(y)
            if sentence:
                assert sentence == "GPGGA"
                print('Parsed a', sentence, 'Sentence')
                assert my_gps.gps_segments == [
                    'GPGGA', '180050.896', '3749.1802', 'N', '08338.7865', 'W',
                    '1', '07', '1.1', '397.4', 'M', '-32.5', 'M', '', '0000',
                    '6C'
                ]
                print('Parsed Strings', my_gps.gps_segments)
                assert my_gps.crc_xor == 0x6c
                print('Sentence CRC Value:', hex(my_gps.crc_xor))
                assert my_gps.longitude == [83, 38.7865, 'W']
                print('Longitude', my_gps.longitude)
                assert my_gps.latitude == [37, 49.1802, 'N']
                print('Latitude', my_gps.latitude)
                assert my_gps.timestamp == [18, 0, 50.896]
                print('UTC Timestamp:', my_gps.timestamp)
                assert my_gps.fix_stat == 1
                print('Fix Status:', my_gps.fix_stat)
                assert my_gps.altitude == 397.4
                print('Altitude:', my_gps.altitude)
                assert my_gps.geoid_height == -32.5
                print('Height Above Geoid:', my_gps.geoid_height)
                assert my_gps.hdop == 1.1
                print('Horizontal Dilution of Precision:', my_gps.hdop)
                assert my_gps.satellites_in_use == 7
                print('Satellites in Use by Receiver:',
                      my_gps.satellites_in_use)
                sentence_count += 1
    assert my_gps.clean_sentences == len(test_GGA)
    assert my_gps.parsed_sentences == len(test_GGA)
    assert my_gps.crc_fails == 0
Example #26
0
def test_logging():
    my_gps = MicropyGPS()
    assert my_gps.start_logging('test.txt', mode="new")
    assert my_gps.write_log('micropyGPS test log\n')
    for RMC_sentence in test_RMC:
        for y in RMC_sentence:
            my_gps.update(y)
    assert my_gps.stop_logging()
    with open('test.txt', 'rb') as log_file:
        log_hash = hashlib.md5()
        log_hash.update(log_file.read())
        assert log_hash.digest(
        ) == b'\x8e\xe4\x29\x5a\xad\xf6\xed\x7d\xd1\x81\x5a\xbf\x62\xa7\x60\xe4'
    assert my_gps.start_logging('test.txt', mode="append")
    for GSV_sentence in test_GSV:
        for y in GSV_sentence:
            my_gps.update(y)
    assert my_gps.stop_logging()
    with open('test.txt', 'rb') as log_file:
        log_hash = hashlib.md5()
        log_hash.update(log_file.read())
        assert log_hash.digest(
        ) == b'\xc5\xf7\x2f\x7d\x4a\xee\xe3\x7d\x1c\x0c\x57\xc0\xe6\x68\x4a\x63'
def pps_callback(line):
    print("Updated GPS Object...")
    global new_data  # Use Global to trigger update
    new_data = True

    print('GPS Interrupt Tester')

    # Instantiate the micropyGPS object
    my_gps = MicropyGPS()

    # Setup the connection to your GPS here
    # This example uses UART 3 with RX on pin Y10
    # Baudrate is 9600bps, with the standard 8 bits, 1 stop bit, no parity
    # Also made the buffer size very large (1000 chars) to accommodate all the characters that stack up
    # each second
    uart = UART(3, 9600, read_buf_len=1000)

    # Create an external interrupt on pin X8
    pps_pin = pyb.Pin.board.X8
    extint = pyb.ExtInt(pps_pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, pps_callback)

    # Main Infinite Loop
    while 1:
        # Do Other Stuff Here.......

        # Update the GPS Object when flag is tripped
        if new_data:
            while uart.any():
            my_gps.update(chr(uart.readchar()))  # Note the conversion to to chr, UART outputs ints normally
                                                                    
            print('UTC Timestamp:', my_gps.timestamp)
            print('Date:', my_gps.date_string('long'))
            print('Latitude:', my_gps.latitude_string())
            print('Longitude:', my_gps.longitude_string())
            print('Horizontal Dilution of Precision:', my_gps.hdop)
            print()
            new_data = False  # Clear the flag
Example #28
0
# Global Flag to start GPS data Processing
new_data = False

xbee = UART(1, 115200)

start = pyb.millis()

# Callback Function
def pps_callback(line):
        # print("Updated GPS Object...")
        global new_data  # Use Global to trigger update
        new_data = True


# Instantiate the micropyGPS object
my_gps = MicropyGPS()

# Setup the connection to your GPS here
uart = UART(6, 9600, read_buf_len=1000)

# Create an external interrupt on pin X8
pps_pin = pyb.Pin.board.X8
extint = pyb.ExtInt(pps_pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP,
                    pps_callback)

# Create relay object
relay = Pin('Y5', Pin.OUT_PP)

# Setup rtc timer to wake up pyboard every 30 seconds during standby to check
# conditions
# rtc = pyb.RTC()
Example #29
0
from machine import Pin, I2C
import time
import ssd1306
import machine
from micropyGPS import MicropyGPS

com = machine.UART(2, 9600, timeout=10)  #定义uart2
my_gps = MicropyGPS(8)  #东八区的修正
my_gps.local_offset

gps_values = 'abc'
rtc = 'efg'


def get_GPS_values():
    global gps_values, rtc  #定义两个全局变量
    time.sleep(2)
    cc = com.readline()
    print(cc)
    for x in cc:
        my_gps.update(chr(x))
    #lat&long
    print(my_gps.latitude[0])
    gps_values = str(my_gps.latitude[0] +
                     (my_gps.latitude[1] /
                      60)) + ',' + str(my_gps.longitude[0] +
                                       (my_gps.longitude[1] / 60))
    #datetime
    date = my_gps.date
    timestamp = my_gps.timestamp
    hour = timestamp[0]
Example #30
0
#   Hafidh Satyanto
#   Library for Adafruit Ultimate GPS sensor

from micropyGPS import MicropyGPS
import time
import serial
#import threading

timezone_offset = -6

gps = MicropyGPS(timezone_offset)

srl = serial.Serial(
    port='/dev/ttyS0',
    baudrate=9600,
)

#def Update_Data():
#    while True:
#        srlline = srl.readline()
#        print(srlline)
#        for iter in srlline:
#            gps.update(iter)
#        time.sleep(1)


def Get_Data():
    try:
        srlline = srl.readline()
        for iter in srlline:
            gps.update(iter)