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

📄 config.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
                                                    pAdapterInfo->hAdapter,
                                                    g_AppContext->hTbxLib,
                                                    TBX_FEATURE_TYPE_LAST,
                                                    pAdapterInfo->aun32FeatureEnabled, NULL, NULL);
            if( TBX_RESULT_FAILURE(apiResult) )
        	{
        		TBX_EXIT_ERROR(apiResult, 0, "Unable to retrieve features");
        	}

        	/* Retreive adapter info */
			apiResult = TBXGetAdapterInfo(  g_AppContext->hTbxLib,
				                            pAdapterInfo->hAdapter,
				                            &pAdapterInfo->AdapterInfo );
		    if( TBX_RESULT_FAILURE(apiResult) )
        	{
        		TBX_EXIT_ERROR(apiResult, 0, "Unable to retrieve adapter info");
        	}

    	}
    	else
    	{
    	    TBX_EXIT_ERROR(TBX_RESULT_INVALID_HANDLE, 0, "Adapter handle NULL");
    	}

    	/*---------------------------------------------------------------------------------------------------------------------------
    	 |  Print adapter info into the license feature log buffer
    	 *--------------------------------------------------------------------------------------------------------------------------*/
        TB640FskGetAdapterIpAddresses( &pAdapterInfo->AdapterInfo, szAdapterIPAddresses );
    	sprintf(   pszLogBufferLicenseFeature, "\nName=%s, Serial=%s, Ip=%s %s\n",
    	           pAdapterInfo->AdapterInfo.szAdapterName,
    	           pAdapterInfo->AdapterInfo.szSerialNumber,
    	           szAdapterIPAddresses,
    	           (pAdapterInfo->AdapterInfo.AdapterType == TBX_ADAPTER_TYPE_TB_MB ) ? "(Switch)" : "" );

        /*---------------------------------------------------------------------------------------------------------------------------
         |  Check global license and configuration mismatch
         *--------------------------------------------------------------------------------------------------------------------------*/
        /* Check if Tone feature is enabled */
        if( pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_TONE_GENERATION] == 0 )
            SET_FEATURE_MISMATCH_AND_RESULT( TBX_FEATURE_TYPE_TONE_GENERATION, af32FeatureMismatch, result );
        if( pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_TONE_DETECTION] == 0 )
            SET_FEATURE_MISMATCH_AND_RESULT( TBX_FEATURE_TYPE_TONE_DETECTION, af32FeatureMismatch, result );

        /* Check if TBX_FEATURE_TYPE_TRANSCODING feature is enabled */
        if( pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_TRANSCODING] == 0 )
            SET_FEATURE_MISMATCH_AND_RESULT( TBX_FEATURE_TYPE_TRANSCODING, af32FeatureMismatch, result );

        /*---------------------------------------------------------------------------------------------------------------------------
    	 |  Check per Trunk configuration/license mismatch
    	 *--------------------------------------------------------------------------------------------------------------------------*/
    	sprintf( pszLogBufferTrunkConfig, "\tTrunk configuration unmatching license features:\n\t\t" );
        /* Cycle through all trunk configurations */
    	for (un32AdapIdx=0; un32AdapIdx<TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32AdapIdx++)
    	{
    	    TBX_BOOL    fMismatch = TBX_FALSE;
			memset(szTrunkLine, '\0', sizeof(szTrunkLine));
    	    pTrunkInfo = &pAdapterInfo->aTrunkInfo[un32AdapIdx];

            /* Check if trunk is configured */
    	    if( pTrunkInfo->TrunkConfiguration.Type > TB640_TRUNK_TYPE_FIRST )
    	    {
                /* Count this trunk type */
                aun32TrunkCount[pTrunkInfo->TrunkConfiguration.Type]++;
                /* Retreive feature Id associated to that trunk type */
    	        un32FeatureId = g_au32TrunkTypeToFeatureId[pTrunkInfo->TrunkConfiguration.Type];

                /* Check Trunk Type */
    	        if( pAdapterInfo->aun32FeatureEnabled[un32FeatureId] == 0 )
    	        {
    	            /* Trunk type doesn't match the licence feature */
    	            SET_TRUNK_MISMATCH_AND_RESULT( un32FeatureId, af32FeatureMismatch, result, fMismatch );
    	            if( (pszToken = TB640FskGetTokenString( g_aParseTrunkTypes, pTrunkInfo->TrunkConfiguration.Type )) )
    	                sprintf( szTrunkLine, "%s ", pszToken );
    	        }
    	    }

    	    if( fMismatch )
    	    {
    	        /* Print szTrunkLine in trunk config buffer */
    	        sprintf( pszLogBufferTrunkConfig, "%sTRUNK.%-3d : %-12s", pszLogBufferTrunkConfig, un32AdapIdx, szTrunkLine );
    	        if( !(++u32NbTrunkPrint % 2) )
    	            sprintf( pszLogBufferTrunkConfig, "%s\n\t\t", pszLogBufferTrunkConfig);
    	        fTrunkMismatch = TBX_TRUE;
    	    }
    	}
    	sprintf( pszLogBufferTrunkConfig, "%s\n", pszLogBufferTrunkConfig);


    	/* Validate the total number of configured trunk according to the TBX_FEATURE_TYPE_MAX_TRUNK license feature */
        if( pAdapterInfo->un32NbTrunk > pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_MAX_TRUNK] )
        {
			pAdapterInfo->un32NbTrunk = pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_MAX_TRUNK];
        }

    	/* Validate the number of configured trunk per type according to license feature */
    	for (un32AdapIdx=TB640_TRUNK_TYPE_E1; un32AdapIdx<TB640_TRUNK_TYPE_LAST; un32AdapIdx++)
    	{
    	    /* Retreive feature Id associated to that trunk type */
    	    un32FeatureId = g_au32TrunkTypeToFeatureId[un32AdapIdx];
            if( aun32TrunkCount[un32AdapIdx] > pAdapterInfo->aun32FeatureEnabled[un32FeatureId] )
            {
                SET_FEATURE_MISMATCH_AND_RESULT( un32FeatureId, af32FeatureMismatch, result );
                if( (pszToken = FeatureTypeToString(un32FeatureId)) )
                {
                    sprintf(    pszLogBufferTrunkConfig, "%s\t\t%d %s > %s\n",
                                pszLogBufferTrunkConfig,
                                aun32TrunkCount[un32AdapIdx],
                                g_apszTrunkTypeString[un32AdapIdx],
                                pszToken );
                }
            }
        }

        /* Check if TBX_FEATURE_TYPE_TONE_GENERATION, TBX_FEATURE_TYPE_TONE_DETECTION and TBX_FEATURE_TYPE_TONE_SUPPRESSION
           feature are enabled */
        /* Calculate max number of channel needed for Tone Detection/Generation */
        /* TB640_TRUNK_TYPE_E1 */
        un32NbChannel += (30 * g_au32TrunkTypeToFeatureId[TB640_TRUNK_TYPE_E1]);
        /* TB640_TRUNK_TYPE_T1 */
        un32NbChannel += (24 * g_au32TrunkTypeToFeatureId[TB640_TRUNK_TYPE_T1]);
        /* TB640_TRUNK_TYPE_J1 */
        un32NbChannel += (24 * g_au32TrunkTypeToFeatureId[TB640_TRUNK_TYPE_J1]);
        if( un32NbChannel > pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_TONE_GENERATION] )
        {
            SET_FEATURE_MISMATCH_AND_RESULT( TBX_FEATURE_TYPE_TONE_GENERATION, af32FeatureMismatch, result );
            sprintf(    pszLogBufferTrunkConfig, "%s\t\t%d total timeslot > TBX_FEATURE_TYPE_TONE_GENERATION\n",
                        pszLogBufferTrunkConfig,
                        pAdapterInfo->un32NbTrunk );
        }
        if( un32NbChannel > pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_TONE_DETECTION] )
        {
            SET_FEATURE_MISMATCH_AND_RESULT( TBX_FEATURE_TYPE_TONE_DETECTION, af32FeatureMismatch, result );
            sprintf(    pszLogBufferTrunkConfig, "%s\t\t%d total timeslot > TBX_FEATURE_TYPE_TONE_DETECTION\n",
                        pszLogBufferTrunkConfig,
                        pAdapterInfo->un32NbTrunk );
        }
        if( un32NbChannel > pAdapterInfo->aun32FeatureEnabled[TBX_FEATURE_TYPE_TONE_SUPPRESSION] )
        {
            SET_FEATURE_MISMATCH_AND_RESULT( TBX_FEATURE_TYPE_TONE_SUPPRESSION, af32FeatureMismatch, result );
            sprintf(    pszLogBufferTrunkConfig, "%s\t\t%d total timeslot > TBX_FEATURE_TYPE_TONE_SUPPRESSION\n",
                        pszLogBufferTrunkConfig,
                        pAdapterInfo->un32NbTrunk );
        }

    	/*---------------------------------------------------------------------------------------------------------------------------
         |  Print the unmatching feature into the license feature log buffer
         *--------------------------------------------------------------------------------------------------------------------------*/
        if( result == TBX_RESULT_NOT_SUPPORTED_BY_LICENSE )
        {
            sprintf( pszLogBufferLicenseFeature, "%s\tLicence features unmatching configuration:\n", pszLogBufferLicenseFeature);
        	for( un32AdapIdx=0; un32AdapIdx<TBX_FEATURE_TYPE_LAST; un32AdapIdx++ )
        	{
        	    if( af32FeatureMismatch[un32AdapIdx] )
        	    {
        	        if( (pszToken = FeatureTypeToString(un32AdapIdx)) )
        	        {
        	            sprintf( pszLogBufferLicenseFeature, "%s\t\t%s=%d\n",
						         pszLogBufferLicenseFeature,
								 pszToken,
								 pAdapterInfo->aun32FeatureEnabled[un32AdapIdx] );
					}
        	    }
        	}
        }

        /*---------------------------------------------------------------------------------------------------------------------------
         |  Logging
         *--------------------------------------------------------------------------------------------------------------------------*/
        if( (result == TBX_RESULT_NOT_SUPPORTED_BY_LICENSE) || fTrunkMismatch )
        {
            TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "%s%s", pszLogBufferLicenseFeature, pszLogBufferTrunkConfig );
        }

        /* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS(result);
    }


    ERROR_HANDLING
	{
		/* Print error message */
		TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

    /*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		if( pszLogBufferLicenseFeature ) free( pszLogBufferLicenseFeature );
		if( pszLogBufferTrunkConfig ) free( pszLogBufferTrunkConfig );
	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskOpenAdapters:	This function searches and open specified adapters in our global configuration structure
 |
 |  ~		        :	No arguments used
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskOpenAdapters (void)
{
	TBX_RESULT							result;
	TBX_FILTER_PARAMS					FilterParams;
	TBX_FILTER_HANDLE					hFilter;
	TBX_MSG_HANDLE						hMsg;
	TBX_BOOL							afAdapterUsed [TB640_FSK_MAX_ADAPTER_DISCOVERED];
	TBX_ADAPTER_HANDLE					aAdapters [TB640_FSK_MAX_ADAPTER_DISCOVERED];
	TBX_CHAR							aszAdapterName [TB640_FSK_MAX_ADAPTER_DISCOVERED][TBX_API_NAME_MAX_LEN];
	TBX_UINT							nAdapters;
	TBX_UINT32							un32StartTimeMsec;
	TBX_UINT32							un32TimeMsec;
	TBX_UINT32							un32AdapterLeftToDiscover;
	TBX_UINT32							un32AdapIdx;
	TBX_UINT32							un32TrunkIdx;
	#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
	TBX_HOST_INFO						Info;
	#else
	TBX_UINT64							un64UniqueID;
	TBX_ADAPTER_INFO					Info;
	TBX_UINT32							un32ExpectedNbResponse;
	#endif
	PTB640_FSK_ADAPTER_INFO				pAdapterInfo;
	PTB640_MSG_ADAPTER_OP_ATTACH		pMsg;
	PTB640_REQ_ADAPTER_OP_ATTACH		pReq;
	PTB640_RSP_ADAPTER_OP_ATTACH		pRsp;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		hFilter = NULL;
		hMsg = NULL;
		pMsg = NULL;
		pReq = NULL;
		pRsp = NULL;
		memset (afAdapterUsed, 0, sizeof(afAdapterUsed));
		memset (aAdapters, 0, sizeof(aAdapters));
		memset (aszAdapterName, 0, sizeof(aszAdapterName));

		TB640_FSK_LOG (TRACE_LEVEL_4, "Attaching to adapter(s)\n");

		/* Create a filter to receive ADAPTER_ADD events */
		FilterParams.un32StructVersion = 1;
		FilterParams.FilterMask = TBX_FILTER_MSG_ID;
		#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
			FilterParams.MsgId = TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ADDED;
		#else
			FilterParams.MsgId = TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED;
		#endif
		result = TBXCreateMsgFilter (g_AppContext->hTbxLib, 1, &FilterParams, &hFilter);
		if (TBX_RESULT_FAILURE (result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to create event filter");
		}

		/*-----------------------------------------------------------------------------------------------------------------------
		 | List all adapters currently known by the TBX library
		 *----------------------------------------------------------------------------------------------------------------------*/

		/* Retrieve the list of currently known adapters */
		#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
			result = TBXGetRemoteHostsList (g_AppContext->hTbxLib, TB640_FSK_MAX_ADAPTER_DISCOVERED, &nAdapters, aAdapters);
		#else
			result = TBXGetAdaptersList (g_AppContext->hTbxLib, TB640_FSK_MAX_ADAPTER_DISCOVERED, &nAdapters, aAdapters);
		#endif
		if (TBX_RESULT_FAILURE (result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve adapter list");
		}

		/* Get the name of currently known adapters */
		for (un32AdapIdx=0; un32AdapIdx<nAdapters; un32AdapIdx++)
		{
			/* Get the name of the adapter */
			#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
			{
				result = TBXGetRemoteHostInfo (g_AppContext->hTbxLib, aAdapters [un32AdapIdx], &Info);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve adapter information");
				}

				/* Keep the adapter name */
				strcpy (aszAdapterName [un32AdapIdx], Info.szHostName);
			}
			#else
			{
				result = TBXGetAdapterInfo (g_AppContext->hTbxLib, aAdapters [un32AdapIdx], &Info);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve adapter information");
				}

				/* Keep the adapter name */
				strcpy (aszAdapterName [un32AdapIdx], Info.szAdapterName);
			}
			#endif

			/* Convert in caps */
			TB640FskToUpper (aszAdapterName [un32AdapIdx]);
		}

		/*-----------------------------------------------------------------------------------------------------------------------
		 | Wait for other adapters to register dynamically
		 *----------------------------------------------------------------------------------------------------------------------*/

		/* Start the waiting loop */
		un32AdapterLeftToDiscover = g_AppContext->un32NbAdapter;
		un32TimeMsec		= 0;
		un32StartTimeMsec	= TBX_GET_TICK();
		while ((un32AdapterLeftToDiscover > 0) && (un32TimeMsec <= TB640_FSK_ADAPTER_DISCOVERY_TIMEOUT_MSEC))
		{
			printf( "  Adapter wait remaining time: %d\n", (int)( TB640_FSK_ADAPTER_DISCOVERY_TIMEOUT_MSEC - un32TimeMsec )/1000 );

			/* Cycle through all adapter configurations */
			for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)

⌨️ 快捷键说明

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