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

fix: ignore device info for origin fit file in strava_to_garmin_sync #448

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 0 additions & 2 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,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
21 changes: 8 additions & 13 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()
return modified_file.to_bytes()
Loading