/** * \return S_OK for success, S_FALSE for failure * * Starts the controller. */ HRESULT CDIL_CAN_i_VIEW::CAN_StartHardware(void) { VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); HRESULT hResult = S_OK; EnterCriticalSection(&m_Mutex); for (UINT i = 0; i < m_nChannels; i++) { pVCI_t pVCI = m_VCI[m_SelectedVCI[i]]; if( pVCI && !pVCI->VCiIF()->Connected() ) { if (pVCI->Connect() != IVIEW_NOERROR) { hResult = S_FALSE; } } } if ( hResult == S_OK ) { m_CurrState = STATE_CONNECTED; } m_TimeStamp = 0; LeaveCriticalSection(&m_Mutex); return hResult; }
HRESULT CDIL_LIN_VectorXL::LIN_Send( STLIN_MSG& sMessage) { VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE); HRESULT hResult = S_FALSE; if (true) { if (sMessage.m_ucChannel <= sg_nNoOfChannels) { EnterCriticalSection(&sg_CritSectForWrite); // Lock the buffer if (nWriteMessage(sMessage, 0) == defERR_OK) { hResult = S_OK; } LeaveCriticalSection(&sg_CritSectForWrite); // Unlock the buffer } else { hResult = ERR_INVALID_CHANNEL; } } else { hResult = ERR_NO_CLIENT_EXIST; } return hResult; }
/** * \return S_OK for success, S_FALSE for failure * * Deselects the selected hardware interface. */ HRESULT CDIL_CAN_i_VIEW::CAN_DeselectHwInterface(void) { VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); HRESULT hResult = S_OK; hResult = CAN_ResetHardware(); m_CurrState = STATE_HW_INTERFACE_LISTED; return hResult; }
/** * @brief Sends STCAN_MSG structure from the client dwClientID. * @param[in] dwClientID is the client ID * @param[in] sMessage is the application specific CAN message structure * @return S_OK for success, S_FALSE for failure */ HRESULT CDIL_CAN_VSCOM::sendMessage(DWORD dwClientID, const STCAN_MSG& sMessage) { VSCAN_MSG msg; DWORD dwTemp; static SACK_MAP sAckMap; HRESULT hResult; VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE); hResult = S_FALSE; if (bClientIdExist(dwClientID)) { if (sMessage.m_ucChannel <= sg_nNoOfChannels) { memset(&msg, 0, sizeof(msg)); if (sMessage.m_ucEXTENDED == 1) { msg.Flags |= VSCAN_FLAGS_EXTENDED; } if (sMessage.m_ucRTR == 1) { msg.Flags |= VSCAN_FLAGS_REMOTE; } msg.Id = sMessage.m_unMsgID; msg.Size = sMessage.m_ucDataLen; memcpy(msg.Data, &sMessage.m_ucData, msg.Size); sAckMap.m_ClientID = dwClientID; sAckMap.m_Channel = sMessage.m_ucChannel; sAckMap.m_MsgID = msg.Id; vMarkEntryIntoMap(sAckMap); if (VSCAN_Write(sg_VSCanCfg.hCan, &msg, 1, &dwTemp) == VSCAN_ERR_OK && dwTemp == 1) { static STCANDATA can_data; CopyMsg2CanData(&can_data, &msg, TX_FLAG); EnterCriticalSection(&sg_DIL_CriticalSection); //Write the msg into registered client's buffer vWriteIntoClientsBuffer(can_data); LeaveCriticalSection(&sg_DIL_CriticalSection); hResult = S_OK; } else { hResult = S_FALSE; sg_pIlog->logMessage(A2T(__FILE__), __LINE__, _("could not write can data into bus")); } } else { hResult = ERR_INVALID_CHANNEL; } } else { hResult = ERR_NO_CLIENT_EXIST; } return(hResult); }
/** * \brief Selects the hardware interface selected by the user. * \param[out] asSelHwInterface, is INTERFACE_HW_LIST structure * \param[out] nCount , is INT contains the selected channel count. * \return S_OK for success, S_FALSE for failure */ HRESULT CDIL_CAN_MHS::CAN_SelectHwInterface(const INTERFACE_HW_LIST& /*asSelHwInterface*/, INT /*nCount*/) { USES_CONVERSION; VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_HW_INTERFACE_LISTED, ERR_IMPROPER_STATE); /* Check for the success */ sg_bCurrState = STATE_HW_INTERFACE_SELECTED; return(S_OK); }
/** * \brief Deselects the selected hardware interface. * \param void * \return S_OK if CAN_ResetHardware call is success, S_FALSE for failure */ HRESULT CDIL_CAN_MHS::CAN_DeselectHwInterface(void) { VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); HRESULT hResult = S_OK; sg_bCurrState = STATE_HW_INTERFACE_LISTED; return hResult; }
/** * \return S_OK for success, S_FALSE for failure * * Selects the hardware interface selected by the user. */ HRESULT CDIL_CAN_i_VIEW::CAN_SelectHwInterface( const INTERFACE_HW_LIST& /*SelHwInterface*/, INT /*Size*/ ) { USES_CONVERSION; VALIDATE_POINTER_RETURN_VAL(m_hDll, S_FALSE); VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_HW_INTERFACE_LISTED, ERR_IMPROPER_STATE); /* Check for the success */ m_CurrState = STATE_HW_INTERFACE_SELECTED; return S_OK; }
/** * \brief Sends STCAN_MSG structure from the client dwClientID. * \param[in] dwClientID is the client ID * \param[in] sMessage is the application specific CAN message structure * \return S_OK for success, S_FALSE for failure */ HRESULT CDIL_CAN_MHS::CAN_SendMsg(DWORD dwClientID, const STCAN_MSG& sMessage) { struct TCanMsg msg; static SACK_MAP sAckMap; HRESULT hResult; VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE); hResult = S_FALSE; if (bClientIdExist(dwClientID)) { if (sMessage.m_ucChannel <= sg_nNoOfChannels) { // msg Variable Initialisieren msg.MsgFlags = 0L; // Alle Flags löschen, Stanadrt Frame Format, // keine RTR, Datenlänge auf 0 if (sMessage.m_ucEXTENDED == 1) { msg.MsgEFF = 1; // Nachricht im EFF (Ext. Frame Format) versenden } if (sMessage.m_ucRTR == 1) { msg.MsgRTR = 1; // Nachricht als RTR Frame versenden } msg.Id = sMessage.m_unMsgID; msg.MsgLen = sMessage.m_ucDataLen; memcpy(msg.MsgData, &sMessage.m_ucData, msg.MsgLen); sAckMap.m_ClientID = dwClientID; sAckMap.m_Channel = sMessage.m_ucChannel; sAckMap.m_MsgID = msg.Id; vMarkEntryIntoMap(sAckMap); if (CanTransmit(0, &msg, 1) >= 0) { hResult = S_OK; } else { hResult = S_FALSE; sg_pIlog->vLogAMessage(A2T(__FILE__), __LINE__, _T(_("could not write can data into bus"))); } } else { hResult = ERR_INVALID_CHANNEL; } } else { hResult = ERR_NO_CLIENT_EXIST; } return(hResult); }
HRESULT CDIL_LIN_VectorXL::LIN_SelectHwInterface(const INTERFACE_HW_LIST& sSelHwInterface, INT nCount) { USES_CONVERSION; VALIDATE_POINTER_RETURN_VAL(hxlDll, S_FALSE); VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_HW_INTERFACE_LISTED, ERR_IMPROPER_STATE); /* Check for the success */ sg_bCurrState = STATE_HW_INTERFACE_SELECTED; return S_OK; }
HRESULT CDIL_CAN_i_VIEW::CAN_DisplayConfigDlg( PSCONTROLLER_DETAILS InitData, int& Length ) { VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); VALIDATE_POINTER_RETURN_VAL(InitData, WARN_INITDAT_NCONFIRM); USES_CONVERSION; INT Result = WARN_INITDAT_NCONFIRM; //First initialize with existing hw description for (INT i = 0; i < min(Length, (INT)m_nChannels); i++) { InitData[i].m_omHardwareDesc = m_Channel[i]->Name(); } if (m_nChannels > 0) { //Result = DisplayConfigurationDlg(m_hOwnerWnd, Callback_DIL_iVIEW, // psContrlDets, m_nChannels); AFX_MANAGE_STATE(AfxGetStaticModuleState()); CChangeRegisters ChangeRegisters(nullptr, InitData, m_nChannels); ChangeRegisters.DoModal(); Result = ChangeRegisters.nGetInitStatus(); switch (Result) { case WARNING_NOTCONFIRMED: Result = WARN_INITDAT_NCONFIRM; break; case INFO_INIT_DATA_CONFIRMED: Length = sizeof(SCONTROLLER_DETAILS) * defNO_OF_CHANNELS; Result = CAN_SetConfigData(InitData, Length); if (Result == S_OK) { Result = INFO_INITDAT_CONFIRM_CONFIG; } break; case INFO_RETAINED_CONFDATA: Result = INFO_INITDAT_RETAINED; break; case ERR_CONFIRMED_CONFIGURED: // Not to be addressed at present case INFO_CONFIRMED_CONFIGURED:// Not to be addressed at present default: break; } } return Result; }
/** * \return S_OK for success, S_FALSE for failure * * Performs intial operations. * Initializes filter, queue, controller config with default values. */ HRESULT CDIL_CAN_i_VIEW::CAN_PerformInitOperations(void) { VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_DRIVER_LOADED, ERR_IMPROPER_STATE); InitializeCriticalSection(&m_Mutex); m_iViewBrowser = m_CreateBrowser( API_MDNS_SERVICE_TYPE, this ); m_iViewBrowser->Start(); //Initialize the selected channel items array to -1 for ( UINT i = 0; i< CHANNEL_ALLOWED; i++ ) { m_SelectedVCI[i] = -1; } return S_OK; m_CurrState = STATE_DRIVER_SELECTED; }
HRESULT CDIL_LIN_VectorXL::PreStartHardware(void) { VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); USES_CONVERSION; HRESULT hResult = S_OK; //Connect to the network hResult = nConnect(TRUE); if (hResult == defERR_OK) { hResult = S_OK; sg_bCurrState = STATE_CONNECTED; vCreateTimeModeMapping(g_hDataEvent[0]); } else { //log the error for open port failure //vRetrieveAndLog(hResult, __FILE__, __LINE for ( int i = 0; i < 16; i++ ) { sg_aodChannels[i].m_nMapIdChecksumType.clear(); m_MapIdClient[i].clear(); } hResult = ERR_LOAD_HW_INTERFACE; } //If everything is ok start the read thread if (hResult == S_OK) { sg_sParmRThread.m_pBuffer = this; if (sg_sParmRThread.bStartThread(LINMsgReadThreadProc_LIN_Vector_XL)) { hResult = S_OK; } else { sg_pIlog->vLogAMessage(A2T(__FILE__), __LINE__, _("Could not start the read thread")); } } return hResult; }
/** * @brief * Display the CAN controller configuration dialog. * * @param [in,out] InitData * Information describing the CAN interfaces, * to be filled with additional information by the dialog. * @param [in,out] Length * The length of the InitData structure. * @todo * At this time only the settings for the first CAN will be set * and no dialog will shown. * * @return * E_POINTER - no IXXAT CAN hardware available. * E_ABORT - aborted by user * S_OK - baudrate set correct to first CAN controller. * */ HRESULT CDIL_CAN_IXXAT_VCI::CAN_DisplayConfigDlg(PSCONTROLLER_DETAILS InitData, int& Length) { //TODO: original line, but here only the first available CAN controller is used // VALIDATE_VALUE_RETURN_VAL(m_byCurrHardwareState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); VALIDATE_VALUE_RETURN_VAL(m_byCurrHardwareState, STATE_HW_INTERFACE_LISTED, ERR_IMPROPER_STATE); VALIDATE_POINTER_RETURN_VAL(InitData, S_FALSE); // absolutely necessary to call this macro // else you will run directly into MFC hell AFX_MANAGE_STATE(AfxGetStaticModuleState()); #ifdef _IXXAT_DEBUG LogMessage(TRUE, "------> CDIL_CAN_IXXAT_VCI::CAN_DisplayConfigDlg\n"); #endif HRESULT hrRes = E_POINTER; if (m_iNumberOfCANChannelsTotal > 0) { // The InitData is an pointer to an array with the controller details // int iNumOfCtrlEntries = Length / sizeof(SCONTROLER_DETAILS); -> no need this time SCONTROLLER_DETAILS* pCtrlArray = (SCONTROLLER_DETAILS*)InitData; INT_PTR iDialogResult = -1; CCANControllerConfigDlg CANControllerConfigDlg(pCtrlArray[0].m_nBTR0BTR1, CWnd::FromHandle(m_hOwnerWndHandle)); iDialogResult = CANControllerConfigDlg.DoModal(); if (IDOK == iDialogResult) { pCtrlArray[0].m_omStrBaudrate = CANControllerConfigDlg.GetBitTimingName(); pCtrlArray[0].m_nBTR0BTR1 = CANControllerConfigDlg.GetBitTimingValue(); m_arrIxxatCanChannels[0].SetControllerParameter(&pCtrlArray[0]); hrRes = S_OK; } else { // aborted because the user had pressed the abort button hrRes = E_ABORT; } } return hrRes; }
/** * \return S_OK for success, S_FALSE for failure * * Sets the controller configuration data supplied by InitData. */ HRESULT CDIL_CAN_i_VIEW::CAN_SetConfigData( PSCONTROLLER_DETAILS InitData, int /*Length*/ ) { VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); CAN_StopHardware(); for (UINT i = 0; i < m_nChannels; i++) { pVCI_t VCI = m_Channel[i]; if (!VCI) { continue; } VCI->Baudrate( FromString<UNUM32>( InitData[i].m_omStrBaudrate ) ); VCI->ClearFilters(); for( UINT f=0; f<defCAN_MSG_IDS; f++ ) { pFilter_t Filter=nullptr; UNUM8 Id[4]= {0,0,0,0}, Mask[4]= {0,0,0,0}; if (InitData[i].m_enmHWFilterType[f]==HW_FILTER_MANUAL_SET) { Id[0] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccCodeByte1[f], true); Id[1] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccCodeByte2[f], true); Id[2] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccCodeByte3[f], true); Id[3] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccCodeByte4[f], true); Mask[0] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccMaskByte1[f], true); Mask[1] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccMaskByte2[f], true); Mask[2] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccMaskByte3[f], true); Mask[3] = (UNUM8)FromString<UNUM32>(InitData[i].m_omStrAccMaskByte4[f], true); } if (InitData[i].m_enmHWFilterType[f]!=HW_FILTER_REJECT_ALL) { pFilter_t Filter = new CFilter( VCI_PASS_FILTER, f==1?VCI_CAN_29BIT_ID:0,4,Id,Mask); VCI->AddFilter( Filter ); } } } return S_OK; }
/** * Close doen the iView interface driver. * Remove all the clients and buffers. * Stop the mDNS browser deselect the interfaces and * delete all the registered VCIs. */ HRESULT CDIL_CAN_i_VIEW::CAN_PerformClosureOperations(void) { VALIDATE_VALUE_RETURN_VAL(m_CurrState, STATE_DRIVER_SELECTED, ERR_IMPROPER_STATE); pClientMap_t Clients = m_Clients; pClientMap_t::iterator CItr = Clients.begin(); for (; CItr != Clients.end(); CItr++ ) { DWORD Id = CItr->first; CAN_RegisterClient(FALSE, Id, nullptr); } if (m_iViewBrowser) { m_iViewBrowser->Stop(); delete m_iViewBrowser; } if( m_CurrState == STATE_CONNECTED ) { CAN_StopHardware(); } CAN_DeselectHwInterface(); EnterCriticalSection(&m_Mutex); pVCIMap_t::iterator VItr = m_VCI.begin(); for (; VItr != m_VCI.end(); VItr++ ) { delete VItr->second->VCiIF(); delete VItr->second; } LeaveCriticalSection(&m_Mutex); DeleteCriticalSection(&m_Mutex); m_CurrState = STATE_DRIVER_LOADED; return S_OK; }
HRESULT CDIL_LIN_VectorXL::StopHardware(void) { VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE); HRESULT hResult = S_OK; //Terminate the read thread sg_sParmRThread.bTerminateThread(); hResult = nConnect(FALSE); if (hResult == defERR_OK) { hResult = S_OK; sg_bCurrState = STATE_HW_INTERFACE_SELECTED; } else { //log the error for open port failure vRetrieveAndLog(hResult, __FILE__, __LINE__); hResult = ERR_LOAD_HW_INTERFACE; } return hResult; }
/** * @brief Stops the controller. * @param void * @return S_OK for success, S_FALSE for failure */ HRESULT CDIL_CAN_VSCOM::stopHardware(void) { VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE); if (sg_hReadThread != NULL) { TerminateThread(sg_hReadThread, 0); sg_hReadThread = NULL; } if (sg_hEventRecv != NULL) { CloseHandle(sg_hEventRecv); sg_hEventRecv = NULL; } if (sg_VSCanCfg.hCan > 0) { VSCAN_Close(sg_VSCanCfg.hCan); sg_VSCanCfg.hCan = 0; } return(S_OK); }
/** * \brief Stops the controller. * \param void * \return S_OK for success, S_FALSE for failure */ HRESULT CDIL_CAN_MHS::CAN_StopHardware(void) { VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_CONNECTED, ERR_IMPROPER_STATE); (void)CanDeviceClose(0); return(S_OK); }