Skip to content

Commit

Permalink
Master flags
Browse files Browse the repository at this point in the history
Remove minimal change over error connection flag to limit the amount of messages sent by the server, without losing control functionality
  • Loading branch information
digitecomg committed Oct 30, 2024
1 parent 960e64e commit 2cde454
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion platformio/stima_v4/master/include/tasks/mqtt_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#define MQTT_TASK_PUBLISH_DELAY_MS (5)
#define MQTT_TASK_PUBLISH_RETRY (5)

#define MIN_ERR_CAN_CHECK_FLAG_PERC (10)

/*!
\def USE_MINIMAL_WAIT_SECOND_CONNECT
\brief Enable using function delay minimal second waiting maintenance MQTT connection active
Expand All @@ -56,7 +58,7 @@
#define MQTT_NET_WAIT_TIMEOUT_SUSPEND (120000) // Time out mqtt suspend operation timeout
#define MQTT_NET_WAIT_TIMEOUT_PUBLISH (MQTT_TIMEOUT_MS + 2500) // Time out mqtt suspend operation timeout

#define MIN_ERR_REPORT_CONNECTION_VALID (90.0)
#define MIN_ERR_REPORT_CONNECTION_VALID (80)

#define MQTT_PUB_CMD_DEBUG_PREFIX (">")
#define MQTT_SUB_CMD_DEBUG_PREFIX ("<")
Expand Down
2 changes: 2 additions & 0 deletions platformio/stima_v4/master/include/tasks/supervisor_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#define SUPERVISOR_TASK_DEEP_POWER_DELAY_MS (5000)
#define SUPERVISOR_TASK_SLEEP_DELAY_MS (1000)

#define MIN_ATTEMPTED_CONNECTION_VALID (5)

#if (ENABLE_I2C1 || ENABLE_I2C2)
#include <Wire.h>
#include "drivers/eeprom.h"
Expand Down
9 changes: 7 additions & 2 deletions platformio/stima_v4/master/src/tasks/mqtt_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ void MqttTask::Run()
if(param.system_status->modem.perc_modem_connection_valid >= MIN_ERR_REPORT_CONNECTION_VALID) {
byteState[indexPosition++] = 0;
} else {
byteState[indexPosition++] = 100 - param.system_status->modem.perc_modem_connection_valid;
// Flags step error only 10% value (10, 20, 30 .. 100 %) prevert small change error for flag byte index server
byteState[indexPosition++] = (uint8_t)((100.0 - (float)param.system_status->modem.perc_modem_connection_valid) / 10.0) * 10;
}
byteState[indexPosition++] = param.boot_request->tot_reset;
byteState[indexPosition++] = param.boot_request->wdt_reset;
Expand Down Expand Up @@ -489,7 +490,11 @@ void MqttTask::Run()
}
indexPosition = 0;
// Report inverted OK (100- for Error...)
byteState[indexPosition++] = param.system_status->data_slave[iNodeSlave].perc_can_comm_err;
if(param.system_status->data_slave[iNodeSlave].perc_can_comm_err <= MIN_ERR_CAN_CHECK_FLAG_PERC) {
byteState[indexPosition++] = 0;
} else {
byteState[indexPosition++] = param.system_status->data_slave[iNodeSlave].perc_can_comm_err;
}
byteState[indexPosition++] = param.system_status->data_slave[iNodeSlave].byteStateFlag[0];
byteState[indexPosition++] = param.system_status->data_slave[iNodeSlave].byteStateFlag[1];
byteState[indexPosition] = param.system_status->data_slave[iNodeSlave].byteStateFlag[2];
Expand Down
5 changes: 2 additions & 3 deletions platformio/stima_v4/master/src/tasks/supervisor_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void SupervisorTask::Run()
param.system_status->command.do_mqtt_connect = false;
param.system_status->command.do_ntp_synchronization = false;

if(param.system_status->modem.connection_attempted) {
if(param.system_status->modem.connection_attempted > MIN_ATTEMPTED_CONNECTION_VALID) {
param.system_status->modem.perc_modem_connection_valid = (uint8_t)
(((float)(param.system_status->modem.connection_completed / (float)param.system_status->modem.connection_attempted)) * 100.0);
} else {
Expand Down Expand Up @@ -347,8 +347,7 @@ void SupervisorTask::Run()
state = SUPERVISOR_STATE_CONNECTION_OPERATION;

// Update percentage good connection vs attemtped
param.systemStatusLock->Take();
if(param.system_status->modem.connection_attempted) {
if(param.system_status->modem.connection_attempted > MIN_ATTEMPTED_CONNECTION_VALID) {
param.system_status->modem.perc_modem_connection_valid = (uint8_t)
(((float)(param.system_status->modem.connection_completed / (float)param.system_status->modem.connection_attempted)) * 100.0);
} else {
Expand Down

0 comments on commit 2cde454

Please sign in to comment.