This commit is contained in:
Timur A. Fatkhullin 2025-10-23 12:13:07 +03:00
parent 80ec2382ea
commit 412f038eb0
2 changed files with 92 additions and 9 deletions

View File

@ -203,6 +203,7 @@ concept mcc_coord_epoch_c = std::derived_from<T, mcc_coord_epoch_interface_t> &&
template <typename T>
concept mcc_error_c = std::default_initializable<T> && (std::convertible_to<T, bool> || requires(const T t) {
{ t.value() } -> std::formattable<char>;
{ t.operator bool() };
(bool)T() == false; // default constucted value must be a "non-error"!
});

View File

@ -41,6 +41,77 @@
#include "mcc_netserver_proto.h"
#include "mcc_traits.h"
namespace mcc::network
{
enum class MccGenericMountNetworkServerErrorCode : int {
ERROR_OK,
ERROR_MOUNT_INIT,
ERROR_MOUNT_STOP,
ERROR_MOUNT_SET_TARGET,
ERROR_MOUNT_GET_TELEMETRY,
ERROR_MOUNT_SLEW,
ERROR_MOUNT_MOVE,
ERROR_MOUNT_TRACK
};
struct MccGenericMountNetworkServerErrorCategory : std::error_category {
const char* name() const noexcept
{
return "MCC-GENERIC-MOUNT-NETWORK-SERVER";
}
std::string message(int ec) const
{
MccGenericMountNetworkServerErrorCode err = static_cast<MccGenericMountNetworkServerErrorCode>(ec);
switch (err) {
case MccGenericMountNetworkServerErrorCode::ERROR_OK:
return "OK";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_INIT:
return "mount init error";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_STOP:
return "mount stop error";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_SET_TARGET:
return "mount set target error";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_GET_TELEMETRY:
return "mount get telemetry error";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_SLEW:
return "mount slewing error";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_MOVE:
return "mount moving error";
case MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_TRACK:
return "mount tracking error";
defaut:
return "unknown";
};
}
static const MccGenericMountNetworkServerErrorCategory& get()
{
static const MccGenericMountNetworkServerErrorCategory constInst;
return constInst;
}
};
inline std::error_code make_error_code(MccGenericMountNetworkServerErrorCode ec)
{
return std::error_code(static_cast<int>(ec), MccGenericMountNetworkServerErrorCategory::get());
}
} // namespace mcc::network
namespace std
{
template <>
class is_error_code_enum<mcc::network::MccGenericMountNetworkServerErrorCode> : public true_type
{
};
} // namespace std
namespace mcc::network
{
@ -846,14 +917,29 @@ public:
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, command);
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_INIT_STR)) {
m_err = mount.initMount();
if (m_err) {
err = mcc_deduce_error_code(m_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_INIT);
}
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_STOP_STR)) {
m_err = mount.stopMount();
if (m_err) {
err = mcc_deduce_error_code(m_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_STOP);
}
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_SLEW_STR)) {
m_err = mount.slewToTarget(false);
if (m_err) {
err = mcc_deduce_error_code(m_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_SLEW);
}
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_MOVE_STR)) {
m_err = mount.slewToTarget(true);
if (m_err) {
err = mcc_deduce_error_code(m_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_MOVE);
}
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_TRACK_STR)) {
m_err = mount.trackTarget();
if (m_err) {
err = mcc_deduce_error_code(m_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_TRACK);
}
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_COORDFMT_STR)) {
auto v = input_msg.paramValue<MccNetMessageCoordFormat>(0);
if (v) {
@ -880,8 +966,10 @@ public:
if (vc) { // coordinates are given - set operation
auto m_err = mount.setPointingTarget(vc.value());
if (m_err) {
// !!!!!!!!!!!!!
err = 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, command);
}
@ -934,11 +1022,6 @@ public:
err = std::make_error_code(std::errc::invalid_argument);
}
if (m_err) {
// ?????!!!!!!
err = m_err;
}
if (err) { // send error description
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, err);
}
@ -974,8 +1057,7 @@ protected:
auto t_err = mount.telemetryData(&tdata);
if (t_err) {
// ??!!!!
return t_err;
return mcc_deduce_error_code(t_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_GET_TELEMETRY);
}
mcc_tp2tp(tdata.target.time_point, cp.time_point);