Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

You are here: Forum Home → ANT+ Forums → ANT+ Fitness Equipment → Thread

   

Bit numbering - Documentation

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

Hi,

I would like a clarification from the documentation.
When it is said "Bit 0 in a byte", does it refer to the left bit (MSB) or the right bit (LSB)?
http://en.wikipedia.org/wiki/Bit_numbering

Trying to figure in order to correctly interpret a "Lap toogle" from the FE-C trainer profile.
page 45 of 96 of "D000001231_-_ANT+_Device_Profile_-_Fitness_Equipment_-_Rev_4.1.pdf"
Thank you!

// Detect if lap toogle activated 
    
if (!lapToogleSet{
        lapToogleValue 
= ((stMessage.aucData[8] >> 7)  & 0x01);
        
lapToogleSet true;
    
}
    
else {
        bool newLapToogleValue 
= ((stMessage.aucData[8] >> 7)  & 0x01);
        if (
newLapToogleValue != lapToogleValue{
            qDebug
() << "NEW LAP!";
            
emit lapChanged();
            
lapToogleValue newLapToogleValue;
        
}
    } 
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

edited      

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

Nevermind, I found that the left most bit is 0 and the right one is 7 while experimenting with the values below and the simulator.
Posted too fast again, thanks ANT!

bool powerMeasurementCalibrationRequired = ((stMessage.aucData[7] >> 4)  & 0x01);  //Bicycle power measurement (i.e. Zero Offset) calibration required
        
bool resistanceCalibrationRequired = ((stMessage.aucData[7] >> 5)  & 0x01);  //Resistance calibration (i.e. Spin-Down Time) required
        
bool userConfigurationRequired = ((stMessage.aucData[7] >> 6)  & 0x01);  //User configuration required 
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com

Avatar
RankRankRankRank

Total Posts: 296

Joined 0

PM

????

Bits are [usually} numbered from the least signicant one. I.e. Bit 0 is 0x01, Bit 1 is 0x02.
After decades in IT business I never found it done the other way round.

Btw, byte numbering in multi-byte data types is another thing - there are two ways to do it: "Big Endian" or "Little Endian".
Cheers,
OMB      
Avatar
RankRankRankRank

Total Posts: 123

Joined 2013-10-07

PM

Hey thanks for the reply,

That's what you get for doing Java and C++ straight, never learned C properly with bit shift operator..

In case this help someone:
bool userConfigurationRequired = ((stMessage.aucData[7] >> 6) & 0x01);
check if the bit #6 (user configuration bit) from Byte 7 is on or off.
My Byte numbering is different from ANT doc. (Byte 6 doc = Byte 7) since I add channel number at the start of each message.
https://www.dropbox.com/s/aype3k6nyoaeee1/bitFinding.png?dl=0



I can get a single bit using the above method, but not sure how to get a "range of bits" from a byte.
I used this workaround for now..

/// FE State Bit Field - Present in all message /////////////////////////////////////
    /// 0 Reserved 
    /// 1 ASLEEP (OFF)
    /// 2 READY
    /// 3 IN_USE
    /// 4 FINISHED (PAUSED)
    /// 5-7 Reserved. Do not send or interpret
    
int feState 0;

    
bool fourValue = ((stMessage.aucData[8] >> 6)  & 0x01); //2^2
    
bool twoValue  = ((stMessage.aucData[8] >> 5)  & 0x01); //2^1
    
bool oneValue  = ((stMessage.aucData[8] >> 4)  & 0x01); //2^0

    
if (fourValue)
        
feState += 4;
    if (
twoValue)
        
feState += 2;
    if (
oneValue)
        
feState += 1
     

Signature

——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com