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

📄 ex05_01.cpp

📁 * 1. Run the Advanced Evaluation Board (AEB) Control software program * (Start>AudioCod
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void exInitLib()
{
    acTInitLibParam InitLibParam;
    acTNumberOfBoardsVector NumberOfBoardsVector;
    acGetDefaultInitLibParameters(&InitLibParam);

    /*
     * Declaration of a stucture of pointers for Callback functions:
     * 1. Error handler CallBack function.
     * 2. Termiation of Polling Thread CallBack function. 
     */
    InitLibParam.VoPLibHandlers.pErrorHandler = exErrorHandler;
    InitLibParam.VoPLibHandlers.pTerminatePollingThreads = exTerminatePollingThreadsCallback;

    /*
     * Initializing the VoIPLib. 
     */
    printf("\nInitializing the VoP library...\n");

    if (acInitLib(&InitLibParam, &NumberOfBoardsVector) == RESULT_SUCCESS)
        printf("\nThe VoPLib was initialized successfully.\n");
    else
        exQuit("\nFailed to initialize the VoPLib.", 1);

    exPrintNumBoardsVec(NumberOfBoardsVector.NumberOfBoardsVector, 
                        NumberOfBoardsVector.NumberOfBoardsFound);
}

/*
 * Board opening related functions 
 */

/*****************************************************************/
/* Example Function: exOpenBoard().                              */
/*                                                               */
/* Do all the necessary work to open the board.                  */
/* The function returns the BoardHanlde after it has been opened */
/* successfully.                                                 */
/* No further delay should be add after calling this function.   */
/*****************************************************************/

acTBoardHandle exOpenBoard()
{
    /*
     * Open the board with the acOpenBoard() function. 
     * acOpenBoard() will return a BoardHandle. 
     */
    acTBoardParam BoardParam;

    /*
     * The acTBoardParam structure is initialized with default values,
     * using acGetDefaultBoardParameters() function. 
     */
    BoardParam = acGetDefaultBoardParameters(BoardType);
    /*
     * Internal function that updates the board parameters in 
     * accordance with the requirements of the example 
     */
    exUpdateBoardParams(&BoardParam);

    /*
     * This example demonstrates opening the board in PCI mode,
     * when using TPNCP replace function with acOpenRemoteBoard() using the same syntax. 
     */
    printf("Initializing Board... This should take approximately 1 minute.\nPlease Wait.\n");
    acTBoardHandle BoardHandle;
    int BoardId = 0;

    BoardHandle = acOpenBoard(BoardType, BoardId, &BoardParam);
    if (BoardHandle == INVALID_BOARD_HANDLE)
        exQuit("Opening board error.", 1);
    printf("\nThe board was opened successfully.\n");

    /*
     * The program enters a loop waiting for the acEV_BOARD_STARTED event.
     * NOTE: When working with PSTN, the work continues after 
     * both acEV_BOARD_STARTED and then acEV_PSTN_STARTED events received 
     */
    printf("\nWaiting for acEV_BOARD_STARTED event...\n"
           "\nYou will see the information about the events from the board.\n"
           "Pay attention, this might be important! (In case of errors, etc.)\n\n");
    exWaitForBoardStartedEvents(BoardHandle);

    /*
     * Creates a thread that handles polling events from the board
     * using acGetEvent(BoardHandle,...) function. 
     */
    exBeginGetEventThread(BoardHandle);

    /*
     * Creates a thread that handles polling packets from the board 
     * using acGetPacket(BoardHandle,...) function. 
     */
    exBeginGetPacketThread(BoardHandle);

    return BoardHandle;
}                               /* end of function exOpenBoard */

/*************************************************/
/* Example Function: exCloseBoard().             */
/*                                               */
/* Do all the necessary work to close the board. */
/*************************************************/

void exCloseBoard(const acTBoardHandle BoardHandle)
{
    /*
     * Close the board 
     */
    if (acCloseBoard(BoardHandle) != 0)
        exQuit("Close board failed.", 1);

    /*
     * Wait for the board's thread to finish and then close the threads' handles 
     */
#if OS_TYPE==OS_WIN_NT
    WaitForSingleObject(EventsThreadHandle, INFINITE);
    WaitForSingleObject(PacketsThreadHandle, INFINITE);

    CloseHandle(EventsThreadHandle);
    CloseHandle(PacketsThreadHandle);
#else
    pthread_join(EventsThreadHandle, NULL);
    pthread_join(PacketsThreadHandle, NULL);
#endif
}                               /* end of function exCloseBoard */

/*********************************************************************/
/* Example Function: exUpdateBoardParams().                          */
/*                                                                   */
/* Internal function that updates the board parameters in accordance */
/* with the requirements of this example.                            */
/*********************************************************************/

void exUpdateBoardParams(acTBoardParam * pBoardParam)
{
    /*
     * Following are examples of usage of some of the board parameters. 
     * It is important to note, that many more parameters exist for other configurations. 
     */

    char *ImageFile;
#if OS_TYPE == OS_WIN_NT
    ImageFile = exFindFile(ImageFileName, "Firmware");
#else
    ImageFile = ImageFileName;
#endif
    if(ImageFile == NULL)
        exQuit("Failed to find the ImageFile.", 1);
    else
        printf("\nIn this example ImageFile - %s is used.\n", ImageFile);

    const char *IPAddr = "10.4.96.100";
    char BoardIPAddr[256];

    printf("\nIn this example we do not use the Network Interface. However,\n"
           "if the Board is connected to the Network, you need to set the\n"
           "IP-address. The program will set the IP-address to '%s'.\n"
           "Enter the string representation of your IP-address or press 'Enter'\n"
           "to leave the default value unchanged.\n", IPAddr);
    fflush(stdin);
    fgets(BoardIPAddr, 256, stdin);
    if(*BoardIPAddr == '\n') strcpy(BoardIPAddr, IPAddr);

    pBoardParam->DownloadableFiles.ImageFile = ImageFile;
    pBoardParam->NetworkSettings.BoardIPAddr = exIPAddr2int(BoardIPAddr);
    pBoardParam->NetworkSettings.BoardSubNetAddr = exIPAddr2int("255.255.0.0");
    pBoardParam->TDMBusSettings.TDMBusType = acFRAMERS; /* when using PSTN; see acTTDMBusType enum for more possible values */
    pBoardParam->TDMBusSettings.TDMBusClockSource = acTDMBusClockSource_Network;    /* see acTTDMBusClockSource enum for more possible values */
    pBoardParam->TDMBusSettings.TDMBusSpeed = acTDMBusSpeed_8192kbps;   /* see acTDMBusSpeed enum for more possible values */
    for (int Trunk = 0; Trunk < MAX_TRUNK_NUM; ++Trunk)
    {
        pBoardParam->TrunkConfig[Trunk].ProtocolType = acPROTOCOL_TYPE_E1_TRANSPARENT_60;   /* see acTPSTNProtocolType enum for more possible values */
    }

    /*
     * all other values are the default values given at acGetDefaultBoardParameters() 
     */

}                               /* end of function exUpdateBoardParams */

/****************************************************************************/
/* Example Function: exWaitForBoardStartedEvents().                         */
/*                                                                          */
/* The program enters a loop waiting for the 2 events:                      */
/*     The first to come:  acEV_BOARD_STARTED                               */
/*     The second to come: acEV_PSTN_STARTED                                */
/*                                                                          */
/* NOTE:                                                                    */
/*  When opening the board with FRAMERS the program should                  */
/*       continue only after both events received.                          */
/*  When opening the board as MVIP / SC / H.110/ H.100 the program          */
/*       should continue after acEV_BOARD_STARTED event received. (The      */
/*       board will not send the   acEV_PSTN_STARTED event in these cases). */
/****************************************************************************/

void exWaitForBoardStartedEvents(const acTBoardHandle BoardHandle)
{
    acTChannelHandle ChannelHandle;
    acTEventInfo EventInfo;
    int EventType;

    while ((EventType = acGetEvent(BoardHandle, &ChannelHandle, 0, 0, &EventInfo)) != acEV_BOARD_STARTED)
        if (EventType != acEV_NONE)
            exProceedEvent(BoardHandle, EventInfo, ChannelHandle, EventType);

    printf("\n'EV_BOARD_STARTED' was received:\n"
           " Parameters reported by the board: \n"
           " Serial Number=%d \n"
           " Software Version=%d.%02d \n"
           " Flash Version=%d.%d \n"
           " CPU=%d.%d@%dMhz \n"
           " MAC=%06x%06x \n",
           EventInfo.BoardStartupInfo.SerialNum,
           EventInfo.BoardStartupInfo.TrunkPackSoftwareVer / 100,
           EventInfo.BoardStartupInfo.TrunkPackSoftwareVer % 100,
           EventInfo.BoardStartupInfo.FlashVer / 100,
           EventInfo.BoardStartupInfo.FlashVer % 100,
           EventInfo.BoardStartupInfo.CPUVer / 16,
           EventInfo.BoardStartupInfo.CPUVer % 16,
           EventInfo.BoardStartupInfo.CPUSpeed, EventInfo.BoardStartupInfo.MACAddrMsb,
           EventInfo.BoardStartupInfo.MACAddrLsb);

    /*
     * The following is optional and should be used only when using PSTN interface 
     */

    while ((EventType = acGetEvent(BoardHandle, &ChannelHandle, 0, 0, &EventInfo)) != acEV_PSTN_STARTED)
        if (EventType != acEV_NONE)
            exProceedEvent(BoardHandle, EventInfo, ChannelHandle, EventType);

    printf("\nEvent 'acEV_PSTN_STARTED' was received:\nComment=%s-%d\n",
           acPSTNInterpretComment(EventInfo.PSTNEventInfo.Started.Comment), EventInfo.PSTNEventInfo.Started.Comment);

    return;
}                               /* end of function exWaitForBoardStartedEvents */

/**************************************************************************/
/* Example Function: exBeginGetEventThread().                             */
/*                                                                        */
/* Create the Thread that handles the events coming from the       board. */
/**************************************************************************/

void exBeginGetEventThread(const acTBoardHandle BoardHandle)
{
#if OS_TYPE==OS_WIN_NT
    DWORD ThreadId;

    EventsThreadHandle = CreateThread(0, 0x1000, exGetEventThreadFunc, (LPVOID) BoardHandle, 0, &ThreadId);
    if (EventsThreadHandle == NULL)
        exQuit("Failed to open events thread.", 1);

    /*
     * The thread priority must be set to highest to handle all
     * the events received from the boards. 
     */
    if (SetThreadPriority(EventsThreadHandle, THREAD_PRIORITY_HIGHEST) == 0)
        exQuit("Failed to set the priority of the packets thread to highest.", 1);

#else
    if (pthread_create(&EventsThreadHandle, NULL, exGetEventThreadFunc, (LPVOID)(unsigned long)BoardHandle) != 0)
        exQuit("Failed to open events thread.", 1);
    else
        printf("\nEvent Thread for Board %d was created.\n", BoardHandle);
#endif
}                               /* end of function exBeginGetEventThread */

/*********************************************************************/
/* Example Function: exBeginGetPacketThread().                       */
/*                                                                   */
/* Create the Thread that handles the packets coming from the board. */
/*********************************************************************/

void exBeginGetPacketThread(const acTBoardHandle BoardHandle)
{
#if OS_TYPE==OS_WIN_NT
    DWORD ThreadId;

    PacketsThreadHandle = CreateThread(0, 0x1000, exGetPacketThreadFunc, (LPVOID) BoardHandle, 0, &ThreadId);
    if (PacketsThreadHandle == NULL)
        exQuit("Failed to open packets thread.", 1);

    /*
     * The thread priority must be set to time critical to handle all
     * the packets received from the board. 
     */
    if (SetThreadPriority(PacketsThreadHandle, THREAD_PRIORITY_TIME_CRITICAL) == 0)
        exQuit("Failed to set the priority of the packets thread to time critical.", 1);
#else
    if (pthread_create(&PacketsThreadHandle, NULL, exGetPacketThreadFunc, (LPVOID)(unsigned long)BoardHandle) != 0)
        exQuit("Failed to open packets thread.", 1);
    else
        printf("\nPacket Thread for Board %d was created.\n", BoardHandle);
#endif
}                               /* end of function exBeginGetPacketThread */

/***************************************************/
/* Example Function: exGetEventThreadFunc().       */
/*                                                 */
/* This function defines the event polling thread. */
/***************************************************/

#if OS_TYPE==OS_WIN_NT
DWORD WINAPI
#else
void*
#endif
exGetEventThreadFunc(void *arg)
{
    acTBoardHandle BoardHandle = (acTBoardHandle)(unsigned long)arg;
    acTChannelHandle ChannelHandle;
    acTEventInfo EventInfo;
    int EventType;

    while (!ExitPollingThread)
    {
        EventType = acGetEvent(BoardHandle, &ChannelHandle, 0, 0, &EventInfo);

        /*
         * Each time the Thread gets it time slice, it should check if there 
         * is an event waiting to be polled:
         * - If there is an event waiting, the Thread should poll the event, 
         * proccess the event according to it's type and then check if there another 
         * Event waiting to be polled, etc..., until there are no more events to be 
         * polled at the moment.
         * - If there no more event to be polled, the Thread should sleep. 
         */

        if (EventType != acEV_NONE)
            exProceedEvent(BoardHandle, EventInfo, ChannelHandle, EventType);
        else
            /*
             * the program will sleep only when no events were found (i.e. acEV_NONE)
             * by this sleep we "wait" for events to come.
             */
            acSleep(10);
    }
#if OS_TYPE==OS_WIN_NT
    return 0;
#else
    return arg;
#endif
}                               /* end of function exGetEventThreadFunc */

/***************************************************/
/* Example Function: exGetPacketThreadFunc().      */
/*                                                 */
/* This function defines the event polling thread. */
/***************************************************/

#if OS_TYPE==OS_WIN_NT
DWORD WINAPI
#else
void*
#endif
exGetPacketThreadFunc(void *arg)
{

⌨️ 快捷键说明

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