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

📄 fsk.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (FSK)
 |
 |	Filename:   	fsk.c
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains the main entry point of the application
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.6 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/




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

#include "includes.h"


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


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


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.6 $";
#endif

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/
PTB640_FSK_CONTEXT				g_AppContext;
extern volatile TBX_BOOL		g_fExit;


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


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

#ifdef WIN32
	static BOOL WINAPI ControlC_Handler(DWORD CtrlType);
#else
	void ControlC_Handler( int in_iSignal );
#endif

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


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  main        	:	This function is the main entry point of the application
 |
 |  in_argc         :	Number of arguments passed to this application (including the application's name)
 |  in_argv			:	Array of strings containing every arguments
 |
 |  Note			:	~
 |
 |  Return          :	Not used
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
int
main (
  IN	int			in_argc,
  IN	char *		in_argv [])
{
	TBX_RESULT		result;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		g_AppContext = NULL;
		srand( time( NULL ) );

		#ifdef WIN32
		{
			/* Install control-C handler function */
			/* SetConsoleCtrlHandler( ControlC_Handler, TBX_TRUE ); */
		}
		#else
		{
			TBX_UINT32	l_un32SigCount;
			int			l_pSignalsToTrap[] 	= { SIGINT, SIGHUP, SIGALRM, SIGQUIT, SIGTERM, SIGUSR1 };
			/* Trap normal exit signals */
			for( l_un32SigCount = 0; l_un32SigCount < sizeof( l_pSignalsToTrap ) / sizeof( int ); l_un32SigCount++ )
			{
				signal( l_pSignalsToTrap[ l_un32SigCount ], ControlC_Handler );
			}
			/* Ignore sig pipe (broken pipe that occurs when a socket closes) */
			signal( SIGPIPE, SIG_IGN );
		}
		#endif

		/* Allocate application context */
		g_AppContext = (PTB640_FSK_CONTEXT)calloc (1, sizeof(*g_AppContext));
		if( !g_AppContext )
		{
			TBX_EXIT_ERROR( TBX_RESULT_NOT_ENOUGH_MEMORY, 0, "Could not allocate memory for internal context\n" );
		}

		/* Initialize some static values */
		g_AppContext->WaitRemote1MsgId			= 1;
		g_AppContext->WaitRemote1ConfirmMsgId	= 2;
		g_AppContext->WaitRemote2MsgId			= 3;
		g_AppContext->WaitRemote2ConfirmMsgId	= 4;
		g_AppContext->CloseRemoteMsgId			= 5;
		g_AppContext->TxStressTestMsgId			= 10;
		g_AppContext->TxAMsgId					= 11;
		g_AppContext->TxBMsgId					= 12;
		g_AppContext->TxCMsgId					= 13;
		g_AppContext->TxDMsgId					= 14;
		g_AppContext->WaitRemote1Data			= 0;
		g_AppContext->WaitRemote2Data			= 0;

		/* Create display output semaphore */
		TBX_SEM_CREATE (&g_AppContext->DisplaySem, 1, 1);

		/* Parse the configuration file and load it into our context structure */
		if (in_argc == 2)
		{
			/* Use filename passed in arguments */
			result = TB640FskParseAndLoadConfiguration (in_argv[1]);
		}
		else
		{
			/* Use default filename */
			result = TB640FskParseAndLoadConfiguration (TB640_FSK_DEFAULT_CONFIGURATION_FILENAME);
		}
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to parse configuration file");
		}

		/* Configure trunk, stacks, VP resources and operation libraries */
		result = TB640FskConfigureSystem ();
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to configure trunks and/or stacks");
		}

		/* Start the client interface (CLI) */
		result = TB640FskCli ();
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Error while executing client interface");
		}

		/* 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
	{
		/* Free the application context */
		if (NULL != g_AppContext)
		{
			/* Configure allocated trunk, stacks, VP resources and operation libraries */
			TB640FskCleanSystem ();

			/* Close the log file if it was opened */
			if (NULL != g_AppContext->pLogFile)
			{
				fclose (g_AppContext->pLogFile);
				g_AppContext->pLogFile = NULL;
			}

			/* Destroy display output semaphore */
			TBX_SEM_DESTROY (&g_AppContext->DisplaySem);

			/* Free global context */
			free (g_AppContext);
			g_AppContext = NULL;
		}
	}

	/* Press RETURN to quit, if leaks detected */
	if( sm_dump(0) || TBX_RESULT_FAILURE( TBX_ERROR_RESULT ) )
	{
		fprintf( stdout, "Done. Press RETURN to quit...\n" );
		fflush( stdin );
		getchar();
	}

	RETURN_WITH_TYPE (int);
}



/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |  ControlC_Handler		:	Function called when the user press Control-C while the test is running.
 |								This function forces all file playbacks to stop.
 |
 |  Note					:
 |
 |  Return					:
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
BOOL WINAPI ControlC_Handler(DWORD CtrlType)
{
	/* Process exit application command from windows */
	if( CtrlType == 2 )
	{
		printf( "Window is being closed. Quitting...\n" );
	}
	else
	{
		printf( "Received control-C. Quitting...\n" );
	}

	g_fExit = TBX_TRUE;

	return TBX_TRUE;
}
#else
void ControlC_Handler( int in_iSignal )
{
	g_fExit = TBX_TRUE;

	/* Re-install this signal handler for the next time */
	if( in_iSignal == SIGINT )
	{
		printf( "Received Control-C. Quitting...\n" );
	}
	else
	{
		printf( "Received quit signal %d. Quitting...\n", in_iSignal );
	}
	signal( in_iSignal, ControlC_Handler );
}
#endif

⌨️ 快捷键说明

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