tty new serialization
This commit is contained in:
parent
a53634e541
commit
2b42258ae0
2 changed files with 19 additions and 22 deletions
32
tty.cpp
32
tty.cpp
|
@ -194,20 +194,19 @@ void tty::write_word(const uint16_t addr, uint16_t v)
|
||||||
registers[(addr - PDP11TTY_BASE) / 2] = v;
|
registers[(addr - PDP11TTY_BASE) / 2] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IS_POSIX
|
JsonDocument tty::serialize()
|
||||||
json_t *tty::serialize()
|
|
||||||
{
|
{
|
||||||
json_t *j = json_object();
|
JsonDocument j;
|
||||||
|
|
||||||
json_t *ja_reg = json_array();
|
JsonArray ja_reg;
|
||||||
for(size_t i=0; i<4; i++)
|
for(size_t i=0; i<4; i++)
|
||||||
json_array_append(ja_reg, json_integer(registers[i]));
|
ja_reg.add(registers[i]);
|
||||||
json_object_set(j, "registers", ja_reg);
|
j["registers"] = ja_reg;
|
||||||
|
|
||||||
json_t *ja_buf = json_array();
|
JsonArray ja_buf;
|
||||||
for(auto & c: chars)
|
for(auto & c: chars)
|
||||||
json_array_append(ja_buf, json_integer(c));
|
ja_buf.add(c);
|
||||||
json_object_set(j, "input-buffer", ja_buf);
|
j["input-buffer"] = ja_buf;
|
||||||
|
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
@ -216,15 +215,14 @@ tty *tty::deserialize(const json_t *const j, bus *const b, console *const cnsl)
|
||||||
{
|
{
|
||||||
tty *out = new tty(cnsl, b);
|
tty *out = new tty(cnsl, b);
|
||||||
|
|
||||||
json_t *ja_reg = json_object_get(j, "registers");
|
JsonArray ja_reg = j["registers"];
|
||||||
for(size_t i=0; i<4; i++)
|
int i_reg = 0;
|
||||||
out->registers[i] = json_integer_value(json_array_get(ja_reg, i));
|
for(auto v: ja_reg)
|
||||||
|
out->registers[i_reg++] = v;
|
||||||
|
|
||||||
json_t *ja_buf = json_object_get(j, "input-buffer");
|
JsonArray ja_buf = j["input-buffer"];
|
||||||
size_t buf_size = json_array_size(ja_buf);
|
for(auto v: ja_buf)
|
||||||
for(size_t i=0; i<buf_size; i++)
|
out->chars.push_back(v);
|
||||||
out->chars.push_back(json_integer_value(json_array_get(ja_buf, i)));
|
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
7
tty.h
7
tty.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -51,10 +52,8 @@ public:
|
||||||
tty(console *const c, bus *const b);
|
tty(console *const c, bus *const b);
|
||||||
virtual ~tty();
|
virtual ~tty();
|
||||||
|
|
||||||
#if IS_POSIX
|
JsonDocument serialize();
|
||||||
json_t *serialize();
|
static tty *deserialize(const JsonDocument j, bus *const b, console *const cnsl);
|
||||||
static tty *deserialize(const json_t *const j, bus *const b, console *const cnsl);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue