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

📄 states.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |  Utility functions
 *------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskActivateReception:	This function is called to activate FSK reception on a timeslot
 |
 |	in_un32AdapterIdx:	Adapter index
 |	in_un32TrunkIdx:	Trunk index to open the call on
 |	in_un32TimeslotIdx:	Timeslot index to open the call on
 |
 |  Note			:	~
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640FskActivateReception (
  IN		TBX_UINT32					in_un32UnusedParam,
  IN		TBX_UINT32					in_un32AdapterIdx,
  IN		TBX_UINT32					in_un32TrunkIdx,
  IN		TBX_UINT32					in_un32TimeslotIdx )
{
	TB640FskLock( in_un32AdapterIdx, in_un32TrunkIdx );
	TB640FskActivateReceptionInternal( in_un32AdapterIdx, in_un32TrunkIdx, in_un32TimeslotIdx );
	TB640FskUnlock( in_un32AdapterIdx, in_un32TrunkIdx );
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskActivateReceptionInternal:	This function is called to activate FSK reception on a timeslot
 |
 |	in_un32AdapterIdx:	Adapter index
 |	in_un32TrunkIdx:	Trunk index to open the call on
 |	in_un32TimeslotIdx:	Timeslot index to open the call on
 |
 |  Note			:	~
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640FskActivateReceptionInternal (
  IN		TBX_UINT32					in_un32AdapterIdx,
  IN		TBX_UINT32					in_un32TrunkIdx,
  IN		TBX_UINT32					in_un32TimeslotIdx )
{
	TBX_RESULT									result;
	PTB640_FSK_ADAPTER_INFO						pAdapterInfo;
	PTB640_FSK_TRUNK_INFO						pTrunkInfo;
	PTB640_FSK_TRUNK_RESOURCE_INFO				pTrunkResInfo;
	PTBX_ASYNC_OP_CONTEXT						pOpContext;
	PTB640_FSK_CALL_CONTEXT						pCallContext;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{

		/* Initialize local variables */
		pAdapterInfo	= &(g_AppContext->ahAdapterInfo [in_un32AdapterIdx]);
		pTrunkInfo		= &(pAdapterInfo->aTrunkInfo [in_un32TrunkIdx]);
		pTrunkResInfo	= &(pTrunkInfo->aResourceInfo [in_un32TimeslotIdx]);

		/* Make sure the timeslot is not already used */
		if (pTrunkResInfo->State == TB640_FSK_CALL_APP_STATE_NOT_USED || pTrunkResInfo->fInUse)
		{
			TB640_FSK_INCREMENT_STATS (un32NbCallNoFreeTimeslotToSend, 1);
			TBX_EXIT_SUCCESS (TBX_RESULT_OK);
		}

		/* Retrieve the operation context */
		result = TBXAsyncRetrieveOp
		(
			pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
			pTrunkResInfo->hVPResource,
			&pOpContext,
			(PTBX_VOID*)&pCallContext
		);
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve operation context for selected timeslot");
		}

		pTrunkResInfo->fInUse = TBX_TRUE;
		TB640_FSK_INCREMENT_TRANSIANT_CALL (1);

		/* Process the state change */
		result = TB640FskProcessStateChange (
		  pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
		  pOpContext,
		  pCallContext,
		  TB640_MSG_ID_FSK_ACTIVATE_RX,
		  NULL);
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to process state change");
		}

		/* 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
	{
		g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
	}

	RETURN_VOID;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskActivateTransmission:	This function is called to activate FSK transmission on a timeslot
 |
 |	in_un32Protocol		: Protocol to use
 |	in_un32AdapterIdx	:	Adapter index
 |	in_un32TrunkIdx		:	Trunk index to open the call on
 |	in_un32TimeslotIdx	:	Timeslot index to open the call on
 |
 |  Note			:	~
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640FskActivateTransmission (
  IN		TBX_UINT32					in_un32Protocol,
  IN		TBX_UINT32					in_un32AdapterIdx,
  IN		TBX_UINT32					in_un32TrunkIdx,
  IN		TBX_UINT32					in_un32TimeslotIdx )
{
	TBX_RESULT									result;
	PTB640_FSK_ADAPTER_INFO						pAdapterInfo;
	PTB640_FSK_TRUNK_INFO						pTrunkInfo;
	PTB640_FSK_TRUNK_RESOURCE_INFO				pTrunkResInfo;
	PTBX_ASYNC_OP_CONTEXT						pOpContext;
	PTB640_FSK_CALL_CONTEXT						pCallContext;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		TB640FskLock( in_un32AdapterIdx, in_un32TrunkIdx );

		/* Initialize local variables */
		pAdapterInfo	= &(g_AppContext->ahAdapterInfo [in_un32AdapterIdx]);
		pTrunkInfo		= &(pAdapterInfo->aTrunkInfo [in_un32TrunkIdx]);
		pTrunkResInfo	= &(pTrunkInfo->aResourceInfo [in_un32TimeslotIdx]);

		/* Make sure the timeslot is not already used */
		if (pTrunkResInfo->State == TB640_FSK_CALL_APP_STATE_NOT_USED || pTrunkResInfo->fInUse)
		{
			TB640_FSK_INCREMENT_STATS (un32NbCallNoFreeTimeslotToSend, 1);
			TBX_EXIT_SUCCESS (TBX_RESULT_OK);
		}

		/* Retrieve the operation context */
		result = TBXAsyncRetrieveOp
		(
			pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
			pTrunkResInfo->hVPResource,
			&pOpContext,
			(PTBX_VOID*)&pCallContext
		);
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve operation context for selected timeslot");
		}

		pTrunkResInfo->fInUse = TBX_TRUE;
		TB640_FSK_INCREMENT_TRANSIANT_CALL (1);

		switch( in_un32Protocol )
		{
			case TB640_FSK_CUSTOM_TEST_TYPE_STRESS:
				pTrunkResInfo->TestType = TB640_FSK_CUSTOM_TEST_TYPE_STRESS;
				break;
		}

		/* Process the state change */
		result = TB640FskProcessStateChange (
		  pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
		  pOpContext,
		  pCallContext,
		  TB640_MSG_ID_FSK_ACTIVATE_TX,
		  NULL);
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to process state change");
		}

		/* 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
	{
		g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
		TB640FskUnlock( in_un32AdapterIdx, in_un32TrunkIdx );
	}

	RETURN_VOID;
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskKickTransmission:	This function starts a transmission sequence on a timeslot
 |
 |	in_un32UnusedParam	:	Unused argument
 |	in_un32AdapterIdx	:	Adapter index
 |	in_un32TrunkIdx		:	Trunk index to open the call on
 |	in_un32TimeslotIdx	:	Timeslot index to open the call on
 |
 |  Note				:	~
 |
 |  Return				:	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID TB640FskKickTransmission (
  IN		TBX_UINT32					in_un32UnusedParam,
  IN		TBX_UINT32					in_un32AdapterIdx,
  IN		TBX_UINT32					in_un32TrunkIdx,
  IN		TBX_UINT32					in_un32TimeslotIdx)
{
	TBX_RESULT									result;
	PTB640_FSK_ADAPTER_INFO						pAdapterInfo;
	PTB640_FSK_TRUNK_INFO						pTrunkInfo;
	PTB640_FSK_TRUNK_RESOURCE_INFO				pTrunkResInfo;
	PTBX_ASYNC_OP_CONTEXT						pOpContext;
	PTB640_FSK_CALL_CONTEXT						pCallContext;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		TB640FskLock( in_un32AdapterIdx, in_un32TrunkIdx );

		/* Initialize local variables */
		pAdapterInfo	= &(g_AppContext->ahAdapterInfo [in_un32AdapterIdx]);
		pTrunkInfo		= &(pAdapterInfo->aTrunkInfo [in_un32TrunkIdx]);
		pTrunkResInfo	= &(pTrunkInfo->aResourceInfo [in_un32TimeslotIdx]);

		/* Make sure the timeslot is in 'ready' state */
		if (pTrunkResInfo->State != TB640_FSK_CALL_APP_STATE_READY )
		{
			TBX_EXIT_SUCCESS (TBX_RESULT_OK);
		}

		/* Retrieve the operation context */
		result = TBXAsyncRetrieveOp
		(
			pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
			pTrunkResInfo->hVPResource,
			&pOpContext,
			(PTBX_VOID*)&pCallContext
		);
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve operation context for selected timeslot");
		}

		/* Process the state change */
		result = TB640FskProcessStateChange (
		  pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
		  pOpContext,
		  pCallContext,
		  TB640_MSG_ID_FSK_KICK_TX_TEST,
		  NULL);
		if (TBX_RESULT_FAILURE(result))
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to process state change");
		}

		/* 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
	{
		g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
		TB640FskUnlock( in_un32AdapterIdx, in_un32TrunkIdx );
	}

	RETURN_VOID;
}




/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskDeactivate	:	This function is called to deactivate a timeslot (return to idle)
 |
 |	in_un32UnusedParam	:	Unused argument.
 |	in_un32AdapterIdx	:	Adapter index
 |	in_un32TrunkIdx		:	Trunk index to open the call on
 |	in_un32TimeslotIdx	:	Timeslot index to open the call on
 |
 |  Note				:	~
 |
 |  Return				:	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640FskDeactivate (
  IN		TBX_UINT32					in_un32UnusedParam,
  IN		TBX_UINT32					in_un32AdapterIdx,
  IN		TBX_UINT32					in_un32TrunkIdx,
  IN		TBX_UINT32					in_un32TimeslotIdx )
{
	TB640FskLock( in_un32AdapterIdx, in_un32TrunkIdx );
	TB640FskDeactivateInternal( in_un32AdapterIdx, in_un32TrunkIdx, in_un32TimeslotIdx );
	TB640FskUnlock( in_un32AdapterIdx, in_un32TrunkIdx );
}


 /*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskDeactivateInternal:	This function is called to deactivate a timeslot (return to idle)
 |
 |	in_un32AdapterIdx:	Adapter index
 |	in_un32TrunkIdx:	Trunk index to open the call on
 |	in_un32TimeslotIdx:	Timeslot index to open the call on
 |
 |  Note			:	~

⌨️ 快捷键说明

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