...
This commit is contained in:
parent
d1e91e1c96
commit
ede00dc200
@ -36,6 +36,9 @@ 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_HA = "telHA";
|
||||||
static constexpr std::string_view CONTROL_PROTO_STR_TEL_HADEC = "telHADEC";
|
static constexpr std::string_view CONTROL_PROTO_STR_TEL_HADEC = "telHADEC";
|
||||||
|
|
||||||
|
// output coordinates format (0 - sexagimal, 1 - floating-point degrees)
|
||||||
|
static constexpr std::string_view CONTROL_PROTO_STR_COORD_FMT = "coofmt";
|
||||||
|
|
||||||
// time/date
|
// time/date
|
||||||
static constexpr std::string_view CONTROL_PROTO_STR_UTC_DATE = "utcDate";
|
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_LOC_DATE = "locDate";
|
||||||
@ -79,14 +82,14 @@ 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_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_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_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_COORD_FMT, CONTROL_PROTO_STR_UTC_DATE, CONTROL_PROTO_STR_LOC_DATE,
|
||||||
CONTROL_PROTO_STR_LOC_TIME, CONTROL_PROTO_STR_UTC_DT, CONTROL_PROTO_STR_LOC_DT,
|
CONTROL_PROTO_STR_UTC_TIME, CONTROL_PROTO_STR_LOC_TIME, CONTROL_PROTO_STR_UTC_DT,
|
||||||
CONTROL_PROTO_STR_JDN, CONTROL_PROTO_STR_TAG_MINALT, CONTROL_PROTO_STR_TAG_MAXALT,
|
CONTROL_PROTO_STR_LOC_DT, CONTROL_PROTO_STR_JDN, CONTROL_PROTO_STR_TAG_MINALT,
|
||||||
CONTROL_PROTO_STR_SLEW_AZALT, CONTROL_PROTO_STR_SLEW_RADEC, CONTROL_PROTO_STR_SLEW_XVEL,
|
CONTROL_PROTO_STR_TAG_MAXALT, CONTROL_PROTO_STR_SLEW_AZALT, CONTROL_PROTO_STR_SLEW_RADEC,
|
||||||
CONTROL_PROTO_STR_SLEW_YVEL, CONTROL_PROTO_STR_TRACK_XVEL, CONTROL_PROTO_STR_TRACK_YVEL,
|
CONTROL_PROTO_STR_SLEW_XVEL, CONTROL_PROTO_STR_SLEW_YVEL, CONTROL_PROTO_STR_TRACK_XVEL,
|
||||||
CONTROL_PROTO_STR_STOP, CONTROL_PROTO_STR_SITE_LON, CONTROL_PROTO_STR_SITE_LAT,
|
CONTROL_PROTO_STR_TRACK_YVEL, CONTROL_PROTO_STR_STOP, CONTROL_PROTO_STR_SITE_LON,
|
||||||
CONTROL_PROTO_STR_SITE_ELEV, CONTROL_PROTO_STR_METEO_TEMP, CONTROL_PROTO_STR_METEO_PRES,
|
CONTROL_PROTO_STR_SITE_LAT, CONTROL_PROTO_STR_SITE_ELEV, CONTROL_PROTO_STR_METEO_TEMP,
|
||||||
CONTROL_PROTO_STR_METEO_HUM, CONTROL_PROTO_STR_NET_CONF};
|
CONTROL_PROTO_STR_METEO_PRES, CONTROL_PROTO_STR_METEO_HUM, CONTROL_PROTO_STR_NET_CONF};
|
||||||
|
|
||||||
class ControlProtoParser
|
class ControlProtoParser
|
||||||
{
|
{
|
||||||
|
|||||||
@ -72,5 +72,16 @@ int main()
|
|||||||
cmd = " 12:30:00 ";
|
cmd = " 12:30:00 ";
|
||||||
print_ang_result(cmd, true);
|
print_ang_result(cmd, true);
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "\n\n";
|
||||||
|
|
||||||
|
double ra = 0.3242345, dec = -1.2342397;
|
||||||
|
|
||||||
|
std::cout << "RADEC (rads): " << ra << ", " << dec << "\n";
|
||||||
|
|
||||||
|
std::cout << "RADEC (sexg): " << mcc::utils::RADEC_rad2sxg(ra, dec, ";", 3, 2) << "\n";
|
||||||
|
|
||||||
|
std::cout << "RADEC (degs): " << mcc::utils::rad2deg_str(ra, dec, ";", 7, 7) << "\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
30
cxx/utils.h
30
cxx/utils.h
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <format>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
@ -160,7 +161,7 @@ static double rad2deg(double ang)
|
|||||||
|
|
||||||
|
|
||||||
template <std::ranges::output_range<char> R, bool NORM = false>
|
template <std::ranges::output_range<char> R, bool NORM = false>
|
||||||
static R rad2deg_str(double ang, int prec = 2)
|
static R rad2deg_str(double ang, int prec = 6)
|
||||||
{
|
{
|
||||||
R res;
|
R res;
|
||||||
|
|
||||||
@ -168,31 +169,33 @@ static R rad2deg_str(double ang, int prec = 2)
|
|||||||
|
|
||||||
auto degs = rad2deg<NORM>(ang);
|
auto degs = rad2deg<NORM>(ang);
|
||||||
|
|
||||||
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, degs);
|
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, std::make_format_args(degs));
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool NORM = false>
|
template <bool NORM = false>
|
||||||
static std::string rad2deg_str(double ang, int prec = 2)
|
static std::string rad2deg_str(double ang, int prec = 6)
|
||||||
{
|
{
|
||||||
return rad2deg_str<std::string, NORM>(ang, prec);
|
return rad2deg_str<std::string, NORM>(ang, prec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <std::ranges::output_range<char> R, bool NORM = false>
|
template <std::ranges::output_range<char> R, bool NORM = false>
|
||||||
static R rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 2, int prec2 = 2)
|
static R rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 6, int prec2 = 6)
|
||||||
{
|
{
|
||||||
R res = rad2deg_str<R, NORM>(ang1, prec1);
|
R res = rad2deg_str<R, NORM>(ang1, prec1);
|
||||||
|
|
||||||
R r = rad2deg_str<R, NORM>(ang2, prec2);
|
R r = rad2deg_str<R, NORM>(ang2, prec2);
|
||||||
|
|
||||||
std::ranges::copy(std::back_inserter(res), delim);
|
std::ranges::copy(delim, std::back_inserter(res));
|
||||||
std::ranges::copy(std::back_inserter(res), r);
|
std::ranges::copy(r, std::back_inserter(res));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool NORM = false>
|
template <bool NORM = false>
|
||||||
static std::string rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 2, int prec2 = 2)
|
static std::string rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 6, int prec2 = 6)
|
||||||
{
|
{
|
||||||
return rad2deg_str<std::string, NORM>(ang1, ang2, delim, prec1, prec2);
|
return rad2deg_str<std::string, NORM>(ang1, ang2, delim, prec1, prec2);
|
||||||
}
|
}
|
||||||
@ -203,7 +206,8 @@ static R rad2sxg(double ang, bool hms = false, int prec = 2)
|
|||||||
{
|
{
|
||||||
R res;
|
R res;
|
||||||
|
|
||||||
std::string fmt = "{:02d}:{:02d}:{:0" + std::to_string(prec + 3) + "." + std::to_string(prec) + "f}";
|
std::string fmt = "{:02.0f}:{:02.0f}:{:0" + std::to_string(prec + 3) + "." + std::to_string(prec) + "f}";
|
||||||
|
// std::string fmt = "{:02.0f}:{:02.0f}:{:02." + std::to_string(prec) + "f}";
|
||||||
|
|
||||||
auto degs = rad2deg<NORM>(std::abs(ang));
|
auto degs = rad2deg<NORM>(std::abs(ang));
|
||||||
if (hms) {
|
if (hms) {
|
||||||
@ -219,7 +223,7 @@ static R rad2sxg(double ang, bool hms = false, int prec = 2)
|
|||||||
std::ranges::copy(std::string_view("-"), std::back_inserter(res));
|
std::ranges::copy(std::string_view("-"), std::back_inserter(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, d, m, s);
|
std::vformat_to(std::back_inserter(res), std::string_view{fmt.begin(), fmt.end()}, std::make_format_args(d, m, s));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -238,8 +242,8 @@ static R RADEC_rad2sxg(double ra, double dec, std::string_view delim = ",", int
|
|||||||
|
|
||||||
R r = rad2sxg(dec, false, dec_prec);
|
R r = rad2sxg(dec, false, dec_prec);
|
||||||
|
|
||||||
std::ranges::copy(std::back_inserter(res), delim);
|
std::ranges::copy(delim, std::back_inserter(res));
|
||||||
std::ranges::copy(std::back_inserter(res), r);
|
std::ranges::copy(r, std::back_inserter(res));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -258,8 +262,8 @@ static R AZZD_rad2sxg(double az, double zd, std::string_view delim = ",", int az
|
|||||||
|
|
||||||
R r = rad2sxg(zd, false, zd_prec);
|
R r = rad2sxg(zd, false, zd_prec);
|
||||||
|
|
||||||
std::ranges::copy(std::back_inserter(res), delim);
|
std::ranges::copy(delim, std::back_inserter(res));
|
||||||
std::ranges::copy(std::back_inserter(res), r);
|
std::ranges::copy(r, std::back_inserter(res));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user