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

📄 cli.c

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

		/* Display a warning to grow the window */
		TB640_CAS_WRITE_STRING_WINDOWED (TB640_CAS_CLI_DEFAULT_LINE_SIZE, "Please, set your window size to at least 132 columns and 50 lines");
		TB640_CAS_DISPLAY_PRINT ("\n");
		TB640_CAS_WRITE_STRING_WINDOWED (TB640_CAS_CLI_DEFAULT_LINE_SIZE, "Turn your NUMLOCK to ON");
		TB640_CAS_DISPLAY_PRINT ("\n");
#ifndef WIN32
		TB640_CAS_WRITE_STRING_WINDOWED (TB640_CAS_CLI_DEFAULT_LINE_SIZE, "Be sure ANSI codes are activated on your terminal");
		TB640_CAS_DISPLAY_PRINT ("\n");
#endif /* !WIN32 */
		if (!g_AppContext->fTestModeActivated)
		{
			TBXCliGetchRemapped ();
		}
		if (!g_AppContext->fDisplayInhibited)
		{
			TBXCliCls ();
		}

		/* Print all error/status into a dedicated window from now on */
		g_fPrintInErrorBuffer = TBX_TRUE;

		/* CLI main-loop */
		while (g_fExit == TBX_FALSE)
		{
			TBX_UINT32		un32ElapsedMs;
			TBX_BOOL        fKeyPressed;
			TBX_CHAR        cKeyPressed;

			/* Sleep a bit to avoid running this loop too often (sucks CPU too much going through
			   all the resources too many times for nothing.. once every 10ms is way enough!) */
			TBX_SLEEP_MS( 10 );

			/* Update the running timer */
			un32Timer = TBX_GET_TICK();

			/* Only refresh if asked to */
			if (g_fRefreshDisplay)
			{
				/* Do not refresh more than once per second */
				un32ElapsedMs = un32Timer - un32LastTimeARefreshWasMade;
				un32ElapsedMs *= TBX_MSEC_PER_TICKS;
				if
				(
					(un32ElapsedMs >= g_AppContext->un32MinRefreshDelayMsec) ||
					(g_fRefreshDisplay & TB640_CAS_CLI_FORCE_REFRESH)
				)
				{
					/* Display is being refreshed */
					un32LastTimeARefreshWasMade = un32Timer;

					/* Do we need to clear the screen completely ? */
					if (!g_AppContext->fDisplayInhibited)
					{
						if (g_fRefreshDisplay & TB640_CAS_CLI_CLEAR_BEFORE_REFRESH)
						{
							TBXCliCls ();
						}
						else
						{
							TBXCliHome ();
						}
					}
					g_fRefreshDisplay = TBX_FALSE;

					/* Display the different adapter status */
					for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
					{
						TB640CasDisplayAdapterStats (un32Count);
					}

					/* Take a snapshot of the stats */
					TBX_SEM_GET (g_StressStatsSem, TBX_SEM_WAIT_FOREVER);
					memcpy ((char *)&StatsCopy, (char *)&g_StressStats, sizeof(g_StressStats));
					TBX_SEM_GIV (g_StressStatsSem);

					/* Calculate the number of calls per seconds and BHCA value */
					if (StatsCopy.un32StartTimestamp != StatsCopy.un32CurrentTimestamp)
					{
						un32TimeSinceBegInSec = ((StatsCopy.un32CurrentTimestamp - StatsCopy.un32StartTimestamp)/1000);
						if (un32TimeSinceBegInSec > 0)
						{
							un32NbCallPerSeconds = StatsCopy.un32NbCallCompleted / un32TimeSinceBegInSec;
						}
						else
						{
							un32NbCallPerSeconds = 0;
						}
					}
					else
					{
						un32NbCallPerSeconds = 0;
					}
					un32NbBHCA = un32NbCallPerSeconds * 3600;

					/* Prints the stats */
					TB640_CAS_DISPLAY_PRINT ("\n");
					TB640_CAS_DISPLAY_PRINT ("\tInstantaneous calls per sec.  : %08d              Instantaneous BHCC            : %08d\n",
						un32NbCallPerSeconds, un32NbBHCA);
					TB640_CAS_DISPLAY_PRINT ("\tCall opening successful       : %08d              Call completed                : %08d\n",
						StatsCopy.un32NbCallOpeningSuccess, StatsCopy.un32NbCallCompleted);
					TB640_CAS_DISPLAY_PRINT ("\tCall opening with out-of-res. : %08d              Call closing total            : %08d\n",
						StatsCopy.un32NbCallOpeningOutOfRes,
						StatsCopy.un32NbCallClosingTotal);
					TB640_CAS_DISPLAY_PRINT ("\tNb incoming call collision    : %08d              Nb outgoing call collision    : %08d\n",
						StatsCopy.un32NbIncomingCallCollision, StatsCopy.un32NbOutgoingCallCollision);
					TB640_CAS_DISPLAY_PRINT ("\tCall opening failure          : %08d              Nb timeout events             : %08d\n",
						StatsCopy.un32NbCallOpeningFailure, StatsCopy.un32NbTimeoutOccured);
					TB640_CAS_DISPLAY_PRINT ("\tRestart sent                  : %08d              Call opening timeslot busy    : %08d\n",
						StatsCopy.un32NbRestartAttempt, StatsCopy.un32NbCallOpeningTimeslotBusy);
					TB640_CAS_DISPLAY_PRINT ("\tNo free tmslot for stress tst : %08d              Nb elapsed sec. since start   : %08d\n",
						StatsCopy.un32NbCallNoFreeTimeslotToOpen, ((StatsCopy.un32CurrentTimestamp - StatsCopy.un32StartTimestamp) / 1000));
					TB640_CAS_DISPLAY_PRINT ("\tNb incoming call refusal      : %08d              \n",
						StatsCopy.un32NbIncomingCallRefusal);

					TB640_CAS_DISPLAY_PRINT ("\n");

					/* Display menu */
					TB640_CAS_DISPLAY_PRINT ("Options:\n");
					TB640_CAS_DISPLAY_PRINT ("\t(M)ake a new call                                     (T)erminate an existing call\n");
					TB640_CAS_DISPLAY_PRINT ("\t(C)lear all calls                                     (A)djust trace levels\n");
					TB640_CAS_DISPLAY_PRINT ("\t(B)egin automatic call generation                     (S)top automatic call generation\n");
					TB640_CAS_DISPLAY_PRINT ("\t(P)rint timeslot history                              (R)estart timeslot\n");
					TB640_CAS_DISPLAY_PRINT ("\t(U)nblock trunk(s)                                    (F)lush log file\n");
					TB640_CAS_DISPLAY_PRINT ("\t($)Print stack stats                                  (D) Toggle 'refuse' incoming calls\n");
					TB640_CAS_DISPLAY_PRINT ("\t(I) Change expected nb. of incoming digits\n");
					TB640_CAS_DISPLAY_PRINT ("\t(Q)uit\n");
					TB640_CAS_DISPLAY_PRINT ("\n");

					/* Display status strings */
					TB640_CAS_WRITE_STRING_CENTERED (ULS, URS, MS, TB640_CAS_CLI_MAX_LINE_SIZE, "Status window");
					TB640_CAS_DISPLAY_PRINT ("\n");
					TBX_SEM_GET (g_AppContext->DisplaySem, TBX_SEM_WAIT_FOREVER);
					un32Count=0;
					un32OldReadIndex = g_un32ErrorLineReadIndex;
					while ((un32Count < TB640_CAS_CLI_MAX_NB_ERROR_LINES_VIEWED) &&
						   (un32OldReadIndex != g_un32ErrorLineWriteIndex))
					{
						if (strlen((PTBX_CHAR)g_aszErrorLines[un32OldReadIndex]) > 0)
						{
							TB640_CAS_DISPLAY_PRINT (TB640_CAS_CLI_LINE_DISPLAY_STRING, g_aszErrorLines[un32OldReadIndex]);
						}
						else
						{
							TB640_CAS_DISPLAY_PRINT (TB640_CAS_CLI_LINE_DISPLAY_STRING, " ");
						}
						un32Count++;
						if (++un32OldReadIndex >= TB640_CAS_CLI_MAX_NB_ERROR_LINES)
						{
							un32OldReadIndex = 0;
						}
					}
					TBX_SEM_GIV (g_AppContext->DisplaySem);
					while (un32Count < TB640_CAS_CLI_MAX_NB_ERROR_LINES_VIEWED)
					{
						TB640_CAS_DISPLAY_PRINT (TB640_CAS_CLI_LINE_DISPLAY_STRING, " ");
						un32Count++;
					}
					TB640_CAS_DISPLAY_PRINT ("\n");
					TB640_CAS_WRITE_LINE(ULS, URS, MS, TB640_CAS_CLI_MAX_LINE_SIZE);
					TB640_CAS_DISPLAY_PRINT ("\n");
				}
			}

			/* Update the screen every seconds minimum when doing the stress testing */
			if (((un32Timer / 1000) > un32TimerSec) && (fAutomaticCallGenerationActivated))
			{
				g_fRefreshDisplay |= (TB640_CAS_CLI_REFRESH_DISPLAY);
			}
			un32TimerSec = (un32Timer / 1000);

			/* Update the statistic timestamps */
			TB640_CAS_UPDATE_STATS (un32CurrentTimestamp, un32Timer);

			/* Check if a key was pressed */
			if (g_AppContext->fTestModeActivated)
			{
				fKeyPressed = g_AppContext->fKeyPressed;
				cKeyPressed = g_AppContext->cKey;
				g_AppContext->fKeyPressed = TBX_FALSE;
			}
			else
			{
				fKeyPressed = TBXCliKeyboardHit();
				if (fKeyPressed)
				{
					cKeyPressed = TBXCliGetchRemapped();
				}
			}
  	 			/* Is there a key stroke ? */
			if (fKeyPressed)
			{
				/* Check what key was pressed */
				nOption = cKeyPressed;
				nOption = toupper (nOption);

				/* Process the key */
				switch (nOption)
				{

				/* (M)ake a new call */
				case 'M':
					Result = TB640CasSelectAdapterTrunkTimeslot (&un32Adapter, &un32Trunk, &un32Timeslot);
					if (TBX_RESULT_SUCCESS(Result))
					{
						Result = TB640CasChangeNumbers (un32Adapter, un32Trunk);
						if (TBX_RESULT_SUCCESS(Result))
						{					
							TB640CasMakeCall (un32Adapter, un32Trunk, un32Timeslot, TBX_ASYNC_NO_TIMEOUT, TBX_ASYNC_NO_TIMEOUT);
							g_fRefreshDisplay |= (TB640_CAS_CLI_CLEAR_BEFORE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY);
						}
					}
					break;

				/* (T)erminate an existing call */
				case 'T':
					Result = TB640CasSelectAdapterTrunkTimeslot (&un32Adapter, &un32Trunk, &un32Timeslot);
					if (TBX_RESULT_SUCCESS(Result))
					{
						TB640CasTerminateCall (un32Adapter, un32Trunk, un32Timeslot);
						g_fRefreshDisplay |= (TB640_CAS_CLI_CLEAR_BEFORE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY);
					}
					break;

				/* (C)lear all calls */
				case 'C':
					Result = TB640CasSelectAdapterTrunk (&un32Adapter, &un32Trunk);
					if (TBX_RESULT_SUCCESS(Result))
					{
						TB640CasTerminateAllCall (un32Adapter, un32Trunk);
						g_fRefreshDisplay |= (TB640_CAS_CLI_CLEAR_BEFORE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY);
					}
					break;

				/* Change expected number of expected digits */
				case 'I':
					Result = TB640CasChangeNbExpectedDigits();
					if (TBX_RESULT_SUCCESS(Result))
					{
						g_fRefreshDisplay |= (TB640_CAS_CLI_CLEAR_BEFORE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY);
					}
					break;

				/* Toggle 'refuse incoming calls' */
				case 'D':
					for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
					{
						g_AppContext->ahAdapterInfo [un32Count].fRefuseIncomingCalls = ~(g_AppContext->ahAdapterInfo [un32Count].fRefuseIncomingCalls);
						TB640_CAS_DISPLAY_PRINT ("Adapter %d is now %s calls\n", un32Count, (g_AppContext->ahAdapterInfo [un32Count].fRefuseIncomingCalls?"refusing":"accepting"));
					}
					break;

				/* (U)nblock trunk(s) */
				case 'U':
					Result = TB640CasSelectAdapterTrunk (&un32Adapter, &un32Trunk);
					if (TBX_RESULT_SUCCESS(Result))
					{
						TB640CasUnblockTrunks (un32Adapter, un32Trunk);
						g_fRefreshDisplay |= (TB640_CAS_CLI_CLEAR_BEFORE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY);
					}
					break;

				/* (B)egin automatic call generation */
				case 'B':

					if (fAutomaticCallGenerationActivated == TBX_FALSE)
					{
						/* During auto-test, the arguments are already known */
						if (g_AppContext->fTestModeActivated)
						{
							TBX_BOOL					fValid;
							TBX_CHAR					szTrunkCfg [128];
							TBX_INT32					n32AdapterNb;
							PTB640_CAS_ADAPTER_INFO		pAdapterInfo;

							/* Parse parameters from the test controller script */
							Result = TBX_RESULT_OK;
							un32StressDelayBetweenCalls = (TBX_UINT32)-1;
							sscanf (g_AppContext->szTestArguments, TB640_CAS_TEST_STRESS_TEST_ARGUMENTS,
								&un32StressDelayBetweenCalls,
								&un32StressMinCallDuration,
								&un32StressMaxCallDuration,
								&un32StressDelayBetweenRestart,
								&un32StressOutgoingTimeslotMinIdleMsec,
								&n32AdapterNb,
								szTrunkCfg);

							/* Check the adapter number */
							if ((TBX_UINT32)n32AdapterNb >= g_AppContext->un32NbAdapter)
							{
								TB640_CAS_DISPLAY_PRINT ("Invalid adapter selected (%d)\n", n32AdapterNb);
								Result = TBX_RESULT_FAIL;
							}
							else
							{
								pAdapterInfo = &(g_AppContext->ahAdapterInfo [n32AdapterNb]);

								/* Parse the trunk selection */
								TB640CasParseTrunkSelection (pAdapterInfo, szTrunkCfg, &fValid);
								if (!fValid)
								{
									TB640_CAS_DISPLAY_PRINT ("Invalid parameters for stress-test\n");
									Result = TBX_RESULT_FAIL;
								}
							}
						}
						else
						{
							/* Ask the user information */
							Result = TB640CasSelectStressParameters (&un32StressDelayBetweenCalls, &un32StressMinCallDuration, &un32StressMaxCallDuration, &un32StressDelayBetweenRestart, &un32StressOutgoingTimeslotMinIdleMsec);
						}



						if (TBX_RESULT_SUCCESS(Result))
						{
							TB640_CAS_LOG (TRACE_LEVEL_4, "Starting stress testing (delay=%d, mincd=%d, maxcd=%d, rstrtdelay=%d, minidlemsec=%d)\n", \
							  un32StressDelayBetweenCalls, un32StressMinCallDuration, un32StressMaxCallDuration, un32StressDelayBetweenRestart, un32StressOutgoingTimeslotMinIdleMsec);

							/* Take a new time snapshot */
							un32Timer = TBX_GET_TICK();

							/* Clear the statistics */
							TBX_SEM_GET (g_StressStatsSem, TBX_SEM_WAIT_FOREVER);
							memset ((char *)&g_StressStats, 0, sizeof(g_StressStats));
							g_StressStats.un32StartTimestamp = un32Timer;
							g_StressStats.un32CurrentTimestamp = un32Timer;
							g_StressStats.fStatsActivated = TBX_TRUE;
							TBX_SEM_GIV (g_StressStatsSem);

							/* Start the test */
							un32LastTimeWhereACallWasMade = un32Timer;
							un32LastTimeWhereARestartWasMade = un32Timer;
							fAutomaticCallGenerationActivated = TBX_TRUE;

							g_fRefreshDisplay |= (TB640_CAS_CLI_CLEAR_BEFORE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY | TB640_CAS_CLI_FORCE_REFRESH);
						}
					}
					else
					{
						TB640_CAS_DISPLAY_PRINT ("Automatic call generation is already activated....\n");
					}
					break;

				/* (S)top automatic call generation */
				case 'S':
					if (fAutomaticCallGenerationActivated != TBX_FALSE)
					{
						TBX_SEM_GET (g_StressStatsSem, TBX_SEM_WAIT_FOREVER);
						g_StressStats.fStatsActivated = TBX_FALSE;

						/* Prints the stats */

⌨️ 快捷键说明

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