From ae8c22122083d7d7daece1c4f0e3f3161d7e3ec2 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Fri, 10 Jan 2020 11:31:34 +0100 Subject: [PATCH] tools: Import the gpxify program. gpxify takes as input an recording retrieved from the GPS watch and converts it to GPX format. --- tools/gpxify | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100755 tools/gpxify diff --git a/tools/gpxify b/tools/gpxify new file mode 100755 index 0000000..08c24e9 --- /dev/null +++ b/tools/gpxify @@ -0,0 +1,138 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2020 Tilman Sauerbeck (tilman at code-monkey de) +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +from datetime import datetime +import struct +import sys + +class Packet(object): + def __init__(self, unix_time, latitude, longitude): + self.unix_time = unix_time + self.latitude = latitude + self.longitude = longitude + +class PacketExtractor(object): + POINTS_PER_GROUP = 7 + PADDING_BYTE = 0xff + + def __init__(self, source): + self._source = source + self._unix_time = None + self._latitude = 0 + self._longitude = 0 + self._flags = 0 + self._num_points = 0 + + def run(self): + header = self._source.read(5) + + format_version, self._unix_time = struct.unpack('> 1) ^ h; + + return n + +if __name__ == '__main__': + filename = sys.argv[1] + + with open(filename, 'rb') as f: + print('') + print('') + print('\t') + print('\t\t{}'.format(filename)) + print('\t\t{}'.format(1)) + print('\t\t') + + for packet in PacketExtractor(f).run(): + print('\t\t\t'.format( + packet.latitude, packet.longitude)) + + dt = datetime.utcfromtimestamp(packet.unix_time) + + print(dt.strftime('\t\t\t\t')) + print('\t\t\t') + + print('\t\t') + print('\t') + print('') -- 2.30.2