From ede00dc20031285694dc7e129aefb1efe1721728 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Thu, 27 Feb 2025 12:21:49 +0300 Subject: [PATCH] ... --- cxx/control_proto.h | 19 +++++++++++-------- cxx/tests/cntr_proto_test.cpp | 11 +++++++++++ cxx/utils.h | 30 +++++++++++++++++------------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/cxx/control_proto.h b/cxx/control_proto.h index ffc18cb..d59d05d 100644 --- a/cxx/control_proto.h +++ b/cxx/control_proto.h @@ -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_HADEC = "telHADEC"; +// output coordinates format (0 - sexagimal, 1 - floating-point degrees) +static constexpr std::string_view CONTROL_PROTO_STR_COORD_FMT = "coofmt"; + // time/date static constexpr std::string_view CONTROL_PROTO_STR_UTC_DATE = "utcDate"; 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_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}; + CONTROL_PROTO_STR_COORD_FMT, 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 { diff --git a/cxx/tests/cntr_proto_test.cpp b/cxx/tests/cntr_proto_test.cpp index b8df7c1..cc879be 100644 --- a/cxx/tests/cntr_proto_test.cpp +++ b/cxx/tests/cntr_proto_test.cpp @@ -72,5 +72,16 @@ int main() cmd = " 12:30:00 "; 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; } diff --git a/cxx/utils.h b/cxx/utils.h index ff22eb3..1b0c27f 100644 --- a/cxx/utils.h +++ b/cxx/utils.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -160,7 +161,7 @@ static double rad2deg(double ang) template R, bool NORM = false> -static R rad2deg_str(double ang, int prec = 2) +static R rad2deg_str(double ang, int prec = 6) { R res; @@ -168,31 +169,33 @@ static R rad2deg_str(double ang, int prec = 2) auto degs = rad2deg(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 -static std::string rad2deg_str(double ang, int prec = 2) +static std::string rad2deg_str(double ang, int prec = 6) { return rad2deg_str(ang, prec); } template 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(ang1, prec1); R r = rad2deg_str(ang2, prec2); - std::ranges::copy(std::back_inserter(res), delim); - std::ranges::copy(std::back_inserter(res), r); + std::ranges::copy(delim, std::back_inserter(res)); + std::ranges::copy(r, std::back_inserter(res)); return res; } template -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(ang1, ang2, delim, prec1, prec2); } @@ -203,7 +206,8 @@ static R rad2sxg(double ang, bool hms = false, int prec = 2) { 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(std::abs(ang)); 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::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; } @@ -238,8 +242,8 @@ static R RADEC_rad2sxg(double ra, double dec, std::string_view delim = ",", int R r = rad2sxg(dec, false, dec_prec); - std::ranges::copy(std::back_inserter(res), delim); - std::ranges::copy(std::back_inserter(res), r); + std::ranges::copy(delim, std::back_inserter(res)); + std::ranges::copy(r, std::back_inserter(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); - std::ranges::copy(std::back_inserter(res), delim); - std::ranges::copy(std::back_inserter(res), r); + std::ranges::copy(delim, std::back_inserter(res)); + std::ranges::copy(r, std::back_inserter(res)); return res; }