mbed-os github

Dependencies:   ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep

Fork of ARNSRS_testDFU by POTLESS

Committer:
potless
Date:
Thu May 31 08:03:28 2018 +0000
Revision:
54:2062e5786a66
Parent:
53:84571a5e2cda
Child:
55:6536e02d729e
OK

Who changed what in which revision?

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