You are here: Forum Home → ANT+ Forums → ANT+ Bike Power → Thread
/// decodePowerMessage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Power_Controller::decodePowerMessage(ANT_MESSAGE stMessage) {
UCHAR ucDataOffset = MESSAGE_BUFFER_DATA2_INDEX; // For most data messages
UCHAR ucPage = stMessage.aucData[ucDataOffset];
switch (ucPage) {
/// 0x10 - Power Main Data Page - Standard Power Only-------------------------------------------------------------------
case (UCHAR)0x10:
{
pstPage16Data.ucPOEventCount = stMessage.aucData[ucDataOffset+1];
pstPage16Data.ucReserveByte2 = stMessage.aucData[ucDataOffset+2]; // Pedal percentage
pstPage16Data.ucPOInstantCadence = stMessage.aucData[ucDataOffset+3];
pstPage16Data.usPOAccumulatedPower = (USHORT)stMessage.aucData[ucDataOffset+4];
pstPage16Data.usPOAccumulatedPower |= (USHORT)(stMessage.aucData[ucDataOffset+5]<<8);
pstPage16Data.usPOInstantPower = (USHORT)stMessage.aucData[ucDataOffset+6];
pstPage16Data.usPOInstantPower |= (USHORT)(stMessage.aucData[ucDataOffset+7]<<8);
if (firstPage0x10Now) {
firstPage0x10Now = false;
ucPOEventCountPrev = pstPage16Data.ucPOEventCount;
usPOAccumulatedPowerPrev = pstPage16Data.usPOAccumulatedPower;
}
else { /// Calculate Average Power
ulPOEventCountDiff = (ULONG)((pstPage16Data.ucPOEventCount - ucPOEventCountPrev) & MAX_UCHAR);
ulPOAccumulatedPowerDiff = (ULONG)((pstPage16Data.usPOAccumulatedPower - usPOAccumulatedPowerPrev) & MAX_USHORT);
if (ulPOEventCountDiff==0)
{
/// TODO EMIT POWER, show 0 value?
// ucWTZeroPowerCheck++;
// if(ucWTZeroPowerCheck >= BPSRX_MAX_REPEATS) // Event sync zero speed condition
// {
// }
}
else
{
stCalculatedStdPowerData.ulAvgStandardPower = ulPOAccumulatedPowerDiff/ulPOEventCountDiff;
ucPOEventCountPrev = pstPage16Data.ucPOEventCount;
usPOAccumulatedPowerPrev = pstPage16Data.usPOAccumulatedPower;
}
if (pstPage16Data.ucReserveByte2 != (UCHAR)0xFF) {
qDebug() << "pedal percent SUPPORTED:" << pstPage16Data.ucReserveByte2; //To calculate : p28 doc
}
// qDebug() << "INSTANT POWER NOW: "<< pstPage16Data.usPOInstantPower;
// qDebug() << "CALCULATED POWER NOW: "<< stCalculatedStdPowerData.ulAvgStandardPower;
// qDebug() << "CADENCE NOW:"<< pstPage16Data.ucPOInstantCadence;
/// EMIT POWER
if (usingForPower) {
emit powerChanged(stCalculatedStdPowerData.ulAvgStandardPower);
}
/// EMIT CADENCE
if (usingForCadence) {
cadenceChanged(pstPage16Data.ucPOInstantCadence);
}
}
break;
}
/// 0x11 - Standard Wheel Torque Main Data Page------------------------------------------------------------------------
case (UCHAR)0x11:
{
///TODO : TEST (SIMULANT DOESNT PROVIDE THIS PAGE)
// Wheel Torque (WT) Main Data Page
pstPage17Data.ucWTEventCount = stMessage.aucData[ucDataOffset+1];
pstPage17Data.ucWTWheelTicks = stMessage.aucData[ucDataOffset+2];
pstPage17Data.ucWTInstantCadence = stMessage.aucData[ucDataOffset+3];
pstPage17Data.usWTAccumulatedWheelPeriod = (USHORT)stMessage.aucData[ucDataOffset+4];
pstPage17Data.usWTAccumulatedWheelPeriod |= (USHORT)(stMessage.aucData[ucDataOffset+5]<<8);
pstPage17Data.usWTAccumulatedTorque = (USHORT)stMessage.aucData[ucDataOffset+6];
pstPage17Data.usWTAccumulatedTorque |= (USHORT)(stMessage.aucData[ucDataOffset+7]<<8);
if (firstPage0x11Now) {
firstPage0x11Now = false;
bWTFirstPageCheck=0;
...
default:
{
qDebug() << "to implement...page:" << hex << ucPage;
break;
}
}
/// TODO:
/// Common page - in a external class -processCommonMessage(stMessage)
/// 0x50 - Common data- Manufacturer’s Information
/// 0x51 - Common data- Product Information
/// 0x52 - Common data- Battery Voltage
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
Hi,
If you use the Power Sensor (Wheel Torque) simulator in SimulANT+ then this page will be provided. Power-only sensors don't send this page.
Kat
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
Are you using the latest version?
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com