mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-05-08 22:35:00 +02:00
Support config introspection
This commit is contained in:
@@ -241,12 +241,39 @@ bool ReadlineComms::send(Message &m)
|
||||
case MessageType::SCAN_RESULT:
|
||||
p = _scan_result_str(m.payload.dump);
|
||||
break;
|
||||
case MessageType::CONFIG_TASK:
|
||||
p = m.payload.config.is_set ? "SET " : "GET ";
|
||||
p += *m.payload.config.key;
|
||||
if (m.payload.config.is_set)
|
||||
{
|
||||
p += " " + *m.payload.config.value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
serial.print(_wrap_str(p));
|
||||
return true;
|
||||
}
|
||||
|
||||
String _stringParam(String &p, String default_v)
|
||||
{
|
||||
p.trim();
|
||||
int i = p.indexOf(' ');
|
||||
if (i < 0)
|
||||
{
|
||||
i = p.length();
|
||||
}
|
||||
|
||||
String v = p.substring(0, i);
|
||||
p = p.substring(i + 1);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
v = default_v;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
int64_t _intParam(String &p, int64_t default_v)
|
||||
{
|
||||
p.trim();
|
||||
@@ -313,6 +340,28 @@ Message *_parsePacket(String p)
|
||||
m->payload.scan.delay = _intParam(p, -1);
|
||||
return m;
|
||||
}
|
||||
|
||||
if (cmd.equalsIgnoreCase("get"))
|
||||
{
|
||||
Message *m = new Message();
|
||||
m->type = MessageType::CONFIG_TASK;
|
||||
m->payload.config.is_set = false;
|
||||
m->payload.config.key = new String(_stringParam(p, ""));
|
||||
m->payload.config.value = NULL;
|
||||
return m;
|
||||
}
|
||||
|
||||
if (cmd.equalsIgnoreCase("set"))
|
||||
{
|
||||
Message *m = new Message();
|
||||
m->type = MessageType::CONFIG_TASK;
|
||||
m->payload.config.is_set = true;
|
||||
m->payload.config.key = new String(_stringParam(p, ""));
|
||||
m->payload.config.value = new String(_stringParam(p, ""));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -353,4 +402,16 @@ Message::~Message()
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == CONFIG_TASK)
|
||||
{
|
||||
delete payload.config.key;
|
||||
|
||||
if (payload.config.is_set)
|
||||
{
|
||||
delete payload.config.value;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user