mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
main.cpp@45:61ba3cc4fc55, 2018-05-05 (annotated)
- Committer:
- potless
- Date:
- Sat May 05 17:21:12 2018 +0000
- Revision:
- 45:61ba3cc4fc55
- Parent:
- 44:5cd6f84a62ec
- Child:
- 46:28298df0ac55
version d'essai du 4 mai Carros - chargement carte ARNSRS via STLINK (r?cup?r? sur une NUCLEO)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
potless | 1:bef7856b5c0a | 1 | #include "mbed.h" |
potless | 2:4a8bf1d53439 | 2 | #include <string> |
POTLESS_2 | 7:ad15c386e960 | 3 | #include "Sensor_head_revB.h" |
POTLESS_2 | 8:a750d531b381 | 4 | #include "HTU21D.h" |
POTLESS_2 | 12:7f3aadd79f89 | 5 | #include "PID.h" |
POTLESS_2 | 19:cac3761a5d0b | 6 | #include "Faulhaber.h" |
POTLESS_2 | 29:5b822d18bce6 | 7 | #include "Utils.h" |
POTLESS_2 | 4:d84250f67dec | 8 | |
POTLESS_2 | 17:bef8abc445f2 | 9 | //Commandes des servos |
potless | 45:61ba3cc4fc55 | 10 | |
potless | 45:61ba3cc4fc55 | 11 | DigitalOut E5V (PA_4); |
POTLESS_2 | 19:cac3761a5d0b | 12 | #define PWM_SERVO_POUMON PB_15 |
POTLESS_2 | 19:cac3761a5d0b | 13 | #define nSleep_SERVO_POUMON PC_6 |
POTLESS_2 | 19:cac3761a5d0b | 14 | #define FWD_SERVO_POUMON PB_14 |
POTLESS_2 | 19:cac3761a5d0b | 15 | #define REV_SERVO_POUMON PB_13 |
POTLESS_2 | 43:5ae8baf28e32 | 16 | #define Channel_A_SERVO_POUMON PB_2 |
POTLESS_2 | 43:5ae8baf28e32 | 17 | #define Channel_B_SERVO_POUMON PB_1 |
POTLESS_2 | 19:cac3761a5d0b | 18 | #define HOME_SERVO_POUMON 0 |
POTLESS_2 | 17:bef8abc445f2 | 19 | |
POTLESS_2 | 19:cac3761a5d0b | 20 | #define PWM_SERVO_FUITE PB_10 |
POTLESS_2 | 43:5ae8baf28e32 | 21 | #define nSleep_SERVO_FUITE PB_0 |
POTLESS_2 | 19:cac3761a5d0b | 22 | #define FWD_SERVO_FUITE PB_4 |
POTLESS_2 | 19:cac3761a5d0b | 23 | #define REV_SERVO_FUITE PB_5 |
POTLESS_2 | 43:5ae8baf28e32 | 24 | #define Channel_A_SERVO_FUITE PC_9 |
POTLESS_2 | 43:5ae8baf28e32 | 25 | #define Channel_B_SERVO_FUITE PA_8 |
POTLESS_2 | 19:cac3761a5d0b | 26 | #define HOME_SERVO_FUITE 90 |
POTLESS_2 | 17:bef8abc445f2 | 27 | |
POTLESS_2 | 43:5ae8baf28e32 | 28 | //Pin de test des alims |
POTLESS_2 | 43:5ae8baf28e32 | 29 | #define PIN_V_PILES_ANALOG PA_1 |
POTLESS_2 | 43:5ae8baf28e32 | 30 | #define PIN_V_PILES_DIGI PC_3 |
POTLESS_2 | 43:5ae8baf28e32 | 31 | #define PIN_V_USB_DIGI PA_0 |
POTLESS_2 | 11:b2feed92584a | 32 | |
potless | 44:5cd6f84a62ec | 33 | //#define OUTPUT(...) { NVIC_DisableIRQ(USART3_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} |
potless | 44:5cd6f84a62ec | 34 | #define OUTPUT(...) { NVIC_DisableIRQ(USART2_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART2_IRQn);} |
POTLESS_2 | 43:5ae8baf28e32 | 35 | //#define IHM(...) { NVIC_DisableIRQ(USART3_IRQn); display.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} |
POTLESS_2 | 34:26f6e3dbefb9 | 36 | |
POTLESS_2 | 25:322ef9488e65 | 37 | //PinName pwm, PinName nSleep, PinName fwd, PinName rev, PinName channelA, PinName channelB, int pulsesPerRev, int Rapport, Encoding encoding = X2_ENCODING |
POTLESS_2 | 25:322ef9488e65 | 38 | Faulhaber Servo_Poumon("Servo_Poumon", PWM_SERVO_POUMON, nSleep_SERVO_POUMON, FWD_SERVO_POUMON, REV_SERVO_POUMON, Channel_A_SERVO_POUMON, Channel_B_SERVO_POUMON, 16, 207, Faulhaber::X2_ENCODING); |
POTLESS_2 | 43:5ae8baf28e32 | 39 | Faulhaber Servo_Fuite("Servo_Fuite", PWM_SERVO_FUITE, nSleep_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, Channel_A_SERVO_FUITE, Channel_B_SERVO_FUITE, 16, 207, Faulhaber::X2_ENCODING); |
POTLESS_2 | 17:bef8abc445f2 | 40 | |
POTLESS_2 | 17:bef8abc445f2 | 41 | //Moniteur série, Serial 2 |
potless | 45:61ba3cc4fc55 | 42 | //Serial serialMonit(PC_10, PC_11, 115200); // UART 3 pour windev nucleo - version définitive sur uart3 pour carte ARNSRS |
potless | 45:61ba3cc4fc55 | 43 | Serial serialMonit(PA_2, PA_3,115200); // UART2 à décommenter pour carte ARNSRS |
POTLESS_2 | 10:aca745a66d51 | 44 | |
POTLESS_2 | 43:5ae8baf28e32 | 45 | //Communication avec l'IHM |
POTLESS_2 | 43:5ae8baf28e32 | 46 | //Serial display(PC_4, PC_5, 115200); |
POTLESS_2 | 43:5ae8baf28e32 | 47 | |
POTLESS_2 | 43:5ae8baf28e32 | 48 | //Moniteur pour le debug avec une nucleo, a commenter avec la carte definitive |
potless | 44:5cd6f84a62ec | 49 | //Serial serial(USBTX, USBRX, 115200); |
POTLESS_2 | 4:d84250f67dec | 50 | |
POTLESS_2 | 7:ad15c386e960 | 51 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 52 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 53 | |
POTLESS_2 | 34:26f6e3dbefb9 | 54 | //pour Param Venant du PV |
POTLESS_2 | 42:3591ec9903b4 | 55 | const int sizeParam = 50; |
POTLESS_2 | 11:b2feed92584a | 56 | char param[sizeParam]; |
POTLESS_2 | 11:b2feed92584a | 57 | volatile int indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 58 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 59 | |
POTLESS_2 | 43:5ae8baf28e32 | 60 | //Flag PID ON / OFF |
POTLESS_2 | 43:5ae8baf28e32 | 61 | int FLAG_PID = 0; |
POTLESS_2 | 42:3591ec9903b4 | 62 | |
POTLESS_2 | 42:3591ec9903b4 | 63 | //Flag pour interrompre l'affichage si on veut... |
POTLESS_2 | 42:3591ec9903b4 | 64 | bool FLAG_AFF = false; |
POTLESS_2 | 25:322ef9488e65 | 65 | |
POTLESS_2 | 40:32d89e04ead1 | 66 | //Flag pour envoyer à l'app windev... |
POTLESS_2 | 40:32d89e04ead1 | 67 | bool FLAG_WINDEV = false; |
POTLESS_2 | 40:32d89e04ead1 | 68 | |
POTLESS_2 | 43:5ae8baf28e32 | 69 | //Flag pour envoyer à l'IHM... |
POTLESS_2 | 43:5ae8baf28e32 | 70 | bool FLAG_DISPLAY = false; |
POTLESS_2 | 43:5ae8baf28e32 | 71 | |
POTLESS_2 | 29:5b822d18bce6 | 72 | //Flag pour interrompre l'enregistrement si on veut... |
POTLESS_2 | 29:5b822d18bce6 | 73 | bool FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 74 | |
POTLESS_2 | 33:f5d4bae05f16 | 75 | //Flag pour interrompre les demandes O2 en cours ed calibration... |
POTLESS_2 | 33:f5d4bae05f16 | 76 | bool FLAG_O2 = true; |
POTLESS_2 | 33:f5d4bae05f16 | 77 | |
POTLESS_2 | 7:ad15c386e960 | 78 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 79 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 80 | float pression = 0; |
POTLESS_2 | 9:04bfdfc029cb | 81 | float Temp1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 82 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 83 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 84 | int CellO2_2 = 0; |
POTLESS_2 | 36:1f5e2247b073 | 85 | |
POTLESS_2 | 18:bfd78c05b589 | 86 | //Variables et constantes OTU |
POTLESS_2 | 18:bfd78c05b589 | 87 | float OTU = 0; |
POTLESS_2 | 18:bfd78c05b589 | 88 | float COEF_OTU = 0.83; |
POTLESS_2 | 18:bfd78c05b589 | 89 | |
POTLESS_2 | 17:bef8abc445f2 | 90 | //Mesure du temps d'éxecution du loop |
POTLESS_2 | 7:ad15c386e960 | 91 | Timer REAL_RATE; |
POTLESS_2 | 7:ad15c386e960 | 92 | float RATE = 0; |
POTLESS_2 | 11:b2feed92584a | 93 | float RATE_TRUE = 0; |
POTLESS_2 | 29:5b822d18bce6 | 94 | float Ref_Time = 2.0; //La durée de la boucle désirée... |
POTLESS_2 | 7:ad15c386e960 | 95 | |
POTLESS_2 | 17:bef8abc445f2 | 96 | //HTU21D sur l'I2C |
POTLESS_2 | 8:a750d531b381 | 97 | HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL |
POTLESS_2 | 9:04bfdfc029cb | 98 | float Temp2; |
POTLESS_2 | 9:04bfdfc029cb | 99 | int Humid; |
POTLESS_2 | 9:04bfdfc029cb | 100 | |
POTLESS_2 | 9:04bfdfc029cb | 101 | //Data LOG |
POTLESS_2 | 9:04bfdfc029cb | 102 | char to_store[50]; |
POTLESS_2 | 9:04bfdfc029cb | 103 | time_t seconds; |
POTLESS_2 | 25:322ef9488e65 | 104 | char Log_File_Name[] = " "; |
POTLESS_2 | 42:3591ec9903b4 | 105 | int count = 0; |
POTLESS_2 | 42:3591ec9903b4 | 106 | int Max_Log_Size = 1800;//1 heure, 1800 lignes donc à multiplier par la fréquence d'enregistrement, Ref_Time, pour voir combien de temps représente un Log... |
POTLESS_2 | 8:a750d531b381 | 107 | |
POTLESS_2 | 10:aca745a66d51 | 108 | //Contrôle des servos |
POTLESS_2 | 19:cac3761a5d0b | 109 | float Consigne_poumon = 0; |
POTLESS_2 | 19:cac3761a5d0b | 110 | float volet_poumon_Position = 0; |
POTLESS_2 | 19:cac3761a5d0b | 111 | float Consigne_fuite = 0; |
POTLESS_2 | 19:cac3761a5d0b | 112 | float volet_fuite_Position = 0; |
potless | 45:61ba3cc4fc55 | 113 | float Volets_Speed = 1; |
POTLESS_2 | 26:a2fe19341f92 | 114 | float Volet_DeadBand = 5; |
POTLESS_2 | 10:aca745a66d51 | 115 | |
POTLESS_2 | 12:7f3aadd79f89 | 116 | //Paramètre du PID |
POTLESS_2 | 12:7f3aadd79f89 | 117 | float Kc = 40; |
POTLESS_2 | 12:7f3aadd79f89 | 118 | float Ti = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 119 | float Td = 0; |
POTLESS_2 | 12:7f3aadd79f89 | 120 | float RATE_PID = Ref_Time; |
POTLESS_2 | 12:7f3aadd79f89 | 121 | float Commande_PID; |
POTLESS_2 | 43:5ae8baf28e32 | 122 | int consigne = 210; |
POTLESS_2 | 15:efd3b3bf3f37 | 123 | float Max_Input = 1000; |
POTLESS_2 | 15:efd3b3bf3f37 | 124 | float Min_Input = 80; |
POTLESS_2 | 19:cac3761a5d0b | 125 | float Max_Output = 85;//Vérifier la valeur pour angle à laisser ouvert... |
POTLESS_2 | 19:cac3761a5d0b | 126 | float Min_Output = 5; |
POTLESS_2 | 10:aca745a66d51 | 127 | |
POTLESS_2 | 12:7f3aadd79f89 | 128 | //Init PID |
POTLESS_2 | 17:bef8abc445f2 | 129 | PID control_Servo(Kc, Ti, Td, RATE_PID); |
POTLESS_2 | 10:aca745a66d51 | 130 | |
POTLESS_2 | 19:cac3761a5d0b | 131 | //Boolean du status de l'appareil, en mode SECU ou nominal |
POTLESS_2 | 19:cac3761a5d0b | 132 | bool EN_MODE_SECU = false; |
POTLESS_2 | 31:231a96d1d1c8 | 133 | |
POTLESS_2 | 31:231a96d1d1c8 | 134 | //Test des alim |
POTLESS_2 | 43:5ae8baf28e32 | 135 | DigitalIn V_USB_DIGI(PIN_V_USB_DIGI); |
POTLESS_2 | 43:5ae8baf28e32 | 136 | DigitalIn V_PILES_DIGI(PIN_V_PILES_DIGI); |
POTLESS_2 | 39:65ff3c4f9675 | 137 | |
POTLESS_2 | 43:5ae8baf28e32 | 138 | //Test voltage piles |
POTLESS_2 | 43:5ae8baf28e32 | 139 | AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG); |
POTLESS_2 | 31:231a96d1d1c8 | 140 | |
POTLESS_2 | 31:231a96d1d1c8 | 141 | int Vusb = 1; |
POTLESS_2 | 31:231a96d1d1c8 | 142 | int VPiles = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 143 | float VPiles_val = 1; |
POTLESS_2 | 18:bfd78c05b589 | 144 | |
POTLESS_2 | 43:5ae8baf28e32 | 145 | //Interruption pin |
POTLESS_2 | 43:5ae8baf28e32 | 146 | InterruptIn vpile_off_on(PIN_V_PILES_DIGI); |
POTLESS_2 | 43:5ae8baf28e32 | 147 | InterruptIn vusb_off_on(PIN_V_USB_DIGI); |
POTLESS_2 | 21:b8900130ca05 | 148 | |
POTLESS_2 | 29:5b822d18bce6 | 149 | void Affichage() |
POTLESS_2 | 29:5b822d18bce6 | 150 | { |
POTLESS_2 | 42:3591ec9903b4 | 151 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 152 | serialMonit.printf(" CO2 = %d ppm\r\n" , co2); |
POTLESS_2 | 29:5b822d18bce6 | 153 | serialMonit.printf(" PPO2 = %d mb\r\n", ppO2); |
POTLESS_2 | 31:231a96d1d1c8 | 154 | serialMonit.printf(" OTU = %d \r\n", (int)OTU); |
POTLESS_2 | 29:5b822d18bce6 | 155 | serialMonit.printf(" Pression = %f msw\r\n", pression); |
POTLESS_2 | 29:5b822d18bce6 | 156 | serialMonit.printf(" Temp MS5837 = %f C\r\n", Temp1); |
POTLESS_2 | 29:5b822d18bce6 | 157 | serialMonit.printf(" Temp HTU21D = %f C\n\r", Temp2); |
POTLESS_2 | 29:5b822d18bce6 | 158 | serialMonit.printf(" Humidity = %d %%\n\r", Humid); |
POTLESS_2 | 42:3591ec9903b4 | 159 | //serialMonit.printf("\n\r"); |
POTLESS_2 | 29:5b822d18bce6 | 160 | serialMonit.printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 29:5b822d18bce6 | 161 | serialMonit.printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 42:3591ec9903b4 | 162 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 163 | serialMonit.printf(" Volet Poumon = %f\r\n" , volet_poumon_Position); |
POTLESS_2 | 29:5b822d18bce6 | 164 | serialMonit.printf(" Volet Fuite = %f\r\n" , volet_fuite_Position); |
POTLESS_2 | 42:3591ec9903b4 | 165 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 166 | serialMonit.printf(" Temps d execution de la boucle = %f seconde(s)\r\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 42:3591ec9903b4 | 167 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 168 | if (FLAG_REC) serialMonit.printf(" Chaine enregistrée = %s\r\n", to_store); |
POTLESS_2 | 30:7a16a66d76f3 | 169 | else serialMonit.printf(" Pas d'enregistrement en cours."); |
POTLESS_2 | 42:3591ec9903b4 | 170 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 171 | serialMonit.printf(" V_USB = %f\r\n", Vusb); |
POTLESS_2 | 42:3591ec9903b4 | 172 | //serialMonit.printf("\r\n\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 173 | fflush(stdout); |
POTLESS_2 | 29:5b822d18bce6 | 174 | } |
POTLESS_2 | 29:5b822d18bce6 | 175 | |
potless | 38:fe77b68eec37 | 176 | |
POTLESS_2 | 19:cac3761a5d0b | 177 | //Passage en mode SECU |
POTLESS_2 | 19:cac3761a5d0b | 178 | void Mode_SECU() |
POTLESS_2 | 18:bfd78c05b589 | 179 | { |
POTLESS_2 | 43:5ae8baf28e32 | 180 | |
POTLESS_2 | 18:bfd78c05b589 | 181 | //Mise du PID en mode manuel (desactivation...) |
POTLESS_2 | 18:bfd78c05b589 | 182 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 183 | |
POTLESS_2 | 19:cac3761a5d0b | 184 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 19:cac3761a5d0b | 185 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 34:26f6e3dbefb9 | 186 | |
POTLESS_2 | 25:322ef9488e65 | 187 | Volets_Speed = 0.1; |
POTLESS_2 | 25:322ef9488e65 | 188 | Volet_DeadBand = 10; |
POTLESS_2 | 25:322ef9488e65 | 189 | |
POTLESS_2 | 19:cac3761a5d0b | 190 | while(1) { |
POTLESS_2 | 25:322ef9488e65 | 191 | wait_ms(100); |
POTLESS_2 | 19:cac3761a5d0b | 192 | if (Servo_Poumon.Pos_OK() == true) break; |
POTLESS_2 | 43:5ae8baf28e32 | 193 | if (Servo_Fuite.Pos_OK() == true) break; |
POTLESS_2 | 19:cac3761a5d0b | 194 | } |
POTLESS_2 | 43:5ae8baf28e32 | 195 | |
POTLESS_2 | 43:5ae8baf28e32 | 196 | OUTPUT(" Appareil en mode SECU\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 197 | |
POTLESS_2 | 25:322ef9488e65 | 198 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 199 | |
POTLESS_2 | 19:cac3761a5d0b | 200 | EN_MODE_SECU = true; |
POTLESS_2 | 43:5ae8baf28e32 | 201 | |
POTLESS_2 | 25:322ef9488e65 | 202 | wait_ms(100); |
POTLESS_2 | 43:5ae8baf28e32 | 203 | int Pos_P = Servo_Poumon.getPulses(); |
POTLESS_2 | 43:5ae8baf28e32 | 204 | UTILS::Store_A_Val((float)Pos_P, "Servo_Poumon.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 205 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos_P); |
POTLESS_2 | 43:5ae8baf28e32 | 206 | |
POTLESS_2 | 43:5ae8baf28e32 | 207 | int Pos_F = Servo_Fuite.getPulses(); |
POTLESS_2 | 43:5ae8baf28e32 | 208 | UTILS::Store_A_Val((float)Pos_F, "Servo_Fuite.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 209 | DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos_F); |
POTLESS_2 | 43:5ae8baf28e32 | 210 | |
POTLESS_2 | 23:7477dc855fad | 211 | Servo_Poumon.Sleep(); |
POTLESS_2 | 43:5ae8baf28e32 | 212 | Servo_Fuite.Sleep(); |
POTLESS_2 | 19:cac3761a5d0b | 213 | } |
POTLESS_2 | 19:cac3761a5d0b | 214 | |
POTLESS_2 | 19:cac3761a5d0b | 215 | //Sequence d'arrêt |
POTLESS_2 | 19:cac3761a5d0b | 216 | void Stop_Sequence() |
POTLESS_2 | 34:26f6e3dbefb9 | 217 | { |
POTLESS_2 | 43:5ae8baf28e32 | 218 | OUTPUT(" Mise en veille de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 219 | |
POTLESS_2 | 43:5ae8baf28e32 | 220 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 221 | |
POTLESS_2 | 34:26f6e3dbefb9 | 222 | Mode_SECU(); |
POTLESS_2 | 39:65ff3c4f9675 | 223 | //ejection de la flash pour pas crasher le system de fichiers |
POTLESS_2 | 39:65ff3c4f9675 | 224 | UTILS::UnMount_Flash(); |
POTLESS_2 | 40:32d89e04ead1 | 225 | |
potless | 37:f9461c6592f2 | 226 | // préparation deepsleep |
POTLESS_2 | 40:32d89e04ead1 | 227 | |
potless | 37:f9461c6592f2 | 228 | /* |
potless | 37:f9461c6592f2 | 229 | //première méthode mais je ne sais pas ce que ça consomme et il faut normalement reduire le frequence d'horloge avant |
potless | 37:f9461c6592f2 | 230 | //il est possible que ça génère un plantage et la rtc ne fonctionnera pas? |
potless | 37:f9461c6592f2 | 231 | HAL_PWREx_EnableLowPowerRunMode(); |
potless | 37:f9461c6592f2 | 232 | DEBUG("----------------LOW POWER RUN MODE--------------------\r\n"); |
POTLESS_2 | 40:32d89e04ead1 | 233 | |
potless | 37:f9461c6592f2 | 234 | bool isDSallowed; |
potless | 37:f9461c6592f2 | 235 | isDSallowed = sleep_manager_can_deep_sleep(); |
potless | 37:f9461c6592f2 | 236 | DEBUG(" Deep sleep autorisé ? %i\r\n", isDSallowed); |
potless | 37:f9461c6592f2 | 237 | wait(1.0); |
POTLESS_2 | 34:26f6e3dbefb9 | 238 | |
potless | 37:f9461c6592f2 | 239 | DEBUG("\n\r Deepsleep tentative normale !(bouton bleu pour ressortir)\n"); |
potless | 37:f9461c6592f2 | 240 | wait(0.1); |
POTLESS_2 | 40:32d89e04ead1 | 241 | |
potless | 37:f9461c6592f2 | 242 | sleep_manager_sleep_auto(); // ne marche pas, je ne sais pas pk |
potless | 37:f9461c6592f2 | 243 | */ |
POTLESS_2 | 40:32d89e04ead1 | 244 | |
POTLESS_2 | 40:32d89e04ead1 | 245 | |
potless | 37:f9461c6592f2 | 246 | DEBUG("\n\r Deepsleep méthode offensive !\n"); |
POTLESS_2 | 40:32d89e04ead1 | 247 | |
POTLESS_2 | 39:65ff3c4f9675 | 248 | /* |
potless | 38:fe77b68eec37 | 249 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2); // pour PC_13 |
POTLESS_2 | 40:32d89e04ead1 | 250 | // Clear wake up Flag |
POTLESS_2 | 40:32d89e04ead1 | 251 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2); |
POTLESS_2 | 40:32d89e04ead1 | 252 | // Enable wakeup pin WKUP2 |
potless | 38:fe77b68eec37 | 253 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW); // low parce qu'on veut que ça redémarre avec le user button TODO à passer sur High pour que ça redémarrage avec l'arrivée du hus sur l'USB |
POTLESS_2 | 39:65ff3c4f9675 | 254 | */ |
POTLESS_2 | 43:5ae8baf28e32 | 255 | HAL_PWREx_EnablePullUpPullDownConfig() ; |
POTLESS_2 | 43:5ae8baf28e32 | 256 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A,PWR_GPIO_BIT_0); |
POTLESS_2 | 40:32d89e04ead1 | 257 | |
potless | 38:fe77b68eec37 | 258 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 |
POTLESS_2 | 40:32d89e04ead1 | 259 | // Clear wake up Flag |
POTLESS_2 | 40:32d89e04ead1 | 260 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
POTLESS_2 | 40:32d89e04ead1 | 261 | // Enable wakeup pin WKUP2 |
POTLESS_2 | 39:65ff3c4f9675 | 262 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut |
POTLESS_2 | 40:32d89e04ead1 | 263 | |
POTLESS_2 | 40:32d89e04ead1 | 264 | // Set RTC back-up register RTC_BKP31R to indicate |
POTLESS_2 | 40:32d89e04ead1 | 265 | //later on that system has entered shutdown mode |
potless | 37:f9461c6592f2 | 266 | WRITE_REG( RTC->BKP31R, 0x1 ); |
POTLESS_2 | 40:32d89e04ead1 | 267 | //Enter shutdown mode |
potless | 37:f9461c6592f2 | 268 | DEBUG("\n\r Attention c'est du brutal ! bouton bleu pour ressort.... ZZZZZZZ ZZZZZ !!!\n"); |
POTLESS_2 | 40:32d89e04ead1 | 269 | |
potless | 37:f9461c6592f2 | 270 | HAL_PWREx_EnterSHUTDOWNMode(); |
POTLESS_2 | 18:bfd78c05b589 | 271 | } |
POTLESS_2 | 18:bfd78c05b589 | 272 | |
POTLESS_2 | 31:231a96d1d1c8 | 273 | //Fonction test de valeur d'entrée digitale |
POTLESS_2 | 29:5b822d18bce6 | 274 | int Power_Test(DigitalIn& pin) |
POTLESS_2 | 20:5f79fb4565a7 | 275 | { |
POTLESS_2 | 29:5b822d18bce6 | 276 | pin.mode(PullDown); |
POTLESS_2 | 34:26f6e3dbefb9 | 277 | |
POTLESS_2 | 34:26f6e3dbefb9 | 278 | if(!pin) { |
POTLESS_2 | 34:26f6e3dbefb9 | 279 | Stop_Sequence(); |
POTLESS_2 | 34:26f6e3dbefb9 | 280 | return 0; |
POTLESS_2 | 34:26f6e3dbefb9 | 281 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 282 | return 1; |
POTLESS_2 | 34:26f6e3dbefb9 | 283 | } |
POTLESS_2 | 20:5f79fb4565a7 | 284 | } |
POTLESS_2 | 20:5f79fb4565a7 | 285 | |
POTLESS_2 | 31:231a96d1d1c8 | 286 | //Fonction test de valeur d'entrée analogique |
POTLESS_2 | 31:231a96d1d1c8 | 287 | float Power_Test(AnalogIn& pin) |
POTLESS_2 | 31:231a96d1d1c8 | 288 | { |
POTLESS_2 | 31:231a96d1d1c8 | 289 | float Val = pin.read(); |
POTLESS_2 | 31:231a96d1d1c8 | 290 | return Val; |
POTLESS_2 | 31:231a96d1d1c8 | 291 | } |
POTLESS_2 | 31:231a96d1d1c8 | 292 | |
POTLESS_2 | 18:bfd78c05b589 | 293 | //Contrôle du status de l'appareil / des constantes |
POTLESS_2 | 18:bfd78c05b589 | 294 | bool Check() |
POTLESS_2 | 18:bfd78c05b589 | 295 | { |
POTLESS_2 | 18:bfd78c05b589 | 296 | if (ppO2 > 100) |
POTLESS_2 | 19:cac3761a5d0b | 297 | return true;//Situation OK |
POTLESS_2 | 18:bfd78c05b589 | 298 | else |
POTLESS_2 | 19:cac3761a5d0b | 299 | return false;//Situation dégradée |
POTLESS_2 | 18:bfd78c05b589 | 300 | } |
POTLESS_2 | 18:bfd78c05b589 | 301 | |
POTLESS_2 | 18:bfd78c05b589 | 302 | //Calcul des OTU |
POTLESS_2 | 18:bfd78c05b589 | 303 | float Calcul_OTU() |
POTLESS_2 | 18:bfd78c05b589 | 304 | { |
POTLESS_2 | 18:bfd78c05b589 | 305 | /* |
POTLESS_2 | 18:bfd78c05b589 | 306 | La formule suivante permet de calculer la quantité d' OTU accumulée |
POTLESS_2 | 18:bfd78c05b589 | 307 | OTU = T * (2* PpO2 -1)0,83 |
POTLESS_2 | 18:bfd78c05b589 | 308 | avec : |
POTLESS_2 | 18:bfd78c05b589 | 309 | T = temps de plongée en minutes |
POTLESS_2 | 18:bfd78c05b589 | 310 | PpO2 = pression partielle d’ oxygène en bars |
POTLESS_2 | 18:bfd78c05b589 | 311 | */ |
POTLESS_2 | 18:bfd78c05b589 | 312 | |
POTLESS_2 | 19:cac3761a5d0b | 313 | if (ppO2 > 500) { |
POTLESS_2 | 18:bfd78c05b589 | 314 | float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb... |
POTLESS_2 | 18:bfd78c05b589 | 315 | OTU += Ref_Time * pow(val, COEF_OTU); |
POTLESS_2 | 19:cac3761a5d0b | 316 | } |
POTLESS_2 | 18:bfd78c05b589 | 317 | } |
POTLESS_2 | 10:aca745a66d51 | 318 | |
POTLESS_2 | 17:bef8abc445f2 | 319 | //Thread d'intérogation des capteurs, positions servo |
POTLESS_2 | 34:26f6e3dbefb9 | 320 | void SENSORS_thread() |
POTLESS_2 | 6:ebed9093d661 | 321 | { |
POTLESS_2 | 7:ad15c386e960 | 322 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 323 | //DEEP_DEBUG(" SENSORS_thread\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 324 | |
POTLESS_2 | 7:ad15c386e960 | 325 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 326 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 327 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 328 | pression = sensors.requestPress(); |
POTLESS_2 | 9:04bfdfc029cb | 329 | Temp1 = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 330 | //PPO2 sur ADS1015 |
POTLESS_2 | 33:f5d4bae05f16 | 331 | if (FLAG_O2) ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 332 | //Cell O2 en mV |
POTLESS_2 | 33:f5d4bae05f16 | 333 | if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 33:f5d4bae05f16 | 334 | if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 9:04bfdfc029cb | 335 | |
POTLESS_2 | 8:a750d531b381 | 336 | //HTU21D |
POTLESS_2 | 9:04bfdfc029cb | 337 | Temp2 = temphumid.sample_ctemp(); |
POTLESS_2 | 9:04bfdfc029cb | 338 | Humid = temphumid.sample_humid(); |
POTLESS_2 | 9:04bfdfc029cb | 339 | |
POTLESS_2 | 10:aca745a66d51 | 340 | //Retour position des servos |
POTLESS_2 | 17:bef8abc445f2 | 341 | volet_poumon_Position = Servo_Poumon.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 342 | volet_fuite_Position = Servo_Fuite.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 343 | |
POTLESS_2 | 43:5ae8baf28e32 | 344 | //Calcul des OTU |
POTLESS_2 | 43:5ae8baf28e32 | 345 | Calcul_OTU(); |
POTLESS_2 | 34:26f6e3dbefb9 | 346 | |
POTLESS_2 | 19:cac3761a5d0b | 347 | } |
POTLESS_2 | 19:cac3761a5d0b | 348 | } |
POTLESS_2 | 12:7f3aadd79f89 | 349 | |
POTLESS_2 | 19:cac3761a5d0b | 350 | void GO_TO_thread() |
POTLESS_2 | 19:cac3761a5d0b | 351 | { |
POTLESS_2 | 19:cac3761a5d0b | 352 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 353 | //DEEP_DEBUG(" GO_TO_Thread\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 354 | |
POTLESS_2 | 19:cac3761a5d0b | 355 | //Servo_Poumon.Go_To_Prop(Consigne_poumon); |
POTLESS_2 | 26:a2fe19341f92 | 356 | //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand); |
POTLESS_2 | 34:26f6e3dbefb9 | 357 | Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 34:26f6e3dbefb9 | 358 | |
POTLESS_2 | 19:cac3761a5d0b | 359 | //Servo_Fuite.Go_To_Prop(Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 360 | //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand); |
POTLESS_2 | 43:5ae8baf28e32 | 361 | Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand ); |
POTLESS_2 | 15:efd3b3bf3f37 | 362 | } |
potless | 2:4a8bf1d53439 | 363 | } |
POTLESS_2 | 4:d84250f67dec | 364 | |
POTLESS_2 | 20:5f79fb4565a7 | 365 | void SECU_thread() |
POTLESS_2 | 20:5f79fb4565a7 | 366 | { |
POTLESS_2 | 34:26f6e3dbefb9 | 367 | while (true) { |
POTLESS_2 | 34:26f6e3dbefb9 | 368 | |
POTLESS_2 | 20:5f79fb4565a7 | 369 | } |
POTLESS_2 | 20:5f79fb4565a7 | 370 | } |
POTLESS_2 | 20:5f79fb4565a7 | 371 | |
POTLESS_2 | 11:b2feed92584a | 372 | //Callback de l'intérruption des envois de commandes depuis le terminal |
POTLESS_2 | 6:ebed9093d661 | 373 | void callbackParam() |
POTLESS_2 | 34:26f6e3dbefb9 | 374 | { |
POTLESS_2 | 40:32d89e04ead1 | 375 | |
POTLESS_2 | 40:32d89e04ead1 | 376 | |
POTLESS_2 | 34:26f6e3dbefb9 | 377 | while(serialMonit.readable()) { |
POTLESS_2 | 40:32d89e04ead1 | 378 | if ((indexParam == sizeParam) || newParamFlag == true) { //éviter la saturation du buffer |
potless | 44:5cd6f84a62ec | 379 | NVIC_DisableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 29:5b822d18bce6 | 380 | char char_flush = serialMonit.getc(); |
potless | 44:5cd6f84a62ec | 381 | NVIC_EnableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 40:32d89e04ead1 | 382 | } else { |
potless | 44:5cd6f84a62ec | 383 | NVIC_DisableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 29:5b822d18bce6 | 384 | param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 40:32d89e04ead1 | 385 | if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 40:32d89e04ead1 | 386 | param[indexParam] = 0; |
POTLESS_2 | 40:32d89e04ead1 | 387 | newParamFlag = true; |
POTLESS_2 | 40:32d89e04ead1 | 388 | } |
potless | 44:5cd6f84a62ec | 389 | NVIC_EnableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 34:26f6e3dbefb9 | 390 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 391 | } |
POTLESS_2 | 6:ebed9093d661 | 392 | } |
POTLESS_2 | 4:d84250f67dec | 393 | |
POTLESS_2 | 9:04bfdfc029cb | 394 | void Decoding_Message(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 395 | { |
POTLESS_2 | 9:04bfdfc029cb | 396 | |
POTLESS_2 | 42:3591ec9903b4 | 397 | char com[20] = ""; |
POTLESS_2 | 42:3591ec9903b4 | 398 | char numb[30] = ""; |
POTLESS_2 | 36:1f5e2247b073 | 399 | |
POTLESS_2 | 34:26f6e3dbefb9 | 400 | sscanf(message,"%s %s",&com , &numb); |
POTLESS_2 | 36:1f5e2247b073 | 401 | |
POTLESS_2 | 35:a209a192f431 | 402 | DEEP_DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 42:3591ec9903b4 | 403 | //serialMonit.printf("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 36:1f5e2247b073 | 404 | |
POTLESS_2 | 43:5ae8baf28e32 | 405 | OUTPUT("?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 406 | |
POTLESS_2 | 30:7a16a66d76f3 | 407 | if (0 == strcmp(com, "secu")) { |
POTLESS_2 | 19:cac3761a5d0b | 408 | Mode_SECU(); |
POTLESS_2 | 42:3591ec9903b4 | 409 | } else if (0 == strcmp(com, "PING")) { |
POTLESS_2 | 43:5ae8baf28e32 | 410 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 411 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 412 | FLAG_WINDEV = false; |
POTLESS_2 | 43:5ae8baf28e32 | 413 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 34:26f6e3dbefb9 | 414 | } else if (0 == strcmp(com, "ARNSRS_ID")) { |
POTLESS_2 | 43:5ae8baf28e32 | 415 | OUTPUT("Changement de l'ID de l'appareil pour le N°: %s?\r\n", numb); |
POTLESS_2 | 34:26f6e3dbefb9 | 416 | UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID"); |
POTLESS_2 | 43:5ae8baf28e32 | 417 | } else if (0 == strcmp(com, "monit")) { |
POTLESS_2 | 43:5ae8baf28e32 | 418 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 419 | FLAG_WINDEV = true; |
POTLESS_2 | 43:5ae8baf28e32 | 420 | } else if (0 == strcmp(com, "debug")) { |
POTLESS_2 | 43:5ae8baf28e32 | 421 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 422 | FLAG_WINDEV = false; |
POTLESS_2 | 34:26f6e3dbefb9 | 423 | } else if (0 == strcmp(com, "Head_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 424 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 43:5ae8baf28e32 | 425 | OUTPUT("Changement de l'ID de la tête capteur pour le N°: %s\r\n", numb); |
POTLESS_2 | 34:26f6e3dbefb9 | 426 | UTILS::write_EEPROM(numb, HEAD_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 427 | } else if (0 == strcmp(com, "O2_1_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 428 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 429 | UTILS::write_EEPROM(numb, CELL_O2_1_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 430 | } else if (0 == strcmp(com, "O2_2_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 431 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 432 | UTILS::write_EEPROM(numb, CELL_O2_2_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 433 | } else if (0 == strcmp(com, "CO2_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 434 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 435 | UTILS::write_EEPROM(numb, CO2_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 436 | } else if (0 == strcmp(com, "calib_O2")) { |
POTLESS_2 | 33:f5d4bae05f16 | 437 | FLAG_O2 = false; |
POTLESS_2 | 33:f5d4bae05f16 | 438 | wait_ms(100); |
POTLESS_2 | 42:3591ec9903b4 | 439 | float Val = sensors.Calibrate_O2(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 440 | OUTPUT(" Calibration O2 dans l'air = %f\r\n", Val); |
POTLESS_2 | 33:f5d4bae05f16 | 441 | wait_ms(100); |
POTLESS_2 | 33:f5d4bae05f16 | 442 | FLAG_O2 = true; |
POTLESS_2 | 41:51ba69648f9d | 443 | } else if (0 == strcmp(com, "calib_CO2_A")) { |
POTLESS_2 | 43:5ae8baf28e32 | 444 | int Val = sensors.Calibrate_CO2(); |
POTLESS_2 | 43:5ae8baf28e32 | 445 | OUTPUT(" Calibration CO2 dans l'air = %d\r\n", Val); |
POTLESS_2 | 34:26f6e3dbefb9 | 446 | } else if (0 == strcmp(com, "flash_i")) { |
POTLESS_2 | 42:3591ec9903b4 | 447 | UTILS::Flash_Infos(&serialMonit); |
POTLESS_2 | 36:1f5e2247b073 | 448 | } else if (0 == strcmp(com, "flash_u")) { |
POTLESS_2 | 43:5ae8baf28e32 | 449 | OUTPUT(" Démontage de la Flash.\r\n"); |
POTLESS_2 | 36:1f5e2247b073 | 450 | FLAG_REC = false; |
POTLESS_2 | 36:1f5e2247b073 | 451 | UTILS::UnMount_Flash(); |
POTLESS_2 | 36:1f5e2247b073 | 452 | } else if (0 == strcmp(com, "flash_m")) { |
POTLESS_2 | 43:5ae8baf28e32 | 453 | OUTPUT(" Montage de la Flash.\r\n"); |
POTLESS_2 | 40:32d89e04ead1 | 454 | UTILS::Mount_Flash(); |
POTLESS_2 | 35:a209a192f431 | 455 | } else if (0 == strcmp(com, "check_F")) { |
POTLESS_2 | 43:5ae8baf28e32 | 456 | OUTPUT(" ARNSRS_ID.sys = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID.sys")); |
POTLESS_2 | 43:5ae8baf28e32 | 457 | OUTPUT(" Servo_Poumon.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon.sys")); |
POTLESS_2 | 43:5ae8baf28e32 | 458 | OUTPUT(" Servo_Fuite.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite.sys")); |
POTLESS_2 | 35:a209a192f431 | 459 | } else if (0 == strcmp(com, "check_E")) { |
POTLESS_2 | 42:3591ec9903b4 | 460 | sensors.Sensor_head_check(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 461 | } else if (0 == strcmp(com, "rec")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 462 | if (FLAG_REC) { |
POTLESS_2 | 34:26f6e3dbefb9 | 463 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 464 | OUTPUT(" Arrêt du Data Logging.\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 465 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 466 | FLAG_REC = true; |
POTLESS_2 | 43:5ae8baf28e32 | 467 | OUTPUT(" Démarrage Data Logging dans %s\r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 468 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 469 | } else if (0 == strcmp(com, "help")) { |
POTLESS_2 | 29:5b822d18bce6 | 470 | FLAG_AFF = false; |
POTLESS_2 | 42:3591ec9903b4 | 471 | UTILS::Help(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 472 | } else if (0 == strcmp(com, "start")) { |
POTLESS_2 | 29:5b822d18bce6 | 473 | FLAG_AFF = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 474 | } else if (0 == strcmp(com, "stop")) { |
POTLESS_2 | 29:5b822d18bce6 | 475 | FLAG_AFF = false; |
POTLESS_2 | 40:32d89e04ead1 | 476 | //UTILS::Help(); |
POTLESS_2 | 36:1f5e2247b073 | 477 | } else if (0 == strcmp(com, "flash_c")) { |
POTLESS_2 | 29:5b822d18bce6 | 478 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 479 | UTILS::Clean_Flash(); |
POTLESS_2 | 42:3591ec9903b4 | 480 | } else if (0 == strcmp(com, "flash_f")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 481 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 482 | UTILS::Clean_Flash_All(); |
POTLESS_2 | 42:3591ec9903b4 | 483 | } else if (0 == strcmp(com, "dir")) { |
POTLESS_2 | 43:5ae8baf28e32 | 484 | FLAG_WINDEV = false; |
POTLESS_2 | 43:5ae8baf28e32 | 485 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 486 | wait(0.5); |
POTLESS_2 | 42:3591ec9903b4 | 487 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 42:3591ec9903b4 | 488 | } else if (0 == strcmp(com, "get")) { |
POTLESS_2 | 29:5b822d18bce6 | 489 | wait_ms(100); |
POTLESS_2 | 43:5ae8baf28e32 | 490 | char filename[20]; |
POTLESS_2 | 43:5ae8baf28e32 | 491 | UTILS::Read_Flash_File(&serialMonit, numb); |
POTLESS_2 | 43:5ae8baf28e32 | 492 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 493 | } else if (0 == strcmp(com, "del")) { |
POTLESS_2 | 29:5b822d18bce6 | 494 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 495 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 496 | UTILS::Delete_Flash_File(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 497 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 498 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 499 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 31:231a96d1d1c8 | 500 | FLAG_REC = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 501 | } else if (0 == strcmp(com, "file_s")) { |
POTLESS_2 | 31:231a96d1d1c8 | 502 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 503 | UTILS::Get_File_Size(&serialMonit, numb); |
POTLESS_2 | 29:5b822d18bce6 | 504 | } else if (0 == strcmp(com, "calib_p")) { |
POTLESS_2 | 20:5f79fb4565a7 | 505 | Consigne_poumon = 0; |
POTLESS_2 | 20:5f79fb4565a7 | 506 | volet_poumon_Position = 0; |
POTLESS_2 | 19:cac3761a5d0b | 507 | Servo_Poumon.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 508 | OUTPUT(" Volet poumon Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 509 | } else if (0 == strcmp(com, "calib_f")) { |
POTLESS_2 | 29:5b822d18bce6 | 510 | Consigne_fuite = 0; |
POTLESS_2 | 29:5b822d18bce6 | 511 | volet_fuite_Position = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 512 | Servo_Fuite.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 513 | OUTPUT(" Volet fuite Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 514 | } else if (0 == strcmp(com, "sleep")) { |
POTLESS_2 | 19:cac3761a5d0b | 515 | Stop_Sequence(); |
POTLESS_2 | 29:5b822d18bce6 | 516 | } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s " |
POTLESS_2 | 34:26f6e3dbefb9 | 517 | set_time(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 518 | OUTPUT(" La RTC a été mise à l'heure.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 519 | } else if (0 == strcmp(com, "c_pou")) { |
POTLESS_2 | 43:5ae8baf28e32 | 520 | Consigne_poumon = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 521 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 522 | } else if (0 == strcmp(com, "c_fui")) { |
POTLESS_2 | 43:5ae8baf28e32 | 523 | Consigne_fuite = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 524 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 525 | } else if (0 == strcmp(com, "mp_pou")) { |
POTLESS_2 | 41:51ba69648f9d | 526 | Consigne_poumon += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 527 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 528 | } else if (0 == strcmp(com, "mp_fui")) { |
POTLESS_2 | 41:51ba69648f9d | 529 | Consigne_fuite += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 530 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 29:5b822d18bce6 | 531 | } else if (0 == strcmp(com, "reset")) { |
POTLESS_2 | 43:5ae8baf28e32 | 532 | FLAG_REC = false; |
POTLESS_2 | 36:1f5e2247b073 | 533 | UTILS::UnMount_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 534 | OUTPUT(" Reset de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 535 | wait(1); |
POTLESS_2 | 10:aca745a66d51 | 536 | NVIC_SystemReset(); |
POTLESS_2 | 43:5ae8baf28e32 | 537 | } else if (0 == strcmp(com, "Kc")) { |
POTLESS_2 | 43:5ae8baf28e32 | 538 | Kc = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 539 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 540 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 541 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 542 | } else if (0 == strcmp(com, "Ti")) { |
POTLESS_2 | 43:5ae8baf28e32 | 543 | Ti = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 544 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 545 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 546 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 547 | } else if (0 == strcmp(com, "Td")) { |
POTLESS_2 | 43:5ae8baf28e32 | 548 | Td = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 549 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 550 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 551 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 552 | } else if (0 == strcmp(com, "Cons")) { |
POTLESS_2 | 43:5ae8baf28e32 | 553 | consigne = atoi(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 554 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 43:5ae8baf28e32 | 555 | OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d?\r\n", consigne); |
POTLESS_2 | 43:5ae8baf28e32 | 556 | } else if (0 == strcmp(com, "PID")) { |
POTLESS_2 | 43:5ae8baf28e32 | 557 | if (FLAG_PID == 1) { |
POTLESS_2 | 43:5ae8baf28e32 | 558 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 559 | OUTPUT(" PID OFF?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 560 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 561 | } else if (FLAG_PID == 0) { |
POTLESS_2 | 43:5ae8baf28e32 | 562 | control_Servo.setMode(AUTO_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 563 | OUTPUT(" PID ON?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 564 | FLAG_PID = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 565 | } |
POTLESS_2 | 12:7f3aadd79f89 | 566 | } else { |
POTLESS_2 | 43:5ae8baf28e32 | 567 | |
POTLESS_2 | 9:04bfdfc029cb | 568 | sensors.cozirSend(message); |
POTLESS_2 | 9:04bfdfc029cb | 569 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 570 | |
POTLESS_2 | 9:04bfdfc029cb | 571 | strcpy(param," "); |
POTLESS_2 | 9:04bfdfc029cb | 572 | indexParam = 0; |
POTLESS_2 | 9:04bfdfc029cb | 573 | newParamFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 574 | } |
POTLESS_2 | 9:04bfdfc029cb | 575 | |
POTLESS_2 | 26:a2fe19341f92 | 576 | void Create_File_Name_Date() |
POTLESS_2 | 25:322ef9488e65 | 577 | { |
POTLESS_2 | 25:322ef9488e65 | 578 | //Du nom du fichier Date / heure |
POTLESS_2 | 25:322ef9488e65 | 579 | seconds = time(NULL); |
POTLESS_2 | 25:322ef9488e65 | 580 | char Time[40]; |
POTLESS_2 | 25:322ef9488e65 | 581 | strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds)); |
POTLESS_2 | 42:3591ec9903b4 | 582 | sprintf(Log_File_Name, "%s_LOG.csv", Time); |
POTLESS_2 | 42:3591ec9903b4 | 583 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 584 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 585 | |
POTLESS_2 | 26:a2fe19341f92 | 586 | void Create_File_Name_Index() |
POTLESS_2 | 26:a2fe19341f92 | 587 | { |
POTLESS_2 | 26:a2fe19341f92 | 588 | //Du nom du fichier par Index |
POTLESS_2 | 42:3591ec9903b4 | 589 | sprintf(Log_File_Name, "LOG_%d.csv", UTILS::File_Index()); |
POTLESS_2 | 34:26f6e3dbefb9 | 590 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 591 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 592 | |
POTLESS_2 | 4:d84250f67dec | 593 | int main() |
POTLESS_2 | 12:7f3aadd79f89 | 594 | { |
POTLESS_2 | 40:32d89e04ead1 | 595 | |
POTLESS_2 | 40:32d89e04ead1 | 596 | HAL_Init(); |
POTLESS_2 | 40:32d89e04ead1 | 597 | |
POTLESS_2 | 40:32d89e04ead1 | 598 | __HAL_RCC_PWR_CLK_ENABLE(); |
potless | 37:f9461c6592f2 | 599 | HAL_PWR_EnableBkUpAccess(); |
POTLESS_2 | 40:32d89e04ead1 | 600 | |
POTLESS_2 | 43:5ae8baf28e32 | 601 | //Ci-dessous commande pour formater une nouvelle carte |
POTLESS_2 | 43:5ae8baf28e32 | 602 | //UTILS::Format_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 603 | |
POTLESS_2 | 43:5ae8baf28e32 | 604 | //Montage Flash |
POTLESS_2 | 43:5ae8baf28e32 | 605 | UTILS::Mount_Flash(); |
POTLESS_2 | 12:7f3aadd79f89 | 606 | |
POTLESS_2 | 43:5ae8baf28e32 | 607 | //Liste des fichiers sur la Flash |
POTLESS_2 | 43:5ae8baf28e32 | 608 | //UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 26:a2fe19341f92 | 609 | |
POTLESS_2 | 43:5ae8baf28e32 | 610 | if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { |
POTLESS_2 | 43:5ae8baf28e32 | 611 | UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 612 | DEBUG("ARNSRS ID forcée à 000\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 613 | } |
potless | 45:61ba3cc4fc55 | 614 | /* |
potless | 45:61ba3cc4fc55 | 615 | while(1){ |
potless | 45:61ba3cc4fc55 | 616 | OUTPUT("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n");} |
potless | 45:61ba3cc4fc55 | 617 | */ |
POTLESS_2 | 34:26f6e3dbefb9 | 618 | |
POTLESS_2 | 43:5ae8baf28e32 | 619 | //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème... |
POTLESS_2 | 43:5ae8baf28e32 | 620 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 621 | char YEAR[10]; |
POTLESS_2 | 43:5ae8baf28e32 | 622 | strftime(YEAR, 10, "%D", localtime(&seconds)); |
POTLESS_2 | 43:5ae8baf28e32 | 623 | if (0 == strcmp(YEAR, "01/01/70")); //OUTPUT(" Vous devez régler la RTC...\r\n\r\n"); |
POTLESS_2 | 18:bfd78c05b589 | 624 | |
POTLESS_2 | 43:5ae8baf28e32 | 625 | bool calib_O2 = false; |
POTLESS_2 | 43:5ae8baf28e32 | 626 | bool calib_CO2 = false; |
POTLESS_2 | 18:bfd78c05b589 | 627 | |
POTLESS_2 | 43:5ae8baf28e32 | 628 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 629 | Par défaut les valeur en cas de calibration sur true sont les suivant |
POTLESS_2 | 18:bfd78c05b589 | 630 | |
POTLESS_2 | 43:5ae8baf28e32 | 631 | nbCalibO2 = 5 |
POTLESS_2 | 43:5ae8baf28e32 | 632 | Mode = SPOOLING |
POTLESS_2 | 43:5ae8baf28e32 | 633 | Filtre = DIGI_FILTER32 |
POTLESS_2 | 43:5ae8baf28e32 | 634 | CalibrationCO2 = "CALIB_AIR" |
POTLESS_2 | 18:bfd78c05b589 | 635 | |
POTLESS_2 | 43:5ae8baf28e32 | 636 | Parfois la calibration du Cozir coince...faire reset et relancer... |
POTLESS_2 | 43:5ae8baf28e32 | 637 | |
POTLESS_2 | 43:5ae8baf28e32 | 638 | Pour calibrer avec ces paramètres : |
POTLESS_2 | 18:bfd78c05b589 | 639 | |
POTLESS_2 | 43:5ae8baf28e32 | 640 | sensors.Sensors_INIT(true, true); |
POTLESS_2 | 43:5ae8baf28e32 | 641 | |
POTLESS_2 | 43:5ae8baf28e32 | 642 | Pour changer utiliser la syntaxe suivante : |
POTLESS_2 | 43:5ae8baf28e32 | 643 | |
POTLESS_2 | 43:5ae8baf28e32 | 644 | sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
POTLESS_2 | 43:5ae8baf28e32 | 645 | |
POTLESS_2 | 43:5ae8baf28e32 | 646 | */ |
POTLESS_2 | 43:5ae8baf28e32 | 647 | |
POTLESS_2 | 43:5ae8baf28e32 | 648 | sensors.Sensors_INIT(calib_O2, calib_CO2); |
POTLESS_2 | 43:5ae8baf28e32 | 649 | |
POTLESS_2 | 43:5ae8baf28e32 | 650 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 651 | |
POTLESS_2 | 43:5ae8baf28e32 | 652 | //Création du nouveau fichier LOG par index / par date. |
POTLESS_2 | 43:5ae8baf28e32 | 653 | //Create_File_Name_Index(); |
POTLESS_2 | 43:5ae8baf28e32 | 654 | Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 655 | |
POTLESS_2 | 43:5ae8baf28e32 | 656 | //Création et écriture du header du fichier LOG |
POTLESS_2 | 43:5ae8baf28e32 | 657 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 42:3591ec9903b4 | 658 | |
POTLESS_2 | 43:5ae8baf28e32 | 659 | Servo_Poumon.Init("Servo_Poumon.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 660 | Servo_Fuite.Init("Servo_Fuite.sys"); |
POTLESS_2 | 15:efd3b3bf3f37 | 661 | |
POTLESS_2 | 43:5ae8baf28e32 | 662 | //OUTPUT(" Demarrage des threads...\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 663 | |
POTLESS_2 | 43:5ae8baf28e32 | 664 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 665 | |
POTLESS_2 | 43:5ae8baf28e32 | 666 | Pour mémoire, les réglage de priorité des thread |
POTLESS_2 | 15:efd3b3bf3f37 | 667 | |
POTLESS_2 | 43:5ae8baf28e32 | 668 | osPriorityIdle = -3, ///< priority: idle (lowest) |
POTLESS_2 | 43:5ae8baf28e32 | 669 | osPriorityLow = -2, ///< priority: low |
POTLESS_2 | 43:5ae8baf28e32 | 670 | osPriorityBelowNormal = -1, ///< priority: below normal |
POTLESS_2 | 43:5ae8baf28e32 | 671 | osPriorityNormal = 0, ///< priority: normal (default) |
POTLESS_2 | 43:5ae8baf28e32 | 672 | osPriorityAboveNormal = +1, ///< priority: above normal |
POTLESS_2 | 43:5ae8baf28e32 | 673 | osPriorityHigh = +2, ///< priority: high |
POTLESS_2 | 43:5ae8baf28e32 | 674 | osPriorityRealtime = +3, ///< priority: realtime (highest) |
POTLESS_2 | 43:5ae8baf28e32 | 675 | osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority |
POTLESS_2 | 43:5ae8baf28e32 | 676 | */ |
POTLESS_2 | 18:bfd78c05b589 | 677 | |
POTLESS_2 | 43:5ae8baf28e32 | 678 | wait(1); |
POTLESS_2 | 20:5f79fb4565a7 | 679 | |
POTLESS_2 | 43:5ae8baf28e32 | 680 | Thread thread_Volets(osPriorityNormal); |
POTLESS_2 | 43:5ae8baf28e32 | 681 | |
POTLESS_2 | 43:5ae8baf28e32 | 682 | thread_Volets.start(callback(GO_TO_thread)); |
POTLESS_2 | 12:7f3aadd79f89 | 683 | |
POTLESS_2 | 43:5ae8baf28e32 | 684 | //OUTPUT(" Contrôle des volets démarré\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 685 | |
POTLESS_2 | 43:5ae8baf28e32 | 686 | wait(1); |
POTLESS_2 | 34:26f6e3dbefb9 | 687 | |
POTLESS_2 | 43:5ae8baf28e32 | 688 | Thread thread_Secu(osPriorityNormal); |
POTLESS_2 | 43:5ae8baf28e32 | 689 | |
POTLESS_2 | 43:5ae8baf28e32 | 690 | thread_Secu.start(callback(SECU_thread)); |
POTLESS_2 | 34:26f6e3dbefb9 | 691 | |
POTLESS_2 | 43:5ae8baf28e32 | 692 | //OUTPUT(" Contrôle des paramètres de sécu démarré\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 693 | |
POTLESS_2 | 43:5ae8baf28e32 | 694 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 695 | |
POTLESS_2 | 43:5ae8baf28e32 | 696 | Thread thread_Head(osPriorityNormal); |
POTLESS_2 | 36:1f5e2247b073 | 697 | |
POTLESS_2 | 43:5ae8baf28e32 | 698 | thread_Head.start(callback(SENSORS_thread)); |
POTLESS_2 | 36:1f5e2247b073 | 699 | |
POTLESS_2 | 43:5ae8baf28e32 | 700 | //OUTPUT(" Tête capteurs démarrée\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 701 | |
POTLESS_2 | 43:5ae8baf28e32 | 702 | wait(1); |
POTLESS_2 | 9:04bfdfc029cb | 703 | |
POTLESS_2 | 43:5ae8baf28e32 | 704 | //Init PID |
POTLESS_2 | 43:5ae8baf28e32 | 705 | //Entrée PPO2 entre 100 et 1000 mb |
POTLESS_2 | 43:5ae8baf28e32 | 706 | control_Servo.setInputLimits(Min_Input, Max_Input); |
POTLESS_2 | 43:5ae8baf28e32 | 707 | //Sortie servo entre 0 et 100 % |
POTLESS_2 | 43:5ae8baf28e32 | 708 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 43:5ae8baf28e32 | 709 | //Mode auto au démarrage |
POTLESS_2 | 43:5ae8baf28e32 | 710 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 711 | //Consigne à x mb |
POTLESS_2 | 43:5ae8baf28e32 | 712 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 34:26f6e3dbefb9 | 713 | |
POTLESS_2 | 43:5ae8baf28e32 | 714 | //OUTPUT(" Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 715 | |
POTLESS_2 | 43:5ae8baf28e32 | 716 | |
potless | 45:61ba3cc4fc55 | 717 | //OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 718 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 719 | UTILS::Dir_Flash(&serialMonit); |
potless | 45:61ba3cc4fc55 | 720 | OUTPUT(" Flash OK\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 721 | |
POTLESS_2 | 43:5ae8baf28e32 | 722 | serialMonit.attach(&callbackParam, Serial::RxIrq); |
potless | 45:61ba3cc4fc55 | 723 | |
potless | 45:61ba3cc4fc55 | 724 | E5V=1; |
POTLESS_2 | 36:1f5e2247b073 | 725 | |
POTLESS_2 | 43:5ae8baf28e32 | 726 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 727 | |
POTLESS_2 | 43:5ae8baf28e32 | 728 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 43:5ae8baf28e32 | 729 | REAL_RATE.start(); |
POTLESS_2 | 36:1f5e2247b073 | 730 | |
POTLESS_2 | 43:5ae8baf28e32 | 731 | if (newParamFlag) { |
POTLESS_2 | 43:5ae8baf28e32 | 732 | DEEP_DEBUG(" From PC = %s\r\n", param); |
POTLESS_2 | 43:5ae8baf28e32 | 733 | Decoding_Message(param); |
POTLESS_2 | 43:5ae8baf28e32 | 734 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 735 | |
POTLESS_2 | 43:5ae8baf28e32 | 736 | //Fabrication de la chaine Date / heure |
POTLESS_2 | 43:5ae8baf28e32 | 737 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 738 | char Time_buf[32]; |
POTLESS_2 | 43:5ae8baf28e32 | 739 | strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); |
POTLESS_2 | 19:cac3761a5d0b | 740 | |
POTLESS_2 | 43:5ae8baf28e32 | 741 | //Fabrication de la chaine à enregistrer |
POTLESS_2 | 43:5ae8baf28e32 | 742 | sprintf(to_store,"<%s;%d;%d;%.2f;%d;%.2f;%.2f;%d;%d;%d;%.2f;%.2f;%d;%.3f;%.3f;%.3f;%d>", |
POTLESS_2 | 43:5ae8baf28e32 | 743 | Time_buf, |
POTLESS_2 | 43:5ae8baf28e32 | 744 | co2, |
POTLESS_2 | 43:5ae8baf28e32 | 745 | ppO2, |
POTLESS_2 | 43:5ae8baf28e32 | 746 | pression, |
POTLESS_2 | 43:5ae8baf28e32 | 747 | (int)OTU, |
POTLESS_2 | 43:5ae8baf28e32 | 748 | Temp1, |
POTLESS_2 | 43:5ae8baf28e32 | 749 | Temp2, |
POTLESS_2 | 43:5ae8baf28e32 | 750 | Humid, |
POTLESS_2 | 43:5ae8baf28e32 | 751 | CellO2_1, |
POTLESS_2 | 43:5ae8baf28e32 | 752 | CellO2_2, |
POTLESS_2 | 43:5ae8baf28e32 | 753 | volet_poumon_Position, |
POTLESS_2 | 43:5ae8baf28e32 | 754 | volet_fuite_Position, |
POTLESS_2 | 43:5ae8baf28e32 | 755 | FLAG_PID, |
POTLESS_2 | 43:5ae8baf28e32 | 756 | Kc, |
POTLESS_2 | 43:5ae8baf28e32 | 757 | Ti, |
POTLESS_2 | 43:5ae8baf28e32 | 758 | Td, |
POTLESS_2 | 43:5ae8baf28e32 | 759 | consigne |
POTLESS_2 | 43:5ae8baf28e32 | 760 | ); |
POTLESS_2 | 15:efd3b3bf3f37 | 761 | |
POTLESS_2 | 15:efd3b3bf3f37 | 762 | |
POTLESS_2 | 43:5ae8baf28e32 | 763 | //Pour windev |
POTLESS_2 | 43:5ae8baf28e32 | 764 | if (FLAG_WINDEV) { |
POTLESS_2 | 43:5ae8baf28e32 | 765 | OUTPUT("%s\r\n", to_store); |
POTLESS_2 | 43:5ae8baf28e32 | 766 | } |
POTLESS_2 | 43:5ae8baf28e32 | 767 | |
POTLESS_2 | 43:5ae8baf28e32 | 768 | //Pour l'IHM |
POTLESS_2 | 43:5ae8baf28e32 | 769 | //if (FLAG_DISPLAY) { |
POTLESS_2 | 43:5ae8baf28e32 | 770 | // IHM("%s\r\n", to_store); |
POTLESS_2 | 43:5ae8baf28e32 | 771 | //} |
POTLESS_2 | 43:5ae8baf28e32 | 772 | |
POTLESS_2 | 43:5ae8baf28e32 | 773 | //Vers le moniteur série |
POTLESS_2 | 43:5ae8baf28e32 | 774 | if (FLAG_AFF) { |
potless | 44:5cd6f84a62ec | 775 | NVIC_DisableIRQ(USART3_IRQn); // USART 2 si ARNSRS mais plus utilisé |
POTLESS_2 | 43:5ae8baf28e32 | 776 | Affichage(); |
potless | 44:5cd6f84a62ec | 777 | NVIC_EnableIRQ(USART3_IRQn); // USART 2 si ARNSRS mais plus utilisé |
POTLESS_2 | 43:5ae8baf28e32 | 778 | } |
POTLESS_2 | 12:7f3aadd79f89 | 779 | |
POTLESS_2 | 43:5ae8baf28e32 | 780 | //Enregistrement de la chaine |
POTLESS_2 | 43:5ae8baf28e32 | 781 | if (FLAG_REC) { |
POTLESS_2 | 43:5ae8baf28e32 | 782 | UTILS::Write_Flash_File(to_store, Log_File_Name); |
POTLESS_2 | 43:5ae8baf28e32 | 783 | count ++; |
POTLESS_2 | 43:5ae8baf28e32 | 784 | if (count > Max_Log_Size) { |
POTLESS_2 | 43:5ae8baf28e32 | 785 | Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 786 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 43:5ae8baf28e32 | 787 | count = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 788 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 789 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 790 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 791 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 792 | } |
POTLESS_2 | 43:5ae8baf28e32 | 793 | |
POTLESS_2 | 43:5ae8baf28e32 | 794 | //Update du PID |
POTLESS_2 | 43:5ae8baf28e32 | 795 | control_Servo.setProcessValue(ppO2); |
POTLESS_2 | 43:5ae8baf28e32 | 796 | //Nouvelle sortie servo fuite si on est pas en mode SECU |
potless | 45:61ba3cc4fc55 | 797 | //if(!EN_MODE_SECU) Consigne_fuite = control_Servo.compute(); |
POTLESS_2 | 43:5ae8baf28e32 | 798 | |
POTLESS_2 | 43:5ae8baf28e32 | 799 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 43:5ae8baf28e32 | 800 | REAL_RATE.stop(); |
POTLESS_2 | 43:5ae8baf28e32 | 801 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 43:5ae8baf28e32 | 802 | RATE = REAL_RATE.read(); |
POTLESS_2 | 43:5ae8baf28e32 | 803 | //Reset du Timer |
POTLESS_2 | 43:5ae8baf28e32 | 804 | REAL_RATE.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 805 | |
POTLESS_2 | 43:5ae8baf28e32 | 806 | //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... |
POTLESS_2 | 43:5ae8baf28e32 | 807 | if (Ref_Time > RATE) { |
POTLESS_2 | 43:5ae8baf28e32 | 808 | RATE_TRUE = (Ref_Time - RATE) * 1000; |
POTLESS_2 | 43:5ae8baf28e32 | 809 | } else { |
POTLESS_2 | 43:5ae8baf28e32 | 810 | RATE_TRUE = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 811 | |
POTLESS_2 | 43:5ae8baf28e32 | 812 | //control_Servo.setInterval(RATE); |
POTLESS_2 | 43:5ae8baf28e32 | 813 | |
POTLESS_2 | 43:5ae8baf28e32 | 814 | DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); |
POTLESS_2 | 43:5ae8baf28e32 | 815 | } |
POTLESS_2 | 43:5ae8baf28e32 | 816 | |
POTLESS_2 | 43:5ae8baf28e32 | 817 | wait_ms(RATE_TRUE); |
POTLESS_2 | 34:26f6e3dbefb9 | 818 | } |
POTLESS_2 | 4:d84250f67dec | 819 | } |
POTLESS_2 | 43:5ae8baf28e32 | 820 | |
POTLESS_2 | 43:5ae8baf28e32 | 821 |