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

📄 config.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
			{
				/* Was this adapter already found ? */
				pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
				if (pAdapterInfo->hAdapter != (TBX_ADAPTER_HANDLE)NULL)
				{
					continue;
				}

				/*--------------------------------------------------------------------------------------------------------------
				 | Check for specific named adapters
				 *-------------------------------------------------------------------------------------------------------------*/

				/* Check for a specific name ? */
				if (strcmp (pAdapterInfo->szAdapterName, TB640_FSK_ANY_ADAPTER_STRING) != 0)
				{
					/* Search for that specific adapter */
					for (un32TrunkIdx=0; un32TrunkIdx<(TBX_UINT32)nAdapters; un32TrunkIdx++)
					{
						/* Compare the names */
						if (strcmp (aszAdapterName [un32TrunkIdx], pAdapterInfo->szAdapterName) == 0)
						{
							/* We found the adapter */
							un32AdapterLeftToDiscover--;

							/* Store the adapter handle */
							pAdapterInfo->hAdapter = aAdapters [un32TrunkIdx];
							afAdapterUsed [un32TrunkIdx] = TBX_TRUE;
							TB640_FSK_LOG (TRACE_LEVEL_4, "Adapter %s will be used as adapter %d/%d\n", \
							  pAdapterInfo->szAdapterName, (un32AdapIdx+1), g_AppContext->un32NbAdapter);

							break;
						}
					}
				}

				/*--------------------------------------------------------------------------------------------------------------
				 | Check for unspecific adapters
				 *-------------------------------------------------------------------------------------------------------------*/

				/* Take any adapter in the list */
				else
				{
					/* Search for any adapter that is not yet assigned */
					for (un32TrunkIdx=0; un32TrunkIdx<(TBX_UINT32)nAdapters; un32TrunkIdx++)
					{
						/* Is this a TB640? */
						#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
						{
							TBX_HOST_INFO	Info;
							result = TBXGetRemoteHostInfo (g_AppContext->hTbxLib, aAdapters [un32TrunkIdx], &Info);
							if (TBX_RESULT_FAILURE (result))
							{
								TBX_EXIT_ERROR(result, 0, "Unable to retrieve remote host information");
							}
							if( strcmp( Info.szApplicationName, "FSK" ) == 0 )
							{
								/* Compare the names */
								if (afAdapterUsed [un32TrunkIdx] == TBX_FALSE)
								{
									/* We found the adapter */
									un32AdapterLeftToDiscover--;

									/* Store the adapter handle */
									pAdapterInfo->hAdapter = aAdapters [un32TrunkIdx];
									afAdapterUsed [un32TrunkIdx] = TBX_TRUE;

									/* Copy the adapter name to our internal structure */
									strcpy (pAdapterInfo->szAdapterName, aszAdapterName [un32TrunkIdx]);
									TB640_FSK_LOG (TRACE_LEVEL_0, "Adapter %s will be used as adapter %d/%d\n", \
									  pAdapterInfo->szAdapterName, (un32AdapIdx+1), g_AppContext->un32NbAdapter);

									pAdapterInfo->un32RemoteProcessId = (TBX_UINT32)Info.un64UserContext2;

									break;
								}
							}
						}
						#else
						{
							TBX_ADAPTER_INFO	Info;
							result = TBXGetAdapterInfo (g_AppContext->hTbxLib, aAdapters [un32TrunkIdx], &Info);
							if (TBX_RESULT_FAILURE (result))
							{
								TBX_EXIT_ERROR(result, 0, "Unable to retrieve adapter information");
							}
							if( Info.AdapterType == TBX_ADAPTER_TYPE_TB640 )
							{
								/* Compare the names */
								if (afAdapterUsed [un32TrunkIdx] == TBX_FALSE)
								{
									/* We found the adapter */
									un32AdapterLeftToDiscover--;

									/* Store the adapter handle */
									pAdapterInfo->hAdapter = aAdapters [un32TrunkIdx];
									afAdapterUsed [un32TrunkIdx] = TBX_TRUE;

									/* Copy the adapter name to our internal structure */
									strcpy (pAdapterInfo->szAdapterName, aszAdapterName [un32TrunkIdx]);
									TB640_FSK_LOG (TRACE_LEVEL_0, "Adapter %s will be used as adapter %d/%d\n", \
									  pAdapterInfo->szAdapterName, (un32AdapIdx+1), g_AppContext->un32NbAdapter);

									break;
								}
							}
						}
						#endif
					}
				}

				/*--------------------------------------------------------------------------------------------------------------
				 | Any events for new adapters ?
				 *-------------------------------------------------------------------------------------------------------------*/

				/* Check if we received any events of card discovery */
				result = TBXReceiveMsg (g_AppContext->hTbxLib, hFilter, TB640_FSK_ADAPTER_LOOP_MSG_RECEIVE_TIMEOUT_MSEC, &hMsg);
				if ((result != TBX_RESULT_API_TIMEOUT) && TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve message");
				}

				/* Have we received a new board ? */
				if (hMsg != (TBX_MSG_HANDLE)NULL)
				{
					#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
					{
						PTBX_EVT_API_NOTIF_REMOTE_HOST_ADDED	pEvent;

						pEvent = (PTBX_EVT_API_NOTIF_REMOTE_HOST_ADDED)TBX_MSG_PAYLOAD_POINTER(hMsg);
						/* Convert in caps */
						TB640FskToUpper (pEvent->Info.szHostName);

						/* Make sure we didn't already receive that board identification */
						for (un32AdapIdx=0; un32AdapIdx<nAdapters; un32AdapIdx++)
						{
							/* This adapter is already registered */
							if (strcmp(aszAdapterName [un32AdapIdx], pEvent->Info.szHostName) == 0)
							{
								break;
							}
						}

						/* Was it already known to us ? */
						if (un32AdapIdx >= nAdapters)
						{
							/* No, then register it */
							strcpy (aszAdapterName [un32AdapIdx], pEvent->Info.szHostName);
							aAdapters [un32AdapIdx] = pEvent->Info.hRemoteHost;
							nAdapters++;
						}
					}
					#else
					{
						PTBX_EVT_API_NOTIF_ADAPTER_ADDED	pEvent;

						pEvent = (PTBX_EVT_API_NOTIF_ADAPTER_ADDED)TBX_MSG_PAYLOAD_POINTER(hMsg);
						/* Convert in caps */
						TB640FskToUpper (pEvent->Info.szAdapterName);

						/* Make sure we didn't already receive that board identification */
						for (un32AdapIdx=0; un32AdapIdx<nAdapters; un32AdapIdx++)
						{
							/* This adapter is already registered */
							if (strcmp(aszAdapterName [un32AdapIdx], pEvent->Info.szAdapterName) == 0)
							{
								break;
							}
						}

						/* Was it already known to us ? */
						if (un32AdapIdx >= nAdapters)
						{
							/* No, then register it */
							strcpy (aszAdapterName [un32AdapIdx], pEvent->Info.szAdapterName);
							aAdapters [un32AdapIdx] = pEvent->Info.hAdapter;
							nAdapters++;
						}
					}
					#endif



					/* Free the message */
					TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
					hMsg = NULL;
				}

				un32TimeMsec = TBX_GET_TICK()  - un32StartTimeMsec;
			}
		}

		/*-----------------------------------------------------------------------------------------------------------------------
		 | Check if we have all required adapters to continue
		 *----------------------------------------------------------------------------------------------------------------------*/

		/* Have we found every adapter we wanted ? */
		if (un32AdapterLeftToDiscover != 0)
		{
			un32TrunkIdx = 0;
			for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)
			{
				pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
				if (pAdapterInfo->hAdapter == (TBX_ADAPTER_HANDLE)NULL)
				{
					if (strcmp(pAdapterInfo->szAdapterName, TB640_FSK_ANY_ADAPTER_STRING) == 0)
					{
						un32TrunkIdx++;
					}
					else
					{
						TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Adapter %s wasn't discovered\n", pAdapterInfo->szAdapterName);
					}
				}
			}

			/* Display indication if "ANY" adapter was used in the configuration file */
			if (un32TrunkIdx > 0)
			{
				TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Missing %d unidentified adapter(s) to start\n", un32TrunkIdx);
			}

			TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Not able to find all required adapter in configuration file\n");
			TBX_EXIT_SUCCESS (TBX_RESULT_NOT_FOUND);
		}

		/* Destroy the filter */
		result = TBXDestroyMsgFilter (g_AppContext->hTbxLib, hFilter);
		if (TBX_RESULT_FAILURE (result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to destroy filter");
		}
		hFilter = NULL;


	    /*-----------------------------------------------------------------------------------------------------------------------
		 | Check if features list of found adapters match feature requirements for the test.
		 *----------------------------------------------------------------------------------------------------------------------*/

		#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
		{
			for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)
			{
				TBX_UINT32	un32TrunkIdx;
				pAdapterInfo = &(g_AppContext->ahAdapterInfo[un32AdapIdx]);

        		/* Retreive adapter info */
				result = TBXGetRemoteHostInfo
				(
					g_AppContext->hTbxLib,
				    pAdapterInfo->hAdapter,
				    &pAdapterInfo->HostInfo
				);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to query remote host info");
				}

				/* Fill remote host info */
				pAdapterInfo->aun32FeatureEnabled[ TBX_FEATURE_TYPE_TRUNK_E1 ]			= 64;
				pAdapterInfo->aun32FeatureEnabled[ TBX_FEATURE_TYPE_TRANSCODING ]		= 2048;
				pAdapterInfo->aun32FeatureEnabled[ TBX_FEATURE_TYPE_TONE_DETECTION ]	= 2048;
				pAdapterInfo->aun32FeatureEnabled[ TBX_FEATURE_TYPE_TONE_SUPPRESSION ]	= 2048;
				pAdapterInfo->un32NbTrunk												= 64;

				for( un32TrunkIdx = 0; un32TrunkIdx < pAdapterInfo->un32NbTrunk; un32TrunkIdx++ )
				{
					PTB640_FSK_TRUNK_INFO				pTrunkInfo;
					TBX_UINT32							un32TsIdx;

					pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32TrunkIdx]);

					pTrunkInfo->un8Trunk								= (TBX_UINT8)un32TrunkIdx;
					pTrunkInfo->hTrunk									= 0x1000 + un32TrunkIdx;
					pTrunkInfo->fActivated								= TBX_TRUE;
					pTrunkInfo->fIncludedInStressTesting				= TBX_TRUE;
					pTrunkInfo->TrunkConfiguration.Type					= TB640_TRUNK_TYPE_E1;
					pTrunkInfo->TrunkConfiguration.Cfg.E1.Framing		= TB640_E1_FRAMING_AUTO;
					pTrunkInfo->TrunkConfiguration.Cfg.E1.Encoding		= TB640_E1_LINE_ENCODING_HDB3;
					pTrunkInfo->TrunkConfiguration.Cfg.E1.Termination	= TB640_E1_LINE_TERMINATION_SHORT;
					pTrunkInfo->TrunkConfiguration.Cfg.E1.fLoopTime		= TBX_FALSE;
					pTrunkInfo->TrunkConfiguration.Cfg.E1.byIdleCode	= 0xff;
					pTrunkInfo->un32OpLibIdx							= un32TrunkIdx / TB640_FSK_MAX_TRUNK_PER_OPERATION_LIBRARY;
					pTrunkInfo->un32NbTrunkResource						= 30;

					for (un32TsIdx=0; un32TsIdx<TB640_FSK_MAX_TIMESLOT_IN_TRUNK; un32TsIdx++)
					{
						PTB640_FSK_TRUNK_RESOURCE_INFO		pTrunkResInfo;

						pTrunkResInfo = &(pTrunkInfo->aResourceInfo [un32TsIdx]);

						if (pTrunkInfo->TrunkConfiguration.Type == TB640_TRUNK_TYPE_E1)
						{
							if (un32TsIdx == 0)
							{
								/* This is the framing timeslot.. no resource to allocate here */
								pTrunkResInfo->State = TB640_FSK_CALL_APP_STATE_NOT_USED;
								continue;
							}
							else if (un32TsIdx == 16)
							{
								/* This is the signaling timeslot.. no resource to allocate here */
								pTrunkResInfo->State = TB640_FSK_CALL_APP_STATE_NOT_USED;
								continue;
							}
						}
						else
						{
							if (un32TsIdx == 0)
							{
								/* Timeslot 0 is not used by convention */
								pTrunkResInfo->State = TB640_FSK_CALL_APP_STATE_NOT_USED;
								continue;
							}
						}

						pTrunkResInfo->fInUse					= TBX_FALSE;
						pTrunkResInfo->fOperationAllocated		= TBX_FALSE;
						pTrunkResInfo->un8Trunk					= pTrunkInfo->un8Trunk;
						pTrunkResInfo->un8Timeslot				= (TBX_UINT8)un32TsIdx;
						/* Create dummy handles to simulate resources are ready */
						pTrunkResInfo->hTrunkResource			= 0x2000 + TB640_FSK_MAX_TIMESLOT_IN_TRUNK * pTrunkResInfo->un8Trunk + pTrunkResInfo->un8Timeslot;
						pTrunkResInfo->hVPGroup					= 0x3000 + TB640_FSK_MAX_TIMESLOT_IN_TRUNK * pTrunkResInfo->un8Trunk + pTrunkResInfo->un8Timeslot;
						pTrunkResInfo->hVPResource				= 0x4000 + TB640_FSK_MAX_TIMESLOT_IN_TRUNK * pTrunkResInfo->un8Trunk + pTrunkResInfo->un8Timeslot;
						pTrunkResInfo->hConnection				= 0;
						pTrunkResInfo->State					= TB640_FSK_CALL_APP_STATE_IDLE;
						pTrunkResInfo->SubState					= TB640_FSK_CALL_APP_SUB_STATE_ENTRY;
						pTrunkResInfo->un32LastIdleTimestamp	= TBX_GET_TICK();
					}
				}

⌨️ 快捷键说明

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