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

📄 config.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (FSK)
 |
 |	Filename:   	config.c
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains the functions to dynamically configure a set of trunks and stacks asynchronously
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.16 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

#include "includes.h"



/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/

/* Timeout in msec to wait in the TBXReceiveMsg() function while waiting for adapters to register */
#define TB640_FSK_ADAPTER_LOOP_MSG_RECEIVE_TIMEOUT_MSEC			500

/* Timeout value for TbxReceiveMsg() used by the operation library */
#define TB640_FSK_OPERATION_RECEIVE_MSG_TIMEOUT_MSEC			250

/* Maximum number of operation active in one library at the same time */
#define TB640_FSK_MAX_OPERATION_PER_LIBRARY						(TB640_FSK_MAX_TRUNK_PER_OPERATION_LIBRARY * TB640_FSK_MAX_TIMESLOT_IN_TRUNK * 4)

/* Allocation granularity for the operation library */
#define TB640_FSK_ALLOCATION_GRANULARITY						512

/* Max concurrent request per operation library */
#define TB640_FSK_MAX_CONCURRENT_REQUEST_PER_LIBRARY			(TB640_FSK_MAX_OPERATION_PER_LIBRARY * 10)

/* Defines a interval at which the adapter sends an heartbeat to the library */
#define TB640_FSK_ADAPTER_KEEPALIVE_TIMER_SEC					1

/* Maximum timeout waiting for adapters attach/detach */
#define TB640_FSK_ADAPTER_ATTACH_TIMEOUT_MSEC					(10*1000)

/* Maximum timeout waiting for adapters VP alloc/free */
#define TB640_FSK_ADAPTER_VP_ALLOC_TIMEOUT_MSEC					(10*1000)

/* Maximum timeout waiting for adapters Trunk alloc/free */
#define TB640_FSK_ADAPTER_TRUNK_ALLOC_TIMEOUT_MSEC				(10*1000)

/* Maximum timeout waiting for adapters Trunk activation/maintenance */
#define TB640_FSK_ADAPTER_TRUNK_ACTIVATION_TIMEOUT_MSEC		(10*1000)

/* Maximum timeout waiting for adapters trunk resources alloc/free */
#define TB640_FSK_ADAPTER_TRUNK_RESOURCE_ALLOC_TIMEOUT_MSEC	(10*1000)

/* Maximum timeout waiting for connection destruction */
#define TB640_FSK_ADAPTER_CONNECTION_DESTRUCTION_TIMEOUT_MSEC	(10*1000)

/* Maximum timeout waiting for adapters stack alloc/free */
#define TB640_FSK_ADAPTER_STACK_ALLOC_TIMEOUT_MSEC				(45*1000)

#ifdef _WIN32
	#define CurrentProcessId		GetCurrentProcessId
#else
	#define CurrentProcessId		getpid
#endif

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.16 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT TB640FskOpenAdapters (void);

TBX_RESULT TB640FskCloseAdapters (void);

TBX_RESULT TB640FskAllocateVPResources (void);

TBX_RESULT TB640FskFreeVPResources (void);

TBX_RESULT TB640FskAllocateTrunks (void);

TBX_RESULT TB640FskFreeTrunks (void);

TBX_RESULT TB640FskAllocateTrunkResources (void);

TBX_RESULT TB640FskFreeTrunkResources (void);

TBX_RESULT TB640FskCreateConnections (void);

TBX_RESULT TB640FskDestroyConnections (void);

TBX_RESULT TB640FskAllocateAsyncOpContexts (void);

TBX_RESULT TB640FskFreeAsyncOpContexts (void);

TBX_RESULT TB640FskActivateTrunks (void);

TBX_RESULT TB640FskMaintenanceTrunks (void);

TB640_FSK_SERVICE_FUNCTION (TB640FskSendCloseRemote);

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskConfigureSystem:	This function allocates and configure the trunks, stacks, VP resources and operation librairies
 |								required to run this application
 |
 |  ~		        :	No arguments used
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskConfigureSystem (void)
{
	TBX_LIB_PARAMS						LibParam;
	TBX_RESULT							result;
	TBX_UINT32							un32AdapIdx;
	TBX_UINT32							un32OpLibIdx;
	PTB640_FSK_ADAPTER_INFO				pAdapterInfo;
	TBX_ASYNC_LIB_PARAMS				OperationLibParams;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */

		/* Initializes the TBX library */
		memset (&LibParam, 0, sizeof (LibParam));
		LibParam.un32StructVersion				= 1;
		LibParam.un32WatchdogTimeoutSec			= TB640_FSK_ADAPTER_WATCHDOT_TIMEOUT_SEC;
		LibParam.TransportType					= TBX_TRANSPORT_TYPE_ETHERNET;
		LibParam.MsgRxThreadPrio				= TBX_MSG_RX_THREAD_PRIO_HIGHER;
		LibParam.un32SendFifoSize				= TBX_SEND_FIFO_SIZE_DEFAULT;
		LibParam.pMsgTrace						= NULL;
		LibParam.pStderr						= g_AppContext->pLogFile;
		strcpy( LibParam.szApplicationName, "FSK" );
		LibParam.un64UserContext2				= CurrentProcessId();
		#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
		LibParam.fEnableInterAppCommunication	= TBX_TRUE;
		#endif
		LibParam.NetworkRedundancyParams.un32StructVersion = 1;
		LibParam.NetworkRedundancyParams.un32PollDelayMs   = TBX_NETWORK_REDUNDANCY_DEFAULT_POLL_DELAY_MS;
		LibParam.NetworkRedundancyParams.un32NetworkDownDelayMs   = TBX_NETWORK_REDUNDANCY_DEFAULT_NETWORK_DOWN_DELAY_MS;
		LibParam.NetworkRedundancyParams.un32AdapterDownDelayMs   = TBX_NETWORK_REDUNDANCY_DEFAULT_ADAPTER_DOWN_DELAY_MS;
		LibParam.NetworkRedundancyParams.fUseNetworkGw0    = TBX_TRUE;
		LibParam.NetworkRedundancyParams.fUseNetworkGw1    = TBX_TRUE;

		if( g_AppContext->un16GwPort )
			LibParam.un16TbxGwPort = g_AppContext->un16GwPort;

		/* Initialize stress-test statistics semaphore */
		TBX_SEM_CREATE (&g_StressStatsSem, 1, 1);

		/* Initialize the transiant calls semaphore */
		TBX_SEM_CREATE (&(g_AppContext->TransientCallsSem), 1, 1);
		g_AppContext->un32TransientCalls = 0;

		/* Opening the TBX library */
		result = TBXOpenLib (&LibParam, &(g_AppContext->hTbxLib));
		if (TBX_RESULT_FAILURE (result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open TBX library");
		}
		TB640_FSK_LOG (TRACE_LEVEL_4, "+--------------------------------------------------------------\n");
		TB640_FSK_LOG (TRACE_LEVEL_4, "| TBX Library %s (0x%08X)\n", LibParam.szBuildTag, LibParam.un32BuildNumber);
		TB640_FSK_LOG (TRACE_LEVEL_4, "+--------------------------------------------------------------\n\n");

		result = TBXGetLibParams( g_AppContext->hTbxLib, &LibParam );
		if (TBX_RESULT_FAILURE (result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to read TBX library parameters");
		}

		/* Open adapters specified in configuration file */
		result = TB640FskOpenAdapters ();
		if (TBX_RESULT_FAILURE (result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open requested adapters");
		}

		/* Open the operation libraries */
		for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)
		{
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
			for (un32OpLibIdx=0; un32OpLibIdx<(((pAdapterInfo->un32NbTrunk-1)/TB640_FSK_MAX_TRUNK_PER_OPERATION_LIBRARY)+1); un32OpLibIdx++)
			{
				#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
				TBX_FILTER_PARAMS	aAsyncLibCustomFilters[ 2 ];
				#else
				TBX_FILTER_PARAMS	aAsyncLibCustomFilters[ 1 ];
				#endif

				TBX_SEM_CREATE (&(pAdapterInfo->Lock.aOperationLibSem[un32OpLibIdx]), 1, 1);
				pAdapterInfo->Lock.apszOperationLibSemFile[un32OpLibIdx] = "";

				/* Build unique async lib Id -> unique app Id, 16 bytes from IP address and async lib index */
				TB640_FSK_BUILD_ASYNC_LIB_ID
				(
					&(pAdapterInfo->aun64UniqueId[un32OpLibIdx]),
					CurrentProcessId(),
					LibParam.szInterfaceIp0,
					un32OpLibIdx
				);

				/* One more operation library */
				pAdapterInfo->un32NbOperationLib++;

				/* Configure the library parameters */
				memset( &OperationLibParams, 0, sizeof(OperationLibParams) );
				OperationLibParams.un32ReceiveTimeoutMSec			= TB640_FSK_OPERATION_RECEIVE_MSG_TIMEOUT_MSEC;
				OperationLibParams.un32OpContextMaxCount			= TB640_FSK_MAX_OPERATION_PER_LIBRARY;
				OperationLibParams.un32OpContextAllocGranularity	= TB640_FSK_ALLOCATION_GRANULARITY;
				OperationLibParams.un32OpContextUserContextSize		= sizeof (TB640_FSK_CALL_CONTEXT);
				OperationLibParams.un32RequestContextMaxCount		= TB640_FSK_MAX_CONCURRENT_REQUEST_PER_LIBRARY;
				OperationLibParams.un32RequestContextAllocGranularity = TB640_FSK_ALLOCATION_GRANULARITY;
				OperationLibParams.pfnUnknowMsgHandler				= TB640FskEventMessageHandler;
				OperationLibParams.pfnAdapterRemovedHandler			= NULL;
				OperationLibParams.pvAppContext						= TB640_FSK_CREATE_APP_CONTEXT (un32AdapIdx, un32OpLibIdx);
				OperationLibParams.pfnErrorPrint					= TB640FskAsyncLibErrorPrint;

				/* Add one custom filter to async lib */
				OperationLibParams.un32NbCustomFilters = sizeof(aAsyncLibCustomFilters)/sizeof(*aAsyncLibCustomFilters);
				OperationLibParams.paCustomFilters = aAsyncLibCustomFilters;

				/* Add filter to receive CPU monitoring */
				aAsyncLibCustomFilters[0].un32StructVersion	= 1;
				aAsyncLibCustomFilters[0].FilterMask			= TBX_FILTER_MSG_ID;
				aAsyncLibCustomFilters[0].MsgId					= TB640_MSG_ID_ADAPTER_NOTIF_CPU_REPORT;
				#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
				{
					/* Add filter to receive messages from remote host */
					aAsyncLibCustomFilters[1].un32StructVersion		= 1;
					aAsyncLibCustomFilters[1].FilterMask			= TBX_FILTER_MSG_USER_CONTEXT2;

					/* Build the user context of the async lib of the other host */
					TB640_FSK_BUILD_ASYNC_LIB_ID
					(
						&aAsyncLibCustomFilters[1].un64UserContext2,
						pAdapterInfo->un32RemoteProcessId,
						pAdapterInfo->HostInfo.szIpAddress0,
						un32OpLibIdx
					);
				}
				#endif

				/* Open the library */
				result = TBXAsyncOpen (
				  g_AppContext->hTbxLib,
				  pAdapterInfo->hAdapter,
				  &OperationLibParams,
				  &(pAdapterInfo->ahOperationLib [un32OpLibIdx]),
 				  &(pAdapterInfo->aun64UniqueId [un32OpLibIdx]));
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open operation library");
				}
			}
		}


		#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
		{
			/* Simulate allocation of VP resource on each adapters */
			result = TB640FskAllocateVPResources ();
			if (TBX_RESULT_FAILURE (result))
			{
				TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to allocate VP resources");
			}
		}
		#else
		{
			/* Allocate trunks */
			result = TB640FskAllocateTrunks ();
			if (TBX_RESULT_FAILURE (result))
			{
				TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to allocate trunks");
			}

			/* Activate trunks */
			result = TB640FskActivateTrunks ();
			if (TBX_RESULT_FAILURE (result))
			{

⌨️ 快捷键说明

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