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

📄 bepmain.c

📁 基于h323协议的软phone
💻 C
字号:

#include <string.h>

#include "event.h"
#include "beptimer.h"
#include "SysDep.h"


#include "stdlib.h"
#include "lcdstats.h"
#include "task.h"
#include "bepcommon.h"
#include "pgi_api.h"

#define TASK_LIST_SIZE 32

extern void ClearLcd( void );
void LcdShowString( char *string );
void Spirit();
void RvTask();
void AppProcess();

#ifdef HC

#ifdef INCLUDE_PPPOE_APP
#include "ipphonePPPoE.h"
extern SEM_ID g_sem_pppoe_startedflag;
#endif

SEM_ID initProcSem;
int initDone = FALSE;


extern void doInit(int showMsg);
extern int reverseIPAddr(int srcIPAddr);

#endif /* HC */

void AppMain()
{
	printf("begin AppMain()...\n");
#ifdef HC
	H323Init();
#endif
#ifdef SIP
	SipInit();
#endif
#ifdef MGCP
	mgcpInit();
#endif

	InitialMenuTask();

	taskSpawn( "spirit", 100, 0, 2048, (FUNCPTR)Spirit,0,0,0,0,0,0,0,0,0,0 );

	taskSpawn( "tAppProc", 200, 0, 51200, (FUNCPTR)AppProcess,0,0,0,0,0,0,0,0,0,0 );

#ifdef HC
	semTake(initProcSem, WAIT_FOREVER);

#ifdef INCLUDE_PPPOE_APP
	if (getIfPPPoE())
	{
		WrapperMsg msg;
		PPPOELINK_PARA pppoeInfo;
		ClearWatchTimer();
		semTake(g_sem_pppoe_startedflag, WAIT_FOREVER);
		pppoeGetLinkInfo(&pppoeInfo);
		if (pppoeInfo.result == 0 )
		{
			msg.msgId=pppoe_connect_ok_event;			
		}
		else
		{
			msg.msgId=pppoe_connect_fail_event;			
		}
		wpSendMsgToApp(&msg);
		phoneconfig.conf_network.ipaddr = reverseIPAddr(pppoeInfo.ip_local);
		phoneconfig.conf_network.subnetmask = pppoeInfo.ip_mask;
		phoneconfig.conf_network.gateway = reverseIPAddr(pppoeInfo.ip_remote);
		ConfigureNetwork();
		
#ifdef INCLUDE_NAT_APP
		if (phoneconfig.conf_network.ifnat)
			natON(IF_TYPE_PPPOE);
#endif

	}
	else
	{
#ifdef INCLUDE_NAT_APP
		if (phoneconfig.conf_network.ifnat)
			natON(IF_TYPE_NAT);
#endif
	}
#endif /* INCLUDE_PPPOE_APP */

	if (!initDone)
	{
		doInit(0);		
	}
#endif /* HC */	
	/*rv seli loop !!!*/
	RvTask();

}

void AppProcess()
{
	s_event se;
	char*				rxBuffer;
	int					event;
	int					iWaitTime, iTimerId;


	while (1)
	{
		iTimerId = getTimeOut(TRUE, &iWaitTime);
		if (iTimerId == -1)
		{
			rxBuffer = MQReceive(&event, iWaitTime);
			if (rxBuffer == NULL)
			{
				if (event == null_event)
				{
					fprintf( stderr, "AppMain: Failed to receive event from queue; errno=%d\n", errno);
					ClearLcd();
					LcdShowString("Event queue failure!");
					return;
				}

				continue;
			}
		}
		else
		{
			rxBuffer = MQBufGet();
			if (rxBuffer == NULL)
			{
				fprintf( stderr, "AppMain: mqueue full!\n");
				ClearLcd();
				LcdShowString("mqueue full!");
				return;
			}
			
			event = timeout_event;
			((NonWrapperMsg*)rxBuffer)->event = timeout_event;
			((NonWrapperMsg*)rxBuffer)->digit = iTimerId;
		}
		
		se.iEvent = event;
		se.pMsg = rxBuffer;
		printf ( "se.Ivent = %d\n", event ) ;

		menu_event = event;
		callTask.fAction(&se, &callTask);
		se.iEvent = menu_event;	
		psMenuTask->fAction(&se, psMenuTask);
			
		MQBufFree(rxBuffer);		
		/*BEP_WAIT_FOREVER*/
	}
}


/**
 *get task name from taskId
 *if two names are matched
 *then task is active, and return TRUE
 *else task is not exit, return FALSE
 *you can add any other conditions for this.
*/
BOOL checkTask(int* list, int listSize, char* name)
{
	char * temp;
	int i = 0;
	BOOL bFind = FALSE, suspended=FALSE;
	if (listSize < 0)
	{
		return TRUE;
	}
	for (i = 0; i < listSize; i++)
	{
		temp = taskName(list[i]);
		if (NULL == temp)
		{
			printf("task %0x 's name is NULL!\n", list[i]);
			continue;
		}

		/*check task from name*/
		if (strstr(temp,  name) == temp)
		{
			if (taskIsSuspended(list[i]) == FALSE)
				return TRUE;
			else
				suspended = TRUE;
		}
	}
	if (suspended)
		printf("task \"%s\" suspended, reboot system...\n", name);	
	else
		printf("task \"%s\" down, reboot system...\n", name);
/*	printf("task list size=%d!\n", listSize);
	for (i = 0; i < listSize; i++)
	{
		temp = taskName(list[i]);
		if (NULL != temp)
		{
			printf("task name is %s! ", temp);
		}
		printf("task id  is %s!\n", list[i]);
	}*/
	reboot_system();
	return FALSE;
}


/**
 *every checked task MUST have different name from other tasks
 *
*/
void Spirit()
{
	int taskIdList[TASK_LIST_SIZE];
	char* name = NULL;
	int i = 0;
	int iSize = 0;

	taskDelay(1000);
	/*printf("starting to scout 9 tasks...\n");*/
	printf("starting to scout 7 tasks...\n");
	
	while (TRUE)
	{
		iSize = taskIdListGet(taskIdList, TASK_LIST_SIZE);

		checkTask(taskIdList, iSize, "dspIsrTask");
		checkTask(taskIdList, iSize, "dspIsr2Task");
		/*checkTask(taskIdList, iSize, "tDspUdpServ");
		checkTask(taskIdList, iSize, "tsrvSendTas");*/
		checkTask(taskIdList, iSize, "tKeyLamp");
		checkTask(taskIdList, iSize, "tShowLcdMes");
		checkTask(taskIdList, iSize, "tAppProc");
		/*checkTask(taskIdList, iSize, "VWSS_TMRTSK");
		checkTask(taskIdList, iSize, "VWSS_STSK");*/
		checkTask(taskIdList, iSize, "dApp");

		taskDelay(100);
	}
}



⌨️ 快捷键说明

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