UINT g_unSendMsg_J1939(STJ1939_MSG* psTxMsg, HMODULE hModule) { UINT Return = 0; VALIDATE_POINTER_RETURN_VAL(psTxMsg, Return); CExecuteFunc* pmCEexecuteFunc = CExecuteManager::ouGetExecuteManager(J1939).pmGetNodeObject(hModule); if (pmCEexecuteFunc != nullptr) { BOOL bMsgTxFlag = pmCEexecuteFunc->bGetMsgTxFlag(); if (bMsgTxFlag) { if (CGlobalObj::GetIJ1939DIL()->DILIJ_SendJ1939Msg(pmCEexecuteFunc->dwGetNodeClientId(), psTxMsg->m_sMsgProperties.m_byChannel, psTxMsg->m_sMsgProperties.m_eType, psTxMsg->m_sMsgProperties.m_uExtendedID.m_s29BitId.unGetPGN(), psTxMsg->m_pbyData, psTxMsg->m_unDLC, psTxMsg->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPriority, ADDRESS_NULL, psTxMsg->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPDU_Specific) == S_OK) { Return = 1; } } } return Return; }
DWORD WINAPI FlexMsgReadThreadProc_Stub(LPVOID pVoid) { VALIDATE_POINTER_RETURN_VAL(sg_pIlog, (DWORD)-1); CPARAM_THREADPROC* pThreadParam = (CPARAM_THREADPROC *) pVoid; pThreadParam->m_unActionCode = CREATE_TIME_MAP; // Validate certain required pointers bool bLoopON = true; while (bLoopON) { static HANDLE ahClientReadHandle[MAX_CLIENT_ALLOWED] = {0}; for (UINT i = 0; i < sg_unClientCnt; i++) { ahClientReadHandle[i] = sg_asClientToBufMap[i].hClientHandle; } DWORD dwIndex = WaitForMultipleObjects(sg_unClientCnt, ahClientReadHandle, FALSE, INFINITE); if (dwIndex == WAIT_FAILED) { GetSystemErrorString(); } else { UINT Index = dwIndex - WAIT_OBJECT_0; switch (pThreadParam->m_unActionCode) { case INVOKE_FUNCTION: { // Retrieve message from the pipe ProcessCanMsg(sg_asClientToBufMap[Index].hPipeFileHandle, Index); } break; case CREATE_TIME_MAP: { PerformAnOperation(GET_TIME_MAP); ProcessCanMsg(sg_asClientToBufMap[Index].hPipeFileHandle, Index); pThreadParam->m_unActionCode = INVOKE_FUNCTION; } break; case EXIT_THREAD: { bLoopON = false; } break; default: case INACTION: { // nothing right at this moment } break; } } } SetEvent(pThreadParam->hGetExitNotifyEvent()); return 0; }
HRESULT CGlobalObj::RegisterNodeToDIL(BOOL bRegister, PSNODEINFO pNodeInfo) { VALIDATE_POINTER_RETURN_VAL(pNodeInfo, S_FALSE); HRESULT hResult = S_FALSE; switch (m_eBus) { case CAN: { hResult = CGlobalObj::GetICANDIL()->DILC_RegisterClient(bRegister, pNodeInfo->m_dwClientId, pNodeInfo->m_omStrNodeName.GetBuffer(MAX_PATH)); if ((hResult == S_OK) && (bRegister == TRUE)) { //Set the buffer hResult = CGlobalObj::GetICANDIL()->DILC_ManageMsgBuf(MSGBUF_ADD, pNodeInfo->m_dwClientId, (pNodeInfo->m_ouCanBufFSE)); } } break; case J1939: { hResult = CGlobalObj::GetIJ1939DIL()->DILIJ_RegisterClient(bRegister, pNodeInfo->m_omStrNodeName.GetBuffer(MAX_CHAR), pNodeInfo->m_unEcuName, pNodeInfo->m_byPrefAddress, pNodeInfo->m_dwClientId); if (((hResult == S_OK) || (hResult == ERR_CLIENT_EXISTS)) && (bRegister == TRUE)) { //Set the buffer hResult = CGlobalObj::GetIJ1939DIL()->DILIJ_ManageMsgBuf(MSGBUF_ADD, pNodeInfo->m_dwClientId, (pNodeInfo->m_ouMsgBufVSE)); GetIJ1939DIL()->DILIJ_SetCallBckFuncPtr(pNodeInfo->m_dwClientId, CLBCK_FN_LDATA_CONF, (PCLBCK_FN_LDATA_CONF)sg_vDataConfEventFnJ1939); GetIJ1939DIL()->DILIJ_SetCallBckFuncPtr(pNodeInfo->m_dwClientId, CLBCK_FN_BC_LDATA_CONF, (PCLBCK_FN_BC_LDATA_CONF)sg_vDataConfEventFnJ1939); GetIJ1939DIL()->DILIJ_SetCallBckFuncPtr(pNodeInfo->m_dwClientId, CLBCK_FN_NM_ACL, (PCLBCK_FN_NM_ACL)sg_vAddressClaimEventFnJ1939); } } break; case LIN: { hResult = CGlobalObj::GetILINDIL()->DILL_RegisterClient(bRegister, pNodeInfo->m_dwClientId, pNodeInfo->m_omStrNodeName.GetBuffer(MAX_PATH)); if (((hResult == S_OK) || (hResult == ERR_CLIENT_EXISTS)) && (bRegister == TRUE)) { //Set the buffer hResult = CGlobalObj::GetILINDIL()->DILL_ManageMsgBuf(MSGBUF_ADD, pNodeInfo->m_dwClientId, (pNodeInfo->m_ouLinBufSE)); } } break; } 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; }
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; }
/** * @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; }
LONG CNetworkMgmt::lCreateNodeConManager(char* pacNodeName, UINT64 un64ECUName, BYTE byPrefAdres, DWORD& dwClientId) { VALIDATE_POINTER_RETURN_VAL(m_pIDIL_CAN, S_FALSE); LONG lResult = S_OK; CNodeConManager* pNodeConMgr = NULL; //Search the array if node is already present pNodeConMgr = pouGetConMagrObj(pacNodeName); if (pNodeConMgr != NULL) { lResult = ERR_CLIENT_EXISTS; dwClientId = pNodeConMgr->m_dwClientID; } //If no. of node reached limit else if(m_nConMgrCnt == DEF_MAX_SIMULATED_NODE) { lResult = ALLOWED_NOMORE; } //Create new node if (lResult == S_OK) { //Find the first available position in the Array. There will //be empty places in beween due to deletion int nEmptyPos = 0; for (int i = 0; i < DEF_MAX_SIMULATED_NODE; i++) { if (m_ConMgrArr[i] == NULL) { nEmptyPos = i; break; } } if ( _tcscmp(pacNodeName, J1939_MONITOR_NODE) == 0 ) { pNodeConMgr = new CMonitorNode(nEmptyPos, pacNodeName, un64ECUName, byPrefAdres); } else { //Provide its position in array and its PGN pNodeConMgr = new CNodeConManager(nEmptyPos, pacNodeName, un64ECUName, byPrefAdres); } if (pNodeConMgr != NULL) { m_ConMgrArr[nEmptyPos] = pNodeConMgr; m_nConMgrCnt++; HRESULT hResult = S_FALSE; // Connection manager is created. Proceed with rest of the procedures if ( _tcscmp(pacNodeName, J1939_MONITOR_NODE) == 0 ) { hResult = m_pIDIL_CAN->DILC_RegisterClient(TRUE, dwClientId, CAN_MONITOR_NODE); m_dwCANMonitorNodeClientId = dwClientId; if (hResult == ERR_CLIENT_EXISTS) { hResult = S_OK; } } else { hResult = m_pIDIL_CAN->DILC_RegisterClient(TRUE, dwClientId, pacNodeName); } //ASSERT(hResult == S_OK); if ((hResult == S_OK) || (hResult == ERR_CLIENT_EXISTS)) { CBaseCANBufFSE* pouBuffer = pNodeConMgr->pouGetBuf(); hResult = m_pIDIL_CAN->DILC_ManageMsgBuf(MSGBUF_ADD, dwClientId, pouBuffer); ASSERT(hResult == S_OK); if (hResult == S_OK) { pNodeConMgr->m_dwClientID = dwClientId; m_ouReadCANMsg.AddEventHandle(pouBuffer->hGetNotifyingEvent(), (BYTE)nEmptyPos); } //Join this node to network if started. if (m_bOnline == TRUE) { pNodeConMgr->vActivate(); BYTE byPrefAddress = pNodeConMgr->m_byPrefAddress; if ((byPrefAddress >= ADDRESS_NULL) || (bIsAddressClaimed(byPrefAddress) == TRUE)) { byPrefAddress = byGetUnclaimedAddress(); } pNodeConMgr->StartAdresClaimProc(byPrefAddress); } } } else { ASSERT(FALSE); } } return lResult; }
/** * \brief Read thread procedure * \param[in] pVoid contains the CPARAM_THREADPROC class object * \return void * \authors Arunkumar Karri * \date 07.19.2013 Created */ DWORD WINAPI CDIL_LIN_VectorXL::LINMsgReadThreadProc_LIN_Vector_XL(LPVOID pVoid) { USES_CONVERSION; CPARAM_THREADPROC* pThreadParam = (CPARAM_THREADPROC*) pVoid; XLstatus xlStatus = XL_SUCCESS; /* Assign thread action to CREATE_TIME_MAP */ pThreadParam->m_unActionCode = CREATE_TIME_MAP; /* Set the event to LIN_Vector_XL driver for wakeup and frame arrival notification */ //for (UINT i = 0; i < sg_unClientCnt; i++) { xlStatus = xlSetNotification (g_xlPortHandle[0], &g_hDataEvent[0], 1); } /* Set the thread action event to first notification event handle */ if (g_hDataEvent[0] != nullptr) { pThreadParam->m_hActionEvent = g_hDataEvent[0]; } /* Get the handle to the controller and validate it */ VALIDATE_POINTER_RETURN_VAL(pThreadParam->m_hActionEvent, (DWORD)-1); DWORD dwResult = 0; unsigned int msgsrx; XLevent xlEvent; bool bLoopON = true; while (bLoopON) { WaitForSingleObject(g_hDataEvent[0], INFINITE); switch (pThreadParam->m_unActionCode) { case INVOKE_FUNCTION: { bool bMoreDataExist; msgsrx = RECEIVE_EVENT_SIZE; xlStatus = xlReceive(g_xlPortHandle[0], &msgsrx, &xlEvent); while (xlStatus == XL_SUCCESS ) { switch (xlStatus) { case XL_SUCCESS: { if ( g_pouDIL_LIN_Vector_XL != nullptr ) { g_pouDIL_LIN_Vector_XL->ProcessLINMsg(xlEvent); bMoreDataExist = true; } } break; default: break; } xlStatus = xlReceive(g_xlPortHandle[0], &msgsrx, &xlEvent);; } } break; case EXIT_THREAD: { bLoopON = false; } break; case CREATE_TIME_MAP: { //vCreateTimeModeMapping(pThreadParam->m_hActionEvent); SetEvent(pThreadParam->m_hActionEvent); pThreadParam->m_unActionCode = INVOKE_FUNCTION; } break; default: case INACTION: { // nothing right at this moment } break; } } SetEvent(pThreadParam->hGetExitNotifyEvent()); { ResetEvent(g_hDataEvent[0]); g_hDataEvent[0] = nullptr; } pThreadParam->m_hActionEvent = nullptr; return 0; }