Commit 650c8164 authored by markus's avatar markus

Refactor command string execution and add return print

parent 2c4a4417
......@@ -51,11 +51,11 @@ void Control::doControl()
Control::hamlibError Control::executeCommandString(String *command_string, Communicator *communicator)
{
String substring;
String response = "";
int lastPos = -1;
int newPos = 0;
int dst = 0;
while (newPos = command_string->indexOf(";", lastPos + 1)) {
while ((newPos = command_string->indexOf(";", lastPos + 1)) != -1) {
substring = command_string->substring(lastPos + 1, newPos);
lastPos = newPos;
......@@ -68,29 +68,36 @@ Control::hamlibError Control::executeCommandString(String *command_string, Commu
// GNAAAARRR
communicator->sendMessage(String(rotor_->getAzimuth()) + ";" + String(rotor_->getElevation()) + ";");
}
else if ( substring.startsWith("setaz") ) {
if( substring.length() < 7 )
return HAMLIB_NOK;
dst = (int)substring.substring(5).toFloat();
if ( dst == 0 && substring.substring(5) != "0" )
return HAMLIB_NOK;
if ( dst < AZIM_MIN or dst > AZIM_MAX )
return HAMLIB_NOK;
rotor_->setAzimuth(dst);
}
else if ( substring.startsWith("setel") ) {
if( substring.length() < 7 )
return HAMLIB_NOK;
dst = (int)substring.substring(5).toFloat();
if ( dst == 0 && substring.substring(5) != "0" )
return HAMLIB_NOK;
if ( dst < ELEV_MIN or dst > ELEV_MAX )
return HAMLIB_NOK;
rotor_->setElevation(dst);
else {
if(executeActiveCommandSubstring(substring) == HAMLIB_OK)
response += "1";
else
response += "0";
}
}
if(response != "")
communicator->sendMessage(response);
return HAMLIB_OK;
}
Control::hamlibError Control::executeActiveCommandSubstring(String substring)
{
Motor::motorError err;
float dst = 0.0;
if (substring.startsWith("setaz") || substring.startsWith("setel")) {
if( substring.length() < 7 )
return HAMLIB_NOK;
dst = substring.substring(5).toFloat();
if ( dst == 0 && substring.substring(5) != "0" )
return HAMLIB_NOK;
if(substring.startsWith("setaz"))
err = rotor_->setAzimuth(dst);
else
err = rotor_->setElevation(dst);
if(err == Motor::ROT_VAL_OUT_OF_RANGE)
return HAMLIB_NOK;
}
return HAMLIB_OK;
}
......@@ -5,6 +5,7 @@
#include "rotor.h"
#include "serial_communicator.h"
#include "udp_communicator.h"
#include "motor.h"
class Control
{
......@@ -22,6 +23,7 @@ public:
private:
void doCommunicate();
hamlibError executeCommandString(String*, Communicator*);
hamlibError executeActiveCommandSubstring(String);
Rotor *rotor_;
Communicator *serial_communicator_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment