...
This commit is contained in:
@@ -6,10 +6,47 @@ namespace asibfm700
|
||||
|
||||
template <mcc::traits::mcc_range_of_input_char_range R>
|
||||
Asibfm700MountNetServer::Asibfm700MountNetServer(asio::io_context& ctx,
|
||||
Asibfm700Mount& mount,
|
||||
std::shared_ptr<spdlog::logger> logger,
|
||||
const R& pattern_range)
|
||||
: _base_t(ctx, [this](std::string_view msg) { return handleMessage(msg); }, std::move(logger), pattern_range)
|
||||
: base_t(ctx, mount, std::move(logger), pattern_range)
|
||||
{
|
||||
// to avoid possible compiler optimization (one needs to catch 'mount' strictly by reference)
|
||||
auto* mount_ptr = &mount;
|
||||
|
||||
base_t::_handleMessageFunc = [base_hndl_func = std::move(base_t::_handleMessageFunc), mount_ptr,
|
||||
this](std::string_view command) {
|
||||
using mount_error_t = typename Asibfm700Mount::error_t;
|
||||
std::error_code err{};
|
||||
|
||||
Asibfm700NetMessage input_msg;
|
||||
Asibfm700NetMessage<handle_message_func_result_t> output_msg;
|
||||
|
||||
auto ec = parseMessage(command, input_msg);
|
||||
|
||||
if (ec) {
|
||||
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, ec);
|
||||
} else {
|
||||
if (input_msg.withKey(ASIBFM700_COMMPROTO_KEYWORD_METEO_STR)) {
|
||||
// what is operation type (set or get)?
|
||||
if (input_msg.paramSize()) { // set operation
|
||||
auto vp = input_msg.paramValue<Asibfm700CCTE::meteo_t>(0);
|
||||
if (vp) {
|
||||
mount_ptr->updateMeteoERFA(vp.value());
|
||||
} else {
|
||||
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ERROR_STR, vp.error());
|
||||
}
|
||||
} else { // get operation
|
||||
output_msg.construct(mcc::network::MCC_COMMPROTO_KEYWORD_SERVER_ACK_STR,
|
||||
ASIBFM700_COMMPROTO_KEYWORD_METEO_STR, mount_ptr->getStateERFA().meteo);
|
||||
}
|
||||
} else {
|
||||
output_msg = base_t::handleMessage<decltype(output_msg)>(input_msg, mount_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
return output_msg.byteRepr();
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace asibfm700
|
||||
|
||||
Reference in New Issue
Block a user