📄 config.c
字号:
/* Create a filter to receive ADAPTER_ADD events */
FilterParams.un32StructVersion = 1;
FilterParams.FilterMask = TBX_FILTER_MSG_ID;
FilterParams.MsgId = TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED;
result = TBXCreateMsgFilter (g_AppContext->hTbxLib, 1, &FilterParams, &hFilter);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to create event filter");
}
/*-----------------------------------------------------------------------------------------------------------------------
| List all adapters currently known by the TBX library
*----------------------------------------------------------------------------------------------------------------------*/
/* Retrieve the list of currently known adapters */
result = TBXGetAdaptersList (g_AppContext->hTbxLib, TB640_ISDN_MAX_ADAPTER_DISCOVERED, &nAdapters, aAdapters);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to retrieve adapter list");
}
/* Get the name of currently known adapters */
for (un32Count=0; un32Count<nAdapters; un32Count++)
{
/* Get the name of the adapter */
result = TBXGetAdapterInfo (g_AppContext->hTbxLib, aAdapters [un32Count], &Info);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to retrieve adapter information");
}
/* Keep the adapter name */
strcpy (aszAdapterName [un32Count], Info.szAdapterName);
/* Convert in caps */
TB640IsdnToUpper (aszAdapterName [un32Count]);
}
/*-----------------------------------------------------------------------------------------------------------------------
| Wait for other adapters to register dynamically
*----------------------------------------------------------------------------------------------------------------------*/
/* Start the waiting loop */
un32AdapterLeftToDiscover = g_AppContext->un32NbAdapter;
un32TimeMsec = 0;
while ((un32AdapterLeftToDiscover > 0) && (un32TimeMsec <= TB640_ISDN_ADAPTER_DISCOVERY_TIMEOUT_MSEC))
{
/* Cycle through all adapter configurations */
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
/* Was this adapter already found ? */
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
if (pAdapterInfo->hAdapter != (TBX_ADAPTER_HANDLE)NULL)
{
continue;
}
/*--------------------------------------------------------------------------------------------------------------
| Check for specific named adapters
*-------------------------------------------------------------------------------------------------------------*/
/* Check for a specific name ? */
if (strcmp (pAdapterInfo->szAdapterName, TB640_ISDN_ANY_ADAPTER_STRING) != 0)
{
/* Search for that specific adapter */
for (un32Count2=0; un32Count2<(TBX_UINT32)nAdapters; un32Count2++)
{
/* Compare the names */
if (strcmp (aszAdapterName [un32Count2], pAdapterInfo->szAdapterName) == 0)
{
/* We found the adapter */
un32AdapterLeftToDiscover--;
/* Store the adapter handle */
pAdapterInfo->hAdapter = aAdapters [un32Count2];
afAdapterUsed [un32Count2] = TBX_TRUE;
TB640_ISDN_LOG (TRACE_LEVEL_4, "Adapter %s will be used as adapter %d/%d\n", \
pAdapterInfo->szAdapterName, (un32Count+1), g_AppContext->un32NbAdapter);
break;
}
}
}
/*--------------------------------------------------------------------------------------------------------------
| Check for unspecific adapters
*-------------------------------------------------------------------------------------------------------------*/
/* Take any adapter in the list */
else
{
/* Search for any adapter that is not yet assigned */
for (un32Count2=0; un32Count2<(TBX_UINT32)nAdapters; un32Count2++)
{
TBX_ADAPTER_INFO Info;
/* Is this a TB640? */
result = TBXGetAdapterInfo (g_AppContext->hTbxLib, aAdapters [un32Count2], &Info);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to retrieve adapter information");
}
if( Info.AdapterType == TBX_ADAPTER_TYPE_TB640 )
{
/* Compare the names */
if (afAdapterUsed [un32Count2] == TBX_FALSE)
{
/* We found the adapter */
un32AdapterLeftToDiscover--;
/* Store the adapter handle */
pAdapterInfo->hAdapter = aAdapters [un32Count2];
afAdapterUsed [un32Count2] = TBX_TRUE;
/* Copy the adapter name to our internal structure */
strcpy (pAdapterInfo->szAdapterName, aszAdapterName [un32Count2]);
TB640_ISDN_LOG (TRACE_LEVEL_0, "Adapter %s will be used as adapter %d/%d\n", \
pAdapterInfo->szAdapterName, (un32Count+1), g_AppContext->un32NbAdapter);
break;
}
}
}
}
/*--------------------------------------------------------------------------------------------------------------
| Any events for new adapters ?
*-------------------------------------------------------------------------------------------------------------*/
/* Check if we received any events of card discovery */
result = TBXReceiveMsg (g_AppContext->hTbxLib, hFilter, TB640_ISDN_ADAPTER_LOOP_MSG_RECEIVE_TIMEOUT_MSEC, &hMsg);
if ((result != TBX_RESULT_API_TIMEOUT) && TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to retrieve message");
}
/* Have we received a new board ? */
if (hMsg != (TBX_MSG_HANDLE)NULL)
{
pEvent = (PTBX_EVT_API_NOTIF_ADAPTER_ADDED)TBX_MSG_PAYLOAD_POINTER(hMsg);
/* Convert in caps */
TB640IsdnToUpper (pEvent->Info.szAdapterName);
/* Make sure we didn't already receive that board identification */
for (un32Count=0; un32Count<nAdapters; un32Count++)
{
/* This adapter is already registered */
if (strcmp(aszAdapterName [un32Count], pEvent->Info.szAdapterName) == 0)
{
break;
}
}
/* Was it already known to us ? */
if (un32Count >= nAdapters)
{
/* No, then register it */
strcpy (aszAdapterName [un32Count], pEvent->Info.szAdapterName);
aAdapters [un32Count] = pEvent->Info.hAdapter;
nAdapters++;
}
/* Free the message */
TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
hMsg = NULL;
}
/* Wait 20 msec to avoid taking all the CPU waiting for boards */
TBX_SLEEP_MS (20);
un32TimeMsec += 20;
}
}
/*-----------------------------------------------------------------------------------------------------------------------
| Check if we have all required adapters to continue
*----------------------------------------------------------------------------------------------------------------------*/
/* Have we found every adapter we wanted ? */
if (un32AdapterLeftToDiscover != 0)
{
un32Count2 = 0;
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
if (pAdapterInfo->hAdapter == (TBX_ADAPTER_HANDLE)NULL)
{
if (strcmp(pAdapterInfo->szAdapterName, TB640_ISDN_ANY_ADAPTER_STRING) == 0)
{
un32Count2++;
}
else
{
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Adapter %s wasn't discovered\n", pAdapterInfo->szAdapterName);
}
}
}
/* Display indication if "ANY" adapter was used in the configuration file */
if (un32Count2 > 0)
{
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Missing %d unidentified adapter(s) to start\n", un32Count2);
}
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "Not able to find all required adapter in configuration file\n");
TBX_EXIT_SUCCESS (TBX_RESULT_NOT_FOUND);
}
/* Destroy the filter */
result = TBXDestroyMsgFilter (g_AppContext->hTbxLib, hFilter);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to destroy filter");
}
hFilter = NULL;
/*-----------------------------------------------------------------------------------------------------------------------
| Configure network redundancy
*----------------------------------------------------------------------------------------------------------------------*/
/* Enable network redundancy */
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
TBX_NETWORK_REDUNDANCY_PARAMETERS RedundancyParams;
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
TBXGetNetworkRedundancyState
(
g_AppContext->hTbxLib,
pAdapterInfo->hAdapter,
&RedundancyParams,
NULL,
NULL
);
RedundancyParams.un32PollDelayMs = 500;
RedundancyParams.un32NetworkDownDelayMs = 1500;
RedundancyParams.un32AdapterDownDelayMs = 10000;
RedundancyParams.fUseNetworkGw0 = TBX_TRUE;
RedundancyParams.fUseNetworkGw1 = TBX_TRUE;
/* Enable Network redundancy for this adapter */
TBXConfigureNetworkRedundancy( g_AppContext->hTbxLib, pAdapterInfo->hAdapter, &RedundancyParams );
}
/*-----------------------------------------------------------------------------------------------------------------------
| Check if features list of found adapters match feature requirements for the test.
*----------------------------------------------------------------------------------------------------------------------*/
for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
{
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
result = TB640IsdnCheckAdapterFeatures(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");
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS_VOID;
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_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;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnCloseAdapters: This function closes previously opened adapters
|
| ~ : No arguments used
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnCloseAdapters (void)
{
TBX_RESULT result;
TBX_FILTER_PARAMS FilterParams;
TBX_UINT64 un64UniqueID;
TBX_FILTER_HANDLE hFilter;
TBX_UINT32 un32Count;
TBX_UINT32 un32ExpectedNbResponse;
TBX_MSG_HANDLE hMsg;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
PTB640_MSG_ADAPTER_OP_DETACH pMsg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -