/****************************************************************************** Function Name : nCreateKeyWithCodeAndType Input(s) : Output : Functionality : Creates a key for SmsgDispEntry map Member of : CMsgContainerCAN Friend of : - Author(s) : Anish kumar Date Created : 01.04.2010 ******************************************************************************/ __int64 CMsgContainerCAN::nCreateMapIndexKey( LPVOID pMsgData ) { STCANDATA* pouCANData = (STCANDATA*)pMsgData; STCAN_MSG& sMsg = pouCANData->m_uDataInfo.m_sCANMsg; // Form message to get message index in the CMap int nMsgID = 0; if (IS_ERR_MESSAGE(pouCANData->m_ucDataType)) { nMsgID = MAKE_RX_TX_MESSAGE( usProcessCurrErrorEntry(pouCANData->m_uDataInfo.m_sErrInfo), IS_RX_MESSAGE(pouCANData->m_ucDataType)); } else { nMsgID = MAKE_RX_TX_MESSAGE( sMsg.m_unMsgID, IS_RX_MESSAGE(pouCANData->m_ucDataType)); } nMsgID = MAKE_DEFAULT_MESSAGE_TYPE(nMsgID); // For extended message if (sMsg.m_ucEXTENDED) { nMsgID = MAKE_EXTENDED_MESSAGE_TYPE(nMsgID); } // Apply Channel Information __int64 n64MapIndex = MAKE_CHANNEL_SPECIFIC_MESSAGE( nMsgID, sMsg.m_ucChannel ); return n64MapIndex; }
int ReadVerifyTSXDataBuffer(CTSExecutionCAN* pTSXCan) { ASSERT(pTSXCan != nullptr); while (pTSXCan->m_ouCanBufFSE.GetMsgCount() > 0) { static STCANDATA sCanData; sCanData.m_lTickCount.QuadPart; int Result = pTSXCan->m_ouCanBufFSE.ReadFromBuffer(&sCanData); if (Result == ERR_READ_MEMORY_SHORT) { TRACE("ERR_READ_MEMORY_SHORT"); } else if (Result == EMPTY_APP_BUFFER) { TRACE("EMPTY_APP_BUFFER"); } else { INT nIndex; pTSXCan->m_ouCanBufVFSE.WriteIntoBuffer(&sCanData, sCanData.m_uDataInfo.m_sCANMsg.m_unMsgID, nIndex); } if(IS_RX_MESSAGE(sCanData.m_ucDataType)) { pTSXCan->m_LastCanMsg = sCanData.m_lTickCount.QuadPart; VerifyCurrentMessage(sCanData, pTSXCan); } } return 0; }
/****************************************************************************** Function Name : nCreateMapIndexKey Input(s) : Output : Functionality : Creates a key for SmsgDispEntry map Member of : CMsgContainerJ1939 Friend of : - Author(s) : Arun kumar K Date Created : 01.02.2011 ******************************************************************************/ __int64 CMsgContainerJ1939::nCreateMapIndexKey( LPVOID pMsgData ) { STJ1939_MSG* pouJ1939Msg = (STJ1939_MSG*) pMsgData; // Form message to get message index in the CMap UINT nMsgID = MAKE_RX_TX_MESSAGE( pouJ1939Msg->m_sMsgProperties.m_uExtendedID.m_s29BitId.unGetPGN(), IS_RX_MESSAGE(pouJ1939Msg->m_sMsgProperties.m_eDirection)); // For extended message nMsgID = MAKE_EXTENDED_MESSAGE_TYPE(nMsgID); // Apply Channel Information __int64 n64MapIndex = MAKE_CHANNEL_SPECIFIC_MESSAGE( nMsgID, pouJ1939Msg->m_sMsgProperties.m_byChannel); n64MapIndex = MAKE_SOURCE_SPECIFIC_MESSAGE( n64MapIndex, pouJ1939Msg->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_bySrcAddress); n64MapIndex = MAKE_DEST_SPECIFIC_MESSAGE( n64MapIndex, pouJ1939Msg->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPDU_Specific); n64MapIndex = MAKE_TYPE_SPECIFIC_MESSAGE( n64MapIndex, pouJ1939Msg->m_sMsgProperties.m_eType); return n64MapIndex; }
__int64 sTCANDATA::GetSlotID(sTCANDATA& pDatCAN) { STCAN_MSG &sMsg = pDatCAN.m_uDataInfo.m_sCANMsg; // Form message to get message index in the CMap int nMsgID = MAKE_RX_TX_MESSAGE( sMsg.m_unMsgID, IS_RX_MESSAGE(pDatCAN.m_ucDataType)); nMsgID = MAKE_DEFAULT_MESSAGE_TYPE(nMsgID); // For extended message if (sMsg.m_ucEXTENDED) { nMsgID = MAKE_EXTENDED_MESSAGE_TYPE(nMsgID); } // Apply Channel Information __int64 n64MapIndex = MAKE_CHANNEL_SPECIFIC_MESSAGE( nMsgID, sMsg.m_ucChannel ); return n64MapIndex; };
__int64 tagSTJ1939_MSG::GetSlotID(STJ1939_MSG& pouJ1939Msg) { // Form message to get message index in the CMap UINT nMsgID = MAKE_RX_TX_MESSAGE( pouJ1939Msg.m_sMsgProperties.m_uExtendedID.m_s29BitId.unGetPGN(), IS_RX_MESSAGE(pouJ1939Msg.m_sMsgProperties.m_eDirection)); // For extended message nMsgID = MAKE_EXTENDED_MESSAGE_TYPE(nMsgID); // Apply Channel Information __int64 n64MapIndex = MAKE_CHANNEL_SPECIFIC_MESSAGE( nMsgID, pouJ1939Msg.m_sMsgProperties.m_byChannel); n64MapIndex = MAKE_SOURCE_SPECIFIC_MESSAGE( n64MapIndex, pouJ1939Msg.m_sMsgProperties.m_uExtendedID.m_s29BitId.m_bySrcAddress); n64MapIndex = MAKE_DEST_SPECIFIC_MESSAGE( n64MapIndex, pouJ1939Msg.m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPDU_Specific); n64MapIndex = MAKE_TYPE_SPECIFIC_MESSAGE( n64MapIndex, pouJ1939Msg.m_sMsgProperties.m_eType); return n64MapIndex; };
/****************************************************************************** Function Name : vProcessNewData Input(s) : Output : Functionality : Process a new Rx/Tx msg Member of : CMsgContainerCAN Friend of : - Author(s) : Anish kumar Date Created : 01.04.2010 ******************************************************************************/ void CMsgContainerCAN::vProcessNewData(STCANDATA& sCanData) { // append : 1. Add item, get count, SetItemCount. // OW : 1. Get ID, Create map index, Search if it is present in map // if present change the offset and time stamp // 2. if not present and (get count < max count) save the Buffer index, // ListCtrl index, time stamp, make offest = time stamp in disp entry // and add to the map and array // 3. if not present and (get count = max count), do nothing // 4. SetItemcount if ( IS_A_MESSAGE(sCanData.m_ucDataType) ) { // Add to append buffer // If its the very first entry, the time stamp must if (m_sCANReadDataSpl.m_lTickCount.QuadPart != 0) // be 0 and will { // retain such value. m_sCANReadDataSpl.m_nDeltime = _abs64(sCanData.m_lTickCount.QuadPart - m_sCANReadDataSpl.m_lTickCount.QuadPart); } STCANDATA* pStcan = &m_sCANReadDataSpl; *pStcan = sCanData; if (!bTobeBlocked(sCanData)) { unsigned char FDataType = m_sCANReadDataSpl.m_ucDataType; if(IS_RX_MESSAGE(FDataType)) { HRESULT h_Evaluate = EvaluateMessage(m_sCANReadDataSpl.m_uDataInfo.m_sCANMsg); } m_ouAppendCanBuf.WriteIntoBuffer(&m_sCANReadDataSpl); if (nullptr != m_pRxMsgCallBack) { m_pRxMsgCallBack->onRxMsg((void*)&sCanData); } } } else //Add the error messages { vProcessCurrErrorEntry(sCanData.m_uDataInfo.m_sErrInfo); // Add to append buffer // If its the very first entry, the time stamp must if (m_sCANReadDataSpl.m_lTickCount.QuadPart != 0) // be 0 and will { // retain such value. m_sCANReadDataSpl.m_nDeltime = _abs64(sCanData.m_lTickCount.QuadPart - m_sCANReadDataSpl.m_lTickCount.QuadPart); } STCANDATA* pStcan = &m_sCANReadDataSpl; *pStcan = sCanData; if (!bTobeBlocked(sCanData)) { m_ouAppendCanBuf.WriteIntoBuffer(&m_sCANReadDataSpl); if (nullptr != m_pRxMsgCallBack) { m_pRxMsgCallBack->onRxMsg((void*)&sCanData); } } } }
/** * \req RS_24_08 Standard frames are considered. * \req RS_24_09 Extended frames are considered. * \req RS_24_10 RTR frames are considered. * \req RS_24_11 Error frames occurs under the purview of status data * * Calculate the Bus statistics in m_sBusStatistics structure */ void CBusStatisticCAN::vUpdateBusStatistics(STCANDATA& sCanData) { EnterCriticalSection(&m_omCritSecBS); m_sCurrEntry = sCanData.m_uDataInfo.m_sCANMsg; int nCurrentChannelIndex = sCanData.m_uDataInfo.m_sCANMsg.m_ucChannel - 1; INT nDLC = sCanData.m_uDataInfo.m_sCANMsg.m_ucDataLen; if ((nCurrentChannelIndex < 0) || (nCurrentChannelIndex > (defNO_OF_CHANNELS - 1))) { nCurrentChannelIndex = 0; //take appropriate action } if(m_sCurrEntry.m_ucRTR == 1) m_sSubBusStatistics[ nCurrentChannelIndex ].m_unDLCCount+= sCanData.m_uDataInfo.m_sCANMsg.m_ucDataLen; //is it Tx Message if(IS_TX_MESSAGE(sCanData.m_ucDataType)) { if(IS_ERR_MESSAGE(sCanData.m_ucDataType)) { m_sSubBusStatistics[nCurrentChannelIndex].m_unErrorTxCount++; } else { m_sSubBusStatistics[nCurrentChannelIndex].m_unTotalTxMsgCount++; if (m_sCurrEntry.m_ucRTR == 0) // Non RTR message { if (m_sCurrEntry.m_ucEXTENDED == 0) { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTxSTDMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsStdMsg[nDLC]; } else { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTxEXTDMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsExdMsg[nDLC]; } } else // RTR message { if (m_sCurrEntry.m_ucEXTENDED == 0) { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTxSTD_RTRMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsStdMsg[0]; } else { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTxEXTD_RTRMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsExdMsg[0]; } } } } //is it Rx Message else if(IS_RX_MESSAGE(sCanData.m_ucDataType)) { if(IS_ERR_MESSAGE(sCanData.m_ucDataType)) { m_sSubBusStatistics[nCurrentChannelIndex].m_unErrorTxCount++; } else { m_sSubBusStatistics[nCurrentChannelIndex].m_unTotalRxMsgCount++; if (m_sCurrEntry.m_ucRTR == 0) // Non RTR message { if (m_sCurrEntry.m_ucEXTENDED == 0) { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unRxSTDMsgCount++; //m_sSubBusStatistics[ nCurrentChannelIndex ].m_unSTDMsgBits = nDLC + floor((double)(nDLC / 5 + TYPE_STD_CONST1)); m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsStdMsg[nDLC]; } else { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unRxEXTDMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsExdMsg[nDLC]; } } else // RTR message { if (m_sCurrEntry.m_ucEXTENDED == 0) { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unRxSTD_RTRMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsStdMsg[0]; } else { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unRxEXTD_RTRMsgCount++; m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += m_unBitsExdMsg[0]; } } } } else { //Is it is Error m_sSubBusStatistics[nCurrentChannelIndex].m_unErrorTotalCount++; if (sCanData.m_uDataInfo.m_sErrInfo.m_ucErrType == ERROR_BUS) { // Update Statistics information m_sSubBusStatistics[ nCurrentChannelIndex ].m_unErrorTotalCount++; USHORT usErrorID = sCanData.m_uDataInfo.m_sErrInfo.m_ucReg_ErrCap & 0xE0; // Received message if (usErrorID & 0x20) { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unErrorRxCount++; } else { m_sSubBusStatistics[ nCurrentChannelIndex ].m_unErrorTxCount++; } m_sSubBusStatistics[ nCurrentChannelIndex ].m_unTotalBitsperSec += defBITS_ERR_FRAME; } } LeaveCriticalSection(&m_omCritSecBS); }
/******************************************************************************* Function Name : vFormatCANDataMsg Input(s) : - Output : - Functionality : Format CAN data bytes Member of : CFormatMsgCAN Author(s) : Ratnadip Date Created : 8.7.2009 Modifications : ArunKumar K 08.09.2010, Added handler for error messages. ERR_FLAG *******************************************************************************/ void CFormatMsgCAN::vFormatCANDataMsg(STCANDATA* pMsgCAN, SFORMATTEDDATA_CAN* CurrDataCAN, BYTE bExprnFlag_Log) { /*PROCESS ERROR MSGS: If Error Message type. Change the data and type fields. */ if (IS_ERR_MESSAGE(pMsgCAN->m_ucDataType)) { USHORT usErrCode = usProcessCurrErrorEntry(pMsgCAN->m_uDataInfo.m_sErrInfo); if( usErrCode != ERROR_UNKNOWN ) { // Format error message char* ptrStrErrName = NULL; ptrStrErrName = vFormatCurrErrorEntry(usErrCode); if(ptrStrErrName) { strcpy_s(CurrDataCAN->m_acDataDec, LENGTH_STR_DATA_CAN, ptrStrErrName); strcpy_s(CurrDataCAN->m_acDataHex, LENGTH_STR_DATA_CAN, ptrStrErrName); } } CurrDataCAN->m_dwMsgID = 0; sprintf_s(CurrDataCAN->m_acMsgIDDec, FORMAT_STR_ID_DEC, CurrDataCAN->m_dwMsgID); strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_TYPE_CAN, "ERR"); } else { if (IS_RX_MESSAGE(pMsgCAN->m_ucDataType)) { CurrDataCAN->m_eDirection = DIR_RX; CurrDataCAN->m_acMsgDir[0] = _T('R'); } else if (IS_TX_MESSAGE(pMsgCAN->m_ucDataType)) { CurrDataCAN->m_eDirection = DIR_TX; CurrDataCAN->m_acMsgDir[0] = _T('T'); } CurrDataCAN->m_acMsgDir[1] = _T('x'); TYPE_CHANNEL CurrChannel = pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucChannel; // Assuming default CAN msg if (pMsgCAN->m_uDataInfo.m_sCANMsg.m_bCANFD) // Incase of CANFD msg { CurrChannel = pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucChannel; } if ((CurrChannel >= CHANNEL_CAN_MIN) && (CurrChannel <= CHANNEL_CAN_MAX )) { sprintf_s(CurrDataCAN->m_acChannel, "%d", CurrChannel); } memset(CurrDataCAN->m_acType,'\0',sizeof(CurrDataCAN->m_acType)); if (pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucEXTENDED != 0) { CurrDataCAN->m_byIDType = TYPE_ID_CAN_EXTENDED; strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_DESCRIPTION_CAN, _("x")); } else { CurrDataCAN->m_byIDType = TYPE_ID_CAN_STANDARD; strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_DESCRIPTION_CAN, _("s")); } /* If it is a CAN FD frame */ if ( pMsgCAN->m_uDataInfo.m_sCANMsg.m_bCANFD ) { strcpy_s(&CurrDataCAN->m_acType[1], LENGTH_STR_DESCRIPTION_CAN, _("-fd")); } else if (pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucRTR != 0) // CANFD cannot have RTR frames { CurrDataCAN->m_byMsgType |= TYPE_MSG_CAN_RTR; strcpy_s(&CurrDataCAN->m_acType[1], LENGTH_STR_DESCRIPTION_CAN, _("r")); } /* If it is a CAN FD frame */ //if ( pMsgCAN->m_bCANFDMsg ) //{ // _itoa_s(pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucDataLen, CurrDataCAN->m_acDataLen, 10); // strcpy_s(CurrDataCAN->m_acMsgDesc, LENGTH_STR_DESCRIPTION_CAN, "Description"); // CurrDataCAN->m_u64TimeStamp = pMsgCAN->m_lTickCount.QuadPart; // CurrDataCAN->m_dwMsgID = pMsgCAN->m_uDataInfo.m_sCANMsg.m_unMsgID; // CurrDataCAN->m_byDataLength = pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucDataLen; // memcpy(CurrDataCAN->m_abData, pMsgCAN->m_uDataInfo.m_sCANMsg.m_aucCANFDData, // CurrDataCAN->m_byDataLength); //} //else { _itoa_s(pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucDataLen, CurrDataCAN->m_acDataLen, 10); strcpy_s(CurrDataCAN->m_acMsgDesc, LENGTH_STR_DESCRIPTION_CAN, "Description"); CurrDataCAN->m_dwMsgID = pMsgCAN->m_uDataInfo.m_sCANMsg.m_unMsgID; CurrDataCAN->m_byDataLength = pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucDataLen; memcpy(CurrDataCAN->m_abData, pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucData, CurrDataCAN->m_byDataLength); } } CurrDataCAN->m_u64TimeStamp = pMsgCAN->m_lTickCount.QuadPart; /* PROCESS ERROR MSGS ENDS */ vFormatTime(bExprnFlag_Log, CurrDataCAN); vFormatDataAndId(bExprnFlag_Log, CurrDataCAN); }