diff --git a/bus.cpp b/bus.cpp index ecbff8e..dff1b16 100644 --- a/bus.cpp +++ b/bus.cpp @@ -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; } diff --git a/comm.cpp b/comm.cpp index 93d08d9..dc1f536 100644 --- a/comm.cpp +++ b/comm.cpp @@ -2,6 +2,7 @@ // Released under MIT license #include "gen.h" +#include #include #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()); diff --git a/comm_posix_tty.cpp b/comm_posix_tty.cpp index ca8e610..86b62a6 100644 --- a/comm_posix_tty.cpp +++ b/comm_posix_tty.cpp @@ -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(), j["bitrate"].as()); + r->begin(); // TODO error-checking + + return r; +} diff --git a/comm_posix_tty.h b/comm_posix_tty.h index 2a01884..4c0d15f 100644 --- a/comm_posix_tty.h +++ b/comm_posix_tty.h @@ -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;