...
This commit is contained in:
parent
4a9ecf8639
commit
d8fae31406
@ -5,6 +5,7 @@
|
||||
/* BASIC NETWORK PROTOCOL DEFINITIONS */
|
||||
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include "mcc_angle.h"
|
||||
@ -15,14 +16,26 @@ namespace mcc::network
|
||||
{
|
||||
|
||||
/*
|
||||
* The network protocol is the ASCII-based, case-sensitive textual protocol.
|
||||
* The "client-server" communication is performed through messages.
|
||||
* The message is a minimal unit of this communication.
|
||||
* The model of network communication is a simple "client-server" one, i.e.,
|
||||
* client asks - server responds.
|
||||
*
|
||||
* network communication message format:
|
||||
* <keyword>[[<key-param-delim>]param1[param-param-delim][param2]...]<stop-seq>
|
||||
* <keyword>[[<key-param-delim>]<param1>[<param-param-delim>][<param2>]...]<stop-seq>
|
||||
*
|
||||
* where
|
||||
* <keyword> - mandatory message keyword (one or more ASCII symbols)
|
||||
* <key-param-delim>
|
||||
*
|
||||
* e.g.
|
||||
* "TARGET 12:23:45.56 00:32:21.978\n"
|
||||
*/
|
||||
|
||||
|
||||
/* message */
|
||||
/* low-level network message format definitions */
|
||||
|
||||
static constexpr std::string_view MCC_COMMPROTO_STOP_SEQ = "\n";
|
||||
static constexpr std::string_view MCC_COMMPROTO_KEYPARAM_DELIM_SEQ = " ";
|
||||
static constexpr std::string_view MCC_COMMPROTO_PARAMPARAM_DELIM_SEQ = " ";
|
||||
@ -60,6 +73,10 @@ static constexpr std::string_view MCC_COMMPROTO_COORD_KIND_XY = "XY";
|
||||
template <mcc::traits::mcc_char_range R>
|
||||
static constexpr MccCoordPairKind mcc_str2pairkind(R&& spair)
|
||||
{
|
||||
if constexpr (std::is_pointer_v<std::decay_t<R>>) {
|
||||
return mcc_str2pairkind(std::string_view{spair});
|
||||
}
|
||||
|
||||
const auto hash = mcc::utils::FNV1aHash(std::forward<R>(spair));
|
||||
|
||||
return hash == mcc::utils::FNV1aHash(MCC_COMMPROTO_COORD_KIND_RADEC_ICRS) ? MccCoordPairKind::COORDS_KIND_RADEC_ICRS
|
||||
@ -71,6 +88,12 @@ static constexpr MccCoordPairKind mcc_str2pairkind(R&& spair)
|
||||
: MccCoordPairKind::COORDS_KIND_GENERIC;
|
||||
}
|
||||
|
||||
// static constexpr MccCoordPairKind mcc_str2pairkind(const char* spair)
|
||||
// {
|
||||
// return mcc_str2pairkind(std::string_view{spair});
|
||||
// }
|
||||
|
||||
|
||||
static constexpr std::string_view mcc_pairkind2str(MccCoordPairKind kind)
|
||||
{
|
||||
return kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS ? MCC_COMMPROTO_COORD_KIND_RADEC_ICRS
|
||||
@ -162,6 +185,7 @@ static constexpr std::string_view MCC_COMMPROTO_KEYWORD_TARGET_STR = "TARGET";
|
||||
// "MOUNT AZAL\n" -> "ERROR INVPAR\n" (invalid parameter of coordinates pair kind)
|
||||
// "MOUNT\n" -> "ACK MOUNT 1.2332325 54.23321312 AZZD\n" for alt-azimuthal mount
|
||||
// "MOUNT\n" -> "ACK MOUNT 1.2332325 54.23321312 HADEC\n" for equathorial mount
|
||||
|
||||
static constexpr std::string_view MCC_COMMPROTO_KEYWORD_MOUNT_STR = "MOUNT";
|
||||
|
||||
|
||||
@ -187,12 +211,17 @@ static constexpr std::string_view MCC_COMMPROTO_KEYWORD_MOVE_STR = "MOVE";
|
||||
// "TRACK\n"
|
||||
static constexpr std::string_view MCC_COMMPROTO_KEYWORD_TRACK_STR = "TRACK";
|
||||
|
||||
// get mount status
|
||||
// "STATUS\n"
|
||||
static constexpr std::string_view MCC_COMMPROTO_KEYWORD_STATUS_STR = "STATUS";
|
||||
|
||||
// valid keywords
|
||||
static constexpr std::array MCC_COMMPROTO_VALID_KEYS = {
|
||||
MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, MCC_COMMPROTO_KEYWORD_COORDFMT_STR,
|
||||
MCC_COMMPROTO_KEYWORD_COORDPREC_STR, MCC_COMMPROTO_KEYWORD_TARGET_STR, MCC_COMMPROTO_KEYWORD_MOUNT_STR,
|
||||
MCC_COMMPROTO_KEYWORD_TELEMETRY_STR, MCC_COMMPROTO_KEYWORD_INIT_STR, MCC_COMMPROTO_KEYWORD_STOP_STR,
|
||||
MCC_COMMPROTO_KEYWORD_SLEW_STR, MCC_COMMPROTO_KEYWORD_MOVE_STR, MCC_COMMPROTO_KEYWORD_TRACK_STR};
|
||||
MCC_COMMPROTO_KEYWORD_SLEW_STR, MCC_COMMPROTO_KEYWORD_MOVE_STR, MCC_COMMPROTO_KEYWORD_TRACK_STR,
|
||||
MCC_COMMPROTO_KEYWORD_STATUS_STR};
|
||||
|
||||
|
||||
// hashes valid keywords
|
||||
@ -350,7 +379,18 @@ bool mcc_netmsg_get_cpoint(mcc_netmsg_parse_result_c auto const& parse_res,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (kind != mcc::MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||
mcc_tp2tp(std::chrono::system_clock::now(), cpoint.time_point);
|
||||
} else {
|
||||
// J2000.0: 11:58:55.816 1 January 2000 UTC
|
||||
auto tp = std::chrono::sys_days(std::chrono::year_month_day(std::chrono::January / std::chrono::day(1) /
|
||||
std::chrono::year(2000))) +
|
||||
std::chrono::hours(11) + std::chrono::minutes(58) + std::chrono::milliseconds(55816);
|
||||
mcc_tp2tp(tp, cpoint.time_point);
|
||||
}
|
||||
|
||||
cpoint.pair_kind = kind;
|
||||
|
||||
cpoint.X = MccAngle(ang1.value(), mcc::MccDegreeTag{}); // to radians
|
||||
cpoint.Y = MccAngle(ang2.value(), mcc::MccDegreeTag{}); // to radians
|
||||
|
||||
|
||||
@ -197,5 +197,23 @@ int main()
|
||||
|
||||
std::cout << "\nNETMSG: [" << sm << "] (" << mr << ")\n";
|
||||
|
||||
auto tp = std::chrono::sys_days(
|
||||
std::chrono::year_month_day(std::chrono::January / std::chrono::day(1) / std::chrono::year(2000)))
|
||||
// + std::chrono::hours(11) + std::chrono::minutes(58) + std::chrono::duration<double>(55.816);
|
||||
+ std::chrono::hours(11) + std::chrono::minutes(58) + std::chrono::milliseconds(55816);
|
||||
|
||||
std::cout << tp << "\n";
|
||||
// std::cout << std::chrono::system_clock::now() << "\n";
|
||||
|
||||
|
||||
constexpr std::string_view stv{"RADEC"};
|
||||
constexpr char ccv[] = "RADEC";
|
||||
|
||||
// const auto pk = mcc::network::mcc_str2pairkind(stv);
|
||||
// const auto pk = mcc::network::mcc_str2pairkind(std::string_view{"RADEC"});
|
||||
// const auto pk = mcc::network::mcc_str2pairkind("RADEC");
|
||||
const auto pk = mcc::network::mcc_str2pairkind(ccv);
|
||||
static_assert(pk == mcc::MccCoordPairKind::COORDS_KIND_RADEC_APP);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user