Exemplo n.º 1
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);
}
Exemplo n.º 2
0
GSM_Error GSM_DecodeSMSFrameText(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
{
	int		off=0;	 	/* length of the User Data Header */
	int 		w,i;
	unsigned char	output[161];

	SMS->UDH.Length = 0;
	/* UDH header available */
	if (buffer[Layout.firstbyte] & 64) {
		/* Length of UDH header */
		off = (buffer[Layout.Text] + 1);
		SMS->UDH.Length = off;
		smfprintf(di, "UDH header available (length %i)\n",off);

		/* Copy UDH header into SMS->UDH */
		for (i = 0; i < off; i++) SMS->UDH.Text[i] = buffer[Layout.Text + i];

		GSM_DecodeUDHHeader(di, &SMS->UDH);
	}

	switch (SMS->Coding) {
		case SMS_Coding_Default_No_Compression:
			i = 0;
			do {
				i+=7;
				w=(i-off)%i;
			} while (w<0);
			SMS->Length=buffer[Layout.TPUDL] - (off*8 + w) / 7;
			if (SMS->Length < 0) {
				smfprintf(di, "No SMS text!\n");
				SMS->Length = 0;
				break;
			}
			GSM_UnpackEightBitsToSeven(w, buffer[Layout.TPUDL]-off, SMS->Length, buffer+(Layout.Text+off), output);
			smfprintf(di, "7 bit SMS, length %i\n",SMS->Length);
			DecodeDefault (SMS->Text, output, SMS->Length, TRUE, NULL);
			smfprintf(di, "%s\n",DecodeUnicodeString(SMS->Text));
			break;
		case SMS_Coding_8bit:
			SMS->Length=buffer[Layout.TPUDL] - off;
			memcpy(SMS->Text,buffer+(Layout.Text+off),SMS->Length);
#ifdef DEBUG
			smfprintf(di, "8 bit SMS, length %i\n",SMS->Length);
			DumpMessageText(di, SMS->Text, SMS->Length);
#endif
			break;
		case SMS_Coding_Unicode_No_Compression:
			SMS->Length=(buffer[Layout.TPUDL] - off) / 2;
			DecodeUnicodeSpecialNOKIAChars(SMS->Text,buffer+(Layout.Text+off), SMS->Length);
#ifdef DEBUG
			smfprintf(di, "Unicode SMS, length %i\n",SMS->Length);
			DumpMessageText(di, buffer+(Layout.Text+off), SMS->Length*2);
			smfprintf(di, "%s\n",DecodeUnicodeString(SMS->Text));
#endif
			break;
		default:
			SMS->Length=0;
			break;
	}

	return ERR_NONE;
}