Skip to content

Commit 896a4be

Browse files
committed
Fix PM5 advertising on Android and optimize UUID handling
- Add startAdvertisingRowerPM5() method in BleAdvertiser.java that uses the PM5 discovery service UUID (CE060000) instead of FTMS - Call the correct advertising method based on pm5Mode flag - Reduce advertised UUIDs to only discovery service (128-bit UUIDs are large, other services are discovered after connection) https://claude.ai/code/session_01XWBgRPWze8Mb7DEEm4oXiF
1 parent 3228038 commit 896a4be

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

src/android/src/BleAdvertiser.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
public class BleAdvertiser {
3939
private static final UUID SERVICE_UUID = UUID.fromString("00001826-0000-1000-8000-00805f9b34fb");
40+
// PM5 Concept2 UUIDs
41+
private static final UUID PM5_DISCOVERY_SERVICE_UUID = UUID.fromString("CE060000-43E5-11E4-916C-0800200C9A66");
42+
private static final UUID PM5_ROWING_SERVICE_UUID = UUID.fromString("CE060030-43E5-11E4-916C-0800200C9A66");
4043
private static final byte[] SERVICE_DATA_ROWER = {0x01, 0x10, 0x00};
4144
private static final byte[] SERVICE_DATA_TREADMILL = {0x01, 0x01, 0x00};
4245

@@ -63,6 +66,31 @@ public static void startAdvertisingRower(Context context) {
6366
}
6467
}
6568

69+
public static void startAdvertisingRowerPM5(Context context) {
70+
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
71+
if (bluetoothManager != null) {
72+
android.bluetooth.le.BluetoothLeAdvertiser advertiser = bluetoothManager.getAdapter().getBluetoothLeAdvertiser();
73+
74+
AdvertiseSettings settings = new AdvertiseSettings.Builder()
75+
.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY)
76+
.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
77+
.setConnectable(true)
78+
.build();
79+
80+
// PM5 advertising - use discovery service UUID
81+
// Note: 128-bit UUIDs take more space, so we only advertise the discovery UUID
82+
AdvertiseData advertiseData = new AdvertiseData.Builder()
83+
.setIncludeDeviceName(true)
84+
.addServiceUuid(new ParcelUuid(PM5_DISCOVERY_SERVICE_UUID))
85+
.build();
86+
87+
if (advertiser != null) {
88+
QLog.d("BleAdvertiser", "Starting PM5 advertising with UUID: " + PM5_DISCOVERY_SERVICE_UUID.toString());
89+
advertiser.startAdvertising(settings, advertiseData, advertiseCallback);
90+
}
91+
}
92+
}
93+
6694
public static void startAdvertisingTreadmill(Context context) {
6795
BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
6896
if (bluetoothManager != null) {

src/virtualdevices/virtualrower.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ virtualrower::virtualrower(bluetoothdevice *t, bool noWriteResistance, bool noHe
124124
if (!heart_only) {
125125
if (pm5Mode) {
126126
// PM5 uses Concept2 proprietary services
127-
// Advertise the discovery service UUID for PM5 identification
127+
// Only advertise the discovery service UUID (128-bit UUIDs are large)
128+
// The other services will be discovered after connection
128129
services << PM5_DISCOVERY_SERVICE_UUID;
129-
services << PM5_ROWING_SERVICE_UUID;
130-
services << PM5_DEVICE_INFO_SERVICE_UUID;
131-
services << PM5_CONTROL_SERVICE_UUID;
132130
} else {
133131
services << ((QBluetoothUuid::ServiceClassUuid)0x1826);
134132
}
@@ -287,8 +285,13 @@ virtualrower::virtualrower(bluetoothdevice *t, bool noWriteResistance, bool noHe
287285
}
288286

289287
#ifdef Q_OS_ANDROID
290-
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/BleAdvertiser", "startAdvertisingRower",
291-
"(Landroid/content/Context;)V", QtAndroid::androidContext().object());
288+
if (pm5Mode) {
289+
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/BleAdvertiser", "startAdvertisingRowerPM5",
290+
"(Landroid/content/Context;)V", QtAndroid::androidContext().object());
291+
} else {
292+
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/BleAdvertiser", "startAdvertisingRower",
293+
"(Landroid/content/Context;)V", QtAndroid::androidContext().object());
294+
}
292295
#else
293296
leController->startAdvertising(pars, advertisingData, advertisingData);
294297
#endif
@@ -438,8 +441,13 @@ void virtualrower::reconnect() {
438441
QLowEnergyAdvertisingParameters pars;
439442
pars.setInterval(100, 100);
440443
#ifdef Q_OS_ANDROID
441-
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/BleAdvertiser", "startAdvertisingRower",
442-
"(Landroid/content/Context;)V", QtAndroid::androidContext().object());
444+
if (pm5Mode) {
445+
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/BleAdvertiser", "startAdvertisingRowerPM5",
446+
"(Landroid/content/Context;)V", QtAndroid::androidContext().object());
447+
} else {
448+
QAndroidJniObject::callStaticMethod<void>("org/cagnulen/qdomyoszwift/BleAdvertiser", "startAdvertisingRower",
449+
"(Landroid/content/Context;)V", QtAndroid::androidContext().object());
450+
}
443451
#else
444452
leController->startAdvertising(pars, advertisingData, advertisingData);
445453
#endif

0 commit comments

Comments
 (0)