int main(int argc, char *argv[]) { if(SIG_ERR == signal(SIGINT, clean_exit)) { perror("signal"); exit(1); } int fd = ANT_OpenSerial("/dev/ttyUSB0"); if(-1 == fd) { perror("Failed to open serial connection"); exit(1); } ANT_SetNetworkKey(fd, 0, NETWORK_KEY); read_response(fd); ANT_AssignChannel(fd, 0, ANT_RX_CHANNEL, 0, 0); read_response(fd); ANT_SetChannelID(fd, 0, 0, 0, 0x78, 0); read_response(fd); ANT_SetRFFrequency(fd, 0, ANT_PLUS_FREQUENCY); read_response(fd); ANT_SetChannelPeriod(fd, 0, ANT_PLUS_PERIOD_102); read_response(fd); ANT_OpenRXScanMode(fd); read_response(fd); read_loop(fd); ANT_RequestMessage(fd, 0, SET_CHANNEL_ID); do_exit = 0; read_loop(fd); //ANT_UnassignChannel(fd, 0); //read_response(fd); ANT_CloseChannel(fd, 0); read_response(fd); close(fd); return 0; }
//////////////////////////////////////////////////////////////////////////// // HandleDataMessages // // \return: N/A. //////////////////////////////////////////////////////////////////////////// BOOL HandleDataMessages(UCHAR* pucBuffer_, ANTPLUS_EVENT_RETURN* pstEventStruct_) { BOOL bTransmit = FALSE; static UCHAR ucOldPage; UCHAR ucPage = pucBuffer_[BUFFER_INDEX_MESG_DATA]; pstEventStruct_->eEvent = ANTPLUS_EVENT_PAGE; pstEventStruct_->usParam1 = HRM_PAGE_0; switch(eThePageState) { case STATE_INIT_PAGE: { eThePageState = STATE_STD_PAGE; break; } case STATE_STD_PAGE: { // Check if the page if changing, if yes // then move to the next state, otherwise // only interpret page 0 if(ucOldPage == ucPage) break; else eThePageState = STATE_EXT_PAGE; // INTENTIONAL FALLTHROUGH !!! } case STATE_EXT_PAGE: { switch(ucPage & ~TOGGLE_MASK) { case HRM_PAGE_1: { HRMPage1_Data* pstPage1Data = HRMRX_GetPage1(); pstPage1Data->ulOperatingTime = (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+1]; pstPage1Data->ulOperatingTime |= (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+2] << 8; pstPage1Data->ulOperatingTime |= (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+3] << 16; pstPage1Data->ulOperatingTime *= 2; pstEventStruct_->eEvent = ANTPLUS_EVENT_PAGE; pstEventStruct_->usParam1 = HRM_PAGE_1; break; } case HRM_PAGE_2: { HRMPage2_Data* pstPage2Data = HRMRX_GetPage2(); pstPage2Data->ucManId = pucBuffer_[BUFFER_INDEX_MESG_DATA + 1]; pstPage2Data->ulSerialNumber = (ULONG)usDeviceNumber; pstPage2Data->ulSerialNumber |= (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+2] << 16; pstPage2Data->ulSerialNumber |= (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+3] << 24; pstEventStruct_->eEvent = ANTPLUS_EVENT_PAGE; pstEventStruct_->usParam1 = HRM_PAGE_2; break; } case HRM_PAGE_3: { HRMPage3_Data* pstPage3Data = HRMRX_GetPage3(); pstPage3Data->ucHwVersion = (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+1]; pstPage3Data->ucSwVersion = (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+2]; pstPage3Data->ucModelNumber = (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+3]; pstEventStruct_->eEvent = ANTPLUS_EVENT_PAGE; pstEventStruct_->usParam1 = HRM_PAGE_3; break; } case HRM_PAGE_4: { HRMPage4_Data* pstPage4Data = HRMRX_GetPage4(); pstPage4Data->usPreviousBeat = (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+2]; pstPage4Data->usPreviousBeat |= (ULONG)pucBuffer_[BUFFER_INDEX_MESG_DATA+3] << 8; pstEventStruct_->eEvent = ANTPLUS_EVENT_PAGE; pstEventStruct_->usParam1 = HRM_PAGE_4; break; } case HRM_PAGE_0: { // Handled above and below, so don't fall-thru to default case break; } default: { pstEventStruct_->eEvent = ANTPLUS_EVENT_UNKNOWN_PAGE; break; } } break; } } ucOldPage = ucPage; DecodeDefault( &pucBuffer_[BUFFER_INDEX_MESG_DATA+4] ); if(usDeviceNumber == 0) { if(ANT_RequestMessage(ucAntChannel, MESG_CHANNEL_ID_ID)) bTransmit = TRUE; } return(bTransmit); }