⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 klcinterface.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
				case klcKeySPEED6:
					msg->event = speed_dial_key_event;
					msg->digit = 6;
					break;

				case klcKeySPEED7:
					msg->event = speed_dial_key_event;
					msg->digit = 7;
					break;

				case klcKeySPEED8:
					msg->event = speed_dial_key_event;
					msg->digit = 8;
					break;

				case klcKeySPEED9:
					msg->event = speed_dial_key_event;
					msg->digit = 9;
					break;

				case klcKeySPEED10:
					msg->event = speed_dial_key_event;
					msg->digit = 10;
					break;

				default:
					/* Uncomment to determine key matrix values: 
					if(keypress == klcKeyNDEF)
						printf("Undefined Key pressed, need to modify klcLkpTbl in klc.c to define it\n");
					else
						printf("Key pressed, value = %d\n",keypress);
					*/
					break;
			}

			keyLongPressEvent=msg->event;
			keyLongPress=msg->digit;
			keyPressFlag=1;
			wait_time = 150;
#ifndef BOOT_ROM_ONLY
			if(( tone != null_dtmf_tone ) && ( handset_up || on_speakerphone))
			{
				/* dial-digit-tone-disconnect */
				/* If the tone is playing and it has to be resumed, 
				after the DTMF digits are played, 
				resume the tone.
				*/
				if(tone_playing != null_tone)
					tone_tobe_resumed = tone_playing;
				else
					tone_tobe_resumed = null_tone;

				StopTone(); 
				PlayDTMF( tone );				
			}
#endif
		} 
		else
		{
#ifndef BOOT_ROM_ONLY
			if( (handset_up || on_speakerphone) && (!tone_enabled) ) 
				StopTone();

			/* dial-digit-tone-disconnect */
			/* resume the tone */
			if (tone_tobe_resumed == ringback_tone)
			{
				tone_playing = tone_tobe_resumed;
				PlayTone (tone_tobe_resumed);
				tone_tobe_resumed = null_tone;
			}
#endif
		}

		if( msg->event != null_event )
		{
			loopCounter = 0;
			if (MQSend ((char*)msg, NO_WAIT) == -1)
			{
				while (loopCounter++ < 10)
				{
					taskDelay(10);
					if (MQSend ((char*)msg, NO_WAIT) != -1) /* resend message */
					{
						break;
					}
				}				
				if (loopCounter >= 10)
				{
					fprintf(stderr, "KeyLampMonitor: Could not get buffer after 10 tries.\n");
					MQBufFree((char*)msg);
				}
			}
			loopCounter = 0;
			while (((msg = (NonWrapperMsg *) MQBufGet()) == NULL) && loopCounter++ < 10)
			{
				taskDelay(10);
			}
#ifndef INTERFACE_TERSE	
			if (loopCounter >= 10)
				fprintf(stderr, "KeyLampMonitor: Could not get buffer after 10 tries.\n");
#endif
		}
	}
}

/***************************************************************************
 *
 *  SetLed( int led, led_blink_type blink )
 *
 *  Arguments
 *      Input: Nothing
 *
 *  Returns:   Nothing
 *
 *  Description:
 *  1. Open keylamp driver if not already open
 *  2. Write new blink type to led
 *
 **************************************************************************/ 

void SetLed( int led, led_blink_type blink )
{
    char    cadence_val;

    switch( blink ){
        case led_off:
            cadence_val = 0;
            break;
        case led_wink:
            cadence_val = 1;
            break;
        case led_inverse_wink:
            cadence_val = 2;
            break;
        case led_flash:
            cadence_val = 4;
            break;
        case led_inverse_flash:
            cadence_val = 3;
            break;
        case led_flutter:
            cadence_val = 5;
            break;
        case led_broken_flutter:
            cadence_val = 6;
            break;
        case led_steady_on:
            cadence_val = 7;
            break;
        default:
            break;
    }

    if( klcWriteLed( led, cadence_val ) == ERROR ){
#ifndef INTERFACE_TERSE
        fprintf( stderr, "SetLed: Failure writing led cadence value.\n" );
#else
		;
#endif /* INTERFACE_TERSE */
    }
} 

/* offhook-reboot-ringing*/
/* This method is called from the Application layer. It calls the klcCheckOffHook() of the KLC module to get the status of the switch. If the off-hook condition is detected, post a message to the application with event as "off-hook".
 */

void ScanForOffHook(void)
{

	NonWrapperMsg   *msg;
	int loopCounter;

	/* check for the off-hook condition at the time of boot up. 
	* this will be enquired from the klc 
	*/
	if (TRUE == klcCheckOffHook())
	{
		/*
		* Get a buffer for sending data to the Application.
		*/
		if ((msg = (NonWrapperMsg *) MQBufGet()) == NULL)
		{
			return;
		}

		msg->event = local_off_hook_event;
		
		loopCounter = 0;
		if (MQSend ((char*)msg, NO_WAIT) == -1)
		{
			while (loopCounter++ < 10)
			{
				taskDelay(10);
				if (MQSend ((char*)msg, NO_WAIT) != -1) /* resend message */
				{
					break;
				}
			}			
			if (loopCounter >= 10)
			{
				fprintf(stderr, "KeyLampMonitor: Could not get buffer after 10 tries.\n");
				MQBufFree((char*)msg);
			}
		}
	}
}


#ifdef PPA
/*===========================================================================*
 * function.... PPAInterfaceInit()
 * author(s)... msingh
 * date........ 4.10.2003
 * purpose..... This function is used to initialize the PPA Interface application
 *               
 *
 * parameter... None
 * returns..... None
 * comment..... This function spawns a daemon task, 
 *===========================================================================*/
static void PPAInterfaceInit()
{
   int   PPAInterfaceTID;

   /* Spawn a task that will run the Daemon */
   PPAInterfaceTID = taskSpawn ("PPAInterfaceDaemon ", 171, 0, 6004,  (FUNCPTR)PPAInterfaceDaemon, 0,0,0,0,0,0,0,0,0,0);

   if (PPAInterfaceTID < 0)
   {
	  printf("\n !!! ERROR: PPAInterfaceInit - Could not spawn task PPAInterfaceDaemon !!!\n\r");
   }

}
/*===========================================================================*
 * function.... PPAInterfaceDaemon()
 * author(s)... msingh
 * date........ 04.09.2003
 * purpose..... Provide reading cpability from the port and initiate
 *              the processing of it.At a time read one line
 *              and initiate its processing
 *
 * parameter... None
 * returns..... Nothing
 * comment..... None
 *===========================================================================*/
static void PPAInterfaceDaemon (void)
{
   int nextDigit = 0;
   int digitCnt;
   int value = 0;
   int i;
   int j;
   for(;;)
   {
      taskDelay(10);
	  /* code has been written this way because offHook - */
	  /* - and onHook values can be set from the vxWorks shell only  */
      if(offHook)
	  {	      			   
		  PPAInterfacePut("offHook");
		  offHook = 0;
		  taskDelay(5);
		   dtmfDigitEnable = 1; 
	  }
	  else if (onHook)
	  {	      			   
		  PPAInterfacePut("onHook");     		               
		  onHook = 0;
	  }
      else if (dtmfDigitEnable)
	  {
		   ppaDtmfEnable();

		  for(digitCnt=0;  digitCnt<MAX_NUM_DIGIT; digitCnt++)
		  {
			  if(digitCnt == 1)
			  {
                StopTone();
			  }

			  do{
		          value = getDtmfDigit(dtmfDigitTbl); 
			  }while(value != 1);

             value = 0;

             for(i=0; i<4;i++)
			 {
				 dtmfDigitCollectTbl[i+nextDigit] = dtmfDigitTbl[i];
			 }			 
			 nextDigit +=4;
		  }	
	
		  dtmfDigitTable();
		  switch(ppaChannelNum)
		  {
			   case 0x0000:
	              PPAInterfacePut(&dstinationAddrTbl[0][0]);				  
	              break;
	           case 0x0001:
	              PPAInterfacePut(&dstinationAddrTbl[1][0]);				  
	              break;
	           case 0x0002:
	              PPAInterfacePut(&dstinationAddrTbl[2][0]);				  
	              break;
	           case 0x0003:
	              PPAInterfacePut(&dstinationAddrTbl[3][0]);				  				 
	              break;
			   default:
				   break;
		  } 
		  dtmfDigitEnable = 0;
	      dtmfDigitDisable = 1;
          nextDigit = 0;		 
	  }
	  else if (dtmfDigitDisable)
	  {    
		   ppaDtmfDisable () ;
		  dtmfDigitDisable = 0;
	  }
	} /* for */
}

/*===================================================================*
* function.... PPAInterfacePut
*
* author(s)... msingh
* date........ 04.09.2003
* purpose..... To process the incomming cmd.
*
* parameter...
* Parameter... None
* Returns..... None
* Comments.... None
*====================================================================*/
static void  PPAInterfacePut(char *readBuff)
{
      
    int  count;
	int  ipCnt;
	char ipVal = '1';
	char keyVal;
	int  callSetUp = 0;
	klcdatatype      klcdata;
    char ipAddr[12];


	/* set the flag */

    if(!(strcmp("offHook", readBuff)))
    {
       if(PPAKlcInterfaceQId)
       {
		  klcdata.keypress = klcKeyHOOK_UP;
          klcdata.tag = KLC_PRESSED;
          msgQSend(PPAKlcInterfaceQId, (char*) &klcdata, sizeof(klcdata), NO_WAIT, MSG_PRI_NORMAL);	  
       }  
    }
	else if(!(strcmp("onHook", readBuff)))
    {
       if(PPAKlcInterfaceQId)
       {
		  klcdata.keypress = klcKeyHOOK_DOWN;
          klcdata.tag = KLC_PRESSED;
          msgQSend(PPAKlcInterfaceQId, (char*) &klcdata, sizeof(klcdata), NO_WAIT, MSG_PRI_NORMAL);		  		 
       }  
    }
	else if(!(strcmp("redial", readBuff)))
    {
       if(PPAKlcInterfaceQId)
       {
		  klcdata.keypress = klcKeyREDIAL;
          klcdata.tag = KLC_PRESSED;
          msgQSend(PPAKlcInterfaceQId, (char*) &klcdata, sizeof(klcdata), NO_WAIT, MSG_PRI_NORMAL);		  		 
       }  
    }
	else if (ipVal == *readBuff)
	{
		  for (ipCnt=0; ipCnt<12; ipCnt++)
		  {
             ipAddr[ipCnt] = *readBuff++;
		  }
	      klcdata.tag = KLC_PRESSED; 
		  klcdata.keypress =  klcKeySTAR;
          msgQSend(PPAKlcInterfaceQId, (char*) &klcdata, sizeof(klcdata), NO_WAIT, MSG_PRI_NORMAL);

		  for (count=0; count<12; count++)
		  {
               klcdata.tag = KLC_PRESSED; 
			   keyVal =  ipAddr[count];               
			   switch(keyVal)
			   {
	              case '0':
	              klcdata.keypress  = klcKey0;				  
	              break;
	              case '1':
	              klcdata.keypress  = klcKey1;				 
	              break;
	              case '2':
	              klcdata.keypress  = klcKey2;				
	              break;
	              case '3':
	              klcdata.keypress  = klcKey3;				 
	              break;
	              case '4':
	              klcdata.keypress  = klcKey4;				 
	              break;
	              case '5':
	              klcdata.keypress  = klcKey5;				 
	              break;
	              case '6':
	              klcdata.keypress  = klcKey6;				
	              break;
	              case '7':
	              klcdata.keypress  = klcKey7;		
	              break;
	              case '8':
	              klcdata.keypress  = klcKey8;		
	              break;
	              case '9':
	              klcdata.keypress  = klcKey9;			
	              break;
			   }  /* switch */
			   printf("\nkeyVal = %x \n\r", keyVal);
			 msgQSend(PPAKlcInterfaceQId, (char*) &klcdata, sizeof(klcdata), NO_WAIT, MSG_PRI_NORMAL);			
		  } /* for */  
	}  /* ip */ 
}

static void dtmfDigitTable(void)
{
	    int digitCnt;
    	int portNumber;
	    int portFactor;
		int channelNumber;
	    int channelFactor = 0;
        int m;
	    int n;
        ushort destDigit;
        ushort digitVal;
	

	for(portNumber = 0; portNumber < (MAX_NUM_DIGIT*PORT_FACTOR); portNumber +=MAX_NUM_DIGIT)
	{
	   portFactor = portNumber;
	   for(digitCnt = 0; digitCnt<MAX_NUM_DIGIT; digitCnt++, portFactor +=4 )
	   {
			destinationDigitTbl[digitCnt+portNumber] = (dtmfDigitCollectTbl[portFactor] >> 16);
	   }
	 }


	for(channelNumber = 0; channelNumber<PORT_FACTOR; channelNumber++, channelFactor +=13)
	{
	   for(digitVal = 0; digitVal<MAX_NUM_DIGIT; digitVal++)
	   {

		   	switch( destinationDigitTbl[channelFactor++])
			{
				case 0x11:
	              dstinationAddrTbl[channelNumber][digitVal]  = '1';				  
	              break;
	            case 0x12:
	              dstinationAddrTbl[channelNumber][digitVal]  = '2';				 
	              break;
	            case 0x14:
	              dstinationAddrTbl[channelNumber][digitVal]  = '3';				
	              break;
	            case 0x21:
	              dstinationAddrTbl[channelNumber][digitVal]  = '4';				 
	              break;
	            case 0x22:
	              dstinationAddrTbl[channelNumber][digitVal]  = '5';				 
	              break;
	            case 0x24:
	              dstinationAddrTbl[channelNumber][digitVal]  = '6';				 
	              break;
	            case 0x41:
	              dstinationAddrTbl[channelNumber][digitVal]  = '7';				
	              break;
	            case 0x42:
	              dstinationAddrTbl[channelNumber][digitVal]  = '8';		
	              break;
	            case 0x44:
	              dstinationAddrTbl[channelNumber][digitVal]  = '9';		
	              break;
	            case 0x82:
	              dstinationAddrTbl[channelNumber][digitVal]  = '0'; 			
	              break;			
			}		       
	   }
	   dstinationAddrTbl[channelNumber][digitCnt] = '\0';
	}
}
#endif /* #ifdef PPA */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -