...
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
|
||||
#include <thread>
|
||||
#include "mcc/mcc_spdlog.h"
|
||||
#include "mcc_error.h"
|
||||
|
||||
namespace mcc::impl
|
||||
@@ -33,8 +34,6 @@ enum class MccGenericMountErrorCode : int {
|
||||
ERROR_TARGET_IN_ZONE
|
||||
};
|
||||
|
||||
enum class MccGenericFsmMountErrorCode : int { ERROR_OK, ERROR_INVALID_OPERATION, ERROR_UNKNOWN_EVENT };
|
||||
|
||||
} // namespace mcc::impl
|
||||
|
||||
|
||||
@@ -70,7 +69,7 @@ struct MccGenericMountCategory : public std::error_category {
|
||||
case MccGenericMountErrorCode::ERROR_OK:
|
||||
return "OK";
|
||||
case MccGenericMountErrorCode::ERROR_HW_INIT:
|
||||
return "an error occured while initializing mount";
|
||||
return "an error occured while initializing mount hardware";
|
||||
case MccGenericMountErrorCode::ERROR_HW_STOP:
|
||||
return "an error occured while stopping mount";
|
||||
case MccGenericMountErrorCode::ERROR_HW_GETSTATE:
|
||||
@@ -113,7 +112,7 @@ template <mcc_hardware_c HARDWARE_T,
|
||||
mcc_telemetry_c TELEMETRY_T,
|
||||
mcc_pzone_container_c PZONE_CONT_T,
|
||||
mcc_movement_controls_c MOVE_CNTRL_T,
|
||||
mcc_logger_c LOGGER_T>
|
||||
mcc_logger_c LOGGER_T = utils::MccSpdlogLogger>
|
||||
class MccGenericMount : protected HARDWARE_T,
|
||||
public TELEMETRY_T,
|
||||
public PZONE_CONT_T,
|
||||
@@ -160,9 +159,33 @@ public:
|
||||
MOVE_CNTRL_T(std::make_from_tuple<MOVE_CNTRL_T>(move_cntrl_ctor_ars)),
|
||||
LOGGER_T(std::make_from_tuple<LOGGER_T>(logger_ctor_args))
|
||||
{
|
||||
logDebug(std::format("Create MccGenericMount class instance (thread: {})", std::this_thread::get_id()));
|
||||
// logDebug(std::format("Create MccGenericMount class instance (thread: {})", std::this_thread::get_id()));
|
||||
logDebug("Create MccGenericMount class instance (thread: {})", std::this_thread::get_id());
|
||||
}
|
||||
|
||||
template <typename... HardwareCtorTs,
|
||||
typename... TelemetryCtorTs,
|
||||
typename... PzoneContCtorTs,
|
||||
typename... MoveCntrCtorTs,
|
||||
typename... LoggerCtorTs>
|
||||
requires std::derived_from<LOGGER_T, utils::MccSpdlogLogger>
|
||||
MccGenericMount(std::tuple<HardwareCtorTs...> hw_ctor_args,
|
||||
std::tuple<TelemetryCtorTs...> telemetry_ctor_args,
|
||||
std::tuple<PzoneContCtorTs...> pzone_cont_ctor_ars,
|
||||
std::tuple<MoveCntrCtorTs...> move_cntrl_ctor_ars,
|
||||
LoggerCtorTs... logger_ctor_args)
|
||||
: HARDWARE_T(std::make_from_tuple<HARDWARE_T>(std::move(hw_ctor_args))),
|
||||
TELEMETRY_T(std::make_from_tuple<TELEMETRY_T>(std::move(telemetry_ctor_args))),
|
||||
PZONE_CONT_T(std::make_from_tuple<PZONE_CONT_T>(pzone_cont_ctor_ars)),
|
||||
MOVE_CNTRL_T(std::make_from_tuple<MOVE_CNTRL_T>(move_cntrl_ctor_ars)),
|
||||
mcc::utils::MccSpdlogLogger(logger_ctor_args...)
|
||||
{
|
||||
// logDebug(std::format("Create MccGenericMount class instance (thread: {})", std::this_thread::get_id()));
|
||||
logDebug("Create MccGenericMount class instance (thread: {})", std::this_thread::get_id());
|
||||
}
|
||||
|
||||
/* movable-only class */
|
||||
|
||||
MccGenericMount(const MccGenericMount&) = delete;
|
||||
MccGenericMount(MccGenericMount&&) = default;
|
||||
|
||||
@@ -171,7 +194,8 @@ public:
|
||||
|
||||
virtual ~MccGenericMount()
|
||||
{
|
||||
logDebug(std::format("Delete MccGenericMount class instance (thread: {})", std::this_thread::get_id()));
|
||||
// logDebug(std::format("Delete MccGenericMount class instance (thread: {})", std::this_thread::get_id()));
|
||||
logDebug("Delete MccGenericMount class instance (thread: {})", std::this_thread::get_id());
|
||||
|
||||
auto err = MOVE_CNTRL_T::stopMount();
|
||||
if (err) {
|
||||
@@ -211,6 +235,45 @@ public:
|
||||
return _lastMountError->load();
|
||||
}
|
||||
|
||||
|
||||
/* log-method wrappers for non-MccSpdlogger classes */
|
||||
|
||||
template <std::formattable<char>... ArgTs>
|
||||
requires(!std::derived_from<LOGGER_T, utils::MccSpdlogLogger>)
|
||||
void logInfo(std::format_string<ArgTs...> fmt, ArgTs&&... args)
|
||||
{
|
||||
LOGGER_T::logInfo(std::format(fmt, std::forward<ArgTs>(args)...));
|
||||
}
|
||||
|
||||
template <std::formattable<char>... ArgTs>
|
||||
requires(!std::derived_from<LOGGER_T, utils::MccSpdlogLogger>)
|
||||
void logDebug(std::format_string<ArgTs...> fmt, ArgTs&&... args)
|
||||
{
|
||||
LOGGER_T::logDebug(std::format(fmt, std::forward<ArgTs>(args)...));
|
||||
}
|
||||
|
||||
template <std::formattable<char>... ArgTs>
|
||||
requires(!std::derived_from<LOGGER_T, utils::MccSpdlogLogger>)
|
||||
void logError(std::format_string<ArgTs...> fmt, ArgTs&&... args)
|
||||
{
|
||||
LOGGER_T::logError(std::format(fmt, std::forward<ArgTs>(args)...));
|
||||
}
|
||||
|
||||
template <std::formattable<char>... ArgTs>
|
||||
requires(!std::derived_from<LOGGER_T, utils::MccSpdlogLogger>)
|
||||
void logWarn(std::format_string<ArgTs...> fmt, ArgTs&&... args)
|
||||
{
|
||||
LOGGER_T::logWarn(std::format(fmt, std::forward<ArgTs>(args)...));
|
||||
}
|
||||
|
||||
template <std::formattable<char>... ArgTs>
|
||||
requires(!std::derived_from<LOGGER_T, utils::MccSpdlogLogger>)
|
||||
void logTrace(std::format_string<ArgTs...> fmt, ArgTs&&... args)
|
||||
{
|
||||
LOGGER_T::logTrace(std::format(fmt, std::forward<ArgTs>(args)...));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
std::unique_ptr<std::atomic<mount_status_t>> _mountStatus{
|
||||
new std::atomic<mount_status_t>{mount_status_t::MOUNT_STATUS_UNINITIALIZED}};
|
||||
|
||||
Reference in New Issue
Block a user