/** * \brief Finds the number of hardware connected. * \param void * \return defERR_OK if successful otherwise corresponding Error code. * 0, Query successful, but no device found * > 0, Number of devices found * < 0, query for devices unsuccessful * \authors Arunkumar Karri * \date 07.10.2011 Created */ static int nGetNoOfConnectedHardware(void) { int nResult = 0; XLstatus xlStatus = XL_SUCCESS; // ------------------------------------ // get the hardware configuration // ------------------------------------ if ( XL_SUCCESS == xlStatus ) { xlStatus = xlGetDriverConfig(&g_xlDrvConfig); } if (XL_SUCCESS == xlStatus) { // ------------------------------------ // select the wanted channels // ------------------------------------ for (UINT i=0; i < g_xlDrvConfig.channelCount; i++) { // check if we have a valid LIN cab/piggy if (g_xlDrvConfig.channel[i].channelBusCapabilities & XL_BUS_ACTIVE_CAP_LIN) { // and check the right hardwaretype //if (g_xlDrvConfig.channel[i].hwType==hwType) { nResult++; } } } if (!nResult) { _tcscpy(sg_omErrStr, _("No available channels found! (e.g. no LINcabs...)")); xlStatus = XL_ERROR; } } else { _tcscpy(sg_omErrStr, _("Problem Finding Device!")); nResult = -1; } /* Return the operation result */ return nResult; }
//////////////////////////////////////////////////////////////////////////// // demoInitDriver // initializes the driver with one port and all founded channels which // have a connected CAN cab/piggy. // //////////////////////////////////////////////////////////////////////////// XLstatus demoInitDriver(XLaccess *pxlChannelMaskTx, unsigned char *pxlChannelIndex) { XLstatus xlStatus; XLaccess xlChannelMaskTx = 0; unsigned int i; // ------------------------------------ // open the driver // ------------------------------------ xlStatus = xlOpenDriver (); // ------------------------------------ // get/print the hardware configuration // ------------------------------------ if (XL_SUCCESS == xlStatus) { xlStatus = xlGetDriverConfig(&g_xlDrvConfig); } if (XL_SUCCESS == xlStatus) { demoPrintConfig(); printf("Usage: J1939_stack_test <BaudRate> <ApplicationName> <Identifier>\n\n"); // ------------------------------------ // select the wanted channels // ------------------------------------ g_xlChannelMask = 0; for (i=0; i < g_xlDrvConfig.channelCount; i++) { // we take all hardware we found and // check that we have only CAN cabs/piggy's // at the moment there is no VN8910 XLAPI support! if (g_xlDrvConfig.channel[i].channelBusCapabilities & XL_BUS_ACTIVE_CAP_CAN) { if (!*pxlChannelMaskTx) { *pxlChannelMaskTx = g_xlDrvConfig.channel[i].channelMask; *pxlChannelIndex = g_xlDrvConfig.channel[i].channelIndex; } g_xlChannelMask |= g_xlDrvConfig.channel[i].channelMask; } } if (!g_xlChannelMask) { printf("ERROR: no available channels found! (e.g. no CANcabs...)\n\n"); xlStatus = XL_ERROR; } } g_xlPermissionMask = g_xlChannelMask; // ------------------------------------ // open ONE port including all channels // ------------------------------------ if (XL_SUCCESS == xlStatus) { xlStatus = xlOpenPort(&g_xlPortHandle, g_AppName, g_xlChannelMask, &g_xlPermissionMask, RX_QUEUE_SIZE, XL_INTERFACE_VERSION, XL_BUS_TYPE_CAN); printf("- OpenPort : CM=0x%I64x, PH=0x%02X, PM=0x%I64x, %s\n", g_xlChannelMask, g_xlPortHandle, g_xlPermissionMask, xlGetErrorString(xlStatus)); } if ((XL_SUCCESS == xlStatus) && (XL_INVALID_PORTHANDLE != g_xlPortHandle)) { // ------------------------------------ // if we have permission we set the // bus parameters (baudrate) // ------------------------------------ if (g_xlChannelMask == g_xlPermissionMask) { xlStatus = xlCanSetChannelBitrate(g_xlPortHandle, g_xlChannelMask, g_BaudRate); printf("- SetChannelBitrate: baudr.=%u, %s\n",g_BaudRate, xlGetErrorString(xlStatus)); } else { printf("- : we have NO init access!\n"); } } else { xlClosePort(g_xlPortHandle); g_xlPortHandle = XL_INVALID_PORTHANDLE; xlStatus = XL_ERROR; } return xlStatus; }