/**
 * \brief Generates the message list
 *
 * This function will parse the input file and line by line
 * and generates  a list of message,signal,value table,comments,etc
 */
void CDBFConverter::GenerateMessageList(fstream& fileInput)
{
    char acLine[defCON_MAX_LINE_LEN]; // I don't expect one line to be more than this
    string local_copy;
    char* pcTok;
    int flag=0;
    int _flag_BS_= 0; //possible values 0,1,2// this flag is used to check if parsing is done in between NS_: and BS_:  #git issue 174

    // parsing the input file
    while(fileInput.getline(acLine, defCON_MAX_LINE_LEN))
    {
        char* pcToken=0, *pcLine=0;

        for (;;)
        {
            pcLine = acLine;
            pcLine += strlen(pcLine); // go to last position
            pcLine --;

            if (*pcLine == '\r')
            {
                fileInput.getline(pcLine, defCON_MAX_LINE_LEN);
            }
            else
            {
                break;
            }
        }

        // avoid leading <spaces> before tokenising, so passing the
        // starting point will be correct in each case, when calling
        // msg.Format, sig.Format etc.
        local_copy = acLine;
        pcLine = acLine;

        while(*pcLine && *pcLine == ' ')
        {
            *pcLine++;
        }

        pcToken = strtok_s(pcLine, " :", &pcTok);

        if(pcToken)
        {
            //compare token to known types to interpret the line further
            if(strstr(pcToken, "BS_") != NULL)  // git issue #174
            {
                if (_flag_BS_ == 1 )
                {
                    _flag_BS_ = 2;    // this means just NS_ and BS_ are done.
                }
            }
            if(strstr(pcToken, "NS_") != NULL)
            {
                if (_flag_BS_ == 0 )
                {
                    _flag_BS_ = 1;    // this means just NS_ is hit and BS_ is still due.
                }
            }

            // new line - skip
            else if(strcmp(pcToken, "\n") == 0)
            {
                continue;
            }
            // message
            else if(strcmp(pcToken, "BO_") == 0)
            {
                CMessage msg;
                msg.Format(pcLine + strlen(pcToken)+1);

                // add the new message to the list
                if((msg.m_acName != "VECTOR__INDEPENDENT_SIG_MSG") && !(msg.m_uiMsgID == 3221225472) )
                {
                    if( CAN == m_eBus )
                    {
                        if( msg.m_ucLength <= 8 )
                        {
                            CDBFConverter::valid_msg = true;
                            m_listMessages.push_back(msg);
                        }
                        else
                        {
                            CDBFConverter::valid_msg = false;
                            m_unsupList.push_back(msg);
                        }
                    }
                    else
                    {
                        CDBFConverter::valid_msg = true;
                        m_listMessages.push_back(msg);
                    }
                }
                else
                {
                    CDBFConverter::valid_msg = false;
                }
            }
            // signal
            else if(strcmp(pcToken, "SG_") == 0)
            {
                CSignal sig;
                sig.Format(pcLine + strlen(pcToken) + 1);

                //if signal associated with a msg add it to that perticular list
                //elses add it to msg independent list
                if(CDBFConverter::valid_msg == true)
                {
                    //insert signals in sorted order
                    int flag = 0;
                    CMessage& msg = m_listMessages.back();

                    /* if (msg.m_listSignals.empty())
                     {
                         msg.m_listSignals.push_front(sig);
                         flag = 1;
                         continue;
                     }

                     int count = 0;
                     list<CSignal>::iterator sig1 = msg.m_listSignals.end();

                     while(sig1!=msg.m_listSignals.begin())
                     {
                         --sig1;
                         count++;

                         if(((sig1->m_ucWhichByte * 8) + sig1->m_ucStartBit) > ((sig.m_ucWhichByte * 8) + sig.m_ucStartBit))
                         {
                             ++sig1;
                             msg.m_listSignals.insert(sig1, sig);
                             flag = 1;
                             break;
                         }
                     }

                     if (flag == 0)*/
                    {
                        msg.m_listSignals.push_back(sig);
                    }

                    // this signal should belong to the last message
                    msg.m_ucNumOfSignals++; // increment the signal count
                }
                else
                {
                    sig.m_ucWhichByte = 1;
                    sig.m_ucStartBit = 0;
                    m_listSignal.push_back(sig);
                }
            }
            // value descriptor
            else if(strcmp(pcToken, "VAL_") == 0)
            {
                // <msgid><sp><signalName><sp><value1><sp><"desc1"><sp><value2><sp><"desc2"> ...;
                // get MsgId, find the message from the messagelist.
                // find the signal from the message, then add the value descritors
                // to the respective signals
                pcLine = pcLine + strlen(pcToken) + 1; // to get next token
                pcToken = strtok_s(pcLine, " ", &pcTok); // msgid
                unsigned int id = (unsigned int) strtoul(pcToken, NULL, 10);

                if(id != 3221225472)
                {
                    list<CMessage>::iterator rMsg;

                    for(rMsg=m_listMessages.begin(); rMsg!=m_listMessages.end(); ++rMsg)
                    {
                        // find matching message from list
                        if(rMsg->m_uiMsgID == id)
                        {
                            pcLine = pcLine + strlen(pcToken) + 1; // to get next token
                            pcToken = strtok_s(pcLine, " ", &pcTok); // Signal name
                            list<CSignal>::iterator rSig;

                            // find matching signal
                            for(rSig=rMsg->m_listSignals.begin(); rSig!=rMsg->m_listSignals.end(); ++rSig)
                            {
                                if(rSig->m_acName == pcToken)
                                {
                                    rSig->AddValueDescriptors(pcLine + strlen(pcToken) + 1, fileInput);
                                    break; // if we got the signal we wanted
                                }
                            }

                            break; // we got the message we wanted
                        }
                    }
                }
                else
                {
                    pcLine = pcLine + strlen(pcToken) + 1; // to get next token
                    pcToken = strtok_s(pcLine, " ", &pcTok); // Signal name
                    list<CSignal>::iterator rSig;

                    // find matching signal
                    for(rSig=m_listSignal.begin(); rSig!=m_listSignal.end(); ++rSig)
                    {
                        if(rSig->m_acName == pcToken)
                        {
                            rSig->AddValueDescriptors(pcLine + strlen(pcToken) + 1, fileInput);
                            break; // if we got the signal we wanted
                        }
                    }
                }
            }
            // signal value qualifier
            else if(strcmp(pcToken, "SIG_VALTYPE_") == 0)
            {
                // <msgID> <signal name> : 1 -- float
                // <msgID> <signal name> : 2 -- double
                // get MsgId, find the message from the messagelist.
                // find the signal from the message, then update the
                // signal type appropriately of the respective signal
                pcToken = strtok_s(NULL, " :;", &pcTok); // msgid
                unsigned int id = (unsigned int)strtoul(pcToken, NULL, 10);

                if(id != 3221225472)
                {
                    list<CMessage>::iterator rMsg;

                    for(rMsg=m_listMessages.begin(); rMsg!=m_listMessages.end(); ++rMsg)
                    {
                        // find matching message from list
                        if(rMsg->m_uiMsgID == id)
                        {
                            pcToken = strtok_s(NULL, " :;", &pcTok); // Signal name
                            list<CSignal>::iterator rSig;

                            // find matching signal
                            for(rSig=rMsg->m_listSignals.begin(); rSig!=rMsg->m_listSignals.end(); ++rSig)
                            {
                                if(rSig->m_acName == pcToken)
                                {
                                    if(pcToken = strtok_s(NULL, " :;", &pcTok)) // qualifier (1 or 2)
                                    {
                                        // update signal type based on qualifier
                                        switch(*pcToken)
                                        {
                                            case '1':
                                                rSig->m_ucType = CSignal::SIG_TYPE_FLOAT;
                                                break;

                                            case '2':
                                                rSig->m_ucType = CSignal::SIG_TYPE_DOUBLE;
                                                break;

                                            default:
                                                break;
                                        }
                                    }

                                    break; // we got the signal we wanted
                                }
                            }

                            break; // we got the message we wanted
                        }
                    }
                }
                else
                {
                    pcToken = strtok_s(NULL, " :;", &pcTok); // Signal name
                    // find matching signal
                    list<CSignal>::iterator rSig;

                    for(rSig=m_listSignal.begin(); rSig!=m_listSignal.end(); ++rSig)
                    {
                        if(rSig->m_acName == pcToken)
                        {
                            if(pcToken = strtok_s(NULL, " :;", &pcTok)) // qualifier (1 or 2)
                            {
                                // update signal type based on qualifier
                                switch(*pcToken)
                                {
                                    case '1':
                                        rSig->m_ucType = CSignal::SIG_TYPE_FLOAT;
                                        break;

                                    case '2':
                                        rSig->m_ucType = CSignal::SIG_TYPE_DOUBLE;
                                        break;

                                    default:
                                        break;
                                }
                            }

                            break; // we got the signal we wanted
                        }
                    }
                }
            }
            //value table
            else if(strcmp(pcToken, "VAL_TABLE_") == 0)
            {
                CValueTable tab;
                pcToken = strtok_s(pcLine, " ", &pcTok);
                tab.Format(pcLine + strlen(pcToken) + 1, fileInput);
                m_vTab.push_back(tab);
            }
            //comments
            else if(strcmp(pcToken, "CM_") == 0)
            {
                string comment = pcTok; // for network node - venkat
                pcLine = pcLine + strlen(pcToken) + 1;
                pcToken = strtok_s(pcLine, " ", &pcTok);
                CComment cm;

                //comments related to node
                if(strcmp(pcToken, "BU_") == 0)
                {
                    pcToken = strtok_s(NULL, " ", &pcTok);
                    cm.m_elementName= pcToken;
                    pcToken = strtok_s(NULL, "", &pcTok);
                    comment = pcToken;

                    while(strstr(pcToken, "\";") == NULL)
                    {
                        fileInput.getline(acLine, defCON_MAX_LINE_LEN);
                        pcToken = acLine;
                        comment = comment + pcToken;
                    }

                    cm.m_comment= comment;
                    m_cmNode.push_back(cm);
                }
                //comments related to messages
                else if(strcmp(pcToken,"BO_") == 0)
                {
                    pcToken = strtok_s(NULL, " ", &pcTok);
                    cm.m_msgID = strtoul(pcToken, NULL, 10);

                    // set the id and frame format
                    // canoe puts MSbit = 1 for extended ID
                    if(cm.m_msgID < 0x80000000UL)
                    {
                        cm.m_msgType= 'S';
                    }
                    else
                    {
                        cm.m_msgType= 'X';
                        cm.m_msgID  &= 0x7FFFFFFF;
                    }

                    pcToken = strtok_s(NULL, "", &pcTok);
                    comment = pcToken;

                    while(strstr(pcToken, "\";") == NULL)
                    {
                        fileInput.getline(acLine, defCON_MAX_LINE_LEN);
                        pcToken = acLine;
                        comment = comment + pcToken;
                    }

                    cm.m_comment= comment;
                    m_cmMsg.push_back(cm);
                }
                //comments related to signals
                else if(strcmp(pcToken, "SG_") == 0)
                {
                    pcToken = strtok_s(NULL, " ", &pcTok);
                    cm.m_msgID = strtoul(pcToken, NULL, 10);

                    if(cm.m_msgID < 0x80000000UL)
                    {
                        cm.m_msgType = 'S';
                    }
                    else
                    {
                        cm.m_msgType = 'X';
                        cm.m_msgID &= 0x7FFFFFFF;
                    }

                    pcToken = strtok_s(NULL, " ", &pcTok);
                    cm.m_elementName = pcToken;
                    pcToken = strtok_s(NULL, "", &pcTok);
                    comment = pcToken;

                    while(strstr(pcToken, "\";") == NULL)
                    {
                        fileInput.getline(acLine, defCON_MAX_LINE_LEN);
                        pcToken = acLine;
                        comment = comment + pcToken;
                    }

                    cm.m_comment= comment;
                    m_cmSig.push_back(cm);
                }
                //comments related to network
                else
                {
                    //comment = pcToken;
                    int nRetVal = comment.find(";");
                    if( nRetVal < 0)
                    {
                        while(strstr(pcToken, "\";") == NULL)
                        {
                            fileInput.getline(acLine, defCON_MAX_LINE_LEN);
                            pcToken = acLine;
                            comment = comment + pcToken;
                        }
                    }

                    cm.m_comment= comment;
                    m_cmNet.push_back(cm);
                }
            }
            // node
            else if(strcmp(pcToken, "BU_") == 0)
            {
                create_Node_List(pcLine + strlen(pcToken)+1);
            }
            else if ( ( (strcmp(pcToken, "BA_DEF_")==0) || (strcmp(pcToken, "BA_DEF_REL_")==0)) && _flag_BS_ > 1)
            {
                CParameter pObj;
                pObj.Format(pcLine + strlen(pcToken) + 1); // to get next token
                m_listParameters.push_back(pObj);
            }
            //Param Initial Values
            else if(strcmp(pcToken, "BA_DEF_DEF_")==0 && _flag_BS_ > 1 )
            {
                char acTemp[defCON_TEMP_LEN],*pcTemp;
                pcTemp = acTemp;
                pcToken = strtok_s(NULL, "\"", &pcTok);
                pcToken = strtok_s(NULL, "\"", &pcTok);
                flag=0;

                while(*pcToken && *pcToken != '"')
                {
                    *pcTemp++ = *pcToken++;
                }

                *pcTemp = '\0';
                list<CParameter>::iterator rParam;

                for(rParam=m_listParameters.begin(); rParam!=m_listParameters.end(); ++rParam)
                {
                    // find matching Parameter from list
                    if(rParam->m_ParamName == acTemp)
                    {
                        pcTemp=acTemp;
                        pcToken = strtok_s(NULL, ";", &pcTok); // default val
                        rParam->ReadDefaultVal(pcToken);
                        flag=1;
                        break;
                    }
                }

                if(flag==0)
                {
                    string errString = "BA_DEF_DEF_ \"";
                    errString += acTemp;
                    errString += "\" ";
                    errString += pcToken;
                    errString += _(" : Match not Found in Param List\n");
                    defList.push_back(errString);
                }
            }
            //RX,Tx Parameter Definition
            else if(strcmp(pcToken,"BA_DEF_DEF_REL_")==0 && _flag_BS_ > 1)
            {
                char acTemp[defCON_TEMP_LEN],*pcTemp;
                pcTemp = acTemp;
                flag = 0;
                pcToken = strtok_s(NULL, "\"", &pcTok);

                while(*pcToken && (*pcToken != '"'))
                {
                    *pcTemp++ = *pcToken++; // copy SIG_NAME only, i.e. till first 'space'
                }

                *pcTemp = '\0';
                list<CParameter>::iterator rParam;

                for(rParam=m_listParameters.begin(); rParam!=m_listParameters.end(); ++rParam)
                {
                    // find matching Parameter from list
                    if(rParam->m_ParamName == acTemp)
                    {
                        pcTemp = acTemp;
                        pcToken = strtok_s(NULL, ";", &pcTok); // default val
                        rParam->ReadDefaultVal(pcToken);
                        flag=1;
                        break;
                    }
                }

                if(flag==0)
                {
                    string errString = "BA_DEF_DEF_REL \"";
                    errString += acTemp;
                    errString += "\" ";
                    errString += pcToken;
                    errString += _(" : Match not Found in Param List\n");
                    defList.push_back(errString);
                }
            }
            // Parameter Other values //
            else if(strcmp(pcToken, "BA_")==0)
            {
                char acTemp[defCON_TEMP_LEN],*pcTemp;
                pcTemp = acTemp;

                while(*pcLine && (*pcLine == ' '))
                {
                    *pcLine++;
                }

                //get Param name
                pcLine = pcLine + strlen(pcToken) + 1;
                pcToken = strtok_s(pcLine, "\"", &pcTok);

                while(*pcToken && (*pcToken != '"'))
                {
                    *pcTemp++ = *pcToken++;
                }

                *pcTemp = '\0';
                list<CParameter>::iterator rParam;

                for(rParam=m_listParameters.begin(); rParam!=m_listParameters.end(); ++rParam)
                {
                    // find matching Parameter from list
                    if(rParam->m_ParamName == acTemp)
                    {
                        rParam->FormatParamValue(pcLine + strlen(acTemp) + 3); // to get next token
                        pcTemp=acTemp;
                        if(rParam->m_ParamName == SIGNAL_LONG_NAME)
                        {
                            CParameterValues uParamVal = rParam->m_listParamValues[3].back();
                            vUpdateSignalNameFromParam(uParamVal);
                            int i = 0;
                        }
                        else if(rParam->m_ParamName == MESSAGE_LONG_NAME)
                        {
                            CParameterValues uParamVal = rParam->m_listParamValues[2].back();
                            vUpdateMessageNameFromParam(uParamVal);
                            int i = 0;
                        }

                        break;
                    }
                }
            }
            //maintain a list of lines not processed
            else
            {
                string str = local_copy;
                m_notProcessed.push_back(str);
                continue;
            }
        }
    }
}
Example #2
0
File: main.cpp Project: CCJY/coliru
 void invokeQueued(CSignal<Arguments...>& signal, std::index_sequence<Is...>, Args&&... args)
 {
     m_queue.emplace_back(
       [signal, t = std::tuple<std::decay_t<Arguments>...>(std::forward<Args>(args)...)]
       (){signal.invoke(std::get<Is>(t)...);});
 }
/**
 * \brief Writes all the data to the output file in CANoe format
 *
 * Writes all the data to the output file in CANoe format.
 */
bool CDBFConverter::WriteToOutputFile(fstream& fileOutput)
{
    bool bResult = true;
    // write to the output file
    // write header
    fileOutput << T_HEADER << endl;
    fileOutput << endl;
    fileOutput << T_DB_VER " " T_VER_NO << endl;
    fileOutput << endl;
    if(m_eBus == J1939)
    {
        fileOutput << T_PROTOCOL " " T_PRPTOCOL_J1939;
    }
    else
    {
        //default CAN
        fileOutput << T_PROTOCOL " " T_PROTOCOL_CAN;
    }
    fileOutput << endl;
    fileOutput << endl;

    //For easy replacement of version Info #define is not added
    fileOutput<< "[BUSMASTER_VERSION] [2.3.0]"<<endl;

    // number of messages
    fileOutput << T_NUM_OF_MSG " " << dec << m_listMessages.size() << endl;
    fileOutput << endl;
    //Write Messagess to the Output file
    CMessage msg;
    bResult &= msg.writeMessageToFile(fileOutput, m_listMessages, false, m_eBus);

    // write all messages, signals not associated with any Messages
    if(!m_listSignal.empty())
    {
        fileOutput << T_ST_SIG_LIST << endl;
        CSignal sig;
        bResult &= sig.WriteSignaltofile(fileOutput, m_listSignal, 0, 0, false);
        fileOutput << T_END_SIG_LIST << endl;
        fileOutput << endl;
    }

    //write value table
    fileOutput << T_ST_VAL_TAB << endl;
    CValueTable temp_vtab;
    temp_vtab.writeValueTabToFile (fileOutput,m_vTab);
    fileOutput << T_END_VAL_TAB << endl;
    fileOutput << endl;
    //write list of nodes
    fileOutput << T_NODE " ";
    bool comma = false;
    list<string>::iterator node;

    for(node=m_listNode.begin(); node!=m_listNode.end(); ++node)
    {
        if(comma)
        {
            fileOutput << ",";
        }

        fileOutput << node->c_str();
        comma = true;
    }

    fileOutput << endl;
    fileOutput << endl;
    //Write Comments
    fileOutput << T_ST_COMMENT << endl;
    //network comments
    fileOutput << T_ST_CM_NET << endl;
    list<CComment>::iterator cmt;

    for(cmt=m_cmNet.begin(); cmt!=m_cmNet.end(); ++cmt)
    {
        fileOutput << cmt->m_elementName.c_str();
        fileOutput << " " << cmt->m_comment.c_str() << endl;
    }

    fileOutput << T_END_CM_NET << endl;
    fileOutput << endl;
    //node comments
    fileOutput << T_ST_CM_NODE << endl;

    for(cmt=m_cmNode.begin(); cmt!=m_cmNode.end(); ++cmt)
    {
        fileOutput << cmt->m_elementName.c_str();
        fileOutput << " " << cmt->m_comment.c_str() << endl;
    }

    fileOutput << T_END_CM_NODE << endl;
    fileOutput << endl;
    //message comments
    fileOutput << T_ST_CM_MSG << endl;

    for(cmt=m_cmMsg.begin(); cmt!=m_cmMsg.end(); ++cmt)
    {
        fileOutput << cmt->m_msgID;
        fileOutput << " " << cmt->m_msgType;
        fileOutput << " " << cmt->m_comment.c_str() << endl;
    }

    fileOutput << T_END_CM_MSG << endl;
    fileOutput << endl;
    //signal comments
    fileOutput << T_ST_CM_SIG << endl;

    for(cmt=m_cmSig.begin(); cmt!=m_cmSig.end(); ++cmt)
    {
        fileOutput << cmt->m_msgID;
        fileOutput << " " << cmt->m_msgType;
        fileOutput << " " << cmt->m_elementName.c_str();
        fileOutput << " " << cmt->m_comment.c_str() << endl;
    }

    fileOutput << T_END_CM_SIG << endl;
    fileOutput << T_END_COMMENT << endl;
    fileOutput << endl;
    //Write Parameters to the output file.
    fileOutput << START_PARAM_TAG << endl;
    fileOutput << START_NETPARAM_TAG << endl;
    bResult=bResult & WriteParametersToFile(fileOutput, m_listParameterArray[0]);
    fileOutput << END_NETPARAM_TAG << endl;
    fileOutput << endl;
    fileOutput << START_NODEPARAM_TAG << endl;
    bResult=bResult & WriteParametersToFile(fileOutput, m_listParameterArray[1]);
    fileOutput << END_NODEPARAM_TAG << endl;
    fileOutput << endl;
    fileOutput << START_MSGPARAM_TAG << endl;
    bResult=bResult & WriteParametersToFile(fileOutput, m_listParameterArray[2]);
    fileOutput << END_MSGPARAM_TAG << endl;
    fileOutput << endl;
    fileOutput << START_SIGPARAM_TAG << endl;
    bResult=bResult & WriteParametersToFile(fileOutput, m_listParameterArray[3]);
    fileOutput << END_SIGPARAM_TAG << endl;
    fileOutput << endl;
    fileOutput << START_RXPARAM_TAG << endl;
    bResult=bResult & WriteParametersToFile(fileOutput, m_listParameterArray[4]);
    fileOutput << END_RXPARAM_TAG << endl;
    fileOutput << endl;
    fileOutput << START_TXPARAM_TAG << endl;
    bResult=bResult & WriteParametersToFile(fileOutput, m_listParameterArray[5]);
    fileOutput << END_TXPARAM_TAG << endl;
    fileOutput << END_PARAM_TAG << endl;
    fileOutput << endl;
    //Parameter Values
    fileOutput << START_PARAMVAL_TAG << endl;
    fileOutput << START_NETVAL_TAG << endl;
    list<CParameter>::iterator rParam;

    for(rParam=m_listParameterArray[0].begin(); rParam!=m_listParameterArray[0].end(); ++rParam)
    {
        list<CParameterValues>::iterator vParam;

        for(vParam=rParam->m_listParamValues[0].begin(); vParam!=rParam->m_listParamValues[0].end(); ++vParam)
        {
            vParam->WriteNetValuesToFile(fileOutput, rParam->m_ParamType, rParam->m_ParamName);
        }
    }

    fileOutput << END_NETVAL_TAG << endl;
    fileOutput << endl;
    fileOutput << START_NODEVAL_TAG << endl;

    for(rParam=m_listParameterArray[1].begin(); rParam!=m_listParameterArray[1].end(); ++rParam)
    {
        list<CParameterValues>::iterator vParam;

        for(vParam=rParam->m_listParamValues[1].begin(); vParam!=rParam->m_listParamValues[1].end(); ++vParam)
        {
            vParam->WriteNodeValuesToFile(fileOutput, rParam->m_ParamType, rParam->m_ParamName);
        }
    }

    fileOutput << END_NODEVAL_TAG << endl;
    fileOutput << endl;
    fileOutput << START_MSGVAL_TAG << endl;

    for(rParam=m_listParameterArray[2].begin(); rParam!=m_listParameterArray[2].end(); ++rParam)
    {
        list<CParameterValues>::iterator vParam;

        for(vParam=rParam->m_listParamValues[2].begin(); vParam!=rParam->m_listParamValues[2].end(); ++vParam)
        {
            vParam->WriteMesgValuesToFile(fileOutput, rParam->m_ParamType, rParam->m_ParamName);
        }
    }

    fileOutput << END_MSGVAL_TAG << endl;
    fileOutput << endl;
    fileOutput << START_SIGVAL_TAG << endl;

    for(rParam=m_listParameterArray[3].begin(); rParam!=m_listParameterArray[3].end(); ++rParam)
    {
        list<CParameterValues>::iterator vParam;

        for(vParam=rParam->m_listParamValues[3].begin(); vParam!=rParam->m_listParamValues[3].end(); ++vParam)
        {
            vParam->WriteSigValuesToFile(fileOutput, rParam->m_ParamType, rParam->m_ParamName);
        }
    }

    fileOutput << END_SIGVAL_TAG << endl;
    fileOutput << endl;
    fileOutput << END_PARAMVAL_TAG << endl;
    fileOutput << endl;
    fileOutput << endl;
    //list of not supported
    fileOutput << T_ST_NOT_SUP << endl;
    msg.writeMessageToFile(fileOutput, m_unsupList, true, m_eBus);
    fileOutput << T_END_NOT_SUP << endl;
    fileOutput << endl;
    //lines that were not processed
    fileOutput << T_ST_NOT_PRO << endl;
    list<string>::iterator np;

    for(np=m_notProcessed.begin(); np!=m_notProcessed.end(); ++np)
    {
        fileOutput << np->c_str() << endl;
    }

    fileOutput << endl;
    fileOutput << T_END_NOT_PRO << endl;
    return bResult;
}
Example #4
0
/**
 * \brief     Generate Message List
 * \param[in] fileInput Input file
 *
 * This function will parse the input file and line by line
 * and generates a list of message,signal,value table,comments,etc
 */
void CConverter::GenerateMessageList(fstream& fileInput)
{
    char acLine[defCON_MAX_LINE_LEN]; // I don't expect one line to be more than this
    bool valTab = false;
    list<CMessage>::iterator posMsg;
    list<CSignal>::iterator posSig;
    // parsing the input file

    while(fileInput.getline(acLine,defCON_MAX_LINE_LEN))
    {
        char* pcToken;
        char* pcNextToken;
        char* pcLine;
        // avoid leading <spaces> before tokenising, so passing the
        // starting point will be correct in each case, when calling
        // msg.Format, sig.Format etc.
        pcLine = acLine;

        while(*pcLine && *pcLine == ' ')
        {
            *pcLine++;
        }

        pcToken = strtok_s(pcLine, " ", &pcNextToken);

        if(pcToken)
        {
            //compare token to known types to interpret the line further

            // new line - skip
            if(strcmp(pcToken,"\n") == 0)
            {
                continue;
            }
            // message
            else if(strcmp(pcToken,"[START_MSG]") == 0)
            {
                bool found = false;
                CMessage msg;
                msg.Format(pcLine + strlen(pcToken)+1);

                // find the message
                for(posMsg=m_listMessages.begin(); posMsg!=m_listMessages.end(); ++posMsg)
                {
                    if((posMsg->m_uiMsgID == msg.m_uiMsgID) && (posMsg->m_cFrameFormat == msg.m_cFrameFormat))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    m_listMessages.push_back(msg);
                    posMsg = m_listMessages.end();
                    --posMsg;
                }
            }
            else if(strcmp(pcToken,"[START_SIG_LIST]") == 0)
            {
                CMessage msg;
                msg.m_sName = "VECTOR__INDEPENDENT_SIG_MSG";
                msg.m_sTxNode = "Vector__XXX";
                msg.m_ucLength = 0;
                msg.m_uiMsgID = 3221225472;
                CConverter::ucMsg_DLC = 8;
                m_listMessages.push_front(msg);
                posMsg = m_listMessages.begin();
                fileInput.getline(acLine,defCON_MAX_LINE_LEN);
                pcToken = strtok_s(pcLine, " ", &pcNextToken);

                while(strcmp(acLine,"[END_SIG_LIST]") != 0)
                {
                    pcToken = strtok_s(pcLine, " ", &pcNextToken);

                    if(strcmp(pcToken,"[START_SIGNALS]") == 0)
                    {
                        CSignal sig;
                        sig.Format(pcLine + strlen(pcToken)+1);
                        sig.m_ucStartBit = 0;
                        posMsg->m_listSignals.push_front(sig);
                        posSig = posMsg->m_listSignals.begin();
                    }
                    else if(strcmp(pcToken,"[VALUE_DESCRIPTION]") == 0)
                    {
                        CValueDescriptor val;
                        val.Format(pcLine + strlen(pcToken)+1);
                        posSig->m_listValueDescriptor.push_front(val);
                    }

                    fileInput.getline(acLine,defCON_MAX_LINE_LEN);
                }
            }
            else if(strcmp(pcToken,"[START_SIGNALS]") == 0)
            {
                CSignal sig;
                sig.Format(pcLine + strlen(pcToken)+1);
                posMsg->m_listSignals.push_front(sig);
                posSig = posMsg->m_listSignals.begin();
            }
            else if(strcmp(pcToken,"[VALUE_DESCRIPTION]") == 0 && valTab == false)
            {
                CValueDescriptor val;
                val.Format(pcLine + strlen(pcToken)+1);
                posSig->m_listValueDescriptor.push_front(val);
            }
            else if(strcmp(pcToken,"[START_NOT_SUPPORTED]") == 0)
            {
            }
            //nodes
            else if(strcmp(pcToken,"[NODE]") == 0)
            {
                create_Node_List(pcLine + strlen(pcToken)+1);
            }
            else if(strcmp(pcToken,"[START_VALUE_TABLE]")==0)
            {
                while(fileInput.getline(acLine,defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_VALUE_TABLE]")!=0)
                {
                    pcLine = acLine;
                    pcToken=strtok_s(pcLine, " ", &pcNextToken);

                    if(strcmp(pcToken,"[START_TABLE]")==0)
                    {
                        CValueTable vTab;
                        vTab.Format_ValueTable(pcLine + strlen(pcToken)+1,fileInput);
                        m_vTab.push_back(vTab);
                    }
                }
            }
            else if(strcmp(pcToken,"[START_PARAM]")==0)
            {
                while(fileInput.getline(acLine,defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM]")!=0)
                {
                    pcLine = acLine;
                    CParameter rParam;

                    if(strcmp(pcLine,"[START_PARAM_NET]")==0)
                    {
                        while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_NET]")!=0)
                        {
                            pcLine = acLine;
                            rParam.Format_ParamDef(pcLine,0);
                            m_listParameterArray[0].push_back(rParam);
                        }
                    }
                    else if(strcmp(pcToken,"[START_PARAM_NODE]")==0)
                    {
                        while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_NODE]")!=0)
                        {
                            pcLine = acLine;
                            rParam.Format_ParamDef(pcLine,1);
                            m_listParameterArray[1].push_back(rParam);
                        }
                    }
                    else if(strcmp(pcToken,"[START_PARAM_MSG]")==0)
                    {
                        while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_MSG]")!=0)
                        {
                            pcLine = acLine;
                            rParam.Format_ParamDef(pcLine,2);
                            m_listParameterArray[2].push_back(rParam);
                        }
                    }
                    else if(strcmp(pcToken,"[START_PARAM_SIG]")==0)
                    {
                        while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_SIG]")!=0)
                        {
                            pcLine = acLine;
                            rParam.Format_ParamDef(pcLine,3);
                            m_listParameterArray[3].push_back(rParam);
                        }
                    }
                    else if(strcmp(pcToken,"[START_PARAM_NODE_RX_SIG]")==0)
                    {
                        while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_NODE_RX_SIG]")!=0)
                        {
                            pcLine = acLine;
                            rParam.Format_ParamDef(pcLine,4);
                            m_listParameterArray[4].push_back(rParam);
                        }
                    }
                    else if(strcmp(pcToken,"[START_PARAM_NODE_TX_MSG]")==0)
                    {
                        while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_NODE_TX_MSG]")!=0)
                        {
                            pcLine = acLine;
                            rParam.Format_ParamDef(pcLine,5);
                            m_listParameterArray[5].push_back(rParam);
                        }
                    }
                }
            }
            else if(strcmp(pcToken,"[START_PARAM_VAL]")==0)
            {
                while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_PARAM_VAL]")!=0)
                {
                    pcLine = acLine;
                    CParameter tParam;

                    if(strcmp(pcLine,"[START_PARAM_NET_VAL]")==0)
                    {
                        tParam.Format_NetParam_Value(fileInput,m_listParameterArray[0]);
                    }
                    else if(strcmp(pcLine,"[START_PARAM_NODE_VAL]")==0)
                    {
                        tParam.Format_NodeParam_Value(fileInput,m_listParameterArray[1]);
                    }
                    else if(strcmp(pcLine,"[START_PARAM_MSG_VAL]")==0)
                    {
                        tParam.Format_MesgParam_Value(fileInput,m_listParameterArray[2]);
                    }
                    else if(strcmp(pcLine,"[START_PARAM_SIG_VAL]")==0)
                    {
                        tParam.Format_SigParam_Value(fileInput,m_listParameterArray[3]);
                    }
                }
            }
            else if(strcmp(pcToken,"[START_DESC]")==0)
            {
                while(fileInput.getline(acLine, defCON_MAX_LINE_LEN) && strcmp(acLine, "[END_DESC]")!=0)
                {
                    pcLine = acLine;
                    CComment tCmt;

                    if(strcmp(pcLine,"[START_DESC_NET]")==0)
                    {
                        tCmt.Format_netComment(fileInput, m_listComments[0]);
                    }
                    else if(strcmp(pcLine,"[START_DESC_NODE]")==0)
                    {
                        tCmt.Format_nodeComment(fileInput, m_listComments[1]);
                    }
                    else if(strcmp(pcLine,"[START_DESC_MSG]")==0)
                    {
                        tCmt.Format_msgComment(fileInput, m_listComments[2]);
                    }
                    else if(strcmp(pcLine,"[START_DESC_SIG]")==0)
                    {
                        tCmt.Format_sigComment(fileInput, m_listComments[3]);
                    }
                }
            }
            else if(strcmp(pcToken,"[START_NOT_PROCESSED]") == 0)
            {
                fileInput.getline(acLine,defCON_MAX_LINE_LEN);

                while(strcmp(pcToken,"[END_NOT_PROCESSED]") != 0)
                {
                    string str = acLine;
                    m_notProcessed.push_back(str);
                    fileInput.getline(acLine, defCON_MAX_LINE_LEN);
                }

                continue;
            }
            //if any other tag continue
            else
            {
                continue;
            }
        }
    }

    return ;
}