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

📄 states.c

📁 基于TB板卡的FSK编程,telcobridges fsk develop
💻 C
📖 第 1 页 / 共 5 页
字号:
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TB640_FSK_STATE_FUNCTION(TB640FskProcessStateReady)
{
	TB640_FSK_STATE_ENTRY(TB640_FSK_CALL_APP_STATE_READY)
	{
		TB640FskUpdateStateTimestamp( in_pCallContext, TB640_FSK_READY_TIMEOUT_SEC );

		/* Wait for message transmission to be kicked on this timeslot */
		TB640_FSK_STATE_WAIT;
	}

	TB640_FSK_STATE_DECLARE_FIRST_EVENT (TB640_MSG_ID_FSK_KICK_TX_TEST)
	{
		/* Continue to "Transmitting" state */
		TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_TRANSMITTING);
	}

	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_VP_FSK_NOTIF_RECEIVE)
	{
		PTB640_EVT_VP_FSK_NOTIF_RECEIVE	pEventRxData = (PTB640_EVT_VP_FSK_NOTIF_RECEIVE)in_pMsgPayload;

		if( pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->CloseRemoteMsgId )
		{
			/* Deactivate current timeslot, as requested by remote peer */
			TB640FskDeactivateInternal
			(
				in_pCallContext->un32AdapterIndex,
				in_pCallContext->un32TrunkIndex,
				in_pCallContext->un32TimeslotIndex
			);
		}
		else
		{
			/* Not expecting any FSK data */
			TB640_FSK_INCREMENT_STATS( un32NbUnexpectedRx, 1 );

			TB640_FSK_LOG (TRACE_LEVEL_4, "Received Unexpected Fsk from tr:ts %d:%d\n",
			in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);
		}
	}

	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_VP_TONE_NOTIF_DETECTION)
	{
		/* Not expecting any ack in this state */
		TB640_FSK_INCREMENT_STATS( un32NbRxWhileTxState, 1 );

		TB640_FSK_LOG (TRACE_LEVEL_4, "Received Unexpected Tone from tr:ts %d:%d\n",
		in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);
	}

	TB640_FSK_STATE_RETURN
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskProcessStateTx		FSK processing for call state 'Transmitting'
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TB640_FSK_STATE_FUNCTION(TB640FskProcessStateTx)
{
	TB640_FSK_STATE_ENTRY(TB640_FSK_CALL_APP_STATE_TRANSMITTING)
	{
		TB640FskUpdateStateTimestamp( in_pCallContext, TB640_FSK_DEFAULT_TX_TIMEOUT_SEC );

		/* Ready to transmit. Call function used to select data to transmit */
		TB640FskReadyToTransmitData (in_pCallContext);

		TB640_FSK_STATE_WAIT;
	}

	TB640_FSK_STATE_DECLARE_FIRST_EVENT (TB640_MSG_ID_VP_FSK_NOTIF_RECEIVE)
	{
		PTB640_EVT_VP_FSK_NOTIF_RECEIVE	pEventRxData = (PTB640_EVT_VP_FSK_NOTIF_RECEIVE)in_pMsgPayload;

		if( pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->CloseRemoteMsgId )
		{
			/* Deactivate current timeslot, as requested by remote peer */
			TB640FskDeactivateInternal
			(
				in_pCallContext->un32AdapterIndex,
				in_pCallContext->un32TrunkIndex,
				in_pCallContext->un32TimeslotIndex
			);
		}
		else
		{
			/* Not expecting any FSK data */
			TB640_FSK_INCREMENT_STATS( un32NbUnexpectedRx, 1 );

			TB640_FSK_LOG (TRACE_LEVEL_4, "Received Unexpected Fsk from tr:ts %d:%d\n",
			in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);
		}
	}

	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_VP_TONE_NOTIF_DETECTION)
	{
		PTB640_EVT_VP_TONE_NOTIF_DETECTION		pEvtTone = (PTB640_EVT_VP_TONE_NOTIF_DETECTION)in_pMsgPayload;

		if( pEvtTone->Tone.Digit == TB640_VP_DIGIT_TYPE_DTMF_DIGIT1 )
		{
			TB640_FSK_INCREMENT_STATS (un32NbRxAck, 1);
		}
		else
		{
			/* Not expecting this ack in this state */
			TB640_FSK_INCREMENT_STATS( un32NbUnexpectedAck, 1 );

			TB640_FSK_LOG (TRACE_LEVEL_4, "Received Unexpected Tone from tr:ts %d:%d\n",
			in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);
		}
	}

	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_VP_TONE_NOTIF_STOP)
	{
		TB640_FSK_TX_ACTION					TxAction;

		TB640FskTransmitDataConfirmed( in_pCallContext, &TxAction );

		switch( TxAction )
		{
			case TB640_FSK_TX_ACTION_SEND:
			{
				/* Continue transmitting send some data */
				TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_TRANSMITTING);
			} break;

			default:
			{
				/* Return to idle state */
				TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_READY);
			} break;
		}
	}
#if 0
	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_VP_FSK_NOTIF_END)
	{
		PTB640_MSG_VP_FSK_NOTIF_END			pEvtEnd = (PTB640_MSG_VP_FSK_NOTIF_END)in_pMsgPayload;
		TB640_FSK_TX_ACTION					TxAction;

		TB640FskTransmitDataConfirmed( in_pCallContext, &TxAction );

		switch( TxAction )
		{
			case TB640_FSK_TX_ACTION_SEND:
			{
				/* Continue transmitting send some data */
				TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_TRANSMITTING);
			} break;

			default:
			{
				/* Return to idle state */
				TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_READY);
			} break;
		}
	}
#endif
	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_FSK_TIMEOUT)
	{
		/* Timeout. Did not receive ack for transmitted data. Return to ready state. */
		if( pTrunkResInfo->un32TxRetransmitLeft )
		{
			/* Perform retransmit */
			pTrunkResInfo->un32TxRetransmitLeft--;
			TB640FskRetransmitData( in_pCallContext, pTrunkResInfo->un32TxRetransmitLeft );
			TB640_FSK_INCREMENT_STATS( un32NbTxRetransmit, 1 );
		}
		else
		{
			/* Return to ready state. */
			TB640_FSK_INCREMENT_STATS( un32NbTxSeqTimeout, 1 );
			TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_READY);
		}
	}

	TB640_FSK_STATE_RETURN
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskProcessStateRxGeneric:	FSK processing for call state 'Rx generic'
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TB640_FSK_STATE_FUNCTION(TB640FskProcessStateRxGeneric)
{
	TB640_FSK_STATE_ENTRY(TB640_FSK_CALL_APP_STATE_RECEIVE_STATE_GENERIC)
	{
		TB640FskUpdateStateTimestamp( in_pCallContext, TB640_FSK_RX_TIMEOUT_SEC );

		/* Wait until remote end sends our TxA data */
		TB640_FSK_STATE_WAIT;
	}

	TB640_FSK_STATE_DECLARE_FIRST_EVENT (TB640_MSG_ID_VP_FSK_NOTIF_RECEIVE)
	{
		PTB640_EVT_VP_FSK_NOTIF_RECEIVE	pEventRxData = (PTB640_EVT_VP_FSK_NOTIF_RECEIVE)in_pMsgPayload;

		if( pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->CloseRemoteMsgId )
		{
			/* Deactivate current timeslot, as requested by remote peer */
			TB640FskDeactivateInternal
			(
				in_pCallContext->un32AdapterIndex,
				in_pCallContext->un32TrunkIndex,
				in_pCallContext->un32TimeslotIndex
			);
		}
		else
		{
			/* Received TxA data */
			TB640_FSK_INCREMENT_STATS( un32NbRxPackets, 1 );

			/* Acknowledge we received it */
			TB640FskSendAck (in_pCallContext, 1);

			/* Call data handler function */
			TB640FskHandleReceive( in_pCallContext, pEventRxData );

			/* Switch to appropriate state, according to test type */
			switch( pTrunkResInfo->TestType )
			{
				case TB640_FSK_CUSTOM_TEST_TYPE_STRESS:
				{
					TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_RECEIVE_STATE_STRESS);
				} break;
				default:
				{
					TB640_FSK_CHANGE_STATE (TB640_FSK_CALL_APP_STATE_RECEIVE_STATE_GENERIC);
				} break;
			}
		}
	}

	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_VP_TONE_NOTIF_DETECTION)
	{
		/* Not expecting any FSK ack */
		TB640_FSK_INCREMENT_STATS( un32NbUnexpectedAck, 1 );

		TB640_FSK_LOG (TRACE_LEVEL_4, "Received Unexpected Tone from tr:ts %d:%d\n",
		in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);
	}

	TB640_FSK_STATE_DECLARE_NEXT_EVENT (TB640_MSG_ID_FSK_TIMEOUT)
	{
		/* Timeout. Did not receive data. Continue to wait. */
		TB640_FSK_INCREMENT_STATS( un32NbRxSeqTimeout, 1 );
		/* Reset our timeout */
		TB640FskUpdateStateTimestamp( in_pCallContext, TB640_FSK_RX_TIMEOUT_SEC );
	}

	TB640_FSK_STATE_RETURN

}




/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640FskProcessStateChange:	This function is called to process all events for a specific operation (call)
 |
 |	in_hLib			:	Operation library handle
 |	in_pOpContext	:	Operation context
 |	in_pCallContext	:	Call context
 |	in_un32MsgId	:	Message ID
 |	in_pMsgPayload	:	Message payload
 |
 |  Note			:	We cannot free or re-use the buffer after this function exits.
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskProcessStateChange (
  IN		TBX_ASYNC_LIB_HANDLE		in_hLib,
  IN		PTBX_ASYNC_OP_CONTEXT		in_pOpContext,
  IN		PTB640_FSK_CALL_CONTEXT		in_pCallContext,
  IN		TBX_UINT32					in_un32MsgId,
  IN		PTBX_VOID					in_pMsgPayload)
{
	TB640_FSK_STATE_ACTION				Action;
	PTB640_FSK_ADAPTER_INFO				pAdapterInfo;
	PTB640_FSK_ADAPTER_INFO				pAdapter;
	PTB640_FSK_TRUNK_INFO				pTrunkInfo;
	PTB640_FSK_TRUNK_RESOURCE_INFO		pTrunkResInfo;

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

		TB640FskCheckLock( in_pCallContext->un32AdapterIndex, in_pCallContext->un32TrunkIndex );

		/* Initialize local variables */
		pAdapterInfo	= &(g_AppContext->ahAdapterInfo [in_pCallContext->un32AdapterIndex]);
		pTrunkInfo		= &(pAdapterInfo->aTrunkInfo [in_pCallContext->un32TrunkIndex]);
		pTrunkResInfo	= &(pTrunkInfo->aResourceInfo [in_pCallContext->un32TimeslotIndex]);

		/* Enter the state machine processing */
		do
		{
			/* Switch according to current state */
			switch (pTrunkResInfo->State)
			{
			case TB640_FSK_CALL_APP_STATE_IDLE:
				Action = TB640FskProcessStateIdle (in_hLib,in_pOpContext,in_pCallContext,in_un32MsgId,in_pMsgPayload);		break;

			case TB640_FSK_CALL_APP_STATE_RX_CONFIGURE:
				Action = TB640FskProcessStateRxConfigure (in_hLib,in_pOpContext,in_pCallContext,in_un32MsgId,in_pMsgPayload);		break;

			case TB640_FSK_CALL_APP_STATE_READY:
				Action = TB640FskProcessStateReady (in_hLib,in_pOpContext,in_pCallContext,in_un32MsgId,in_pMsgPayload);		break;

			case TB640_FSK_CALL_APP_STATE_TRANSMITTING:
				Action = TB640FskProcessStateTx (in_hLib,in_pOpContext,in_pCallContext,in_un32MsgId,in_pMsgPayload);		break;

			case TB640_FSK_CALL_APP_STATE_RECEIVE_STATE_GENERIC:
			case TB640_FSK_CALL_APP_STATE_RECEIVE_STATE_STRESS:
				Action = TB640FskProcessStateRxGeneric (in_hLib,in_pOpContext,in_pCallContext,in_un32MsgId,in_pMsgPayload);		break;


			default:
				Action = TB640_FSK_STATE_ACTION_WAIT;
				TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unknown state");
				break;
			}
		}
		while (Action == TB640_FSK_STATE_ACTION_CONTINUE);

		/* Do we need to destroy the call context */
		if (Action == TB640_FSK_STATE_ACTION_DESTROY_CONTEXT)
		{
			TBXAsyncDestroyOp (
			  in_hLib,
			  in_pOpContext);
		}

		/* 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
	{
	}

	RETURN;
}


⌨️ 快捷键说明

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