📄 protocol.c
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
|
| Project: VoiceLink TB640 sample (FSK)
|
| Filename: states.c
|
| Copyright: TelcoBridges 2002-2003, All Rights Reserved
|
| Description: This file contains custom protocols based on FSK protocol
|
| Notes: Tabs = 4
|
*-------------------------------------------------------------------------------------------------------------------------------
|
| Revision: $Revision: 1.7 $
|
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Includes
*------------------------------------------------------------------------------------------------------------------------------*/
#include "includes.h"
/*--------------------------------------------------------------------------------------------------------------------------------
| Forward declarations
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Defines
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Types
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Versioning
*------------------------------------------------------------------------------------------------------------------------------*/
#if 0
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.7 $";
#endif
/*--------------------------------------------------------------------------------------------------------------------------------
| Global variables
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Macros
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Function Prototypes
*------------------------------------------------------------------------------------------------------------------------------*/
static TBX_RESULT TB640FskReadyToTransmitDataStress
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
IN PTB640_FSK_ADAPTER_INFO in_pAdapterInfo,
IN PTB640_FSK_TRUNK_INFO in_pTrunkInfo,
IN PTB640_FSK_TRUNK_RESOURCE_INFO in_pTrunkResInfo
);
static TBX_RESULT TB640FskRetransmitDataStress
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
IN PTB640_FSK_ADAPTER_INFO in_pAdapterInfo,
IN PTB640_FSK_TRUNK_INFO in_pTrunkInfo,
IN PTB640_FSK_TRUNK_RESOURCE_INFO in_pTrunkResInfo
);
TB640_FSK_SERVICE_FUNCTION (TB640FskSendTxStressStart);
TB640_FSK_SERVICE_FUNCTION (TB640FskSendTxStressA);
TB640_FSK_SERVICE_FUNCTION (TB640FskSendTxStressB);
TB640_FSK_SERVICE_FUNCTION (TB640FskSendTxStressC);
TB640_FSK_SERVICE_FUNCTION (TB640FskSendTxStressD);
/*--------------------------------------------------------------------------------------------------------------------------------
| Implementation
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
| TB640FskTransmitDataModeEnter: State machine is entering the "data transmit mode".
| According to selected protocol, this applicaion may:
| - Do nothing
| - Send initial data to remote peer
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640FskTransmitDataModeEnter
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
OUT PTB640_FSK_TX_ACTION out_pTxAction
)
{
TBX_RESULT result = TBX_RESULT_OK;
PTB640_FSK_ADAPTER_INFO pAdapterInfo;
PTB640_FSK_TRUNK_INFO pTrunkInfo;
PTB640_FSK_TRUNK_RESOURCE_INFO pTrunkResInfo;
pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_pCallContext->un32AdapterIndex]);
pTrunkInfo = &(pAdapterInfo->aTrunkInfo [in_pCallContext->un32TrunkIndex]);
pTrunkResInfo = &(pTrunkInfo->aResourceInfo [in_pCallContext->un32TimeslotIndex]);
/* Transmit data according to current test in progress */
switch( pTrunkResInfo->TestType )
{
case TB640_FSK_CUSTOM_TEST_TYPE_STRESS:
{
/* Reset stress test state */
pTrunkResInfo->StateStressTest = 0;
/* First transmission is required to "wake" remote side. */
*out_pTxAction = TB640_FSK_TX_ACTION_SEND;
} break;
default:
{
/* Don't do anything */
*out_pTxAction = TB640_FSK_TX_ACTION_NONE;
} break;
}
return result;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| TB640FskReadyToTransmitData: State machine is ready to transmit data for specified timeslot
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640FskReadyToTransmitData
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext
)
{
TBX_RESULT result = TBX_RESULT_OK;
PTB640_FSK_ADAPTER_INFO pAdapterInfo;
PTB640_FSK_TRUNK_INFO pTrunkInfo;
PTB640_FSK_TRUNK_RESOURCE_INFO pTrunkResInfo;
pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_pCallContext->un32AdapterIndex]);
pTrunkInfo = &(pAdapterInfo->aTrunkInfo [in_pCallContext->un32TrunkIndex]);
pTrunkResInfo = &(pTrunkInfo->aResourceInfo [in_pCallContext->un32TimeslotIndex]);
/* Transmit data according to current test in progress */
switch( pTrunkResInfo->TestType )
{
case TB640_FSK_CUSTOM_TEST_TYPE_STRESS:
{
result = TB640FskReadyToTransmitDataStress
(
in_pCallContext,
pAdapterInfo,
pTrunkInfo,
pTrunkResInfo
);
} break;
default:
{
/* Not supposed to happen */
} break;
}
return result;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| TB640FskTransmitDataConfirmed: State machine confirmed that the transmission has completed successfully.
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640FskTransmitDataConfirmed
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
OUT PTB640_FSK_TX_ACTION out_pTxAction
)
{
TBX_RESULT result = TBX_RESULT_OK;
PTB640_FSK_ADAPTER_INFO pAdapterInfo;
PTB640_FSK_TRUNK_INFO pTrunkInfo;
PTB640_FSK_TRUNK_RESOURCE_INFO pTrunkResInfo;
pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_pCallContext->un32AdapterIndex]);
pTrunkInfo = &(pAdapterInfo->aTrunkInfo [in_pCallContext->un32TrunkIndex]);
pTrunkResInfo = &(pTrunkInfo->aResourceInfo [in_pCallContext->un32TimeslotIndex]);
/* Default action: stop sending: */
*out_pTxAction = TB640_FSK_TX_ACTION_NONE;
/* Transmit data according to current test in progress */
switch( pTrunkResInfo->TestType )
{
case TB640_FSK_CUSTOM_TEST_TYPE_STRESS:
{
if( pTrunkResInfo->StateStressTest == 0 )
{
*out_pTxAction = TB640_FSK_TX_ACTION_NONE;
}
else
{
*out_pTxAction = TB640_FSK_TX_ACTION_SEND;
}
/* Continue to next state */
pTrunkResInfo->StateStressTest++;
if( pTrunkResInfo->StateStressTest > 4 )
{
/* Send loop finished */
pTrunkResInfo->StateStressTest = 1;
/* Continue to send */
*out_pTxAction = TB640_FSK_TX_ACTION_NONE;
}
} break;
default:
{
/* Not supposed to happen */
} break;
}
return result;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| TB640FskRetransmitData: State machine requires retransmission of previously sent data for specified timeslot
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640FskRetransmitData
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
IN TBX_UINT32 in_un32RetransmitCount
)
{
TBX_RESULT result = TBX_RESULT_OK;
PTB640_FSK_ADAPTER_INFO pAdapterInfo;
PTB640_FSK_TRUNK_INFO pTrunkInfo;
PTB640_FSK_TRUNK_RESOURCE_INFO pTrunkResInfo;
pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_pCallContext->un32AdapterIndex]);
pTrunkInfo = &(pAdapterInfo->aTrunkInfo [in_pCallContext->un32TrunkIndex]);
pTrunkResInfo = &(pTrunkInfo->aResourceInfo [in_pCallContext->un32TimeslotIndex]);
/* Transmit data according to current test in progress */
switch( pTrunkResInfo->TestType )
{
case TB640_FSK_CUSTOM_TEST_TYPE_STRESS:
{
result = TB640FskRetransmitDataStress
(
in_pCallContext,
pAdapterInfo,
pTrunkInfo,
pTrunkResInfo
);
} break;
default:
{
/* Not supposed to happen */
} break;
}
return result;
}
TBX_RESULT TB640FskHandleReceive
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
IN PTB640_EVT_VP_FSK_NOTIF_RECEIVE in_pEventRxData
)
{
TBX_RESULT result = TBX_RESULT_OK;
PTB640_FSK_ADAPTER_INFO pAdapterInfo;
PTB640_FSK_TRUNK_INFO pTrunkInfo;
PTB640_FSK_TRUNK_RESOURCE_INFO pTrunkResInfo;
pAdapterInfo = &(g_AppContext->ahAdapterInfo [in_pCallContext->un32AdapterIndex]);
pTrunkInfo = &(pAdapterInfo->aTrunkInfo [in_pCallContext->un32TrunkIndex]);
pTrunkResInfo = &(pTrunkInfo->aResourceInfo [in_pCallContext->un32TimeslotIndex]);
if( in_pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->TxStressTestMsgId )
{
/* Remote side is performing the "stress test" option */
pTrunkResInfo->TestType = TB640_FSK_CUSTOM_TEST_TYPE_STRESS;
pTrunkResInfo->StateStressTest = 1;
}
else if( in_pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->TxAMsgId )
{
/* Remote side is performing the "stress test" option */
pTrunkResInfo->TestType = TB640_FSK_CUSTOM_TEST_TYPE_STRESS;
pTrunkResInfo->StateStressTest = 2;
}
else if( in_pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->TxBMsgId )
{
/* Remote side is performing the "stress test" option */
pTrunkResInfo->TestType = TB640_FSK_CUSTOM_TEST_TYPE_STRESS;
pTrunkResInfo->StateStressTest = 3;
}
else if( in_pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->TxCMsgId )
{
/* Remote side is performing the "stress test" option */
pTrunkResInfo->TestType = TB640_FSK_CUSTOM_TEST_TYPE_STRESS;
pTrunkResInfo->StateStressTest = 4;
}
else if( in_pEventRxData->FskMsg.Gr30.un8MsgType == g_AppContext->TxDMsgId )
{
/* Remote side is performing the "stress test" option */
pTrunkResInfo->TestType = TB640_FSK_CUSTOM_TEST_TYPE_STRESS;
pTrunkResInfo->StateStressTest = 1;
}
else
{
/* Todo: Implement whatever protocol for this timeslot */
TB640_FSK_INCREMENT_STATS( un32NbUnexpectedRx, 1 );
TB640_FSK_LOG (TRACE_LEVEL_4, "Received Unexpected Fsk Data (msgType=0x%X,msgSz=%d) from tr:ts %d:%d\n",
in_pEventRxData->FskMsg.Gr30.un8MsgType, in_pEventRxData->FskMsg.Gr30.un8MsgLength,
in_pCallContext->un32TrunkIndex, in_pCallContext->un32TimeslotIndex);
}
return result;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| TB640FskReadyToTransmitDataStress: Transmit next stress test data
*------------------------------------------------------------------------------------------------------------------------------*/
static TBX_RESULT TB640FskReadyToTransmitDataStress
(
IN PTB640_FSK_CALL_CONTEXT in_pCallContext,
IN PTB640_FSK_ADAPTER_INFO in_pAdapterInfo,
IN PTB640_FSK_TRUNK_INFO in_pTrunkInfo,
IN PTB640_FSK_TRUNK_RESOURCE_INFO in_pTrunkResInfo
)
{
TBX_RESULT result = TBX_RESULT_OK;
/* Update current state timestamp */
TB640FskUpdateStateTimestamp( in_pCallContext, TB640_FSK_STRESS_TX_TIMEOUT_SEC );
/* Update number of retransmit left */
in_pTrunkResInfo->un32TxRetransmitLeft = 1;
switch( in_pTrunkResInfo->StateStressTest )
{
case 0:
/* Send a Stress Stess start message */
TB640FskSendTxStressStart( in_pCallContext );
break;
case 1:
result = TB640FskSendTxStressA( in_pCallContext );
break;
case 2:
result = TB640FskSendTxStressB( in_pCallContext );
break;
case 3:
result = TB640FskSendTxStressC( in_pCallContext );
break;
case 4:
result = TB640FskSendTxStressD( in_pCallContext );
break;
}
return result;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| TB640FskRetransmitDataStress: Retransmit stress test data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -