Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions core/src/plc_app/unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res
{
if (strcmp(command, "PING") == 0)
{
log_debug("Received PING command");
strncpy(response, "PING:OK\n", response_size);
}
else if (strcmp(command, "STATUS") == 0)
{
log_debug("Received STATUS command");
PLCState current_state = plc_get_state();

if (current_state == PLC_STATE_INIT)
Expand All @@ -68,15 +66,13 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res
}
else if (strcmp(command, "STOP") == 0)
{
log_debug("Received STOP command");
if (plc_set_state(PLC_STATE_STOPPED))
strncpy(response, "STOP:OK\n", response_size);
else
strncpy(response, "STOP:ERROR\n", response_size);
}
else if (strcmp(command, "START") == 0)
{
log_debug("Received START command");
PLCState current_state = plc_get_state();
if (current_state != PLC_STATE_RUNNING)
{
Expand All @@ -97,12 +93,10 @@ void handle_unix_socket_commands(const char *command, char *response, size_t res
}
else if (strcmp(command, "STATS") == 0)
{
log_debug("Received STATS command");
format_timing_stats_response(response, response_size);
}
else if (strncmp(command, "DEBUG:", 6) == 0)
{
log_debug("Received DEBUG command");
uint8_t debug_data[4096] = {0};
size_t data_length = parse_hex_string(&command[6], debug_data);
if (data_length > 0)
Expand Down Expand Up @@ -181,8 +175,6 @@ void *unix_socket_thread(void *arg)
ssize_t bytes_read = read_line(client_fd, command_buffer, COMMAND_BUFFER_SIZE);
if (bytes_read > 0)
{
log_debug("Received command: %s", command_buffer);

// Handle the command
char response[MAX_RESPONSE_SIZE] = {0};
handle_unix_socket_commands(command_buffer, response, MAX_RESPONSE_SIZE);
Expand Down
14 changes: 9 additions & 5 deletions webserver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ def handle_status(data: dict) -> dict:

result: dict = {"status": response}

# Fetch timing stats and include them in the response
stats_response = runtime_manager.stats_plc()
timing_stats = parse_timing_stats(stats_response)
if timing_stats is not None:
result["timing_stats"] = timing_stats
# Only fetch timing stats if explicitly requested via include_stats parameter.
# This avoids acquiring the stats mutex on every status poll, which could
# introduce latency to the critical PLC scan cycle.
include_stats = data.get("include_stats", "").lower() == "true"
if include_stats:
stats_response = runtime_manager.stats_plc()
timing_stats = parse_timing_stats(stats_response)
if timing_stats is not None:
result["timing_stats"] = timing_stats

return result

Expand Down