Ejemplo n.º 1
0
/******************************************************************************
Function Name  :  bFillDataStructureFromDatabaseFile
Input(s)       :  CString strFileName - DataBase File Path
Output         :  BOOL
Functionality  :
Member of      :  CDataBaseMsgList
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :
******************************************************************************/
ERRORCODE CDataBaseMsgList::FillDataStructureFromDatabaseFile( std::string strFileName )
{
    bFreeMessageMemory();
    std::list<ClusterResult> clusterList;
    ERRORCODE ecError = mDbManagerAccess.mParseDbFile( strFileName, CAN, clusterList );
    if ( ecError != EC_SUCCESS && ecError != EC_WARNING_SUCCESS )
    {
        return ecError;
    }
    if ( clusterList.end() == clusterList.begin() )
    {
        mCurrentCluster = nullptr;
        return EC_FAILURE;
    }
    mCurrentCluster = clusterList.begin()->m_pCluster;
    return EC_SUCCESS;
}
Ejemplo n.º 2
0
/******************************************************************************
Function Name  :  ~CDataBaseMsgList
Input(s)       :  -
Output         :  -
Functionality  :  Destructor
Member of      :  CDataBaseMsgList
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :
******************************************************************************/
CDataBaseMsgList::~CDataBaseMsgList(void)
{
    bFreeMessageMemory();
}
Ejemplo n.º 3
0
/******************************************************************************
Function Name  :  bFillDataStructureFromDatabaseFile
Input(s)       :  CString strFileName - DataBase File Path
Output         :  BOOL
Functionality  :
Member of      :  CDataBaseMsgList
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :
******************************************************************************/
BOOL CDataBaseMsgList::bFillDataStructureFromDatabaseFile( CString strFileName, eProtocol eProtocolName, INT nChannelNumber)
{
    BOOL bReturnValue   = TRUE;
    BOOL bIsFileOpen    = FALSE;
    m_unMessageCount = 0;
    // validate the file
    bReturnValue = bValidateDatabaseFile(strFileName);
    if ( bReturnValue == TRUE )
    {
        // For File I/O
        CStdioFile o_File;

        TRY
        {
            // Open File
            bIsFileOpen = o_File.Open(
                strFileName, CFile::modeRead|CFile::typeText );
            if(bIsFileOpen != FALSE )
            {
                float fDBVerNum = 0;
                float fCurrDBVer = 0;
                CString sFirstLine  = "";
                CString omDBVerLine  = "";
                // read subsequent info from the file
                /* Read Database version number*/
                int nIndex = -1;
                while( nIndex == -1 && o_File.ReadString( omDBVerLine ))
                {
                    nIndex = omDBVerLine.Find(DATABASE_VERSION);
                }
                if (nIndex != -1)
                {
                    int nPlace = omDBVerLine.Find('=');
                    if(nPlace == -1)
                    {
                        nPlace = omDBVerLine.Find(']');
                    }
                    CString omDbVerNo =
                        omDBVerLine.Right( omDBVerLine.GetLength() - (nPlace+2));
                    fDBVerNum = (FLOAT)atof(omDbVerNo.GetBuffer(MAX_PATH));
                    fCurrDBVer = (FLOAT)atof(DATABASE_VERSION_NO);

                    // Updated for checking the dbf version with Previous version
                    if ((fDBVerNum < fCurrDBVer) && (omDbVerNo != DATABASE_PREVIOUS_VERSION_NO))
                    {
                        //m_bIsDatabaseSaved = FALSE;
                    }
                    if (fDBVerNum > fCurrDBVer)
                    {
                        return FALSE;
                    }
                }
                /* Reading of database version number ends */
                //int nCount = 0;

                nIndex = -1;
                // Get number of messages
                while( nIndex == -1 && o_File.ReadString( sFirstLine ))
                {
                    nIndex = sFirstLine.Find(NUMBER_OF_MESSAGES);
                }

                if ( nIndex != -1 )
                {
                    int nPlace = sFirstLine.Find('=');
                    if(nPlace == -1)
                    {
                        nPlace = sFirstLine.Find(']');
                    }
                    CString omstrNoOfMsgs =
                        sFirstLine.Right( sFirstLine.GetLength() - (nPlace+2));



                    // create message signal structure using no of message
                    if(bFreeMessageMemory() == TRUE)
                    {
                        m_unMessageCount = atoi( omstrNoOfMsgs );
                        m_psMessages = new sMESSAGE[m_unMessageCount];
                    }
                    else
                    {
                        return FALSE;
                    }
                    // Number of messages updated here

                    if ( m_psMessages != nullptr )
                    {
                        // Initialise all signal stuff to nullptr to
                        // make sure application will not crash
                        for ( UINT nCount = 0; nCount < m_unMessageCount; nCount++ )
                        {
                            m_psMessages[nCount].m_psSignals = nullptr;
                        }

                        UINT unMsgCount = 0;

                        // start getting message information with in the
                        // message boundary. The message count is included to
                        // avoid crash if the file has more entries
                        while ( unMsgCount < m_unMessageCount
                                && o_File.ReadString( sFirstLine ))
                        {
                            nIndex = sFirstLine.Find( MSG_START_ID, 0);

                            if ( nIndex != -1 )
                            {
                                // initialise all the matrix elements
                                // to zero for this message
                                for ( UINT nCount = 0; nCount < 1785/*8*/; nCount++ )
                                {
                                    m_psMessages[unMsgCount].m_bySignalMatrix[nCount] = 0x00;
                                }

                                CString sMsgDet = sFirstLine;

                                nIndex = sMsgDet.Find( SPACE );

                                // Find Msg Name
                                if (  nIndex != -1 )
                                {
                                    CString strTmp = sMsgDet.Right(sMsgDet.GetLength() - nIndex);

                                    strTmp.TrimLeft();

                                    nIndex = strTmp.Find( ',' );

                                    if ( nIndex != -1 )
                                    {
                                        // Msg Name
                                        if(nChannelNumber > 0)
                                        {
                                            m_psMessages[unMsgCount].m_omStrMessageName = strTmp.Left( nIndex );
                                            //m_psMessages[unMsgCount].m_omStrMessageName.Format("%s%d::", rgProtocol[eProtocolName], nChannelNumber);
                                            //m_psMessages[unMsgCount].m_omStrMessageName += strTmp.Left( nIndex );
                                        }
                                        else    // Channel 0 does not exist - do not use channelnumber::framename-format. Useful for e.g. database editor
                                        {
                                            m_psMessages[unMsgCount].m_omStrMessageName = strTmp.Left( nIndex );
                                        }
                                        sMsgDet = strTmp.Right(strTmp.GetLength() - nIndex - 1);
                                        m_psMessages[unMsgCount].m_byMessageChannel = nChannelNumber;  // Associate all messages of 
                                                                                                       // this database to exactly one channel
                                    }
                                    else
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }

                                    // Find Msg Code

                                    nIndex = sMsgDet.Find( ',' );

                                    if (  nIndex != -1 )
                                    {
                                        strTmp = sMsgDet.Left(nIndex);

                                        // Msg Code
                                        m_psMessages[unMsgCount].m_unMessageCode = (UINT)atoi((const char*) strTmp );
                                        int len = sMsgDet.GetLength() - nIndex - 1;
                                        sMsgDet = sMsgDet.Right(len);
                                    }
                                    else
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }

                                    // Find Msg Length

                                    nIndex = sMsgDet.Find( ',' );

                                    if (  nIndex != - 1 )
                                    {
                                        strTmp = sMsgDet.Left(nIndex);

                                        // Msg length
                                        m_psMessages[unMsgCount].m_unMessageLength = atoi(strTmp);

                                        sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                    }
                                    else
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }

                                    nIndex = sMsgDet.Find( ',' );

                                    if (  nIndex != - 1 )
                                    {
                                        strTmp = sMsgDet.Left(nIndex);

                                        // No of Signals
                                        m_psMessages[unMsgCount].m_unNumberOfSignals = (UINT)atoi((const char*) sMsgDet );

                                        sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                    }
                                    else
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }

                                    // rajesh: 03-03-2003: modification begin: Read Data-Format & Frame-Format
                                    nIndex = sMsgDet.Find( ',' );

                                    if (  nIndex != - 1 )
                                    {
                                        strTmp = sMsgDet.Left(nIndex);

                                        // No of Signals
                                        m_psMessages[unMsgCount].m_nMsgDataFormat = 1;//(UINT)atoi((const char*) sMsgDet );

                                        sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                    }
                                    else
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }

                                    // check that extracted substring is not empty
                                    if(sMsgDet.IsEmpty())
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }

                                    // if not empty, find frame-format
                                    if(sMsgDet[0] == 'S')
                                    {
                                        m_psMessages[unMsgCount].m_bMessageFrameFormat = 0; // STANDARD
                                    }
                                    else if(sMsgDet[0] == 'X')
                                    {
                                        m_psMessages[unMsgCount].m_bMessageFrameFormat = 1; // EXTENDED
                                    }
                                    else
                                    {
                                        bReturnValue = FALSE;
                                        break;
                                    }
                                    // rajesh: 03-03-2003: modification end

                                    if ( m_psMessages[unMsgCount].m_unNumberOfSignals > 0)
                                    {
                                        sSIGNALS* pNext =
                                            m_psMessages[unMsgCount].m_psSignals = nullptr;

                                        // start getting signal information
                                        UINT unNumberofSignalsRead = 0;

                                        BOOL bLineRead = FALSE;

                                        while (unNumberofSignalsRead < m_psMessages[unMsgCount].m_unNumberOfSignals)
                                        {
                                            if (!bLineRead)
                                            {
                                                o_File.ReadString( sFirstLine );
                                            }
                                            int nIndex = sFirstLine.Find( SG_START_ID, 0 );

                                            if ( nIndex != -1)
                                            {
                                                // Allocate memory for signal
                                                sSIGNALS* sTempSg = new sSIGNALS;

                                                if (sTempSg == nullptr)
                                                {
                                                    bReturnValue = FALSE;
                                                    break;
                                                }
                                                else
                                                {
                                                    sTempSg->m_psNextSignalList = nullptr;

                                                    CString sMsgDet = sFirstLine;

                                                    nIndex = sMsgDet.Find( SPACE );
                                                    // Find Signal Name
                                                    if (  nIndex != -1 )
                                                    {
                                                        CString strTmp = sMsgDet.Right(sMsgDet.GetLength() - nIndex);

                                                        strTmp.TrimLeft();

                                                        sMsgDet = strTmp;

                                                        nIndex = strTmp.Find( ',' );

                                                        // Find and get signal name
                                                        if ( nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            sTempSg->m_omStrSignalName = sTmp;

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get SIGNAL LENGTH
                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);
                                                            sTempSg->m_unSignalLength = atoi( (const char*) sTmp );
                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get byte info from which signal has started
                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            sTempSg->m_unStartByte =  atoi( (const char*) sTmp );

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal start bit
                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            //Type cast no problem since we are usinf one character only
                                                            sTempSg->m_byStartBit = (BYTE)atoi( (const char*) sTmp );

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            //TODO::    vWriteTextToTrace();
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal type
                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            const char* ucSgTyp  = (const char*)sTmp;

                                                            sTempSg->m_bySignalType = ucSgTyp[0];

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }
                                                        // Find and get signal maximum value

                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            if(sTempSg->m_bySignalType == CHAR_INT)
                                                            {
                                                                sTempSg->m_SignalMaxValue.n64Value =_atoi64(sTmp);
                                                            }
                                                            else
                                                            {
                                                                sTempSg->m_SignalMaxValue.un64Value = _atoi64(sTmp);
                                                            }

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal minimum value

                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            if(sTempSg->m_bySignalType == CHAR_INT)
                                                            {
                                                                sTempSg->m_SignalMinValue.n64Value = _atoi64(sTmp);
                                                            }
                                                            else
                                                            {
                                                                sTempSg->m_SignalMinValue.un64Value = _atoi64(sTmp);
                                                            }

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal data format

                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            sTempSg->m_eFormat = DATA_FORMAT_MOTOROLA;
                                                            if (atoi(sTmp) == 1) // Forced to use hardcoded value owing to
                                                            {
                                                                // the already existing nonsense code.
                                                                sTempSg->m_eFormat = DATA_FORMAT_INTEL;
                                                            }
                                                            if (fDBVerNum < fCurrDBVer)
                                                            {
                                                                sTempSg->m_eFormat = DATA_FORMAT_INTEL;
                                                            }
                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal offset value

                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            sTempSg->m_fSignalOffset = (float)atof(sTmp);

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal factor value

                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            sTempSg->m_fSignalFactor = (float)atof(sTmp);

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex - 1);
                                                        }
                                                        else
                                                        {
                                                            bReturnValue = FALSE;
                                                            break;
                                                        }

                                                        // Find and get signal unit
                                                        //in 1.1 version ","will be added to end signal unit field
                                                        //in 1.0 it is ended with space

                                                        nIndex = sMsgDet.Find( ',' );

                                                        if (  nIndex != -1 )
                                                        {
                                                            CString sTmp = sMsgDet.Left(nIndex);

                                                            sTempSg->m_omStrSignalUnit = sTmp;

                                                            sMsgDet = sMsgDet.Right(sMsgDet.GetLength() - nIndex -1 );
                                                        }

                                                        CSignalDescVal* pomSgDescValNext = sTempSg->m_oSignalIDVal = nullptr;

                                                        // Get signal value descriptor and value
                                                        while ( o_File.ReadString( sFirstLine ))
                                                        {
                                                            int nFoundIndex = sFirstLine.Find( SG_DESC_START_ID ,0 );

                                                            if ( nFoundIndex != -1)
                                                            {
                                                                nFoundIndex = sFirstLine.Find( " " );
                                                            }
                                                            if (nFoundIndex != -1 )
                                                            {
                                                                CSignalDescVal* pomSgDescVal =
                                                                    new CSignalDescVal;

                                                                // Find Msg Name
                                                                CString strTmp = sFirstLine.Right(sFirstLine.GetLength() - (nFoundIndex+1));

                                                                strTmp.TrimLeft();

                                                                sFirstLine = strTmp;

                                                                nFoundIndex = sFirstLine.Find( ',' );

                                                                // Find and get signal type
                                                                if (  nFoundIndex != -1 )
                                                                {
                                                                    CString sTmp = sFirstLine.Left(nFoundIndex);

                                                                    // Get ID
                                                                    pomSgDescVal->m_omStrSignalDescriptor = sTmp;

                                                                    sFirstLine = sFirstLine.Right(sFirstLine.GetLength() - nFoundIndex - 1);

                                                                    pomSgDescVal->m_DescValue.n64Value = _atoi64( (const char*) sFirstLine );

                                                                    pomSgDescVal->m_pouNextSignalSignalDescVal = nullptr;

                                                                }// end if ( finding for comma)
                                                                else
                                                                {
                                                                    bReturnValue = FALSE;
                                                                    break;
                                                                }
                                                                // Attach the signal descand value to the data structure.

                                                                if ( pomSgDescValNext != nullptr)
                                                                {
                                                                    while ( pomSgDescValNext->m_pouNextSignalSignalDescVal != nullptr )
                                                                    {
                                                                        pomSgDescValNext = pomSgDescValNext->m_pouNextSignalSignalDescVal;
                                                                    }
                                                                    pomSgDescValNext->m_pouNextSignalSignalDescVal = pomSgDescVal;
                                                                }
                                                                else
                                                                {
                                                                    pomSgDescValNext = sTempSg->m_oSignalIDVal = pomSgDescVal;

                                                                    pomSgDescValNext->m_pouNextSignalSignalDescVal = nullptr;
                                                                }

                                                            }
                                                            else
                                                            {
                                                                bLineRead = TRUE;

                                                                break;
                                                            }
                                                        }// while
                                                    }//

                                                    // allocate memory for next signal
                                                    if ( pNext != nullptr )
                                                    {
                                                        while( pNext->m_psNextSignalList != nullptr )
                                                        {
                                                            pNext = pNext->m_psNextSignalList;
                                                        }
                                                        pNext->m_psNextSignalList = sTempSg;

                                                    }
                                                    else
                                                    {
                                                        pNext = m_psMessages[unMsgCount].m_psSignals = sTempSg;

                                                        pNext->m_psNextSignalList = nullptr;
                                                    }

                                                    unNumberofSignalsRead++;

                                                }// if (!=nullptr)

                                            }// if signal found
                                        }

                                        if (bReturnValue == FALSE)
                                        {
                                            break;
                                        }
                                    }
                                    else // No signals defined.
                                    {
                                        m_psMessages[unMsgCount].m_psSignals = nullptr;
                                    }

                                    // next message index
                                    unMsgCount++;
                                }

                            }// message not found

                        }// while read message
                    }
                    else
                    {
                        bReturnValue = FALSE;
                    }

                }
                if (bIsFileOpen == TRUE)
                {
                    o_File.Close();
                }
            }
            else
            {
            }
        }
        CATCH_ALL (pomE)
        {
            if(pomE != nullptr )
            {
                LPTSTR lpszError = "";
                // Get error
                pomE->GetErrorMessage( lpszError, defSIZE_OF_ERROR_BUFFER);
                pomE->Delete();
            }

            if (bIsFileOpen == TRUE)
            {
                o_File.Close();
            }

        }
        END_CATCH_ALL

    }