added Debug-CLI on WebUI

This commit is contained in:
Marcel Peterkau 2024-06-06 20:33:29 +02:00
parent 024a00e1bf
commit 0763fe2181
6 changed files with 101 additions and 62 deletions

View File

@ -159,8 +159,11 @@
<p>
<h4>Live Debug</h4>
<div class="form-group row">
<textarea class="form-control" spellcheck="false" id="livedebug-out" rows="3" readonly></textarea>
</div>
<input id="livedebug-in" type="text" class="set-wsevent data-livedebug-in form-control">
</div>
<div class="form-group row">
<textarea class="form-control" spellcheck="false" id="livedebug-out" rows="3" readonly></textarea>
</div>
<div class="form-group row">
<div class="col text-center">
<button id="debugstart" class="btn-wsevent btn btn-outline-primary ml-2">Start</button>

View File

@ -1,27 +1,42 @@
$(document).ready(function () {
$(".navbar-nav a").on("click", function () {
$(".navbar-collapse").collapse("hide");
});
$("#show_hide_password a").on("click", function (event) {
event.preventDefault();
if ($("#show_hide_password input").attr("type") == "text") {
$("#show_hide_password input").attr("type", "password");
$("#show_hide_password i").addClass("fa-eye-slash");
$("#show_hide_password i").removeClass("fa-eye");
} else if ($("#show_hide_password input").attr("type") == "password") {
$("#show_hide_password input").attr("type", "text");
$("#show_hide_password i").removeClass("fa-eye-slash");
$("#show_hide_password i").addClass("fa-eye");
}
});
// Event-Listener für Navbar-Links
$(".navbar-nav a").on("click", function () {
$(".navbar-collapse").collapse("hide");
});
document
.querySelector(".custom-file-input")
.addEventListener("change", function (e) {
var fileName = document.getElementById("fw-update-file").files[0].name;
var nextSibling = e.target.nextElementSibling;
nextSibling.innerText = fileName;
});
// Event-Listener für Passwort zeigen/verborgen
$("#show_hide_password a").on("click", function (event) {
event.preventDefault();
var inputField = $("#show_hide_password input");
var icon = $("#show_hide_password i");
if (inputField.attr("type") == "text") {
inputField.attr("type", "password");
icon.addClass("fa-eye-slash");
icon.removeClass("fa-eye");
} else if (inputField.attr("type") == "password") {
inputField.attr("type", "text");
icon.removeClass("fa-eye-slash");
icon.addClass("fa-eye");
}
});
// Event-Listener für Datei-Upload
$(".custom-file-input").on("change", function (e) {
var fileName = document.getElementById("fw-update-file").files[0].name;
var nextSibling = e.target.nextElementSibling;
nextSibling.innerText = fileName;
});
// Event-Listener für Live-Debug-Eingabe
$('#livedebug-in').on('keydown', function(event) {
if (event.key === 'Enter' || event.keyCode === 13) {
event.preventDefault(); // Verhindert, dass die Enter-Taste die Standardaktion ausführt (z.B. Absenden eines Formulars)
const command = $('#livedebug-in').val(); // Den Befehl aus dem Eingabefeld holen
executeCommand(command); // Den Befehl an die Funktion übergeben
$('#livedebug-in').val(''); // Leert das Eingabefeld
$('#livedebug-in').focus(); // Setzt den Fokus zurück auf das Eingabefeld
}
});
});

View File

@ -139,6 +139,10 @@ function websocket_sendevent(element_id, element_value) {
websocket.send(element_id + ":" + element_value);
}
function websocket_sendDebugCommand(command) {
websocket.send("debug-in:" + command);
}
function do_resize(textbox) {
var maxrows = 15;
var minrows = 3;

View File

@ -57,5 +57,5 @@ void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data);
void Debug_pushMessage(const char *format, ...);
void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status);
void Debug_Process();
void Debug_ProcessCommand(uint8_t *command);
#endif

View File

@ -525,6 +525,20 @@ void Debug_Reboot()
globals.systemStatus = sysStat_Shutdown;
}
/**
* @brief Processes a debug command.
*
* This function takes a pointer to a debug command and processes it by
* passing it to the `processCmdDebug` function. The command is expected
* to be a string, so it is cast to `const char *` before being processed.
*
* @param command Pointer to the debug command, expected to be a null-terminated string.
*/
void Debug_ProcessCommand(uint8_t *command)
{
processCmdDebug((const char *)command);
}
/**
* @brief Convert a uint32_t value to a binary string with nibbles separated by a space.
*

View File

@ -424,6 +424,10 @@ void Websocket_HandleMessage(void *arg, uint8_t *data, size_t len)
{
Websocket_HandleSettings(data + strlen("set-"));
}
else if (strncmp((char *)data, "debug", strlen("debug")) == 0)
{
Debug_ProcessCommand(data - strlen("debug"));
}
else
{
Debug_pushMessage("Got unknown Websocket-Message '%s' from client\n", (char *)data);
@ -604,44 +608,43 @@ void Websocket_RefreshClientData_DTCs(uint32_t client_id)
*/
void Websocket_RefreshClientData_Status(uint32_t client_id, bool send_mapping)
{
if (send_mapping)
{
const char mapping[] = "MAPPING_STATUS:"
"batterylevel;"
"systemstatus;"
"activefaction;"
"time_faction1;"
"time_faction2;"
"time_faction3;";
if (client_id > 0)
webSocket.text(client_id, mapping);
else
webSocket.textAll(mapping);
Debug_pushMessage("send MAPPING_STATUS WS-Client Data\n");
}
char dataString[200] = {0}; // Maximal 200 Zeichen für den Data-String
sprintf(dataString, "STATUS:%d;%s;%d;%ld;%ld;%ld;",
globals.battery_level,
globals.systemStatustxt,
PersistenceData.activeFaction,
PersistenceData.faction_1_timer,
PersistenceData.faction_2_timer,
PersistenceData.faction_3_timer);
if (send_mapping)
{
const char mapping[] = "MAPPING_STATUS:"
"batterylevel;"
"systemstatus;"
"activefaction;"
"time_faction1;"
"time_faction2;"
"time_faction3;";
if (client_id > 0)
{
webSocket.text(client_id, dataString);
}
webSocket.text(client_id, mapping);
else
{
webSocket.textAll(dataString);
}
}
webSocket.textAll(mapping);
Debug_pushMessage("send MAPPING_STATUS WS-Client Data\n");
}
char dataString[200] = {0}; // Maximal 200 Zeichen für den Data-String
sprintf(dataString, "STATUS:%d;%s;%d;%ld;%ld;%ld;",
globals.battery_level,
globals.systemStatustxt,
PersistenceData.activeFaction,
PersistenceData.faction_1_timer,
PersistenceData.faction_2_timer,
PersistenceData.faction_3_timer);
if (client_id > 0)
{
webSocket.text(client_id, dataString);
}
else
{
webSocket.textAll(dataString);
}
}
/**
* @brief Refreshes client data related to static configuration parameters on WebSocket clients.