54 lines
2.1 KiB
C++
54 lines
2.1 KiB
C++
#include "asibfm700_netserver.h"
|
|
|
|
|
|
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, 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 = [mount_ptr, this](std::string_view command) {
|
|
using mount_error_t = typename Asibfm700Mount::error_t;
|
|
std::error_code err{};
|
|
|
|
Asibfm700NetMessage input_msg;
|
|
using output_msg_t = Asibfm700NetMessage<handle_message_func_result_t>;
|
|
output_msg_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 {
|
|
// basic network message processing
|
|
output_msg = base_t::handleMessage<output_msg_t>(input_msg, mount_ptr);
|
|
}
|
|
}
|
|
|
|
return output_msg.byteRepr();
|
|
};
|
|
}
|
|
|
|
} // namespace asibfm700
|