Browse Source

example gps (output) file and nmea message with checksum in gps-sim.py

clementinecomputing 6 years ago
parent
commit
f8bac27669
2 changed files with 107 additions and 2 deletions
  1. 48 0
      busunit/testing/gps/example.gps
  2. 59 2
      busunit/testing/gps/gps-sim.py

+ 48 - 0
busunit/testing/gps/example.gps

@@ -0,0 +1,48 @@
+$GPGSV,3,1,12,17,43,264,38,08,12,066,38,28,65,320,35,11,57,059,32*73
+$GPGSV,3,2,12,07,23,180,32,19,21,254,32,01,59,075,31,13,08,275,25*7C
+$GPGSV,3,3,12,22,18,106,25,30,47,210,15,18,38,053,,04,,,*44
+$GPGSV,4,4,13,04,,,*7F
+$GPGGA,040341.1,4226.692702,N,07630.419493,W,1,07,1.0,117.5,M,0,M,,*6D
+$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42
+$GPRMC,040341.1,A,4226.692702,N,07630.419493,W,0.0,0.0,050500,,,A*75
+$GPGSA,A,3,01,07,08,11,17,19,28,,,,,,1.5,1.0,1.2*3E
+$GPGSV,3,1,12,08,12,066,38,17,43,264,38,28,65,320,35,11,57,059,33*72
+$GPGSV,3,2,12,07,23,180,32,01,59,075,32,19,21,254,32,22,18,106,26*78
+$GPGSV,3,3,12,13,08,275,25,30,47,210,17,18,38,053,,04,,,*42
+$GPGSV,4,4,13,04,,,*7F
+$GPGGA,040344.1,4226.692722,N,07630.419464,W,1,07,1.0,117.3,M,0,M,,*64
+$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42
+$GPRMC,040344.1,A,4226.692722,N,07630.419464,W,0.0,0.0,050500,,,A*7A
+$GPGSA,A,3,01,07,08,11,17,19,28,,,,,,1.5,1.0,1.2*3E
+$GPGSV,3,1,12,08,12,066,38,17,43,264,37,28,65,320,35,11,57,059,34*7A
+$GPGSV,3,2,12,01,59,075,33,07,23,180,32,19,21,254,31,22,18,106,28*74
+$GPGSV,3,3,12,13,08,275,23,30,47,210,16,18,38,053,,04,,,*45
+$GPGSV,4,4,13,04,,,*7F
+$GPGGA,040347.1,4226.692743,N,07630.419452,W,1,07,1.0,117.2,M,0,M,,*64
+$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42
+$GPRMC,040347.1,A,4226.692743,N,07630.419452,W,0.0,0.0,050500,,,A*7B
+$GPGSA,A,3,01,07,08,11,17,19,28,,,,,,1.5,1.0,1.2*3E
+$GPGSV,3,1,12,08,12,066,38,17,43,264,36,28,65,320,35,11,57,059,34*7B
+$GPGSV,3,2,12,01,59,075,34,07,23,180,32,19,21,254,31,22,18,106,28*73
+$GPGSV,3,3,12,13,08,275,24,30,47,210,18,18,38,053,,04,,,*4C
+$GPGSV,4,4,13,04,,,*7F
+$GPGGA,040350.1,4226.692763,N,07630.419447,W,1,07,1.0,117.0,M,0,M,,*66
+$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42
+$GPRMC,040350.1,A,4226.692763,N,07630.419447,W,0.0,0.0,050500,,,A*7B
+$GPGSA,A,3,01,07,08,11,17,19,28,,,,,,1.5,1.0,1.2*3E
+$GPGSV,3,1,12,08,12,066,38,17,43,264,36,28,65,320,36,11,57,059,33*7F
+$GPGSV,3,2,12,01,59,075,33,07,23,180,31,19,21,254,30,22,18,106,30*7F
+$GPGSV,3,3,12,13,08,275,24,30,47,210,19,18,38,053,,04,,,*4D
+$GPGSV,4,4,13,04,,,*7F
+$GPGGA,040353.1,4226.692779,N,07630.419449,W,1,08,1.0,116.9,M,0,M,,*67
+$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42
+$GPRMC,040353.1,A,4226.692779,N,07630.419449,W,0.0,0.0,050500,,,A*7D
+$GPGSA,A,3,01,07,08,11,17,19,22,28,,,,,1.5,1.0,1.2*3E
+$GPGSV,4,1,13,08,12,066,38,28,65,320,36,17,43,264,36,01,59,075,32*79
+$GPGSV,4,2,13,11,57,059,32,07,23,180,31,19,21,254,29,22,18,106,29*79
+$GPGSV,4,3,13,13,08,275,23,03,09,127,20,30,47,210,20,18,38,053,*7E
+$GPGSV,4,4,13,04,,,*7F
+$GPGGA,040356.1,4226.692793,N,07630.419449,W,1,08,0.9,116.9,M,0,M,,*6E
+$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42
+$GPRMC,040356.1,A,4226.692793,N,07630.419449,W,0.0,0.0,050500,,,A*7C
+$GPGSA,A,3,01,07,08,11,17,19,22,28,,,,,1.5,0.9,1.1*35

+ 59 - 2
busunit/testing/gps/gps-sim.py

@@ -27,6 +27,7 @@ import getopt
 import sys
 import time
 import math
+import datetime
 
 DT = 0.5
 DS = 2
@@ -72,6 +73,61 @@ def load_latlon_csv(fn):
 
   return latlon
 
+def nmea_checksum(msg):
+  cksum = 0
+  for idx in range(len(msg)):
+    c = ord(msg[idx])
+    cksum = cksum ^ (c & 0xff)
+
+  return ("%02X" % cksum)
+
+
+#tstmsg = [ "$GPGSV,3,1,12,17,43,264,38,08,12,066,38,28,65,320,35,11,57,059,32*73",
+#  "$GPGSV,3,2,12,07,23,180,32,19,21,254,32,01,59,075,31,13,08,275,25*7C",
+#  "$GPGSV,3,3,12,22,18,106,25,30,47,210,15,18,38,053,,04,,,*44",
+#  "$GPGSV,4,4,13,04,,,*7F",
+#  "$GPGGA,040341.1,4226.692702,N,07630.419493,W,1,07,1.0,117.5,M,0,M,,*6D",
+#  "$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42",
+#  "$GPRMC,040341.1,A,4226.692702,N,07630.419493,W,0.0,0.0,050500,,,A*75",
+#  "$GPGSA,A,3,01,07,08,11,17,19,28,,,,,,1.5,1.0,1.2*3E",
+#  "$GPGSV,3,1,12,08,12,066,38,17,43,264,38,28,65,320,35,11,57,059,33*72",
+#  "$GPGSV,3,2,12,07,23,180,32,01,59,075,32,19,21,254,32,22,18,106,26*78",
+#  "$GPGSV,3,3,12,13,08,275,25,30,47,210,17,18,38,053,,04,,,*42",
+#  "$GPGSV,4,4,13,04,,,*7F",
+#  "$GPGGA,040344.1,4226.692722,N,07630.419464,W,1,07,1.0,117.3,M,0,M,,*64",
+#  "$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42",
+#  "$GPRMC,040344.1,A,4226.692722,N,07630.419464,W,0.0,0.0,050500,,,A*7A",
+#  "$GPGSA,A,3,01,07,08,11,17,19,28,,,,,,1.5,1.0,1.2*3E" ]
+#
+#for msg in tstmsg:
+#  s = msg[1:-3]
+#  print s, "(", msg, ")"
+#  print "  >>", nmea_checksum(s)
+#
+#sys.exit(0)
+
+def print_gps_nmea_messages(ofp, lat, lon, utc_str = ""):
+  if len(utc_str) == 0:
+    n = datetime.datetime.utcnow()
+    utc_str = n.strftime("%H") + n.strftime("%M") + n.strftime("%S") + "." + n.strftime("%f")[0:1]
+
+  ofp.write("$GPGSV,4,1,13,08,12,066,38,28,65,320,36,17,43,264,36,01,59,075,32*79\n")
+  ofp.write("$$GPGSV,4,2,13,11,57,059,32,07,23,180,31,19,21,254,29,22,18,106,29*79\n")
+  ofp.write("$GPGSV,4,3,13,13,08,275,23,03,09,127,20,30,47,210,20,18,38,053,*7E\n")
+  ofp.write("$GPGSV,4,4,13,04,,,*7F\n")
+
+  msg = "GPGGA," + utc_str + "," + str(lat) + ",N," + str(lon) + ",W,1,08,0.9,116.9,M,0,M,,"
+  ofp.write("$" + msg + "*" + nmea_checksum(msg) + "\n")
+
+  ofp.write("$GPVTG,NaN,T,,M,0.0,N,0.0,K,A*42\n")
+
+  msg = "GPRMC," + utc_str + ",A," + str(lat) + ",N," + str(lon) + ",W,0.0,0.0,050500,,,A"
+  ofp.write("$" + msg + "*" + nmea_checksum(msg) + "\n")
+
+  ofp.write("$GPGSA,A,3,01,07,08,11,17,19,22,28,,,,,1.5,0.9,1.1*35\n")
+
+  
+
 latlon = []
 noarg = True
 ifn = ""
@@ -156,8 +212,9 @@ while curiter < ITER_COUNT:
     cursec = float(time.time())
     if (cursec - lastupdate_sec) > DTUPDATE:
       lastupdate_sec = cursec
-      #print _p, _pos
-      sys.stdout.write(str(_pos[0]) + " " + str(_pos[1]) + "\n")
+      #sys.stdout.write(str(_pos[0]) + " " + str(_pos[1]) + "\n")
+
+      print_gps_nmea_messages(sys.stdout, _pos[0], _pos[1])
       sys.stdout.flush()
 
     time.sleep(DS)