comm & dc11 devices serialization (posix)

This commit is contained in:
folkert van heusden 2024-05-20 16:41:52 +02:00
parent c31c74164e
commit 6261bfd893
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
4 changed files with 39 additions and 2 deletions

10
bus.cpp
View file

@ -70,7 +70,10 @@ JsonDocument bus::serialize() const
if (rk05_)
j_out["rk05"] = rk05_->serialize();
// TODO: tm11, dc11
if (dc11_)
j_out["dc11"] = dc11_->serialize();
// TODO: tm11
return j_out;
}
@ -103,7 +106,10 @@ bus *bus::deserialize(const JsonDocument j, console *const cnsl, std::atomic_uin
if (j.containsKey("kw11-l"))
b->add_KW11_L(kw11_l::deserialize(j["kw11-l"], b, cnsl));
// TODO: tm11, dc11
if (j.containsKey("dc11"))
b->add_DC11(dc11::deserialize(j["dc11"], b));
// TODO: tm11
return b;
}

View file

@ -2,6 +2,7 @@
// Released under MIT license
#include "gen.h"
#include <cassert>
#include <cstring>
#include "comm.h"
@ -11,6 +12,9 @@
#if defined(ESP32)
#include "comm_esp32_hardwareserial.h"
#endif
#if IS_POSIX
#include "comm_posix_tty.h"
#endif
#include "comm_tcp_socket_client.h"
#include "comm_tcp_socket_server.h"
#include "log.h"
@ -53,6 +57,10 @@ comm *comm::deserialize(const JsonVariantConst j, bus *const b)
#if defined(ARDUINO)
else if (type == "arduino")
d = comm_arduino::deserialize(j);
#endif
#if IS_POSIX
else if (type == "posix")
d = comm_posix_tty::deserialize(j);
#endif
else {
DOLOG(warning, false, "comm::deserialize: \"%s\" not de-serialized", type.c_str());

View file

@ -132,3 +132,23 @@ void comm_posix_tty::send_data(const uint8_t *const in, const size_t n)
len -= rc;
}
}
JsonDocument comm_posix_tty::serialize() const
{
JsonDocument j;
j["comm-backend-type"] = "posix";
j["device"] = device;
j["bitrate"] = bitrate;
return j;
}
comm_posix_tty *comm_posix_tty::deserialize(const JsonVariantConst j)
{
comm_posix_tty *r = new comm_posix_tty(j["device"].as<std::string>(), j["bitrate"].as<int>());
r->begin(); // TODO error-checking
return r;
}

View file

@ -18,6 +18,9 @@ public:
bool begin() override;
JsonDocument serialize() const override;
static comm_posix_tty *deserialize(const JsonVariantConst j);
std::string get_identifier() const override { return device; }
bool is_connected() override;