comm & dc11 devices serialization (posix)
This commit is contained in:
parent
c31c74164e
commit
6261bfd893
4 changed files with 39 additions and 2 deletions
10
bus.cpp
10
bus.cpp
|
@ -70,7 +70,10 @@ JsonDocument bus::serialize() const
|
||||||
if (rk05_)
|
if (rk05_)
|
||||||
j_out["rk05"] = rk05_->serialize();
|
j_out["rk05"] = rk05_->serialize();
|
||||||
|
|
||||||
// TODO: tm11, dc11
|
if (dc11_)
|
||||||
|
j_out["dc11"] = dc11_->serialize();
|
||||||
|
|
||||||
|
// TODO: tm11
|
||||||
|
|
||||||
return j_out;
|
return j_out;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +106,10 @@ bus *bus::deserialize(const JsonDocument j, console *const cnsl, std::atomic_uin
|
||||||
if (j.containsKey("kw11-l"))
|
if (j.containsKey("kw11-l"))
|
||||||
b->add_KW11_L(kw11_l::deserialize(j["kw11-l"], b, cnsl));
|
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;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
8
comm.cpp
8
comm.cpp
|
@ -2,6 +2,7 @@
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "comm.h"
|
#include "comm.h"
|
||||||
|
@ -11,6 +12,9 @@
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include "comm_esp32_hardwareserial.h"
|
#include "comm_esp32_hardwareserial.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if IS_POSIX
|
||||||
|
#include "comm_posix_tty.h"
|
||||||
|
#endif
|
||||||
#include "comm_tcp_socket_client.h"
|
#include "comm_tcp_socket_client.h"
|
||||||
#include "comm_tcp_socket_server.h"
|
#include "comm_tcp_socket_server.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -53,6 +57,10 @@ comm *comm::deserialize(const JsonVariantConst j, bus *const b)
|
||||||
#if defined(ARDUINO)
|
#if defined(ARDUINO)
|
||||||
else if (type == "arduino")
|
else if (type == "arduino")
|
||||||
d = comm_arduino::deserialize(j);
|
d = comm_arduino::deserialize(j);
|
||||||
|
#endif
|
||||||
|
#if IS_POSIX
|
||||||
|
else if (type == "posix")
|
||||||
|
d = comm_posix_tty::deserialize(j);
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
DOLOG(warning, false, "comm::deserialize: \"%s\" not de-serialized", type.c_str());
|
DOLOG(warning, false, "comm::deserialize: \"%s\" not de-serialized", type.c_str());
|
||||||
|
|
|
@ -132,3 +132,23 @@ void comm_posix_tty::send_data(const uint8_t *const in, const size_t n)
|
||||||
len -= rc;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ public:
|
||||||
|
|
||||||
bool begin() override;
|
bool begin() override;
|
||||||
|
|
||||||
|
JsonDocument serialize() const override;
|
||||||
|
static comm_posix_tty *deserialize(const JsonVariantConst j);
|
||||||
|
|
||||||
std::string get_identifier() const override { return device; }
|
std::string get_identifier() const override { return device; }
|
||||||
|
|
||||||
bool is_connected() override;
|
bool is_connected() override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue