bool StreamIface::syncWriteRead(uint8_t* snd, uint8_t snd_len, uint8_t* rcv, uint8_t rcv_len){ //send the request if ( !writeNow(snd,snd_len) ){ //fails if the m_out queue isn't big enough or if the serial write fails somehow return false; } //recieve the response if ( !readNow(rcv,rcv_len) ){ //fails if the m_in queue isn't big enough return false; } return true; }
void conditionDrivenWritingFunctionObject::write() { bool doWrite=false; switch(theState_) { case stateWaiting: doWrite=checkWrite(); break; case stateWriting: switch(writeControlMode_) { case scmWriteAlways: doWrite=checkStartWriting(); break; case scmWriteNTimesteps: doWrite=(time().timeIndex()<=timestepForStateChange_); break; case scmWriteIntervall: doWrite=(time().value()<=timeForStateChange_); break; case scmWriteUntilSwitch: doWrite=!checkStopWriting(); break; default: FatalErrorIn("conditionDrivenWritingFunctionObject::write") << "Unimplemented 'writeControlMode'" << endl << exit(FatalError); } if(!doWrite) { Info << name() << ": Stopped writting. Starting cooldown" << endl; theState_=stateStartCooldown; } break; case stateCooldown: { bool stopCooldown=checkCooldown(); if(stopCooldown) { Info << name() << " cooldown ended. Writing possible" << endl; theState_=stateWaiting; doWrite=checkWrite(); } } break; case stateStartCooldown: FatalErrorIn("conditionDrivenWritingFunctionObject::write") << "State 'startCooldown' should not be reached here" << endl << exit(FatalError); default: FatalErrorIn("conditionDrivenWritingFunctionObject::write") << "Unsupported state" << endl << exit(FatalError); } if(theState_==stateStartCooldown) { theState_=stateCooldown; switch(cooldownMode_) { case cdmNoCooldown: theState_=stateWaiting; break; case cdmNTimesteps: Info << name() << ": Waiting for " << cooldownTimesteps_ << " till next output" << endl; timestepForStateChange_=time().timeIndex()+cooldownTimesteps_; break; case cdmIntervall: timeForStateChange_=time().value()+cooldownIntervall_; Info << name() << ": Waiting till " << timeForStateChange_ << " till next output" << endl; break; case cdmRetrigger: Info << name() << ": waiting until triggered for next output" << endl; break; default: FatalErrorIn("conditionDrivenWritingFunctionObject::write") << "Unsupported cooldown mode" << endl << exit(FatalError); } bool stopCooldown=checkCooldown(); if(stopCooldown) { Info << name() << " cooldown ended. Writing possible" << endl; theState_=stateWaiting; doWrite=checkWrite(); } } if(doWrite) { writeNow(); } else { // don't need to store the state if it was already written if(storeAndWritePreviousState_) { storePreviousState(); } } }