📄 cli.c
字号:
TB640IsdnUnlockFromOpLibIdx( pAdapterInfo, i );
}
}
return ( fOpActiveListEmpty && fOpTimeoutListEmpty );
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnCli : This function starts the client interface and also contains the main loop.
|
| ~ : No arguments used
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnCli (void)
{
TBX_RESULT Result;
TBX_BOOL fAutomaticCallGenerationActivated;
TBX_BOOL fUseOverlapMode;
TBX_INT nOption;
TBX_UINT8 un8Digit;
TBX_UINT8 un8NbDigit;
TBX_UINT32 un32OldReadIndex;
TBX_UINT32 un32Count;
TBX_UINT32 un32Adapter;
TBX_UINT32 un32Trunk;
TBX_UINT32 un32Timeslot;
TBX_INT32 n32SStressNbCallToPerform = -1;
TBX_UINT32 un32StressDelayBetweenCalls;
TBX_UINT32 un32StressDelayBetweenRestart;
TBX_UINT32 un32StressMinCallDuration;
TBX_UINT32 un32StressMaxCallDuration;
TBX_UINT32 un32StressOutgoingTimeslotMinIdleMsec;
TBX_UINT32 un32Timer;
TBX_UINT32 un32TimerSec;
TBX_UINT32 un32LastTimeARefreshWasMade;
TBX_UINT32 un32LastTimeWhereACallWasMade;
TBX_UINT32 un32LastTimeWhereARestartWasMade;
TBX_UINT32 un32NbCallPerSeconds;
TBX_UINT32 un32NbBHCA;
TBX_UINT32 un32TimeSinceBegInSec;
TB640_ISDN_STRESS_STATS StatsCopy;
TB640_ISDN_BCHANNEL_STATUS State;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
fAutomaticCallGenerationActivated = TBX_FALSE;
un32Timer = TBX_GET_TICK();
un32LastTimeARefreshWasMade = un32Timer;
un32TimerSec = (un32Timer / 1000);
un32LastTimeARefreshWasMade = 0;
un32LastTimeWhereACallWasMade = 0;
un32LastTimeWhereARestartWasMade = 0;
un32NbCallPerSeconds = 0;
un32NbBHCA = 0;
/* Display a warning to grow the window */
TB640_ISDN_WRITE_STRING_WINDOWED (TB640_ISDN_CLI_DEFAULT_LINE_SIZE, "Please, set your window size to at least 132 columns and 50 lines");
TB640_ISDN_DISPLAY_PRINT ("\n");
TB640_ISDN_WRITE_STRING_WINDOWED (TB640_ISDN_CLI_DEFAULT_LINE_SIZE, "Turn your NUMLOCK to ON");
TB640_ISDN_DISPLAY_PRINT ("\n");
#ifndef WIN32
TB640_ISDN_WRITE_STRING_WINDOWED (TB640_ISDN_CLI_DEFAULT_LINE_SIZE, "Be sure ANSI codes are activated on your terminal");
TB640_ISDN_DISPLAY_PRINT ("\n");
#endif /* !WIN32 */
TBXCliGetchRemapped ();
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;
/* 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 <configurable> times per seconds */
un32ElapsedMs = un32Timer - un32LastTimeARefreshWasMade;
un32ElapsedMs *= TBX_MSEC_PER_TICKS;
if
(
(un32ElapsedMs >= g_AppContext->un32MinRefreshDelayMsec) ||
(g_fRefreshDisplay & TB640_ISDN_CLI_FORCE_REFRESH)
)
{
/* Display is being refreshed */
un32LastTimeARefreshWasMade = un32Timer;
/* Do we need to clear the screen completely ? */
if (g_fRefreshDisplay & TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH)
{
TBXCliCls ();
}
else
{
TBXCliHome ();
}
g_fRefreshDisplay = TBX_FALSE;
/* Display the different adapter status */
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
TB640IsdnDisplayAdapterStats (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;
/* Print Legend */
TB640_ISDN_DISPLAY_PRINT ("Legend:\n");
if (g_AppContext->fDisplayBChannelStates)
{
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FMAGEN, TB640_ISDN_TRUNK_BCHANNEL_STATE_IN_SERVICE, DEFAULT_COLOR, "In-service" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FYELLOW, TB640_ISDN_TRUNK_BCHANNEL_STATE_MAINTENANCE, DEFAULT_COLOR, "Maintenance" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FRED, TB640_ISDN_TRUNK_BCHANNEL_STATE_OUT_OF_SERVICE, DEFAULT_COLOR, "Out-of-service" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s\n", FYELLOW, TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_UP, DEFAULT_COLOR, "Framing up" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FBLUE, TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_DOWN, DEFAULT_COLOR, "Framing down" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FMAGEN, TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_UP, DEFAULT_COLOR, "Link up" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FCYAN, TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_DOWN, DEFAULT_COLOR, "Link down" );
TB640_ISDN_DISPLAY_PRINT ("\n\n");
}
else
{
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FRED, TB640_ISDN_TRUNK_RESOURCE_STATE_IDLE, DEFAULT_COLOR, "Idle" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FBLUE, TB640_ISDN_TRUNK_RESOURCE_STATE_OPENING_INCOMING, DEFAULT_COLOR, "Opening incoming" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FYELLOW, TB640_ISDN_TRUNK_RESOURCE_STATE_OPENING_OUTGOING, DEFAULT_COLOR, "Opening outgoing" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s\n", FGREEN, TB640_ISDN_TRUNK_RESOURCE_STATE_CONNECTING, DEFAULT_COLOR, "Connecting" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FMAGEN, TB640_ISDN_TRUNK_RESOURCE_STATE_ACTIVE, DEFAULT_COLOR, "Active" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FCYAN, TB640_ISDN_TRUNK_RESOURCE_STATE_DISCONNECTING, DEFAULT_COLOR, "Disconnecting" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FWHITE, TB640_ISDN_TRUNK_RESOURCE_STATE_CLOSING, DEFAULT_COLOR, "Closing" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s\n", FRED, TB640_ISDN_TRUNK_RESOURCE_STATE_RESTARTING, DEFAULT_COLOR, "Restarting" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FGREEN, TB640_ISDN_TRUNK_RESOURCE_STATE_CONDEMNED, DEFAULT_COLOR, "Condemned" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FYELLOW, TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_UP, DEFAULT_COLOR, "Framing up" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FBLUE, TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_DOWN, DEFAULT_COLOR, "Framing down" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s\n", FMAGEN, TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_UP, DEFAULT_COLOR, "Link up" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FCYAN, TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_DOWN, DEFAULT_COLOR, "Link down" );
TB640_ISDN_DISPLAY_PRINT ("\t%s%c%s %-20s", FWHITE, TB640_ISDN_TRUNK_RESOURCE_STATE_NOT_USED, DEFAULT_COLOR, "Not used" );
}
TB640_ISDN_DISPLAY_PRINT ("\n\n");
/* Prints the stats */
TB640_ISDN_DISPLAY_PRINT ("Statistics:\n");
TB640_ISDN_DISPLAY_PRINT ("\tInstantaneous calls per sec. : %08d Instantaneous BHCC : %08d\n",
un32NbCallPerSeconds, un32NbBHCA);
TB640_ISDN_DISPLAY_PRINT ("\tCall opening successful : %08d Call completed : %08d\n",
StatsCopy.un32NbCallOpeningSuccess, StatsCopy.un32NbCallCompleted);
TB640_ISDN_DISPLAY_PRINT ("\tCall opening with out-of-res. : %08d Call closing total : %08d\n",
StatsCopy.un32NbCallOpeningOutOfRes,
StatsCopy.un32NbCallClosingTotal);
TB640_ISDN_DISPLAY_PRINT ("\tNb incoming call collision : %08d Nb outgoing call collision : %08d\n",
StatsCopy.un32NbIncomingCallCollision, StatsCopy.un32NbOutgoingCallCollision);
TB640_ISDN_DISPLAY_PRINT ("\tCall opening failure : %08d Nb timeout events : %08d\n",
StatsCopy.un32NbCallOpeningFailure, StatsCopy.un32NbTimeoutOccured);
TB640_ISDN_DISPLAY_PRINT ("\tRestart sent : %08d Reset sent : %08d\n",
StatsCopy.un32NbRestartAttempt, StatsCopy.un32NbResetAttempt);
TB640_ISDN_DISPLAY_PRINT ("\tNb free tmslot for stress tst : %08d Nb elapsed sec. since start : %08d\n",
StatsCopy.un32NbCallNoFreeTimeslotToOpen, ((StatsCopy.un32CurrentTimestamp - StatsCopy.un32StartTimestamp) / 1000));
TB640_ISDN_DISPLAY_PRINT ("\tNb calls left : %08d\n", (n32SStressNbCallToPerform == -1) ? 0 : n32SStressNbCallToPerform );
TB640_ISDN_DISPLAY_PRINT ("\n");
/* Display menu */
TB640_ISDN_DISPLAY_PRINT ("Options:\n");
TB640_ISDN_DISPLAY_PRINT ("\t(M)ake a new call (T)erminate an existing call\n");
TB640_ISDN_DISPLAY_PRINT ("\t(C)lear all calls (A)djust trace levels\n");
TB640_ISDN_DISPLAY_PRINT ("\t(B)egin automatic call generation (S)top automatic call generation\n");
TB640_ISDN_DISPLAY_PRINT ("\t(N) Answer a call (O) Toggle automatic call answering in overlap mode\n");
TB640_ISDN_DISPLAY_PRINT ("\t(P)rint timeslot history (R)estart timeslots\n");
TB640_ISDN_DISPLAY_PRINT ("\t(K)ill gateways (U)nkill gateways\n");
TB640_ISDN_DISPLAY_PRINT ("\t(D) Toggle between calls and B-chan states (E) Change B-chan state\n");
TB640_ISDN_DISPLAY_PRINT ("\t($)Print stack stats (F)lush log file\n");
TB640_ISDN_DISPLAY_PRINT ("\t(Q)uit\n");
TB640_ISDN_DISPLAY_PRINT ("\n");
/* Display status strings */
TB640_ISDN_WRITE_STRING_CENTERED (ULS, URS, MS, TB640_ISDN_CLI_MAX_LINE_SIZE, "Status window");
TB640_ISDN_DISPLAY_PRINT ("\n");
TBX_SEM_GET (g_AppContext->DisplaySem, TBX_SEM_WAIT_FOREVER);
un32Count=0;
un32OldReadIndex = g_un32ErrorLineReadIndex;
while ((un32Count < TB640_ISDN_CLI_MAX_NB_ERROR_LINES_VIEWED) &&
(un32OldReadIndex != g_un32ErrorLineWriteIndex))
{
if (strlen((PTBX_CHAR)g_aszErrorLines[un32OldReadIndex]) > 0)
{
TB640_ISDN_DISPLAY_PRINT (TB640_ISDN_CLI_LINE_DISPLAY_STRING, g_aszErrorLines[un32OldReadIndex]);
}
else
{
TB640_ISDN_DISPLAY_PRINT (TB640_ISDN_CLI_LINE_DISPLAY_STRING, " ");
}
un32Count++;
if (++un32OldReadIndex >= TB640_ISDN_CLI_MAX_NB_ERROR_LINES)
{
un32OldReadIndex = 0;
}
}
TBX_SEM_GIV (g_AppContext->DisplaySem);
while (un32Count < TB640_ISDN_CLI_MAX_NB_ERROR_LINES_VIEWED)
{
TB640_ISDN_DISPLAY_PRINT (TB640_ISDN_CLI_LINE_DISPLAY_STRING, " ");
un32Count++;
}
TB640_ISDN_DISPLAY_PRINT ("\n");
TB640_ISDN_WRITE_LINE(ULS, URS, MS, TB640_ISDN_CLI_MAX_LINE_SIZE);
TB640_ISDN_DISPLAY_PRINT ("\n");
}
}
/* Update the screen every seconds minimum when doing the stress testing */
if (((un32Timer / 1000) > un32TimerSec) && (fAutomaticCallGenerationActivated))
{
g_fRefreshDisplay |= TB640_ISDN_CLI_REFRESH_DISPLAY;
}
un32TimerSec = (un32Timer / 1000);
/* Update the statistic timestamps */
TB640_ISDN_UPDATE_STATS (un32CurrentTimestamp, un32Timer);
/* Is there a key stroke ? */
if (TBXCliKeyboardHit())
{
/* Check what key was pressed */
nOption = TBXCliGetchRemapped();
/* Process the key */
switch (nOption)
{
/* (M)ake a new call */
case 'M':
Result = TB640IsdnSelectAdapterTrunkTimeslotAndOverlap (&un32Adapter, &un32Trunk, &un32Timeslot, &fUseOverlapMode);
if (TBX_RESULT_SUCCESS(Result))
{
/* Collect overlap digits */
if (fUseOverlapMode)
{
/* Enter number */
un8NbDigit = 0;
TB640_ISDN_DISPLAY_PRINT ("Enter all digits (CR to finish): " );
while (TBX_TRUE)
{
while( !TBXCliKeyboardHit() )
{
TBX_SLEEP_MS(10);
}
/* Get the input from the user */
un8Digit = TBXCliGetchRemapped();
if( un8Digit == '\n' || un8Digit == '\r' || un8Digit == '#')
{
/* Send the 'sending complete' signal */
TB640IsdnEnterNewDigit (un32Adapter, un32Trunk, un32Timeslot, '#');
g_fRefreshDisplay |= (TB640_ISDN_CLI_REFRESH_DISPLAY | TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH);
break;
}
if( (un8Digit < '0' || un8Digit > '9') && un8Digit != '-' )
{
continue;
}
TB640_ISDN_DISPLAY_PRINT ("%c", un8Digit );
if( un8Digit == '-' )
{
continue;
}
/* Is this the first digit we send ? */
if (un8NbDigit == 0)
{
TB640IsdnMakeCall (un32Adapter, un32Trunk, un32Timeslot, TBX_ASYNC_NO_TIMEOUT, TBX_ASYNC_NO_TIMEOUT, fUseOverlapMode, un8Digit);
}
else
{
/* Send the digit to the state machine */
TB640IsdnEnterNewDigit (un32Adapter, un32Trunk, un32Timeslot, un8Digit);
}
/* We received one more digit */
un8NbDigit++;
/* Refresh the display */
g_fRefreshDisplay |= TB640_ISDN_CLI_REFRESH_DISPLAY;
}
}
else
{
TB640IsdnMakeCall (un32Adapter, un32Trunk, un32Timeslot, TBX_ASYNC_NO_TIMEOUT, TBX_ASYNC_NO_TIMEOUT, fUseOverlapMode, 0);
g_fRefreshDisplay |= (TB640_ISDN_CLI_REFRESH_DISPLAY | TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -