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

📄 cli.c

📁 telcobridges cas develop
💻 C
📖 第 1 页 / 共 5 页
字号:
						}

						/* Send the restart */
						Result = TB640CasSelectCallForAutomaticRestart(&un32Adapter, &un32Trunk, &un32Timeslot);
						if (TBX_RESULT_SUCCESS(Result))
						{
							TB640CasRestartTimeslot (un32Adapter, un32Trunk, un32Timeslot);
						}

						/* Wait until next time delay is expired before restarting another timeslot */
						un32LastTimeWhereARestartWasMade += un32StressDelayBetweenRestart;
					}
				}
			}
		}

		/* Print all error/status on the standard output from now on */
		g_fPrintInErrorBuffer = TBX_FALSE;

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_CAS_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
	{
		TBXCliCls ();
		TB640_CAS_DISPLAY_PRINT ("Exiting from the application\n\n");
	}

	RETURN;
}


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Utility functions
 *------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasAdjustTraceLevel:	This function makes the user to select new trace levels
 |
 |  out_pun32FileLogLevel:	File log level selected by the user
 |	out_pun32DisplayLogLevel:	Display log level selected by the user
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasAdjustTraceLevel (
  OUT		PTBX_UINT32				out_pun32FileLogLevel,
  OUT		PTBX_UINT32				out_pun32DisplayLogLevel)
{
	TBX_CHAR										szLine [TB640_CAS_CLI_MAX_LINE_SIZE_GET];

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		*out_pun32FileLogLevel = 0;
		*out_pun32DisplayLogLevel = 0;

		/* Display prompt */
		TB640_CAS_DISPLAY_PRINT ("Enter the FILE log level (0=loud, 5=light): ");

		/* Get the input from the user */
		fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32FileLogLevel = atoi (szLine);
		if (*out_pun32FileLogLevel > 5)
		{
			*out_pun32FileLogLevel = 5;
		}

		/* Display prompt */
		TB640_CAS_DISPLAY_PRINT ("Enter the DISPLAY log level (0=loud, 5=light): ");

		/* Get the input from the user */
		fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32DisplayLogLevel = atoi (szLine);
		if (*out_pun32DisplayLogLevel > 5)
		{
			*out_pun32DisplayLogLevel = 5;
		}

		/* Refresh the display */
		g_fRefreshDisplay |= (TB640_CAS_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;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasSelectCallForAutomaticCall:	This function automatically selects the next timeslot to use for automatic call
 |											generation
 |
 |	in_un32StressOutgoingTimeslotMinIdleMsec:	Minimum time a timeslot needs to be idle before selection for an outgoing call
 |  out_pun32AdapterNb:	Adapter number to use
 |  out_pun32TrunkNb:	Trunk number to use
 |	out_pun32TimeslotNb:Timeslot number to use
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasSelectCallForAutomaticCall (
  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_CAS_ADAPTER_INFO						pAdapterInfo;
	PTB640_CAS_TRUNK_INFO							pTrunkInfo;
	PTB640_CAS_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 trunk is active before making a call */
			if (pTrunkInfo->aResourceInfo [0].Statistics.State == TB640_CAS_TRUNK_RESOURCE_STATE_FRAMING_UP)
			{
				if (pTrunkResInfo->Statistics.State != TB640_CAS_TRUNK_RESOURCE_STATE_BLOCKED)
				{
					/* Check if the current timeslot is valid for a new call */
					if ((pTrunkInfo->fIncludedInStressTesting == TBX_TRUE) &&
						(pTrunkResInfo->hTrunkResource != (TB640_RESOURCE_HANDLE)NULL) &&
						(pTrunkResInfo->hCall == (TB640_CAS_CALL_HANDLE)NULL) &&
						(pTrunkResInfo->Statistics.State == TB640_CAS_TRUNK_RESOURCE_STATE_IDLE))
					{
						/* Make sure the timeslot was idle long enough before selecting it */
						un32DiffTime = TBX_GET_TICK() - pTrunkResInfo->Statistics.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_CAS_MAX_TIMESLOT_IN_TRUNK)
			{
				/* Increment to the next trunk */
				un32Timeslot = 0;
				if (++un32Trunk >= TB640_CAS_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;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasSelectCallForAutomaticRestart:	This function automatically selects the next timeslot to use for automatic restart
 |											generation
 |
 |  out_pun32AdapterNb:	Adapter number to use
 |  out_pun32TrunkNb:	Trunk number to use
 |	out_pun32TimeslotNb:Timeslot number to use
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasSelectCallForAutomaticRestart (
  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										un32StartingAdapter;
	TBX_UINT32										un32StartingTrunk;
	TBX_UINT32										un32StartingTimeslot;
	TBX_UINT32										un32DChannelIndex;

	PTB640_CAS_ADAPTER_INFO						pAdapterInfo;
	PTB640_CAS_TRUNK_INFO							pTrunkInfo;
	PTB640_CAS_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 trunk is active before making a call */
			if (pTrunkInfo->aResourceInfo [0].Statistics.State == TB640_CAS_TRUNK_RESOURCE_STATE_FRAMING_UP)
			{
				/* Make sure the D-Channel is active before making a call */
				if (pTrunkInfo->TrunkConfiguration.Type == TB640_TRUNK_TYPE_E1)
				{
					un32DChannelIndex = 16;
				}
				else
				{
					un32DChannelIndex = 24;
				}
				if (pTrunkResInfo->Statistics.State != TB640_CAS_TRUNK_RESOURCE_STATE_BLOCKED)
				{
					/* Check if the current timeslot is valid for a new call */
					if ((pTrunkInfo->fIncludedInStressTesting == TBX_TRUE) &&
						(pTrunkResInfo->hTrunkResource != (TB640_RESOURCE_HANDLE)NULL) &&
						(pTrunkResInfo->hCall != (TB640_CAS_CALL_HANDLE)NULL) &&
						(pTrunkResInfo->Statistics.State != TB640_CAS_TRUNK_RESOURCE_STATE_IDLE) &&
						(pTrunkResInfo->Statistics.State != TB640_CAS_TRUNK_RESOURCE_STATE_CONDEMNED))
					{
						/* We found the timeslot to use */
						*out_pun32AdapterNb = un32Adapter;
						*out_pun32TrunkNb = un32Trunk;
						*out_pun32TimeslotNb = un32Timeslot;
						fFound = TBX_TRUE;
					}
				}
			}

			/* Increment to the next timeslot */

⌨️ 快捷键说明

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