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

📄 复件 (2) h323f.cpp

📁 基于h323协议的软phone
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	return null_event;
}

int h323_wait_first_digit_state_to_dead_end_state(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_wait_first_digit_state_to_dead_end_state\n");
	return null_event;
}

int h323_wait_first_digit_state_to_collect_digits_state(s_event* psEvent,
    s_task* psTask)
{
	H323TRACE("action: h323_wait_first_digit_state_to_collect_digits_state\n");
	return null_event;
}

int h323_wait_first_digit_state_to_collect_transfer_digits_state(s_event*
    psEvent, s_task* psTask)
{
	H323TRACE("action: h323_wait_first_digit_state_to_collect_transfer_digits_state\n");
	return null_event;
}

int h323_wait_first_digit_state_to_bidir_voice_state(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_wait_first_digit_state_to_bidir_voice_state\n");
	PreserveLcdMessage = FALSE;
	return null_event;
}

int h323_wait_first_digit_state_to_query_availability_state(s_event* psEvent,
    s_task* psTask)
{
	H323TRACE("action: h323_wait_first_digit_state_to_query_availability_state\n");	
	return null_event;
}

/**
 * 收集、记录号码
 */
int h323_collect_digits_state_digit_event(s_event* psEvent, s_task* psTask)
{
	H323TRACE("action: h323_collect_digits_state_digit_event\n");
	/* 已进入菜单,不接收按键号码,退出事件处理 */
	if (*menu_inuse)
		return null_event;
		
	if (num_digits >= MAX_PHONE_NUMBER_LEN)
		return null_event;

	if (toAddr[0] != '\0')
	{
		memset(toAddr, 0, sizeof(toAddr));		
	}

	msg = (NonWrapperMsg *) psEvent->pMsg;

        if(!gkEnabled)
        { 
	       if ((digitCollectAmount != -1) && (msg->digit > 9 || num_digits == digitCollectAmount))
		       return null_event;

	       if ((digitCollectAmount == -1) && (msg->digit == 10))
		       return null_event;
        }

	digit_set[num_digits] = msg->digit+'0';	
        if (digit_set[num_digits] == '0' + 10)
		digit_set[num_digits] = '*';
	else if (digit_set[num_digits] == '0' + 11)
		digit_set[num_digits] = '#';
	
	digit_set[num_digits+1] = '\0';
	LcdShowDigit(digit_set[num_digits], FALSE);

	/* 设置等待后续拨号的计时器 */
	DeleteTimer(&h323_timer);
	h323_timer = CreateTimer(FIFTEEN_SEC);
	
		num_digits++;	

	if (!gkEnabled &&num_digits == digitCollectAmount/* || (msg->digit == 11)*/)
	{
		return AppCalloutDirect();
	}
	
	return null_event;
}

/**
 * 提供速拨功能:
 * 若已输入的号码在电话本的号码编号范围以内,
 * 则拨出对应编号的电话号码
 */
int h323_collect_digits_state_long_digit_event(s_event* psEvent, s_task* psTask)
{
	H323TRACE("action: h323_collect_digits_state_long_digit_event\n");

	if (SearchSpeedDialNumber(digit_set) == 0)
	{
		return null_event;
	}
	
	return AppCalloutDirect();
}

/**
 * 返回忙或进行呼叫转移
 */
int h323_collect_digits_state_receive_query_availability_event(s_event* psEvent,
    s_task* psTask)
{
	H323TRACE("action: h323_collect_digits_state_receive_query_availability_event\n");

	wp_msg = (WrapperMsg *) psEvent->pMsg;
	AppReplyNotAvailOrFwd(wp_msg);
	return null_event;
}

/**
 * 终结terminate所指通道的通话
 */
int h323_collect_digits_state_receive_terminate_event(s_event* psEvent, s_task*
    psTask)
{
	H323TRACE("action: h323_collect_digits_state_receive_terminate_event\n");
	return null_event;
}
extern "C"{
typedef struct Interval
{
	int interval;
	Interval* next;
}Interval;
void AppCallout(int);
void AutoCalloutTask(int);
void AppAnsCall(int);
void AutoAnsCallTask(int);
void ClearBlock(Interval *);
int SetupCount;
int AlertingCount;
int VoiceCount,TotalCount;
int* alerting_interval;
Interval mvoice_interval;
Interval svoice_interval;
char (*MVoiceMsg)[40];

void AppCallout(int times)
{
	if(taskSpawn("tautoCallout",200,0,1024*10,(FUNCPTR)AutoCalloutTask,times,0,0,0,0,0,0,0,0,0)==ERROR)
	{
		H323TRACE("Unable to spawn autocallouttask!\n");

	}
/*
	if(SpawnTask("tautoCallout", (FUNCPTR)AutoCalloutTask, TRUE, 200, 1024*10)==ERROR)
	{
		H323TRACE("Unable to spawn autocallouttask\n");
	}	
*/
}

void AutoCalloutTask(int calltimes)
{
	int i=0;
	alerting_interval=(int*)malloc(sizeof(int)*(calltimes+1));
	MVoiceMsg=(char (*)[40]) malloc((calltimes+1)*40);
	
	printf("pointer =0x%x\n",alerting_interval);
	char call_out_msg[40];
	char alerting_msg[40];
	char voice_msg[40];
	int num =0,connectd = 0,voiced =0;
	AlertingCount = 0;
	VoiceCount = 0;
	TotalCount = 0;
	NonWrapperMsg* msg;
	struct timespec tpShow;
	struct tm call_out_Buffer;
	struct tm alerting_Buffer;
	struct tm voice_Buffer;
	Interval* Vptr = &mvoice_interval;
	Vptr->next = NULL;
/*	for(i=0;i<calltimes+1;i++)
		MVoiceMsg[i] =(char*) malloc(40);
*/
	while(1)
	{	
		if(i<calltimes)
		{
			
			if(*state == ST_H323_ON_HOOK_STATE)
			{
				num = 0;
				connectd = 0;
				voiced =0;

				TotalCount++;
				printf("This is %d time to call\n",TotalCount);
				taskDelay(500);
				strcpy(toAddr,"80028");
				if((msg=(NonWrapperMsg *)MQBufGet()) == NULL)
				{
					continue;
				}
				msg->event = speaker_event;
				msg->digit = 0;
				if (MQSend((char*)msg, NO_WAIT) == -1)
				{
					MQBufFree((char*)msg);
					free(alerting_interval);
					return ;
				}
				if((msg=(NonWrapperMsg *)MQBufGet()) == NULL)
				{
					continue;
				}
				msg->event =  callout_key_event;
				msg->digit = 0;
				if (MQSend((char*)msg, NO_WAIT) == -1)
				{
					MQBufFree((char*)msg);
					free(alerting_interval);
					return ;
				}
				if (clock_gettime(CLOCK_REALTIME, &tpShow) == OK)
				{
					if(gmtime_r(&(tpShow.tv_sec), &call_out_Buffer) == OK)
					{
						sprintf(call_out_msg, "%04u-%02u-%02u  %02u:%02u:%02u",
							call_out_Buffer.tm_year + 1900,
							call_out_Buffer.tm_mon + 1,
							call_out_Buffer.tm_mday,
							call_out_Buffer.tm_hour,
							call_out_Buffer.tm_min,
							call_out_Buffer.tm_sec);
						printf("The time we call out is %s\n", call_out_msg);
					}
				}
		
				
			}
				
			else if(*state == ST_H323_WAIT_FOR_CONNECT_STATE && !connectd)
			{
				AlertingCount++;
				printf("AlertingCount is %d\n", AlertingCount);
				connectd = 1;
					
				if (clock_gettime(CLOCK_REALTIME, &tpShow) == OK)
				{
					if(gmtime_r(&(tpShow.tv_sec), &alerting_Buffer) == OK)
					{
						sprintf(alerting_msg, "%04u-%02u-%02u  %02u:%02u:%02u",
							alerting_Buffer.tm_year + 1900,
							alerting_Buffer.tm_mon + 1,
							alerting_Buffer.tm_mday,
							alerting_Buffer.tm_hour,
							alerting_Buffer.tm_min,
							alerting_Buffer.tm_sec);
						printf("The time we received alerting is %s\n", alerting_msg);
					}
				}
				alerting_interval[AlertingCount] = (alerting_Buffer.tm_hour*3600+alerting_Buffer.tm_min*60+alerting_Buffer.tm_sec)-
					(call_out_Buffer.tm_hour*3600+call_out_Buffer.tm_min*60+call_out_Buffer.tm_sec);
				printf("the interval between call out and alerting is %ds\n",alerting_interval[AlertingCount]);
					
				
			}
			else if(*state == ST_H323_BIDIR_VOICE_STATE && !voiced)
			{
				VoiceCount++;
			/*	connectd = 0;*/
				voiced =1;
				if (clock_gettime(CLOCK_REALTIME, &tpShow) == OK)
				{
					if(gmtime_r(&(tpShow.tv_sec), &voice_Buffer) == OK)
					{
						sprintf(voice_msg, "%04u-%02u-%02u  %02u:%02u:%02u",
							voice_Buffer.tm_year + 1900,
							voice_Buffer.tm_mon + 1,
							voice_Buffer.tm_mday,
							voice_Buffer.tm_hour,
							voice_Buffer.tm_min,
							voice_Buffer.tm_sec);
						printf("The time we start voice is %s\n", voice_msg);
						strcpy(MVoiceMsg[VoiceCount],voice_msg);
						printf("The %d time we begin to talk is %s\n",VoiceCount,MVoiceMsg[VoiceCount]);
						Vptr->interval = (voice_Buffer.tm_hour*3600+voice_Buffer.tm_min*60+voice_Buffer.tm_sec)-
							(alerting_Buffer.tm_hour*3600+alerting_Buffer.tm_min*60+alerting_Buffer.tm_sec);
						printf("The master's interval is %d", Vptr->interval);
						Vptr->next = (Interval*)malloc(sizeof(Interval));
						Vptr = Vptr->next;
						Vptr->next = NULL;
					}
					
				}
			}
			else if(*state == ST_H323_DEAD_END_STATE && !num)
			{
				num = 1;
			/*	voiced = 0;*/
				if((msg=(NonWrapperMsg *)MQBufGet()) == NULL)
				{
					continue;
				}
				msg->event =  speaker_event;
				msg->digit = 0;
				if (MQSend((char*)msg, NO_WAIT) == -1)
				{
					MQBufFree((char*)msg);
					free(alerting_interval);
					return ;
				}	
				i++;
			}
		}
		
		taskDelay(0);
	}
	//free(alerting_interval);	
	
}
/*extern "C"{	*/
void MShowCallNumber()
{

	Interval* ptr;
	int i = 0;
	double sum = 0;
	for(ptr= &mvoice_interval;ptr->next!=NULL;ptr=ptr->next)
	{	
		i++;
		sum += ptr->interval;
		printf("the master's interval is %d\n",ptr->interval);
	}
	printf("recieved alerting times is %d,\n",AlertingCount);
	printf("recieved voice times is %d,\n",VoiceCount);
	printf("I have dialed %d times.\n",TotalCount);
	printf("mean time is %f\n",sum/i);
	ClearBlock(mvoice_interval.next);
/*	printf("pointer =0x%x\n", alerting_interval);
	for(i=1;i<=AlertingCount;i++)
		printf("Received Alerting %d times, interval between callout and alerting is %d\n",i,alerting_interval[i]);
	for(i=1;i<=VoiceCount;i++)
		printf("the time begin to talk is %s\n",MVoiceMsg[i]);*/
}


void ClearBlock(Interval * ptr_block)
{
	Interval * p, * q;
	
	#ifdef __UPDATE_DEBUG__
	printf("Clear  Node...\n");
	#endif
	
	if (ptr_block == NULL)
	{
		return;
	}
	for (p = ptr_block; p != NULL; p = q)
	{
		q = p -> next;
		free(p);
	}	
	return;
}

void AppAnsCall(int voicetime)
{
	if(taskSpawn("tautoAnsCall",200,0,1024*10,(FUNCPTR)AutoAnsCallTask,voicetime,0,0,0,0,0,0,0,0,0)==ERROR)
	{
		H323TRACE("Unable to spawn AutoAnsCallTask\n");
	}
/*	if(SpawnTask("tautoAnsCall", (FUNCPTR)AutoAnsCallTask, TRUE, 200, 1024*10)==ERROR)
	{
		H323TRACE("Unable to spawn AutoAnsCallTask\n");
	}
*/
}

void AutoAnsCallTask(int bivoicetime)
{

	NonWrapperMsg* msg;
	int ringed = 0, connected = 0,num =0;
	struct timespec tpShow;
	struct tm send_connect_Buffer;
	struct tm voice_Buffer;
	char send_connect_msg[40];
	char voice_msg[40];
/*	SCallInfo* Vptr = &SVoiceInfo;*/
	Interval* Sptr = &svoice_interval;
/*	Vptr->next = NULL;*/
	Sptr->next = NULL;
	while(1)
	{
		if(*state == ST_H323_RINGING_STATE && !ringed)
		{
			ringed =1;
			connected = 0;
			num = 0;
			SetupCount++;
		/*	taskDelay(300);*/
			if((msg=(NonWrapperMsg *)MQBufGet()) == NULL)
			{
				continue;
			}
			msg->event = speaker_event;
			msg->digit = 0;
			if (MQSend((char*)msg, NO_WAIT) == -1)
			{
				MQBufFree((char*)msg);
				return ;
			}	
			if (clock_gettime(CLOCK_REALTIME, &tpShow) == OK)
			{
				if(gmtime_r(&(tpShow.tv_sec), &send_connect_Buffer) == OK)
				{
					sprintf(send_connect_msg, "%04u-%02u-%02u  %02u:%02u:%02u",
						send_connect_Buffer.tm_year + 1900,
						send_connect_Buffer.tm_mon + 1,
						send_connect_Buffer.tm_mday,
						send_connect_Buffer.tm_hour,
						send_connect_Buffer.tm_min,
						send_connect_Buffer.tm_sec);
					printf("The time we begin to connect is %s\n", send_connect_msg);

⌨️ 快捷键说明

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