Skip to content

Commit

Permalink
add more functions to debug page
Browse files Browse the repository at this point in the history
  • Loading branch information
zivillian committed Jul 6, 2022
1 parent 3aa55d6 commit 85298e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
void sendResponseTrailer(AsyncResponseStream *response);
void sendButton(AsyncResponseStream *response, const char *title, const char *action, const char *css = "");
void sendTableRow(AsyncResponseStream *response, const char *name, uint32_t value);
void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, String function);
void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, String function, String count);
const String ErrorName(Modbus::Error code);
#endif /* PAGES_H */
37 changes: 25 additions & 12 deletions src/pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void setupPages(AsyncWebServer *server, ModbusClientRTU *rtu, ModbusBridgeWiFi *
dbgln("[webserver] GET /debug");
auto *response = request->beginResponseStream("text/html");
sendResponseHeader(response, "Debug");
sendDebugForm(response, "1", "1", "3");
sendDebugForm(response, "1", "1", "3", "1");
sendButton(response, "Back", "/");
sendResponseTrailer(response);
request->send(response);
Expand All @@ -246,13 +246,17 @@ void setupPages(AsyncWebServer *server, ModbusClientRTU *rtu, ModbusBridgeWiFi *
if (request->hasParam("func", true)){
func = request->getParam("func", true)->value();
}
String count = "1";
if (request->hasParam("count", true)){
count = request->getParam("count", true)->value();
}
auto *response = request->beginResponseStream("text/html");
sendResponseHeader(response, "Debug");
response->print("<pre>");
auto previous = LOGDEVICE;
auto debug = WebPrint(previous, response);
LOGDEVICE = &debug;
ModbusMessage answer = rtu->syncRequest(0xdeadbeef, slaveId.toInt(), func.toInt(), reg.toInt(), 1);
ModbusMessage answer = rtu->syncRequest(0xdeadbeef, slaveId.toInt(), func.toInt(), reg.toInt(), count.toInt());
LOGDEVICE = previous;
response->print("</pre>");
auto error = answer.getError();
Expand All @@ -268,7 +272,7 @@ void setupPages(AsyncWebServer *server, ModbusClientRTU *rtu, ModbusBridgeWiFi *
else{
response->printf("<span class=\"e\">Error: %#02x (%s)</span>", error, ErrorName(error));
}
sendDebugForm(response, slaveId, reg, func);
sendDebugForm(response, slaveId, reg, func, count);
sendButton(response, "Back", "/");
sendResponseTrailer(response);
request->send(response);
Expand Down Expand Up @@ -443,7 +447,7 @@ void sendTableRow(AsyncResponseStream *response, const char *name, uint32_t valu
"</tr>", name, value);
}

void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, String function){
void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, String function, String count){
response->print("<form method=\"post\">");
response->print("<table>"
"<tr>"
Expand All @@ -454,6 +458,19 @@ void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, St
response->printf("<input type=\"number\" min=\"0\" max=\"247\" id=\"slave\" name=\"slave\" value=\"%s\">", slaveId);
response->print("</td>"
"</tr>"
"<tr>"
"<td>"
"<label for=\"func\">Function</label>"
"</td>"
"<td>");
response->printf("<select id=\"func\" name=\"func\" data-value=\"%s\">", function);
response->print("<option value=\"1\">01 Read Coils</option>"
"<option value=\"2\">02 Read Discrete Inputs</option>"
"<option value=\"3\">03 Read Holding Register</option>"
"<option value=\"4\">04 Read Input Register</option>"
"</select>"
"</td>"
"</tr>"
"<tr>"
"<td>"
"<label for=\"reg\">Register</label>"
Expand All @@ -464,17 +481,13 @@ void sendDebugForm(AsyncResponseStream *response, String slaveId, String reg, St
"</tr>"
"<tr>"
"<td>"
"<label for=\"func\">Function</label>"
"<label for=\"count\">Count</label>"
"</td>"
"<td>");
response->printf("<select id=\"func\" name=\"func\" data-value=\"%s\">", function);
response->print(
"<option value=\"3\">03 Read Holding Register</option>"
"<option value=\"4\">04 Read Input Register</option>"
"</select>"
"</td>"
response->printf("<input type=\"number\" min=\"0\" max=\"65535\" id=\"count\" name=\"count\" value=\"%s\">", count);
response->print("</td>"
"</tr>"
"</table>");
"</table>");
response->print("<button class=\"r\">Send</button>"
"</form>"
"<p></p>");
Expand Down

0 comments on commit 85298e8

Please sign in to comment.