Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/python/bin/gnuboat-log-converter

    r26f77a6 r0c14082  
    3434
    3535regex_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]+)$")
     36regex_nmea_position = re.compile(r"^([0-9]+)([0-9]{2}\.[0-9]+)$")
    3937
    4038def toFloat(string, current_row):
    … …  
    4846           return 0
    4947
    50 def nmeaLatitudeToDecimalDegrees(nmea_value, current_row):
    51     global regex_nmea_position_latitude
     48def nmeaToDecimalDegrees(nmea_value, current_row):
     49    global regex_nmea_position
    5250
    5351    if toFloat(nmea_value, current_row) == 0:
    5452        return 0
    5553
    56     matches = regex_nmea_position_latitude.match(nmea_value)
     54    matches = regex_nmea_position.match(nmea_value)
    5755    if matches is None:
    58         print('INFO: Failed to convert latitude position value from line {} into decimal degrees: {}'.format(current_row, nmea_value))
     56        print('INFO: Failed to convert position value from line {} into decimal degrees: {}'.format(current_row, nmea_value))
    5957        return
    6058    decimalDegrees = toFloat(matches.group(1), current_row)
    … …  
    6260    return decimalDegrees + (decimalMinutes / 60.0)
    6361
    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)
    77 
    78 def convertToCsv(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time):
     62def convertToCsv(input_file_path, output_file_path, errors_ignore, strip_time):
    7963    global regex_nmea_sentence
    80     global regex_nmea_sentence_without_checksum
    8164
    8265    try:
    … …  
    10487    for line in input_file:
    10588        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
     89        matches = regex_nmea_sentence.match(line)
    11290        if matches is None:
    11391            print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row))
    … …  
    11795                sys.exit(4)
    11896        else:
    119             nmea_sentence = pynmea2.parse(matches.group(2), check=pynmea_parse_check)
     97            nmea_sentence = pynmea2.parse(matches.group(2))
    12098            if nmea_sentence.sentence_type == 'RMC':
    12199                if last_row is not None:
    … …  
    123101                last_row = {'datetime': '{} {}'.format(nmea_sentence.datestamp, nmea_sentence.timestamp),
    124102                            'gps_status': nmea_sentence.status,
    125                             'latitude': nmeaLatitudeToDecimalDegrees(nmea_sentence.lat, current_row),
     103                            'latitude': nmeaToDecimalDegrees(nmea_sentence.lat, current_row),
    126104                            'latitude_direction': nmea_sentence.lat_dir,
    127                             'longitude': nmeaLongitudeToDecimalDegrees(nmea_sentence.lon, current_row),
     105                            'longitude': nmeaToDecimalDegrees(nmea_sentence.lon, current_row),
    128106                            'longitude_direction': nmea_sentence.lon_dir,
    129107                            'speed_over_ground': toFloat(nmea_sentence.spd_over_grnd, current_row),
    … …  
    141119    input_file.close()
    142120
    143 def convertToNmea0183(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time):
     121def convertToNmea0183(input_file_path, output_file_path, errors_ignore, strip_time):
    144122    global regex_nmea_sentence
    145     global regex_nmea_sentence_without_checksum
    146123
    147124    try:
    … …  
    161138    for line in input_file:
    162139        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
     140        matches = regex_nmea_sentence.match(line)
    169141        if matches is None:
    170142            print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row))
    … …  
    174146                sys.exit(4)
    175147        else:
    176             nmea_sentence = pynmea2.parse(matches.group(2), check=pynmea_parse_check)
     148            nmea_sentence = pynmea2.parse(matches.group(2))
    177149            output_string = str(nmea_sentence)
    178150            if not strip_time and matches.group(1):
    … …  
    182154    input_file.close()
    183155   
    184 def convertToGpx(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time):
     156def convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time):
     157    global regex_nmea_sentence
     158   
    185159    # make sure, nmea input file, does not have timestamps in front of the nmea
    186160    # sentences
    187161    [nmea_without_timestamps_handle, nmea_without_timestamp_file_path] = tempfile.mkstemp(text=True)
    188     convertToNmea0183(input_file_path, nmea_without_timestamp_file_path, errors_ignore, checksums_fix, True)
     162    convertToNmea0183(input_file_path, nmea_without_timestamp_file_path, errors_ignore, True)
    189163   
    190164    subprocess.call(['gpsbabel', '-i', 'nmea', '-f', nmea_without_timestamp_file_path, '-o', 'gpx', '-F', output_file_path])
    … …  
    208182    parser.add_argument('-i', '--ignore-errors', dest='errors_ignore', action='store_false',
    209183                        help='Ignore any errors reading the log file')
    210     parser.add_argument('-c', '--checksums-fix', dest='checksums_fix', action='store_true',
    211                         help='Ignore all checksums (and replace them with a new correct one, if needed)')
    212184    parser.add_argument('input_file', metavar='input_file_path', type=str,
    213185                        help='File to be converted (input)')
    … …  
    231203        errors_ignore = arguments.errors_ignore
    232204       
    233     if arguments.checksums_fix is not None:
    234         checksums_fix = arguments.checksums_fix
    235        
    236205    if arguments.strip_time is not None:
    237206        strip_time = arguments.strip_time
    … …  
    240209        print('ERROR: No input file specified')
    241210        sys.exit(2)
    242     #elif not os.path.exists(arguments.input_file):
     211    elif not os.path.exists(arguments.input_file):
    243212        print('ERROR: Specified input file does not exists: {}'.format(arguments.input_file))
    244213        sys.exit(3)
    … …  
    256225
    257226    if output_format == Format.CSV.value:
    258         convertToCsv(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time)
     227        convertToCsv(input_file_path, output_file_path, errors_ignore, strip_time)
    259228    elif output_format == Format.NMEA0183.value:
    260         convertToNmea0183(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time)
     229        convertToNmea0183(input_file_path, output_file_path, errors_ignore, strip_time)
    261230    elif output_format == Format.GPX.value:
    262         convertToGpx(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time)
     231        convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time)
    263232    else:
    264233        print('ERROR: Undefined output format!\n')
Note: See TracChangeset for help on using the changeset viewer.