33#include <Envelope.hpp>
51 return value ?
"true" :
"false";
55 return value ==
"true" || value ==
"1" || value ==
"online" ||
63 return std::stoi(value);
64 }
catch (
const std::exception&) {
65 throw std::invalid_argument(
"lacte bus integer field is invalid: " + value);
85 std::optional<std::uint64_t>
87 std::optional<std::uint16_t>
145 envelope.m_headers[
"aeration"] = std::to_string(snapshot.
aeration);
146 envelope.m_headers[
"app_version"] = snapshot.
app_version;
147 envelope.m_headers[
"fw_version"] = snapshot.
fw_version;
149 envelope.m_headers[
"expiry_date"] = snapshot.
expiry_date;
151 envelope.m_headers[
"remaining_percent"] =
155 envelope.m_headers[
"error_flags"] = std::to_string(*snapshot.
error_flags);
158 envelope.m_headers[
"system_state"] = snapshot.
system_state;
165 if (
const auto found = envelope.m_headers.find(
"online");
166 found != envelope.m_headers.end()) {
169 if (
const auto found = envelope.m_headers.find(
"aeration");
170 found != envelope.m_headers.end()) {
173 if (
const auto found = envelope.m_headers.find(
"app_version");
174 found != envelope.m_headers.end()) {
177 if (
const auto found = envelope.m_headers.find(
"fw_version");
178 found != envelope.m_headers.end()) {
181 if (
const auto found = envelope.m_headers.find(
"milk_system_sn");
182 found != envelope.m_headers.end()) {
185 if (
const auto found = envelope.m_headers.find(
"expiry_date");
186 found != envelope.m_headers.end()) {
189 if (
const auto found = envelope.m_headers.find(
"remaining_percent");
190 found != envelope.m_headers.end()) {
194 if (
const auto found = envelope.m_headers.find(
"error_flags");
195 found != envelope.m_headers.end()) {
199 if (
const auto found = envelope.m_headers.find(
"system_state");
200 found != envelope.m_headers.end()) {
213 envelope.m_headers[
"rfid_number"] = data.
rfid_number;
214 envelope.m_headers[
"lacte_id"] = data.
lacte_id;
215 envelope.m_headers[
"lacte_sn"] = data.
lacte_sn;
216 envelope.m_headers[
"mcu_uid"] = data.
mcu_uid;
217 envelope.m_headers[
"machine_sn"] = data.
machine_sn;
219 envelope.m_headers[
"prod_date"] = data.
prod_date;
220 envelope.m_headers[
"shelf_life"] = data.
shelf_life;
221 envelope.m_headers[
"usage_time"] = data.
usage_time;
230 if (
const auto found = envelope.m_headers.find(
"present");
231 found != envelope.m_headers.end()) {
237 auto field = [&](
const char* key, std::string& out) ->
void {
238 if (
const auto found = envelope.m_headers.find(key);
239 found != envelope.m_headers.end()) {
246 field(
"mcu_uid", data.
mcu_uid);
269 static constexpr auto
276 [[nodiscard]]
static auto build() -> std::vector<uint8_t> {
return {}; }
288 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
289 insitech::bus::Envelope envelope;
290 envelope.m_headers[
"status"] =
ok ?
"ok" :
"error";
291 if (!
error.empty()) {
292 envelope.m_headers[
"error"] =
error;
294 return insitech::bus::encode_envelope(envelope);
297 const auto [m_headers, m_payload] = insitech::bus::decode_envelope(bytes);
299 if (
const auto found = m_headers.find(
"status"); found != m_headers.end()) {
300 reply.
ok = found->second ==
"ok";
302 if (
const auto found = m_headers.find(
"error"); found != m_headers.end()) {
303 reply.
error = found->second;
312 static constexpr auto
321 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
322 insitech::bus::Envelope envelope;
323 envelope.m_headers[
"param"] =
param;
324 return insitech::bus::encode_envelope(envelope);
327 const auto [m_headers, m_payload] = insitech::bus::decode_envelope(bytes);
329 if (
const auto found = m_headers.find(
"param"); found != m_headers.end()) {
330 request.
param = found->second;
343 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
344 insitech::bus::Envelope envelope;
345 envelope.m_headers[
"status"] =
ok ?
"ok" :
"error";
346 if (!
error.empty()) {
347 envelope.m_headers[
"error"] =
error;
350 envelope.m_headers[
"param"] =
param;
351 envelope.m_headers[
"value"] = std::to_string(
value);
353 return insitech::bus::encode_envelope(envelope);
356 const auto [m_headers, m_payload] = insitech::bus::decode_envelope(bytes);
358 if (
const auto found = m_headers.find(
"status"); found != m_headers.end()) {
359 reply.
ok = found->second ==
"ok";
361 if (
const auto found = m_headers.find(
"error"); found != m_headers.end()) {
362 reply.
error = found->second;
364 if (
const auto found = m_headers.find(
"param"); found != m_headers.end()) {
365 reply.
param = found->second;
367 if (
const auto found = m_headers.find(
"value"); found != m_headers.end()) {
377 static constexpr auto
387 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
388 insitech::bus::Envelope envelope;
389 envelope.m_headers[
"param"] =
param;
390 envelope.m_headers[
"value"] = std::to_string(
value);
391 return insitech::bus::encode_envelope(envelope);
394 const auto envelope = insitech::bus::decode_envelope(bytes);
396 if (
const auto found = envelope.m_headers.find(
"param");
397 found != envelope.m_headers.end()) {
398 request.
param = found->second;
400 if (
const auto found = envelope.m_headers.find(
"value");
401 found != envelope.m_headers.end()) {
411 static constexpr auto K_TOPIC =
"snapshot.get";
412 static constexpr auto
419 [[nodiscard]]
static auto build() -> std::vector<uint8_t> {
return {}; }
431 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
432 insitech::bus::Envelope envelope;
433 envelope.m_headers[
"status"] =
ok ?
"ok" :
"error";
434 if (!
error.empty()) {
435 envelope.m_headers[
"error"] =
error;
438 return insitech::bus::encode_envelope(envelope);
441 const auto envelope = insitech::bus::decode_envelope(bytes);
443 if (
const auto found = envelope.m_headers.find(
"status");
444 found != envelope.m_headers.end()) {
445 reply.
ok = found->second ==
"ok";
447 if (
const auto found = envelope.m_headers.find(
"error");
448 found != envelope.m_headers.end()) {
449 reply.
error = found->second;
462 static constexpr auto
469 [[nodiscard]]
static auto build() -> std::vector<uint8_t> {
return {}; }
481 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
482 insitech::bus::Envelope envelope;
483 envelope.m_headers[
"status"] =
ok ?
"ok" :
"error";
484 if (!
error.empty()) {
485 envelope.m_headers[
"error"] =
error;
488 return insitech::bus::encode_envelope(envelope);
491 const auto envelope = insitech::bus::decode_envelope(bytes);
493 if (
const auto found = envelope.m_headers.find(
"status");
494 found != envelope.m_headers.end()) {
495 reply.
ok = found->second ==
"ok";
497 if (
const auto found = envelope.m_headers.find(
"error");
498 found != envelope.m_headers.end()) {
499 reply.
error = found->second;
509 static constexpr auto K_TOPIC =
"test.board.online.set";
510 static constexpr auto
519 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
520 insitech::bus::Envelope envelope;
522 return insitech::bus::encode_envelope(envelope);
524 static auto parse(
const std::vector<uint8_t>& bytes)
526 const auto [m_headers, m_payload] = insitech::bus::decode_envelope(bytes);
528 if (
const auto found = m_headers.find(
"online"); found != m_headers.end()) {
540 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
541 const std::string command =
enable ?
"enable" :
"disable";
542 return {command.begin(), command.end()};
545 const std::string command(bytes.begin(), bytes.end());
546 return {command ==
"enable"};
555 [[nodiscard]]
auto build() const -> std::vector<uint8_t> {
556 insitech::bus::Envelope envelope;
558 return insitech::bus::encode_envelope(envelope);
void encode_rfid_data(insitech::bus::Envelope &envelope, const RfidData &data)
void encode_board_snapshot(insitech::bus::Envelope &envelope, const BoardSnapshot &snapshot)
auto decode_rfid_data(const insitech::bus::Envelope &envelope) -> RfidData
auto decode_board_snapshot(const insitech::bus::Envelope &envelope) -> BoardSnapshot
auto string_to_int(const std::string &value) -> int
constexpr auto K_PARAM_AERATION
Имя параметра бэкенда (и ключ заголовка снапшота) для уровня аэрации.
auto string_to_bool(const std::string &value) -> bool
auto bool_to_string(const bool value) -> std::string
Push backend -> UI: сериализованный снапшот платы.
auto build() const -> std::vector< uint8_t >
static constexpr auto K_TOPIC
static auto parse(const std::vector< uint8_t > &bytes) -> BoardSnapshotEvent
Моментальный снимок состояния диспенсера/платы, которым обмениваются бэкенд и UI (как запрос/ответ сн...
bool board_online
Доступна/онлайн ли диспенсерная плата в данный момент.
std::optional< std::uint64_t > remaining_percent
Оставшийся процент молока, если известен.
std::string expiry_date
Срок годности подключённой молочной системы, как сообщает бэкенд.
std::optional< std::uint16_t > error_flags
Битовая маска активных флагов ошибок, если известна.
std::string fw_version
Строка версии низкоуровневой прошивки платы, если известна.
std::string app_version
Строка версии прикладной прошивки, выполняющейся на плате, если известна.
std::string system_state
Совмещённое состояние системы (online lacte-платы + HMI-сигнал двери, см.
int aeration
Текущий уровень аэрации (в процентах).
std::string milk_system_sn
Серийный номер подключённой молочной системы/картриджа, если известен.
Запрос UI -> backend: жив ли бэкенд и здоров ли он? Без payload.
static constexpr auto kTopic
static auto parse(const std::vector< uint8_t > &) -> HealthRequest
static auto build() -> std::vector< uint8_t >
static constexpr auto K_TOPIC
Ответ на ParamGetRequest: значение запрошенного параметра.
static auto parse(const std::vector< uint8_t > &bytes) -> ParamGetReply
auto build() const -> std::vector< uint8_t >
Запрос UI -> backend: прочитать именованный параметр бэкенда.
static auto parse(const std::vector< uint8_t > &bytes) -> ParamGetRequest
auto build() const -> std::vector< uint8_t >
static constexpr auto K_TOPIC
static constexpr auto kTopic
Запрос UI -> backend: записать именованный параметр бэкенда.
auto build() const -> std::vector< uint8_t >
static auto parse(const std::vector< uint8_t > &bytes) -> ParamSetRequest
static constexpr auto kTopic
static constexpr auto K_TOPIC
СЫРЫЕ поля, считанные с текущей подключённой RFID-карты/молочной системы - ДЕРЖАТСЯ ОТДЕЛЬНО от Board...
std::string lacte_id
LacteId - идентификатор продукта/рецепта.
std::string shelf_life
Срок годности (сырое значение счётчика).
std::string rfid_number
Собственный сырой RFID-номер карты.
std::string product_volume
Общий объём продукта, которым была заполнена карта.
std::string lacte_sn
LacteSn - серийный номер продукта.
std::string prod_date
Дата производства (сырое значение счётчика).
std::string activation_time
Когда эта карта была впервые активирована (сырое значение счётчика).
std::string milk_counter
Количество напитков, выданных с этой карты.
std::string time_counter
Накопительный счётчик времени использования.
std::string machine_sn
Серийный номер диспенсера, на котором эта карта была активирована.
std::string mcu_uid
MCU UID собственного контроллера карты.
bool present
Отражают ли поля ниже реально считанную сейчас карту - зеркалит собственную защиту "ошибка rfid" в Mo...
std::string usage_time
Окно времени использования (сырое значение счётчика).
Ответ на RfidDataRequest: сырые данные RFID-карты.
static auto parse(const std::vector< uint8_t > &bytes) -> RfidDataReply
auto build() const -> std::vector< uint8_t >
Запрос UI -> backend: получить сырые данные текущей подключённой RFID-карты по требованию (почему это...
static auto build() -> std::vector< uint8_t >
static constexpr auto kTopic
static constexpr auto K_TOPIC
static auto parse(const std::vector< uint8_t > &) -> RfidDataRequest
Ответ на SnapshotRequest: полный снапшот состояния устройства.
static auto parse(const std::vector< uint8_t > &bytes) -> SnapshotReply
auto build() const -> std::vector< uint8_t >
Запрос UI -> backend: получить полный снапшот устройства по требованию.
static auto parse(const std::vector< uint8_t > &) -> SnapshotRequest
static auto build() -> std::vector< uint8_t >
static constexpr auto K_TOPIC
static constexpr auto kTopic
Универсальный ответ ok/error, переиспользуемый каждым запросом ниже, которому больше нечего сообщить ...
static auto parse(const std::vector< uint8_t > &bytes) -> StatusReply
auto build() const -> std::vector< uint8_t >
Запрос UI -> backend: переключить виртуальную тестовую плату (только для консольного тестирования).
static auto parse(const std::vector< uint8_t > &bytes) -> TestBoardOnlineRequest
static constexpr auto K_TOPIC
static constexpr auto kTopic
auto build() const -> std::vector< uint8_t >
Push backend -> UI: команда enable/disable.
static auto parse(const std::vector< uint8_t > &bytes) -> UiCommand
static constexpr auto K_TOPIC
auto build() const -> std::vector< uint8_t >