From c2458a6d6f37231766a34c35313d9a9f1778724b Mon Sep 17 00:00:00 2001 From: digitecomg Date: Mon, 1 Jul 2024 18:47:52 +0200 Subject: [PATCH] WindClass check round Check value (fix round unlikely error) on WindClass --- .../stima_v4/master/src/tasks/mqtt_task.cpp | 18 ------- .../stima_v4/slave-wind/include/config.h | 2 +- .../src/tasks/elaborate_data_task.cpp | 50 ++++++++++++++++++- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/platformio/stima_v4/master/src/tasks/mqtt_task.cpp b/platformio/stima_v4/master/src/tasks/mqtt_task.cpp index 6070fec2a..cb217a92c 100644 --- a/platformio/stima_v4/master/src/tasks/mqtt_task.cpp +++ b/platformio/stima_v4/master/src/tasks/mqtt_task.cpp @@ -2440,24 +2440,6 @@ error_t MqttTask::makeSensorMessageClassSpeed(rmap_sensors_WindClassSpeed_1_0 se error = ERROR_FAILURE; } - // Check block limit for table area data if valid - if ((sensor.class1.val.value <= rmap_tableb_B11211_1_0_MAX) || - (sensor.class2.val.value <= rmap_tableb_B11212_1_0_MAX) || - (sensor.class3.val.value <= rmap_tableb_B11213_1_0_MAX) || - (sensor.class4.val.value <= rmap_tableb_B11214_1_0_MAX) || - (sensor.class5.val.value <= rmap_tableb_B11215_1_0_MAX) || - (sensor.class6.val.value <= rmap_tableb_B11216_1_0_MAX)) { - if (sensor.class1.val.value > rmap_tableb_B11211_1_0_MAX) sensor.class1.val.value = 0; - if (sensor.class2.val.value > rmap_tableb_B11212_1_0_MAX) sensor.class2.val.value = 0; - if (sensor.class3.val.value > rmap_tableb_B11213_1_0_MAX) sensor.class3.val.value = 0; - if (sensor.class4.val.value > rmap_tableb_B11214_1_0_MAX) sensor.class4.val.value = 0; - if (sensor.class5.val.value > rmap_tableb_B11215_1_0_MAX) sensor.class5.val.value = 0; - if (sensor.class6.val.value > rmap_tableb_B11216_1_0_MAX) sensor.class6.val.value = 0; - uint8_t chkVal = sensor.class1.val.value + sensor.class2.val.value + sensor.class3.val.value + - sensor.class4.val.value + sensor.class5.val.value + sensor.class6.val.value; - if(chkVal != rmap_tableb_B11216_1_0_MAX) sensor.class1.val.value += (rmap_tableb_B11216_1_0_MAX - chkVal); - } - if (!error) { if (sensor.class1.val.value <= rmap_tableb_B11211_1_0_MAX) diff --git a/platformio/stima_v4/slave-wind/include/config.h b/platformio/stima_v4/slave-wind/include/config.h index 9dcf00b68..86764c011 100644 --- a/platformio/stima_v4/slave-wind/include/config.h +++ b/platformio/stima_v4/slave-wind/include/config.h @@ -34,7 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define MODULE_MAIN_VERSION (4) /// @brief Module minor version. -#define MODULE_MINOR_VERSION (3) +#define MODULE_MINOR_VERSION (4) /// @brief rmap protocol version #define RMAP_PROCOTOL_VERSION (1) diff --git a/platformio/stima_v4/slave-wind/src/tasks/elaborate_data_task.cpp b/platformio/stima_v4/slave-wind/src/tasks/elaborate_data_task.cpp index 851687cf5..4e6f6fea2 100644 --- a/platformio/stima_v4/slave-wind/src/tasks/elaborate_data_task.cpp +++ b/platformio/stima_v4/slave-wind/src/tasks/elaborate_data_task.cpp @@ -598,13 +598,61 @@ void ElaborateDataTask::make_report(bool is_init, uint16_t report_time_s, uint8_ if (valid_count_speed_per >= SAMPLE_ERROR_PERCENTAGE_MIN) { report.avg_speed = (rmapdata_t) avg_speed * WIND_CASTING_SPEED_MULT; - report.quality = (rmapdata_t) round(avg_quality); + report.quality = (rmapdata_t) round(avg_quality); report.class_1 = (rmapdata_t) round((float)class_1 / (float)valid_count_speed * 100.0); report.class_2 = (rmapdata_t) round((float)class_2 / (float)valid_count_speed * 100.0); report.class_3 = (rmapdata_t) round((float)class_3 / (float)valid_count_speed * 100.0); report.class_4 = (rmapdata_t) round((float)class_4 / (float)valid_count_speed * 100.0); report.class_5 = (rmapdata_t) round((float)class_5 / (float)valid_count_speed * 100.0); report.class_6 = (rmapdata_t) round((float)class_6 / (float)valid_count_speed * 100.0); + // Check sum report round class (unlikely error) + uint8_t perc_sum = report.class_1 + report.class_2 + report.class_3 + report.class_4 + report.class_5 + report.class_6; + if (perc_sum != 100) { + uint8_t max_val = report.class_1; + uint8_t max_cls = 1; + if (report.class_2 >= max_val) { + max_val = report.class_2; + max_cls = 2; + } + if (report.class_3 >= max_val) { + max_val = report.class_3; + max_cls = 3; + } + if (report.class_4 >= max_val) { + max_val = report.class_4; + max_cls = 4; + } + if (report.class_5 >= max_val) { + max_val = report.class_5; + max_cls = 5; + } + if (report.class_6 >= max_val) { + max_val = report.class_6; + max_cls = 6; + } + if(perc_sum > 100) { + max_val = perc_sum - 100; + switch(max_cls) { + case 1: report.class_1 -= max_val; break; + case 2: report.class_2 -= max_val; break; + case 3: report.class_3 -= max_val; break; + case 4: report.class_4 -= max_val; break; + case 5: report.class_5 -= max_val; break; + case 6: report.class_6 -= max_val; break; + } + } + if(perc_sum < 100) { + max_val = 100 - perc_sum; + switch(max_cls) { + case 1: report.class_1 += max_val; break; + case 2: report.class_2 += max_val; break; + case 3: report.class_3 += max_val; break; + case 4: report.class_4 += max_val; break; + case 5: report.class_5 += max_val; break; + case 6: report.class_6 += max_val; break; + } + } + } } TRACE_DEBUG_F(F("-> report.vavg10_speed (%d)\r\n"), (rmapdata_t) report.vavg10_speed);