126 lines
5.6 KiB
C++
126 lines
5.6 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <optional>
|
|
#include <string_view>
|
|
|
|
namespace BM700
|
|
{
|
|
|
|
/* CONTROL PROTOCOL DEFINITIONS */
|
|
|
|
// command: cmd-name[=arg1[,arg2[,...]]\n
|
|
static constexpr std::string_view CONTROL_PROTO_STOP_SEQ = "\n";
|
|
static constexpr std::string_view CONTROL_PROTO_COMM_ARG_DELIM_SEQ = "=";
|
|
static constexpr std::string_view CONTROL_PROTO_ARG_DELIM_SEQ = ",";
|
|
|
|
|
|
/* CONTROL PROTOCOL SERVER RESPONDS */
|
|
|
|
static constexpr std::string_view CONTROL_PROTO_STR_RESP_ACK = "ACK";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_RESP_INVALID_COMM = "INVDCOMM"; // invalid command
|
|
static constexpr std::string_view CONTROL_PROTO_STR_RESP_INVALID_PARS = "INVDPARS"; // invalid command parameters
|
|
|
|
/* CONTROL PROTOCOL COMMANDS */
|
|
|
|
// coordinates getter/setter
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_AZ = "tagAZ";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_ALT = "tagALT";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_AZALT = "tagAZALT";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_RA = "tagRA";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_DEC = "tagDEC";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_RADEC = "tagRADEC";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TEL_RA = "telRA";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TEL_DEC = "telDEC";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TEL_RADEC = "telRADEC";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TEL_HA = "telHA";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TEL_HADEC = "telHADEC";
|
|
|
|
// time/date
|
|
static constexpr std::string_view CONTROL_PROTO_STR_UTC_DATE = "utcDate";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_LOC_DATE = "locDate";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_UTC_TIME = "utcTime";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_LOC_TIME = "locTime";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_UTC_DT = "utcDT"; // full date-time
|
|
static constexpr std::string_view CONTROL_PROTO_STR_LOC_DT = "locDT"; // full date-time
|
|
static constexpr std::string_view CONTROL_PROTO_STR_JDN = "julDN"; // Julian day number
|
|
|
|
// target limits
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_MINALT = "tagMINALT";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TAG_MAXALT = "tagMAXALT";
|
|
|
|
// moving
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SLEW_AZALT = "slewAZALT"; // slew and stop
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SLEW_RADEC = "slewRADEC"; // slew and track
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SLEW_XVEL = "slewXVEL"; // velocity along Az/RA
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SLEW_YVEL = "slewYVEL"; // velocity along ALT/DEC
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TRACK_XVEL = "trackXVEL";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_TRACK_YVEL = "trackYVEL";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_STOP = "stop";
|
|
|
|
// site coordinates
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SITE_LON = "siteLON";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SITE_LAT = "siteLAT";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_SITE_ELEV = "siteELEV";
|
|
|
|
// meteo
|
|
static constexpr std::string_view CONTROL_PROTO_STR_METEO_TEMP = "atmTEMP";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_METEO_PRES = "atmPRES";
|
|
static constexpr std::string_view CONTROL_PROTO_STR_METEO_HUM = "atmHUM";
|
|
|
|
// PCS
|
|
|
|
// network setup:
|
|
// format: netCONF=<iface>:<IP-addr>/<net-mask>,<gateway>,<broadcast>
|
|
// netCONF=eth0:192.168.1.10/24,192.168.1.1,192.168.1.255
|
|
static constexpr std::string_view CONTROL_PROTO_STR_NET_CONF = "netCONF";
|
|
|
|
static constexpr std::array CONTROL_PROTO_VALID_COMMAND = {
|
|
CONTROL_PROTO_STR_TAG_AZ, CONTROL_PROTO_STR_TAG_ALT, CONTROL_PROTO_STR_TAG_AZALT,
|
|
CONTROL_PROTO_STR_TAG_RA, CONTROL_PROTO_STR_TAG_DEC, CONTROL_PROTO_STR_TAG_RADEC,
|
|
CONTROL_PROTO_STR_TEL_RA, CONTROL_PROTO_STR_TEL_DEC, CONTROL_PROTO_STR_TEL_RADEC,
|
|
CONTROL_PROTO_STR_UTC_DATE, CONTROL_PROTO_STR_LOC_DATE, CONTROL_PROTO_STR_UTC_TIME,
|
|
CONTROL_PROTO_STR_LOC_TIME, CONTROL_PROTO_STR_UTC_DT, CONTROL_PROTO_STR_LOC_DT,
|
|
CONTROL_PROTO_STR_JDN, CONTROL_PROTO_STR_TAG_MINALT, CONTROL_PROTO_STR_TAG_MAXALT,
|
|
CONTROL_PROTO_STR_SLEW_AZALT, CONTROL_PROTO_STR_SLEW_RADEC, CONTROL_PROTO_STR_SLEW_XVEL,
|
|
CONTROL_PROTO_STR_SLEW_YVEL, CONTROL_PROTO_STR_TRACK_XVEL, CONTROL_PROTO_STR_TRACK_YVEL,
|
|
CONTROL_PROTO_STR_STOP, CONTROL_PROTO_STR_SITE_LON, CONTROL_PROTO_STR_SITE_LAT,
|
|
CONTROL_PROTO_STR_SITE_ELEV, CONTROL_PROTO_STR_METEO_TEMP, CONTROL_PROTO_STR_METEO_PRES,
|
|
CONTROL_PROTO_STR_METEO_HUM, CONTROL_PROTO_STR_NET_CONF};
|
|
|
|
class ControlProtoParser
|
|
{
|
|
public:
|
|
typedef std::function<void(std::string_view, std::vector<std::string_view>)> user_func_t;
|
|
// typedef std::pair<std::string_view, std::vector<std::string_view>> parse_result_t;
|
|
struct parse_result_t {
|
|
std::string_view cmd;
|
|
std::vector<std::string_view> args;
|
|
};
|
|
|
|
ControlProtoParser();
|
|
|
|
virtual ~ControlProtoParser() = default;
|
|
|
|
template <std::convertible_to<user_func_t> FT>
|
|
bool addUserFunc(std::string_view command, FT&& func)
|
|
{
|
|
if (auto res = _userFunc.find(command); res != _userFunc.end()) {
|
|
*res = std::forward<FT>(func);
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
std::optional<parse_result_t> parse(std::string_view command);
|
|
bool exec(std::string_view command);
|
|
|
|
protected:
|
|
static void generateCommMap();
|
|
inline static std::unordered_map<std::string_view, user_func_t> _userFunc;
|
|
};
|
|
|
|
|
|
} // namespace BM700
|