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