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:
Fri May 04 08:13:31 2018 +0000
Revision:
44:5cd6f84a62ec
Parent:
43:5ae8baf28e32
Child:
45:61ba3cc4fc55
version carte ARNSRS sans format flash

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