diff options
author | Jon Schlueter <jschlueter@redhat.com> | 2016-02-06 22:42:47 -0500 |
---|---|---|
committer | Jon Schlueter <jschlueter@redhat.com> | 2016-02-06 22:42:47 -0500 |
commit | d019151fc5ce02cbaf4ae56556614d320eb80347 (patch) | |
tree | 761f88373683e05065091f48e57f147c17d59ba2 /gpssim.py | |
parent | 021f907e552eb0b46ceff566d8a3b680817c3335 (diff) | |
download | gpsd-d019151fc5ce02cbaf4ae56556614d320eb80347.tar.gz |
[pep8] whitespace cleanup in gpssim.py
Diffstat (limited to 'gpssim.py')
-rw-r--r-- | gpssim.py | 38 |
1 files changed, 30 insertions, 8 deletions
@@ -11,8 +11,10 @@ import gps, gpslib # First, the mathematics. We simulate a moving viewpoint on the Earth # and a satellite with specified orbital elements in the sky. + class ksv: "Kinematic state vector." + def __init__(self, time=0, lat=0, lon=0, alt=0, course=0, speed=0, climb=0, h_acc=0, v_acc=0): self.time = time # Seconds from epoch @@ -24,11 +26,12 @@ class ksv: self.climb = climb # Meters per second self.h_acc = h_acc # Meters per second per second self.v_acc = v_acc # Meters per second per second + def next(self, quantum=1): "State after quantum." self.time += quantum - avspeed = (2*self.speed + self.h_acc*quantum)/2 - avclimb = (2*self.climb + self.v_acc*quantum)/2 + avspeed = (2 * self.speed + self.h_acc * quantum) / 2 + avclimb = (2 * self.climb + self.v_acc * quantum) / 2 self.alt += avclimb * quantum self.speed += self.h_acc * quantum self.climb += self.v_acc * quantum @@ -43,11 +46,11 @@ class ksv: lat = gps.Deg2Rad(self.lat) lon = gps.Deg2Rad(self.lon) lat += distance * math.cos(tc) - dphi = math.log(math.tan(lat/2+math.pi/4)/math.tan(self.lat/2+math.pi/4)) - if abs(lat-self.lat) < math.sqrt(1e-15): + dphi = math.log(math.tan(lat / 2 + math.pi / 4) / math.tan(self.lat / 2 + math.pi / 4)) + if abs(lat - self.lat) < math.sqrt(1e-15): q = math.cos(self.lat) else: - q = (lat-self.lat)/dphi + q = (lat - self.lat) / dphi dlon = -distance * math.sin(tc) / q self.lon = gps.Rad2Deg(math.mod(lon + dlon + math.pi, 2 * math.pi) - math.pi) self.lat = gps.Rad2Deg(lat) @@ -57,10 +60,13 @@ class ksv: # Orbital theory at: # <http://www.wolffdata.se/gps/gpshtml/anomalies.html> + class satellite: "Orbital elements of one satellite. PRESENTLY A STUB" + def __init__(self, prn): self.prn = prn + def position(self, time): "Return right ascension and declination of satellite," pass @@ -70,18 +76,22 @@ class satellite: # sammples that might be reported by a GPS, and calls a reporting # class to generate output. + class gpssimException(exceptions.Exception): def __init__(self, message, filename, lineno): exceptions.Exception.__init__(self) self.message = message self.filename = filename self.lineno = lineno + def __str__(self): return '"%s", %d:' % (self.filename, self.lineno) + class gpssim: "Simulate a moving sensor, with skyview." - active_PRNs = range(1, 24+1) + [134,] + active_PRNs = range(1, 24 + 1) + [134, ] + def __init__(self, outfmt): self.ksv = ksv() self.ephemeris = {} @@ -99,6 +109,7 @@ class gpssim: self.satellites_used = 0 self.filename = None self.lineno = 0 + def parse_tdl(self, line): "Interpret one TDL directive." line = line.strip() @@ -127,14 +138,14 @@ class gpssim: elif command == "status": try: code = fields[1] - self.status = {"no_fix":0, "fix":1, "dgps_fix":2}[code.lower()] + self.status = {"no_fix": 0, "fix": 1, "dgps_fix": 2}[code.lower()] except KeyError: raise gpssimException("invalid status code '%s'" % code, self.filename, self.lineno) elif command == "mode": try: code = fields[1] - self.status = {"no_fix":1, "2d":2, "3d":3}[code.lower()] + self.status = {"no_fix": 1, "2d": 2, "3d": 3}[code.lower()] except KeyError: raise gpssimException("invalid mode code '%s'" % code, self.filename, self.lineno) @@ -147,6 +158,7 @@ class gpssim: self.filename, self.lineno) # FIX-ME: add syntax for ephemeris elements self.lineno += 1 + def filter(self, inp, outp): "Make this a filter for file-like objects." self.filename = input.name @@ -154,6 +166,7 @@ class gpssim: self.output = outp for line in inp: self.execute(line) + def go(self, seconds): "Run the simulation for a specified number of seconds." for i in range(seconds): @@ -172,11 +185,14 @@ class gpssim: MPS_TO_KNOTS = 1.9438445 # Meters per second to knots + class NMEA: "NMEA output generator." + def __init__(self): self.sentences = ("RMC", "GGA",) self.counter = 0 + def add_checksum(self, mstr): "Concatenate NMEA checksum and trailer to a string" csum = 0 @@ -186,10 +202,12 @@ class NMEA: csum ^= ord(c) mstr += "*%02X\r\n" % csum return mstr + def degtodm(self, angle): "Decimal degrees to GPS-style, degrees first followed by minutes." (fraction, _integer) = math.modf(angle) return math.floor(angle) * 100 + fraction * 60 + def GGA(self, sim): "Emit GGA sentence describing the simulation state." tm = time.gmtime(sim.ksv.time) @@ -215,6 +233,7 @@ class NMEA: gga += "," # DGPS station ID goes here return self.add_checksum(gga) + def GLL(self, sim): "Emit GLL sentence describing the simulation state." tm = time.gmtime(sim.ksv.time) @@ -229,6 +248,7 @@ class NMEA: ) # FAA mode indicator could go after these fields. return self.add_checksum(gll) + def RMC(self, sim): "Emit RMC sentence describing the simulation state." tm = time.gmtime(sim.ksv.time) @@ -249,6 +269,7 @@ class NMEA: rmc += ",," # FAA mode goes here return self.add_checksum(rmc) + def ZDA(self, sim): "Emit ZDA sentence describing the simulation state." tm = time.gmtime(sim.ksv.time) @@ -265,6 +286,7 @@ class NMEA: # Local zone minutes description goes here zda += "," return self.add_checksum(zda) + def report(self, sim): "Report the simulation state." out = "" |