📄 config.c
字号:
}
}
#else
{
for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo[un32AdapIdx]);
/* Until we have the feature count, assume we have 64 trunks */
pAdapterInfo->un32NbTrunk = TB640_FSK_MAX_SUPPORTED_TRUNKS_PER_ADAPTER;
result = TB640FskCheckAdapterFeatures(pAdapterInfo);
if ( result == TBX_RESULT_NOT_SUPPORTED_BY_LICENSE )
{
TBX_ERROR_RESULT = result;
}
else if (TBX_RESULT_FAILURE(result))
{
TBX_EXIT_ERROR(result, 0, "Unable to retrieve adapter features information");
}
}
if( result == TBX_RESULT_NOT_SUPPORTED_BY_LICENSE )
{
TBX_EXIT_ERROR(result, 0, "Adapter features mismatch");
}
/*-----------------------------------------------------------------------------------------------------------------------
| Attach to the adapters asynchronously
*----------------------------------------------------------------------------------------------------------------------*/
/* Create a new filter to receive response from adapters*/
un64UniqueID = g_AppContext->ahAdapterInfo [0].aun64UniqueId [0] + 0x100 + rand();
FilterParams.un32StructVersion = 1;
FilterParams.FilterMask = (TBX_FILTER_MSG_ID|TBX_FILTER_MSG_USER_CONTEXT1);
FilterParams.MsgId = TB640_MSG_ID_ADAPTER_OP_ATTACH;
FilterParams.un64UserContext1 = un64UniqueID;
result = TBXCreateMsgFilter (g_AppContext->hTbxLib, 1, &FilterParams, &hFilter);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to create event filter");
}
/* Attach to the adapters */
un32ExpectedNbResponse = 0;
for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
/* Format the "attach" request */
result = TBXGetMsg (g_AppContext->hTbxLib, sizeof(*pMsg), &hMsg);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_OUT_OF_MEMORY, 0, "Unable to allocate a message buffer");
}
/* Format the message header */
TBX_FORMAT_MSG_HEADER (
hMsg,
TB640_MSG_ID_ADAPTER_OP_ATTACH,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsg),
pAdapterInfo->hAdapter,
un64UniqueID,
un32AdapIdx);
/* Format the message payload */
pMsg = (PTB640_MSG_ADAPTER_OP_ATTACH)TBX_MSG_PAYLOAD_POINTER (hMsg);
pReq = &(pMsg->Request);
pReq->un32MsgVersion = 1;
pReq->fEnableAutoReattach = TBX_TRUE;
/* Send the message */
TBXSendMsg (g_AppContext->hTbxLib, hMsg, NULL);
hMsg = TBX_HANDLE_INVALID;
un32ExpectedNbResponse++;
}
/* Wait the response */
while (un32ExpectedNbResponse > 0)
{
/* Wait for responses */
result = TBXReceiveMsg (g_AppContext->hTbxLib, hFilter, TB640_FSK_ADAPTER_ATTACH_TIMEOUT_MSEC, &hMsg);
if ((result != TBX_RESULT_API_TIMEOUT) && TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve message");
}
else if (result == TBX_RESULT_API_TIMEOUT)
{
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Unable to attach to %s\n", pAdapterInfo->szAdapterName);
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to attach to adapter");
}
/* Retrieve the adapter number */
un32AdapIdx = (TBX_UINT32)TBX_MSG_USER_CONTEXT2_GET(hMsg);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
pMsg = (PTB640_MSG_ADAPTER_OP_ATTACH)TBX_MSG_PAYLOAD_POINTER (hMsg);
pRsp = &(pMsg->Response);
/* We are now attached */
un32ExpectedNbResponse--;
pAdapterInfo->fAttached = TBX_TRUE;
/* Free the message */
TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
hMsg = NULL;
}
}
#endif
/* 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 any received message */
if (hMsg != (TBX_MSG_HANDLE)NULL)
{
TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
hMsg = NULL;
}
/* Free the filter */
if (hFilter != NULL)
{
TBXDestroyMsgFilter (g_AppContext->hTbxLib, hFilter);
hFilter = NULL;
}
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640FskCloseAdapters: This function closes previously opened adapters
|
| ~ : No arguments used
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640FskCloseAdapters (void)
{
TBX_RESULT result;
TBX_FILTER_PARAMS FilterParams;
TBX_UINT64 un64UniqueID;
TBX_FILTER_HANDLE hFilter;
TBX_UINT32 un32AdapIdx;
TBX_UINT32 un32ExpectedNbResponse;
TBX_MSG_HANDLE hMsg;
PTB640_FSK_ADAPTER_INFO pAdapterInfo;
PTB640_MSG_ADAPTER_OP_DETACH pMsg;
PTB640_REQ_ADAPTER_OP_DETACH pReq;
PTB640_RSP_ADAPTER_OP_DETACH pRsp;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
hFilter = NULL;
hMsg = NULL;
TB640_FSK_LOG (TRACE_LEVEL_4, "Detaching from adapter(s)\n");
/*-----------------------------------------------------------------------------------------------------------------------
| Detach from the adapters asynchronously
*----------------------------------------------------------------------------------------------------------------------*/
/* Create a new filter to receive response from adapters*/
un64UniqueID = g_AppContext->ahAdapterInfo [0].aun64UniqueId [0] + 0x100 + rand();
FilterParams.un32StructVersion = 1;
FilterParams.FilterMask = (TBX_FILTER_MSG_ID|TBX_FILTER_MSG_USER_CONTEXT1);
FilterParams.MsgId = TB640_MSG_ID_ADAPTER_OP_DETACH;
FilterParams.un64UserContext1 = un64UniqueID;
result = TBXCreateMsgFilter (g_AppContext->hTbxLib, 1, &FilterParams, &hFilter);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to create event filter");
}
/* Detach from the adapters */
un32ExpectedNbResponse = 0;
for (un32AdapIdx=0; un32AdapIdx<g_AppContext->un32NbAdapter; un32AdapIdx++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
/* If the adapter was not attached, no need to send any message */
if (pAdapterInfo->fAttached == TBX_FALSE)
{
continue;
}
/* Format the "detach" request */
result = TBXGetMsg (g_AppContext->hTbxLib, sizeof(*pMsg), &hMsg);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_OUT_OF_MEMORY, 0, "Unable to allocate a message buffer");
}
/* Format the message header */
TBX_FORMAT_MSG_HEADER (
hMsg,
TB640_MSG_ID_ADAPTER_OP_DETACH,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsg),
pAdapterInfo->hAdapter,
un64UniqueID,
un32AdapIdx);
/* Format the message payload */
pMsg = (PTB640_MSG_ADAPTER_OP_DETACH)TBX_MSG_PAYLOAD_POINTER (hMsg);
pReq = &(pMsg->Request);
pReq->un32MsgVersion = 1;
/* Send the message */
TBXSendMsg (g_AppContext->hTbxLib, hMsg, NULL);
hMsg = TBX_HANDLE_INVALID;
un32ExpectedNbResponse++;
}
/* Wait the response */
while (un32ExpectedNbResponse > 0)
{
/* Wait for responses */
result = TBXReceiveMsg (g_AppContext->hTbxLib, hFilter, TB640_FSK_ADAPTER_ATTACH_TIMEOUT_MSEC, &hMsg);
if ((result != TBX_RESULT_API_TIMEOUT) && TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to retrieve message");
}
else if (result == TBX_RESULT_API_TIMEOUT)
{
TB640_FSK_LOG (TRACE_LEVEL_ALWAYS, "Unable to detach from %s\n", pAdapterInfo->szAdapterName);
TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "Unable to detach from adapter");
}
/* Retrieve the adapter number */
un32AdapIdx = (TBX_UINT32)TBX_MSG_USER_CONTEXT2_GET(hMsg);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapIdx]);
pMsg = (PTB640_MSG_ADAPTER_OP_DETACH)TBX_MSG_PAYLOAD_POINTER (hMsg);
pRsp = &(pMsg->Response);
/* We are now attached */
un32ExpectedNbResponse--;
pAdapterInfo->fAttached = TBX_FALSE;
pAdapterInfo->hAdapter = (TBX_ADAPTER_HANDLE)NULL;
/* Free the message */
TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
hMsg = NULL;
}
/* 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 any received message */
if (hMsg != (TBX_MSG_HANDLE)NULL)
{
TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
hMsg = NULL;
}
/* Free the filter */
if (hFilter != NULL)
{
TBXDestroyMsgFilter (g_AppContext->hTbxLib, hFilter);
hFilter = NULL;
}
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640FskVPResourcesGetKey: This function is called by the hash library to retrieve the key from a VP resource
| element
|
| in_pUserContext : User context (not used)
| in_pElement : Pointer to the element
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_HASH_KEY TB6
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -