From d7363af4d24dbd7c399b556a0069b97d101b046c Mon Sep 17 00:00:00 2001 From: balu_ Date: Mon, 6 Apr 2015 01:38:31 +0200 Subject: [PATCH 1/6] Do not download all non archived Files everytime reverts da76e054ea1618a805c4e34789479dfd35021929 --- antfs_cli/program.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/antfs_cli/program.py b/antfs_cli/program.py index d5b5fa2..e5f3736 100755 --- a/antfs_cli/program.py +++ b/antfs_cli/program.py @@ -211,7 +211,7 @@ def on_transport(self, beacon): remote_names = set(name for (name, fil) in remote_files) downloading = [fil for name, fil in remote_files - if name not in local_names or not fil.is_archived()] + if name not in local_names] uploading = [(name, filetype) for name, filetype in local_files if name not in remote_names] From 03f02f7791e2a0e016e0f154e5e0ed10451067fc Mon Sep 17 00:00:00 2001 From: balu_ Date: Mon, 6 Apr 2015 01:51:38 +0200 Subject: [PATCH 2/6] Added option to set time on vivofit --- antfs_cli/program.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/antfs_cli/program.py b/antfs_cli/program.py index e5f3736..9cdfa13 100755 --- a/antfs_cli/program.py +++ b/antfs_cli/program.py @@ -137,6 +137,7 @@ def __init__(self, config_dir, args): self._device = None self._uploading = args.upload + self._time = args.time self._pair = args.pair self._skip_archived = args.skip_archived @@ -189,8 +190,19 @@ def on_authentication(self, beacon): return False def on_transport(self, beacon): + #transmit time so that devices can adjust their clocks + if self._time: + print("Transfer time to device") + try: + result = self.set_time() + except AntFSTimeException, e: + print("Could not set time %s", str(e)) + _logger.debug("Could not set time") + else: + print("Time set") + directory = self.download_directory() - # directory.print_list() + directory.print_list() # Map local filenames to FIT file types local_files = [] @@ -306,6 +318,7 @@ def callback(new_progress): def main(): parser = ArgumentParser(description="Extracts FIT files from ANT-FS based sport watches.") parser.add_argument("--upload", action="store_true", help="enable uploading") + parser.add_argument("-t","--time", action="store_true", help="send time to divice (for example to set its clock)") parser.add_argument("--debug", action="store_true", help="enable debug") parser.add_argument("--pair", action="store_true", help="force pairing even if already paired") parser.add_argument("-a", "--skip-archived", action="store_true", help="don't download files marked as 'archived' on the watch") From 1db06249dbc62f74ea9ee25c94150cf0ff384b0e Mon Sep 17 00:00:00 2001 From: balu_ Date: Mon, 6 Apr 2015 02:47:31 +0200 Subject: [PATCH 3/6] Added an option to delete monitoring_B files that were present before download began --- antfs_cli/program.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/antfs_cli/program.py b/antfs_cli/program.py index 9cdfa13..ca6e2af 100755 --- a/antfs_cli/program.py +++ b/antfs_cli/program.py @@ -138,6 +138,7 @@ def __init__(self, config_dir, args): self._device = None self._uploading = args.upload self._time = args.time + self._erase = args.erase self._pair = args.pair self._skip_archived = args.skip_archived @@ -202,6 +203,8 @@ def on_transport(self, beacon): print("Time set") directory = self.download_directory() + + print("Files on device:") directory.print_list() # Map local filenames to FIT file types @@ -224,6 +227,9 @@ def on_transport(self, beacon): downloading = [fil for name, fil in remote_files if name not in local_names] + already_downloaded = [fil + for name, fil in remote_files + if name in local_names and fil.get_fit_sub_type() == File.Identifier.MONITORING_B] uploading = [(name, filetype) for name, filetype in local_files if name not in remote_names] @@ -241,7 +247,13 @@ def on_transport(self, beacon): # Download missing files: for fileobject in downloading: self.download_file(fileobject) - + + #delete file + if self._erase: + print("Erase all files that were already present before downloading") + for fileobject in already_downloaded: + self.erase_file(fileobject) + # Upload missing files: if uploading and self._uploading: # Upload @@ -274,6 +286,21 @@ def get_filepath(self, fil): _filetypes[fil.get_fit_sub_type()], self.get_filename(fil)) + def erase_file(self, fil): + if not isinstance(fil, File): + print("fil not of type File") + return + sys.stdout.write("Erasing file {0}: ".format(self.get_filename(fil))) + sys.stdout.flush() + try: + self.erase(fil.get_index()) + except AntFSDownloadException, e: + sys.stdout.write("Could not erase file") + else: + sys.stdout.write("Done") + sys.stdout.write("\n") + sys.stdout.flush() + def download_file(self, fil): sys.stdout.write("Downloading {0}: ".format(self.get_filename(fil))) sys.stdout.flush() @@ -319,6 +346,7 @@ def main(): parser = ArgumentParser(description="Extracts FIT files from ANT-FS based sport watches.") parser.add_argument("--upload", action="store_true", help="enable uploading") parser.add_argument("-t","--time", action="store_true", help="send time to divice (for example to set its clock)") + parser.add_argument("-e","--erase", action="store_true", help="delete monitoring_b files that have already been downloaded before") parser.add_argument("--debug", action="store_true", help="enable debug") parser.add_argument("--pair", action="store_true", help="force pairing even if already paired") parser.add_argument("-a", "--skip-archived", action="store_true", help="don't download files marked as 'archived' on the watch") From ced7a37a1a079ae692fb04fb0d97617857e1a012 Mon Sep 17 00:00:00 2001 From: balu_ Date: Tue, 7 Apr 2015 00:05:48 +0200 Subject: [PATCH 4/6] Changed dependency to openant 0.3 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index f17c0a8..35d8ace 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4'], - dependency_links=['git+https://github.com/Tigge/openant.git#egg=openant-0.2'], - install_requires=['openant>=0.2'], + dependency_links=['git+https://github.com/Tigge/openant.git#egg=openant-0.3'], + install_requires=['openant>=0.3'], test_suite='tests') From e12ced0dc90ea81cf2dc2b2537f103993a09754b Mon Sep 17 00:00:00 2001 From: balu_ Date: Tue, 7 Apr 2015 00:06:14 +0200 Subject: [PATCH 5/6] Added option to print file-listing --- antfs_cli/program.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/antfs_cli/program.py b/antfs_cli/program.py index ca6e2af..ffa7839 100755 --- a/antfs_cli/program.py +++ b/antfs_cli/program.py @@ -139,6 +139,7 @@ def __init__(self, config_dir, args): self._uploading = args.upload self._time = args.time self._erase = args.erase + self._ls = args.ls self._pair = args.pair self._skip_archived = args.skip_archived @@ -204,8 +205,9 @@ def on_transport(self, beacon): directory = self.download_directory() - print("Files on device:") - directory.print_list() + if self._ls: + print("Files on device:") + directory.print_list() # Map local filenames to FIT file types local_files = [] @@ -347,6 +349,7 @@ def main(): parser.add_argument("--upload", action="store_true", help="enable uploading") parser.add_argument("-t","--time", action="store_true", help="send time to divice (for example to set its clock)") parser.add_argument("-e","--erase", action="store_true", help="delete monitoring_b files that have already been downloaded before") + parser.add_argument("--ls", action="store_true", help="print files stored on device") parser.add_argument("--debug", action="store_true", help="enable debug") parser.add_argument("--pair", action="store_true", help="force pairing even if already paired") parser.add_argument("-a", "--skip-archived", action="store_true", help="don't download files marked as 'archived' on the watch") From c9cbd2f46bf6a4c2b41a1927d759592de786e4ab Mon Sep 17 00:00:00 2001 From: balu_ Date: Tue, 7 Apr 2015 01:53:11 +0200 Subject: [PATCH 6/6] Updated Readme --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cfedc33..e262de4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ avoid having to re-sync. Requirements ------------ -- [openant >= 0.2](https://github.com/Tigge/openant) +- [openant >= 0.3](https://github.com/Tigge/openant) Installation ------------ @@ -29,9 +29,15 @@ Usage Usage: antfs-cli [options] Options: - -h, --help show this help message and exit - --upload enable uploading - --debug enable debug + -h, --help show this help message and exit + --upload enable uploading + -t, --time send time to divice (for example to set its clock) + -e, --erase delete monitoring_b files that have already been + downloaded before + --ls print files stored on device + --debug enable debug + --pair force pairing even if already paired + -a, --skip-archived don't download files marked as 'archived' on the watch File locations @@ -74,5 +80,6 @@ have been reported as working: - Garmin Forerunner 910XT - Garmin FR70 - Garmin Swim + - Garmin vivofit Please let me know if you have any success with devices that are not listed here.