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

📄 cli.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
  IN		TBX_UINT32				in_un32StressOutgoingTimeslotMinIdleMsec,
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkNb,
  OUT		PTBX_UINT32				out_pun32TimeslotNb)
{
	TBX_BOOL									fFound;
	static TBX_UINT32							un32Adapter		= 0;
	static TBX_UINT32							un32Trunk		= 0;
	static TBX_UINT32							un32Timeslot	= 0;

	TBX_UINT32									un32DiffTime;
	TBX_UINT32									un32StartingAdapter;
	TBX_UINT32									un32StartingTrunk;
	TBX_UINT32									un32StartingTimeslot;

	PTB640_FSK_ADAPTER_INFO						pAdapterInfo;
	PTB640_FSK_TRUNK_INFO						pTrunkInfo;
	PTB640_FSK_TRUNK_RESOURCE_INFO				pTrunkResInfo;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		*out_pun32AdapterNb		= 0;
		*out_pun32TrunkNb		= 0;
		*out_pun32TimeslotNb	= 0;
		fFound = TBX_FALSE;

		/* Remember the starting point */
		un32StartingAdapter		= un32Adapter;
		un32StartingTrunk		= un32Trunk;
		un32StartingTimeslot	= un32Timeslot;

		/* Search until we find a free timeslot to use */
		do
		{

			/* Get the pointers to the structures */
			pAdapterInfo	= &(g_AppContext->ahAdapterInfo [un32Adapter]);
			pTrunkInfo		= &(pAdapterInfo->aTrunkInfo [un32Trunk]);
			pTrunkResInfo	= &(pTrunkInfo->aResourceInfo [un32Timeslot]);

			/* Make sure the resource is ready before transmitting on it */
			if (pTrunkResInfo->State == TB640_FSK_CALL_APP_STATE_READY)
			{
				/* Check if the current timeslot is valid for a new call */
				if ((pTrunkInfo->fIncludedInStressTesting == TBX_TRUE) &&
					(pTrunkResInfo->hVPResource != (TB640_RESOURCE_HANDLE)NULL))
				{
					/* Make sure the timeslot was idle long enough before selecting it */
					un32DiffTime = TBX_GET_TICK() - pTrunkResInfo->un32LastIdleTimestamp;
					if (un32DiffTime >= in_un32StressOutgoingTimeslotMinIdleMsec)
					{
						/* We found the timeslot to use */
						*out_pun32AdapterNb		= un32Adapter;
						*out_pun32TrunkNb		= un32Trunk;
						*out_pun32TimeslotNb	= un32Timeslot;
						fFound = TBX_TRUE;
					}
				}
			}

			/* Increment to the next timeslot */
			if (++un32Timeslot >= TB640_FSK_MAX_TIMESLOT_IN_TRUNK)
			{
				/* Increment to the next trunk */
				un32Timeslot = 0;
				if (++un32Trunk >= TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
				{
					/* Increment to the next adapter */
					un32Trunk = 0;
					if (++un32Adapter >= g_AppContext->un32NbAdapter)
					{
						/* Wrap around to the first adapter */
						un32Adapter = 0;
					}
				}
			}

		} while ((fFound == TBX_FALSE) &&
				 !((un32StartingAdapter == un32Adapter) && (un32StartingTrunk == un32Trunk) && (un32StartingTimeslot == un32Timeslot)));

		/* Was there a free resource to use ? */
		if (!fFound)
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "No more free resource");
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{

	}

	RETURN;
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskSelectStressParameters:	This function makes the user to select parameters for stress testing
 |
 |  out_pun32StressDelayBetweenCalls:	Delay in msec between calls
 |  out_pun32StressOutgoingTimeslotMinIdleMsec:	Minimum time an outgoing timeslot needs to stay idle
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskSelectStressParameters (
  OUT		PTBX_UINT32				out_pun32StressDelayBetweenCalls,
  OUT		PTBX_UINT32				out_pun32StressOutgoingTimeslotMinIdleMsec)
{
	TBX_BOOL										fContinue;
	TBX_BOOL										fTrunkSelectionOk;
	TBX_CHAR										szLine [TB640_FSK_CLI_MAX_LINE_SIZE_GET];
	TBX_UINT32										un32NbToken;
	TBX_UINT32										un32Adapter;
	TBX_UINT32										un32Trunk;
	PTBX_CHAR										pToken;
	PTB640_FSK_ADAPTER_INFO						pAdapterInfo;
	PTB640_FSK_TRUNK_INFO							pTrunkInfo;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		*out_pun32StressDelayBetweenCalls = 0;
		*out_pun32StressOutgoingTimeslotMinIdleMsec = 0;
		un32NbToken = 0;

		/* Display prompt */
		TB640_FSK_DISPLAY_PRINT ("Enter the delay between each call attempt (%d to ... msec): ", TB640_FSK_CLI_MIN_TIME_BETWEEN_STRESS_CALLS);

		/* Get the input from the user */
		szLine[0] = 0;
		fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32StressDelayBetweenCalls = atoi (szLine);
		if (*out_pun32StressDelayBetweenCalls < TB640_FSK_CLI_MIN_TIME_BETWEEN_STRESS_CALLS)
		{
			*out_pun32StressDelayBetweenCalls = TB640_FSK_CLI_MIN_TIME_BETWEEN_STRESS_CALLS;
		}

		/* Display prompt */
		TB640_FSK_DISPLAY_PRINT ("Enter the minimum delay for an outgoing timeslot to stay idle (0 to ... msec): ");

		/* Get the input from the user */
		szLine[0] = 0;
		fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32StressOutgoingTimeslotMinIdleMsec = atoi (szLine);

		/* Reset all adapters not to be included in stress testing */
		for (un32Adapter=0; un32Adapter<g_AppContext->un32NbAdapter; un32Adapter++)
		{
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Adapter]);

			/* Reset all trunks of the adapter not to be included in stress testing */
			for (un32Trunk = 0; un32Trunk<TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32Trunk++)
			{
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Trunk]);

				pTrunkInfo->fIncludedInStressTesting = TBX_FALSE;
			}
		}

		/* Continue to select trunks until the user decides to stop*/
		while (TBX_TRUE)
		{
			/* Make the user to select the adapter number */
			TB640_FSK_DISPLAY_PRINT ("Select adapter for which to specify trunks (-1 to exit): ");
			szLine[0] = '\0';
			fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);
			un32Adapter = atoi (szLine);

			/* Has the user finished ? */
			if (un32Adapter == (TBX_UINT32)-1)
			{
				break;
			}

			/* Validate the adapter number */
			if (un32Adapter >= g_AppContext->un32NbAdapter)
			{
				TB640_FSK_DISPLAY_PRINT ("Invalid selected adapter (%d)\n",un32Adapter);
				continue;
			}
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Adapter]);
			fTrunkSelectionOk = TBX_FALSE;
			while (fTrunkSelectionOk == TBX_FALSE)
			{
				/* Reset all trunks of the adapter not to be included in stress testing */
				for (un32Trunk = 0; un32Trunk<TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32Trunk++)
				{
					pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Trunk]);

					pTrunkInfo->fIncludedInStressTesting = TBX_FALSE;
				}

				TB640_FSK_DISPLAY_PRINT ("Select trunks in adapter %d to be included in stress (0-3,7...): ", un32Adapter);
				szLine[0] = '\0';
				fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);

				/* Parse the string */
				pToken = strtok (szLine, ",");
				fContinue = TBX_TRUE;
				while ((pToken != NULL) && fContinue)
				{
					TBX_UINT32		un32TrunkTop = 0;
					PTBX_CHAR		pSubToken;

					/* Check which trunk has been selected */
					un32Trunk = atoi (pToken);

					/* Parse the next token */
					pSubToken = strchr (pToken, '-');
					if( pSubToken++ )
						un32TrunkTop = atoi (pSubToken);
					do
					{
						/* Validate the trunk number */
						if (un32Trunk >= TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
						{
							TB640_FSK_DISPLAY_PRINT ("Invalid selected trunk (%d)\n",un32Trunk);
							fContinue = TBX_FALSE;
							continue;
						}

						/* Check if the trunk is active */
						pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Trunk]);
						if (pTrunkInfo->hTrunk == (TB640_TRUNK_HANDLE)NULL)
						{
							TB640_FSK_DISPLAY_PRINT ("Invalid selected trunk (%d)\n",un32Trunk);
							fContinue = TBX_FALSE;
							continue;
						}

						/* Include the trunk in the stress testing */
						pTrunkInfo->fIncludedInStressTesting = TBX_TRUE;
					}
					while( ++un32Trunk <= un32TrunkTop );

					/* Parse the next token */
					pToken = strtok (NULL, ",");
				}

				/* Has the parsing been completed */
				if (pToken == NULL)
				{
					fTrunkSelectionOk = TBX_TRUE;
				}
			}
		}

		/* Refresh the display */
		g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{

	}

	RETURN;
}




/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskSelectAdapterTrunkTimeslot:	This function makes the user to select an adapter, a trunk number and a timeslot
 |											number.
 |
 |  out_pun32AdapterNb:	Adapter number to display
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskSelectAdapterTrunkTimeslot (
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkFirst,
  OUT		PTBX_UINT32				out_pun32TrunkCnt,
  OUT		PTBX_UINT32				out_pun32TimeslotNb)
{
	TBX_CHAR										szLine [TB640_FSK_CLI_MAX_LINE_SIZE_GET];
	TBX_UINT32										un32NbToken;
	PTBX_CHAR										pToken;
	PTB640_FSK_ADAPTER_INFO							pAdapterInfo;
	PTB640_FSK_TRUNK_INFO							pTrunkInfo;
	PTB640_FSK_TRUNK_RESOURCE_INFO					pTrunkResInfo;
	TBX_UINT32										un32TrunkTop;
	TBX_UINT32										un32TrunkCnt;
	TBX_UINT32										un32Trunk;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		*out_pun32AdapterNb = 0;
		*out_pun32TrunkFirst = 0;
		*out_pun32TrunkCnt = 0;
		*out_pun32TimeslotNb = 0;
		un32NbToken = 0;
		un32TrunkTop = 0;
		un32TrunkCnt = 0;
		un32Trunk = 0;

		/* Display prompt */
		TB640_FSK_DISPLAY_PRINT ("Select an adapter, trunk and timeslot (a,tr,ti) ([0],[2|2-3],[1|-1]): ");

		/* Get the input from the user */
		szLine[0] = '\0';
		fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);

		/* Parse the string */
		pToken = strtok (szLine, ",");
		while ((pToken != NULL) && (un32NbToken < 3))
		{
			/* Get the arguments */
			if (un32NbToken == 0)
			{

⌨️ 快捷键说明

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