| |
libFAUDES
Sections
Index
|
simfaudes.cppGo to the documentation of this file.00001 /** @file simfaudes.cpp Simple simulator application for faudes generators 00002 00003 This tutorial demonstrates how to build a simulator application from 00004 the class faudes::ProposingExecutor. When compiled with the 00005 IO device plugin, the faudes::DeviceExecutor is used to run a 00006 hardware-in-the-loop simulation. 00007 00008 @code 00009 ~/libfaudes/plugins/simulator/tutorial> ./simfaudes -? 00010 00011 simfaudes: usage: 00012 00013 simfaudes [-q][-v][-i][-bc] [-bt <nnn>][-bs <nnn>] [-l <logfile>] [-ls] [-le] [-lt] <simfile> 00014 00015 where 00016 <simfile>: simulation configuration file or generator file 00017 00018 -q: less console output 00019 -qq: absolutely no console output 00020 -v: more console output 00021 -vv: even more console output 00022 -i: interactive mode 00023 00024 -bc: break on condition 00025 -bt <nnn>: break on time <nnn> 00026 -bs <nnn>: break on step <nnn> 00027 00028 -l <logfile>: log to <logfile> 00029 -ls: log states 00030 -le: log events 00031 -lt: log time 00032 -la: log all 00033 -t <nnn>: fifo trace buffer length <nnn> 00034 00035 -d <devfile>: use io device configured from file 00036 -dt <nnn>: tolerance in time synchronisation 00037 @endcode 00038 00039 00040 You may test the simulator with the examples provided in the data 00041 directory: 00042 00043 @code 00044 00045 ~/libfaudes/plugins/simulator/tutorial>./simfaudes -bs 5 data/gausstest.sim 00046 % simfaudes: ========================================= current state: 00047 <DiscreteState> "idle" </DiscreteState> 00048 % simfaudes: ========================================= current time: 00049 <Time> 0 </Time> 00050 % simfaudes: ========================================= proposed action: 00051 <ProposedTime> 205 </ProposedTime> 00052 <ProposedEvent> "alpha" </ProposedEvent> 00053 % simfaudes: ========================================= execute event: 00054 <ExecutedEvent> "alpha" </ExecutedEvent> 00055 % simfaudes: ========================================= current state: 00056 <DiscreteState> "busy" </DiscreteState> 00057 % simfaudes: ========================================= current time: 00058 <Time> 205 </Time> 00059 % simfaudes: ========================================= found conditions satisfied: 00060 <SatisfiedConditions> "BusyCond" </SatisfiedConditions> 00061 % simfaudes: ========================================= proposed action: 00062 <ProposedTime> 51 </ProposedTime> 00063 % simfaudes: ========================================= current state: 00064 <DiscreteState> "busy" </DiscreteState> 00065 % simfaudes: ========================================= current time: 00066 <Time> 256 </Time> 00067 % simfaudes: ========================================= found conditions satisfied: 00068 <SatisfiedConditions> "BusyCond" </SatisfiedConditions> 00069 % simfaudes: ========================================= proposed action: 00070 <ProposedTime> 39 </ProposedTime> 00071 <ProposedEvent> "beta" </ProposedEvent> 00072 % simfaudes: ========================================= execute event: 00073 <ExecutedEvent> "beta" </ExecutedEvent> 00074 % simfaudes: ========================================= current state: 00075 <DiscreteState> "idle" </DiscreteState> 00076 % simfaudes: ========================================= current time: 00077 <Time> 295 </Time> 00078 % simfaudes: ========================================= found conditions satisfied: 00079 <SatisfiedConditions> "IdleCond" </SatisfiedConditions> 00080 % simfaudes: ========================================= proposed action: 00081 <ProposedTime> 191 </ProposedTime> 00082 <ProposedEvent> "alpha" </ProposedEvent> 00083 % simfaudes: ========================================= execute event: 00084 <ExecutedEvent> "alpha" </ExecutedEvent> 00085 % simfaudes: ========================================= current state: 00086 <DiscreteState> "busy" </DiscreteState> 00087 % simfaudes: ========================================= current time: 00088 <Time> 486 </Time> 00089 % simfaudes: ========================================= found conditions satisfied: 00090 <SatisfiedConditions> "BusyCond" </SatisfiedConditions> 00091 % simfaudes: ========================================= proposed action: 00092 <ProposedTime> 51 </ProposedTime> 00093 % simfaudes: ========================================= end simulation 00094 00095 @endcode 00096 00097 The code is straight forward: after some command line parsing 00098 for behavioural configuration, it reads a proposing executor from file 00099 and loops to execute the proposed transitions. 00100 00101 00102 @ingroup Tutorials 00103 00104 @include simfaudes.cpp 00105 00106 */ 00107 00108 00109 #include "libfaudes.h" 00110 #include <signal.h> 00111 00112 using namespace faudes; 00113 00114 // fix windows/mingw definition 00115 #ifdef FAUDES_WINEXTRA 00116 #define sleep(sec) Sleep((sec) * 1000) 00117 #define usleep(usec) Sleep((usec) / 1000) 00118 #define SIGQUIT SIGBREAK 00119 #define SIGHUP SIGBREAK 00120 #define strsignal(sig) "unknown" 00121 #endif 00122 00123 00124 // global vars used in exit handler 00125 DeviceExecutor mExecutor; 00126 int mConsoleOut=0; 00127 std::string mMark="% simfaudes: ========================================= "; 00128 00129 // simulator clean-up on exit 00130 void simfaudes_exit(void); 00131 00132 // signal handler recursion flag 00133 volatile sig_atomic_t signal_in_progress = 0; 00134 00135 // signal handler to stop devices 00136 void catch_signal(int sig) { 00137 // detect recursion, pass on 00138 if(signal_in_progress) raise(sig); 00139 signal_in_progress = 1; 00140 // report 00141 std::cerr << "simfaudes: signal " << strsignal(sig) << std::endl; 00142 // call my exit function 00143 simfaudes_exit(); 00144 // re-install default handler 00145 signal(sig, SIG_DFL); 00146 // pass on signal 00147 raise(sig); 00148 } 00149 00150 00151 // clean-up on exit 00152 void simfaudes_exit(void) { 00153 #ifdef FAUDES_PLUGIN_IODEVICE 00154 // report device performance 00155 if(vDevice* dev=mExecutor.Devicep()) { 00156 dev->WritePerformance(); 00157 } 00158 // stop all devices 00159 vDevice::StopAll(); 00160 #endif 00161 // report statistics 00162 if(mConsoleOut>=-1) { 00163 std::cout << mMark << " end simulation #" << mExecutor.Size() << std::endl; 00164 for(ProposingExecutor::ConditionIterator cit=mExecutor.ConditionsBegin(); 00165 cit!=mExecutor.ConditionsEnd(); cit++) { 00166 if(!mExecutor.Condition(*cit).IsEnabled()) continue; 00167 std::cout << mMark << "statistics for simulation condition \"" << 00168 mExecutor.Conditions().SymbolicName(*cit) << "\"" << std::endl; 00169 mExecutor.Condition(*cit).mSamplesPeriod.Compile(); 00170 std::cout << mExecutor.Condition(*cit).mSamplesPeriod.Str(); 00171 mExecutor.Condition(*cit).mSamplesDuration.Compile(); 00172 std::cout << mExecutor.Condition(*cit).mSamplesDuration.Str() << std::endl; 00173 } 00174 } 00175 // close log file 00176 mExecutor.LogClose(); 00177 // reset incl device if such 00178 mExecutor.Reset(); 00179 } 00180 00181 // print usage info and exit 00182 void usage_exit(const std::string& message="") { 00183 if(message!="") { 00184 std::cout << "simfaudes: " << message << std::endl; 00185 std::cout << "" << std::endl; 00186 } 00187 std::cout << "simfaudes: version " << FDVersionString() << std::endl; 00188 std::cout << "" << std::endl; 00189 std::cout << "simfaudes: usage: " << std::endl; 00190 std::cout << " simfaudes [-q][-v][-i][-bc] [-bt <nnn>][-bs <nnn>] [-l <logfile>] [-ls] [-le] [-lt] <simfile> " << std::endl; 00191 std::cout << "where " << std::endl; 00192 std::cout << " <simfile>: simulation configuration file" << std::endl; 00193 std::cout << "" << std::endl; 00194 std::cout << " -q: less console output " << std::endl; 00195 std::cout << " -qq: absolutely no console output " << std::endl; 00196 std::cout << " -v: more console output" << std::endl; 00197 std::cout << " -vv: even more console output" << std::endl; 00198 std::cout << " -i: interactive mode " << std::endl; 00199 std::cout << "" << std::endl; 00200 std::cout << " -bc: break on condition" << std::endl; 00201 std::cout << " -bt <nnn>: break on time <nnn> " << std::endl; 00202 std::cout << " -bs <nnn>: break on step <nnn> " << std::endl; 00203 std::cout << "" << std::endl; 00204 std::cout << " -l <logfile>: log to <logfile> " << std::endl; 00205 std::cout << " -ls: log states" << std::endl; 00206 std::cout << " -le: log events" << std::endl; 00207 std::cout << " -lt: log time" << std::endl; 00208 std::cout << " -la: log all" << std::endl; 00209 std::cout << " -t <nnn>: fifo trace buffer length <nnn> " << std::endl; 00210 #ifdef FAUDES_PLUGIN_IODEVICE 00211 std::cout << "" << std::endl; 00212 std::cout << " -d <devfile>: use io device configured from file" << std::endl; 00213 std::cout << " -dt <nnn>: tolerance in time synchronisation" << std::endl; 00214 #endif 00215 std::cout << "" << std::endl; 00216 std::cout << "" << std::endl; 00217 exit(-1); 00218 } 00219 00220 // parse commandline, read executor and run executor 00221 int main(int argc, char* argv[]) 00222 { 00223 00224 00225 // install my signal handler 00226 signal(SIGTERM, catch_signal); 00227 signal(SIGINT, catch_signal); 00228 signal(SIGQUIT, catch_signal); 00229 signal(SIGHUP, catch_signal); 00230 signal(SIGABRT, catch_signal); 00231 00232 // install my exit fnct 00233 atexit(simfaudes_exit); 00234 00235 // default behaviour 00236 mConsoleOut=0; 00237 bool mInteractive=false; 00238 std::string mSimFile=""; 00239 std::string mDevFile=""; 00240 tpTime::Type mTolerance=-1; 00241 bool mBreakCondition=false; 00242 tpTime::Type mBreakTime=tpTime::Max; 00243 int mBreakStep=-1; 00244 std::string mLogFile=""; 00245 int mLogMode=0; 00246 int mTraceLength=5; 00247 00248 // primitive commad line parsing 00249 for(int i=1; i<argc; i++) { 00250 std::string option(argv[i]); 00251 // option: quiet 00252 if((option=="-q") || (option=="--quiet")) { 00253 mConsoleOut=-1; 00254 continue; 00255 } 00256 // option: more quiet 00257 if((option=="-qq") || (option=="--quietquiet")) { 00258 mConsoleOut=-2; 00259 continue; 00260 } 00261 // option: verbose 00262 if((option=="-v") || (option=="--verbose")) { 00263 mConsoleOut=1; 00264 continue; 00265 } 00266 // option: more verbose 00267 if((option=="-vv") || (option=="--verboseverbose")) { 00268 mConsoleOut=2; 00269 continue; 00270 } 00271 // option: interactive 00272 if((option=="-i") || (option=="--interactive")) { 00273 mInteractive=true; 00274 continue; 00275 } 00276 // option: io device 00277 if((option=="-d") || (option=="--device")) { 00278 i++; if(i>=argc) usage_exit(); 00279 mDevFile=argv[i]; 00280 continue; 00281 } 00282 // option: io device tolerance 00283 if((option=="-dt") || (option=="--tolerance")) { 00284 i++; if(i>=argc) usage_exit(); 00285 mTolerance=(tpTime::Type) ToIdx(argv[i]); 00286 continue; 00287 } 00288 // option: break condition 00289 if((option=="-bc") || (option=="--breakcondition")) { 00290 mBreakCondition=true; 00291 continue; 00292 } 00293 // option: break time 00294 if((option=="-bt") || (option=="--breaktime")) { 00295 i++; if(i>=argc) usage_exit(); 00296 mBreakTime=(tpTime::Type) ToIdx(argv[i]); 00297 continue; 00298 } 00299 // option: break step 00300 if((option=="-bs") || (option=="--breakstep")) { 00301 i++; if(i>=argc) usage_exit(); 00302 mBreakStep=(int) ToIdx(argv[i]); 00303 continue; 00304 } 00305 // option: log file 00306 if((option=="-l") || (option=="--logfile")) { 00307 i++; if(i>=argc) usage_exit(); 00308 mLogFile=argv[i]; 00309 continue; 00310 } 00311 // option: log states 00312 if((option=="-ls") || (option=="--logstates")) { 00313 mLogMode |= LoggingExecutor::States; 00314 continue; 00315 } 00316 // option: log events 00317 if((option=="-le") || (option=="--logevents")) { 00318 mLogMode |= LoggingExecutor::Events; 00319 continue; 00320 } 00321 // option: log time 00322 if((option=="-lt") || (option=="--logtime")) { 00323 mLogMode |= LoggingExecutor::Time; 00324 continue; 00325 } 00326 // option: log all 00327 if((option=="-la") || (option=="--logall")) { 00328 mLogMode |= 0xff; 00329 continue; 00330 } 00331 // option: trace 00332 if((option=="-t") || (option=="--trace")) { 00333 i++; if(i>=argc) usage_exit(); 00334 mTraceLength=(int) ToIdx(argv[i]); 00335 continue; 00336 } 00337 // option: help 00338 if((option=="-?") || (option=="--help")) { 00339 usage_exit(); 00340 continue; 00341 } 00342 // option: unknown 00343 if(option.c_str()[0]=='-') { 00344 usage_exit("unknown option "+ option); 00345 continue; 00346 } 00347 // filename 00348 if(mSimFile!="") 00349 usage_exit("more than one filname specified" ); 00350 mSimFile=option; 00351 } 00352 00353 // insist in filename 00354 if(mSimFile=="") 00355 usage_exit("you must specify a filename" ); 00356 00357 // dont have both, interactive and sync physics 00358 if(mDevFile!="" && mInteractive) 00359 usage_exit("you must not specify both interactive and synchrone mode"); 00360 00361 // relaxed read configuration: test for generator file 00362 bool gfile=false; 00363 TokenReader* tr = new TokenReader(mSimFile); 00364 Token token; 00365 tr->Peek(token); 00366 if(token.Type()==Token::Begin) 00367 if(token.StringValue()=="Generator") 00368 gfile=true; 00369 00370 // read congiguration 00371 if(gfile) { 00372 mExecutor.Insert(mSimFile); 00373 mExecutor.Reset(); 00374 } else { 00375 mExecutor.Read(mSimFile); 00376 mExecutor.Reset(); 00377 } 00378 00379 // report configuration 00380 if(mConsoleOut>=1) { 00381 std::cout << mMark << "dumping configuration" << std::endl; 00382 // generators 00383 for(Idx i=0; i< mExecutor.Size(); i++) { 00384 std::cout << mMark << "found generator #" << i+1 << 00385 ": " << mExecutor.At(i).Generator().Name() << std::endl; 00386 } 00387 // event attributes 00388 for(EventSet::Iterator eit=mExecutor.Alphabet().Begin(); 00389 eit!=mExecutor.Alphabet().End(); eit++) { 00390 std::cout << mMark << "found event attributes for \"" << 00391 mExecutor.EventName(*eit) << "\"" << std::endl; 00392 std::cout << mExecutor.Alphabet().Attribute(*eit).ToString() << std::endl; 00393 } 00394 // conditions 00395 for(ProposingExecutor::ConditionIterator cit=mExecutor.ConditionsBegin(); 00396 cit!=mExecutor.ConditionsEnd(); cit++) { 00397 std::cout << mMark << "found simulation condition \"" << 00398 mExecutor.Conditions().SymbolicName(*cit) << "\"" << std::endl; 00399 std::cout << mExecutor.Condition(*cit).ToString() << std::endl; 00400 } 00401 } 00402 00403 // report generators 00404 if(mConsoleOut>=2) { 00405 // generators 00406 for(Idx i=0; i< mExecutor.Size(); i++) { 00407 std::cout << mMark << "generator #" << i+1 << std::endl; 00408 mExecutor.At(i).Generator().DWrite(); 00409 } 00410 } 00411 00412 // initialze log file 00413 if(mLogFile!="") { 00414 mExecutor.LogOpen(mLogFile,mLogMode | LoggingExecutor::Statistics); 00415 } 00416 if(mLogFile=="" && mLogMode!=0) { 00417 TokenWriter* ptw= new TokenWriter(TokenWriter::Stdout); 00418 mExecutor.LogOpen(*ptw, mLogMode | LoggingExecutor::Statistics); 00419 } 00420 00421 // set trace buffer 00422 mExecutor.TraceClear(mTraceLength); 00423 00424 // ************************************************ synchronous prep 00425 if(mDevFile!="") { 00426 #ifdef FAUDES_PLUGIN_IODEVICE 00427 00428 // create device from file 00429 vDevice* dev=vDevice::FromFile(mDevFile); 00430 00431 00432 #ifdef FAUDES_IODEVICE_SIMPLENET 00433 #ifdef FAUDES_WINEXTRA 00434 // if its a net device on windows, initialise winsocks 00435 if(dynamic_cast<nDevice*>(dev)) { 00436 WSADATA wsaData; 00437 if(WSAStartup(MAKEWORD(2,2), &wsaData)!=0) { 00438 usage_exit("cannot start winsock (network error)"); 00439 } 00440 } 00441 #endif 00442 #endif 00443 00444 // report 00445 if(mConsoleOut>=0) 00446 std::cout << mMark << "Execute via IO device: \""<< dev->Name() << "\"" << std::endl; 00447 00448 // set tolerance 00449 if(mTolerance!=-1) mExecutor.ToleranceTime(mTolerance); 00450 00451 // assign device to executor ad wait for startuo to complete 00452 mExecutor.Devicep(dev); 00453 if(mBreakTime==tpTime::UnDef) mBreakTime=tpTime::Max; 00454 mExecutor.DeviceStart(); 00455 dev->Reset(); // flush buffer 00456 while(dev->Status()!=vDevice::Up) { 00457 std::cout << mMark << "Starting IO device \""<< dev->Name() << "\" Status: " << dev->StatusString() << std::endl; 00458 sleep(1); 00459 } 00460 dev->CurrentTime(0); // sync time 00461 std::cout << mMark << "IO device \""<< dev->Name() << "\" is Up" << std::endl; 00462 #else 00463 // cannot run device without plugin 00464 usage_exit("cannot load device \""+mDevFile+"\": device plugin not present"); 00465 #endif 00466 00467 } 00468 00469 00470 // ************************************************* interactive loop 00471 bool mRunning=true; 00472 bool mInterTemp=mInteractive; 00473 SimConditionSet mSatisfied; 00474 mSatisfied.Name("SatisfiedConditions"); 00475 while(mRunning) { 00476 // report current state 00477 if(mConsoleOut>=2) { 00478 std::cout << mMark << "current state:" << std::endl; 00479 std::cout << mExecutor.CurrentParallelTimedState().ToString("TimedState",&mExecutor) << std::endl; 00480 } 00481 // report current state 00482 if(mConsoleOut>=0 && mConsoleOut<2) { 00483 std::cout << mMark << "current state:" << std::endl; 00484 std::cout << mExecutor.CurrentParallelTimedState().ToString("DiscreteState",&mExecutor) << std::endl; 00485 } 00486 // report current time 00487 if(mConsoleOut>=1) { 00488 std::cout << mMark << "current time:" << std::endl; 00489 std::cout << "<Time> " << mExecutor.CurrentTime() << " </Time>" << std::endl; 00490 std::cout << "<Step> " << mExecutor.CurrentStep() << " </Step>" << std::endl; 00491 } 00492 // report current time 00493 if(mConsoleOut==0) { 00494 std::cout << mMark << "current time:" << std::endl; 00495 std::cout << "<Time> " << mExecutor.CurrentTime() << " </Time>" << std::endl; 00496 } 00497 // report satisfied conditions 00498 if(mConsoleOut>=0) { 00499 mSatisfied.Clear(); 00500 for(ProposingExecutor::ConditionIterator cit=mExecutor.ConditionsBegin(); 00501 cit!=mExecutor.ConditionsEnd(); cit++) { 00502 if(mExecutor.Condition(*cit).Satisfied()) mSatisfied.Insert(*cit); 00503 } 00504 if(mSatisfied.Size()>0) { 00505 std::cout << mMark << "found conditions satisfied:" << std::endl; 00506 std::cout << mSatisfied.ToString() << std::endl; 00507 } 00508 } 00509 // report internal state 00510 if(mConsoleOut>=2) { 00511 std::cout << mMark << "simulation event states:" << std::endl; 00512 std::cout << mExecutor.EventStatesToString() << std::endl; 00513 } 00514 // report enabled transitions 00515 if(mConsoleOut>=1) { 00516 std::cout << mMark << "enabled events:" << std::endl; 00517 std::cout << mExecutor.EnabledEvents().ToString() << std::endl; 00518 std::cout << mMark << "enabled interval:" << std::endl; 00519 std::cout << mExecutor.EnabledInterval().Str() << std::endl; 00520 std::cout << mMark << "enabled time:" << std::endl; 00521 std::cout << mExecutor.EnabledTime().Str() << std::endl; 00522 } 00523 // test break: time up 00524 if(mExecutor.CurrentTime() >= tpTime::Max) { 00525 if(mConsoleOut>=-1) std::cout << mMark << "time is up" << std::endl; 00526 mInterTemp=false; 00527 mRunning=false; 00528 break; 00529 } 00530 // test break: condition 00531 if(mExecutor.BreakCondition() && (mBreakCondition || mInteractive)) { 00532 if(mConsoleOut>=-1) std::cout << mMark << "break condition triggered" << std::endl; 00533 mInterTemp=mInteractive; 00534 mRunning=mInteractive; 00535 } 00536 // test break: time 00537 if(mBreakTime!=tpTime::UnDef) 00538 if(mExecutor.CurrentTime() >= mBreakTime) { 00539 if(mConsoleOut>=-1) std::cout << mMark << "break time reached" << std::endl; 00540 mInterTemp=mInteractive; 00541 mRunning=mInteractive; 00542 } 00543 // test break: step 00544 if(mBreakStep>=0) 00545 if(mExecutor.CurrentStep() >= mBreakStep) { 00546 if(mConsoleOut>=-1) std::cout << mMark << "break step reached" << std::endl; 00547 mInterTemp=mInteractive; 00548 mRunning=mInteractive; 00549 } 00550 // test break: synchronous device 00551 if(!mExecutor.IsSynchronous()) { 00552 if(mConsoleOut>=-1) std::cout << mMark << "device out of sync" << std::endl; 00553 mInterTemp=false; 00554 mRunning=false; 00555 break; 00556 } 00557 // proposed action 00558 TimedEvent mPropTrans=mExecutor.ProposeNextTransition(); 00559 if(mConsoleOut>=0) { 00560 std::cout << mMark << "proposed action:" << std::endl; 00561 if(mPropTrans.Time>0) 00562 std::cout << "<ProposedTime> " << ToStringInteger(mPropTrans.Time) << " </ProposedTime>" << std::endl; 00563 if(mPropTrans.Event!=0) 00564 std::cout << "<ProposedEvent> \"" << mExecutor.EventName(mPropTrans.Event) << "\" </ProposedEvent>" << std::endl; 00565 if((mPropTrans.Time<=0) && (mPropTrans.Event==0) ) 00566 std::cout << "+DeadLock+" << std::endl; 00567 } 00568 // record transition 00569 Idx mEvent=0; 00570 // ask choice 00571 while(mInterTemp) { 00572 std::cout << mMark << "enter command:" << std::endl; 00573 std::string line; 00574 std::getline(std::cin,line); 00575 // separate cmd from arg 00576 std::string choice; 00577 std::string param; 00578 std::istringstream sline(line); 00579 sline >> choice; 00580 sline >> param; 00581 // convert to int 00582 int ichoice =-1; 00583 std::istringstream schoice(choice); 00584 schoice >> ichoice; 00585 if(!schoice) ichoice=-1; 00586 int iparam =-1; 00587 std::istringstream sparam(param); 00588 sparam >> iparam; 00589 if(!sparam) iparam=-1; 00590 // convert to symbol 00591 std::string nchoice=choice; 00592 if(choice.length()>2) 00593 if(choice.at(0)=='"' && choice.at(choice.length()-1)== '"') 00594 nchoice=choice.substr(1,choice.length()-2); 00595 // switch cases 00596 bool err=false; 00597 if(choice=="x" || choice == "exit") { 00598 mRunning=false; 00599 } else 00600 if(choice=="p" || choice=="proposal" || choice=="") { 00601 mExecutor.ExecuteTime(mPropTrans.Time); 00602 if(mExecutor.ExecuteEvent(mPropTrans.Event)) 00603 mEvent=mPropTrans.Event; 00604 } else 00605 if(choice=="r" || choice=="run") { 00606 mInterTemp=false; 00607 } else 00608 if(choice=="v" || choice=="revert") { 00609 int step = mExecutor.CurrentStep()-1; 00610 if(iparam!=-1) step=iparam; 00611 std::cout << mMark << "revert to step " << step << std::endl; 00612 mExecutor.RevertToStep(step); 00613 } else 00614 if(choice=="t" || choice=="trace") { 00615 std::cout << mMark << "system trace" << std::endl; 00616 mExecutor.TraceWrite(); 00617 continue; 00618 } else 00619 if(ichoice>0) { 00620 mExecutor.ExecuteTime(ichoice); 00621 } else 00622 if(mExecutor.Alphabet().Exists(nchoice)) { 00623 if(mExecutor.ExecuteEvent(mExecutor.EventIndex(nchoice))) 00624 mEvent=mExecutor.EventIndex(nchoice); 00625 } else { 00626 std::cout << mMark << "simfaudes interactive mode" << std::endl; 00627 std::cout << "%" << std::endl; 00628 std::cout << "% execute time and/or transitions" << std::endl; 00629 std::cout << "% * <nn> to pass a specified duration <nn> (excl brackets)" << std::endl; 00630 std::cout << "% * \"event\" to execute an event (incl quotes)" << std::endl; 00631 std::cout << "% * [P] or [Ret] to execute the recent proPosal " << std::endl; 00632 std::cout << "%" << std::endl; 00633 std::cout << "% show trace and revert" << std::endl; 00634 std::cout << "% * [T] to show a Trace of recent events and states" << std::endl; 00635 std::cout << "% * [V] <nn> to reVert to step <nn> (obmit <nn> for one step backward) "<< std::endl; 00636 std::cout << "%" << std::endl; 00637 std::cout << "% other" << std::endl; 00638 std::cout << "% * [X] to eXit" << std::endl<< std::endl; 00639 err=true; 00640 } 00641 if(!err) break; 00642 } 00643 // execute proposal 00644 if(!mInterTemp && mDevFile=="") { 00645 mExecutor.ExecuteTime(mPropTrans.Time); 00646 if(mExecutor.ExecuteEvent(mPropTrans.Event)) 00647 mEvent=mPropTrans.Event; 00648 } 00649 #ifdef FAUDES_PLUGIN_IODEVICE 00650 // sync step 00651 if(mDevFile!="") { 00652 if(mConsoleOut>=0 && mPropTrans.Time>0) 00653 std::cout << mMark << "sync wait" << std::endl; 00654 mEvent=mExecutor.SyncStep(); 00655 mExecutor.SyncTime(); 00656 } 00657 #endif 00658 // report event 00659 if(mConsoleOut>=0 && mEvent!=0) { 00660 std::cout << mMark << "execute event:" << std::endl; 00661 std::cout << "<ExecutedEvent> \"" << mExecutor.EventName(mEvent) << "\" </ExecutedEvent>" 00662 << std::endl; 00663 } 00664 00665 } // loop: while mRunning 00666 00667 return 0; 00668 } |
libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6