From c17c5488bbec9eb3f5bda75eefba70b697360451 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 6 Mar 2011 21:16:04 +0000 Subject: [PATCH] Native ANT+ Part 2 - tweaks Couple of little tweaks to the Native ANT support. Firstly, data channels such as watts, hr and cadence are now rounded to an integer (lots of grid lines in ride plot looked nasty). Secondly, basic support for calibration messages; this has been limited to SRM messages, but will add support for other devices as we start to debug them. Part 3 of this work is still pending, this patch only contains adjustments to part 2. I suspect there will be further adjustments as we squash bugs for Quarq and PT users. --- src/ANT.h | 1 + src/ANTChannel.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++- src/ANTMessage.cpp | 46 +++++++++++++++++++++++++++++++++++----- src/ANTMessage.h | 3 ++- src/RealtimeData.cpp | 6 +++--- 5 files changed, 96 insertions(+), 10 deletions(-) diff --git a/src/ANT.h b/src/ANT.h index d4262e84b..07e282f61 100644 --- a/src/ANT.h +++ b/src/ANT.h @@ -199,6 +199,7 @@ static inline double get_timestamp( void ) { #define ANT_QUARQ_FREQUENCY 61 #define ANT_SPORT_CALIBRATION_MESSAGE 0x01 +#define ANT_SPORT_SRM_CALIBRATIONID 0x10 #define ANT_SPORT_AUTOZERO_OFF 0x00 #define ANT_SPORT_AUTOZERO_ON 0x01 #define ANT_SPORT_CALIBRATION_REQUEST_MANUALZERO 0xAA diff --git a/src/ANTChannel.cpp b/src/ANTChannel.cpp index 691611495..6d49be640 100755 --- a/src/ANTChannel.cpp +++ b/src/ANTChannel.cpp @@ -285,7 +285,53 @@ void ANTChannel::broadcastEvent(unsigned char *ant_message) case CHANNEL_TYPE_FAST_QUARQ_NEW: // what kind of power device is this? - switch(antMessage.power_type) { + switch(antMessage.data_page) { + + case ANT_SPORT_CALIBRATION_MESSAGE: + { + // Always ack calibs unless they are acks too! + if (antMessage.data[6] != 0xAC) { + antMessage.data[6] = 0xAC; + qDebug()<<"sending calibration ack..."; + parent->sendMessage(antMessage); + } + + // each device sends a different type + // of calibration message... + switch (antMessage.calibrationID) { + + case ANT_SPORT_SRM_CALIBRATIONID: + + switch (antMessage.ctfID) { + + case 0x01: // offset + // if we're getting calibration messages then + // we should be coasting, so power and cadence + // will be zero + srm_offset = antMessage.srmOffset; + parent->setWatts(0); + parent->setCadence(0); +qDebug()<<"got new offset!"<= 4) { // 4 messages on an SRM parent->setWatts(0); parent->setCadence(0); diff --git a/src/ANTMessage.cpp b/src/ANTMessage.cpp index 984f19d15..e6b59eb38 100755 --- a/src/ANTMessage.cpp +++ b/src/ANTMessage.cpp @@ -372,6 +372,8 @@ qDebug()<<"request message"; qDebug()<<"broadcast data, channel="<antChannel[message[3]]->channel_type) { @@ -398,11 +400,11 @@ qDebug()<<"broadcast data, channel="<watts = watts; + this->watts = (int)watts; } void RealtimeData::setHr(double hr) { - this->hr = hr; + this->hr = (int)hr; } void RealtimeData::setTime(long time) { @@ -52,7 +52,7 @@ void RealtimeData::setWheelRpm(double wheelRpm) } void RealtimeData::setCadence(double aCadence) { - cadence = aCadence; + cadence = (int)aCadence; } void RealtimeData::setLoad(double load) {