Changeset 8ef59a1 for src/python/bin


Ignore:
Timestamp:
Oct 30, 2017, 9:53:22 AM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, debian/jessie
Children:
8fd7454
Parents:
e86d691 (diff), 26f77a6 (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.
Message:

Merge branch '0.5' into debian/jessie

Conflicts:

setup.py

Location:
src/python/bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/python/bin/gnuboat

    re86d691 r8ef59a1  
    107107        nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.RMC('GN', 'RMC',
    108108                                                     (gpsTime.strftime("%H%M%S"), gpsStatus,
    109                                                      '{:02d}{}'.format(latitude['degrees'], latitude['minutes']),
     109                                                     '{:02d}{:07.4f}'.format(latitude['degrees'], latitude['minutes']),
    110110                                                     latitudeDirection,
    111                                                      '{:03d}{}'.format(longitude['degrees'], longitude['minutes']),
     111                                                     '{:03d}{:07.4f}'.format(longitude['degrees'], longitude['minutes']),
    112112                                                     longitudeDirection,
    113113                                                     '{:04.1f}'.format(speedOverGround), '{:04.1f}'.format(courseOverGround),
  • src/python/bin/gnuboat-log-converter

    re86d691 r8ef59a1  
    3434
    3535regex_nmea_sentence = re.compile(r"^([^\$!]{0,})([\$!]{1}[\w]{2}[\w]{3}[^\*]+\*[\da-zA-Z]+)$")
    36 regex_nmea_position = re.compile(r"^([0-9]+)([0-9]{2}\.[0-9]+)$")
     36regex_nmea_sentence_without_checksum = re.compile(r"^([^\$!]{0,})([\$!]{1}[\w]{2}[\w]{3}[^\*]+)\*[\da-zA-Z]+$")
     37regex_nmea_position_latitude = re.compile(r"^([0-9]{2})([0-9]{2}\.[0-9]+)$")
     38regex_nmea_position_longitude = re.compile(r"^([0-9]{3})([0-9]{2}\.[0-9]+)$")
    3739
    3840def toFloat(string, current_row):
    … …  
    4648           return 0
    4749
    48 def nmeaToDecimalDegrees(nmea_value, current_row):
    49     global regex_nmea_position
     50def nmeaLatitudeToDecimalDegrees(nmea_value, current_row):
     51    global regex_nmea_position_latitude
    5052
    5153    if toFloat(nmea_value, current_row) == 0:
    5254        return 0
    5355
    54     matches = regex_nmea_position.match(nmea_value)
     56    matches = regex_nmea_position_latitude.match(nmea_value)
    5557    if matches is None:
    56         print('INFO: Failed to convert position value from line {} into decimal degrees: {}'.format(current_row, nmea_value))
     58        print('INFO: Failed to convert latitude position value from line {} into decimal degrees: {}'.format(current_row, nmea_value))
    5759        return
    5860    decimalDegrees = toFloat(matches.group(1), current_row)
    … …  
    6062    return decimalDegrees + (decimalMinutes / 60.0)
    6163
    62 def convertToCsv(input_file_path, output_file_path, errors_ignore, strip_time):
     64def 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
     78def convertToCsv(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time):
    6379    global regex_nmea_sentence
     80    global regex_nmea_sentence_without_checksum
    6481
    6582    try:
    … …  
    87104    for line in input_file:
    88105        line = line.strip()
    89         matches = regex_nmea_sentence.match(line)
     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
    90112        if matches is None:
    91113            print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row))
    … …  
    95117                sys.exit(4)
    96118        else:
    97             nmea_sentence = pynmea2.parse(matches.group(2))
     119            nmea_sentence = pynmea2.parse(matches.group(2), check=pynmea_parse_check)
    98120            if nmea_sentence.sentence_type == 'RMC':
    99121                if last_row is not None:
    … …  
    101123                last_row = {'datetime': '{} {}'.format(nmea_sentence.datestamp, nmea_sentence.timestamp),
    102124                            'gps_status': nmea_sentence.status,
    103                             'latitude': nmeaToDecimalDegrees(nmea_sentence.lat, current_row),
     125                            'latitude': nmeaLatitudeToDecimalDegrees(nmea_sentence.lat, current_row),
    104126                            'latitude_direction': nmea_sentence.lat_dir,
    105                             'longitude': nmeaToDecimalDegrees(nmea_sentence.lon, current_row),
     127                            'longitude': nmeaLongitudeToDecimalDegrees(nmea_sentence.lon, current_row),
    106128                            'longitude_direction': nmea_sentence.lon_dir,
    107129                            'speed_over_ground': toFloat(nmea_sentence.spd_over_grnd, current_row),
    … …  
    119141    input_file.close()
    120142
    121 def convertToNmea0183(input_file_path, output_file_path, errors_ignore, strip_time):
     143def convertToNmea0183(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time):
    122144    global regex_nmea_sentence
     145    global regex_nmea_sentence_without_checksum
    123146
    124147    try:
    … …  
    138161    for line in input_file:
    139162        line = line.strip()
    140         matches = regex_nmea_sentence.match(line)
     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
    141169        if matches is None:
    142170            print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row))
    … …  
    146174                sys.exit(4)
    147175        else:
    148             nmea_sentence = pynmea2.parse(matches.group(2))
     176            nmea_sentence = pynmea2.parse(matches.group(2), check=pynmea_parse_check)
    149177            output_string = str(nmea_sentence)
    150178            if not strip_time and matches.group(1):
    … …  
    154182    input_file.close()
    155183   
    156 def convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time):
    157     global regex_nmea_sentence
    158    
     184def convertToGpx(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time):
    159185    # make sure, nmea input file, does not have timestamps in front of the nmea
    160186    # sentences
    161187    [nmea_without_timestamps_handle, nmea_without_timestamp_file_path] = tempfile.mkstemp(text=True)
    162     convertToNmea0183(input_file_path, nmea_without_timestamp_file_path, errors_ignore, True)
     188    convertToNmea0183(input_file_path, nmea_without_timestamp_file_path, errors_ignore, checksums_fix, True)
    163189   
    164190    subprocess.call(['gpsbabel', '-i', 'nmea', '-f', nmea_without_timestamp_file_path, '-o', 'gpx', '-F', output_file_path])
    … …  
    182208    parser.add_argument('-i', '--ignore-errors', dest='errors_ignore', action='store_false',
    183209                        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)')
    184212    parser.add_argument('input_file', metavar='input_file_path', type=str,
    185213                        help='File to be converted (input)')
    … …  
    203231        errors_ignore = arguments.errors_ignore
    204232       
     233    if arguments.checksums_fix is not None:
     234        checksums_fix = arguments.checksums_fix
     235       
    205236    if arguments.strip_time is not None:
    206237        strip_time = arguments.strip_time
    … …  
    209240        print('ERROR: No input file specified')
    210241        sys.exit(2)
    211     elif not os.path.exists(arguments.input_file):
     242    #elif not os.path.exists(arguments.input_file):
    212243        print('ERROR: Specified input file does not exists: {}'.format(arguments.input_file))
    213244        sys.exit(3)
    … …  
    225256
    226257    if output_format == Format.CSV.value:
    227         convertToCsv(input_file_path, output_file_path, errors_ignore, strip_time)
     258        convertToCsv(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time)
    228259    elif output_format == Format.NMEA0183.value:
    229         convertToNmea0183(input_file_path, output_file_path, errors_ignore, strip_time)
     260        convertToNmea0183(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time)
    230261    elif output_format == Format.GPX.value:
    231         convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time)
     262        convertToGpx(input_file_path, output_file_path, errors_ignore, checksums_fix, strip_time)
    232263    else:
    233264        print('ERROR: Undefined output format!\n')
Note: See TracChangeset for help on using the changeset viewer.