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

Garmin ad Raspberry power sensor #1362

Open
wants to merge 5 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
79 changes: 71 additions & 8 deletions src/virtualbike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ using namespace std::chrono_literals;
virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHeartService, uint8_t bikeResistanceOffset,
double bikeResistanceGain) {
Bike = t;

this->noHeartService = noHeartService;
this->bikeResistanceGain = bikeResistanceGain;
this->bikeResistanceOffset = bikeResistanceOffset;
Expand Down Expand Up @@ -92,7 +91,7 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
services << QBluetoothUuid::HeartRate;
}

services << ((QBluetoothUuid::ServiceClassUuid)0xFF00);
// services << ((QBluetoothUuid::ServiceClassUuid)0xFF00);
} else if (ifit) {
services << (QBluetoothUuid(QStringLiteral("00001533-1412-efde-1523-785feabcd123")));

Expand Down Expand Up @@ -196,15 +195,56 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
serviceDataFIT.addCharacteristic(charDataFIT5);
serviceDataFIT.addCharacteristic(charDataFIT6);
} else if (power) {
QLowEnergyCharacteristicData charDataFIT;
charDataFIT.setUuid(
(QBluetoothUuid::CharacteristicType)0x2A00); // FitnessMachineFeatureCharacteristicUuid
QByteArray valueFIT;
valueFIT.append((char)'P'); // average speed, cadence and resistance level supported
valueFIT.append((char)'i'); // heart rate and elapsed time
valueFIT.append((char)'x');
valueFIT.append((char)'e');
valueFIT.append((char)'l'); // resistance and power target supported
valueFIT.append((char)' '); // indoor simulation, wheel and spin down supported
valueFIT.append((char)'6');
valueFIT.append((char)'a');
valueFIT.append((char)0x00);
charDataFIT.setValue(valueFIT);
charDataFIT.setProperties(QLowEnergyCharacteristic::Read);

QLowEnergyCharacteristicData charDataFIT2;
charDataFIT2.setUuid(
(QBluetoothUuid::CharacteristicType)0x2A01); // FitnessMachineFeatureCharacteristicUuid
QByteArray valueFIT2;
valueFIT2.append((char)0x00);
charDataFIT2.setValue(valueFIT2);
charDataFIT2.setProperties(QLowEnergyCharacteristic::Read);

serviceDataFIT.setUuid((QBluetoothUuid::ServiceClassUuid)0x1800); // FitnessMachineServiceUuid
serviceDataFIT.addCharacteristic(charDataFIT);
serviceDataFIT.addCharacteristic(charDataFIT2);

QLowEnergyCharacteristicData charDataFIT3;
charDataFIT3.setUuid(
(QBluetoothUuid::CharacteristicType)0x2A05); // FitnessMachineFeatureCharacteristicUuid
charDataFIT3.setProperties(QLowEnergyCharacteristic::Indicate);
QByteArray descriptor33;
descriptor33.append((char)0x02);
descriptor33.append((char)0x00);
const QLowEnergyDescriptorData clientConfig43(QBluetoothUuid::ClientCharacteristicConfiguration,
descriptor33);
charDataFIT3.addDescriptor(clientConfig43);

serviceEchelon.setUuid((QBluetoothUuid::ServiceClassUuid)0x1801); // FitnessMachineServiceUuid
serviceEchelon.addCharacteristic(charDataFIT3);

QLowEnergyCharacteristicData charData;
charData.setUuid(QBluetoothUuid::CharacteristicType::CyclingPowerFeature);
charData.setProperties(QLowEnergyCharacteristic::Read);
QByteArray value;
value.append((char)0x08); // crank supported
value.append((char)0x00);
value.append((char)0x00); // crank supported
value.append((char)0x00);
value.append((char)0x00);
value.append((char)0x08);
charData.setValue(value);

QLowEnergyCharacteristicData charData2;
Expand All @@ -220,6 +260,7 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
QLowEnergyCharacteristicData charData3;
charData3.setUuid(QBluetoothUuid::CharacteristicType::CyclingPowerMeasurement);
charData3.setProperties(QLowEnergyCharacteristic::Notify | QLowEnergyCharacteristic::Read);
charData3.setValue(valueLocaltion);
QByteArray descriptor;
descriptor.append((char)0x01);
descriptor.append((char)0x00);
Expand All @@ -230,8 +271,8 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
serviceData.setType(QLowEnergyServiceData::ServiceTypePrimary);
serviceData.setUuid(QBluetoothUuid::ServiceClassUuid::CyclingPower);
serviceData.addCharacteristic(charData);
serviceData.addCharacteristic(charData3);
serviceData.addCharacteristic(charData2);
serviceData.addCharacteristic(charData3);
} else {

QLowEnergyCharacteristicData charData;
Expand Down Expand Up @@ -393,6 +434,8 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear

serviceFIT = leController->addService(serviceDataFIT);
} else {
serviceFIT = leController->addService(serviceDataFIT);
service = leController->addService(serviceEchelon);
service = leController->addService(serviceData);
}
}
Expand Down Expand Up @@ -434,10 +477,30 @@ virtualbike::virtualbike(bluetoothdevice *t, bool noWriteResistance, bool noHear
settings.value(QZSettings::bluetooth_relaxed, QZSettings::default_bluetooth_relaxed).toBool();
QLowEnergyAdvertisingParameters pars = QLowEnergyAdvertisingParameters();
if (!bluetooth_relaxed) {
pars.setInterval(100, 100);
}

leController->startAdvertising(pars, advertisingData, advertisingData);
pars.setInterval(30, 50);

QByteArray a;
a.append(0x02);
a.append(0x01);
a.append(0x06);
a.append(0x03);
a.append(0x03);
a.append(0x18);
a.append(0x18);
a.append(0x09);
a.append(0x09);
a.append(0x50);
a.append(0x69);
a.append(0x78);
a.append(0x65);
a.append(0x6c);
a.append(0x20);
a.append(0x36);
a.append(0x61);

advertisingData.setRawData(a);
leController->startAdvertising(pars, advertisingData);

//! [Start Advertising]
}
Expand Down
53 changes: 48 additions & 5 deletions src/virtualtreadmill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ virtualtreadmill::virtualtreadmill(bluetoothdevice *t, bool noHeartService) {
services << QBluetoothUuid::HeartRate;
}

services << ((QBluetoothUuid::ServiceClassUuid)0xFF00);

advertisingData.setServices(services);
//! [Advertising Data]

Expand Down Expand Up @@ -170,6 +168,45 @@ virtualtreadmill::virtualtreadmill(bluetoothdevice *t, bool noHeartService) {
}

if (RSCEnable()) {
QLowEnergyCharacteristicData charDataFIT;
charDataFIT.setUuid((QBluetoothUuid::CharacteristicType)0x2A00); // FitnessMachineFeatureCharacteristicUuid
QByteArray valueFIT;
valueFIT.append((char)'P'); // average speed, cadence and resistance level supported
valueFIT.append((char)'i'); // heart rate and elapsed time
valueFIT.append((char)'x');
valueFIT.append((char)'e');
valueFIT.append((char)'l'); // resistance and power target supported
valueFIT.append((char)' '); // indoor simulation, wheel and spin down supported
valueFIT.append((char)'6');
valueFIT.append((char)'a');
valueFIT.append((char)0x00);
charDataFIT.setValue(valueFIT);
charDataFIT.setProperties(QLowEnergyCharacteristic::Read);

QLowEnergyCharacteristicData charDataFIT2;
charDataFIT2.setUuid((QBluetoothUuid::CharacteristicType)0x2A01); // FitnessMachineFeatureCharacteristicUuid
QByteArray valueFIT2;
valueFIT2.append((char)0x00);
charDataFIT2.setValue(valueFIT2);
charDataFIT2.setProperties(QLowEnergyCharacteristic::Read);

serviceDataFIT.setUuid((QBluetoothUuid::ServiceClassUuid)0x1800); // FitnessMachineServiceUuid
serviceDataFIT.addCharacteristic(charDataFIT);
serviceDataFIT.addCharacteristic(charDataFIT2);

QLowEnergyCharacteristicData charDataFIT3;
charDataFIT3.setUuid((QBluetoothUuid::CharacteristicType)0x2A05); // FitnessMachineFeatureCharacteristicUuid
charDataFIT3.setProperties(QLowEnergyCharacteristic::Indicate);
QByteArray descriptor33;
descriptor33.append((char)0x02);
descriptor33.append((char)0x00);
const QLowEnergyDescriptorData clientConfig43(QBluetoothUuid::ClientCharacteristicConfiguration,
descriptor33);
charDataFIT3.addDescriptor(clientConfig43);

serviceEchelon.setUuid((QBluetoothUuid::ServiceClassUuid)0x1801); // FitnessMachineServiceUuid
serviceEchelon.addCharacteristic(charDataFIT3);

QLowEnergyCharacteristicData charData;
charData.setUuid(QBluetoothUuid::CharacteristicType::RSCFeature);
charData.setProperties(QLowEnergyCharacteristic::Read);
Expand All @@ -191,6 +228,7 @@ virtualtreadmill::virtualtreadmill(bluetoothdevice *t, bool noHeartService) {
QLowEnergyCharacteristicData charData3;
charData3.setUuid(QBluetoothUuid::CharacteristicType::RSCMeasurement);
charData3.setProperties(QLowEnergyCharacteristic::Read | QLowEnergyCharacteristic::Notify);
charData3.setValue(valueLocaltion);
QByteArray descriptor;
descriptor.append((char)0x01);
descriptor.append((char)0x00);
Expand Down Expand Up @@ -232,8 +270,11 @@ virtualtreadmill::virtualtreadmill(bluetoothdevice *t, bool noHeartService) {
Q_ASSERT(leController);
if (ftmsServiceEnable())
serviceFTMS = leController->addService(serviceDataFTMS);
if (RSCEnable())
if (RSCEnable()) {
serviceRSC = leController->addService(serviceDataRSC);
serviceFIT = leController->addService(serviceDataFIT);
service = leController->addService(serviceEchelon);
}
if (noHeartService == false) {
serviceHR = leController->addService(serviceDataHR);
}
Expand All @@ -246,10 +287,12 @@ virtualtreadmill::virtualtreadmill(bluetoothdevice *t, bool noHeartService) {
settings.value(QZSettings::bluetooth_relaxed, QZSettings::default_bluetooth_relaxed).toBool();
QLowEnergyAdvertisingParameters pars = QLowEnergyAdvertisingParameters();
if (!bluetooth_relaxed) {
pars.setInterval(100, 100);
}

leController->startAdvertising(pars, advertisingData, advertisingData);
pars.setInterval(30, 50);

leController->startAdvertising(pars, advertisingData);

//! [Start Advertising]

//! [Provide Heartbeat]
Expand Down
4 changes: 4 additions & 0 deletions src/virtualtreadmill.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ class virtualtreadmill : public virtualdevice {
QLowEnergyService *serviceFTMS = nullptr;
QLowEnergyService *serviceRSC = nullptr;
QLowEnergyService *serviceHR = nullptr;
QLowEnergyService *serviceFIT = nullptr;
QLowEnergyService *service = nullptr;
QLowEnergyAdvertisingData advertisingData;
QLowEnergyServiceData serviceDataFTMS;
QLowEnergyServiceData serviceDataRSC;
QLowEnergyServiceData serviceDataHR;
QLowEnergyServiceData serviceDataFIT;
QLowEnergyServiceData serviceEchelon;
QTimer treadmillTimer;
bluetoothdevice *treadMill;

Expand Down
Loading