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

📄 states.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
			{
				g_fRefreshDisplay |= (TB640_FSK_CLI_REFRESH_DISPLAY);
			}
			break;
		}

		/* 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
	{
		TB640FskUnlockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );
	}

	RETURN_VOID;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskResponseMessageHandler:	This function is called by the operation library when it has receive a response that
 |										matches a specific operation (i.e. call) context
 |
 |	in_pvAppContext			:	Context passed by the application when the async lib was initialized.
 |	in_pRequestContext		:	The context of the request that has received its response.
 |	in_un32SearchKey		:	The search key of the operation that contained this request.
 |								The appliation has to search for the op context if it needs it by calling
 |								TBXAsyncRetrieveOp().
 |	in_MsgId				:	The MessageId of the received response.
 |	in_pvMsgPayload			:	The payload of the received response.
 |
 |  Note			:	~
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID
TB640FskResponseMessageHandler(
	IN		PTBX_VOID								in_pvAppContext,
	IN		PTBX_VOID								in_pRequestContext,
	IN		TBX_UINT32								in_un32SearchKey,
	IN		TBX_MSG_ID								in_MsgId,
	IN		PTBX_VOID								in_pvMsgPayload )
{
	TBX_RESULT						result;
	TBX_UINT32						un32AdapterIdx;
	TBX_UINT32						un32OpLibIdx;
	PTBX_ASYNC_OP_CONTEXT			pOpContext;
	PTB640_FSK_ADAPTER_INFO			pAdapterInfo;
	PTB640_FSK_CALL_CONTEXT			pCallContext;
	PTB640_FSK_TRUNK_INFO			pTrunkInfo;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pTrunkInfo = NULL;

		/* Retrieve the adapter index and operation lib index */
		TB640_FSK_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
		pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);

		TB640FskLockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );

		/* Retrieve the operation context */
		result = TBXAsyncRetrieveOp
		(
			pAdapterInfo->ahOperationLib [un32OpLibIdx],
			in_un32SearchKey,
			&pOpContext,
			(PTBX_VOID*)&pCallContext
		);
		if( pOpContext )
		{
			if (pCallContext->fSpuriousCallContext != TBX_FALSE)
			{
				/* This field is necessary for spurious call context */
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [pCallContext->un32TrunkIndex]);
			}

			/* Check which message did we received ? */
			switch (in_MsgId)
			{
			case TB640_MSG_ID_VP_FSK_TRANSMIT:
				{
					/* Response for a "Tx data" we have performed. We can ignore, we are waiting for the
					   remote side "ack" for this transmission instead. */
				}
				break;

			case TB640_MSG_ID_VP_FSK_SEND_DIGIT:
				{
					/* Response for a "Tx ack" we have performed. We don't care. */
				}
				break;

			case TB640_MSG_ID_VP_FSK_RECEIVE:
				{
					/* Response for configuring a timeslot in receive. */

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

			/* Unknown message, just discard */
			default:
				TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Unknow message Id 0x%08X\n", in_MsgId);
				TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unknown response received");
				break;
			}


			/* Do we need to destroy the operation context ? */
			if (pCallContext->fSpuriousCallContext != TBX_FALSE)
			{
				TBXAsyncDestroyOp (
				  pAdapterInfo->ahOperationLib [pTrunkInfo->un32OpLibIdx],
				  pOpContext);
			}
		}
		else
		{
			/* Operation does not exist. Probably a race condition where another of our threads has
			   destroyed the operation before this callback occurs. Just ignore this callback! */
		}

		/* 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
	{
		TB640FskUnlockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );
	}

	RETURN_VOID;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskRequestTimeoutHandler:	This function is called by the operation library when it has declared a timeout on a
 |									request on a specific call.
 |
 |	in_pvAppContext			:	Context passed by the application when the async lib was initialized.
 |	in_pRequestContext		:	The context of the request that has timed out.
 |								WARNING: This value will be NULL when an OPERATION timeout, rather than one of
 |										 the requests it contains...
 |	in_un32SearchKey		:	The search key of the operation that contained this request.
 |								The appliation has to search for the op context if it needs it by calling
 |								TBXAsyncRetrieveOp().
 |
 |  Note			:	~
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID TB640FskRequestTimeoutHandler (
  IN		PTBX_VOID 						in_pvAppContext,
  IN		PTBX_VOID						in_pRequestContext,
  IN		TBX_UINT32						in_un32SearchKey)
{
	TBX_RESULT						result;
	TBX_UINT32						un32AdapterIdx;
	TBX_UINT32						un32OpLibIdx;
	PTBX_ASYNC_OP_CONTEXT			pOpContext;
	PTB640_FSK_ADAPTER_INFO			pAdapterInfo;
	PTB640_FSK_CALL_CONTEXT			pCallContext;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */

		/* Retrieve the adapter index and operation lib index */
		TB640_FSK_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
		pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);

		TB640FskLockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );

		/* Retrieve the operation context */
		result = TBXAsyncRetrieveOp
		(
			pAdapterInfo->ahOperationLib [un32OpLibIdx],
			in_un32SearchKey,
			&pOpContext,
			(PTBX_VOID*)&pCallContext
		);
		if( pOpContext )
		{
			PTB640_FSK_ADAPTER_INFO				pAdapterInfo;
			PTB640_FSK_TRUNK_INFO				pTrunkInfo;
			PTB640_FSK_TRUNK_RESOURCE_INFO		pTrunkResInfo;

			pAdapterInfo = &(g_AppContext->ahAdapterInfo [pCallContext->un32AdapterIndex]);
			pTrunkInfo = &(pAdapterInfo->aTrunkInfo [pCallContext->un32TrunkIndex]);
			pTrunkResInfo = &(pTrunkInfo->aResourceInfo [pCallContext->un32TimeslotIndex]);

			TB640_FSK_LOG (TRACE_LEVEL_4, "Received TB640_MSG_ID_FSK_TIMEOUT tr:ts %d:%d\n",
			pCallContext->un32TrunkIndex, pCallContext->un32TimeslotIndex);

			/* Process the state change */
			result = TB640FskProcessStateChange (
			  pAdapterInfo->ahOperationLib [un32OpLibIdx],
			  pOpContext,
			  pCallContext,
			  TB640_MSG_ID_FSK_TIMEOUT,
			  NULL);
			if (TBX_RESULT_FAILURE(result))
			{
				TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to process state change");
			}
		}
		else
		{
			/* Operation does not exist. Probably a race condition where another of our threads has
			   destroyed the operation before the timeout occurs. Just ignore this timeout! */
		}

		/* 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
	{
		TB640FskUnlockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );
	}

	RETURN_VOID;
}





/*-------------------------------------------------------------------------------------------------------------------------------
 |  											Service message request functions
 *------------------------------------------------------------------------------------------------------------------------------*/



/*-------------------------------------------------------------------------------------------------------------------------------
 |  TB640FskSendRxConfigure:	This function is called to send a "Rx configure" message to configure a timeslot in Rx
 *------------------------------------------------------------------------------------------------------------------------------*/
TB640_FSK_SERVICE_FUNCTION (TB640FskSendRxConfigure)
{
	PTB640_REQ_VP_FSK_RECEIVE					pReq;

	TB640_FSK_SERVICE_FUNCTION_VAR()

	TB640_FSK_LOG (TRACE_LEVEL_1, "Sending 'RxConfigure': tr:ts %d:%d\n",
	in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);

	/* Allocate the request */
	TB640_FSK_SERVICE_FUNCTION_ALLOC (pReq, sizeof(*pReq), TB640_MSG_ID_VP_FSK_RECEIVE);
	#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
	TBX_MSG_TYPE_SET( pAsyncRequest->hMsg, TBX_MSG_TYPE_EVENT );
	#endif

	/* Fill the message */
	pReq = (PTB640_REQ_VP_FSK_RECEIVE)TBX_MSG_PAYLOAD_POINTER(pAsyncRequest->hMsg);
	pReq->un32MsgVersion			= 1;
	pReq->hVPResource				= pTrunkResInfo->hVPResource;

	/* Post the message and exit */
	TB640_FSK_INCREMENT_STATS (un32NbTxPackets, 1);
	TB640_FSK_SERVICE_FUNCTION_POST_EVENT();
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |  TB640FskSendWaitRemote1:	This function is called to send a "Wait remote 1" FSK message
 *------------------------------------------------------------------------------------------------------------------------------*/
TB640_FSK_SERVICE_FUNCTION (TB640FskSendWaitRemote1)
{
	PTB640_REQ_VP_FSK_TRANSMIT					pReq;
	TBX_UINT32									aun32FSKData[2];

	TB640_FSK_SERVICE_FUNCTION_VAR()

	TB640_FSK_LOG (TRACE_LEVEL_1, "Sending FSK 'WaitRemote1' tr:ts %d:%d\n",
	in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);

	/* Allocate the request */
	TB640_FSK_SERVICE_FUNCTION_ALLOC (pReq, sizeof(*pReq), TB640_MSG_ID_VP_FSK_TRANSMIT);
	#ifdef TB640_FSK_USE_INTERHOST_SIMULATION
	TBX_MSG_TYPE_SET( pAsyncRequest->hMsg, TBX_MSG_TYPE_EVENT );
	#endif

	/* Assign an expected remote data for this message so we identify the reply */
	if( in_pCallContext->ExpectedWaitRemote1Data == 0 )
	{
		g_AppContext->WaitRemote1Data++;
		in_pCallContext->ExpectedWaitRemote1Data = g_AppContext->WaitRemote1Data;
		if( g_AppContext->WaitRemote1Data == 0 ) g_AppContext->WaitRemote1Data++;	/* Avoid 0 */
	}

	/* Prepare our FSK data */
	aun32FSKData[0]	= in_pCallContext->ExpectedWaitRemote1Data;

	/* Fill the message */
	pReq = (PTB640_REQ_VP_FSK_TRANSMIT)TBX_MSG_PAYLOAD_POINTER(pAsyncRequest->hMsg);
	pReq->un32MsgVersion						= 1;
	pReq->hVPResource							= pTrunkResInfo->hVPResource;
	pReq->fMsgEndEvent							= TBX_FALSE;
	pReq->fVoiceFallBack						= TBX_FALSE;
	pReq->un8MsgNumber							= 1;
	pReq->un8BurstSize							= 1;
	pReq->FskMsg.Gr30.un8MsgType				= g_AppContext->WaitRemote1MsgId;
	pReq->FskMsg.Gr30.un8MsgLength				= sizeof(aun32FSKData);
	pReq->FskMsg.un16PayloadLength				= pReq->FskMsg.Gr30.un8MsgLength + 2;
	pReq->FskMsg.Gr30.Mmb.un8MsgNumber			= 1;
	memcpy
	(
		pReq->FskMsg.Gr

⌨️ 快捷键说明

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