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

📄 cli.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (FSK)
 |
 |	Filename:   	cli.c
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains the client interface function
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.11 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

#include "includes.h"


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


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/

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

/* Define the width of the CLI screen */
#define TB640_FSK_CLI_MAX_LINE_SIZE						129
#define TB640_FSK_CLI_MAX_LINE_SIZE_GET					256

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

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

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

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

/* Minimum time between two consecutive stress-test calls (must be between 1 and 1000) */
#define TB640_FSK_CLI_MIN_TIME_BETWEEN_STRESS_CALLS		0
#define TB640_FSK_CLI_MAX_CALLS_PER_LOOP				50



/* 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.11 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/
volatile TBX_BOOL					g_fExit				= TBX_FALSE;
volatile TBX_BOOL					g_fRefreshDisplay	= (TB640_FSK_CLI_FORCE_REFRESH | TB640_FSK_CLI_REFRESH_DISPLAY | TB640_FSK_CLI_CLEAR_BEFORE_REFRESH);
TBX_SEM								g_StressStatsSem;
volatile TB640_FSK_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_FSK_CLI_MAX_NB_ERROR_LINES+1] [TB640_FSK_CLI_MAX_ERROR_LINE_SIZE] = {{0}};


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

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


#define TB640_FSK_WRITE_STRING_INDENTED(__StartChar__,__EndChar__,__FillChar__,__Index__,__LineLength__,____String__)	\
{																						\
	TBX_UINT32			un32Count;														\
	TBX_UINT32			un32Index;														\
	TBX_CHAR			szLine [(TB640_FSK_CLI_MAX_LINE_SIZE*10) + 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_FSK_DISPLAY_PRINT (szLine);													\
}


#define TB640_FSK_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_FSK_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_FSK_DISPLAY_PRINT (szLine);													\
}


#define TB640_FSK_WRITE_STRING_WINDOWED(__LineWidth__,____String__)					\
{																						\
	TB640_FSK_WRITE_LINE (ULS, URS, MS, (__LineWidth__));								\
	TB640_FSK_DISPLAY_PRINT ("\n");													\
	TB640_FSK_WRITE_STRING_CENTERED (MVS, MVS, ' ', (__LineWidth__), (____String__));	\
	TB640_FSK_DISPLAY_PRINT ("\n");													\
	TB640_FSK_WRITE_LINE (LLS, LRS, MS, (__LineWidth__));								\
	TB640_FSK_DISPLAY_PRINT ("\n");													\
}


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

TBX_RESULT TB640FskDisplayAdapterStats (
  IN		TBX_UINT32				in_un32AdapterNb);

TBX_RESULT
TB640FskSelectAdapterTrunkTimeslot (
  OUT		PTBX_UINT32				out_pun32AdapterNb,
  OUT		PTBX_UINT32				out_pun32TrunkFirst,
  OUT		PTBX_UINT32				out_pun32TrunkCnt,
  OUT		PTBX_UINT32				out_pun32TimeslotNb);

TBX_VOID  TB640FskAdapterTrunkTimeslotLaunchAction (
  IN		PFCT_TB640_FSK_CMDLINE_ACTION	in_pFctAction,
  IN		TBX_UINT32						in_un32FctParam,
  IN		TBX_UINT32						in_pun32AdapterNb,
  IN		TBX_UINT32						in_pun32TrunkNb,
  IN		TBX_UINT32						in_pun32TimeslotNb);

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

TBX_RESULT  TB640FskSelectStressParameters (
  OUT		PTBX_UINT32				out_pun32StressDelayBetweenCalls,
  OUT		PTBX_UINT32				out_pun32StressOutgoingTimeslotMinIdleMsec);

TBX_RESULT  TB640FskAdjustTraceLevel (
  OUT		PTBX_UINT32				out_pun32FileLogLevel,
  OUT		PTBX_UINT32				out_pun32DisplayLogLevel);

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



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



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskCli	:	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
TB640FskCli (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					un32TrunkCnt;
	TBX_UINT32					un32Timeslot;
	TBX_UINT32					un32StressDelayBetweenCalls;
	TBX_UINT32					un32StressOutgoingTimeslotMinIdleMsec;
	TBX_UINT32					un32Timer;
	TBX_UINT32					un32TimerSec;
	TBX_UINT32					un32LastTimeARefreshWasMade;
	TBX_UINT32					un32LastTimeWhereACallWasMade;
	TBX_UINT32					un32NbRxFskMsgPerSeconds;
	TBX_UINT32					un32NbTxFskMsgPerSeconds;
	TBX_UINT32					un32NbRxFskAckPerSeconds;
	TBX_UINT32					un32NbTxFskAckPerSeconds;
	TBX_UINT32					un32TimeSinceBegInSec;
	TB640_FSK_STRESS_STATS		StatsCopy;
	TBX_BOOL					fSleep;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		fAutomaticCallGenerationActivated	= TBX_FALSE;
		un32Timer							= TBX_GET_TICK();
		un32LastTimeARefreshWasMade			= un32Timer;
		un32TimerSec						= (un32Timer / 1000);
		fSleep								= TBX_TRUE;
		un32LastTimeARefreshWasMade			= 0;
		un32LastTimeWhereACallWasMade		= 0;
		un32NbRxFskMsgPerSeconds			= 0;
		un32NbTxFskMsgPerSeconds			= 0;
		un32NbRxFskAckPerSeconds			= 0;
		un32NbTxFskAckPerSeconds			= 0;
		un32TimeSinceBegInSec				= 0;

		/* Display a warning to grow the window */
		TB640_FSK_WRITE_STRING_WINDOWED (TB640_FSK_CLI_DEFAULT_LINE_SIZE, "Please, set your window size to at least 132 columns and 50 lines");
		TB640_FSK_DISPLAY_PRINT ("\n");
		TB640_FSK_WRITE_STRING_WINDOWED (TB640_FSK_CLI_DEFAULT_LINE_SIZE, "Turn your NUMLOCK to ON");
		TB640_FSK_DISPLAY_PRINT ("\n");
#ifndef WIN32
		TB640_FSK_WRITE_STRING_WINDOWED (TB640_FSK_CLI_DEFAULT_LINE_SIZE, "Be sure ANSI codes are activated on your terminal");
		TB640_FSK_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!) */
			if( fSleep )
			{
				TBX_SLEEP_MS( 10 );
			}
			fSleep = TBX_FALSE;

			/* 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_FSK_CLI_FORCE_REFRESH)
				)
				{
					/* Display is being refreshed */
					un32LastTimeARefreshWasMade = un32Timer;

					/* Do we need to clear the screen completely ? */
					if (g_fRefreshDisplay & TB640_FSK_CLI_CLEAR_BEFORE_REFRESH)
					{
						TBXCliCls ();
					}
					else
					{
						TBXCliHome ();
					}
					g_fRefreshDisplay = TBX_FALSE;

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

⌨️ 快捷键说明

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