Пример #1
0
/**
 * @brief
 *      Add the CAN controller information of all IXXAT VCI
 *      devices to the array with the hardware information.
 *
 * @param [in] iStartPosArray
 *  The start position array where to write the data into.
 * @param [in]  pVciDevInfo
 *  If non-null, information describing the current VCI device
 *  found by the device enumerator.
 * @param [out]  sSelHwInterface
 *  The array with the information of all hardware interfaces.
 *
 * @return
 *      The number of found CAN controllers. The calling function
 *      must use this value to increment the current position in
 *      the hardware array.
 */
int CDIL_CAN_IXXAT_VCI::VciDeviceInfoAddToArray(int iStartPosArray, VCIDEVICEINFO* pVciDevInfo, INTERFACE_HW_LIST& sSelHwInterface)
{
    int iNumOfCANController = 0;
    HANDLE hDevice = nullptr;
    VCIDEVICECAPS sVciDeviceCaps;

    // try to open the VCI device
    if ( VCI_OK == DYNCALL(vciDeviceOpen)(pVciDevInfo->VciObjectId, &hDevice) )
    {
        // try to get the capabilities of the current open device to check
        // the number and type of the CAN controller to add it to the
        // program global device array.
        if ( VCI_OK == DYNCALL(vciDeviceGetCaps)(hDevice, &sVciDeviceCaps) )
        {
            for (int i=0; i < sVciDeviceCaps.BusCtrlCount; i++)
            {
                if (VCI_BUS_CAN == VCI_BUS_TYPE(sVciDeviceCaps.BusCtrlTypes[i]))
                {
                    iNumOfCANController++;

                    // store the current information in our class internal structure
                    m_arrTmpIxxatCanChannels[iStartPosArray].SetHardwareParams(pVciDevInfo->VciObjectId.AsInt64, i, &m_ClientList);

                    sSelHwInterface[iStartPosArray].m_dwIdInterface = iStartPosArray;
                    sSelHwInterface[iStartPosArray].m_bytNetworkID = (BYTE) i;    ///< Controller number inside this device.
                    sSelHwInterface[iStartPosArray].m_dwVendor = 0; // always 0

                    //strcpy_s(sSelHwInterface[iStartPosArray].m_acDeviceName, MAX_CHAR_SHORT, pVciDevInfo->Description); // the name of the device
                    sSelHwInterface[iStartPosArray].m_acDeviceName = pVciDevInfo->Description; // the name of the device


                    std::ostringstream oss;
                    oss<<"CAN "<<i;
                    sSelHwInterface[iStartPosArray].m_acNameInterface = oss.str();

                    // if the cantype.h from IXXAT was enhanced then add the new hardware descriptions here
                    switch (VCI_CTL_TYPE(sVciDeviceCaps.BusCtrlTypes[i]))
                    {
                        case CAN_CTRL_82527:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Intel 82527" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Intel 82527";
                            break;
                        case CAN_CTRL_82C200:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Intel 82C200" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Intel 82C200";
                            break;
                        case CAN_CTRL_82C90:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Intel 82C90" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Intel 82C90";
                            break;
                        case CAN_CTRL_82C92:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Intel 82C92" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Intel 82C92";
                            break;
                        case CAN_CTRL_SJA1000:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Philips SJA 1000" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Philips SJA 1000";
                            break;
                        case CAN_CTRL_82C900:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Infinion 82C900 (TwinCAN)" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Infinion 82C900 (TwinCAN)";
                            break;
                        case CAN_CTRL_TOUCAN:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "Motorola TOUCAN" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "Motorola TOUCAN";
                            break;
                        case CAN_CTRL_IFI:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, "IFI-CAN" );
                            sSelHwInterface[iStartPosArray].m_acDescription = "IFI-CAN";
                            break;
                        default:
                            //strcpy_s( sSelHwInterface[iStartPosArray].m_acDescription, MAX_CHAR_LONG, _("unknown CAN controller") );
                            sSelHwInterface[iStartPosArray].m_acDescription = "unknown CAN controller";
                            break;
                    }
                    // jump to the next array entry
                    iStartPosArray++;
                    if (iStartPosArray >= CHANNEL_CAN_MAX)
                    {
                        LogMessage(FALSE, _("Too many IXXAT CAN controllers found. Abort filling hardware list!"));
                        break;
                    }
                }
            }
        }
        // close the formerly opened device for later use
        DYNCALL(vciDeviceClose)(hDevice);
        hDevice = nullptr;
    }

    // return the number of found CAN controllers
    return iNumOfCANController;
}
Пример #2
0
/**
 * @brief
 *  Create a list will all IXXAT CAN controllers.
 *
 * @todo
 *  At this time only the settings for the first CAN will be set
 *  and no dialog will shown.
 * *
 *
 * @param [in,out]  sSelHwInterface
 *  The selected hardware interface.
 * @param [in,out]  nCount
 *  Number of.
 *
 * @return
 *      S_OK - list successful filled
 *      E_POINTER - no access to the VCI drivers
 *      NO_HW_INTERFACE - no CAN interface found
 */
HRESULT CDIL_CAN_IXXAT_VCI::CAN_ListHwInterfaces(INTERFACE_HW_LIST& sSelHwInterface, INT& nCount, PSCONTROLLER_DETAILS InitData)
{
#ifdef _IXXAT_DEBUG
    LogMessage(TRUE, "------> CDIL_CAN_IXXAT_VCI::CAN_ListHwInterfaces\n");
#endif
    HRESULT hResult = E_POINTER;

    UINT unDefaultChannelCnt = nCount;
    // default: no IXXAT interface available
    nCount = 0;
    m_iNumberOfCANChannelsTotal = 0;

    if (m_bDriverAccessLoaded)
    {
        HANDLE        hEnum;   // enumerator handle
        VCIDEVICEINFO sInfo;   // device info

        // open the device list
        hResult = DYNCALL(vciEnumDeviceOpen)(&hEnum);
        if (VCI_OK == hResult)
        {
            while (DYNCALL(vciEnumDeviceNext)(hEnum, &sInfo) == VCI_OK)
            {
                // increment the counter and add the device info to our list
                m_iNumberOfCANChannelsTotal += VciDeviceInfoAddToArray(nCount, &sInfo, m_sSelHwInterface);
            }
        }
        int nHwCount = m_iNumberOfCANChannelsTotal;
        //TODO: currently only 1 interface selected
        if (m_iNumberOfCANChannelsTotal > 0)
        {
            INT64 qiVCIDeviceID = 0;
            int iCANControllerNumber = 0;
            CClientList* pClientList = nullptr;

            //if ( m_iNumberOfCANChannelsTotal == 1 ) /* Only single channel available */
            //{
            //    sSelHwInterface[0] = m_sSelHwInterface[0];

            //    /* Rearrange hardware parameters */
            //    m_arrTmpIxxatCanChannels[0].GetHardwareParams(&qiVCIDeviceID,
            //            &iCANControllerNumber, (void**)&pClientList);
            //    m_arrIxxatCanChannels[0].SetHardwareParams(qiVCIDeviceID, iCANControllerNumber,
            //            pClientList);
            //}
            //else    /* Multiple channels available */
            {
                /* If the default channel count parameter is set, prevent displaying the hardware selection dialog */
                if ( unDefaultChannelCnt && nHwCount >= unDefaultChannelCnt )
                {
                    for (UINT i = 0; i < unDefaultChannelCnt; i++)
                    {
                        m_anSelectedItems[i] = i;
                    }
                    nHwCount  = unDefaultChannelCnt;
                }
                else if ( ListHardwareInterfaces(m_hOwnerWndHandle, m_sSelHwInterface, m_anSelectedItems, nHwCount,InitData) != 0 )
                {
                    /* return if user cancels hardware selection */
                    return HW_INTERFACE_NO_SEL;
                }

                for ( int nCount = 0; nCount < nHwCount; nCount++ )
                {
                    /* Order the hardware information according to user selection */
                    sSelHwInterface[nCount] = m_sSelHwInterface[m_anSelectedItems[nCount]];

                    /* Rearrange hardware parameters */
                    m_arrTmpIxxatCanChannels[m_anSelectedItems[nCount]].GetHardwareParams(&qiVCIDeviceID,
                            &iCANControllerNumber, (void**)&pClientList);
                    m_arrIxxatCanChannels[nCount].SetHardwareParams(qiVCIDeviceID, iCANControllerNumber,
                            pClientList);
                }
                m_iNumberOfCANChannelsTotal = nHwCount;
            }
            nCount = m_iNumberOfCANChannelsTotal;
        }

        if (m_iNumberOfCANChannelsTotal == 0)
        {
            hResult = NO_HW_INTERFACE;
            LogMessage(FALSE, "No valid IXXAT CAN interface found.");
        }

        m_byCurrHardwareState = STATE_HW_INTERFACE_LISTED;
    }
    else
    {
        // the return value is already set to E_POINTER
        LogMessage(FALSE, "IXXAT VCI access not loaded or valid.");
    }

    return hResult;
}
/**
 * @brief
 *      Add the CAN controller information of all IXXAT VCI
 *      devices to the array with the hardware information.
 *
 * @param [in,out] iStartPosArray
 *  The start position array where to write the data into.
 *  The veriable will be inremented at every found CAN controller
 * @param [in]  pVciDevInfo
 *  If non-null, information describing the current VCI device
 *  found by the device enumerator.
 * @param [out]  sSelHwInterface
 *  The array with the information of all hardware interfaces.
 *
 * @return
 *      The number of found CAN controllers. The calling function
 *      must use this value to increment the current position in
 *      the hardware array.
 */
int CDIL_CAN_IXXAT_VCI::VciDeviceInfoAddToArray(INT& nStartPosArray, VCIDEVICEINFO* pVciDevInfo, INTERFACE_HW_LIST& sSelHwInterface)
{
    int iNumOfCANController = 0;
    HANDLE hDevice = nullptr;
    VCIDEVICECAPS sVciDeviceCaps;


    // try to open the VCI device
    if ( VCI_OK == DYNCALL(vciDeviceOpen)(pVciDevInfo->VciObjectId, &hDevice) )
    {
        // try to get the capabilities of the current open device to check
        // the number and type of the CAN controller to add it to the
        // program global device array.
        if ( VCI_OK == DYNCALL(vciDeviceGetCaps)(hDevice, &sVciDeviceCaps) )
        {
            for (int i=0; i < sVciDeviceCaps.BusCtrlCount; i++)
            {
#ifdef _IXXAT_DEBUG
                LogMessage(TRUE, "------> Interface: %s  BusCtrl No.: %u  Type: 0x%.4X\n", pVciDevInfo->Description, i, sVciDeviceCaps.BusCtrlTypes[i]);
#endif
                if (VCI_BUS_CAN == VCI_BUS_TYPE(sVciDeviceCaps.BusCtrlTypes[i]))
                {
                    iNumOfCANController++;
#ifdef _IXXAT_DEBUG
                    LogMessage(TRUE, "------> iNumOfCANController: %u\n", iNumOfCANController);
#endif


                    // store the current information in our class internal structure
                    m_arrTmpIxxatCanChannels[nStartPosArray].SetHardwareParams(pVciDevInfo->VciObjectId.AsInt64, i, &m_ClientList);

                    sSelHwInterface[nStartPosArray].m_dwIdInterface = nStartPosArray;
                    sSelHwInterface[nStartPosArray].m_bytNetworkID = (BYTE)i;    ///< Controller number inside this device.
                    sSelHwInterface[nStartPosArray].m_dwVendor = 0; // always 0

                    //strcpy_s(sSelHwInterface[iStartPosArray].m_acDeviceName, MAX_CHAR_SHORT, pVciDevInfo->Description); // the name of the device
                    sSelHwInterface[nStartPosArray].m_acDeviceName = pVciDevInfo->Description; // the name of the device


                    std::ostringstream oss;
                    oss<<"CAN "<<i;
                    sSelHwInterface[nStartPosArray].m_acNameInterface = oss.str();

                    // if the cantype.h from IXXAT was enhanced then add the new hardware descriptions here
                    switch (VCI_CTL_TYPE(sVciDeviceCaps.BusCtrlTypes[i]))
                    {
                        case CAN_CTRL_82527:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Intel 82527";
                            break;
                        case CAN_CTRL_82C200:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Intel 82C200";
                            break;
                        case CAN_CTRL_81C90:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Intel 81C90";
                            break;
                        case CAN_CTRL_81C92:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Intel 81C92";
                            break;
                        case CAN_CTRL_SJA1000:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Philips SJA 1000";
                            break;
                        case CAN_CTRL_82C900:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Infinion 82C900 (TwinCAN)";
                            break;
                        case CAN_CTRL_TOUCAN:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Motorola TOUCAN";
                            break;
                        case CAN_CTRL_MSCAN:    // Freescale Star12 MSCAN
                            sSelHwInterface[nStartPosArray].m_acDescription = "Freescale Star12 MSCAN";
                            break;
                        case CAN_CTRL_FLEXCAN:  // Freescale FlexCAN
                            sSelHwInterface[nStartPosArray].m_acDescription = "Freescale FlexCAN";
                            break;
                        case CAN_CTRL_IFICAN:
                            sSelHwInterface[nStartPosArray].m_acDescription = "IFI-CAN";
                            break;
                        case CAN_CTRL_BCCAN:   // Bosch C_CAN
                            sSelHwInterface[nStartPosArray].m_acDescription = "Bosch C_CAN";
                            break;
                        case CAN_CTRL_BXCAN:   // ST BX_CAN
                            sSelHwInterface[nStartPosArray].m_acDescription = "ST BX_CAN";
                            break;
                        case CAN_CTRL_IFICFD:  // IFI CAN FD Controller
                            sSelHwInterface[nStartPosArray].m_acDescription = "IFI CAN FD";
                            break;
                        case CAN_CTRL_BMCAN:   // Bosch M_CAN
                            sSelHwInterface[nStartPosArray].m_acDescription = "Bosch M_CAN";
                            break;
                        // end
                        default:
                            sSelHwInterface[nStartPosArray].m_acDescription = "Unknown CAN controller";
                            break;
                    }
                    // jump to the next array entry
                    nStartPosArray++;
                    if (nStartPosArray >= CHANNEL_CAN_MAX)
                    {
                        LogMessage(FALSE, _("Too many IXXAT CAN controllers found. Abort filling hardware list!"));
                        break;
                    }
                }
#ifdef _IXXAT_DEBUG
                else
                {
                    // TODO remove
                    LogMessage(TRUE, "------> Not Added! Interface: %s  BusCtrl No.: %u  Type: 0x%.4X\n", pVciDevInfo->Description, i, sVciDeviceCaps.BusCtrlTypes[i]);
                }
#endif
            }
        }
        // close the formerly opened device for later use
        DYNCALL(vciDeviceClose)(hDevice);
        hDevice = nullptr;
    }

    // return the number of found CAN controllers
    return iNumOfCANController;
}