|
7 | 7 | constexpr auto LIST = "list"; |
8 | 8 | constexpr auto STATUS = "status"; |
9 | 9 | constexpr auto CONFIG = "config"; |
| 10 | +constexpr auto TMP_CONFIG = "tmp_config"; |
| 11 | +constexpr auto RESET_TMP_CONFIG = "reset_tmp_config"; |
10 | 12 | constexpr auto SCHEDULER = "scheduler"; |
11 | 13 | constexpr auto SUCCESS = "success"; |
12 | 14 | constexpr auto FAILED = "failed"; |
13 | 15 | constexpr auto LABEL = "remote"; |
14 | 16 |
|
15 | 17 | using namespace std::placeholders; |
16 | 18 |
|
17 | | -RemoteController::RemoteController(const Config& config, Mqtt& mqtt) : m_config(config), m_mqtt(mqtt) { |
18 | | - mqtt.setRawMessageCallback(fmt::format("sdr/{}", LIST), std::bind(&RemoteController::listCallback, this, _1)); |
19 | | - Logger::info(LABEL, "started, id: {}", colored(GREEN, "{}", m_config.getId())); |
20 | | -} |
| 19 | +RemoteController::RemoteController(const Config& config, Mqtt& mqtt) : m_config(config), m_mqtt(mqtt) { Logger::info(LABEL, "started, id: {}", colored(GREEN, "{}", m_config.getId())); } |
21 | 20 |
|
22 | | -void RemoteController::reloadConfigCallback(const Mqtt::JsonCallback& callback) { m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}", CONFIG, m_config.getId()), callback); } |
| 21 | +void RemoteController::getConfigQuery(const Mqtt::RawCallback& callback) { m_mqtt.setRawMessageCallback(fmt::format("sdr/{}", LIST), callback); } |
| 22 | +void RemoteController::getConfigResponse(const std::string& data) { m_mqtt.publish(fmt::format("sdr/{}/{}", STATUS, m_config.getId()), data, 2); } |
23 | 23 |
|
24 | | -void RemoteController::reloadConfigStatus(const bool& success) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", CONFIG, m_config.getId(), success ? SUCCESS : FAILED), "", 2); } |
| 24 | +void RemoteController::setConfigQuery(const Mqtt::JsonCallback& callback) { m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}", CONFIG, m_config.getId()), callback); } |
| 25 | +void RemoteController::setConfigResponse(const bool& success) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", CONFIG, m_config.getId(), success ? SUCCESS : FAILED), "", 2); } |
25 | 26 |
|
26 | | -void RemoteController::schedulerQuery(const std::string& device, const std::string& query) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}/get", SCHEDULER, m_config.getId(), device), query, 2); } |
| 27 | +void RemoteController::resetTmpConfigQuery(const Mqtt::RawCallback& callback) { m_mqtt.setRawMessageCallback(fmt::format("sdr/{}/{}", RESET_TMP_CONFIG, m_config.getId()), callback); } |
| 28 | +void RemoteController::resetTmpConfigResponse(const bool& success) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", RESET_TMP_CONFIG, m_config.getId(), success ? SUCCESS : FAILED), "", 2); } |
| 29 | + |
| 30 | +void RemoteController::setTmpConfigQuery(const Mqtt::JsonCallback& callback) { m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}", TMP_CONFIG, m_config.getId()), callback); } |
| 31 | +void RemoteController::setTmpConfigResponse(const bool& success) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}", TMP_CONFIG, m_config.getId(), success ? SUCCESS : FAILED), "", 2); } |
27 | 32 |
|
| 33 | +void RemoteController::schedulerQuery(const std::string& device, const std::string& query) { m_mqtt.publish(fmt::format("sdr/{}/{}/{}/get", SCHEDULER, m_config.getId(), device), query, 2); } |
28 | 34 | void RemoteController::schedulerCallback(const std::string& device, const Mqtt::JsonCallback& callback) { |
29 | 35 | m_mqtt.setJsonMessageCallback(fmt::format("sdr/{}/{}/{}/set", SCHEDULER, m_config.getId(), device), callback); |
30 | 36 | } |
31 | | - |
32 | | -void RemoteController::listCallback(const std::string&) { |
33 | | - Logger::info(LABEL, "received list"); |
34 | | - m_mqtt.publish(fmt::format("sdr/{}/{}", STATUS, m_config.getId()), m_config.json().dump(), 2); |
35 | | -} |
|
0 commit comments