Skip to content

Commit

Permalink
Domyos Woodrower #1963
Browse files Browse the repository at this point in the history
  • Loading branch information
cagnulein committed Jan 8, 2024
1 parent bd0dd1c commit 1882862
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/domyosrower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,16 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte

if (!Flags.moreData) {

if(index >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}
Cadence = ((uint8_t)newValue.at(index)) / cadence_divider;

if(index + 2 >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}
StrokesCount =
(((uint16_t)((uint8_t)newValue.at(index + 2)) << 8) | (uint16_t)((uint8_t)newValue.at(index + 1)));

Expand All @@ -446,12 +454,20 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte
if (Flags.avgStroke) {

double avgStroke;
if(index >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}
avgStroke = ((double)(uint16_t)((uint8_t)newValue.at(index))) / cadence_divider;
index += 1;
emit debug(QStringLiteral("Current Average Stroke: ") + QString::number(avgStroke));
}

if (Flags.totDistance) {
if(index + 2 >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}
Distance = ((double)((((uint32_t)((uint8_t)newValue.at(index + 2)) << 16) |
(uint32_t)((uint8_t)newValue.at(index + 1)) << 8) |
(uint32_t)((uint8_t)newValue.at(index)))) /
Expand All @@ -466,6 +482,11 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte

if (Flags.instantPace) {

if(index + 1 >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}

double instantPace;
instantPace =
((double)(((uint16_t)((uint8_t)newValue.at(index + 1)) << 8) | (uint16_t)((uint8_t)newValue.at(index))));
Expand All @@ -479,6 +500,11 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte

if (Flags.avgPace) {

if(index + 1>= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}

double avgPace;
avgPace =
((double)(((uint16_t)((uint8_t)newValue.at(index + 1)) << 8) | (uint16_t)((uint8_t)newValue.at(index))));
Expand All @@ -487,6 +513,11 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte
}

if (Flags.instantPower) {
if(index + 1 >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}

double watt =
((double)(((uint16_t)((uint8_t)newValue.at(index + 1)) << 8) | (uint16_t)((uint8_t)newValue.at(index))));
index += 2;
Expand All @@ -495,6 +526,10 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte
}

if (Flags.avgPower) {
if(index + 1 >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}

double avgPower;
avgPower =
Expand All @@ -504,6 +539,10 @@ void domyosrower::characteristicChanged(const QLowEnergyCharacteristic &characte
}

if (Flags.resistanceLvl) {
if(index + 1 >= newValue.length()) {
qDebug() << "index out of range" << index;
return;
}
Resistance =
((double)(((uint16_t)((uint8_t)newValue.at(index + 1)) << 8) | (uint16_t)((uint8_t)newValue.at(index))));
emit resistanceRead(Resistance.value());
Expand Down

0 comments on commit 1882862

Please sign in to comment.