Skip to content

Commit

Permalink
fix: ignore device info for origin fit file in strava_to_garmin_sync (#…
Browse files Browse the repository at this point in the history
…448)

* fix: ignore fit file origin device

fix: ignore fit file origin device

* docs: remove redundant English desc

* chore: remove test code

* style: reformat code
  • Loading branch information
zhaohongxuan committed Jul 10, 2023
1 parent d56ef2c commit 0336dc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
2 changes: 0 additions & 2 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,6 @@ python3(python) scripts/strava_to_garmin_sync.py ${{ secrets.STRAVA_CLIENT_ID }}
python3(python) scripts/strava_to_garmin_sync.py ${{ secrets.STRAVA_CLIENT_ID }} ${{ secrets.STRAVA_CLIENT_SECRET }} ${{ secrets.STRAVA_CLIENT_REFRESH_TOKEN }} ${{ secrets.GARMIN_CN_EMAIL }} ${{ secrets.GARMIN_CN_PASSWORD }} ${{ secrets.STRAVA_EMAIL }} ${{ secrets.STRAVA_PASSWORD }} --is-cn
```

If you want to add Garmin Device during sync, you should add `--use_fake_garmin_device` argument, this will add a Garmin Device (Garmin Forerunner 245 by default, and you can change device in `garmin_device_adaptor.py`) in synced Garmin workout record, this is essential when you want to sync the workout record to other APP like Keep, JoyRun etc. and the final command will be:

如果要在同步到Garmin的运动记录中添加Garmin设备信息,需要添加`--use_fake_garmin_device`参数,这将在同步的Garmin锻炼记录中添加一个Garmin设备(默认情况下为 `Garmin Forerunner 245`,您可以在`garmin_device_adaptor.py`中更改设备信息),运动记录中有了设备信息之后就可以同步到其他APP中,比如数字心动(攒上马积分)这类不能通过Apple Watch同步的APP,当然也可以同步到Keep,悦跑圈,咕咚等APP。

<img width="830" alt="image" src="https://github.com/yihong0618/running_page/assets/8613196/b5076942-3133-4c89-ad66-a828211667dc">
Expand Down
19 changes: 7 additions & 12 deletions scripts/garmin_device_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from fit_tool.fit_file import FitFile
from fit_tool.fit_file_builder import FitFileBuilder
from fit_tool.profile.messages.device_info_message import DeviceInfoMessage
from fit_tool.profile.messages.file_id_message import FileIdMessage
from io import BytesIO

# the device manufacturer and product info can be found in github,
Expand Down Expand Up @@ -43,6 +42,13 @@ def do_wrap_device_info(origin_file):
fit_file = FitFile.from_bytes(origin_file.read())
builder = FitFileBuilder(auto_define=True)

for record in fit_file.records:
message = record.message
if message.global_id == DeviceInfoMessage.ID:
# ignore file device info, like WorkoutDoors APP
continue
builder.add(message)

# Add custom Device Info
message = DeviceInfoMessage()
# the serial number must be real, otherwise Garmin will not identify it
Expand All @@ -55,17 +61,6 @@ def do_wrap_device_info(origin_file):
message.product = GARMIN_DEVICE_PRODUCT_ID
builder.add(message)

for record in fit_file.records:
message = record.message
if message.global_id == FileIdMessage.ID:
if isinstance(message, FileIdMessage):
message.manufacturer = MANUFACTURER
message.garmin_product = GARMIN_DEVICE_PRODUCT_ID
message.product = GARMIN_DEVICE_PRODUCT_ID
message.type = 4 # Activity

builder.add(message)

modified_file = builder.build()
print("wrap garmin device info sucess, product id:", GARMIN_DEVICE_PRODUCT_ID)
return modified_file.to_bytes()

1 comment on commit 0336dc7

@vercel
Copy link

@vercel vercel bot commented on 0336dc7 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

running-page – ./

running-page-git-master-yihong0618.vercel.app
running-page-yihong0618.vercel.app
running-page.vercel.app

Please sign in to comment.