Changeset 8fd7454 for src/python/bin
- Timestamp:
- Dec 10, 2017, 4:32:57 PM (9 years ago)
- Branches:
- debian/bullseye, debian/jessie
- Children:
- ce5244e
- Parents:
- c810990 (diff), 8ef59a1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/python/bin
- Files:
-
- 2 added
- 2 edited
-
gnuboat (modified) (8 diffs)
-
gnuboat-data-generator (added)
-
gnuboat-log-converter (added)
-
gnuboat-splashscreen (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/python/bin/gnuboat
rc810990 r8fd7454 27 27 from pytz import timezone 28 28 import pytz 29 import getopt29 import argparse 30 30 import sys 31 31 import pynmea2 32 import traceback 33 import math 32 34 33 35 from gnuboat import daemon … … 43 45 logdir = "/var/log/gnuboat" 44 46 logperiod = 2 47 logverbose = False 48 logsystemtime = False 45 49 displayperiod = 5 46 50 … … 48 52 nmeafile = None 49 53 nmeaFileDate = None 50 51 52 def rraRows(duration, resolution, step):53 return int(round(float(duration) / rraSteps(resolution, float(step)) / float(step)))54 55 56 def rraSteps(resolution, step):57 return int(round(float(resolution) / float(step)))58 59 60 def createDatabase(databaseFile):61 rrdDataSources = ['DS:latitude:GAUGE:15:-90:90',62 'DS:longitude:GAUGE:15:-180:180',63 'DS:speedthroughwater:GAUGE:15:U:U',64 'DS:speedoverground:GAUGE:15:U:U',65 'DS:waterdepth:GAUGE:15:0:10000',66 'DS:watertemperature:GAUGE:15:-10:50',67 'DS:gpsfix:GAUGE:15:-999:3']68 69 step = logperiod70 # durations: each archive should contain values for in seconds71 archives = [72 {"duration": 240, "resolution": 2},73 {"duration": 3600, "resolution": 10},74 {"duration": 86400, "resolution": 60},75 ]76 rrdArchives = []77 for i in range(0, len(archives)):78 rrdArchives += ['RRA:AVERAGE:0.5:%d:%d' % (rraSteps(archives[i]["resolution"], step), rraRows(79 archives[i]["duration"], archives[i]["resolution"], step))]80 81 if not os.path.isfile(databaseFile):82 rrdtool.create(databaseFile,83 "--start",84 "N",85 "--step",86 str(step),87 rrdDataSources,88 rrdArchives)89 54 90 55 … … 104 69 os.system("sudo shutdown -h now") 105 70 106 107 def usage():108 print "Usage of gnuboat daemon:"109 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]"110 print ""111 print " -h --help Display this help"112 print " -r --rrdfile Path to the rrd database used by the webservice to serve the clients"113 print " -s --shutdownfile Path to the shutdown request file, used by the webservice to request a shutdown of the system running gnuboat"114 print " -l --logperiod Time in seconds to update the logs"115 print " -d --displayperiod Timein seconds to update the display"116 print " -o --output Directory where the log files are stored (e.g. the NMEA0183 log files)"117 118 71 def log(gpsFix, gpsTime, gpsStatus, latitude, latitudeDirection, longitude, 119 longitudeDirection, courseOverGround, speedOverGround, waterDepth, water DepthValid):72 longitudeDirection, courseOverGround, speedOverGround, waterDepth, waterTemperature, transducerValid, logVerbose, logSystemTime): 120 73 global logdir 121 74 global nmeafile 122 75 global nmeaFileDate 123 76 124 77 # Only log, if we have a gps fix 125 78 if gpsFix < 2: 126 return 79 if not logVerbose: 80 return 81 gpsStatus = 'V' 82 mode = 'N' 83 if gpsTime is None: 84 gpsTime = datetime.datetime.utcnow() 127 85 128 86 nmeaFileDateShould = datetime.datetime.utcnow().strftime("%Y-%m-%d") … … 133 91 try: 134 92 nmeaFileDate = nmeaFileDateShould 135 nmeaLogFile = "nmea0183-%s.log" % nmeaFileDate136 nmeafile = open( "%s/%s" %(logdir, nmeaLogFile), 'a', 0)93 nmeaLogFile = 'nmea0183-{}.log'.format(nmeaFileDate) 94 nmeafile = open('{}/{}'.format(logdir, nmeaLogFile), 'a', 0) 137 95 except IOError as error: 138 print "Could not open the logfile: %s" % error96 print('Could not open the logfile: {}'.format(error)) 139 97 sys.exit(2) 140 141 nmeafile.write("%s\r\n" % str(pynmea2.RMC('GN', 'RMC', 142 (gpsTime.strftime("%H%M%S"), gpsStatus, '$%04.3f' % latitude, 143 latitudeDirection, '$%05.3f' % longitude, longitudeDirection, 144 '$%02.1f' % speedOverGround, '$%02.1f' % courseOverGround, 145 gpsTime.strftime("%d%m%y"), '', '', mode)))) 146 if waterDepthValid: 147 nmeafile.write("%s\r\n" % str(pynmea2.DPT('SD', 'DPT', ('%02.2f' % waterDepth, '00.00')))) 98 99 latitude = degreesDecimalToNmea(latitude) 100 longitude = degreesDecimalToNmea(longitude) 101 102 logsystemtime = "" 103 if logsystemtime: 104 logsystemtime = '{}: '.format(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")) 105 106 try: 107 nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.RMC('GN', 'RMC', 108 (gpsTime.strftime("%H%M%S"), gpsStatus, 109 '{:02d}{:07.4f}'.format(latitude['degrees'], latitude['minutes']), 110 latitudeDirection, 111 '{:03d}{:07.4f}'.format(longitude['degrees'], longitude['minutes']), 112 longitudeDirection, 113 '{:04.1f}'.format(speedOverGround), '{:04.1f}'.format(courseOverGround), 114 gpsTime.strftime("%d%m%y"), '', '', mode))))) 115 if transducerValid: 116 nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.DPT('SD', 'DPT', ('{:05.2f}'.format(waterDepth), '00.00'))))) 117 nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.MTW('YX', 'MTW', ('{:04.1f}'.format(waterTemperature), 'C'))))) 118 except: 119 print('Failed writing to logfile {}'.format(nmeaLogFile)) 120 print(traceback.format_exc()) 121 122 def degreesDecimalToNmea(decimalDegrees): 123 degrees = int(math.floor(decimalDegrees)) 124 minutes = 60.0 * (decimalDegrees - degrees) 125 return { 'degrees': degrees, 'minutes': minutes} 148 126 149 127 def main(argv): … … 151 129 global shutdownfile 152 130 global logperiod 131 global logverbose 132 global logsystemtime 153 133 global displayperiod 154 134 global logdir 155 135 global nmeafile 156 136 157 try: 158 opts, args = getopt.getopt(argv, "hr:s:l:d:o:", [ 159 "help", "rrdfile=", "shutdownfile=", "logperiod=", "displayperiod=", "output="]) 160 except getopt.GetoptError: 161 usage() 162 sys.exit(2) 163 164 for option, argument in opts: 165 if option == ("-h", "--help"): 166 usage() 167 sys.exit() 168 elif option in ("-r", "--rrdfile"): 169 rrdfile = argument 170 elif option in ("-s", "--shutdownfile"): 171 shutdownfile = argument 172 elif option in ("-l", "--logperiod"): 173 logperiod = argument 174 elif option in ("-d", "--displayperiod"): 175 displayperiod = argument 176 elif option in ("-o", "--output"): 177 logdir = argument 178 else: 179 assert False, "unhandled option" 137 parser = argparse.ArgumentParser(description='Collects the data from canboat and gpsd and writes them to the rrd database and the nmea log file') 138 parser.add_argument('-r', '--rrdfile', dest='rrd_file', metavar='rrd_file', type=str, 139 help='Path to the rrd database used by the webservice to serve the clients', default=rrdfile) 140 parser.add_argument('-s', '--shutdownfile', dest='shutdown_file', metavar='shutdown_file', type=str, 141 help='Path to the shutdown request file, used by the webservice to request a shutdown of the system running gnuboat', default=shutdownfile) 142 parser.add_argument('-lp', '--logperiod', dest='log_period', metavar='log_period', type=int, 143 help='Time in seconds to update the logs', default=logperiod) 144 parser.add_argument('-lv', '--log-verbose', action='store_true', dest='log_verbose', 145 help='Log verbose information to nmea log file (Enables -ls and adds RMC sentences, with invalid GPS state, on non fixes (Default off)') 146 parser.add_argument('-ls', '--log-system-time', action='store_true', dest='log_system_time', 147 help='Add to enable prefixing every logline with the system time (Default off)') 148 parser.add_argument('-d', '--displayperiod', dest='display_period', metavar='display_period', type=int, 149 help='Time in seconds to update the display', default=displayperiod) 150 parser.add_argument('-o', '--output', dest='output', metavar='output', type=str, 151 help='Directory where the log files are stored (e.g. the NMEA0183 log files)', default=logdir) 152 arguments = parser.parse_args(argv) 153 154 if arguments.rrd_file is not None: 155 rrdfile = arguments.rrd_file 156 if arguments.shutdown_file is not None: 157 shutdownfile = arguments.shutdown_file 158 if arguments.log_period is not None: 159 logperiod = arguments.log_period 160 if arguments.log_verbose is not None: 161 logverbose = arguments.log_verbose 162 logsystemtime = True 163 if arguments.log_system_time is not None and arguments.log_verbose is None: 164 logsystemtime = arguments.log_system_time 165 if arguments.display_period is not None: 166 displayperiod = arguments.display_period 167 if arguments.output is not None: 168 logdir = arguments.output 180 169 181 170 if not os.path.exists(os.path.dirname(rrdfile)): 182 print "rrd database directory not found %s" % os.path.dirname(rrdfile) 183 print "" 184 usage() 171 print('rrd database directory not found {}'.format(os.path.dirname(rrdfile))) 172 parser.print_help() 185 173 sys.exit(2) 186 174 187 175 if not os.path.exists(os.path.dirname(shutdownfile)): 188 print "Shutdown request directory not found %s" % os.path.dirname(shutdownfile) 189 print "" 190 usage() 176 print('Shutdown request directory not found {}'.format(os.path.dirname(shutdownfile))) 177 parser.print_help() 191 178 sys.exit(2) 192 179 193 180 if logperiod < 1: 194 print "Log period must be >= 1" 195 print "" 196 usage() 181 print('Log period must be >= 1') 182 parser.print_help() 197 183 sys.exit(2) 198 184 199 185 if displayperiod < 1 or displayperiod < logperiod: 200 print "Display period must be >= 1 and could not be faster than log period" 201 print "" 202 usage() 203 sys.exit(2) 204 205 createDatabase(rrdfile) 186 print('Display period must be >= 1 and could not be faster than log period') 187 parser.print_help() 188 sys.exit(2) 189 190 daemon.rrd_create_database(rrdfile, logperiod) 191 192 if os.path.isfile(shutdownfile): 193 os.remove(shutdownfile) 206 194 207 195 displayHandler = daemon.DisplayHandler(displayperiod) … … 220 208 speedThroughWater = n2kd.speedThroughWater() 221 209 speedOverGround = gpsp.speedOverGround() 210 courseOverGround = gpsp.courseOverGround() 222 211 waterDepth = n2kd.waterDepth() 223 212 waterTemperature = n2kd.waterTemperature() … … 225 214 226 215 # update rrd database for the webservice 227 rrdtool.update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s" %(228 latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix))216 daemon.rrd_update(rrdfile, 'N:{}:{}:{}:{}:{}:{}:{}:{}'.format( 217 latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix)) 229 218 230 219 # append to log 231 220 log(gpsFix, gpsp.timeUtc(), gpsp.status(), latitude, gpsp.latitudeDirection(), 232 longitude, gpsp.longitudeDirection(), gpsp.courseOverGround(), speedOverGround,233 waterDepth, n2kd.waterDepthValid())221 longitude, gpsp.longitudeDirection(), courseOverGround, speedOverGround, 222 waterDepth, waterTemperature, n2kd.waterDepthValid(), logverbose, logsystemtime) 234 223 235 224 # display data 236 225 displayHandler.setValues( 237 speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)226 speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix) 238 227 239 228 # check for shutdown request -
src/python/bin/gnuboat-splashscreen
rc810990 r8fd7454 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 %s not found" % image 68 print "" 67 print("Image {} not found".format(image)) 69 68 usage() 70 69 sys.exit(2) 71 70 72 71 if not epdEnabled: 73 print "Could not initialize EPD or PIL python packages"72 print("Could not initialize EPD or PIL python packages") 74 73 sys.exit(2) 75 74
Note:
See TracChangeset
for help on using the changeset viewer.
