Skip to content

Commit 13ea531

Browse files
committed
Add D500V2 workaround for FTMS start simulation command
Implements a workaround for D500V2 bikes that require a START_RESUME (0x07) command before accepting simulation parameters (0x11). The code now tracks the command sequence and injects the necessary command if missing, ensuring compatibility with D500V2 models. Also adds detection and flag for D500V2 during device discovery.
1 parent 7f69473 commit 13ea531

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/devices/ftmsbike/ftmsbike.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,29 @@ void ftmsbike::ftmsCharacteristicChanged(const QLowEnergyCharacteristic &charact
14771477
if (gattWriteCharControlPointId.isValid()) {
14781478
qDebug() << "routing FTMS packet to the bike from virtualbike" << characteristic.uuid() << newValue.toHex(' ');
14791479

1480+
// D500V2 workaround: track request control (0x00) and start simulation (0x07) commands
1481+
// If we receive simulation params (0x11) without start simulation, inject it first
1482+
if (D500V2 && b.length() > 0) {
1483+
uint8_t commandCode = (uint8_t)b.at(0);
1484+
1485+
if (commandCode == FTMS_REQUEST_CONTROL) {
1486+
// Command 0x00: Request Control - expect start simulation next
1487+
awaiting_start_simulation_after_request_control = true;
1488+
qDebug() << "D500V2 workaround: received REQUEST_CONTROL (0x00), now awaiting START_RESUME (0x07)";
1489+
} else if (commandCode == FTMS_START_RESUME) {
1490+
// Command 0x07: Start Resume - no longer awaiting
1491+
awaiting_start_simulation_after_request_control = false;
1492+
qDebug() << "D500V2 workaround: received START_RESUME (0x07), ready for simulation params";
1493+
} else if (commandCode == FTMS_SET_INDOOR_BIKE_SIMULATION_PARAMS && D500V2 && awaiting_start_simulation_after_request_control) {
1494+
// Command 0x11: Set Simulation Params - but we're still awaiting start simulation
1495+
// For D500V2, inject the start simulation command (0x07) first
1496+
qDebug() << "D500V2 workaround: received SET_INDOOR_BIKE_SIMULATION_PARAMS (0x11) without START_RESUME, injecting 0x07 first";
1497+
uint8_t startSimulation[] = {FTMS_START_RESUME};
1498+
writeCharacteristic(startSimulation, sizeof(startSimulation), "injectWrite [D500V2 workaround: start simulation 0x07]", false, true);
1499+
awaiting_start_simulation_after_request_control = false;
1500+
}
1501+
}
1502+
14801503
// handling gears
14811504
if (b.at(0) == FTMS_SET_INDOOR_BIKE_SIMULATION_PARAMS && (zwiftPlayService == nullptr || !gears_zwift_ratio)) {
14821505
double min_inclination = settings.value(QZSettings::min_inclination, QZSettings::default_min_inclination).toDouble();
@@ -1684,6 +1707,9 @@ void ftmsbike::deviceDiscovered(const QBluetoothDeviceInfo &device) {
16841707
ergModeSupported = false;
16851708
max_resistance = 32;
16861709
DOMYOS = true;
1710+
} else if (bluetoothDevice.name().toUpper().startsWith("D500V2")) {
1711+
qDebug() << QStringLiteral("D500V2 found - enabling workaround for start simulation command");
1712+
D500V2 = true;
16871713
} else if ((bluetoothDevice.name().toUpper().startsWith("3G Cardio RB"))) {
16881714
qDebug() << QStringLiteral("_3G_Cardio_RB found");
16891715
_3G_Cardio_RB = true;

src/devices/ftmsbike/ftmsbike.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ class ftmsbike : public bike {
135135
bool resistance_received = false;
136136
inclinationResistanceTable _inclinationResistanceTable;
137137

138+
// D500V2 workaround: track if we're awaiting start simulation command after request control
139+
bool awaiting_start_simulation_after_request_control = false;
140+
138141
bool DU30_bike = false;
139142
bool ICSE = false;
140143
bool DOMYOS = false;
144+
bool D500V2 = false;
141145
bool _3G_Cardio_RB = false;
142146
bool SCH_190U = false;
143147
bool SCH_290R = false;

0 commit comments

Comments
 (0)