Skip to content

Commit

Permalink
Limit WS calls to work with standard msg queue of 32 ;-) + improvements
Browse files Browse the repository at this point in the history
index.js: limit ws calls, group them in uiFunCommands

SysModSystem: clean up reset restart reasons

SysModUI
- processJson: uiFun is now an array of grouped objects instead of one by one

SysModWeb
- refactor: use web->getResponseDoc(); to get the task dependent responseDoc, make responseDoc0 and responseDoc1 private
  • Loading branch information
ewoudwijma committed Jul 26, 2023
1 parent 8e1efcb commit ae0b2e2
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 409 deletions.
3 changes: 2 additions & 1 deletion data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ function preview3D(node, leds) {
}

if (jsonValues.pview) {
renderer.setSize( gId("pview").width, gId("pview").height);
if (renderer.width != gId("pview").width || renderer.height != gId("pview").height)
renderer.setSize( gId("pview").width, gId("pview").height);
//light up the cube
let firstLed = 4;
var i = 1;
Expand Down
43 changes: 25 additions & 18 deletions data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,32 @@ comment {
margin-left: 6px; /*space before*/
}

text { /*currently onlu for buttonSaveNode and buttonCancelNode*/
text { /*currently only for buttonSaveNode and buttonCancelNode*/
font-size: 10px;
}


/* For textarea objects */
textarea {
width: 100%;
height: 100%;
}

/* for toggleModal */
.modal {
position:fixed;
left: 0px;
bottom: 0px;
right: 0px;
top: 0px;
/* calc(var(--th) - 1px); */
background-color: var(--c-o);
transform: translateY(100%);
transition: transform 0.4s;
padding: 8px;
font-size: 18px; /* WLEDMM: smaller is better (was 20px)*/
overflow: auto;
}

/*table layout */
.table-style {
font-family: Arial, Helvetica, sans-serif;
Expand Down Expand Up @@ -87,7 +109,7 @@ text { /*currently onlu for buttonSaveNode and buttonCancelNode*/
--c-l: #48a;
--c-y: #a90;
--t-b: 0.5;
--c-o: rgba(34, 34, 34, 0.9);
--c-o: rgba(195, 145, 145, 0.9); /* used for modal background, changed to more readable*/
--c-tb : rgba(34, 34, 34, var(--t-b));
--c-tba: rgba(102, 102, 102, var(--t-b));
--c-tbh: rgba(51, 51, 51, var(--t-b));
Expand All @@ -112,18 +134,3 @@ text { /*currently onlu for buttonSaveNode and buttonCancelNode*/
z-index: -2;
}

/* for toggleModal */
.modal {
position:fixed;
left: 0px;
bottom: 0px;
right: 0px;
top: 0px;
/* calc(var(--th) - 1px); */
background-color: var(--c-o);
transform: translateY(100%);
transition: transform 0.4s;
padding: 8px;
font-size: 18px; /* WLEDMM: smaller is better (was 20px)*/
overflow: auto;
}
36 changes: 23 additions & 13 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let nrOfColumns = 4;
let userFunId = "";
let htmlGenerated = false;
let jsonValues = {};
let uiFunCommands = [];

function gId(c) {return d.getElementById(c);}
function cE(e) { return d.createElement(e); }
Expand Down Expand Up @@ -41,6 +42,10 @@ function makeWS() {
console.log("WS receive generateHTML", json);
generateHTML(null, json); //no parentNode
htmlGenerated = true;
//send request for uiFun
if (uiFunCommands.length) { //flush commands not already send
flushUIFunCommands();
}
}
else
console.log("Error: no array", json);
Expand Down Expand Up @@ -179,7 +184,7 @@ function generateHTML(parentNode, json) {
newNode.appendChild(spanNode);
}
}
else { //not ro
else { //not ro or button
newNode = cE("p");
let buttonSaveNode = null;
let buttonCancelNode = null;
Expand Down Expand Up @@ -221,16 +226,24 @@ function generateHTML(parentNode, json) {

//call ui Functionality, if defined (to set label, comment, lov etc)
if (json.uiFun >= 0) { //>=0 as element in object
var command = {};
command["uiFun"] = json.id; //ask to run uiFun for object (to add the options)
requestJson(command);
uiFunCommands.push(json.id);
if (uiFunCommands.length > 8) { //every 10 objects (to respect responseDoc size) check WS_EVT_DATA info
flushUIFunCommands();
}
}

if (json.n) generateHTML(newNode, json.n); //details (e.g. module)

}
}

function flushUIFunCommands() {
var command = {};
command["uiFun"] = uiFunCommands; //ask to run uiFun for object (to add the options)
console.log("uiFunCommands", command);
requestJson(command);
uiFunCommands = [];
}

function processUpdate(json) {
// console.log("processUpdate", json);
for (var key of Object.keys(json)) {
Expand Down Expand Up @@ -271,7 +284,7 @@ function processUpdate(json) {
}
if (json[key].lov) {
console.log("processUpdate lov", key, json[key].lov);
if (gId(key).nodeName.toLocaleLowerCase() == "span") { //readonly tbd: only the displayed value needs to be in the lov
if (gId(key).nodeName.toLocaleLowerCase() == "span") { //readonly. tbd: only the displayed value needs to be in the lov
var index = 0;
for (var value of json[key].lov) {
if (parseInt(gId(key).textContent) == index) {
Expand All @@ -290,8 +303,6 @@ function processUpdate(json) {
gId(key).remove(0);
}
for (var value of json[key].lov) {
if (key=="reset0")
console.log("processUpdate lov3", value, gId(key), gId(key).textContent, index);
let optNode = cE("option");
optNode.value = index;
optNode.text = value;
Expand All @@ -317,9 +328,9 @@ function processUpdate(json) {
gId(key).replaceChild(tbodyNode, gId(key).lastChild); //replace <table><tbody>
}
if (json[key].value && !overruleValue) { //after lov, in case used
if (key=="ledFix" || key =="ledFixGen" || key =="reset0")
if (key=="ledFix" || key =="ledFixGen")
console.log("processUpdate value", key, json[key].value, gId(key));
if (gId(key).nodeName.toLocaleLowerCase() == "span") //display
if (gId(key).nodeName.toLocaleLowerCase() == "span") //read only objects
gId(key).textContent = json[key].value;
else if (gId(key).nodeName.toLocaleLowerCase() == "canvas") {
userFunId = key; //prepare for websocket data
Expand All @@ -337,7 +348,7 @@ function processUpdate(json) {

//we need to send a request which the server can handle using request variable
let url = `http://${window.location.hostname}/file`;
fetchAndExecute(url, json[key].file, jsonValues, function(jsonValues,text) {
fetchAndExecute(url, json[key].file, key, function(key,text) { //send key as parameter
// console.log("fetchAndExecute", text); //in case of invalid json
var ledmapJson = JSON.parse(text);
jsonValues[key] = ledmapJson;
Expand Down Expand Up @@ -427,7 +438,6 @@ function toggleModal(element) {
modalPlaceHolder.width = element.width;
modalPlaceHolder.height = element.height;

console.log("replaceChild", element, element.parentNode, modalPlaceHolder);
element.parentNode.replaceChild(modalPlaceHolder, element);

gId('modalView').appendChild(element);
Expand Down
6 changes: 4 additions & 2 deletions src/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ class AppModLeds:public Module {
mdl->setValueI("nrOfLeds", nrOfLeds);

//send to pview a message to get file filename
JsonVariant responseVariant = (strncmp(pcTaskGetTaskName(NULL), "loopTask", 8) != 0?web->responseDoc0:web->responseDoc1)->as<JsonVariant>();
(strncmp(pcTaskGetTaskName(NULL), "loopTask", 8) != 0?web->responseDoc0:web->responseDoc1)->clear();
JsonDocument *responseDoc = web->getResponseDoc();
responseDoc->clear(); //needed for deserializeJson?
JsonVariant responseVariant = responseDoc->as<JsonVariant>();

web->addResponse("pview", "file", fileName);
web->sendDataWs(responseVariant);
print->printJson("ledfix chFun send ws done", responseVariant); //during server startup this is not send to a client, so client refresh should also trigger this
Expand Down
1 change: 0 additions & 1 deletion src/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void SysModFiles::loop(){
filesChanged = false;

ui->processUiFun("flist");

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SysModModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ JsonObject SysModModel::setValueB(const char * id, bool value) {
}

//Set value with argument list
JsonObject SysModModel::setValueV(const char * id, const char * format, ...) { //static to use in *Fun
JsonObject SysModModel::setValueV(const char * id, const char * format, ...) {
va_list args;
va_start(args, format);

Expand Down Expand Up @@ -210,7 +210,7 @@ JsonVariant SysModModel::getValue(const char * id) {
}
}

JsonObject SysModModel::findObject(const char * id, JsonArray parent) { //static for processJson
JsonObject SysModModel::findObject(const char * id, JsonArray parent) {
JsonArray root;
// print ->print("findObject %s %s\n", id, parent.isNull()?"root":"n");
if (parent.isNull()) {
Expand Down
4 changes: 2 additions & 2 deletions src/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class SysModModel:public Module {
static JsonObject setValueB(const char * id, bool value);

//Set value with argument list
static JsonObject setValueV(const char * id, const char * format, ...);
static JsonObject setValueV(const char * id, const char * format, ...); //static to use in *Fun

//Set value with argument list and print
JsonObject setValueP(const char * id, const char * format, ...);

JsonVariant getValue(const char * id);

//returns the object defined by id (parent to recursively call findObject)
static JsonObject findObject(const char * id, JsonArray parent = JsonArray());
static JsonObject findObject(const char * id, JsonArray parent = JsonArray()); //static for processJson

private:
static bool doWriteModel;
Expand Down
72 changes: 40 additions & 32 deletions src/SysModSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,20 @@ void SysModSystem::setup() {
});

ui->initSelect(parentObject, "reset0", (int)rtc_get_reset_reason(0), true, [](JsonObject object) { //uiFun
web->addResponse(object["id"], "comment", "Reset reason core 0");
web->addResponse(object["id"], "label", "Reset 0");
web->addResponse(object["id"], "comment", "Reason Core 0");
sys->addResetReasonsLov(web->addResponseA(object["id"], "lov"));
});
if (ESP.getChipCores() > 1)
ui->initSelect(parentObject, "reset1", (int)rtc_get_reset_reason(1), true, [](JsonObject object) { //uiFun
web->addResponse(object["id"], "comment", "Reset reason core 1");
web->addResponse(object["id"], "label", "Reset 1");
web->addResponse(object["id"], "comment", "Reason Core 1");
sys->addResetReasonsLov(web->addResponseA(object["id"], "lov"));
});
ui->initSelect(parentObject, "restartReason", (int)esp_reset_reason(), true, [](JsonObject object) { //uiFun
web->addResponse(object["id"], "comment", "Restart reason");
JsonArray lov = web->addResponseA(object["id"], "lov");
lov.add("ESP_RST_UNKNOWN");// //!< Reset reason can not be determined
lov.add("ESP_RST_POWERON");// //!< Reset due to power-on event
lov.add("ESP_RST_EXT");// //!< Reset by external pin (not applicable for ESP32)
lov.add("ESP_RST_SW");// //!< Software reset via esp_restart
lov.add("ESP_RST_PANIC");// //!< Software reset due to exception/panic
lov.add("ESP_RST_INT_WDT");// //!< Reset (software or hardware) due to interrupt watchdog
lov.add("ESP_RST_TASK_WDT");// //!< Reset due to task watchdog
lov.add("ESP_RST_WDT");// //!< Reset due to other watchdogs
lov.add("ESP_RST_DEEPSLEEP");////!< Reset after exiting deep sleep mode
lov.add("ESP_RST_BROWNOUT");// //!< Brownout reset (software or hardware)
lov.add("ESP_RST_SDIO");// //!< Reset over SDIO

web->addResponse(object["id"], "label", "Restart");
web->addResponse(object["id"], "comment", "Reason restart");
sys->addRestartReasonsLov(web->addResponseA(object["id"], "lov"));
});

// static char msgbuf[32];
Expand Down Expand Up @@ -92,21 +83,38 @@ void SysModSystem::loop() {
}
}

//replace code by sentence as soon it occurs, so we know what will happen and what not
void SysModSystem::addResetReasonsLov(JsonArray lov) {
lov.add("NO_MEAN"); // 0,
lov.add("POWERON_RESET"); // 1, /**<1, Vbat power on reset*/
lov.add("SW_RESET"); // 3, /**<3, Software reset digital core*/
lov.add("OWDT_RESET"); // 4, /**<4, Legacy watch dog reset digital core*/
lov.add("DEEPSLEEP_RESET"); // 5, /**<3, Deep Sleep reset digital core*/
lov.add("SDIO_RESET"); // 6, /**<6, Reset by SLC module, reset digital core*/
lov.add("TG0WDT_SYS_RESET"); // 7, /**<7, Timer Group0 Watch dog reset digital core*/
lov.add("TG1WDT_SYS_RESET"); // 8, /**<8, Timer Group1 Watch dog reset digital core*/
lov.add("RTCWDT_SYS_RESET"); // 9, /**<9, RTC Watch dog Reset digital core*/
lov.add("INTRUSION_RESET"); //10, /**<10, Instrusion tested to reset CPU*/
lov.add("TGWDT_CPU_RESET"); //11, /**<11, Time Group reset CPU*/
lov.add("SW_CPU_RESET"); //12, /**<12, Software reset CPU*/
lov.add("RTCWDT_CPU_RESET"); //13, /**<13, RTC Watch dog Reset CPU*/
lov.add("EXT_CPU_RESET"); //14, /**<14, for APP CPU, reseted by PRO CPU*/
lov.add("RTCWDT_BROWN_OUT_RESET"); //15, /**<15, Reset when the vdd voltage is not stable*/
lov.add("RTCWDT_RTC_RESET"); //16 /**<16, RTC Watch dog reset digital core and rtc module*/
lov.add("NO_MEAN"); // 0,
lov.add("POWERON_RESET"); // 1, /**<1, Vbat power on reset*/
lov.add("SW_RESET (2)"); // 2, /**<3, Software reset digital core*/
lov.add("SW_RESET (3)"); // 3, /**<3, Software reset digital core*/
lov.add("OWDT_RESET"); // 4, /**<4, Legacy watch dog reset digital core*/
lov.add("DEEPSLEEP_RESET"); // 5, /**<3, Deep Sleep reset digital core*/
lov.add("SDIO_RESET"); // 6, /**<6, Reset by SLC module, reset digital core*/
lov.add("TG0WDT_SYS_RESET"); // 7, /**<7, Timer Group0 Watch dog reset digital core*/
lov.add("TG1WDT_SYS_RESET"); // 8, /**<8, Timer Group1 Watch dog reset digital core*/
lov.add("RTCWDT_SYS_RESET"); // 9, /**<9, RTC Watch dog Reset digital core*/
lov.add("INTRUSION_RESET"); //10, /**<10, Instrusion tested to reset CPU*/
lov.add("TGWDT_CPU_RESET"); //11, /**<11, Time Group reset CPU*/
lov.add("SW reset CPU (12)");//SW_CPU_RESET"); //12, /**<12, */
lov.add("RTCWDT_CPU_RESET"); //13, /**<13, RTC Watch dog Reset CPU*/
lov.add("EXT_CPU_RESET"); //14, /**<14, for APP CPU, reseted by PRO CPU*/
lov.add("RTCWDT_BROWN_OUT_RESET"); //15, /**<15, Reset when the vdd voltage is not stable*/
lov.add("RTCWDT_RTC_RESET"); //16 /**<16, RTC Watch dog reset digital core and rtc module*/
}

//replace code by sentence as soon it occurs, so we know what will happen and what not
void SysModSystem::addRestartReasonsLov(JsonArray lov) {
lov.add("ESP_RST_UNKNOWN");// //!< Reset reason can not be determined
lov.add("ESP_RST_POWERON");// //!< Reset due to power-on event
lov.add("ESP_RST_EXT");// //!< Reset by external pin (not applicable for ESP32)
lov.add("ESP_RST_SW");// //!< Software reset via esp_restart
lov.add("SW reset due to exception/panic (4)");//ESP_RST_PANIC");// //!<
lov.add("ESP_RST_INT_WDT");// //!< Reset (software or hardware) due to interrupt watchdog
lov.add("ESP_RST_TASK_WDT");// //!< Reset due to task watchdog
lov.add("ESP_RST_WDT");// //!< Reset due to other watchdogs
lov.add("ESP_RST_DEEPSLEEP");////!< Reset after exiting deep sleep mode
lov.add("ESP_RST_BROWNOUT");// //!< Brownout reset (software or hardware)
lov.add("ESP_RST_SDIO");// //!< Reset over SDIO
}
1 change: 1 addition & 0 deletions src/SysModSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SysModSystem:public Module {
unsigned long loopCounter = 0;

void addResetReasonsLov(JsonArray lov);
void addRestartReasonsLov(JsonArray lov);

};

Expand Down
Loading

0 comments on commit ae0b2e2

Please sign in to comment.