Changes in / [20d6392:6b3dd00]
- Location:
- src/python
- Files:
-
- 7 edited
-
bin/gnuboat (modified) (6 diffs)
-
bin/gnuboat-data-generator (modified) (4 diffs)
-
bin/gnuboat-log-converter (modified) (15 diffs)
-
bin/gnuboat-splashscreen (modified) (2 diffs)
-
gnuboat/daemon/gpsdpoller.py (modified) (4 diffs)
-
gnuboat/daemon/n2kdpoller.py (modified) (7 diffs)
-
gnuboat/daemon/rrdhandler.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/python/bin/gnuboat
r20d6392 r6b3dd00 67 67 if (currentTime - shutdownRequested) > datetime.timedelta(seconds=0): 68 68 os.system("sudo shutdown -h now") 69 70 71 def usage(): 72 print "Usage of gnuboat daemon:" 73 print " gnuboat -r PATH_TO_RRD_DATABAE_FILE -s PATH_TO_SHUTDOWN_REQUEST_FILE [-l [LOG_UPDATE_PERIOD] [-d DISPLAY_UPDATE_PERIOD] [-o PATH_TO_NMEA1983_LOG]" 74 print "" 75 print " -h --help Display this help" 76 print " -r --rrdfile Path to the rrd database used by the webservice to serve the clients" 77 print " -s --shutdownfile Path to the shutdown request file, used by the webservice to request a shutdown of the system running gnuboat" 78 print " -l --logperiod Time in seconds to update the logs" 79 print " -lv --log-verbose Log verbose information to nmea log file (Enables -ls and adds RMC sentences, with invalid GPS state, on non fixes" 80 print " -ls --log-system-time Add to enable prefixing every logline with the system time (Default off)" 81 print " -d --displayperiod Timein seconds to update the display" 82 print " -o --output Directory where the log files are stored (e.g. the NMEA0183 log files)" 69 83 70 84 def log(gpsFix, gpsTime, gpsStatus, latitude, latitudeDirection, longitude, … … 90 104 try: 91 105 nmeaFileDate = nmeaFileDateShould 92 nmeaLogFile = 'nmea0183-{}.log'.format(nmeaFileDate)93 nmeafile = open( '{}/{}'.format(logdir, nmeaLogFile), 'a', 0)106 nmeaLogFile = "nmea0183-%s.log" % nmeaFileDate 107 nmeafile = open("%s/%s" % (logdir, nmeaLogFile), 'a', 0) 94 108 except IOError as error: 95 print ('Could not open the logfile: {}'.format(error))109 print "Could not open the logfile: %s" % error 96 110 sys.exit(2) 97 111 … … 101 115 logsystemtime = "" 102 116 if logsystemtime: 103 logsystemtime = '{}: '.format(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"))117 logsystemtime = "%s:" datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") 104 118 105 119 try: 106 nmeafile.write( '{}{}\r\n'.format(logsystemtime, str(pynmea2.RMC('GN', 'RMC',120 nmeafile.write("%s%s\r\n" % (logsystemtime, str(pynmea2.RMC('GN', 'RMC', 107 121 (gpsTime.strftime("%H%M%S"), gpsStatus, 108 ' {:02d}{:s}'.format(latitude['degrees'], latitude['minutes']),122 '%02d%s' % (latitude['degrees'], latitude['minutes']) 109 123 latitudeDirection, 110 ' {:03d}{:s}'.format(longitude['degrees'], longitude['minutes']),124 '%03d%s' % (longitude['degrees'], longitude['minutes']), 111 125 longitudeDirection, 112 ' {:04.1f}'.format(speedOverGround), '{:04.1f}'.format(courseOverGround),126 '%04.1f' % speedOverGround, '%04.1f' % courseOverGround, 113 127 gpsTime.strftime("%d%m%y"), '', '', mode))))) 114 128 if transducerValid: 115 nmeafile.write( '{}{}\r\n'.format(logsystemtime, str(pynmea2.DPT('SD', 'DPT', ('{:05.2f}'.format(waterDepth, '00.00'))))))116 nmeafile.write( '{}{}\r\n'.format(logsystemtime, str(pynmea2.MTW('YX', 'MTW', ('{:04.1f}'.format(waterTemperature, 'C'))))))129 nmeafile.write("%s%s\r\n" % (logsystemtime, str(pynmea2.DPT('SD', 'DPT', ('%05.2f' % waterDepth, '00.00'))))) 130 nmeafile.write("%s%s\r\n" % (logsystemtime, str(pynmea2.MTW('YX', 'MTW', ('%04.1f' % waterTemperature, 'C'))))) 117 131 except: 118 print ('Failed writing to logfile {}'.format(nmeaLogFile))132 print "Failed writing to logfile %s" % nmeaLogFile 119 133 print(traceback.format_exc()) 120 134 … … 134 148 global nmeafile 135 149 136 parser = argparse.ArgumentParser(description= 'Collects the data from canboat and gpsd and writes them to the rrd database and the nmea log file')150 parser = argparse.ArgumentParser(description="Collects the data from canboat and gpsd and writes them to the rrd database and the nmea log file") 137 151 parser.add_argument('-r', '--rrdfile', dest='rrd_file', metavar='rrd_file', type=str, 138 152 help='Path to the rrd database used by the webservice to serve the clients', default=rrdfile) … … 168 182 169 183 if not os.path.exists(os.path.dirname(rrdfile)): 170 print('rrd database directory not found {}'.format(os.path.dirname(rrdfile))) 171 parser.print_help() 184 print "rrd database directory not found %s" % os.path.dirname(rrdfile) 185 print "" 186 usage() 172 187 sys.exit(2) 173 188 174 189 if not os.path.exists(os.path.dirname(shutdownfile)): 175 print('Shutdown request directory not found {}'.format(os.path.dirname(shutdownfile))) 176 parser.print_help() 190 print "Shutdown request directory not found %s" % os.path.dirname(shutdownfile) 191 print "" 192 usage() 177 193 sys.exit(2) 178 194 179 195 if logperiod < 1: 180 print('Log period must be >= 1') 181 parser.print_help() 196 print "Log period must be >= 1" 197 print "" 198 usage() 182 199 sys.exit(2) 183 200 184 201 if displayperiod < 1 or displayperiod < logperiod: 185 print('Display period must be >= 1 and could not be faster than log period') 186 parser.print_help() 202 print "Display period must be >= 1 and could not be faster than log period" 203 print "" 204 usage() 187 205 sys.exit(2) 188 206 … … 213 231 214 232 # update rrd database for the webservice 215 daemon.rrd_update(rrdfile, 'N:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}'.format(233 daemon.rrd_update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s:%s" % ( 216 234 latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix)) 217 235 -
src/python/bin/gnuboat-data-generator
r20d6392 r6b3dd00 46 46 global logperiod 47 47 48 parser = argparse.ArgumentParser(description= 'Generates test data for gnuboat webservice and fills the rrd database')48 parser = argparse.ArgumentParser(description="Generates test data for gnuboat webservice and fills the rrd database") 49 49 parser.add_argument('-f', '--file', dest='rrd_database', metavar='rrd_database', type=str, 50 50 help='File path of the rrd database to fill', default="/var/lib/gnuboat/gnuboat.rrd") … … 78 78 79 79 if not os.path.exists(os.path.dirname(rrdfile)): 80 print('rrd database directory not found {}'.format(os.path.dirname(rrdfile))) 80 print "rrd database directory not found %s" % os.path.dirname(rrdfile) 81 print "" 81 82 parser.print_help() 82 83 sys.exit(2) … … 86 87 87 88 if os.path.isfile(rrdfile): 88 print ('Removing old database {}'.format(rrdfile))89 print "Removing old database %s" % rrdfile 89 90 os.remove(rrdfile) 90 91 91 print ('Creating {}'.format(rrdfile))92 print "Creating %s" % rrdfile 92 93 daemon.rrd_create_database(rrdfile, logperiod, str(start_time)) 93 94 94 print ('Filling database inside [{}, {}] --> [{}, {}]...'.format(latitude_min, longitude_min, latitude_max, longitude_max))95 print "Filling database inside [%s, %s] --> [%s,%s]..." % (latitude_min, longitude_min, latitude_max, longitude_max) 95 96 for current_time in xrange(timestamp - duration, timestamp, logperiod): 96 97 latitude = random.uniform(latitude_min, latitude_max) … … 103 104 gpsFix = 3 104 105 # update rrd database for the webservice 105 daemon.rrd_update(rrdfile, '{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}'.format(106 daemon.rrd_update(rrdfile, "%s:%s:%s:%s:%s:%s:%s:%s:%s" % ( 106 107 current_time, latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix)) 107 108 -
src/python/bin/gnuboat-log-converter
r20d6392 r6b3dd00 43 43 return int(string) 44 44 except ValueError as error: 45 print ('INFO: Failed to convert value from line %s into numeric: {:s}\n Message: {:s}'.format(current_row, string, error))45 print 'INFO: Failed to convert value from line %s into numeric: %s\n Message: %s' % (current_row, string, error) 46 46 return 0 47 47 … … 54 54 matches = regex_nmea_position.match(nmea_value) 55 55 if matches is None: 56 print ('INFO: Failed to convert position value from line {:s} into decimal degrees: {:s}'.format(current_row, nmea_value))56 print 'INFO: Failed to convert position value from line %s into decimal degrees: %s' % (current_row, nmea_value) 57 57 return 58 58 decimalDegrees = toFloat(matches.group(1), current_row) … … 66 66 output_file = open(output_file_path, 'w', 0) 67 67 except IOError as error: 68 print ('ERROR: Could not open the output file: {}'.format(error))68 print "ERROR: Could not open the output file: %s" % error 69 69 sys.exit(3) 70 70 … … 81 81 input_file = open(input_file_path, 'r') 82 82 except IOError as error: 83 print ('ERROR: Could not open the input file: {}'.format(error))83 print "ERROR: Could not open the input file: %s" % error 84 84 sys.exit(3) 85 85 current_row = 1 … … 89 89 matches = regex_nmea_sentence.match(line) 90 90 if matches is None: 91 print ('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row))91 print 'INFO: Failed to parse nmea sentence (%s) at line %s\n' % (line, current_row) 92 92 if not errors_ignore: 93 93 input_file.close() … … 99 99 if last_row is not None: 100 100 output_file_csv.writerow(last_row) 101 last_row = {'datetime': ' {} {}'.format(nmea_sentence.datestamp, nmea_sentence.timestamp),101 last_row = {'datetime': '%s %s' % (nmea_sentence.datestamp, nmea_sentence.timestamp), 102 102 'gps_status': nmea_sentence.status, 103 103 'latitude': nmeaToDecimalDegrees(nmea_sentence.lat, current_row), … … 125 125 output_file = open(output_file_path, 'w', 0) 126 126 except IOError as error: 127 print ('ERROR: Could not open the output file: {}'.format(error))127 print "ERROR: Could not open the output file: %s" % error 128 128 sys.exit(3) 129 129 … … 132 132 input_file = open(input_file_path, 'r') 133 133 except IOError as error: 134 print ('ERROR: Could not open the input file: {}'.format(error))134 print "ERROR: Could not open the input file: %s" % error 135 135 sys.exit(3) 136 136 current_row = 1 … … 140 140 matches = regex_nmea_sentence.match(line) 141 141 if matches is None: 142 print ('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row))142 print 'INFO: Failed to parse nmea sentence (%s) at line %s\n' % (line, current_row) 143 143 if not errors_ignore: 144 144 input_file.close() … … 149 149 output_string = str(nmea_sentence) 150 150 if not strip_time and matches.group(1): 151 output_string = ' {}{}'.format(matches.group(1), output_string)152 output_file.write( '{}\r\n'.format(str(output_string)))151 output_string = '%s%s' % (matches.group(1), output_string) 152 output_file.write("%s\r\n" % str(output_string)) 153 153 output_file.close() 154 154 input_file.close() … … 177 177 formats.append(file_format.name) 178 178 179 parser = argparse.ArgumentParser(description= 'Convert gnuboat logfiles into other formats')179 parser = argparse.ArgumentParser(description="Convert gnuboat logfiles into other formats") 180 180 parser.add_argument('-f', '--format', dest='output_format', metavar='output_format', type=str, 181 181 help='Format of the output file.', choices=formats, default='CSV') … … 197 197 format_found = True 198 198 if not format_found: 199 print ('ERROR: Invalid input format specified: {}'.format(arguments.output_format))199 print 'ERROR: Invalid input format specified: %s' % arguments.output_format 200 200 sys.exit(1) 201 201 … … 207 207 208 208 if arguments.input_file is None: 209 print ('ERROR: No input file specified')209 print 'ERROR: No input file specified' 210 210 sys.exit(2) 211 211 elif not os.path.exists(arguments.input_file): 212 print ('ERROR: Specified input file does not exists: {}'.format(arguments.input_file))212 print 'ERROR: Specified input file does not exists: %s' % arguments.input_file 213 213 sys.exit(3) 214 214 else: … … 216 216 217 217 if arguments.output_file is None: 218 print ('ERROR: No output file specified')218 print 'ERROR: No output file specified' 219 219 sys.exit(2) 220 220 elif not os.path.exists(os.path.dirname(arguments.output_file)): 221 print ('ERROR: Specified directory of output file does not exists: {}'.format(arguments.output_file))221 print 'ERROR: Specified directory of output file does not exists: %s' % arguments.output_file 222 222 sys.exit(3) 223 223 else: … … 231 231 convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time) 232 232 else: 233 print ('ERROR: Undefined output format!\n')233 print "ERROR: Undefined output format!\n"; 234 234 sys.exit(1) 235 235 -
src/python/bin/gnuboat-splashscreen
r20d6392 r6b3dd00 39 39 40 40 def usage(): 41 print ("Usage of gnuboat-splashscreen:")42 print (" gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY")43 print ("")44 print (" -h --help Print this help")45 print (" -i --image Path to the image, which should be displayed")41 print "Usage of gnuboat-splashscreen:" 42 print " gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY" 43 print "" 44 print " -h --help Print this help" 45 print " -i --image Path to the image, which should be displayed" 46 46 sys.exit() 47 47 … … 65 65 66 66 if not os.path.exists(image): 67 print("Image {} not found".format(image)) 67 print "Image %s not found" % image 68 print "" 68 69 usage() 69 70 sys.exit(2) 70 71 71 72 if not epdEnabled: 72 print ("Could not initialize EPD or PIL python packages")73 print "Could not initialize EPD or PIL python packages" 73 74 sys.exit(2) 74 75 -
src/python/gnuboat/daemon/gpsdpoller.py
r20d6392 r6b3dd00 47 47 48 48 def latitudeDirection(self): 49 return 'N'49 return "N" 50 50 51 51 def longitude(self): … … 55 55 56 56 def longitudeDirection(self): 57 return 'E'57 return "E" 58 58 59 59 def speedOverGround(self): … … 74 74 def status(self): 75 75 if self._currentValue == None or self.gpsFix() < 2: 76 return 'V'77 return 'A'76 return "V" 77 return "A" 78 78 79 79 def timeUtc(self): … … 96 96 break 97 97 except: 98 print ('Failed to read gpsd data')99 print (traceback.format_exc())98 print 'Failed to read gpsd data' 99 print traceback.format_exc() 100 100 self._currentValue = None 101 101 except StopIteration: -
src/python/gnuboat/daemon/n2kdpoller.py
r20d6392 r6b3dd00 69 69 except socket.error as error: 70 70 if not self._connectErrorPrinted: 71 print ('Failed to connect to n2kd server at {}:{}: {}'.format(self._serverHost, self._serverPort, error))71 print 'Failed to connect to n2kd server at %s:%s: %s' % (self._serverHost, self._serverPort, error) 72 72 self._connectErrorPrinted = True 73 73 self._waterDepthValid = False 74 74 return 75 75 if self._connectErrorPrinted: 76 print ('Connected to n2kd server at {}:{}'.format(self._serverHost, self._serverPort))76 print "Connected to n2kd server at %s:%s" % (self._serverHost, self._serverPort) 77 77 self._connectErrorPrinted = False 78 78 … … 82 82 data = n2kdSocket.recv(1024) 83 83 except: 84 print ('Failed to update n2kd data')85 print (traceback.format_exc())84 print 'Failed to update n2kd data' 85 print traceback.format_exc() 86 86 self._waterDepthValid = False 87 87 if not data: … … 92 92 data = json.loads(response) 93 93 except ValueError as error: 94 print ('Failed to decode json: {}'.format(error))94 print "Failed to decode json: %s" % error 95 95 96 96 descriptions = [ … … 100 100 entryKeys = data[key].keys() 101 101 if len(entryKeys) != 2: 102 print ('Malformed json n2kd response? {}'.format(response))102 print "Malformed json n2kd response? %s" % response 103 103 else: 104 104 if data[key]["description"] in descriptions: … … 106 106 lineKeys = data[key][entryKey].keys() 107 107 if "fields" not in lineKeys: 108 print ('No fields entry. Malformed json n2kd response in {}'.format(data[key][entryKey]))108 print "No fields entry. Malformed json n2kd response in %s" % data[key][entryKey] 109 109 else: 110 110 fields = data[key][entryKey]["fields"] … … 116 116 # try speed 117 117 if "Speed Water Referenced" in fields: 118 self._speedThroughWater = fields["Speed Water Referenced"] 118 self._speedThroughWater = fields[ 119 "Speed Water Referenced"] 119 120 # try sea temperature 120 121 if "Temperature Source" in fields and "Temperature" in fields: … … 128 129 129 130 def _serverUrl(self): 130 return 'http://{}:{:d}/'.format(self._serverHost, self._serverPort)131 return "http://%s:%d/" % (self._serverHost, self._serverPort) 131 132 132 133 def stop(self): -
src/python/gnuboat/daemon/rrdhandler.py
r20d6392 r6b3dd00 40 40 rrd_archives = [] 41 41 for i in range(0, len(archives)): 42 rrd_archives += ['RRA:AVERAGE:0.5: {:d}:{:d}'.format(_steps(archives[i]["resolution"], step), _rows(42 rrd_archives += ['RRA:AVERAGE:0.5:%d:%d' % (_steps(archives[i]["resolution"], step), _rows( 43 43 archives[i]["duration"], archives[i]["resolution"], step))] 44 44 … … 56 56 rrdtool.update(rrdfile, value_string) 57 57 except: 58 print ('Failed to update rrd database {} with values\n {}'.format(rrdfile, value_string))59 print (traceback.format_exc())58 print 'Failed to update rrd database %s with values\n %s' % (rrdfile, value_string) 59 print traceback.format_exc() 60 60 61 61 def _rows(duration, resolution, step):
Note:
See TracChangeset
for help on using the changeset viewer.
