You are here: Forum Home → ANT Developers Forums → ANT General Questions → Thread
// If we recieved a data message, display its contents here.
if(bPrintBuffer)
{
if(bDisplay)
{
printf("[x],[x],[x],[x],[x],[x],[x],[x]\n",
stMessage.aucData[ucDataOffset + 0],
stMessage.aucData[ucDataOffset + 1],
stMessage.aucData[ucDataOffset + 2],
stMessage.aucData[ucDataOffset + 3],
stMessage.aucData[ucDataOffset + 4],
stMessage.aucData[ucDataOffset + 5],
stMessage.aucData[ucDataOffset + 6],
stMessage.aucData[ucDataOffset + 7]);
printf("Computed HR %d : \n", stMessage.aucData[ucDataOffset + 7]);
}
else
{
static int iIndex = 0;
static char ac[] = {'|','/','-','\\'};
printf("Rx: %c\r",ac[iIndex++]); fflush(stdout);
iIndex &= 3;
}
}
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
// If we recieved a data message, we decode its content here and display it
if(bPrintBuffer)
{
if(bDisplay)
{
printf("[x],[x],[x],[x],[x],[x],[x],[x]\n",
stMessage.aucData[ucDataOffset + 0],
stMessage.aucData[ucDataOffset + 1],
stMessage.aucData[ucDataOffset + 2],
stMessage.aucData[ucDataOffset + 3],
stMessage.aucData[ucDataOffset + 4],
stMessage.aucData[ucDataOffset + 5],
stMessage.aucData[ucDataOffset + 6],
stMessage.aucData[ucDataOffset + 7]);
// Get the deviceType so we correctly decode the message.
UCHAR ucDeviceType = stMessage.aucData[MESSAGE_BUFFER_DATA13_INDEX];
if (ucDeviceType == 120) {
//TODO: use antplus_heart_rate_monitor_v1.3.0 decoding classes to decode correctly
printf("DECODE HR PAGE...\n");
printf("Computed HR %d : \n", stMessage.aucData[ucDataOffset + 7]);
}
else if (ucDeviceType == 121) {
printf("DECODE S&C PAGE...\n");
}
else if (ucDeviceType == 11) {
printf("DECODE POWER PAGE...\n");
}
else {
printf("Device not support by app...\n");
}
}
...
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
switch(stMessage.aucData[1])
{
case MESG_NETWORK_KEY_ID:
{
if(stMessage.aucData[2] != RESPONSE_NO_ERROR)
{
printf("Error configuring network key: Code 0%d\n", stMessage.aucData[2]);
break;
}
qDebug() << "Network key set";
qDebug() << "Assigning channel...";
UCHAR ucDeviceType = stMessage.aucData[MESSAGE_BUFFER_DATA4_INDEX];
printf("Device Type: %d\n ", ucDeviceType); // return 144, my device is a HR strap (120) ??
//HR
if (ucDeviceType == 120) {
bStatus = pclMessageObject->AssignChannel(0, 0, 0, MESSAGE_TIMEOUT);
}
//S&C
else if (ucDeviceType == 121) {
bStatus = pclMessageObject->AssignChannel(1, 0, 0, MESSAGE_TIMEOUT);
}
//Power
else if (ucDeviceType == 11) {
bStatus = pclMessageObject->AssignChannel(2, 0, 0, MESSAGE_TIMEOUT);
}
else {
bStatus = pclMessageObject->AssignChannel(USER_ANTCHANNEL, 0, 0, MESSAGE_TIMEOUT);
}
break;
}
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
The easiest way to implement connecting to multiple sensors is to set up each channel you open to only acquire each specific device type you need (Device Number - Wildcard, Transmission Type - Wildcard, Device Type - 120 or 121 or 11, etc)
/////////////////////////////////////////////////////////////////////////////
// Message Format
// Messages are in the format:
//
// AX XX YY -------- CK
//
// where: AX is the 1 byte sync byte either transmit or recieve
// XX is the 1 byte size of the message (0-249) NOTE: THIS WILL BE LIMITED BY THE EMBEDDED RECEIVE BUFFER SIZE
// YY is the 1 byte ID of the message (1-255, 0 is invalid)
// ----- is the data of the message (0-249 bytes of data)
// CK is the 1 byte Checksum of the message
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
switch(stMessage.ucMessageID)
{
//RESPONSE MESG
case MESG_RESPONSE_EVENT_ID:
{
//RESPONSE TYPE
switch(stMessage.aucData[1])
{
case MESG_NETWORK_KEY_ID:
{
....
pclMessageObject->SetNetworkKey(USER_NETWORK_NUM, ucNetKey, MESSAGE_TIMEOUT);
////////////////////////////////////////////////////////////////////////////////
// InitANT
//
// Resets the system and starts the test
//
////////////////////////////////////////////////////////////////////////////////
BOOL Hub::InitANT(void)
{
qDebug() << "Init Ant...";
BOOL bStatus;
// Reset system
printf("Resetting module...\n");
bStatus = pclMessageObject->ResetSystem();
DSIThread_Sleep(1000);
// Start the test by setting network key
printf("Setting network key...\n");
UCHAR ucNetKey[8] = USER_NETWORK_KEY;
//TODO: IMPORTANT FIRST MSG HERE
bStatus = pclMessageObject->SetNetworkKey(USER_NETWORK_NUM, ucNetKey, MESSAGE_TIMEOUT);
return bStatus;
}
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com
——————————————————
Free Indoor Cycling Software - https://maximumtrainer.com