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
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
extern "C" char *sbrk(int i);
double checkFreeMemory() {
char stack_dummy = 0;
return static_cast<double>(&stack_dummy - sbrk(0));
}
bool Communicator::communicate(){
if(!serialCharAvailable_()){ //no communication
if(msElapsedSinceLastTransaction_() > interval_assume_eow_ms_){
......@@ -55,18 +62,15 @@ bool Communicator::communicate(){
}
if(PTimer::elapsed() >= timeout_us_){
handleTimeout_(); //timeout
flushSerialBuffer_();
return false;
}
else if(i >= arg_.size()-10){
handleInputOverflow_(); //input overflow
flushSerialBuffer_();
return false;
}
//apply the setting
else{
handleSetCommand_();
flushSerialBuffer_();
return true;
}
}
......@@ -74,15 +78,15 @@ bool Communicator::communicate(){
if(cmd_ == 't'){ //getTemperature
snprintf( outbuf_,
255,
"%f,%f,%f,%f,%f;",
"%f,%f,%f,%f,%f,%f;",
Temperatures::temperatures[0],
Temperatures::temperatures[1],
Temperatures::temperatures[2],
Temperatures::temperatures[3],
Temperatures::temperatures[4]
Temperatures::temperatures[4],
Communicator::arg_.capacity()
);
sendBuf_();
flushSerialBuffer_();
return true;
}
else if(cmd_ == 'p'){ //getPidCoeff
......@@ -95,7 +99,6 @@ bool Communicator::communicate(){
kpids[2]
);
sendBuf_();
flushSerialBuffer_();
return true;
}
else if(cmd_ == 'v'){ //getPropIntDer
......@@ -108,35 +111,29 @@ bool Communicator::communicate(){
pids[2]
);
sendBuf_();
flushSerialBuffer_();
return true;
}
else if(cmd_ == 'o'){ //getOutput
snprintf(outbuf_, 255, "%f;", Pid_controller::get_output());
sendBuf_();
flushSerialBuffer_();
return true;
}
else if(cmd_ == 's'){ //getSetpoint
snprintf(outbuf_, 255, "%f;", Pid_controller::get_setpoint());
sendBuf_();
flushSerialBuffer_();
return true;
}
else{ //invalid command
handleInvalidCommand_();
flushSerialBuffer_();
return false;
}
}
else if(isNopCommand_()){
handleNopCommand_();
flushSerialBuffer_();
return true;
}
else{ //invalid command
handleInvalidCommand_();
flushSerialBuffer_();
return false;
}
}
......@@ -179,6 +176,7 @@ char Communicator::getSerialChar_(){
void Communicator::sendBuf_(){
SERCHAN.write(outbuf_);
SERCHAN.flush();
}
void Communicator::handleTimeout_(){
......@@ -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