![](/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@46:28298df0ac55, 2018-05-15 (annotated)
- Committer:
- POTLESS_2
- Date:
- Tue May 15 14:22:53 2018 +0000
- Revision:
- 46:28298df0ac55
- Parent:
- 45:61ba3cc4fc55
- Child:
- 47:89a088bc8866
??
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 | 46:28298df0ac55 | 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 | 46:28298df0ac55 | 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 | 46:28298df0ac55 | 70 | bool FLAG_DISPLAY = true; |
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 | 46:28298df0ac55 | 135 | //DigitalIn V_PILES_DIGI(PIN_V_PILES_DIGI); |
POTLESS_2 | 39:65ff3c4f9675 | 136 | |
POTLESS_2 | 43:5ae8baf28e32 | 137 | //Test voltage piles |
POTLESS_2 | 43:5ae8baf28e32 | 138 | AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG); |
POTLESS_2 | 31:231a96d1d1c8 | 139 | |
POTLESS_2 | 31:231a96d1d1c8 | 140 | int Vusb = 1; |
POTLESS_2 | 31:231a96d1d1c8 | 141 | int VPiles = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 142 | float VPiles_val = 1; |
POTLESS_2 | 18:bfd78c05b589 | 143 | |
POTLESS_2 | 43:5ae8baf28e32 | 144 | //Interruption pin |
POTLESS_2 | 43:5ae8baf28e32 | 145 | InterruptIn vpile_off_on(PIN_V_PILES_DIGI); |
POTLESS_2 | 43:5ae8baf28e32 | 146 | InterruptIn vusb_off_on(PIN_V_USB_DIGI); |
POTLESS_2 | 21:b8900130ca05 | 147 | |
POTLESS_2 | 29:5b822d18bce6 | 148 | void Affichage() |
POTLESS_2 | 29:5b822d18bce6 | 149 | { |
POTLESS_2 | 42:3591ec9903b4 | 150 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 151 | serialMonit.printf(" CO2 = %d ppm\r\n" , co2); |
POTLESS_2 | 29:5b822d18bce6 | 152 | serialMonit.printf(" PPO2 = %d mb\r\n", ppO2); |
POTLESS_2 | 31:231a96d1d1c8 | 153 | serialMonit.printf(" OTU = %d \r\n", (int)OTU); |
POTLESS_2 | 29:5b822d18bce6 | 154 | serialMonit.printf(" Pression = %f msw\r\n", pression); |
POTLESS_2 | 29:5b822d18bce6 | 155 | serialMonit.printf(" Temp MS5837 = %f C\r\n", Temp1); |
POTLESS_2 | 29:5b822d18bce6 | 156 | serialMonit.printf(" Temp HTU21D = %f C\n\r", Temp2); |
POTLESS_2 | 29:5b822d18bce6 | 157 | serialMonit.printf(" Humidity = %d %%\n\r", Humid); |
POTLESS_2 | 42:3591ec9903b4 | 158 | //serialMonit.printf("\n\r"); |
POTLESS_2 | 29:5b822d18bce6 | 159 | serialMonit.printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 29:5b822d18bce6 | 160 | serialMonit.printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 42:3591ec9903b4 | 161 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 162 | serialMonit.printf(" Volet Poumon = %f\r\n" , volet_poumon_Position); |
POTLESS_2 | 29:5b822d18bce6 | 163 | serialMonit.printf(" Volet Fuite = %f\r\n" , volet_fuite_Position); |
POTLESS_2 | 42:3591ec9903b4 | 164 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 165 | serialMonit.printf(" Temps d execution de la boucle = %f seconde(s)\r\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 42:3591ec9903b4 | 166 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 167 | if (FLAG_REC) serialMonit.printf(" Chaine enregistrée = %s\r\n", to_store); |
POTLESS_2 | 30:7a16a66d76f3 | 168 | else serialMonit.printf(" Pas d'enregistrement en cours."); |
POTLESS_2 | 42:3591ec9903b4 | 169 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 170 | serialMonit.printf(" V_USB = %f\r\n", Vusb); |
POTLESS_2 | 42:3591ec9903b4 | 171 | //serialMonit.printf("\r\n\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 172 | fflush(stdout); |
POTLESS_2 | 29:5b822d18bce6 | 173 | } |
POTLESS_2 | 29:5b822d18bce6 | 174 | |
potless | 38:fe77b68eec37 | 175 | |
POTLESS_2 | 19:cac3761a5d0b | 176 | //Passage en mode SECU |
POTLESS_2 | 19:cac3761a5d0b | 177 | void Mode_SECU() |
POTLESS_2 | 18:bfd78c05b589 | 178 | { |
POTLESS_2 | 43:5ae8baf28e32 | 179 | |
POTLESS_2 | 18:bfd78c05b589 | 180 | //Mise du PID en mode manuel (desactivation...) |
POTLESS_2 | 18:bfd78c05b589 | 181 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 182 | |
POTLESS_2 | 19:cac3761a5d0b | 183 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 19:cac3761a5d0b | 184 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 34:26f6e3dbefb9 | 185 | |
POTLESS_2 | 25:322ef9488e65 | 186 | Volets_Speed = 0.1; |
POTLESS_2 | 25:322ef9488e65 | 187 | Volet_DeadBand = 10; |
POTLESS_2 | 25:322ef9488e65 | 188 | |
POTLESS_2 | 19:cac3761a5d0b | 189 | while(1) { |
POTLESS_2 | 25:322ef9488e65 | 190 | wait_ms(100); |
POTLESS_2 | 19:cac3761a5d0b | 191 | if (Servo_Poumon.Pos_OK() == true) break; |
POTLESS_2 | 43:5ae8baf28e32 | 192 | if (Servo_Fuite.Pos_OK() == true) break; |
POTLESS_2 | 19:cac3761a5d0b | 193 | } |
POTLESS_2 | 43:5ae8baf28e32 | 194 | |
POTLESS_2 | 43:5ae8baf28e32 | 195 | OUTPUT(" Appareil en mode SECU\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 196 | |
POTLESS_2 | 25:322ef9488e65 | 197 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 198 | |
POTLESS_2 | 19:cac3761a5d0b | 199 | EN_MODE_SECU = true; |
POTLESS_2 | 43:5ae8baf28e32 | 200 | |
POTLESS_2 | 25:322ef9488e65 | 201 | wait_ms(100); |
POTLESS_2 | 43:5ae8baf28e32 | 202 | int Pos_P = Servo_Poumon.getPulses(); |
POTLESS_2 | 43:5ae8baf28e32 | 203 | UTILS::Store_A_Val((float)Pos_P, "Servo_Poumon.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 204 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos_P); |
POTLESS_2 | 43:5ae8baf28e32 | 205 | |
POTLESS_2 | 43:5ae8baf28e32 | 206 | int Pos_F = Servo_Fuite.getPulses(); |
POTLESS_2 | 43:5ae8baf28e32 | 207 | UTILS::Store_A_Val((float)Pos_F, "Servo_Fuite.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 208 | DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos_F); |
POTLESS_2 | 43:5ae8baf28e32 | 209 | |
POTLESS_2 | 23:7477dc855fad | 210 | Servo_Poumon.Sleep(); |
POTLESS_2 | 43:5ae8baf28e32 | 211 | Servo_Fuite.Sleep(); |
POTLESS_2 | 19:cac3761a5d0b | 212 | } |
POTLESS_2 | 19:cac3761a5d0b | 213 | |
POTLESS_2 | 19:cac3761a5d0b | 214 | //Sequence d'arrêt |
POTLESS_2 | 19:cac3761a5d0b | 215 | void Stop_Sequence() |
POTLESS_2 | 34:26f6e3dbefb9 | 216 | { |
POTLESS_2 | 43:5ae8baf28e32 | 217 | OUTPUT(" Mise en veille de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 218 | |
POTLESS_2 | 43:5ae8baf28e32 | 219 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 220 | |
POTLESS_2 | 34:26f6e3dbefb9 | 221 | Mode_SECU(); |
POTLESS_2 | 39:65ff3c4f9675 | 222 | //ejection de la flash pour pas crasher le system de fichiers |
POTLESS_2 | 39:65ff3c4f9675 | 223 | UTILS::UnMount_Flash(); |
POTLESS_2 | 40:32d89e04ead1 | 224 | |
potless | 37:f9461c6592f2 | 225 | // préparation deepsleep |
POTLESS_2 | 40:32d89e04ead1 | 226 | |
potless | 37:f9461c6592f2 | 227 | /* |
potless | 37:f9461c6592f2 | 228 | //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 | 229 | //il est possible que ça génère un plantage et la rtc ne fonctionnera pas? |
potless | 37:f9461c6592f2 | 230 | HAL_PWREx_EnableLowPowerRunMode(); |
potless | 37:f9461c6592f2 | 231 | DEBUG("----------------LOW POWER RUN MODE--------------------\r\n"); |
POTLESS_2 | 40:32d89e04ead1 | 232 | |
potless | 37:f9461c6592f2 | 233 | bool isDSallowed; |
potless | 37:f9461c6592f2 | 234 | isDSallowed = sleep_manager_can_deep_sleep(); |
potless | 37:f9461c6592f2 | 235 | DEBUG(" Deep sleep autorisé ? %i\r\n", isDSallowed); |
potless | 37:f9461c6592f2 | 236 | wait(1.0); |
POTLESS_2 | 34:26f6e3dbefb9 | 237 | |
potless | 37:f9461c6592f2 | 238 | DEBUG("\n\r Deepsleep tentative normale !(bouton bleu pour ressortir)\n"); |
potless | 37:f9461c6592f2 | 239 | wait(0.1); |
POTLESS_2 | 40:32d89e04ead1 | 240 | |
potless | 37:f9461c6592f2 | 241 | sleep_manager_sleep_auto(); // ne marche pas, je ne sais pas pk |
potless | 37:f9461c6592f2 | 242 | */ |
POTLESS_2 | 40:32d89e04ead1 | 243 | |
POTLESS_2 | 40:32d89e04ead1 | 244 | |
potless | 37:f9461c6592f2 | 245 | DEBUG("\n\r Deepsleep méthode offensive !\n"); |
POTLESS_2 | 40:32d89e04ead1 | 246 | |
POTLESS_2 | 39:65ff3c4f9675 | 247 | /* |
potless | 38:fe77b68eec37 | 248 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2); // pour PC_13 |
POTLESS_2 | 40:32d89e04ead1 | 249 | // Clear wake up Flag |
POTLESS_2 | 40:32d89e04ead1 | 250 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2); |
POTLESS_2 | 40:32d89e04ead1 | 251 | // Enable wakeup pin WKUP2 |
potless | 38:fe77b68eec37 | 252 | 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 | 253 | */ |
POTLESS_2 | 43:5ae8baf28e32 | 254 | HAL_PWREx_EnablePullUpPullDownConfig() ; |
POTLESS_2 | 46:28298df0ac55 | 255 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); |
POTLESS_2 | 40:32d89e04ead1 | 256 | |
potless | 38:fe77b68eec37 | 257 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 |
POTLESS_2 | 40:32d89e04ead1 | 258 | // Clear wake up Flag |
POTLESS_2 | 40:32d89e04ead1 | 259 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
POTLESS_2 | 40:32d89e04ead1 | 260 | // Enable wakeup pin WKUP2 |
POTLESS_2 | 39:65ff3c4f9675 | 261 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut |
POTLESS_2 | 40:32d89e04ead1 | 262 | |
POTLESS_2 | 40:32d89e04ead1 | 263 | // Set RTC back-up register RTC_BKP31R to indicate |
POTLESS_2 | 40:32d89e04ead1 | 264 | //later on that system has entered shutdown mode |
potless | 37:f9461c6592f2 | 265 | WRITE_REG( RTC->BKP31R, 0x1 ); |
POTLESS_2 | 40:32d89e04ead1 | 266 | //Enter shutdown mode |
potless | 37:f9461c6592f2 | 267 | DEBUG("\n\r Attention c'est du brutal ! bouton bleu pour ressort.... ZZZZZZZ ZZZZZ !!!\n"); |
POTLESS_2 | 40:32d89e04ead1 | 268 | |
potless | 37:f9461c6592f2 | 269 | HAL_PWREx_EnterSHUTDOWNMode(); |
POTLESS_2 | 18:bfd78c05b589 | 270 | } |
POTLESS_2 | 18:bfd78c05b589 | 271 | |
POTLESS_2 | 31:231a96d1d1c8 | 272 | //Fonction test de valeur d'entrée digitale |
POTLESS_2 | 29:5b822d18bce6 | 273 | int Power_Test(DigitalIn& pin) |
POTLESS_2 | 20:5f79fb4565a7 | 274 | { |
POTLESS_2 | 29:5b822d18bce6 | 275 | pin.mode(PullDown); |
POTLESS_2 | 34:26f6e3dbefb9 | 276 | |
POTLESS_2 | 34:26f6e3dbefb9 | 277 | if(!pin) { |
POTLESS_2 | 34:26f6e3dbefb9 | 278 | Stop_Sequence(); |
POTLESS_2 | 34:26f6e3dbefb9 | 279 | return 0; |
POTLESS_2 | 34:26f6e3dbefb9 | 280 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 281 | return 1; |
POTLESS_2 | 34:26f6e3dbefb9 | 282 | } |
POTLESS_2 | 20:5f79fb4565a7 | 283 | } |
POTLESS_2 | 20:5f79fb4565a7 | 284 | |
POTLESS_2 | 31:231a96d1d1c8 | 285 | //Fonction test de valeur d'entrée analogique |
POTLESS_2 | 31:231a96d1d1c8 | 286 | float Power_Test(AnalogIn& pin) |
POTLESS_2 | 31:231a96d1d1c8 | 287 | { |
POTLESS_2 | 31:231a96d1d1c8 | 288 | float Val = pin.read(); |
POTLESS_2 | 31:231a96d1d1c8 | 289 | return Val; |
POTLESS_2 | 31:231a96d1d1c8 | 290 | } |
POTLESS_2 | 31:231a96d1d1c8 | 291 | |
POTLESS_2 | 18:bfd78c05b589 | 292 | //Contrôle du status de l'appareil / des constantes |
POTLESS_2 | 18:bfd78c05b589 | 293 | bool Check() |
POTLESS_2 | 18:bfd78c05b589 | 294 | { |
POTLESS_2 | 18:bfd78c05b589 | 295 | if (ppO2 > 100) |
POTLESS_2 | 19:cac3761a5d0b | 296 | return true;//Situation OK |
POTLESS_2 | 18:bfd78c05b589 | 297 | else |
POTLESS_2 | 19:cac3761a5d0b | 298 | return false;//Situation dégradée |
POTLESS_2 | 18:bfd78c05b589 | 299 | } |
POTLESS_2 | 18:bfd78c05b589 | 300 | |
POTLESS_2 | 18:bfd78c05b589 | 301 | //Calcul des OTU |
POTLESS_2 | 18:bfd78c05b589 | 302 | float Calcul_OTU() |
POTLESS_2 | 18:bfd78c05b589 | 303 | { |
POTLESS_2 | 18:bfd78c05b589 | 304 | /* |
POTLESS_2 | 18:bfd78c05b589 | 305 | La formule suivante permet de calculer la quantité d' OTU accumulée |
POTLESS_2 | 18:bfd78c05b589 | 306 | OTU = T * (2* PpO2 -1)0,83 |
POTLESS_2 | 18:bfd78c05b589 | 307 | avec : |
POTLESS_2 | 18:bfd78c05b589 | 308 | T = temps de plongée en minutes |
POTLESS_2 | 18:bfd78c05b589 | 309 | PpO2 = pression partielle d’ oxygène en bars |
POTLESS_2 | 18:bfd78c05b589 | 310 | */ |
POTLESS_2 | 18:bfd78c05b589 | 311 | |
POTLESS_2 | 19:cac3761a5d0b | 312 | if (ppO2 > 500) { |
POTLESS_2 | 18:bfd78c05b589 | 313 | float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb... |
POTLESS_2 | 18:bfd78c05b589 | 314 | OTU += Ref_Time * pow(val, COEF_OTU); |
POTLESS_2 | 19:cac3761a5d0b | 315 | } |
POTLESS_2 | 18:bfd78c05b589 | 316 | } |
POTLESS_2 | 10:aca745a66d51 | 317 | |
POTLESS_2 | 17:bef8abc445f2 | 318 | //Thread d'intérogation des capteurs, positions servo |
POTLESS_2 | 34:26f6e3dbefb9 | 319 | void SENSORS_thread() |
POTLESS_2 | 6:ebed9093d661 | 320 | { |
POTLESS_2 | 7:ad15c386e960 | 321 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 322 | //DEEP_DEBUG(" SENSORS_thread\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 323 | |
POTLESS_2 | 7:ad15c386e960 | 324 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 325 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 326 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 327 | pression = sensors.requestPress(); |
POTLESS_2 | 9:04bfdfc029cb | 328 | Temp1 = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 329 | //PPO2 sur ADS1015 |
POTLESS_2 | 33:f5d4bae05f16 | 330 | if (FLAG_O2) ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 331 | //Cell O2 en mV |
POTLESS_2 | 33:f5d4bae05f16 | 332 | if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 33:f5d4bae05f16 | 333 | if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 9:04bfdfc029cb | 334 | |
POTLESS_2 | 8:a750d531b381 | 335 | //HTU21D |
POTLESS_2 | 9:04bfdfc029cb | 336 | Temp2 = temphumid.sample_ctemp(); |
POTLESS_2 | 9:04bfdfc029cb | 337 | Humid = temphumid.sample_humid(); |
POTLESS_2 | 9:04bfdfc029cb | 338 | |
POTLESS_2 | 10:aca745a66d51 | 339 | //Retour position des servos |
POTLESS_2 | 17:bef8abc445f2 | 340 | volet_poumon_Position = Servo_Poumon.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 341 | volet_fuite_Position = Servo_Fuite.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 342 | |
POTLESS_2 | 43:5ae8baf28e32 | 343 | //Calcul des OTU |
POTLESS_2 | 43:5ae8baf28e32 | 344 | Calcul_OTU(); |
POTLESS_2 | 34:26f6e3dbefb9 | 345 | |
POTLESS_2 | 19:cac3761a5d0b | 346 | } |
POTLESS_2 | 19:cac3761a5d0b | 347 | } |
POTLESS_2 | 12:7f3aadd79f89 | 348 | |
POTLESS_2 | 19:cac3761a5d0b | 349 | void GO_TO_thread() |
POTLESS_2 | 19:cac3761a5d0b | 350 | { |
POTLESS_2 | 19:cac3761a5d0b | 351 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 352 | //DEEP_DEBUG(" GO_TO_Thread\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 353 | |
POTLESS_2 | 19:cac3761a5d0b | 354 | //Servo_Poumon.Go_To_Prop(Consigne_poumon); |
POTLESS_2 | 26:a2fe19341f92 | 355 | //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand); |
POTLESS_2 | 34:26f6e3dbefb9 | 356 | Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 34:26f6e3dbefb9 | 357 | |
POTLESS_2 | 19:cac3761a5d0b | 358 | //Servo_Fuite.Go_To_Prop(Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 359 | //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand); |
POTLESS_2 | 43:5ae8baf28e32 | 360 | Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand ); |
POTLESS_2 | 15:efd3b3bf3f37 | 361 | } |
potless | 2:4a8bf1d53439 | 362 | } |
POTLESS_2 | 4:d84250f67dec | 363 | |
POTLESS_2 | 20:5f79fb4565a7 | 364 | void SECU_thread() |
POTLESS_2 | 20:5f79fb4565a7 | 365 | { |
POTLESS_2 | 34:26f6e3dbefb9 | 366 | while (true) { |
POTLESS_2 | 34:26f6e3dbefb9 | 367 | |
POTLESS_2 | 20:5f79fb4565a7 | 368 | } |
POTLESS_2 | 20:5f79fb4565a7 | 369 | } |
POTLESS_2 | 20:5f79fb4565a7 | 370 | |
POTLESS_2 | 11:b2feed92584a | 371 | //Callback de l'intérruption des envois de commandes depuis le terminal |
POTLESS_2 | 6:ebed9093d661 | 372 | void callbackParam() |
POTLESS_2 | 34:26f6e3dbefb9 | 373 | { |
POTLESS_2 | 40:32d89e04ead1 | 374 | |
POTLESS_2 | 40:32d89e04ead1 | 375 | |
POTLESS_2 | 34:26f6e3dbefb9 | 376 | while(serialMonit.readable()) { |
POTLESS_2 | 40:32d89e04ead1 | 377 | if ((indexParam == sizeParam) || newParamFlag == true) { //éviter la saturation du buffer |
potless | 44:5cd6f84a62ec | 378 | NVIC_DisableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 29:5b822d18bce6 | 379 | char char_flush = serialMonit.getc(); |
potless | 44:5cd6f84a62ec | 380 | NVIC_EnableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 40:32d89e04ead1 | 381 | } else { |
potless | 44:5cd6f84a62ec | 382 | NVIC_DisableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 29:5b822d18bce6 | 383 | param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 40:32d89e04ead1 | 384 | if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 40:32d89e04ead1 | 385 | param[indexParam] = 0; |
POTLESS_2 | 40:32d89e04ead1 | 386 | newParamFlag = true; |
POTLESS_2 | 40:32d89e04ead1 | 387 | } |
potless | 44:5cd6f84a62ec | 388 | NVIC_EnableIRQ(USART2_IRQn); // USART 2 pour carte ARNSRS |
POTLESS_2 | 34:26f6e3dbefb9 | 389 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 390 | } |
POTLESS_2 | 6:ebed9093d661 | 391 | } |
POTLESS_2 | 4:d84250f67dec | 392 | |
POTLESS_2 | 9:04bfdfc029cb | 393 | void Decoding_Message(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 394 | { |
POTLESS_2 | 9:04bfdfc029cb | 395 | |
POTLESS_2 | 42:3591ec9903b4 | 396 | char com[20] = ""; |
POTLESS_2 | 42:3591ec9903b4 | 397 | char numb[30] = ""; |
POTLESS_2 | 36:1f5e2247b073 | 398 | |
POTLESS_2 | 34:26f6e3dbefb9 | 399 | sscanf(message,"%s %s",&com , &numb); |
POTLESS_2 | 36:1f5e2247b073 | 400 | |
POTLESS_2 | 35:a209a192f431 | 401 | DEEP_DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 42:3591ec9903b4 | 402 | //serialMonit.printf("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 36:1f5e2247b073 | 403 | |
POTLESS_2 | 43:5ae8baf28e32 | 404 | OUTPUT("?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 405 | |
POTLESS_2 | 30:7a16a66d76f3 | 406 | if (0 == strcmp(com, "secu")) { |
POTLESS_2 | 19:cac3761a5d0b | 407 | Mode_SECU(); |
POTLESS_2 | 42:3591ec9903b4 | 408 | } else if (0 == strcmp(com, "PING")) { |
POTLESS_2 | 43:5ae8baf28e32 | 409 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 410 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 411 | FLAG_WINDEV = false; |
POTLESS_2 | 43:5ae8baf28e32 | 412 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 34:26f6e3dbefb9 | 413 | } else if (0 == strcmp(com, "ARNSRS_ID")) { |
POTLESS_2 | 43:5ae8baf28e32 | 414 | OUTPUT("Changement de l'ID de l'appareil pour le N°: %s?\r\n", numb); |
POTLESS_2 | 34:26f6e3dbefb9 | 415 | UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID"); |
POTLESS_2 | 43:5ae8baf28e32 | 416 | } else if (0 == strcmp(com, "monit")) { |
POTLESS_2 | 43:5ae8baf28e32 | 417 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 418 | FLAG_WINDEV = true; |
POTLESS_2 | 43:5ae8baf28e32 | 419 | } else if (0 == strcmp(com, "debug")) { |
POTLESS_2 | 43:5ae8baf28e32 | 420 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 421 | FLAG_WINDEV = false; |
POTLESS_2 | 34:26f6e3dbefb9 | 422 | } else if (0 == strcmp(com, "Head_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 423 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 43:5ae8baf28e32 | 424 | OUTPUT("Changement de l'ID de la tête capteur pour le N°: %s\r\n", numb); |
POTLESS_2 | 34:26f6e3dbefb9 | 425 | UTILS::write_EEPROM(numb, HEAD_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 426 | } else if (0 == strcmp(com, "O2_1_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 427 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 428 | UTILS::write_EEPROM(numb, CELL_O2_1_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 429 | } else if (0 == strcmp(com, "O2_2_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 430 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 431 | UTILS::write_EEPROM(numb, CELL_O2_2_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 432 | } else if (0 == strcmp(com, "CO2_ID")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 433 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 434 | UTILS::write_EEPROM(numb, CO2_ID); |
POTLESS_2 | 34:26f6e3dbefb9 | 435 | } else if (0 == strcmp(com, "calib_O2")) { |
POTLESS_2 | 33:f5d4bae05f16 | 436 | FLAG_O2 = false; |
POTLESS_2 | 33:f5d4bae05f16 | 437 | wait_ms(100); |
POTLESS_2 | 42:3591ec9903b4 | 438 | float Val = sensors.Calibrate_O2(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 439 | OUTPUT(" Calibration O2 dans l'air = %f\r\n", Val); |
POTLESS_2 | 33:f5d4bae05f16 | 440 | wait_ms(100); |
POTLESS_2 | 33:f5d4bae05f16 | 441 | FLAG_O2 = true; |
POTLESS_2 | 41:51ba69648f9d | 442 | } else if (0 == strcmp(com, "calib_CO2_A")) { |
POTLESS_2 | 43:5ae8baf28e32 | 443 | int Val = sensors.Calibrate_CO2(); |
POTLESS_2 | 43:5ae8baf28e32 | 444 | OUTPUT(" Calibration CO2 dans l'air = %d\r\n", Val); |
POTLESS_2 | 34:26f6e3dbefb9 | 445 | } else if (0 == strcmp(com, "flash_i")) { |
POTLESS_2 | 42:3591ec9903b4 | 446 | UTILS::Flash_Infos(&serialMonit); |
POTLESS_2 | 36:1f5e2247b073 | 447 | } else if (0 == strcmp(com, "flash_u")) { |
POTLESS_2 | 43:5ae8baf28e32 | 448 | OUTPUT(" Démontage de la Flash.\r\n"); |
POTLESS_2 | 36:1f5e2247b073 | 449 | FLAG_REC = false; |
POTLESS_2 | 36:1f5e2247b073 | 450 | UTILS::UnMount_Flash(); |
POTLESS_2 | 36:1f5e2247b073 | 451 | } else if (0 == strcmp(com, "flash_m")) { |
POTLESS_2 | 43:5ae8baf28e32 | 452 | OUTPUT(" Montage de la Flash.\r\n"); |
POTLESS_2 | 40:32d89e04ead1 | 453 | UTILS::Mount_Flash(); |
POTLESS_2 | 35:a209a192f431 | 454 | } else if (0 == strcmp(com, "check_F")) { |
POTLESS_2 | 43:5ae8baf28e32 | 455 | OUTPUT(" ARNSRS_ID.sys = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID.sys")); |
POTLESS_2 | 43:5ae8baf28e32 | 456 | OUTPUT(" Servo_Poumon.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon.sys")); |
POTLESS_2 | 43:5ae8baf28e32 | 457 | OUTPUT(" Servo_Fuite.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite.sys")); |
POTLESS_2 | 35:a209a192f431 | 458 | } else if (0 == strcmp(com, "check_E")) { |
POTLESS_2 | 42:3591ec9903b4 | 459 | sensors.Sensor_head_check(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 460 | } else if (0 == strcmp(com, "rec")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 461 | if (FLAG_REC) { |
POTLESS_2 | 34:26f6e3dbefb9 | 462 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 463 | OUTPUT(" Arrêt du Data Logging.\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 464 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 465 | FLAG_REC = true; |
POTLESS_2 | 43:5ae8baf28e32 | 466 | OUTPUT(" Démarrage Data Logging dans %s\r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 467 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 468 | } else if (0 == strcmp(com, "help")) { |
POTLESS_2 | 29:5b822d18bce6 | 469 | FLAG_AFF = false; |
POTLESS_2 | 42:3591ec9903b4 | 470 | UTILS::Help(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 471 | } else if (0 == strcmp(com, "start")) { |
POTLESS_2 | 29:5b822d18bce6 | 472 | FLAG_AFF = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 473 | } else if (0 == strcmp(com, "stop")) { |
POTLESS_2 | 29:5b822d18bce6 | 474 | FLAG_AFF = false; |
POTLESS_2 | 40:32d89e04ead1 | 475 | //UTILS::Help(); |
POTLESS_2 | 36:1f5e2247b073 | 476 | } else if (0 == strcmp(com, "flash_c")) { |
POTLESS_2 | 29:5b822d18bce6 | 477 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 478 | UTILS::Clean_Flash(); |
POTLESS_2 | 42:3591ec9903b4 | 479 | } else if (0 == strcmp(com, "flash_f")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 480 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 481 | UTILS::Clean_Flash_All(); |
POTLESS_2 | 42:3591ec9903b4 | 482 | } else if (0 == strcmp(com, "dir")) { |
POTLESS_2 | 43:5ae8baf28e32 | 483 | FLAG_WINDEV = false; |
POTLESS_2 | 43:5ae8baf28e32 | 484 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 485 | wait(0.5); |
POTLESS_2 | 42:3591ec9903b4 | 486 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 42:3591ec9903b4 | 487 | } else if (0 == strcmp(com, "get")) { |
POTLESS_2 | 29:5b822d18bce6 | 488 | wait_ms(100); |
POTLESS_2 | 43:5ae8baf28e32 | 489 | char filename[20]; |
POTLESS_2 | 43:5ae8baf28e32 | 490 | UTILS::Read_Flash_File(&serialMonit, numb); |
POTLESS_2 | 43:5ae8baf28e32 | 491 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 492 | } else if (0 == strcmp(com, "del")) { |
POTLESS_2 | 29:5b822d18bce6 | 493 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 494 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 495 | UTILS::Delete_Flash_File(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 496 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 497 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 498 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 31:231a96d1d1c8 | 499 | FLAG_REC = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 500 | } else if (0 == strcmp(com, "file_s")) { |
POTLESS_2 | 31:231a96d1d1c8 | 501 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 502 | UTILS::Get_File_Size(&serialMonit, numb); |
POTLESS_2 | 29:5b822d18bce6 | 503 | } else if (0 == strcmp(com, "calib_p")) { |
POTLESS_2 | 20:5f79fb4565a7 | 504 | Consigne_poumon = 0; |
POTLESS_2 | 20:5f79fb4565a7 | 505 | volet_poumon_Position = 0; |
POTLESS_2 | 19:cac3761a5d0b | 506 | Servo_Poumon.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 507 | OUTPUT(" Volet poumon Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 508 | } else if (0 == strcmp(com, "calib_f")) { |
POTLESS_2 | 29:5b822d18bce6 | 509 | Consigne_fuite = 0; |
POTLESS_2 | 29:5b822d18bce6 | 510 | volet_fuite_Position = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 511 | Servo_Fuite.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 512 | OUTPUT(" Volet fuite Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 513 | } else if (0 == strcmp(com, "sleep")) { |
POTLESS_2 | 19:cac3761a5d0b | 514 | Stop_Sequence(); |
POTLESS_2 | 29:5b822d18bce6 | 515 | } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s " |
POTLESS_2 | 34:26f6e3dbefb9 | 516 | set_time(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 517 | OUTPUT(" La RTC a été mise à l'heure.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 518 | } else if (0 == strcmp(com, "c_pou")) { |
POTLESS_2 | 43:5ae8baf28e32 | 519 | Consigne_poumon = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 520 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 521 | } else if (0 == strcmp(com, "c_fui")) { |
POTLESS_2 | 43:5ae8baf28e32 | 522 | Consigne_fuite = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 523 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 524 | } else if (0 == strcmp(com, "mp_pou")) { |
POTLESS_2 | 41:51ba69648f9d | 525 | Consigne_poumon += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 526 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 527 | } else if (0 == strcmp(com, "mp_fui")) { |
POTLESS_2 | 41:51ba69648f9d | 528 | Consigne_fuite += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 529 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 29:5b822d18bce6 | 530 | } else if (0 == strcmp(com, "reset")) { |
POTLESS_2 | 43:5ae8baf28e32 | 531 | FLAG_REC = false; |
POTLESS_2 | 36:1f5e2247b073 | 532 | UTILS::UnMount_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 533 | OUTPUT(" Reset de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 534 | wait(1); |
POTLESS_2 | 10:aca745a66d51 | 535 | NVIC_SystemReset(); |
POTLESS_2 | 43:5ae8baf28e32 | 536 | } else if (0 == strcmp(com, "Kc")) { |
POTLESS_2 | 43:5ae8baf28e32 | 537 | Kc = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 538 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 539 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 540 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 541 | } else if (0 == strcmp(com, "Ti")) { |
POTLESS_2 | 43:5ae8baf28e32 | 542 | Ti = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 543 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 544 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 545 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 546 | } else if (0 == strcmp(com, "Td")) { |
POTLESS_2 | 43:5ae8baf28e32 | 547 | Td = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 548 | control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 549 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 550 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); |
POTLESS_2 | 43:5ae8baf28e32 | 551 | } else if (0 == strcmp(com, "Cons")) { |
POTLESS_2 | 43:5ae8baf28e32 | 552 | consigne = atoi(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 553 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 43:5ae8baf28e32 | 554 | OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d?\r\n", consigne); |
POTLESS_2 | 43:5ae8baf28e32 | 555 | } else if (0 == strcmp(com, "PID")) { |
POTLESS_2 | 43:5ae8baf28e32 | 556 | if (FLAG_PID == 1) { |
POTLESS_2 | 43:5ae8baf28e32 | 557 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 558 | OUTPUT(" PID OFF?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 559 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 560 | } else if (FLAG_PID == 0) { |
POTLESS_2 | 43:5ae8baf28e32 | 561 | control_Servo.setMode(AUTO_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 562 | OUTPUT(" PID ON?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 563 | FLAG_PID = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 564 | } |
POTLESS_2 | 12:7f3aadd79f89 | 565 | } else { |
POTLESS_2 | 43:5ae8baf28e32 | 566 | |
POTLESS_2 | 9:04bfdfc029cb | 567 | sensors.cozirSend(message); |
POTLESS_2 | 9:04bfdfc029cb | 568 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 569 | |
POTLESS_2 | 9:04bfdfc029cb | 570 | strcpy(param," "); |
POTLESS_2 | 9:04bfdfc029cb | 571 | indexParam = 0; |
POTLESS_2 | 9:04bfdfc029cb | 572 | newParamFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 573 | } |
POTLESS_2 | 9:04bfdfc029cb | 574 | |
POTLESS_2 | 26:a2fe19341f92 | 575 | void Create_File_Name_Date() |
POTLESS_2 | 25:322ef9488e65 | 576 | { |
POTLESS_2 | 25:322ef9488e65 | 577 | //Du nom du fichier Date / heure |
POTLESS_2 | 25:322ef9488e65 | 578 | seconds = time(NULL); |
POTLESS_2 | 25:322ef9488e65 | 579 | char Time[40]; |
POTLESS_2 | 25:322ef9488e65 | 580 | strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds)); |
POTLESS_2 | 42:3591ec9903b4 | 581 | sprintf(Log_File_Name, "%s_LOG.csv", Time); |
POTLESS_2 | 42:3591ec9903b4 | 582 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 583 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 584 | |
POTLESS_2 | 26:a2fe19341f92 | 585 | void Create_File_Name_Index() |
POTLESS_2 | 26:a2fe19341f92 | 586 | { |
POTLESS_2 | 26:a2fe19341f92 | 587 | //Du nom du fichier par Index |
POTLESS_2 | 42:3591ec9903b4 | 588 | sprintf(Log_File_Name, "LOG_%d.csv", UTILS::File_Index()); |
POTLESS_2 | 34:26f6e3dbefb9 | 589 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 590 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 591 | |
POTLESS_2 | 4:d84250f67dec | 592 | int main() |
POTLESS_2 | 12:7f3aadd79f89 | 593 | { |
POTLESS_2 | 40:32d89e04ead1 | 594 | |
POTLESS_2 | 40:32d89e04ead1 | 595 | HAL_Init(); |
POTLESS_2 | 40:32d89e04ead1 | 596 | |
POTLESS_2 | 40:32d89e04ead1 | 597 | __HAL_RCC_PWR_CLK_ENABLE(); |
potless | 37:f9461c6592f2 | 598 | HAL_PWR_EnableBkUpAccess(); |
POTLESS_2 | 40:32d89e04ead1 | 599 | |
POTLESS_2 | 43:5ae8baf28e32 | 600 | //Ci-dessous commande pour formater une nouvelle carte |
POTLESS_2 | 43:5ae8baf28e32 | 601 | //UTILS::Format_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 602 | |
POTLESS_2 | 43:5ae8baf28e32 | 603 | //Montage Flash |
POTLESS_2 | 43:5ae8baf28e32 | 604 | UTILS::Mount_Flash(); |
POTLESS_2 | 12:7f3aadd79f89 | 605 | |
POTLESS_2 | 43:5ae8baf28e32 | 606 | //Liste des fichiers sur la Flash |
POTLESS_2 | 43:5ae8baf28e32 | 607 | //UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 26:a2fe19341f92 | 608 | |
POTLESS_2 | 43:5ae8baf28e32 | 609 | if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { |
POTLESS_2 | 43:5ae8baf28e32 | 610 | UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 611 | DEBUG("ARNSRS ID forcée à 000\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 612 | } |
potless | 45:61ba3cc4fc55 | 613 | /* |
potless | 45:61ba3cc4fc55 | 614 | while(1){ |
potless | 45:61ba3cc4fc55 | 615 | OUTPUT("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n");} |
potless | 45:61ba3cc4fc55 | 616 | */ |
POTLESS_2 | 34:26f6e3dbefb9 | 617 | |
POTLESS_2 | 43:5ae8baf28e32 | 618 | //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème... |
POTLESS_2 | 43:5ae8baf28e32 | 619 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 620 | char YEAR[10]; |
POTLESS_2 | 43:5ae8baf28e32 | 621 | strftime(YEAR, 10, "%D", localtime(&seconds)); |
POTLESS_2 | 43:5ae8baf28e32 | 622 | if (0 == strcmp(YEAR, "01/01/70")); //OUTPUT(" Vous devez régler la RTC...\r\n\r\n"); |
POTLESS_2 | 18:bfd78c05b589 | 623 | |
POTLESS_2 | 43:5ae8baf28e32 | 624 | bool calib_O2 = false; |
POTLESS_2 | 43:5ae8baf28e32 | 625 | bool calib_CO2 = false; |
POTLESS_2 | 18:bfd78c05b589 | 626 | |
POTLESS_2 | 43:5ae8baf28e32 | 627 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 628 | Par défaut les valeur en cas de calibration sur true sont les suivant |
POTLESS_2 | 18:bfd78c05b589 | 629 | |
POTLESS_2 | 43:5ae8baf28e32 | 630 | nbCalibO2 = 5 |
POTLESS_2 | 43:5ae8baf28e32 | 631 | Mode = SPOOLING |
POTLESS_2 | 43:5ae8baf28e32 | 632 | Filtre = DIGI_FILTER32 |
POTLESS_2 | 43:5ae8baf28e32 | 633 | CalibrationCO2 = "CALIB_AIR" |
POTLESS_2 | 18:bfd78c05b589 | 634 | |
POTLESS_2 | 43:5ae8baf28e32 | 635 | Parfois la calibration du Cozir coince...faire reset et relancer... |
POTLESS_2 | 43:5ae8baf28e32 | 636 | |
POTLESS_2 | 43:5ae8baf28e32 | 637 | Pour calibrer avec ces paramètres : |
POTLESS_2 | 18:bfd78c05b589 | 638 | |
POTLESS_2 | 43:5ae8baf28e32 | 639 | sensors.Sensors_INIT(true, true); |
POTLESS_2 | 43:5ae8baf28e32 | 640 | |
POTLESS_2 | 43:5ae8baf28e32 | 641 | Pour changer utiliser la syntaxe suivante : |
POTLESS_2 | 43:5ae8baf28e32 | 642 | |
POTLESS_2 | 43:5ae8baf28e32 | 643 | sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); |
POTLESS_2 | 43:5ae8baf28e32 | 644 | |
POTLESS_2 | 43:5ae8baf28e32 | 645 | */ |
POTLESS_2 | 43:5ae8baf28e32 | 646 | |
POTLESS_2 | 43:5ae8baf28e32 | 647 | sensors.Sensors_INIT(calib_O2, calib_CO2); |
POTLESS_2 | 43:5ae8baf28e32 | 648 | |
POTLESS_2 | 43:5ae8baf28e32 | 649 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 650 | |
POTLESS_2 | 43:5ae8baf28e32 | 651 | //Création du nouveau fichier LOG par index / par date. |
POTLESS_2 | 43:5ae8baf28e32 | 652 | //Create_File_Name_Index(); |
POTLESS_2 | 43:5ae8baf28e32 | 653 | Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 654 | |
POTLESS_2 | 43:5ae8baf28e32 | 655 | //Création et écriture du header du fichier LOG |
POTLESS_2 | 43:5ae8baf28e32 | 656 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 42:3591ec9903b4 | 657 | |
POTLESS_2 | 43:5ae8baf28e32 | 658 | Servo_Poumon.Init("Servo_Poumon.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 659 | Servo_Fuite.Init("Servo_Fuite.sys"); |
POTLESS_2 | 15:efd3b3bf3f37 | 660 | |
POTLESS_2 | 43:5ae8baf28e32 | 661 | //OUTPUT(" Demarrage des threads...\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 662 | |
POTLESS_2 | 43:5ae8baf28e32 | 663 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 664 | |
POTLESS_2 | 43:5ae8baf28e32 | 665 | Pour mémoire, les réglage de priorité des thread |
POTLESS_2 | 15:efd3b3bf3f37 | 666 | |
POTLESS_2 | 43:5ae8baf28e32 | 667 | osPriorityIdle = -3, ///< priority: idle (lowest) |
POTLESS_2 | 43:5ae8baf28e32 | 668 | osPriorityLow = -2, ///< priority: low |
POTLESS_2 | 43:5ae8baf28e32 | 669 | osPriorityBelowNormal = -1, ///< priority: below normal |
POTLESS_2 | 43:5ae8baf28e32 | 670 | osPriorityNormal = 0, ///< priority: normal (default) |
POTLESS_2 | 43:5ae8baf28e32 | 671 | osPriorityAboveNormal = +1, ///< priority: above normal |
POTLESS_2 | 43:5ae8baf28e32 | 672 | osPriorityHigh = +2, ///< priority: high |
POTLESS_2 | 43:5ae8baf28e32 | 673 | osPriorityRealtime = +3, ///< priority: realtime (highest) |
POTLESS_2 | 43:5ae8baf28e32 | 674 | osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority |
POTLESS_2 | 43:5ae8baf28e32 | 675 | */ |
POTLESS_2 | 18:bfd78c05b589 | 676 | |
POTLESS_2 | 43:5ae8baf28e32 | 677 | wait(1); |
POTLESS_2 | 20:5f79fb4565a7 | 678 | |
POTLESS_2 | 43:5ae8baf28e32 | 679 | Thread thread_Volets(osPriorityNormal); |
POTLESS_2 | 43:5ae8baf28e32 | 680 | |
POTLESS_2 | 43:5ae8baf28e32 | 681 | thread_Volets.start(callback(GO_TO_thread)); |
POTLESS_2 | 12:7f3aadd79f89 | 682 | |
POTLESS_2 | 43:5ae8baf28e32 | 683 | //OUTPUT(" Contrôle des volets démarré\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 684 | |
POTLESS_2 | 43:5ae8baf28e32 | 685 | wait(1); |
POTLESS_2 | 34:26f6e3dbefb9 | 686 | |
POTLESS_2 | 43:5ae8baf28e32 | 687 | Thread thread_Secu(osPriorityNormal); |
POTLESS_2 | 43:5ae8baf28e32 | 688 | |
POTLESS_2 | 43:5ae8baf28e32 | 689 | thread_Secu.start(callback(SECU_thread)); |
POTLESS_2 | 34:26f6e3dbefb9 | 690 | |
POTLESS_2 | 43:5ae8baf28e32 | 691 | //OUTPUT(" Contrôle des paramètres de sécu démarré\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 692 | |
POTLESS_2 | 43:5ae8baf28e32 | 693 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 694 | |
POTLESS_2 | 43:5ae8baf28e32 | 695 | Thread thread_Head(osPriorityNormal); |
POTLESS_2 | 36:1f5e2247b073 | 696 | |
POTLESS_2 | 43:5ae8baf28e32 | 697 | thread_Head.start(callback(SENSORS_thread)); |
POTLESS_2 | 36:1f5e2247b073 | 698 | |
POTLESS_2 | 43:5ae8baf28e32 | 699 | //OUTPUT(" Tête capteurs démarrée\r\n\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 700 | |
POTLESS_2 | 43:5ae8baf28e32 | 701 | wait(1); |
POTLESS_2 | 9:04bfdfc029cb | 702 | |
POTLESS_2 | 43:5ae8baf28e32 | 703 | //Init PID |
POTLESS_2 | 43:5ae8baf28e32 | 704 | //Entrée PPO2 entre 100 et 1000 mb |
POTLESS_2 | 43:5ae8baf28e32 | 705 | control_Servo.setInputLimits(Min_Input, Max_Input); |
POTLESS_2 | 43:5ae8baf28e32 | 706 | //Sortie servo entre 0 et 100 % |
POTLESS_2 | 43:5ae8baf28e32 | 707 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 43:5ae8baf28e32 | 708 | //Mode auto au démarrage |
POTLESS_2 | 43:5ae8baf28e32 | 709 | control_Servo.setMode(MANUAL_MODE); |
POTLESS_2 | 43:5ae8baf28e32 | 710 | //Consigne à x mb |
POTLESS_2 | 43:5ae8baf28e32 | 711 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 34:26f6e3dbefb9 | 712 | |
POTLESS_2 | 43:5ae8baf28e32 | 713 | //OUTPUT(" Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 714 | |
POTLESS_2 | 43:5ae8baf28e32 | 715 | |
POTLESS_2 | 46:28298df0ac55 | 716 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 717 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 718 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 43:5ae8baf28e32 | 719 | |
POTLESS_2 | 43:5ae8baf28e32 | 720 | serialMonit.attach(&callbackParam, Serial::RxIrq); |
potless | 45:61ba3cc4fc55 | 721 | |
POTLESS_2 | 46:28298df0ac55 | 722 | vusb_off_on.fall(&Stop_Sequence); |
POTLESS_2 | 46:28298df0ac55 | 723 | |
POTLESS_2 | 46:28298df0ac55 | 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 | 46:28298df0ac55 | 769 | if (FLAG_DISPLAY) { |
POTLESS_2 | 46:28298df0ac55 | 770 | IHM("%s\r\n", to_store); |
POTLESS_2 | 46:28298df0ac55 | 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 |