void CFormatMsgJ1939::vFormatJ1939DataMsg(PSTJ1939_MSG psJ1939BData, PSFORMATTEDATA_J1939 psJ1939FData, BYTE bExprnFlag_Log) { psJ1939FData->m_dwMsgID = psJ1939BData->m_sMsgProperties.m_uExtendedID.m_unExtID; GetMessageTypeStr(psJ1939BData->m_sMsgProperties.m_eType, psJ1939FData->m_acMsgType); TYPE_CHANNEL CurrChannel = psJ1939BData->m_sMsgProperties.m_byChannel; if ((CurrChannel >= CHANNEL_CAN_MIN) && (CurrChannel <= CHANNEL_CAN_MAX )) { _stprintf(psJ1939FData->m_acChannel, "%d", CurrChannel); } if (IS_NUM_HEX_SET(bExprnFlag_Log)) { _stprintf(psJ1939FData->m_acSrcHex, FORMAT_STR_DATA_HEX, psJ1939BData->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_bySrcAddress); _stprintf(psJ1939FData->m_acDestHex, FORMAT_STR_DATA_HEX, psJ1939BData->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPDU_Specific); } if (IS_NUM_DEC_SET(bExprnFlag_Log)) { _stprintf(psJ1939FData->m_acSrcDec, FORMAT_STR_DATA_DEC, psJ1939BData->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_bySrcAddress); _stprintf(psJ1939FData->m_acDestDec, FORMAT_STR_DATA_DEC, psJ1939BData->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPDU_Specific); } _stprintf(psJ1939FData->m_acPriority, FORMAT_STR_DATA_DEC, psJ1939BData->m_sMsgProperties.m_uExtendedID.m_s29BitId.m_uPGN.m_sPGN.m_byPriority); if (DIR_RX == psJ1939BData->m_sMsgProperties.m_eDirection) { psJ1939FData->m_acMsgDir[0] = L'R'; } else if (DIR_TX == psJ1939BData->m_sMsgProperties.m_eDirection) { psJ1939FData->m_acMsgDir[0] = L'T'; } else { ASSERT(FALSE); } _itot(psJ1939BData->m_unDLC, psJ1939FData->m_acDataLen, 10); vFormatTime(bExprnFlag_Log, psJ1939BData, psJ1939FData); vFormatDataAndId(bExprnFlag_Log, psJ1939BData, psJ1939FData); }
/******************************************************************************* 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) { if (RX_FLAG == pMsgCAN->m_ucDataType) { CurrDataCAN->m_eDirection = DIR_RX; CurrDataCAN->m_acMsgDir[0] = _T('R'); } else if (TX_FLAG == 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; 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; CurrDataCAN->m_acType[0] = 'x'; } else { CurrDataCAN->m_byIDType = TYPE_ID_CAN_STANDARD; CurrDataCAN->m_acType[0] = _T('s'); } if (pMsgCAN->m_uDataInfo.m_sCANMsg.m_ucRTR != 0) { CurrDataCAN->m_byMsgType |= TYPE_MSG_CAN_RTR; CurrDataCAN->m_acType[1] = _T('r'); } _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_ucData, CurrDataCAN->m_byDataLength); /*PROCESS ERROR MSGS: If Error Message type. Change the data and type fields. */ if(ERR_FLAG == 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 = pMsgCAN->m_uDataInfo.m_sCANMsg.m_unMsgID; sprintf_s(CurrDataCAN->m_acMsgIDDec, FORMAT_STR_ID_DEC, CurrDataCAN->m_dwMsgID); strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_TYPE_CAN, "ERR"); } /* PROCESS ERROR MSGS ENDS */ vFormatTime(bExprnFlag_Log, CurrDataCAN); vFormatDataAndId(bExprnFlag_Log, CurrDataCAN); }
/******************************************************************************* 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) { if (RX_FLAG == pMsgCAN->m_ucDataType) { CurrDataCAN->m_eDirection = DIR_RX; CurrDataCAN->m_acMsgDir[0] = 'R'; } else if (TX_FLAG == pMsgCAN->m_ucDataType) { CurrDataCAN->m_eDirection = DIR_TX; CurrDataCAN->m_acMsgDir[0] = 'T'; } CurrDataCAN->m_acMsgDir[1] = '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_TYPE_CAN, "x"); } else { CurrDataCAN->m_byIDType = TYPE_ID_CAN_STANDARD; strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_TYPE_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_TYPE_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_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_ucData, CurrDataCAN->m_byDataLength); } /*PROCESS ERROR MSGS: If Error Message type. Change the data and type fields. */ if(ERR_FLAG == pMsgCAN->m_ucDataType) { USHORT usErrCode = usProcessCurrErrorEntry(pMsgCAN->m_uDataInfo.m_sErrInfo); if( usErrCode != ERROR_UNKNOWN ) { // Format error message char* ptrStrErrName = nullptr; 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 = pMsgCAN->m_uDataInfo.m_sCANMsg.m_unMsgID; sprintf_s(CurrDataCAN->m_acMsgIDDec, FORMAT_STR_ID_DEC, CurrDataCAN->m_dwMsgID); strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_TYPE_CAN, "ERR"); } /* PROCESS ERROR MSGS ENDS */ vFormatTime(bExprnFlag_Log, CurrDataCAN); vFormatDataAndId(bExprnFlag_Log, CurrDataCAN); }
/******************************************************************************* Function Name : CFormatMsgEthernet Input(s) : - Output : - Functionality : Format Ethernet data bytes Member of : CFormatMsgEthernet Author(s) : Ashwin R Uchil Date Created : 5.6.2014 Modifications : *******************************************************************************/ void CFormatMsgEthernet::vFormatEthernetDataMsg(STETHERNETDATA* pMsgEthernet, SFORMATTEDDATA_ETHERNET* CurrDataEthernet, BYTE bExprnFlag_Log) { if (RX_FLAG == pMsgEthernet->m_ucDataType) { CurrDataEthernet->m_eDirection = DIR_RX; CurrDataEthernet->m_acMsgDir[0] = _T('R'); } else if (TX_FLAG == pMsgEthernet->m_ucDataType) { CurrDataEthernet->m_eDirection = DIR_TX; CurrDataEthernet->m_acMsgDir[0] = _T('T'); } CurrDataEthernet->m_acMsgDir[1] = _T('x'); //TYPE_CHANNEL CurrChannel = pMsgEthernet->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); //} char chSrcMAC[12], chDestMAC[12]; _itoa_s(pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_unDataLen, CurrDataEthernet->m_acDataLen, 10); memcpy(chSrcMAC, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucSourceMAC, 12); sprintf(CurrDataEthernet->m_SourceMAC, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c\0", chSrcMAC[0],chSrcMAC[1],chSrcMAC[2],chSrcMAC[3],chSrcMAC[4],chSrcMAC[5],chSrcMAC[6],chSrcMAC[7],chSrcMAC[8],chSrcMAC[9],chSrcMAC[10],chSrcMAC[11]); memcpy(chDestMAC, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucDestMac, 12); sprintf(CurrDataEthernet->m_DestMAC, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c\0", chDestMAC[0],chDestMAC[1],chDestMAC[2],chDestMAC[3],chDestMAC[4],chDestMAC[5],chDestMAC[6],chDestMAC[7],chDestMAC[8],chDestMAC[9],chDestMAC[10],chDestMAC[11]); //strcpy(CurrDataEthernet->m_DestMAC, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucDestMac); memcpy(CurrDataEthernet->m_SourceIP, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucSourceIP, 15); memcpy(CurrDataEthernet->m_DestIP, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucDestIP, 15); memcpy(CurrDataEthernet->m_acMsgDesc, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucName, 100); //strcpy_s(CurrDataEthernet->m_acMsgDesc, LENGTH_STR_DESCRIPTION_CAN, (char*)pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucName); CurrDataEthernet->m_u64TimeStamp = pMsgEthernet->m_lTickCount.QuadPart; CurrDataEthernet->m_dwMsgID = pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_unMsgID; CurrDataEthernet->m_nDataLength = pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_unDataLen; memcpy(CurrDataEthernet->m_abData, pMsgEthernet->m_uDataInfo.m_sETHERNETMsg.m_ucData, CurrDataEthernet->m_nDataLength); /*PROCESS ERROR MSGS: If Error Message type. Change the data and type fields. */ //if(ERR_FLAG == 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 = pMsgCAN->m_uDataInfo.m_sCANMsg.m_unMsgID; // sprintf_s(CurrDataCAN->m_acMsgIDDec, FORMAT_STR_ID_DEC, CurrDataCAN->m_dwMsgID); // strcpy_s(CurrDataCAN->m_acType, LENGTH_STR_TYPE_CAN, "ERR"); //} /* PROCESS ERROR MSGS ENDS */ vFormatTime(bExprnFlag_Log, CurrDataEthernet); vFormatDataAndId(bExprnFlag_Log, CurrDataEthernet); }