📄 cli.c
字号:
if (un32Tmp >= TB640_FSK_CLI_MAX_NB_ERROR_LINES)
{
/* Wrap around case */
un32Tmp = 0 + (un32Tmp - TB640_FSK_CLI_MAX_NB_ERROR_LINES);
if (g_un32ErrorLineReadIndex > g_un32ErrorLineWriteIndex)
{
if (un32Tmp < g_un32ErrorLineWriteIndex)
{
/* No overflow */
g_un32ErrorLineReadIndex = un32Tmp;
}
else
{
/* Overflow */
g_un32ErrorLineReadIndex = (g_un32ErrorLineWriteIndex - 1);
}
}
else
{
/* Overflow */
g_un32ErrorLineReadIndex = (g_un32ErrorLineWriteIndex - 1);
}
}
else
{
/* No wrap-around case */
if (g_un32ErrorLineReadIndex < g_un32ErrorLineWriteIndex)
{
if (un32Tmp < g_un32ErrorLineWriteIndex)
{
/* No overflow */
g_un32ErrorLineReadIndex = un32Tmp;
}
else
{
/* Overflow */
g_un32ErrorLineReadIndex = (g_un32ErrorLineWriteIndex - 1);
}
}
else
{
/* No overflow possible - the write pointer is behind us */
g_un32ErrorLineReadIndex = un32Tmp;
}
}
}
TBX_SEM_GIV (g_AppContext->DisplaySem);
g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
break;
/* Display window move up */
case '8':
TBX_SEM_GET (g_AppContext->DisplaySem, TBX_SEM_WAIT_FOREVER);
un32OldReadIndex = g_un32ErrorLineReadIndex;
if (g_un32ErrorLineReadIndex != 0)
{
g_un32ErrorLineReadIndex--;
}
else
{
g_un32ErrorLineReadIndex = (TB640_FSK_CLI_MAX_NB_ERROR_LINES-1);
}
if (g_un32ErrorLineReadIndex == g_un32ErrorLineWriteIndex)
{
g_un32ErrorLineReadIndex = un32OldReadIndex;
}
TBX_SEM_GIV (g_AppContext->DisplaySem);
g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
break;
/* Display window page up */
case '9':
TBX_SEM_GET (g_AppContext->DisplaySem, TBX_SEM_WAIT_FOREVER);
/* Make sure there is something in the buffer */
if (g_un32ErrorLineReadIndex != g_un32ErrorLineWriteIndex)
{
if (g_un32ErrorLineReadIndex < 25)
{
/* Wrap around case */
un32Tmp = (TB640_FSK_CLI_MAX_NB_ERROR_LINES - g_un32ErrorLineReadIndex);
if (g_un32ErrorLineReadIndex < g_un32ErrorLineWriteIndex)
{
if (un32Tmp > g_un32ErrorLineWriteIndex)
{
/* No underflow */
g_un32ErrorLineReadIndex = un32Tmp;
}
else
{
/* underflow */
g_un32ErrorLineReadIndex = (g_un32ErrorLineWriteIndex + 1);
if (g_un32ErrorLineReadIndex >= TB640_FSK_CLI_MAX_NB_ERROR_LINES)
{
g_un32ErrorLineReadIndex = 0;
}
}
}
else
{
/* underflow */
g_un32ErrorLineReadIndex = (g_un32ErrorLineWriteIndex + 1);
}
}
else
{
/* No wrap-around case */
un32Tmp = g_un32ErrorLineReadIndex - 25;
if (g_un32ErrorLineReadIndex > g_un32ErrorLineWriteIndex)
{
if (un32Tmp > g_un32ErrorLineWriteIndex)
{
/* No underflow */
g_un32ErrorLineReadIndex = un32Tmp;
}
else
{
/* underflow */
g_un32ErrorLineReadIndex = (g_un32ErrorLineWriteIndex + 1);
}
}
else
{
/* No underflow possible - the write pointer is in front of us */
g_un32ErrorLineReadIndex = un32Tmp;
}
}
}
TBX_SEM_GIV (g_AppContext->DisplaySem);
g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
break;
/* (F)lush log file */
case 'F':
{
TBX_CHAR szNewFilename [128];
time_t tTime;
struct tm * pTime;
/* Close the log file if it was opened */
if (NULL != g_AppContext->pLogFile)
{
fclose (g_AppContext->pLogFile);
g_AppContext->pLogFile = NULL;
sprintf (szNewFilename, "%s_%d", g_AppContext->szFilename, g_AppContext->un32LogNumber++ );
g_AppContext->pLogFile = fopen (szNewFilename, "w+");
if (NULL == g_AppContext->pLogFile)
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to open log file");
}
/* Get the time of day */
time (&tTime);
pTime = localtime( &tTime );
/* Print a string to the log file... */
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "FSK sample application\n");
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Copyright (c)2003 by Telcobridges inc.\n");
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Application instance run on %s", asctime(pTime));
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "----------------------------------------------------------------\n\n");
}
}
break;
/* (Q)uit */
case 'Q':
g_fExit = TBX_TRUE;
break;
/* Unknown command */
default:
break;
}
}
/* If automatic call generation is activated */
if (fAutomaticCallGenerationActivated)
{
TBX_UINT32 un32NbCalls = 0;
/* Only start calls on precise boundary */
while (TBX_TRUE)
{
TBX_INT32 n32ElapsedMs;
/* Make sure we are not processing in the futur */
n32ElapsedMs = (TBX_INT32)(un32Timer - un32LastTimeWhereACallWasMade);
n32ElapsedMs *= TBX_MSEC_PER_TICKS;
if (n32ElapsedMs < 0)
{
un32LastTimeWhereACallWasMade = un32Timer;
break;
}
/* Do we need to make a call ? */
un32ElapsedMs = un32Timer - un32LastTimeWhereACallWasMade;
un32ElapsedMs *= TBX_MSEC_PER_TICKS;
if (un32ElapsedMs < un32StressDelayBetweenCalls)
{
break;
}
/* Select timeslot to use for call generation */
Result = TB640FskSelectCallForAutomaticCall(un32StressOutgoingTimeslotMinIdleMsec, &un32Adapter, &un32Trunk, &un32Timeslot);
if (TBX_RESULT_SUCCESS(Result))
{
TB640FskKickTransmission (0, un32Adapter, un32Trunk, un32Timeslot);
}
else
{
TB640_FSK_INCREMENT_STATS (un32NbCallNoFreeTimeslotToSend, 1);
g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
}
/* Wait until next time delay is expired before making another call */
un32LastTimeWhereACallWasMade += un32StressDelayBetweenCalls;
un32NbCalls++;
if( un32NbCalls >= TB640_FSK_CLI_MAX_CALLS_PER_LOOP )
{
fSleep = TBX_TRUE;
break;
}
}
}
}
/* Print all error/status on the standard output from now on */
g_fPrintInErrorBuffer = TBX_FALSE;
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
TBXCliCls ();
TB640_FSK_DISPLAY_PRINT ("Exiting from the application\n\n");
}
RETURN;
}
/*--------------------------------------------------------------------------------------------------------------------------------
| Utility functions
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640FskAdjustTraceLevel: This function makes the user to select new trace levels
|
| out_pun32FileLogLevel: File log level selected by the user
| out_pun32DisplayLogLevel: Display log level selected by the user
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskAdjustTraceLevel (
OUT PTBX_UINT32 out_pun32FileLogLevel,
OUT PTBX_UINT32 out_pun32DisplayLogLevel)
{
TBX_CHAR szLine [TB640_FSK_CLI_MAX_LINE_SIZE_GET];
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variable */
*out_pun32FileLogLevel = 0;
*out_pun32DisplayLogLevel = 0;
/* Display prompt */
TB640_FSK_DISPLAY_PRINT ("Enter the FILE log level (0=loud, 5=light): ");
/* Get the input from the user */
szLine[0] = '\0';
fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);
*out_pun32FileLogLevel = atoi (szLine);
if (*out_pun32FileLogLevel > 5)
{
*out_pun32FileLogLevel = 5;
}
/* Display prompt */
TB640_FSK_DISPLAY_PRINT ("Enter the DISPLAY log level (0=loud, 5=light): ");
/* Get the input from the user */
szLine[0] = '\0';
fgets (szLine, TB640_FSK_CLI_MAX_LINE_SIZE_GET, stdin);
*out_pun32DisplayLogLevel = atoi (szLine);
if (*out_pun32DisplayLogLevel > 5)
{
*out_pun32DisplayLogLevel = 5;
}
/* Refresh the display */
g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640FskSelectCallForAutomaticCall: This function automatically selects the next timeslot to use for automatic call
| generation
|
| in_un32StressOutgoingTimeslotMinIdleMsec: Minimum time a timeslot needs to be idle before selection for an outgoing call
| out_pun32AdapterNb: Adapter number to use
| out_pun32TrunkNb: Trunk number to use
| out_pun32TimeslotNb:Timeslot number to use
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskSelectCallForAutomaticCall (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -