From 99ceab03ebbe96eecc273a336ff5846e4170f461 Mon Sep 17 00:00:00 2001 From: Le Van Truong <le.truong@telecom-paris.fr> Date: Thu, 19 Dec 2019 14:16:15 +0100 Subject: [PATCH] modify write signal to channel --- .../c++2/src_simulator/sim/SimComponents.cpp | 10 ++- .../c++2/src_simulator/sim/SimComponents.h | 2 +- .../c++2/src_simulator/sim/Simulator.cpp | 85 ++++++++++--------- simulators/c++2/src_simulator/sim/Simulator.h | 1 - 4 files changed, 56 insertions(+), 42 deletions(-) diff --git a/simulators/c++2/src_simulator/sim/SimComponents.cpp b/simulators/c++2/src_simulator/sim/SimComponents.cpp index 899234d2bb..948b32b0af 100644 --- a/simulators/c++2/src_simulator/sim/SimComponents.cpp +++ b/simulators/c++2/src_simulator/sim/SimComponents.cpp @@ -342,11 +342,17 @@ TMLChannel* SimComponents::getChannelByID(ID iID) const{ return NULL; } -void SimComponents::getChannelList(){ +std::string SimComponents::getChannelList(std::string channelName){ for(ChannelList::const_iterator i=_channelList.begin(); i != _channelList.end(); ++i){ + std::string temp = (*i)->toShortString(); std::cout << "Channel ID " << (*i)->getID() << std::endl; - std::cout << "Channel name " << (*i)->toShortString() << std::endl; + std::cout << "Channel name " << temp << std::endl; + std::string::size_type position=temp.find(channelName); + if(position!=std::string::npos){ + return temp; + } } + return "00"; } /*TMLChoiceCommand* SimComponents::getCurrentChoiceCmd(){ diff --git a/simulators/c++2/src_simulator/sim/SimComponents.h b/simulators/c++2/src_simulator/sim/SimComponents.h index 628a81803d..24f14d5596 100644 --- a/simulators/c++2/src_simulator/sim/SimComponents.h +++ b/simulators/c++2/src_simulator/sim/SimComponents.h @@ -316,7 +316,7 @@ public: ListenerSubject<GeneralListener>* getListenerByID(ID iID); virtual void generateTEPEs()=0; void showTaskStates(); - void getChannelList(); + std::string getChannelList(std::string channelName); bool couldCPUBeIdle(CPU* iCPU); bool couldFPGABeIdle(FPGA* iFPGA); protected: diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index 6d7330ae3c..9468380717 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -1119,16 +1119,23 @@ std::vector<std::string> readFromFile(std::string& filename){ inFile.close(); return parameters; } -void Simulator::addSignalToTask(){ - _simComp->getChannelList(); -} + template < typename T > std::string to_string( const T& n ) { std::ostringstream stm ; stm << n ; return stm.str() ; } +int countLineNumber(std::string& filename){ + int number_of_lines = 0; + std::string line; + std::ifstream myfile(filename.c_str()); + while (std::getline(myfile, line)) + ++number_of_lines; + std::cout << "Number of lines in text file: " << number_of_lines << std::endl; + return number_of_lines; +} ServerIF* Simulator::run(int iLen, char ** iArgs){ std::string aArgString; std::string graphName = ""; @@ -1157,46 +1164,48 @@ ServerIF* Simulator::run(int iLen, char ** iArgs){ _replyToServer = false; aArgString=getArgs("-signals", "signals.txt", iLen, iArgs); if (!aArgString.empty()) { - addSignalToTask(); - std::ifstream inFile1(aArgString.c_str()); - int lineNumber = std::count(std::istreambuf_iterator<char>(inFile1), std::istreambuf_iterator<char>(), '\n'); + int lineNumber = countLineNumber(aArgString); std::vector<std::string> parameters = readFromFile(aArgString); std::string aNewCmd; int previousTransTime = 0; - for (int i = 0; i < lineNumber; i++){ - - std::string channelName = "Application__" + parameters[i*4+1] + "__Application__" + parameters[i*4+1]; - TMLChannel* t = _simComp->getChannelByName(channelName); - int timeToRun; - std::istringstream (parameters[i*4]) >> timeToRun; - timeToRun = timeToRun - previousTransTime; - std::istringstream (parameters[i*4]) >> previousTransTime; - if(t != 0){ - aNewCmd += "1 6 " + to_string(timeToRun) + "; 6 " + to_string(t->getID()) + " 1 " + parameters[i*4+3]; + if(lineNumber != 0){ + for (int i = 0; i < lineNumber; i++){ + std::string channelName =_simComp->getChannelList(parameters[i*4+1]); + TMLChannel* t = _simComp->getChannelByName(channelName); + if(t != 0){ + aNewCmd += "1 5 " + parameters[i*4] + "; 6 " + to_string(t->getID()) + " 1 " + parameters[i*4+3] + "; "; + } + else { + std::cout << "Error: Wrong channel name\n"; + previousTransTime++; + } } - else { - std::cout << "Error: Wrong channel name"; + if(previousTransTime != lineNumber){ + aNewCmd += "1 0; 7 1 test.html; 1 7 100 100 test"; + } else { + aNewCmd = "1 0; 7 1 test.html; 1 7 100 100 test"; + } + + std::cout<<"DecodeCommand "<< aNewCmd << std::endl; + std::ofstream aXmlOutFile1; + std::string aXmlFileName1 = getArgs("-oxml", "reply.xml", iLen, iArgs); + if (aXmlFileName1.empty()) aXmlOutFile1.open("/dev/null"); else aXmlOutFile1.open(aXmlFileName1.c_str()); + if (aXmlOutFile1.is_open()){ + std::string aNextCmd1; + std::istringstream iss1(aNewCmd+";"); + getline(iss1, aNextCmd1, ';'); + while (!(iss1.eof() || aNextCmd1.empty())){ + std::cout << "next cmd to execute: \"" << aNextCmd1 << "\"\n"; + decodeCommand(aNextCmd1, aXmlOutFile1); + getline(iss1, aNextCmd1, ';'); + } + aXmlOutFile1.close(); + } else{ + std::cout << "XML output file could not be opened, aborting.\n"; } - if(i + 1 != lineNumber) aNewCmd += ";"; - - } - aNewCmd += ";1 0; 7 1 test.html; 1 7 100 100 test"; - std::cout<<"DecodeCommand "<< aNewCmd << std::endl; - std::ofstream aXmlOutFile1; - std::string aXmlFileName1 = getArgs("-oxml", "reply.xml", iLen, iArgs); - if (aXmlFileName1.empty()) aXmlOutFile1.open("/dev/null"); else aXmlOutFile1.open(aXmlFileName1.c_str()); - if (aXmlOutFile1.is_open()){ - std::string aNextCmd1; - std::istringstream iss1(aNewCmd+";"); - getline(iss1, aNextCmd1, ';'); - while (!(iss1.eof() || aNextCmd1.empty())){ - std::cout << "next cmd to execute: \"" << aNextCmd1 << "\"\n"; - decodeCommand(aNextCmd1, aXmlOutFile1); - getline(iss1, aNextCmd1, ';'); - } - aXmlOutFile1.close(); - }else - std::cout << "XML output file could not be opened, aborting.\n"; + } else { + std::cout << "Signal file contains nothing, aborting.\n"; + } } aArgString =getArgs("-help", "help", iLen, iArgs); if (aArgString.empty()){ diff --git a/simulators/c++2/src_simulator/sim/Simulator.h b/simulators/c++2/src_simulator/sim/Simulator.h index 10d1a348d0..a105075607 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.h +++ b/simulators/c++2/src_simulator/sim/Simulator.h @@ -265,7 +265,6 @@ public: /** \param iTraceFileName Name of the output trace file */ - void addSignalToTask(); void schedule2TXT(std::string& iTraceFileName) const; void schedule2XML(std::ostringstream& glob,std::string& iTraceFileName) const; -- GitLab