This commit is contained in:
2025-10-28 18:01:22 +03:00
parent 85dfa2e9a5
commit 78e4bb182c
10 changed files with 277 additions and 200 deletions

View File

@@ -159,8 +159,9 @@ public:
static constexpr std::chrono::duration DEFAULT_RCV_TIMEOUT = std::chrono::hours(12);
static constexpr std::chrono::duration DEFAULT_SND_TIMEOUT = std::chrono::milliseconds(2000);
typedef std::vector<char> handle_message_func_result_t;
// handle received message user function
typedef std::function<std::vector<char>(std::string_view)> handle_message_func_t;
typedef std::function<handle_message_func_result_t(std::string_view)> handle_message_func_t;
MccGenericNetworkServer(asio::io_context& ctx, const handle_message_func_t& func)
@@ -892,6 +893,8 @@ class MccGenericMountNetworkServer : public MccGenericNetworkServer<LoggerT>
using base_t = MccGenericNetworkServer<LoggerT>;
public:
using typename base_t::handle_message_func_result_t;
template <mcc_generic_mount_c MountT, typename... LoggerCtorArgsTs>
MccGenericMountNetworkServer(asio::io_context& ctx, MountT& mount, LoggerCtorArgsTs&&... log_args)
: base_t(ctx, {}, std::forward<LoggerCtorArgsTs>(log_args)...)
@@ -901,7 +904,7 @@ public:
mount_error_t m_err;
MccNetMessage input_msg;
MccNetMessage<std::vector<char>> output_msg;
MccNetMessage<handle_message_func_result_t> output_msg;
std::error_code err{};
@@ -941,7 +944,7 @@ public:
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);
auto v = input_msg.paramValue<MccCoordinateSerializer::SerializedCoordFormat>(0);
if (v) {
_coordFormat = v.value();
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, command);
@@ -949,7 +952,7 @@ public:
err = v.error();
}
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_COORDPREC_STR)) {
auto v = input_msg.paramValue<MccNetMessageCoordPrec>(0);
auto v = input_msg.paramValue<MccCoordinateSerializer::SexagesimalCoordPrec>(0);
if (v) {
_coordPrec = v.value();
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, command);
@@ -990,7 +993,7 @@ public:
err = coordsFromTelemetryData(mount, true, cp);
if (!err) {
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, MCC_COMMPROTO_KEYWORD_TARGET_STR,
cp);
_coordFormat, _coordPrec, cp);
}
}
@@ -1015,7 +1018,7 @@ public:
err = coordsFromTelemetryData(mount, false, cp);
if (!err) {
output_msg.construct(MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR, MCC_COMMPROTO_KEYWORD_MOUNT_STR,
cp);
_coordFormat, _coordPrec, cp);
}
}
} else {
@@ -1030,15 +1033,19 @@ public:
// }
}
return output_msg;
return output_msg.byteRepr();
};
}
virtual ~MccGenericMountNetworkServer() {}
protected:
MccNetMessageCoordFormat _coordFormat{MccNetMessageCoordFormat::CFMT_SGM}; // ouput coordinates format
MccNetMessageCoordPrec _coordPrec{2, 1};
// MccNetMessageCoordFormat _coordFormat{MccNetMessageCoordFormat::CFMT_SGM}; // ouput coordinates format
// MccNetMessageCoordPrec _coordPrec{2, 1};
MccCoordinateSerializer::SerializedCoordFormat _coordFormat{
MccCoordinateSerializer::SerializedCoordFormat::CFMT_SGM};
MccCoordinateSerializer::SexagesimalCoordPrec _coordPrec{2, 1};
template <typename MSG_T>
std::error_code parseMessage(std::string_view msg_bytes, MSG_T& msg)