Skip to content
Snippets Groups Projects
Commit c61a23e9 authored by Sebastian Huber's avatar Sebastian Huber :wrench:
Browse files

Changed flushing and send size of different vector for logging

parent c7521171
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,13 @@ std::vector<char> Communicator::arg_ = std::vector<char>(256, '\0'); //arguments ...@@ -22,6 +22,13 @@ std::vector<char> Communicator::arg_ = std::vector<char>(256, '\0'); //arguments
unsigned long Communicator::last_transaction_ms_ = 0u; //time of last transaction unsigned long Communicator::last_transaction_ms_ = 0u; //time of last transaction
unsigned long Communicator::interval_assume_eow_ms_ = 1800000u; //no transaction for 30 minutes means we shut down unsigned long Communicator::interval_assume_eow_ms_ = 1800000u; //no transaction for 30 minutes means we shut down
extern "C" char *sbrk(int i);
double checkFreeMemory() {
char stack_dummy = 0;
return static_cast<double>(&stack_dummy - sbrk(0));
}
bool Communicator::communicate(){ bool Communicator::communicate(){
if(!serialCharAvailable_()){ //no communication if(!serialCharAvailable_()){ //no communication
if(msElapsedSinceLastTransaction_() > interval_assume_eow_ms_){ if(msElapsedSinceLastTransaction_() > interval_assume_eow_ms_){
...@@ -55,18 +62,15 @@ bool Communicator::communicate(){ ...@@ -55,18 +62,15 @@ bool Communicator::communicate(){
} }
if(PTimer::elapsed() >= timeout_us_){ if(PTimer::elapsed() >= timeout_us_){
handleTimeout_(); //timeout handleTimeout_(); //timeout
flushSerialBuffer_();
return false; return false;
} }
else if(i >= arg_.size()-10){ else if(i >= arg_.size()-10){
handleInputOverflow_(); //input overflow handleInputOverflow_(); //input overflow
flushSerialBuffer_();
return false; return false;
} }
//apply the setting //apply the setting
else{ else{
handleSetCommand_(); handleSetCommand_();
flushSerialBuffer_();
return true; return true;
} }
} }
...@@ -74,15 +78,15 @@ bool Communicator::communicate(){ ...@@ -74,15 +78,15 @@ bool Communicator::communicate(){
if(cmd_ == 't'){ //getTemperature if(cmd_ == 't'){ //getTemperature
snprintf( outbuf_, snprintf( outbuf_,
255, 255,
"%f,%f,%f,%f,%f;", "%f,%f,%f,%f,%f,%f;",
Temperatures::temperatures[0], Temperatures::temperatures[0],
Temperatures::temperatures[1], Temperatures::temperatures[1],
Temperatures::temperatures[2], Temperatures::temperatures[2],
Temperatures::temperatures[3], Temperatures::temperatures[3],
Temperatures::temperatures[4] Temperatures::temperatures[4],
Communicator::arg_.capacity()
); );
sendBuf_(); sendBuf_();
flushSerialBuffer_();
return true; return true;
} }
else if(cmd_ == 'p'){ //getPidCoeff else if(cmd_ == 'p'){ //getPidCoeff
...@@ -95,7 +99,6 @@ bool Communicator::communicate(){ ...@@ -95,7 +99,6 @@ bool Communicator::communicate(){
kpids[2] kpids[2]
); );
sendBuf_(); sendBuf_();
flushSerialBuffer_();
return true; return true;
} }
else if(cmd_ == 'v'){ //getPropIntDer else if(cmd_ == 'v'){ //getPropIntDer
...@@ -108,35 +111,29 @@ bool Communicator::communicate(){ ...@@ -108,35 +111,29 @@ bool Communicator::communicate(){
pids[2] pids[2]
); );
sendBuf_(); sendBuf_();
flushSerialBuffer_();
return true; return true;
} }
else if(cmd_ == 'o'){ //getOutput else if(cmd_ == 'o'){ //getOutput
snprintf(outbuf_, 255, "%f;", Pid_controller::get_output()); snprintf(outbuf_, 255, "%f;", Pid_controller::get_output());
sendBuf_(); sendBuf_();
flushSerialBuffer_();
return true; return true;
} }
else if(cmd_ == 's'){ //getSetpoint else if(cmd_ == 's'){ //getSetpoint
snprintf(outbuf_, 255, "%f;", Pid_controller::get_setpoint()); snprintf(outbuf_, 255, "%f;", Pid_controller::get_setpoint());
sendBuf_(); sendBuf_();
flushSerialBuffer_();
return true; return true;
} }
else{ //invalid command else{ //invalid command
handleInvalidCommand_(); handleInvalidCommand_();
flushSerialBuffer_();
return false; return false;
} }
} }
else if(isNopCommand_()){ else if(isNopCommand_()){
handleNopCommand_(); handleNopCommand_();
flushSerialBuffer_();
return true; return true;
} }
else{ //invalid command else{ //invalid command
handleInvalidCommand_(); handleInvalidCommand_();
flushSerialBuffer_();
return false; return false;
} }
} }
...@@ -179,6 +176,7 @@ char Communicator::getSerialChar_(){ ...@@ -179,6 +176,7 @@ char Communicator::getSerialChar_(){
void Communicator::sendBuf_(){ void Communicator::sendBuf_(){
SERCHAN.write(outbuf_); SERCHAN.write(outbuf_);
SERCHAN.flush();
} }
void Communicator::handleTimeout_(){ void Communicator::handleTimeout_(){
...@@ -257,8 +255,3 @@ unsigned long Communicator::msElapsedSinceLastTransaction_(){ ...@@ -257,8 +255,3 @@ unsigned long Communicator::msElapsedSinceLastTransaction_(){
} }
void Communicator::flushSerialBuffer_(){
while (SERCHAN.available()) {
SERCHAN.read(); // Dump any remaining data
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment