BOOL CMsgContainerCAN::bTobeBlocked(STCANDATA& sCanData)
{
    static SFRAMEINFO_BASIC_CAN sBasicCanInfo;
    vFormatCANDataMsg(&sCanData, &sBasicCanInfo);

    EnterCriticalSection(&m_omCritSecFilter);
    BOOL bBlock = m_sFilterCAN.bToBeBlocked(sBasicCanInfo);
    LeaveCriticalSection(&m_omCritSecFilter);
    return bBlock;
}
Example #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;
}