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

📄 cli.c

📁 telcobridges pri develop,30b+d
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (ISDN)
 |
 |	Filename:   	cli.c
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains the client interface function
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.86 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  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_isdnmgr.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 "isdn.h"
#include "prototypes.h"
#include "macros.h"


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/
#define ISDN_COLOR

/* Define the width of the default applicaton screen when it starts */
#define TB640_ISDN_CLI_DEFAULT_LINE_SIZE				79

/* Define the width of the CLI screen */
#define TB640_ISDN_CLI_MAX_LINE_SIZE					129
#define TB640_ISDN_CLI_MAX_LINE_SIZE_GET				256
#define TB640_ISDN_CLI_MAX_BUFFER_SIZE					512

/* Format string to display the status line */
#define TB640_ISDN_CLI_LINE_DISPLAY_STRING				"%-129s\n"

/* Define the heigth of the CLI screen */
#define TB640_ISDN_CLI_MAX_LINE							49

/* Define the number of trunk column */
#define TB640_ISDN_CLI_COLUMN_NB						3

/* Define the width of a trunk column */
#define TB640_ISDN_CLI_COLUMN_SIZE						43

/* Minimum time between two consecutive stress-test calls (must be between 1 and 1000) */
#ifdef WIN32
#define TB640_ISDN_CLI_MIN_TIME_BETWEEN_STRESS_CALLS	1		/* 1 msec = 1000 calls/sec */
#else
#define TB640_ISDN_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.86 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/
volatile TBX_BOOL					g_fExit				= TBX_FALSE;
volatile TBX_BOOL					g_fRefreshDisplay	= (TB640_ISDN_CLI_FORCE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY | TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH);
TBX_SEM								g_StressStatsSem;
volatile TB640_ISDN_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_ISDN_CLI_MAX_NB_ERROR_LINES+1] [TB640_ISDN_CLI_MAX_ERROR_LINE_SIZE] = {{0}};


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/

#define TB640_ISDN_WRITE_LINE(__StartChar__,__EndChar__,__FillChar__,__LineLength__)	\
{																						\
	TBX_UINT32			un32Count;														\
	TBX_UINT32			un32Index;														\
	TBX_CHAR			szLine [TB640_ISDN_CLI_MAX_BUFFER_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_ISDN_DISPLAY_PRINT (szLine);													\
}


#define TB640_ISDN_WRITE_STRING_INDENTED(__StartChar__,__EndChar__,__FillChar__,__Index__,__LineLength__,____String__)	\
{																						\
	TBX_UINT32			un32Count;														\
	TBX_UINT32			un32Index;														\
	TBX_CHAR			szLine [TB640_ISDN_CLI_MAX_BUFFER_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_ISDN_DISPLAY_PRINT (szLine);													\
}


#define TB640_ISDN_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_ISDN_CLI_MAX_BUFFER_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_ISDN_DISPLAY_PRINT (szLine);													\
}


#define TB640_ISDN_WRITE_STRING_WINDOWED(__LineWidth__,____String__)					\
{																						\
	TB640_ISDN_WRITE_LINE (ULS, URS, MS, (__LineWidth__));								\
	TB640_ISDN_DISPLAY_PRINT ("\n");													\
	TB640_ISDN_WRITE_STRING_CENTERED (MVS, MVS, ' ', (__LineWidth__), (____String__));	\
	TB640_ISDN_DISPLAY_PRINT ("\n");													\
	TB640_ISDN_WRITE_LINE (LLS, LRS, MS, (__LineWidth__));								\
	TB640_ISDN_DISPLAY_PRINT ("\n");													\
}


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT TB640IsdnDisplayAdapterStats (
  IN		TBX_UINT32				in_un32AdapterNb);

TBX_RESULT TB640IsdnSelectAdapter (
  OUT		PTBX_UINT32				out_pun32AdapterNb);

TBX_RESULT  TB640IsdnSelectAdapterTrunkTimeslot (
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkNb,
  OUT		PTBX_UINT32				out_pun32TimeslotNb);

TBX_RESULT	TB640IsdnSelectAdapterTrunkTimeslotAndBChanState (
  OUT		PTBX_UINT32					out_pun32AdapterNb,
  OUT		PTBX_UINT32					out_pun32TrunkNb,
  OUT		PTBX_UINT32					out_pun32TimeslotNb,
  OUT		PTB640_ISDN_BCHANNEL_STATUS	out_pState);

TBX_RESULT  TB640IsdnSelectAdapterTrunkTimeslotAndOverlap (
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkNb,
  OUT		PTBX_UINT32				out_pun32TimeslotNb,
  OUT		PTBX_BOOL				out_fOverlapMode);

TBX_RESULT  TB640IsdnSelectAdapterTrunk (
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkNb);

TBX_RESULT  TB640IsdnTerminateAllCall (
  IN		TBX_UINT32				in_un32AdapterNb,
  IN		TBX_UINT32				in_un32TrunkNb);

TBX_RESULT  TB640IsdnSelectCallForAutomaticCall (
  IN		TBX_UINT32				in_un32StressOutgoingTimeslotMinIdleMsec,
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkNb,
  OUT		PTBX_UINT32				out_pun32TimeslotNb);

TBX_RESULT 	TB640IsdnSelectCallForAutomaticRestart (
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkNb,
  OUT		PTBX_UINT32				out_pun32TimeslotNb);

TBX_RESULT  TB640IsdnSelectStressParameters (
  OUT		PTBX_UINT32				out_pun32StressNbCall,
  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  TB640IsdnAdjustTraceLevel (
  OUT		PTBX_UINT32				out_pun32FileLogLevel,
  OUT		PTBX_UINT32				out_pun32DisplayLogLevel);

TBX_VOID TB640IsdnPrintTimeslotHistory (
  IN		TBX_UINT32				in_un32AdapterIdx,
  IN		TBX_UINT32				in_un32TrunkIdx,
  IN		TBX_UINT32				in_un32TimeslotIdx);

TBX_VOID TB640IsdnRestartMultipleTimeslots (void);


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_BOOLEAN TB640IsdnOpLibraryEmpty(void)
{
    PTB640_ISDN_ADAPTER_INFO    pAdapterInfo;
    PTBX_ASYNC_CONTEXT          pAsyncContext;
    TBX_UINT32					un32Count;
    TBX_UINT32					i;
    TBX_BOOLEAN                 fOpActiveListEmpty = TBX_TRUE;
    TBX_BOOLEAN                 fOpTimeoutListEmpty = TBX_TRUE;

    /* Display the different adapter status */
	for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
	{
		pAdapterInfo = (PTB640_ISDN_ADAPTER_INFO)&g_AppContext->ahAdapterInfo[un32Count];
		for(i=0; i<pAdapterInfo->un32NbOperationLib; i++)
		{
		    TB640IsdnLockFromOpLibIdx( pAdapterInfo, i );
		    pAsyncContext = (PTBX_ASYNC_CONTEXT)pAdapterInfo->ahOperationLib[i];
		    if( !TBXAsyncIsEmpty(&pAsyncContext->ListOpActive) )
		    {
		        fOpActiveListEmpty = TBX_FALSE;
		    }

		    if( !TBXAsyncIsEmpty(&pAsyncContext->ListOpTimeout) )
		    {
		        fOpTimeoutListEmpty = TBX_FALSE;
		    }

⌨️ 快捷键说明

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