From 6e4e776ecf56150de7fcd0f06aa1e798ab45dbef Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 26 Jan 2025 17:28:20 +0300 Subject: [PATCH] custom control protocol (starting) --- cxx/CMakeLists.txt | 3 +- cxx/control_proto.h | 75 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 cxx/control_proto.h diff --git a/cxx/CMakeLists.txt b/cxx/CMakeLists.txt index e049c35..646494c 100644 --- a/cxx/CMakeLists.txt +++ b/cxx/CMakeLists.txt @@ -11,4 +11,5 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(COMM_PROTO_LIB_SRC comm_proto.h comm_proto.cpp) set(COMM_PROTO_LIB comm_proto) -add_library(${COMM_PROTO_LIB} STATIC ${COMM_PROTO_LIB_SRC}) +add_library(${COMM_PROTO_LIB} STATIC ${COMM_PROTO_LIB_SRC} + control_proto.h) diff --git a/cxx/control_proto.h b/cxx/control_proto.h new file mode 100644 index 0000000..8aec6d4 --- /dev/null +++ b/cxx/control_proto.h @@ -0,0 +1,75 @@ +#pragma once + +#include +#include + +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 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"; + +// 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"; +static constexpr std::string_view CONTROL_PROTO_STR_SLEW_RADEC = "slewRADEC"; +static constexpr std::string_view CONTROL_PROTO_STR_SLEW_XVEL = "slewXVEL"; +static constexpr std::string_view CONTROL_PROTO_STR_SLEW_YVEL = "slewYVEL"; +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"; + + +class ControlProtoParser +{ +public: + typedef std::function)> user_func_t; + + ControlProtoParser() {} + + template FT> + bool addUserFunc(std::string_view command, FT&& func) + { + auto res = _userFunc.try_emplace(command, std::forward(func)); + return res.second; + // _userFunc[command] = std::forward(func); + } + + bool parse(std::string_view command); + bool exec(std::string_view command); + +protected: + static std::unordered_map _userFunc; +}; + + +} // namespace BM700