Changeset ea6eba1
- Timestamp:
- Jun 10, 2018, 12:28:07 PM (8 years ago)
- Branches:
- debian/bullseye, master
- Children:
- ca02e8f
- Parents:
- 9f28f0a
- git-author:
- Joachim Langenbach <joachim.langenbach@…> (06/10/18 11:49:37)
- git-committer:
- Joachim Langenbach <joachim.langenbach@…> (06/10/18 12:28:07)
- Files:
-
- 3 added
- 4 edited
-
setup.py (modified) (2 diffs)
-
src/python/bin/gnuboat (modified) (8 diffs)
-
src/python/bin/gnuboat-log-converter (modified) (6 diffs)
-
src/python/gnuboat/__init__.py (modified) (2 diffs)
-
src/python/gnuboat/datahandler/__init__.py (added)
-
src/python/gnuboat/datahandler/logdataset.py (added)
-
src/python/gnuboat/datahandler/loghandler.py (added)
Legend:
- Unmodified
- Added
- Removed
-
setup.py
r9f28f0a rea6eba1 2 2 # -*- coding: utf-8 -*- 3 3 ''' 4 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.4 Copyright (C) 2017 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 5 5 6 6 This program is free software: you can redistribute it and/or modify … … 28 28 setup( 29 29 name="gnuboat", 30 version="0.4. 2",30 version="0.4.3", 31 31 maintainer="EngSaS - Langenbach", 32 32 maintainer_email="info@engsas.de", -
src/python/bin/gnuboat
r9f28f0a rea6eba1 2 2 # -*- coding: utf-8 -*- 3 3 ''' 4 Copyright (C) 2016 - 201 7EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.4 Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 5 5 6 6 This program is free software: you can redistribute it and/or modify … … 34 34 35 35 from gnuboat import daemon 36 from gnuboat.datahandler import loghandler, logdataset 36 37 37 38 WHITE = 1 … … 50 51 51 52 shutdownRequested = None 52 nmeafile = None 53 nmeaFileDate = None 53 log_handler = None 54 54 55 55 … … 69 69 os.system("sudo shutdown -h now") 70 70 71 def log(gpsFix, gpsTime, gpsStatus, latitude, latitudeDirection, longitude,72 longitudeDirection, courseOverGround, speedOverGround, waterDepth, waterTemperature, transducerValid, logVerbose, logSystemTime):73 global logdir74 global nmeafile75 global nmeaFileDate76 77 # Only log, if we have a gps fix78 if gpsFix < 2:79 if not logVerbose:80 return81 gpsStatus = 'V'82 mode = 'N'83 if gpsTime is None:84 gpsTime = datetime.datetime.utcnow()85 86 nmeaFileDateShould = datetime.datetime.utcnow().strftime("%Y-%m-%d")87 mode = 'A'88 if nmeafile == None or nmeaFileDate is None or nmeaFileDate != nmeaFileDateShould:89 if nmeafile:90 nmeafile.close()91 try:92 nmeaFileDate = nmeaFileDateShould93 nmeaLogFile = 'nmea0183-{}.log'.format(nmeaFileDate)94 nmeafile = open('{}/{}'.format(logdir, nmeaLogFile), 'a', 0)95 except IOError as error:96 print('Could not open the logfile: {}'.format(error))97 sys.exit(2)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}126 127 71 def main(argv): 128 72 global rrdfile … … 133 77 global displayperiod 134 78 global logdir 135 global nmeafile79 global log_handler 136 80 137 81 parser = argparse.ArgumentParser(description='Collects the data from canboat and gpsd and writes them to the rrd database and the nmea log file') … … 194 138 195 139 displayHandler = daemon.DisplayHandler(displayperiod) 140 log_handler = loghandler.LogHandler(logdir) 196 141 197 142 gpsp = daemon.GpsdPoller(logperiod) … … 218 163 219 164 # append to log 220 log(gpsFix, gpsp.timeUtc(), gpsp.status(), latitude, gpsp.latitudeDirection(),165 dataset = logdataset.LogDataset(None, gpsp.status(), latitude, gpsp.latitudeDirection(), 221 166 longitude, gpsp.longitudeDirection(), courseOverGround, speedOverGround, 222 waterDepth, waterTemperature, n2kd.waterDepthValid(), logverbose, logsystemtime) 167 waterDepth, waterTemperature) 168 if not log_handler.gnuboat_write(gpsFix, gpsp.timeUtc(), dataset, n2kd.waterDepthValid(), logverbose, logsystemtime): 169 sys.exit(2) 223 170 224 171 # display data … … 230 177 231 178 except (KeyboardInterrupt, SystemExit): # when you press ctrl+c 232 if nmeafile:233 nmeafile.close()179 if log_handler: 180 log_handler.gnuboat_close() 234 181 if gpsp.ident is not None: 235 182 gpsp.stop() -
src/python/bin/gnuboat-log-converter
r9f28f0a rea6eba1 24 24 from enum import Enum 25 25 import csv 26 import re27 26 import tempfile 28 27 import subprocess 28 29 from gnuboat.datahandler import loghandler, logdataset 29 30 30 31 class Format(Enum): … … 33 34 GPX = 3 34 35 35 regex_nmea_sentence = re.compile(r"^([^\$!]{0,})([\$!]{1}[\w]{2}[\w]{3}[^\*]+\*[\da-zA-Z]+)$") 36 regex_nmea_sentence_without_checksum = re.compile(r"^([^\$!]{0,})([\$!]{1}[\w]{2}[\w]{3}[^\*]+)\*[\da-zA-Z]+$") 37 regex_nmea_position_latitude = re.compile(r"^([0-9]{2})([0-9]{2}\.[0-9]+)$") 38 regex_nmea_position_longitude = re.compile(r"^([0-9]{3})([0-9]{2}\.[0-9]+)$") 36 class CsvCallback: 37 def __init__(self, output_file): 38 self._output_file = output_file 39 39 40 def toFloat(string, current_row): 41 try: 42 return float(string) 43 except ValueError as error: 44 try: 45 return int(string) 46 except ValueError as error: 47 print('INFO: Failed to convert value from line {} into numeric: {}\n Message: {}'.format(current_row, string, error)) 48 return 0 49 50 def nmeaLatitudeToDecimalDegrees(nmea_value, current_row): 51 global regex_nmea_position_latitude 52 53 if toFloat(nmea_value, current_row) == 0: 54 return 0 55 56 matches = regex_nmea_position_latitude.match(nmea_value) 57 if matches is None: 58 print('INFO: Failed to convert latitude position value from line {} into decimal degrees: {}'.format(current_row, nmea_value)) 59 return 60 decimalDegrees = toFloat(matches.group(1), current_row) 61 decimalMinutes = toFloat(matches.group(2), current_row) 62 return decimalDegrees + (decimalMinutes / 60.0) 63 64 def nmeaLongitudeToDecimalDegrees(nmea_value, current_row): 65 global regex_nmea_position_longitude 66 67 if toFloat(nmea_value, current_row) == 0: 68 return 0 69 70 matches = regex_nmea_position_longitude.match(nmea_value) 71 if matches is None: 72 print('INFO: Failed to convert longitude position value from line {} into decimal degrees: {}'.format(current_row, nmea_value)) 73 return 74 decimalDegrees = toFloat(matches.group(1), current_row) 75 decimalMinutes = toFloat(matches.group(2), current_row) 76 return decimalDegrees + (decimalMinutes / 60.0) 40 def callback(self, dataset): 41 self._output_file.writerow(dataset.to_dict()) 77 42 78 43 def convertToCsv(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time): 79 global regex_nmea_sentence80 global regex_nmea_sentence_without_checksum81 82 44 try: 83 45 output_file = open(output_file_path, 'w', 0) … … 94 56 output_file_csv.writeheader() 95 57 96 # reading input file 97 try: 98 input_file = open(input_file_path, 'r') 99 except IOError as error: 100 print('ERROR: Could not open the input file: {}'.format(error)) 101 sys.exit(3) 102 current_row = 1 103 last_row = None 104 for line in input_file: 105 line = line.strip() 106 if checksums_fix: 107 matches = regex_nmea_sentence_without_checksum.match(line) 108 pynmea_parse_check = False 109 else: 110 matches = regex_nmea_sentence.match(line) 111 pynmea_parse_check = True 112 if matches is None: 113 print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row)) 114 if not errors_ignore: 115 input_file.close() 116 output_file.close() 117 sys.exit(4) 118 else: 119 nmea_sentence = pynmea2.parse(matches.group(2), check=pynmea_parse_check) 120 if nmea_sentence.sentence_type == 'RMC': 121 if last_row is not None: 122 output_file_csv.writerow(last_row) 123 last_row = {'datetime': '{} {}'.format(nmea_sentence.datestamp, nmea_sentence.timestamp), 124 'gps_status': nmea_sentence.status, 125 'latitude': nmeaLatitudeToDecimalDegrees(nmea_sentence.lat, current_row), 126 'latitude_direction': nmea_sentence.lat_dir, 127 'longitude': nmeaLongitudeToDecimalDegrees(nmea_sentence.lon, current_row), 128 'longitude_direction': nmea_sentence.lon_dir, 129 'speed_over_ground': toFloat(nmea_sentence.spd_over_grnd, current_row), 130 'course_over_ground': toFloat(nmea_sentence.true_course, current_row), 131 'water_depth': None, 132 'water_temperature': None} 133 elif nmea_sentence.sentence_type == 'DPT' and last_row is not None: 134 last_row['water_depth'] = toFloat(nmea_sentence.depth, current_row) 135 elif nmea_sentence.sentence_type == 'MTW' and last_row is not None: 136 last_row['water_temperature'] = toFloat(nmea_sentence.temperature, current_row) 137 current_row += 1 138 if last_row is not None: 139 output_file_csv.writerow(last_row) 58 csv_callback = CsvCallback(output_file_csv) 59 log_handler = loghandler.LogHandler() 60 log_handler.gnuboat_read(input_file_path, csv_callback.callback, checksums_fix, errors_ignore) 140 61 output_file.close() 141 input_file.close()142 62 143 63 def convertToNmea0183(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time): 144 global regex_nmea_sentence145 global regex_nmea_sentence_without_checksum146 147 64 try: 148 65 output_file = open(output_file_path, 'w', 0) … … 157 74 print('ERROR: Could not open the input file: {}'.format(error)) 158 75 sys.exit(3) 76 77 log_handler = loghandler.LogHandler() 159 78 current_row = 1 160 79 last_row = None 161 80 for line in input_file: 162 line = line.strip() 163 if checksums_fix: 164 matches = regex_nmea_sentence_without_checksum.match(line) 165 pynmea_parse_check = False 166 else: 167 matches = regex_nmea_sentence.match(line) 168 pynmea_parse_check = True 169 if matches is None: 170 print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row)) 81 nmea_sentence = log_handler.parse_nmea_sentence(line, checksums_fix) 82 if nmea_sentence is None: 83 print('INFO: Failed to parse nmea sentence ({}) at line {}'.format(line.strip(), current_row)) 171 84 if not errors_ignore: 172 85 input_file.close() … … 174 87 sys.exit(4) 175 88 else: 176 nmea_sentence = pynmea2.parse(matches.group(2), check=pynmea_parse_check) 177 output_string = str(nmea_sentence) 178 if not strip_time and matches.group(1): 179 output_string = '{}{}'.format(matches.group(1), output_string) 89 output_string = str(nmea_sentence['nmea_sentence']) 90 if not strip_time and nmea_sentence['log_timestamp']: 91 output_string = '{}{}'.format(nmea_sentence['log_timestamp'], output_string) 180 92 output_file.write('{}\r\n'.format(str(output_string))) 93 current_row += 1 181 94 output_file.close() 182 95 input_file.close() … … 198 111 errors_ignore = False 199 112 strip_time = False 200 113 201 114 formats = [] 202 115 for file_format in Format: -
src/python/gnuboat/__init__.py
r9f28f0a rea6eba1 1 1 # -*- coding: utf-8 -*- 2 2 ''' 3 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.3 Copyright (C) 2017 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. 4 4 5 5 This program is free software: you can redistribute it and/or modify … … 21 21 from daemon.rrdhandler import rrd_create_database 22 22 from daemon.rrdhandler import rrd_update 23 from datahandler.loghandler import LogHandler
Note:
See TracChangeset
for help on using the changeset viewer.
