From 8c8dc55db4436453d41dacb4774509b4bbad0248 Mon Sep 17 00:00:00 2001 From: medina5 Date: Sun, 7 Dec 2025 15:51:07 +0100 Subject: [PATCH] Exception --- AutomForArduino.cpp | 12 +++--- main.cpp | 102 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 98 insertions(+), 16 deletions(-) diff --git a/AutomForArduino.cpp b/AutomForArduino.cpp index e03477a..fc708b1 100644 --- a/AutomForArduino.cpp +++ b/AutomForArduino.cpp @@ -52,9 +52,9 @@ typedef struct PinIO unsigned long time; double duration; unsigned int nb; // compteur d'activation - int memory; - unsigned char raising; - unsigned char falling; + int memory; // valeur précédente + unsigned char raising; // front montant + unsigned char falling; // front descendant } PinIO; PinIO _digital[256]; @@ -75,8 +75,6 @@ void pinMode(unsigned char p, unsigned char mode) } - - /* KEYBOARD */ typedef struct @@ -323,7 +321,7 @@ class MiseAEchelle float minEntree; float minSortie; float maxEntree; - float maxSortie; + float maxSortie; }; /* READ */ @@ -351,6 +349,8 @@ void digitalWrite(unsigned int p, int value) // En panne ! if (!(_digital[p].mode & 0x01)) { + _digital[p].ivalue = 0; + _digital[p].dvalue = 0.0; return; } diff --git a/main.cpp b/main.cpp index 1e9713b..1c061b4 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,12 @@ #include "main.hpp" #include "AutomForArduino.cpp" +#include +#include +#include +#include +#include + // Constantes de fonctionnement #define LEVEL_MIN 2 #define FLOW_PER_PUMP 150 @@ -20,14 +26,35 @@ unsigned short sensor_max, sensor_high, sensor_low, sensor_min; float TankInitalValue = 7; -TemporisationRetardMontee tempo1(500); -TemporisationRetardMontee tempo2(1000); -TemporisationRetardMontee tempo3(1500); -TemporisationRetardMontee tempo4(2000); +TemporisationRetardMontee tempo1(1500); +TemporisationRetardMontee tempo2(3000); +TemporisationRetardMontee tempo3(4000); +TemporisationRetardMontee tempo4(6000); // Prometheus // ************************************************************ +using namespace prometheus; +std::shared_ptr registry; +Gauge *debit_entree = nullptr; +Gauge *debit_sortie = nullptr; + +Gauge *debit_p1 = nullptr; +Gauge *debit_p2 = nullptr; +Gauge *debit_p3 = nullptr; +Gauge *debit_p4 = nullptr; +Gauge *tank_gauge = nullptr; + +Counter *volume_p1 = nullptr; +Counter *volume_p2 = nullptr; +Counter *volume_p3 = nullptr; +Counter *volume_p4 = nullptr; + +Histogram::BucketBoundaries buckets = { + 2, 5, 6, 7, 8, 9, 9.5 +}; + +Histogram *tank_histogram = nullptr; // ************************************************************ int main() @@ -437,10 +464,11 @@ double ProcessMoteur(int i) void ProcessException() { - if (t_elapsed > 30) { + if (t_elapsed > 60) { _digital[OUT_PUMP_1].mode = 0; + digitalWrite(OUT_PUMP_1, 0); } else if (t_elapsed > 15) { - _digital[IN_SENSOR_LOW].mode = 0; + //_digital[IN_SENSOR_LOW].mode = 0; } } @@ -454,8 +482,8 @@ void Process() // ***** FLOW OUT if (_digital[IN_TANK_LEVEL].dvalue > 1.0) { - //_digital[IN_FLOW_OUT].dvalue = SimulConsoSinusoidale(t); - _digital[IN_FLOW_OUT].dvalue = SimulConsoBrown(_digital[IN_FLOW_OUT].dvalue); + _digital[IN_FLOW_OUT].dvalue = SimulConsoSinusoidale(t); + //_digital[IN_FLOW_OUT].dvalue = SimulConsoBrown(_digital[IN_FLOW_OUT].dvalue); } else { @@ -502,8 +530,7 @@ void Process() unsigned char p = i + (OUT_PUMP_1 - IN_KEYBOARD_7); _digital[p].mode ^= 0x01; if (!(_digital[p].mode & 0x01)) { - _digital[p].ivalue = 0; - _digital[p].dvalue = 0.0; + digitalWrite(p, 0); } } } @@ -770,11 +797,66 @@ void AffichageGraphe(int y, int x, double value) */ void InitPrometheus() { + static Exposer exposer{"0.0.0.0:8099"}; + // Le registre central + registry = std::make_shared(); + exposer.RegisterCollectable(registry); + + auto& gauge_volume = BuildGauge() + .Name("geii_volume") + .Help("Volume en m3") + .Register(*registry); + + tank_gauge = &gauge_volume.Add({}); + + auto& gauge_debit = BuildGauge() + .Name("geii_debit") + .Help("Débit en l/s") + .Register(*registry); + + debit_entree = &gauge_debit.Add({{"numero", "entree"}}); + debit_sortie = &gauge_debit.Add({{"numero", "sortie"}}); + + debit_p1 = &gauge_debit.Add({{"numero", "1"}}); + debit_p2 = &gauge_debit.Add({{"numero", "2"}}); + debit_p3 = &gauge_debit.Add({{"numero", "3"}}); + debit_p4 = &gauge_debit.Add({{"numero", "4"}}); + + auto& counter_debit = BuildCounter() + .Name("geii_litre") + .Help("Volume en l") + .Register(*registry); + + volume_p1 = &counter_debit.Add({{"numero", "1"}}); + volume_p2 = &counter_debit.Add({{"numero", "2"}}); + volume_p3 = &counter_debit.Add({{"numero", "3"}}); + volume_p4 = &counter_debit.Add({{"numero", "4"}}); + + auto& hist_volume = BuildHistogram() + .Name("geii_tank") + .Help("volume du reservoir en m3") + .Register(*registry); + + tank_histogram = &hist_volume.Add({}, buckets); } void ProcessPrometheus() { + tank_gauge->Set(_digital[IN_TANK_LEVEL].dvalue); + tank_histogram->Observe(_digital[IN_TANK_LEVEL].dvalue); + debit_entree->Set(_digital[IN_FLOW_IN].dvalue); + debit_sortie->Set(_digital[IN_FLOW_OUT].dvalue); + + debit_p1->Set(_digital[IN_FLOW_1].dvalue); + debit_p2->Set(_digital[IN_FLOW_2].dvalue); + debit_p3->Set(_digital[IN_FLOW_3].dvalue); + debit_p4->Set(_digital[IN_FLOW_4].dvalue); + + volume_p1->Increment(_digital[IN_FLOW_1].dvalue * dt); + volume_p2->Increment(_digital[IN_FLOW_2].dvalue * dt); + volume_p3->Increment(_digital[IN_FLOW_3].dvalue * dt); + volume_p4->Increment(_digital[IN_FLOW_4].dvalue * dt); }