📄 cli.c
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
|
| Project: VoiceLink TB640 sample (CAS)
|
| Filename: cli.c
|
| Copyright: TelcoBridges 2002-2005, All Rights Reserved
|
| Description: This file contains the client interface function
|
| Notes: Tabs = 4
|
*-------------------------------------------------------------------------------------------------------------------------------
|
| Revision: $Revision: 1.30.2.1 $
|
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Includes
*------------------------------------------------------------------------------------------------------------------------------*/
/* System includes */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef WIN32
#include <conio.h>
#else
#include <termios.h>
#endif /* WIN32 */
/* Local includes */
#include "tbx_ostypes.h"
#include "tbx_id.h"
#include "tbx_result.h"
#include "tbx_msg.h"
#include "tbx_std.h"
#include "tbx_api.h"
#include "tbx_featmgr.h"
#include "tb640_id.h"
#include "tb640_handle.h"
#include "tb640_adpmgr.h"
#include "tb640_trkmgr.h"
#include "tb640_casmgr.h"
#include "tbx_os_wrapper.h"
#include "tbx_hash.h"
#include "tbx_pool_of_buffers.h"
#include "tbx_timer.h"
#include "tbxasync.h"
#include "tbx_cli.h"
#include "cas.h"
#include "prototypes.h"
#include "macros.h"
#include "tbx_auto_test.h"
/*--------------------------------------------------------------------------------------------------------------------------------
| Forward declarations
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Defines
*------------------------------------------------------------------------------------------------------------------------------*/
/* Define the width of the default applicaton screen when it starts */
#define TB640_CAS_CLI_DEFAULT_LINE_SIZE 79
/* Define the width of the CLI screen */
#define TB640_CAS_CLI_MAX_LINE_SIZE 129
#define TB640_CAS_CLI_MAX_LINE_SIZE_GET 256
/* Format string to display the status line */
#define TB640_CAS_CLI_LINE_DISPLAY_STRING "%-129s\n"
/* Define the heigth of the CLI screen */
#define TB640_CAS_CLI_MAX_LINE 49
/* Define the number of trunk column */
#define TB640_CAS_CLI_COLUMN_NB 3
/* Define the width of a trunk column */
#define TB640_CAS_CLI_COLUMN_SIZE 43
/* Minimum time between two consecutive stress-test calls (must be between 1 and 1000) */
#ifdef WIN32
#define TB640_CAS_CLI_MIN_TIME_BETWEEN_STRESS_CALLS 1 /* 1 msec = 1000 calls/sec */
#else
#define TB640_CAS_CLI_MIN_TIME_BETWEEN_STRESS_CALLS 4 /* 1 msec = 250 calls/sec */
#endif /* WIN32 */
/* The following define the ASCII character to use when displaying text graphics */
#define ULS '+' /* ASCII character Upper-Left symbol */
#define URS '+' /* ASCII character Upper-right symbol*/
#define MS '-' /* ASCII character Middle symbol */
#define LLS '+' /* ASCII character Lower-left symbol */
#define LRS '+' /* ASCII character Lower-right symbol */
#define MVS '|' /* ASCII character Middle-vertical symbol */
#define MLHS '+' /* ASCII character Middle-left-horizontal symbol */
#define MRHS '+' /* ASCII character Middle-right-horizontal symbol */
/*--------------------------------------------------------------------------------------------------------------------------------
| Types
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Versioning
*------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.30.2.1 $";
#endif
/*--------------------------------------------------------------------------------------------------------------------------------
| Global variables
*------------------------------------------------------------------------------------------------------------------------------*/
volatile TBX_BOOL g_fExit = TBX_FALSE;
volatile TBX_BOOL g_fRefreshDisplay = (TB640_CAS_CLI_FORCE_REFRESH | TB640_CAS_CLI_REFRESH_DISPLAY | TB640_CAS_CLI_CLEAR_BEFORE_REFRESH);
TBX_SEM g_StressStatsSem;
volatile TB640_CAS_STRESS_STATS g_StressStats;
volatile TBX_BOOL g_fPrintInErrorBuffer = TBX_FALSE;
volatile TBX_UINT32 g_un32ErrorLine = 0;
volatile TBX_UINT32 g_un32ErrorLineId = 0;
volatile TBX_UINT32 g_un32ErrorLineWriteIndex = 0;
volatile TBX_UINT32 g_un32ErrorLineReadIndex = 0;
volatile TBX_CHAR g_aszErrorLines [TB640_CAS_CLI_MAX_NB_ERROR_LINES+1] [TB640_CAS_CLI_MAX_ERROR_LINE_SIZE] = {{0}};
extern TBX_UINT32 g_un32NbDigitExpected;
/*--------------------------------------------------------------------------------------------------------------------------------
| Macros
*------------------------------------------------------------------------------------------------------------------------------*/
#define TB640_CAS_WRITE_LINE(__StartChar__,__EndChar__,__FillChar__,__LineLength__) \
{ \
TBX_UINT32 un32Count; \
TBX_UINT32 un32Index; \
TBX_CHAR szLine [TB640_CAS_CLI_MAX_LINE_SIZE + 1]; \
\
szLine [0] = (__StartChar__); \
un32Index = 1; \
for (un32Count=0; un32Count<(TBX_UINT32)((__LineLength__)-2); un32Count++) \
{ \
szLine [un32Index++] = (__FillChar__); \
} \
szLine [un32Index++] = (__EndChar__); \
szLine [un32Index] = '\0'; \
TB640_CAS_DISPLAY_PRINT (szLine); \
}
#define TB640_CAS_WRITE_STRING_INDENTED(__StartChar__,__EndChar__,__FillChar__,__Index__,__LineLength__,____String__) \
{ \
TBX_UINT32 un32Count; \
TBX_UINT32 un32Index; \
TBX_CHAR szLine [TB640_CAS_CLI_MAX_LINE_SIZE + 1]; \
\
szLine [0] = (__StartChar__); \
un32Index = 1; \
for (un32Count=un32Index; un32Count<(TBX_UINT32)((__Index__)-1); un32Count++) \
{ \
szLine [un32Count] = (__FillChar__); \
un32Index++; \
} \
szLine [un32Index++] = ' '; \
szLine [un32Index] = '\0'; \
strcpy (&(szLine [un32Index]), (const char *)(____String__)); \
un32Index += strlen ((const char *)(____String__)); \
szLine [un32Index++] = ' '; \
for (un32Count=un32Index; un32Count<(TBX_UINT32)((__LineLength__)-1); un32Count++) \
{ \
szLine [un32Count] = (__FillChar__); \
un32Index++; \
} \
szLine [un32Index++] = (__EndChar__); \
szLine [un32Index] = '\0'; \
TB640_CAS_DISPLAY_PRINT (szLine); \
}
#define TB640_CAS_WRITE_STRING_CENTERED(__StartChar__,__EndChar__,__FillChar__,__LineLength__,____String__) \
{ \
TBX_UINT32 un32Count; \
TBX_UINT32 un32Index; \
TBX_UINT32 un32StrLen; \
TBX_UINT32 un32NbSpaceLeft; \
TBX_UINT32 un32NbSpaceRight; \
TBX_CHAR szLine [TB640_CAS_CLI_MAX_LINE_SIZE + 1]; \
\
un32StrLen = strlen ((const char *)(____String__)); \
un32NbSpaceLeft = ((__LineLength__) - un32StrLen - 4) / 2; \
un32NbSpaceRight = (((__LineLength__) - un32StrLen - 4) / 2) + (((__LineLength__) - un32StrLen - 4) % 2); \
\
szLine [0] = (__StartChar__); \
un32Index = 1; \
for (un32Count=0; un32Count<un32NbSpaceLeft; un32Count++) \
{ \
szLine [un32Index++] = (__FillChar__); \
} \
szLine [un32Index++] = ' '; \
szLine [un32Index] = '\0'; \
strcpy (&(szLine [un32Index]), (const char *)(____String__)); \
un32Index += strlen ((const char *)(____String__)); \
szLine [un32Index++] = ' '; \
for (un32Count=0; un32Count<un32NbSpaceRight; un32Count++) \
{ \
szLine [un32Index++] = (__FillChar__); \
} \
szLine [un32Index++] = (__EndChar__); \
szLine [un32Index] = '\0'; \
TB640_CAS_DISPLAY_PRINT (szLine); \
}
#define TB640_CAS_WRITE_STRING_WINDOWED(__LineWidth__,____String__) \
{ \
TB640_CAS_WRITE_LINE (ULS, URS, MS, (__LineWidth__)); \
TB640_CAS_DISPLAY_PRINT ("\n"); \
TB640_CAS_WRITE_STRING_CENTERED (MVS, MVS, ' ', (__LineWidth__), (____String__)); \
TB640_CAS_DISPLAY_PRINT ("\n"); \
TB640_CAS_WRITE_LINE (LLS, LRS, MS, (__LineWidth__)); \
TB640_CAS_DISPLAY_PRINT ("\n"); \
}
/*--------------------------------------------------------------------------------------------------------------------------------
| Function Prototypes
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640CasDisplayAdapterStats (
IN TBX_UINT32 in_un32AdapterNb);
TBX_RESULT TB640CasSelectAdapterTrunkTimeslot (
OUT PTBX_UINT32 out_pun32AdapterNb,
OUT PTBX_UINT32 out_pun32TrunkNb,
OUT PTBX_UINT32 out_pun32TimeslotNb);
TBX_RESULT TB640CasSelectAdapterTrunk (
OUT PTBX_UINT32 out_pun32AdapterNb,
OUT PTBX_UINT32 out_pun32TrunkNb);
TBX_RESULT TB640CasChangeNumbers (
IN TBX_UINT32 in_un32AdapterNb,
IN TBX_UINT32 in_un32TrunkNb);
TBX_RESULT TB640CasChangeNbExpectedDigits();
TBX_RESULT TB640CasTerminateAllCall (
IN TBX_UINT32 in_un32AdapterNb,
IN TBX_UINT32 in_un32TrunkNb);
TBX_RESULT TB640CasSelectCallForAutomaticCall (
IN TBX_UINT32 in_un32StressOutgoingTimeslotMinIdleMsec,
OUT PTBX_UINT32 out_pun32AdapterNb,
OUT PTBX_UINT32 out_pun32TrunkNb,
OUT PTBX_UINT32 out_pun32TimeslotNb);
TBX_RESULT TB640CasSelectCallForAutomaticRestart (
OUT PTBX_UINT32 out_pun32AdapterNb,
OUT PTBX_UINT32 out_pun32TrunkNb,
OUT PTBX_UINT32 out_pun32TimeslotNb);
TBX_RESULT TB640CasSelectStressParameters (
OUT PTBX_UINT32 out_pun32StressDelayBetweenCalls,
OUT PTBX_UINT32 out_pun32StressCallMinDuration,
OUT PTBX_UINT32 out_pun32StressCallMaxDuration,
OUT PTBX_UINT32 out_pun32StressDelayBetweenRestart,
OUT PTBX_UINT32 out_pun32StressOutgoingTimeslotMinIdleMsec);
TBX_RESULT TB640CasAdjustTraceLevel (
OUT PTBX_UINT32 out_pun32FileLogLevel,
OUT PTBX_UINT32 out_pun32DisplayLogLevel);
TBX_VOID TB640CasPrintTimeslotHistory (
IN TBX_UINT32 in_un32AdapterIdx,
IN TBX_UINT32 in_un32TrunkIdx,
IN TBX_UINT32 in_un32TimeslotIdx);
TBX_RESULT TB640CasParseTrunkSelection (
IN PTB640_CAS_ADAPTER_INFO in_pAdapterInfo,
IN PTBX_CHAR in_pszArguments,
OUT PTBX_BOOL out_pfDone);
/*--------------------------------------------------------------------------------------------------------------------------------
| Implementation
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640CasCli : 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
TB640CasCli (void)
{
TBX_RESULT Result;
TBX_BOOL fAutomaticCallGenerationActivated;
TBX_INT nOption;
TBX_UINT32 un32OldReadIndex;
TBX_UINT32 un32Count;
TBX_UINT32 un32Tmp;
TBX_UINT32 un32Adapter;
TBX_UINT32 un32Trunk;
TBX_UINT32 un32Timeslot;
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_CAS_STRESS_STATS StatsCopy;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
un32LastTimeWhereACallWasMade = 0;
un32LastTimeWhereARestartWasMade = 0;
un32NbCallPerSeconds = 0;
un32NbBHCA = 0;
fAutomaticCallGenerationActivated = TBX_FALSE;
un32Timer = TBX_GET_TICK();
un32LastTimeARefreshWasMade = un32Timer;
un32TimerSec = (un32Timer / 1000);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -