Commit cdf748d2 authored by markus's avatar markus

Improve command parsing

parent ad4f7e34
......@@ -6,6 +6,7 @@
///
#include "hamlib.h"
#include <string.h>
///
/// @brief Constructor
......@@ -63,15 +64,47 @@ void CHamlib::sendHamlibPacket()
CHamlib::hamlibError CHamlib::parseHamlibPacket()
{
packet_received_ = false;
if ( received_packet_ == "rotor state\n" )
{
// Answer with max rotor values
sprintf(tx_packet_, "%f/%f %f/%f", AZIM_MIN, AZIM_MAX, ELEV_MIN, ELEV_MAX);
packet_parsed_ = true;
sendHamlibPacket();
return HAMLIB_OK;
String token = strtok(received_packet_, ";");
int dst = 0;
while (token != NULL) {
if ( token == "state" )
{
// Answer with max rotor values
sprintf(tx_packet_, "%f/%f %f/%f", AZIM_MIN, AZIM_MAX, ELEV_MIN, ELEV_MAX);
packet_parsed_ = true;
sendHamlibPacket();
}
else if ( token == "get position" ) {
sprintf(tx_packet_, "%f %f", rotor_->getActualAzimuth(), rotor_->getActualElevation());
packet_parsed_ = true;
sendHamlibPacket();
}
else if ( token.startsWith("set az") ) {
if( token.length() < 8 )
return HAMLIB_NOK;
dst = token.substring(8).toInt();
if ( dst == 0 && token.substring(8) != "0" )
return HAMLIB_NOK;
if ( dst < AZIM_MIN or dst > AZIM_MAX )
return HAMLIB_NOK;
rotor_->setAzimuth(dst);
}
else if ( token.startsWith("set ev") ) {
if( token.length() < 8 )
return HAMLIB_NOK;
dst = token.substring(8).toInt();
if ( dst == 0 && token.substring(8) != "0" )
return HAMLIB_NOK;
if ( dst < ELEV_MIN or dst > ELEV_MAX )
return HAMLIB_NOK;
rotor_->setElevation(dst);
}
else
return HAMLIB_NOK;
}
return HAMLIB_NOK;
return HAMLIB_OK;
}
///
......
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