Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

You are here: Forum Home → ANT+ Forums → ANT+ Heart Rate Monitor → Thread

   

toggle bit vs page

Avatar
Rank

Total Posts: 2

Joined 2022-03-15

PM

Hi,

I'm a bit confused after reading the Heart Rate device profile pdf. Is the following interpretation correct?

1. When the page number doesn't change between 2 consecutive messages, then I only decode bytes 1-3 when the toggle bit switched.

2. When the pageNumber changes then I decode bytes 1-3 anyway. Is this right? Or even then I should wait until the toggle bit switches?

if ((lastPageNumber == payload.pageNumber && lastPageChangeToggleBit != payload.pageChangeToggleBit)
    || 
lastPageNumber != payload.pageNumber // should I keep this line or remove it?
    
{
   decodeBytes123
(payload);
}
decodeBytes4567
(payload);
lastPageNumber payload.pageNumber;
lastPageChangeToggleBit payload.pageChangeToggleBit

     
RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

toggleBitHasBeenDetected and firstPage are static variables that persists between decodes and are initialized to false and true respectively when you connect to the sensor.
lastPageChangeToggleBit is a static variable that persists between decodes and is initialized to false when you connect to the sensor.

if(!firstPage && !toggleBitHasBeenDetected) {
if(payload.pageChangeToggleBit != lastPageChangeToggleBit) {
toggleBitHasBeenDetected = true;
}
}

if(toggleBitHasBeenDetected) {
decodeBytes123(payload)
}

decodeBytes4567(payload);
lastPageChangeToggleBit = payload.pageChangeToggleBit;
firstPage = false;      

Signature

Ian Haigh

RankRankRankRank

Total Posts: 370

Joined 2012-06-27

PM

The toggle bit is used to detect old sensors that don't encode bytes 0-3 vs new sensors that do. Once it has been observed to change, then you know you are connected to a new sensor and can decode bytes 0-3.      

Signature

Ian Haigh

Avatar
Rank

Total Posts: 2

Joined 2022-03-15

PM

Thanks, Ian, this is clear now. It would be a good idea to update the official doc too. From there I thought I need to wait for a toggle each time I want to interpret bytes 1-3.