示例#1
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
示例#2
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
示例#3
0
def run_tests():
    sentence_count = 0

    test_RMC = [
        '$GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62\n',
        '$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A\n',
        '$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68\n',
        '$GPRMC,180041.896,A,3749.1851,N,08338.7891,W,001.9,154.9,240911,,,A*7A\n',
        '$GPRMC,180049.896,A,3749.1808,N,08338.7869,W,001.8,156.3,240911,,,A*70\n',
        '$GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A*45\n'
    ]

    test_VTG = ['$GPVTG,232.9,T,,M,002.3,N,004.3,K,A*01\n']
    test_GGA = [
        '$GPGGA,180050.896,3749.1802,N,08338.7865,W,1,07,1.1,397.4,M,-32.5,M,,0000*6C\n'
    ]
    test_GSA = [
        '$GPGSA,A,3,07,11,28,24,26,08,17,,,,,,2.0,1.1,1.7*37\n',
        '$GPGSA,A,3,07,02,26,27,09,04,15,,,,,,1.8,1.0,1.5*33\n'
    ]
    test_GSV = [
        '$GPGSV,3,1,12,28,72,355,39,01,52,063,33,17,51,272,44,08,46,184,38*74\n',
        '$GPGSV,3,2,12,24,42,058,33,11,34,053,33,07,20,171,40,20,15,116,*71\n',
        '$GPGSV,3,3,12,04,12,204,34,27,11,324,35,32,11,089,,26,10,264,40*7B\n',
        '$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74\n',
        '$GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*74\n',
        '$GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D\n',
        '$GPGSV,4,1,14,22,81,349,25,14,64,296,22,18,54,114,21,51,40,212,*7D\n',
        '$GPGSV,4,2,14,24,30,047,22,04,22,312,26,31,22,204,,12,19,088,23*72\n',
        '$GPGSV,4,3,14,25,17,127,18,21,16,175,,11,09,315,16,19,05,273,*72\n',
        '$GPGSV,4,4,14,32,05,303,,15,02,073,*7A\n'
    ]
    test_GLL = [
        '$GPGLL,3711.0942,N,08671.4472,W,000812.000,A,A*46\n',
        '$GPGLL,4916.45,N,12311.12,W,225444,A,*1D\n',
        '$GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2D\n',
        '$GPGLL,0000.0000,N,00000.0000,E,235947.000,V*2D\n'
    ]

    my_gps = MicropyGPS()
    my_gps.start_logging('test.txt', mode="new")
    my_gps.write_log('micropyGPS test log\n')
    sentence = ''
    for RMC_sentence in test_RMC:
        sentence_count += 1
        for y in RMC_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings:', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Longitude:', my_gps.longitude)
        print('Latitude', my_gps.latitude)
        print('UTC Timestamp:', my_gps.timestamp)
        print('Speed:', my_gps.speed)
        print('Date Stamp:', my_gps.date)
        print('Course', my_gps.course)
        print('Data is Valid:', my_gps.valid)
        print('Compass Direction:', my_gps.compass_direction())
        print('')

    for GLL_sentence in test_GLL:
        sentence_count += 1
        for y in GLL_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Longitude:', my_gps.longitude)
        print('Latitude', my_gps.latitude)
        print('UTC Timestamp:', my_gps.timestamp)
        print('Data is Valid:', my_gps.valid)
        print('')

    for VTG_sentence in test_VTG:
        sentence_count += 1
        for y in VTG_sentence:
            sentence = my_gps.update(y)
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Speed:', my_gps.speed)
        print('Course', my_gps.course)
        print('Compass Direction:', my_gps.compass_direction())
        print('')

    for GGA_sentence in test_GGA:
        sentence_count += 1
        for y in GGA_sentence:
            sentence = my_gps.update(y)
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Longitude', my_gps.longitude)
        print('Latitude', my_gps.latitude)
        print('UTC Timestamp:', my_gps.timestamp)
        print('Fix Status:', my_gps.fix_stat)
        print('Altitude:', my_gps.altitude)
        print('Height Above Geoid:', my_gps.geoid_height)
        print('Horizontal Dilution of Precision:', my_gps.hdop)
        print('Satellites in Use by Receiver:', my_gps.satellites_in_use)
        print('')

    for GSA_sentence in test_GSA:
        sentence_count += 1
        for y in GSA_sentence:
            sentence = my_gps.update(y)
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Satellites Used', my_gps.satellites_used)
        print('Fix Type Code:', my_gps.fix_type)
        print('Horizontal Dilution of Precision:', my_gps.hdop)
        print('Vertical Dilution of Precision:', my_gps.vdop)
        print('Position Dilution of Precision:', my_gps.pdop)
        print('')

    for GSV_sentence in test_GSV:
        sentence_count += 1
        for y in GSV_sentence:
            sentence = my_gps.update(y)
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('SV Sentences Parsed', my_gps.last_sv_sentence)
        print('SV Sentences in Total', my_gps.total_sv_sentences)
        print('# of Satellites in View:', my_gps.satellites_in_view)
        data_valid = my_gps.satellite_data_updated()
        print('Is Satellite Data Valid?:', data_valid)
        if data_valid:
            print('Satellite Data:', my_gps.satellite_data)
            print('Satellites Visible:', my_gps.satellites_visible())
        print('')

    print("Pretty Print Examples:")
    print('Latitude:', my_gps.latitude_string())
    print('Longitude:', my_gps.longitude_string())
    print('Speed:', my_gps.speed_string('kph'), 'or',
          my_gps.speed_string('mph'), 'or', my_gps.speed_string('knot'))
    print('Date (Long Format):', my_gps.date_string('long'))
    print('Date (Short D/M/Y Format):', my_gps.date_string('s_dmy'))
    print('Date (Short M/D/Y Format):', my_gps.date_string('s_mdy'))
    print()

    print('### Final Results ###')
    print('Sentences Attempted:', sentence_count)
    print('Sentences Found:', my_gps.clean_sentences)
    print('Sentences Parsed:', my_gps.parsed_sentences)
    print('CRC_Fails:', my_gps.crc_fails)
示例#4
0
            print('')

        elif sentenceType == 'GPRMC':
            print("--------------------------------------------------")
            print('Parsed a', sentenceType, 'Sentence')
            print("--------------------------------------------------")
            print('Parsed Strings', my_gps.gps_segments)
            print("Sentence CRC value: ", hex(my_gps.crc_xor))
            print('Longitude:', my_gps.longitude)
            print('Latitude', my_gps.latitude)
            print('Timestamp:', my_gps.timestamp)
            print('Speed:', my_gps.speed)
            print('Date Stamp:', my_gps.date)
            print('Course', my_gps.course)
            print('Data is Valid:', my_gps.valid)
            print('Compass Direction:', my_gps.compass_direction())
            print('')

        elif sentenceType == 'GPVTG':
            for x in sentence:
                my_gps.update(x)
            print("--------------------------------------------------")
            print('Parsed a', sentenceType, 'Sentence')
            print("--------------------------------------------------")
            print('Parsed Strings', my_gps.gps_segments)
            print("Sentence CRC value: ", hex(my_gps.crc_xor))
            print('Speed:', my_gps.speed)
            print('Course', my_gps.course)
            print('Compass Direction:', my_gps.compass_direction())
            print('Data is Valid:', my_gps._valid)
            print('')
示例#5
0
def run_tests():
    sentence_count = 0

    test_RMC = ['$GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62\n',
                '$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A\n',
                '$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68\n',
                '$GPRMC,180041.896,A,3749.1851,N,08338.7891,W,001.9,154.9,240911,,,A*7A\n',
                '$GPRMC,180049.896,A,3749.1808,N,08338.7869,W,001.8,156.3,240911,,,A*70\n',
                '$GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A*45\n']

    test_VTG = ['$GPVTG,232.9,T,,M,002.3,N,004.3,K,A*01\n']
    test_GGA = ['$GPGGA,180050.896,3749.1802,N,08338.7865,W,1,07,1.1,397.4,M,-32.5,M,,0000*6C\n']
    test_GSA = ['$GPGSA,A,3,07,11,28,24,26,08,17,,,,,,2.0,1.1,1.7*37\n',
                '$GPGSA,A,3,07,02,26,27,09,04,15,,,,,,1.8,1.0,1.5*33\n']
    test_GSV = ['$GPGSV,3,1,12,28,72,355,39,01,52,063,33,17,51,272,44,08,46,184,38*74\n',
                '$GPGSV,3,2,12,24,42,058,33,11,34,053,33,07,20,171,40,20,15,116,*71\n',
                '$GPGSV,3,3,12,04,12,204,34,27,11,324,35,32,11,089,,26,10,264,40*7B\n',
                '$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74\n',
                '$GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*74\n',
                '$GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D\n',
                '$GPGSV,4,1,14,22,81,349,25,14,64,296,22,18,54,114,21,51,40,212,*7D\n',
                '$GPGSV,4,2,14,24,30,047,22,04,22,312,26,31,22,204,,12,19,088,23*72\n',
                '$GPGSV,4,3,14,25,17,127,18,21,16,175,,11,09,315,16,19,05,273,*72\n',
                '$GPGSV,4,4,14,32,05,303,,15,02,073,*7A\n',
                '$GPGSV,3,1,12,13,65,002,50,02,61,098,47,39,60,352,,05,56,183,49*70\n',
                '$GPGSV,3,2,12,15,35,325,50,29,32,229,49,06,25,070,44,30,16,096,38*70\n',
                '$GPGSV,3,3,12,19,08,022,35,07,07,122,,12,06,316,49,25,03,278,36*7D\n']
    test_GLL = ['$GPGLL,3711.0942,N,08671.4472,W,000812.000,A,A*46\n',
                '$GPGLL,4916.45,N,12311.12,W,225444,A,*1D\n',
                '$GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2D\n',
                '$GPGLL,0000.0000,N,00000.0000,E,235947.000,V*2D\n']

    my_gps = MicropyGPS()
    my_gps.start_logging('test.txt', mode="new")
    my_gps.write_log('micropyGPS test log\n')
    sentence = ''
    for RMC_sentence in test_RMC:
        sentence_count += 1
        for y in RMC_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings:', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Longitude:', my_gps.longitude)
        print('Latitude', my_gps.latitude)
        print('UTC Timestamp:', my_gps.timestamp)
        print('Speed:', my_gps.speed)
        print('Date Stamp:', my_gps.date)
        print('Course', my_gps.course)
        print('Data is Valid:', my_gps.valid)
        print('Compass Direction:', my_gps.compass_direction())
        print('')

    for GLL_sentence in test_GLL:
        sentence_count += 1
        for y in GLL_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Longitude:', my_gps.longitude)
        print('Latitude', my_gps.latitude)
        print('UTC Timestamp:', my_gps.timestamp)
        print('Data is Valid:', my_gps.valid)
        print('')

    for VTG_sentence in test_VTG:
        sentence_count += 1
        for y in VTG_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Speed:', my_gps.speed)
        print('Course', my_gps.course)
        print('Compass Direction:', my_gps.compass_direction())
        print('')

    for GGA_sentence in test_GGA:
        sentence_count += 1
        for y in GGA_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Longitude', my_gps.longitude)
        print('Latitude', my_gps.latitude)
        print('UTC Timestamp:', my_gps.timestamp)
        print('Fix Status:', my_gps.fix_stat)
        print('Altitude:', my_gps.altitude)
        print('Height Above Geoid:', my_gps.geoid_height)
        print('Horizontal Dilution of Precision:', my_gps.hdop)
        print('Satellites in Use by Receiver:', my_gps.satellites_in_use)
        print('')

    for GSA_sentence in test_GSA:
        sentence_count += 1
        for y in GSA_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('Satellites Used', my_gps.satellites_used)
        print('Fix Type Code:', my_gps.fix_type)
        print('Horizontal Dilution of Precision:', my_gps.hdop)
        print('Vertical Dilution of Precision:', my_gps.vdop)
        print('Position Dilution of Precision:', my_gps.pdop)
        print('')

    for GSV_sentence in test_GSV:
        sentence_count += 1
        for y in GSV_sentence:
            sentence = my_gps.update(y)
            if sentence:
                break
        print('Parsed a', sentence, 'Sentence')
        print('Parsed Strings', my_gps.gps_segments)
        print('Sentence CRC Value:', hex(my_gps.crc_xor))
        print('SV Sentences Parsed', my_gps.last_sv_sentence)
        print('SV Sentences in Total', my_gps.total_sv_sentences)
        print('# of Satellites in View:', my_gps.satellites_in_view)
        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())
        print('')

    print("Pretty Print Examples:")
    print('Latitude:', my_gps.latitude_string())
    print('Longitude:', my_gps.longitude_string())
    print('Speed:', my_gps.speed_string('kph'), 'or', my_gps.speed_string('mph'), 'or', my_gps.speed_string('knot'))
    print('Date (Long Format):', my_gps.date_string('long'))
    print('Date (Short D/M/Y Format):', my_gps.date_string('s_dmy'))
    print('Date (Short M/D/Y Format):', my_gps.date_string('s_mdy'))
    print()

    print('### Final Results ###')
    print('Sentences Attempted:', sentence_count)
    print('Sentences Found:', my_gps.clean_sentences)
    print('Sentences Parsed:', my_gps.parsed_sentences)
    print('CRC_Fails:', my_gps.crc_fails)
示例#6
0
文件: gpsInfluxdb.py 项目: RasulM/gps
while 1:
    sent = uart.readline().decode('utf-8')
    for x in sent:
        gps.update(x)

    json_body = [{
        "measurement":
        "gpsEvents",
        "tags": {
            "user": "******",
            "Id":
            "6b 65 74 74 65 72 69 6e 67 20 69 73 20 45 70 69 63 20 4f 77 4f"
        },
        "time":
        str('{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())),
        "fields": {
            "fix_type": str(gps.fix_type),
            "latitude": gps.latitude_string(),
            "latitude_Minutes": float(gps.latitude[1]),
            "longitude": gps.longitude_string(),
            "longitude_Minutes": float(gps.longitude[1]),
            "speed": float(gps.speed[2]),
            "direction": str(gps.compass_direction())
        }
    }]

    print(json_body)
# uncomment line below to log
# client.write_points(json_body)
示例#7
0
文件: gps.py 项目: RasulM/gps
import serial  # pyserial is required
from micropyGPS import MicropyGPS  #https://github.com/inmcm/micropyGPS

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

while 1:
    sent = uart.readline().decode('utf-8')
    print(sent)
    for x in sent:
        gps.update(x)
    print("fix_type 1 means no fix: ", gps.fix_type)
    print("lat ", gps.latitude)
    print("long ", gps.longitude)
    print("speed ", gps.speed)
    print("satellites_visible ", gps.satellites_visible())
    print("direction ", gps.compass_direction())