...
This commit is contained in:
parent
1ea5fb623d
commit
9e8a7a62c9
@ -35,6 +35,8 @@ Asibfm700MountNetServer::Asibfm700MountNetServer(asio::io_context& ctx,
|
||||
auto vp = input_msg.paramValue<Asibfm700CCTE::meteo_t>(0);
|
||||
if (vp) {
|
||||
mount_ptr->updateMeteoERFA(vp.value());
|
||||
|
||||
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, input_msg.byteRepr());
|
||||
} else {
|
||||
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, vp.error());
|
||||
}
|
||||
|
||||
@ -509,6 +509,82 @@ static_assert(mcc_telemetry_data_c<MccTelemetryData>, "");
|
||||
/* DEFAULT SERIALIZER/DESERIALIZER FOR COORDINATE-RELATED CLASSES */
|
||||
|
||||
|
||||
enum class MccCoordinateConvErrorCode : int {
|
||||
ERROR_OK,
|
||||
ERROR_ARG_LEN,
|
||||
ERROR_NONNUM_ARG,
|
||||
ERROR_NONSGM_ARG,
|
||||
ERROR_INVALID_CPAIR,
|
||||
ERROR_TIMEPOINT,
|
||||
ERROR_INVALID_COORD_FMT,
|
||||
ERROR_INVALID_COORD_PREC
|
||||
};
|
||||
|
||||
class MccCoordinateConvErrorCategory : public std::error_category
|
||||
{
|
||||
public:
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "MCC-COORD-CONV";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
MccCoordinateConvErrorCode err = static_cast<MccCoordinateConvErrorCode>(ec);
|
||||
|
||||
switch (err) {
|
||||
case MccCoordinateConvErrorCode::ERROR_OK:
|
||||
return "OK";
|
||||
case MccCoordinateConvErrorCode::ERROR_ARG_LEN:
|
||||
return "invalid argument length or number of argument elements";
|
||||
case MccCoordinateConvErrorCode::ERROR_NONNUM_ARG:
|
||||
return "non-numeric or out-of-range argument";
|
||||
case MccCoordinateConvErrorCode::ERROR_NONSGM_ARG:
|
||||
return "non-sexagesimal argument";
|
||||
case MccCoordinateConvErrorCode::ERROR_INVALID_CPAIR:
|
||||
return "invalid coordinate pair name";
|
||||
case MccCoordinateConvErrorCode::ERROR_TIMEPOINT:
|
||||
return "invalid time point";
|
||||
case MccCoordinateConvErrorCode::ERROR_INVALID_COORD_FMT:
|
||||
return "invalid coordinate formatter string";
|
||||
case MccCoordinateConvErrorCode::ERROR_INVALID_COORD_PREC:
|
||||
return "invalid coordinate formatter precision string";
|
||||
defaut:
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static const MccCoordinateConvErrorCategory& get()
|
||||
{
|
||||
static const MccCoordinateConvErrorCategory constInst;
|
||||
return constInst;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
class is_error_code_enum<mcc::MccCoordinateConvErrorCode> : public true_type
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
|
||||
inline std::error_code make_error_code(mcc::MccCoordinateConvErrorCode ec)
|
||||
{
|
||||
return std::error_code(static_cast<int>(ec), mcc::MccCoordinateConvErrorCategory::get());
|
||||
}
|
||||
|
||||
static constexpr std::string_view MccCoordinateDefaultDelimiter{","};
|
||||
|
||||
// base class
|
||||
@ -572,7 +648,8 @@ protected:
|
||||
|
||||
bool ok = cep.fromCharRange(bytes);
|
||||
if (!ok) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_TIMEPOINT;
|
||||
}
|
||||
|
||||
mcc_tp2tp(cep.UTC(), cp.time_point);
|
||||
@ -588,7 +665,8 @@ protected:
|
||||
if (ang) {
|
||||
ang_value = MccAngle(ang.value(), MccDegreeTag{});
|
||||
} else {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_NONNUM_ARG;
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -602,7 +680,8 @@ protected:
|
||||
if (ang) {
|
||||
ang_value = MccAngle(ang.value(), MccDegreeTag{});
|
||||
} else {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_NONNUM_ARG;
|
||||
}
|
||||
|
||||
return {};
|
||||
@ -761,7 +840,8 @@ public:
|
||||
auto els = splitToElements(std::forward<IR>(bytes));
|
||||
|
||||
if (els.size() < 2) { // at least coordinate pair must be given
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_ARG_LEN;
|
||||
}
|
||||
|
||||
MccCelestialPoint pt{.pair_kind = MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||
@ -769,7 +849,8 @@ public:
|
||||
if (els.size() > 2) { // pair of coordinates and the pair kind
|
||||
pt.pair_kind = MccCoordStrToPairKind(els[2]);
|
||||
if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_UNKNOWN) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_INVALID_CPAIR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -804,12 +885,14 @@ public:
|
||||
ang1 = mcc::utils::parsAngleString(els[0]);
|
||||
}
|
||||
if (!ang1) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_NONNUM_ARG;
|
||||
}
|
||||
|
||||
ang2 = mcc::utils::parsAngleString(els[1]);
|
||||
if (!ang2) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_NONNUM_ARG;
|
||||
}
|
||||
|
||||
|
||||
@ -886,13 +969,15 @@ public:
|
||||
|
||||
auto els = splitToElements(std::forward<IR>(bytes));
|
||||
if (els.size() < 10) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_ARG_LEN;
|
||||
}
|
||||
|
||||
MccEqtHrzCoords pt;
|
||||
pt.pair_kind = MccCoordStrToPairKind(els[8]);
|
||||
if (pt.pair_kind == MccCoordPairKind::COORDS_KIND_UNKNOWN) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_INVALID_CPAIR;
|
||||
}
|
||||
|
||||
auto err = parseTimePoint(els[9], pt);
|
||||
@ -999,7 +1084,8 @@ public:
|
||||
|
||||
auto els = splitToElements(std::forward<IR>(bytes));
|
||||
if (els.size() < 12) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_ARG_LEN;
|
||||
}
|
||||
|
||||
MccPointingTarget pt;
|
||||
@ -1068,7 +1154,8 @@ public:
|
||||
|
||||
auto els = splitToElements(std::forward<IR>(bytes));
|
||||
if (els.size() < 12) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_ARG_LEN;
|
||||
}
|
||||
|
||||
MccTelemetryData tdata;
|
||||
|
||||
@ -1012,31 +1012,59 @@ protected:
|
||||
MccCelestialPoint cp{.pair_kind = MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||
|
||||
auto sz = input_msg.paramSize();
|
||||
if (sz) { // set or get operation
|
||||
auto vc = input_msg.template paramValue<MccCelestialPoint>(0); // is it set operation?
|
||||
if (vc) { // coordinates are given - set operation
|
||||
auto m_err = mount_ptr->setPointingTarget(vc.value());
|
||||
if (m_err) {
|
||||
if (sz) { // set or get operation
|
||||
auto vp = input_msg.template paramValue<MccCoordPairKind>(0); // is it get operation?
|
||||
if (vp) { // coordinate pair kind is given, it is get operation
|
||||
cp.pair_kind = vp.value();
|
||||
err = coordsFromTelemetryData(*mount_ptr, true, cp);
|
||||
if (!err) {
|
||||
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, MCC_COMMPROTO_KEYWORD_TARGET_STR,
|
||||
_coordFormat, _coordPrec, cp);
|
||||
}
|
||||
} else { // here a celestial point must be given
|
||||
auto vc = input_msg.template paramValue<MccCelestialPoint>(0);
|
||||
if (vc) { // set operation
|
||||
auto m_err = mount_ptr->setPointingTarget(vc.value());
|
||||
if (m_err) {
|
||||
err = mcc_deduce_error_code(m_err,
|
||||
MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_SET_TARGET);
|
||||
if (m_err) {
|
||||
err = mcc_deduce_error_code(
|
||||
m_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_SET_TARGET);
|
||||
}
|
||||
} else {
|
||||
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, input_msg.byteRepr());
|
||||
}
|
||||
} else {
|
||||
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, input_msg.byteRepr());
|
||||
}
|
||||
} else {
|
||||
auto vp = input_msg.template paramValue<MccCoordPairKind>(0);
|
||||
if (vp) { // coordinate pair kind is given
|
||||
cp.pair_kind = vp.value();
|
||||
err = coordsFromTelemetryData(*mount_ptr, true, cp);
|
||||
if (!err) {
|
||||
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, MCC_COMMPROTO_KEYWORD_TARGET_STR,
|
||||
_coordFormat, _coordPrec, cp);
|
||||
}
|
||||
} else { // invalid command!!!
|
||||
err = vp.error();
|
||||
err = vc.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// auto vc = input_msg.template paramValue<MccCelestialPoint>(0); // is it set operation?
|
||||
// if (vc) { // coordinates are given - set
|
||||
// operation
|
||||
// auto m_err = mount_ptr->setPointingTarget(vc.value());
|
||||
// if (m_err) {
|
||||
// if (m_err) {
|
||||
// err = mcc_deduce_error_code(m_err,
|
||||
// MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_SET_TARGET);
|
||||
// }
|
||||
// } else {
|
||||
// output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, input_msg.byteRepr());
|
||||
// }
|
||||
// } else {
|
||||
// auto vp = input_msg.template paramValue<MccCoordPairKind>(0);
|
||||
// if (vp) { // coordinate pair kind is given
|
||||
// cp.pair_kind = vp.value();
|
||||
// err = coordsFromTelemetryData(*mount_ptr, true, cp);
|
||||
// if (!err) {
|
||||
// output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR,
|
||||
// MCC_COMMPROTO_KEYWORD_TARGET_STR,
|
||||
// _coordFormat, _coordPrec, cp);
|
||||
// }
|
||||
// } else { // invalid command!!!
|
||||
// err = vp.error();
|
||||
// }
|
||||
// }
|
||||
} else { // get operation
|
||||
err = coordsFromTelemetryData(*mount_ptr, true, cp);
|
||||
if (!err) {
|
||||
|
||||
@ -325,7 +325,8 @@ protected:
|
||||
} else if constexpr (std::same_as<VT, MccCoordPairKind>) {
|
||||
value = MccCoordStrToPairKind(bytes);
|
||||
if (value == MccCoordPairKind::COORDS_KIND_UNKNOWN) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_INVALID_CPAIR;
|
||||
}
|
||||
} else if constexpr (std::same_as<VT, MccCoordinateSerializer::SerializedCoordFormat>) {
|
||||
std::string v;
|
||||
@ -339,13 +340,15 @@ protected:
|
||||
} else if (v.compare(MCC_COMMPROTO_KEYWORD_COORDFMT_FIXED_STR) == 0) {
|
||||
value = MccCoordinateSerializer::SerializedCoordFormat::CFMT_DEGREES;
|
||||
} else {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
// return std::make_error_code(std::errc::invalid_argument);
|
||||
return MccCoordinateConvErrorCode::ERROR_INVALID_COORD_FMT;
|
||||
}
|
||||
} else if constexpr (std::same_as<VT, MccCoordinateSerializer::SexagesimalCoordPrec>) {
|
||||
std::vector<int64_t> v;
|
||||
auto ec = (*this)(std::forward<IR>(bytes), v);
|
||||
if (ec) {
|
||||
return ec;
|
||||
// return ec;
|
||||
return MccCoordinateConvErrorCode::ERROR_INVALID_COORD_PREC;
|
||||
}
|
||||
|
||||
auto hprec = v[0];
|
||||
|
||||
@ -79,7 +79,8 @@ int main()
|
||||
cpser(cpt, s);
|
||||
std::cout << "Serialized: " << s << "\n";
|
||||
|
||||
auto err = cpdser(s, cpt);
|
||||
// auto err = cpdser(s, cpt);
|
||||
std::error_code err = cpdser(s, cpt);
|
||||
if (err) {
|
||||
std::cout << "deserialization error: " << err.message() << "\n";
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user