# Very simple GPS simulator # Arlotto 2019 #first install python3-serial : sudo apt install python3-serial gpsPort = '/dev/ttyUSB0' gpsSpeed = 9600 timeBetweenSentences = 1 # value in seconds gpsEndChars = '\r\n' # NMEA0183 use CR+LF https://en.wikipedia.org/wiki/NMEA_0183 gpsLat='4300.000,N' gpsLong='006.000,E' gpsType = 'GPGGA' gpsSentenceEnd=gpsLat+gpsLong+\ ',1,08,0.9,100.1,M,46.9,M,,*' """ GGA - essential fix data which provide 3D location and accuracy data. $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 Where: GGA Global Positioning System Fix Data 123519 Fix taken at 12:35:19 UTC 4807.038,N Latitude 48 deg 07.038' N 01131.000,E Longitude 11 deg 31.000' E 1 Fix quality: 0 = invalid 1 = GPS fix (SPS) 2 = DGPS fix 3 = PPS fix 4 = Real Time Kinematic 5 = Float RTK 6 = estimated (dead reckoning) (2.3 feature) 7 = Manual input mode 8 = Simulation mode 08 Number of satellites being tracked 0.9 Horizontal dilution of position 545.4,M Altitude, Meters, above mean sea level 46.9,M Height of geoid (mean sea level) above WGS84 ellipsoid (empty field) time in seconds since last DGPS update (empty field) DGPS station ID number *47 the checksum data, always begins with * If the height of geoid is missing then the altitude should be suspect. Some non-standard implementations report altitude with respect to the ellipsoid rather than geoid altitude. Some units do not report negative altitudes at all. This is the only sentence that reports altitude. """ import sys import time def computeCheckSum(sentence) : chk = 0 for c in sentence : chk ^=ord(c) chk = hex(chk)[2:] if len(chk)<2 : chk='0'+chk return chk try : import serial except ModuleNotFoundError: print('first install python3-serial : $sudo apt install python3-serial') sys.exit(-1) try : gps = serial.Serial(port=gpsPort,baudrate=gpsSpeed,\ bytesize=8, parity='N', stopbits=1, timeout=None,\ xonxoff=0, rtscts=0) except : print('unable to open gps port',gpsPort); sys.exit(-1) if not gps.isOpen() : print('unable to open gps port',gpsPort); sys.exit(-1) while 1 : # read gmt time gmt = time.gmtime() gpsTime = f'{gmt.tm_hour:02d}{gmt.tm_min:02d}{gmt.tm_sec:02d}' gpsSentence = '$'+gpsType+','+gpsTime+','+gpsSentenceEnd chk=computeCheckSum(gpsSentence[1:-1]) gpsSentence += chk+gpsEndChars print(gpsSentence) #print(chk) gps.write(gpsSentence.encode('ASCII')) time.sleep(timeBetweenSentences) # parameter in second !!