Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added options to optimize use with Vivofit #131

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -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
Expand Down Expand Up @@ -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.
50 changes: 47 additions & 3 deletions antfs_cli/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')