예제 #1
0
/*******************************************************************************
  Function Name  : sGetCanMsg
  Input(s)       : -
  Output         : -
  Functionality  : To extract CAN data from a message
  Member of      : CReplayProcess
  Author(s)      : Robin George Koshy
  Date Created   : 09.06.2014
  Modifications  :
*******************************************************************************/
bool CReplayProcess::sGetCanMsg(CString omStrMessage,STCANDATA& sCanMsg)
{
    //Check whether hex or dec and set the flag appropriately.
    if(omStrMessage.Find("0x")!=-1)
    {
        m_bReplayHexON = TRUE;
    }
    else
    {
        m_bReplayHexON = FALSE;
    }
    BOOL bIsValidMessage = bGetMsgInfoFromMsgStr( omStrMessage,
                           &sCanMsg,
                           m_bReplayHexON );
    if(bIsValidMessage == TRUE)
    {
        return true;
    }
    else
    {
        return false;
    }
}
예제 #2
0
/*******************************************************************************
  Function Name  : bOpenReplayFile
  Input(s)       : BOOL - TRUE if parsing is successful, FALSE otherwise
  Output         : -
  Functionality  : Load the replay file. Updates entries and CAN message list
                   with the parsed content
  Member of      : CReplayProcess
  Author(s)      : Raja N
  Date Created   : 16.7.2005
  Modifications  : Raja N on 26.07.2005, Implementwed code review comments
*******************************************************************************/
BOOL CReplayProcess::bOpenReplayFile()
{
    BOOL bReturn = TRUE;
    BOOL bModeMismatch              = FALSE;
    CString     omStrLine           = "";
    CString     omStrTemp           = "";
    CHAR        Line[500]           = { 0 };
    CString     omStrMsgType        = " ";
    std::ifstream    omInReplayFile;
    int nBlockCounter = 0;

    // Clear string array
    m_omEntries.RemoveAll();
    m_omMsgList.RemoveAll();
    // Clear error message
    m_omStrError = "";

    TRY
    {
        omInReplayFile.open( m_ouReplayFile.m_omStrFileName,
        std::ios::in  );
        if (!omInReplayFile.good())
        {
            // Info file open error notification
            m_omStrError  = defSTR_FILE_OPEN_ERROR;
            bReturn = FALSE ;
        }
        if(bReturn != FALSE)
        {
            // Read the file line by line.
            BOOL bModeFound = FALSE;
            BOOL bFileEndFlag = FALSE;
            BOOL bMsgModeFound = FALSE;
            BOOL bOldVersionFile = FALSE;
            BOOL bVersionFound = FALSE;
            BOOL bProtocolFound = FALSE;
            while ( bOldVersionFile == FALSE &&
            (!omInReplayFile.eof()) &&
            ( bMsgModeFound == FALSE  ||
            bModeFound == FALSE ||
            bVersionFound == FALSE ))
            {
                omInReplayFile.getline( Line, sizeof(Line));
                omStrLine = Line;
                omStrLine.TrimLeft();
                omStrLine.TrimRight();
                // Check if Protocol exists in the log file
                if( omStrLine.Find(defSTR_PROTOCOL_USED) != -1)
                {
                    // If can related log file
                    if( omStrLine.Find(defSTR_PROTOCOL_CAN) == -1)
                    {
                        m_omStrError = defSTR_LOG_PRTOCOL_MISMATCH;
                        bReturn = FALSE ;
                        bFileEndFlag = TRUE;
                    }
                }
                // Version check
                if( omStrLine.Find(defSTR_BUSMASTER_VERSION_STRING) != -1 )
                {
                    bVersionFound = TRUE;
                    int nPos = omStrLine.Find( defSTR_BUSMASTER_VERSION_STRING );
                    nPos += (int)strlen( defSTR_BUSMASTER_VERSION_STRING );
                    int nMajorVer = omStrLine[ nPos ] - '0';
                    if( nMajorVer < defLOG_FILE_MAJOR_VERSION_SUPPORTED )
                    {
                        bOldVersionFile = TRUE;
                    }
                }

                // set the mode of reply
                if( omStrLine.Find(HEX_MODE) == 0)
                {
                    m_bReplayHexON = TRUE;
                    bMsgModeFound = TRUE;

                }
                else if (omStrLine.Find(DEC_MODE) == 0)
                {
                    m_bReplayHexON = FALSE;
                    bMsgModeFound = TRUE;
                }
                if( omStrLine.Find(SYSTEM_MODE) == 0)
                {
                    m_wLogReplayTimeMode= eSYSTEM_MODE;
                    bModeFound = TRUE;
                }
                else if( omStrLine.Find(ABSOLUTE_MODE) == 0)
                {
                    m_wLogReplayTimeMode= eABSOLUTE_MODE;
                    bModeFound = TRUE;
                }
                else if( omStrLine.Find(RELATIVE_MODE) == 0)
                {
                    m_wLogReplayTimeMode= eRELATIVE_MODE;
                    bModeFound = TRUE;
                }
            }
            if( bOldVersionFile == TRUE )
            {
                m_omStrError = defSTR_LOG_FILE_UNSUPPORTED;
                bReturn = FALSE ;
                bFileEndFlag = TRUE;
            }
            if( bReturn == TRUE &&
                    ( bModeFound == FALSE || bMsgModeFound == FALSE ||
                      bVersionFound == FALSE ) )
            {
                m_omStrError = defINVALID_HEADER;
                bReturn = FALSE ;
                bFileEndFlag = TRUE;
            }


            while (! omInReplayFile.eof() && bFileEndFlag == FALSE )
            {
                omInReplayFile.getline( Line, sizeof(Line));
                omStrLine = Line;
                omStrLine.TrimLeft();
                omStrLine.TrimRight();
                // Exclude empty line, line with starting string
                // hash defined as DefSPL_LINE
                if( omStrLine.IsEmpty()==0 &&
                        omStrLine.Find(DefSPL_LINE) == -1 &&
                        omStrLine.Find(omStrMsgType) != -1)
                {
                    // Apply Filtering
                    STCANDATA sCanMsg;
                    if( bGetMsgInfoFromMsgStr( omStrLine,
                                               &sCanMsg,
                                               m_bReplayHexON ) == TRUE )
                    {
                        SFRAMEINFO_BASIC_CAN sBasicCanInfo;
                        vFormatCANDataMsg(&sCanMsg, &sBasicCanInfo);
                        EnterCriticalSection(&m_omCritSecFilter);
                        BOOL bTobeBlocked = m_ouReplayFile.m_sFilterApplied.bToBeBlocked(sBasicCanInfo);
                        LeaveCriticalSection(&m_omCritSecFilter);

                        // Add it to the list based on filtering result
                        //if( bTobeBlocked == FALSE )
                        //{
                        // bTobeBlocked = bMessageTobeBlocked( sBasicCanInfo );
                        //if(bTobeBlocked == FALSE)
                        {
                            m_omEntries.Add( omStrLine );
                            m_omMsgList.Add(sCanMsg );
                        }
                        // }
                    }
                }
                else if(! omStrLine.Compare(START_SESSION))
                {
                    bModeMismatch = bIsModeMismatch( omInReplayFile,
                                                     m_bReplayHexON, m_wLogReplayTimeMode );
                    if(bModeMismatch == TRUE)
                    {
                        nBlockCounter++;
                        BOOL bEndBlock = FALSE;
                        CString omStrEndBlock = END_SESSION;
                        while (! omInReplayFile.eof() && bEndBlock == FALSE)
                        {
                            omInReplayFile.getline( Line, sizeof(Line));
                            if( omStrEndBlock.Compare(Line) == 0)
                            {
                                bEndBlock = TRUE;
                            }
                        }
                    }
                }
            }// while
        }
    }
    CATCH_ALL(pomException)
    {
        if(pomException != nullptr )
        {
            CHAR scErrorMsg[255];
            // Get the exception error message
            pomException->GetErrorMessage(scErrorMsg,sizeof(scErrorMsg));
            m_omStrError = scErrorMsg;
            pomException->Delete();
        }
        bReturn = FALSE;
        if( omInReplayFile.is_open() !=0)
        {
            omInReplayFile.close();
        }
    }
    END_CATCH_ALL
    if(nBlockCounter >=1 )
    {
        m_omStrError.Format( defSTR_MIXED_MODE_WARNING, nBlockCounter );
    }
    // close the file if it open
    if( omInReplayFile.is_open() !=0 )
    {
        omInReplayFile.close();
    }
    return bReturn;
}
예제 #3
0
/*******************************************************************************
  Function Name  : omStrGetMsgFromLog
  Input(s)       : -
  Output         : -
  Functionality  : To get a particular message from the log file.
  Member of      : CReplayProcess
  Author(s)      : Robin George Koshy
  Date Created   : 09.06.2014
  Modifications  :
*******************************************************************************/
CString CReplayProcess::omStrGetMsgFromLog(DWORD dwLineNo,STCANDATA& sCanMsg,bool& bSessionFlag, bool& bEOFflag, bool& bProtocolMismatch, bool& bInvalidMsg)
{
    EnterCriticalSection(&m_omCritSecFilter);
    bSessionFlag = false;
    bEOFflag = false;
    bProtocolMismatch = false;
    bInvalidMsg = false;
    DWORD dwPegOffset = dwLineNo%PEG_STEP;
    DWORD dwPegCount = dwLineNo/PEG_STEP;
    DWORD dwLinesNotPegged = dwLineNo - vecPeg.size()*PEG_STEP;
    DWORD dwDepth;
    std::string strLine = "";
    bool bIsComment = false;

    if((dwPegCount < vecPeg.size()) || dwLinesNotPegged < 0)
    {
        omInReplayFile.seekg(vecPeg[dwPegCount],std::ios::beg);
        bSessionFlag = vecSessionFlag[dwPegCount];
        for(int i=0; i<=dwPegOffset; i++)
        {
            do
            {
                getline(omInReplayFile,strLine);
                CUtilFunctions::Trim(strLine,' ');
                if(strLine.find(START_COMMENT) != std::string::npos)
                {
                    bIsComment = true;
                }
                if(strLine.find(END_COMMENT) != std::string::npos)
                {
                    bIsComment = false;
                }
                if(bIsComment)
                {
                    continue;
                }
                if(strLine.find("*")!=std::string::npos && dwLineNo!=0)
                {
                    if( strLine.find(defSTR_PROTOCOL_USED) != std::string::npos)
                    {
                        // If can related log file
                        if( strLine.find(defSTR_PROTOCOL_CAN) == std::string::npos)
                        {
                            bProtocolMismatch = true;
                            strLine = "";
                        }
                    }
                    bSessionFlag = true;
                }
                if(omInReplayFile.eof())
                {
                    bEOFflag = true;
                }
            }
            while(((strLine.find("*")!=std::string::npos || strLine.empty())&& !omInReplayFile.eof() && !bProtocolMismatch)||bIsComment);
            //Check valid Message
            if(strLine.find("0x")!=-1)
            {
                m_bReplayHexON = TRUE;
            }
            else
            {
                m_bReplayHexON = FALSE;
            }
            if(!bGetMsgInfoFromMsgStr( strLine.c_str(),
                                       &sCanMsg,
                                       m_bReplayHexON ))
            {
                bInvalidMsg = true;
            }
        }
    }
    else
    {
        if(dwLineNo==0)
        {
            omInReplayFile.seekg(0,std::ios::beg);

        }
        else
        {
            omInReplayFile.seekg(vecPeg.back(),std::ios::beg);

        }
        if(dwLinesNotPegged==0 && dwLineNo != 0)
        {
            dwLinesNotPegged = PEG_STEP;
        }
        for(int i=0; i<=dwLinesNotPegged; i++)
        {
            do
            {
                dwDepth = omInReplayFile.tellg();
                getline(omInReplayFile,strLine);
                CUtilFunctions::Trim(strLine,' ');
                if(strLine.find(START_COMMENT) != std::string::npos)
                {
                    bIsComment = true;
                }
                if(strLine.find(END_COMMENT) != std::string::npos)
                {
                    bIsComment = false;
                }
                if(bIsComment)
                {
                    continue;
                }
                if(strLine.find("*")!=std::string::npos && dwLineNo!=0)
                {
                    if( strLine.find(defSTR_PROTOCOL_USED) != std::string::npos)
                    {
                        // If can related log file
                        if( strLine.find(defSTR_PROTOCOL_CAN) == std::string::npos)
                        {
                            bProtocolMismatch = true;
                            strLine = "";
                        }
                    }
                    bSessionFlag = true;
                }
                if(omInReplayFile.eof())
                {
                    bEOFflag = true;
                }
            }
            while(((strLine.find("*")!=std::string::npos || strLine.empty())&& !omInReplayFile.eof() && !bProtocolMismatch)||bIsComment);
            //Check valid Message
            if(strLine.find("0x")!=-1)
            {
                m_bReplayHexON = TRUE;
            }
            else
            {
                m_bReplayHexON = FALSE;
            }
            if(!bGetMsgInfoFromMsgStr( strLine.c_str(),
                                       &sCanMsg,
                                       m_bReplayHexON ))
            {
                strLine = "";
                bInvalidMsg = true;
            }
            if(((i%PEG_STEP == 0 && i!=0) || dwLineNo == 0) && !strLine.empty())
            {
                vecPeg.push_back(dwDepth);
                vecSessionFlag.push_back(bSessionFlag);
            }

        }
    }

    if(omInReplayFile.eof())
    {
        omInReplayFile.clear();
    }

    LeaveCriticalSection(&m_omCritSecFilter);

    return strLine.c_str();


}