Device list and selection integrated into configuration interface
This commit is contained in:
@@ -99,7 +99,7 @@ void webserver_init() {
|
||||
});
|
||||
|
||||
server.on("/api/config", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
StaticJsonDocument<512> doc;
|
||||
StaticJsonDocument<1024> doc;
|
||||
doc["systemName"] = config.getString("systemName");
|
||||
doc["systemMode"] = String(config.getChar("systemMode"));
|
||||
doc["logLevel"] = loglevel;
|
||||
@@ -130,6 +130,9 @@ void webserver_init() {
|
||||
doc["key4long"] = longcode[BUTTON_4];
|
||||
doc["key5long"] = longcode[BUTTON_5];
|
||||
doc["key6long"] = longcode[BUTTON_6];
|
||||
doc["n2kDestA"] = config.getString("n2kDestA");
|
||||
doc["n2kDestB"] = config.getString("n2kDestB");
|
||||
doc["n2kDestC"] = config.getString("n2kDestC");
|
||||
doc["envInterval"] = config.getShort("envInterval");
|
||||
String out;
|
||||
serializeJson(doc, out);
|
||||
@@ -230,7 +233,7 @@ void webserver_init() {
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
response->print("[");
|
||||
bool first = true;
|
||||
for (int i = 0; i <= 252; i++) {
|
||||
for (uint8_t i = 0; i <= 252; i++) {
|
||||
const tNMEA2000::tDevice *d = pN2kDeviceList->FindDeviceBySource(i);
|
||||
if (d == nullptr) {
|
||||
continue;
|
||||
@@ -244,8 +247,36 @@ void webserver_init() {
|
||||
first = false;
|
||||
}
|
||||
// TODO last seen?
|
||||
response->printf("{\"source\":%d,\"name\":\"%s\",\"manuf\":\"%d\",\"model\":\"%s\"}",
|
||||
i, hex_name, d->GetManufacturerCode(), d->GetModelID());
|
||||
uint16_t mfcode = d->GetManufacturerCode();
|
||||
// TODO RAW-String!
|
||||
response->printf("{\"source\":%d,\"name\":\"%s\",\"manufcode\":\"%d\",\"model\":\"%s\",\"manufname\":\"%s\"}",
|
||||
i, hex_name, mfcode, d->GetModelID(), NMEA2000.GetManufacturerName(mfcode));
|
||||
}
|
||||
response->print("]");
|
||||
request->send(response);
|
||||
});
|
||||
|
||||
server.on("/api/dyndevlist", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
// NMEA2000 dynmic config list: devices
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
response->print("[");
|
||||
bool first = true;
|
||||
for (uint8_t i = 0; i <= 252; i++) {
|
||||
const tNMEA2000::tDevice *d = pN2kDeviceList->FindDeviceBySource(i);
|
||||
if (d == nullptr) {
|
||||
continue;
|
||||
}
|
||||
uint64_t NAME = d->GetName();
|
||||
char hex_name[17];
|
||||
snprintf(hex_name, sizeof(hex_name), "%08X%08X", (uint32_t)(NAME >> 32), (uint32_t)(NAME & 0xFFFFFFFF));
|
||||
if (!first) {
|
||||
response->print(",");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
uint16_t mfcode = d->GetManufacturerCode();
|
||||
response->printf(R"DELIM({"v":"%s","l":"%s - %s (%d)"})DELIM",
|
||||
hex_name, d->GetModelID(), NMEA2000.GetManufacturerName(mfcode), mfcode);
|
||||
}
|
||||
response->print("]");
|
||||
request->send(response);
|
||||
|
||||
Reference in New Issue
Block a user