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. diff --git a/antfs_cli/program.py b/antfs_cli/program.py index d5b5fa2..ffa7839 100755 --- a/antfs_cli/program.py +++ b/antfs_cli/program.py @@ -137,6 +137,9 @@ def __init__(self, config_dir, args): self._device = None 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 @@ -189,8 +192,22 @@ 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() + + if self._ls: + print("Files on device:") + directory.print_list() # Map local filenames to FIT file types local_files = [] @@ -211,7 +228,10 @@ 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] + 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] @@ -229,7 +249,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 @@ -262,6 +288,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() @@ -306,6 +347,9 @@ 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("-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") 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')