/** * \brief writes the signals in the given list to the output file * \param[in] fileOutput Pointer to the Output file * \param[in] m_listSignals List of Signals * \param[in] m_ucLength Message length * \param[in] m_cDataFormat If 1 dataformat Intel, 0- Motorola * \param[in] writeErr If true write error signals also else write onlt correct signals * * Writes the signals in the given list to the output file. */ bool CSignal::WriteSignaltofile(CStdioFile &fileOutput,CList<CSignal,CSignal&> &m_listSignals,int m_ucLength,int m_cDataFormat,bool writeErr) { bool bResult = true; char acLine[defCON_MAX_LINE_LEN]; POSITION posSig = m_listSignals.GetHeadPosition(); while(posSig != NULL) { // SIG_NAME,SIG_LENGTH,WHICH_BYTE_IN_MSG,START_BIT,SIG_TYPE,MAX_VAL,MIN_VAL,SIG_DATA_FORMAT,SIG_OFFSET,SIG_FACTOR,SIG_UNIT CSignal& sig = m_listSignals.GetNext(posSig); // write signal only if it is valid if(sig.m_uiError == CSignal::SIG_EC_NO_ERR || sig.m_uiError == CSignal::SIG_EC_OVERFLOW || writeErr) { // For signal having motoroal format, the message length could be less // then eight byte. so in that case the whichByte needs to be shifted // accordingly. switch(sig.m_ucType) { case CSignal::SIG_TYPE_BOOL: case CSignal::SIG_TYPE_UINT: sprintf(acLine,"%s %s,%u,%u,%u,%c,%u,%u,%c,%f,%f,%s,%s,%s\n",T_SIG, sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,sig.m_ucType, sig.m_MaxValue.uiValue,sig.m_MinValue.uiValue,sig.m_ucDataFormat, sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit,sig.m_acMultiplex,sig.m_rxNode); break; case CSignal::SIG_TYPE_INT: sprintf(acLine,"%s %s,%u,%u,%u,%c,%d,%d,%c,%f,%f,%s,%s,%s\n",T_SIG, sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,sig.m_ucType, sig.m_MaxValue.iValue,sig.m_MinValue.iValue,sig.m_ucDataFormat, sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit,sig.m_acMultiplex,sig.m_rxNode); break; case CSignal::SIG_TYPE_FLOAT: sprintf(acLine,"%s %s,%u,%u,%u,%c,%f,%f,%c,%f,%f,%s,%s,%s\n",T_SIG, sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,sig.m_ucType, sig.m_MaxValue.fValue,sig.m_MinValue.fValue,sig.m_ucDataFormat, sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit,sig.m_acMultiplex,sig.m_rxNode); break; case CSignal::SIG_TYPE_DOUBLE: sprintf(acLine,"%s %s,%u,%u,%u,%c,%f,%f,%c,%f,%f,%s,%s,%s\n",T_SIG, sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,sig.m_ucType, sig.m_MaxValue.dValue,sig.m_MinValue.dValue,sig.m_ucDataFormat, sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit,sig.m_acMultiplex,sig.m_rxNode); break; case CSignal::SIG_TYPE_INT64: sprintf(acLine,"%s %s,%u,%u,%u,%c,%I64d,%I64d,%c,%f,%f,%s,%s,%s\n",T_SIG, sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,/*sig.m_ucType*/'I', sig.m_MaxValue.i64Value,sig.m_MinValue.i64Value,sig.m_ucDataFormat, sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit,sig.m_acMultiplex,sig.m_rxNode); break; case CSignal::SIG_TYPE_UINT64: sprintf(acLine,"%s %s,%u,%u,%u,%c,%I64u,%I64u,%c,%f,%f,%s,%s,%s\n",T_SIG, sig.m_acName,sig.m_ucLength,sig.m_ucWhichByte,sig.m_ucStartBit,/*sig.m_ucType*/'U', sig.m_MaxValue.ui64Value,sig.m_MinValue.ui64Value,sig.m_ucDataFormat, sig.m_fOffset,sig.m_fScaleFactor,sig.m_acUnit,sig.m_acMultiplex,sig.m_rxNode); break; default: break; } fileOutput.WriteString(acLine); CValueDescriptor val; val.writeValuDescToFile (fileOutput,sig.m_ucType,sig.m_listValueDescriptor); if(sig.m_uiError == CSignal::SIG_EC_OVERFLOW ) bResult = false; } else bResult = false; } return bResult; }
/** * \brief Write to Output File * \param[in] fileOutput Output file * \return Status code * * Writes all the data to the output file in CANoe format */ bool CConverter::WriteToOutputFile(fstream& fileOutput) { bool bResult = true; // write to the output file // write header fileOutput << _("VERSION \"\"") << endl; fileOutput << endl; fileOutput << endl; fileOutput << "BS_:" << endl; fileOutput << endl; fileOutput << "BU_:"; //write all nodes list<string>::iterator node; for(node = m_listNode.begin(); node != m_listNode.end(); ++node) { fileOutput << " " << node->c_str(); } fileOutput << endl; fileOutput << endl; //Value Table CValueTable temp_vtab; temp_vtab.writeValueTabToFile(fileOutput, m_vTab); fileOutput << endl; //write messages list<CMessage>::iterator msg; for(msg=m_listMessages.begin(); msg!=m_listMessages.end(); ++msg) { bResult &= msg->writeMessageToFile(fileOutput); } //write environment variables if any list<string>::iterator str; for(str=m_notProcessed.begin(); str!=m_notProcessed.end(); ++str) { if(strcmp(str->substr(0, 3).c_str(), "EV_") == 0) { fileOutput << str->c_str() << endl; } } //Comments ----- Net list<CComment>::iterator cmt; for(cmt=m_listComments[0].begin(); cmt!=m_listComments[0].end(); ++cmt) { fileOutput << "CM_ " << cmt->m_elementName.c_str(); fileOutput << " " << cmt->m_comment.c_str()<<endl; } //Comments ----- Node for (cmt=m_listComments[1].begin(); cmt!=m_listComments[1].end(); ++cmt) { fileOutput << "CM_ BU_ " << cmt->m_elementName.c_str(); fileOutput << " " << cmt->m_comment.c_str()<<endl; } //Comments ----- Mesg for (cmt=m_listComments[2].begin(); cmt!=m_listComments[2].end(); ++cmt) { fileOutput << "CM_ BO_ " << dec << cmt->m_msgID; fileOutput << " " << cmt->m_comment.c_str()<<endl; } //Comments ----- Signal for (cmt=m_listComments[3].begin(); cmt!=m_listComments[3].end(); ++cmt) { fileOutput << "CM_ SG_ " << dec << cmt->m_msgID; fileOutput << " " << cmt->m_elementName.c_str(); fileOutput << " " << cmt->m_comment.c_str()<<endl; } //Param definition WriteParamToFile(fileOutput, m_listParameterArray[0]); WriteParamToFile(fileOutput, m_listParameterArray[1]); WriteParamToFile(fileOutput, m_listParameterArray[2]); WriteParamToFile(fileOutput, m_listParameterArray[3]); WriteParamToFile(fileOutput, m_listParameterArray[4]); WriteParamToFile(fileOutput, m_listParameterArray[5]); //Param Default values Write_DefVal_ToFile(fileOutput, m_listParameterArray[0]); Write_DefVal_ToFile(fileOutput, m_listParameterArray[1]); Write_DefVal_ToFile(fileOutput, m_listParameterArray[2]); Write_DefVal_ToFile(fileOutput, m_listParameterArray[3]); //Param Other values 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); } } 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); } } 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); } } 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) { list<CMessage>::iterator msg; for(msg=m_listMessages.begin(); msg!=m_listMessages.end(); ++msg) { if(msg->m_uiMsgID == vParam->m_MsgId) { list<CSignal>::iterator sig; for(sig=msg->m_listSignals.begin(); sig!=msg->m_listSignals.end(); ++sig) { if((sig->m_sName == vParam->m_SignalName) && (sig->m_uiError == CSignal::SIG_EC_NO_ERR)) { vParam->WriteSigValuesToFile(fileOutput, rParam->m_ParamType, rParam->m_ParamName); break; } } } } } } fileOutput << endl; fileOutput << endl; //BA_ for(str = m_notProcessed.begin(); str != m_notProcessed.end(); ++str) { if(strcmp(str->substr(0, 3).c_str(), "BA_") == 0) { fileOutput << str->c_str() << endl; } } //VAL_ for(msg=m_listMessages.begin(); msg!=m_listMessages.end(); ++msg) { list<CSignal>::iterator sig; for(sig=msg->m_listSignals.begin(); sig!=msg->m_listSignals.end(); ++sig) { if(sig->m_listValueDescriptor.empty() == 0 && sig->m_uiError == CSignal::SIG_EC_NO_ERR) { fileOutput << " VAL_ " << dec << msg->m_uiMsgID; fileOutput << " " << sig->m_sName.c_str(); fileOutput << " "; CValueDescriptor temp; temp.writeValueDescToFile(fileOutput, sig->m_ucType, sig->m_listValueDescriptor); } } } //write SIG_VALTYPE_ for(msg=m_listMessages.begin(); msg!=m_listMessages.end(); ++msg) { list<CSignal>::iterator sig; for(sig=msg->m_listSignals.begin(); sig!=msg->m_listSignals.end(); ++sig) { if(sig->m_ucType == 'F') { fileOutput << "SIG_VALTYPE_ " << dec << msg->m_uiMsgID; fileOutput << " " << sig->m_sName.c_str(); fileOutput << " : 1;" << endl; } else if(sig->m_ucType == 'D') { fileOutput << "SIG_VALTYPE_ " << dec << msg->m_uiMsgID; fileOutput << " " << sig->m_sName.c_str(); fileOutput << " : 2;" << endl; } } } fileOutput << endl; return bResult; }
/** * \brief writes the signals in the given list to the output file * \param[in] fileOutput Pointer to the Output file * \param[in] m_listSignals List of Signals * \param[in] m_ucLength Message length * \param[in] m_cDataFormat If 1 dataformat Intel, 0- Motorola * \param[in] writeErr If true write error signals also else write onlt correct signals * \return Status code * * Writes the signals in the given list to the output file. */ bool CSignal::WriteSignaltofile(fstream& fileOutput, list<CSignal> &m_listSignals, int m_ucLength, int m_cDataFormat, bool writeErr) { bool bResult = true; list<CSignal>::iterator sig; for (sig=m_listSignals.begin(); sig!=m_listSignals.end(); ++sig) { // SIG_NAME,SIG_LENGTH,WHICH_BYTE_IN_MSG,START_BIT,SIG_TYPE,MAX_VAL,MIN_VAL,SIG_DATA_FORMAT,SIG_OFFSET,SIG_FACTOR,SIG_UNIT // write signal only if it is valid if((sig->m_uiError == CSignal::SIG_EC_NO_ERR) || (sig->m_uiError == CSignal::SIG_EC_OVERFLOW) || writeErr) { // For signal having motoroal format, the message length could be less // then eight byte. so in that case the whichByte needs to be shifted // accordingly. fileOutput << T_SIG << " " << sig->m_acName.c_str(); fileOutput << "," << dec << sig->m_ucLength; fileOutput << "," << dec << sig->m_ucWhichByte; fileOutput << "," << dec << sig->m_ucStartBit; switch(sig->m_ucType) { case CSignal::SIG_TYPE_BOOL: case CSignal::SIG_TYPE_UINT: fileOutput << "," << sig->m_ucType; fileOutput << "," << dec << sig->m_MaxValue.uiValue; fileOutput << "," << dec << sig->m_MinValue.uiValue; break; case CSignal::SIG_TYPE_INT: fileOutput << "," << sig->m_ucType; fileOutput << "," << dec << sig->m_MaxValue.iValue; fileOutput << "," << dec << sig->m_MinValue.iValue; break; case CSignal::SIG_TYPE_FLOAT: fileOutput << "," << sig->m_ucType; fileOutput << "," << sig->m_MaxValue.fValue; fileOutput << "," << sig->m_MinValue.fValue; break; case CSignal::SIG_TYPE_DOUBLE: fileOutput << "," << sig->m_ucType; fileOutput << "," << sig->m_MaxValue.dValue; fileOutput << "," << sig->m_MinValue.dValue; break; case CSignal::SIG_TYPE_INT64: fileOutput << ",I"; fileOutput << "," << dec << sig->m_MaxValue.i64Value; fileOutput << "," << dec << sig->m_MinValue.i64Value; break; case CSignal::SIG_TYPE_UINT64: fileOutput << ",U"; fileOutput << "," << dec << sig->m_MaxValue.ui64Value; fileOutput << "," << dec << sig->m_MinValue.ui64Value; break; default: break; } fileOutput << "," << sig->m_ucDataFormat; fileOutput << "," << sig->m_fOffset; fileOutput << "," << sig->m_fScaleFactor; fileOutput << "," << sig->m_acUnit.c_str(); fileOutput << "," << sig->m_acMultiplex.c_str(); fileOutput << "," << sig->m_rxNode.c_str() << endl; CValueDescriptor val; val.writeValueDescToFile(fileOutput, sig->m_ucType, sig->m_listValueDescriptor); if(sig->m_uiError == CSignal::SIG_EC_OVERFLOW) { bResult = false; } } else { bResult = false; } } return bResult; }
/** * \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 ; }