![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
main.cpp@84:49f0acf09f67, 2018-09-10 (annotated)
- Committer:
- POTLESS_2
- Date:
- Mon Sep 10 09:33:38 2018 +0000
- Revision:
- 84:49f0acf09f67
- Parent:
- 83:855eb58c017d
- Child:
- 85:98861c7bb3a1
- Child:
- 86:02e83a215e4e
ajout de commandes reset PID, changement des output limit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
potless | 1:bef7856b5c0a | 1 | #include "mbed.h" |
potless | 2:4a8bf1d53439 | 2 | #include <string> |
POTLESS_2 | 7:ad15c386e960 | 3 | #include "Sensor_head_revB.h" |
POTLESS_2 | 8:a750d531b381 | 4 | #include "HTU21D.h" |
POTLESS_2 | 12:7f3aadd79f89 | 5 | #include "PID.h" |
POTLESS_2 | 19:cac3761a5d0b | 6 | #include "Faulhaber.h" |
POTLESS_2 | 29:5b822d18bce6 | 7 | #include "Utils.h" |
POTLESS_2 | 47:89a088bc8866 | 8 | #include "beep.h" |
POTLESS_2 | 47:89a088bc8866 | 9 | #include "USBSerial.h" |
POTLESS_2 | 4:d84250f67dec | 10 | |
POTLESS_2 | 17:bef8abc445f2 | 11 | //Commandes des servos |
POTLESS_2 | 19:cac3761a5d0b | 12 | #define PWM_SERVO_POUMON PB_15 |
POTLESS_2 | 19:cac3761a5d0b | 13 | #define nSleep_SERVO_POUMON PC_6 |
POTLESS_2 | 19:cac3761a5d0b | 14 | #define FWD_SERVO_POUMON PB_14 |
POTLESS_2 | 19:cac3761a5d0b | 15 | #define REV_SERVO_POUMON PB_13 |
POTLESS_2 | 55:6536e02d729e | 16 | #define Channel_A_SERVO_POUMON PB_1 |
POTLESS_2 | 55:6536e02d729e | 17 | #define Channel_B_SERVO_POUMON PB_2 |
POTLESS_2 | 19:cac3761a5d0b | 18 | #define HOME_SERVO_POUMON 0 |
POTLESS_2 | 17:bef8abc445f2 | 19 | |
POTLESS_2 | 19:cac3761a5d0b | 20 | #define PWM_SERVO_FUITE PB_10 |
POTLESS_2 | 43:5ae8baf28e32 | 21 | #define nSleep_SERVO_FUITE PB_0 |
POTLESS_2 | 55:6536e02d729e | 22 | #define FWD_SERVO_FUITE PB_5 |
POTLESS_2 | 55:6536e02d729e | 23 | #define REV_SERVO_FUITE PB_4 |
POTLESS_2 | 43:5ae8baf28e32 | 24 | #define Channel_A_SERVO_FUITE PC_9 |
POTLESS_2 | 43:5ae8baf28e32 | 25 | #define Channel_B_SERVO_FUITE PA_8 |
POTLESS_2 | 19:cac3761a5d0b | 26 | #define HOME_SERVO_FUITE 90 |
POTLESS_2 | 17:bef8abc445f2 | 27 | |
POTLESS_2 | 43:5ae8baf28e32 | 28 | //Pin de test des alims |
POTLESS_2 | 43:5ae8baf28e32 | 29 | #define PIN_V_PILES_ANALOG PA_1 |
POTLESS_2 | 59:fd64ca9dae27 | 30 | #define PIN_V_PILES_DIGI PC_3 |
POTLESS_2 | 43:5ae8baf28e32 | 31 | #define PIN_V_USB_DIGI PA_0 |
POTLESS_2 | 11:b2feed92584a | 32 | |
potless | 44:5cd6f84a62ec | 33 | //#define OUTPUT(...) { NVIC_DisableIRQ(USART3_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} |
POTLESS_2 | 56:61b0f4d6a890 | 34 | //#define OUTPUT(...) { NVIC_DisableIRQ(USART2_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART2_IRQn);} |
POTLESS_2 | 57:a0827fa46b03 | 35 | //#define OUTPUT(...) { NVIC_DisableIRQ(OTG_FS_IRQn);serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(OTG_FS_IRQn);} |
POTLESS_2 | 69:9afe54d53bb0 | 36 | #define TRACEUR_DEBUG(...) { printf(__VA_ARGS__); fflush(stdout);} |
POTLESS_2 | 69:9afe54d53bb0 | 37 | //#define TRACEUR(...) { serialMonit.printf(__VA_ARGS__); fflush(stdout);} |
POTLESS_2 | 56:61b0f4d6a890 | 38 | #define OUTPUT(...) { serialMonit.printf(__VA_ARGS__); fflush(stdout);} |
POTLESS_2 | 46:28298df0ac55 | 39 | #define IHM(...) { NVIC_DisableIRQ(USART3_IRQn); display.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} |
POTLESS_2 | 34:26f6e3dbefb9 | 40 | |
POTLESS_2 | 57:a0827fa46b03 | 41 | //Communication USB, OTG_FS |
POTLESS_2 | 82:5a0589682877 | 42 | USBSerial serialMonit; |
POTLESS_2 | 57:a0827fa46b03 | 43 | //USBSerial serialMonit;//Pour pilotes windows Olivier |
POTLESS_2 | 10:aca745a66d51 | 44 | |
POTLESS_2 | 57:a0827fa46b03 | 45 | //Moniteur série debug, Serial 2 |
POTLESS_2 | 68:7f4ab9c03b32 | 46 | Serial serial(PA_2, PA_3,115200); // UART2 à décommenter / commenter pour DEBUG et DEEP_DEBUG |
POTLESS_2 | 43:5ae8baf28e32 | 47 | |
POTLESS_2 | 57:a0827fa46b03 | 48 | //Communication avec l'IHM, Serial 3 |
POTLESS_2 | 57:a0827fa46b03 | 49 | Serial display(PC_4, PC_5, 115200); |
POTLESS_2 | 4:d84250f67dec | 50 | |
POTLESS_2 | 62:891379d80b1b | 51 | //PinName pwm, PinName nSleep, PinName fwd, PinName rev, PinName channelA, PinName channelB, int pulsesPerRev, int Rapport, Encoding encoding = X2_ENCODING |
POTLESS_2 | 62:891379d80b1b | 52 | //Angle 0 -> tuyau fermé, Angle 90 -> tuyau ouvert |
POTLESS_2 | 62:891379d80b1b | 53 | Faulhaber Servo_Poumon(VOLET_POUMON_ADDR, PWM_SERVO_POUMON, nSleep_SERVO_POUMON, FWD_SERVO_POUMON, REV_SERVO_POUMON, Channel_A_SERVO_POUMON, Channel_B_SERVO_POUMON, 16, 1257, HOME_SERVO_POUMON, Faulhaber::X2_ENCODING); |
POTLESS_2 | 62:891379d80b1b | 54 | Faulhaber Servo_Fuite(VOLET_FUITE_ADDR, PWM_SERVO_FUITE, nSleep_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, Channel_A_SERVO_FUITE, Channel_B_SERVO_FUITE, 16, 207, HOME_SERVO_FUITE, Faulhaber::X2_ENCODING); |
POTLESS_2 | 62:891379d80b1b | 55 | |
POTLESS_2 | 7:ad15c386e960 | 56 | //Init de la lib ARNSRS; |
POTLESS_2 | 7:ad15c386e960 | 57 | SENSOR_HEAD_REV_B sensors; |
potless | 2:4a8bf1d53439 | 58 | |
POTLESS_2 | 34:26f6e3dbefb9 | 59 | //pour Param Venant du PV |
POTLESS_2 | 42:3591ec9903b4 | 60 | const int sizeParam = 50; |
POTLESS_2 | 11:b2feed92584a | 61 | char param[sizeParam]; |
POTLESS_2 | 11:b2feed92584a | 62 | volatile int indexParam = 0; |
POTLESS_2 | 6:ebed9093d661 | 63 | bool newParamFlag = false; |
potless | 2:4a8bf1d53439 | 64 | |
POTLESS_2 | 56:61b0f4d6a890 | 65 | //pour Param Venant de l'IHM |
POTLESS_2 | 56:61b0f4d6a890 | 66 | const int sizeIHM = 50; |
POTLESS_2 | 56:61b0f4d6a890 | 67 | char IHM[sizeIHM]; |
POTLESS_2 | 56:61b0f4d6a890 | 68 | volatile int indexIHM = 0; |
POTLESS_2 | 56:61b0f4d6a890 | 69 | bool newIHMFlag = false; |
POTLESS_2 | 56:61b0f4d6a890 | 70 | |
POTLESS_2 | 43:5ae8baf28e32 | 71 | //Flag PID ON / OFF |
POTLESS_2 | 43:5ae8baf28e32 | 72 | int FLAG_PID = 0; |
POTLESS_2 | 42:3591ec9903b4 | 73 | |
POTLESS_2 | 42:3591ec9903b4 | 74 | //Flag pour interrompre l'affichage si on veut... |
POTLESS_2 | 42:3591ec9903b4 | 75 | bool FLAG_AFF = false; |
POTLESS_2 | 25:322ef9488e65 | 76 | |
POTLESS_2 | 70:0ae5fd4f826c | 77 | //Flag pour interrompre le traceur si on veut... |
POTLESS_2 | 68:7f4ab9c03b32 | 78 | bool FLAG_TRACE = false; |
POTLESS_2 | 68:7f4ab9c03b32 | 79 | |
POTLESS_2 | 40:32d89e04ead1 | 80 | //Flag pour envoyer à l'app windev... |
POTLESS_2 | 40:32d89e04ead1 | 81 | bool FLAG_WINDEV = false; |
POTLESS_2 | 40:32d89e04ead1 | 82 | |
POTLESS_2 | 43:5ae8baf28e32 | 83 | //Flag pour envoyer à l'IHM... |
POTLESS_2 | 46:28298df0ac55 | 84 | bool FLAG_DISPLAY = true; |
POTLESS_2 | 43:5ae8baf28e32 | 85 | |
POTLESS_2 | 29:5b822d18bce6 | 86 | //Flag pour interrompre l'enregistrement si on veut... |
POTLESS_2 | 29:5b822d18bce6 | 87 | bool FLAG_REC = true; |
POTLESS_2 | 29:5b822d18bce6 | 88 | |
POTLESS_2 | 70:0ae5fd4f826c | 89 | //Flag pour interrompre les demandes O2 en cours de calibration... |
POTLESS_2 | 33:f5d4bae05f16 | 90 | bool FLAG_O2 = true; |
POTLESS_2 | 33:f5d4bae05f16 | 91 | |
POTLESS_2 | 70:0ae5fd4f826c | 92 | //Flag si on débranche l'USB |
POTLESS_2 | 72:6d5590dbe13e | 93 | bool ALIM_UNPLUGGED = false; |
POTLESS_2 | 71:23e7435e236f | 94 | |
POTLESS_2 | 7:ad15c386e960 | 95 | //Variables de stockage des infos capteurs |
POTLESS_2 | 7:ad15c386e960 | 96 | int co2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 97 | float pression = 0; |
POTLESS_2 | 9:04bfdfc029cb | 98 | float Temp1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 99 | int ppO2 = 0; |
POTLESS_2 | 7:ad15c386e960 | 100 | int CellO2_1 = 0; |
POTLESS_2 | 7:ad15c386e960 | 101 | int CellO2_2 = 0; |
POTLESS_2 | 36:1f5e2247b073 | 102 | |
POTLESS_2 | 18:bfd78c05b589 | 103 | //Variables et constantes OTU |
POTLESS_2 | 58:694d4d00407c | 104 | Ticker OTU_Ticker; |
POTLESS_2 | 18:bfd78c05b589 | 105 | float OTU = 0; |
POTLESS_2 | 58:694d4d00407c | 106 | float EXP_OTU = 0.83; |
POTLESS_2 | 18:bfd78c05b589 | 107 | |
POTLESS_2 | 17:bef8abc445f2 | 108 | //Mesure du temps d'éxecution du loop |
POTLESS_2 | 7:ad15c386e960 | 109 | Timer REAL_RATE; |
POTLESS_2 | 7:ad15c386e960 | 110 | float RATE = 0; |
POTLESS_2 | 11:b2feed92584a | 111 | float RATE_TRUE = 0; |
POTLESS_2 | 29:5b822d18bce6 | 112 | float Ref_Time = 2.0; //La durée de la boucle désirée... |
POTLESS_2 | 7:ad15c386e960 | 113 | |
POTLESS_2 | 17:bef8abc445f2 | 114 | //HTU21D sur l'I2C |
POTLESS_2 | 8:a750d531b381 | 115 | HTU21D temphumid(PB_9, PB_8); //Temp humid sensor || SDA, SCL |
POTLESS_2 | 9:04bfdfc029cb | 116 | float Temp2; |
POTLESS_2 | 9:04bfdfc029cb | 117 | int Humid; |
POTLESS_2 | 9:04bfdfc029cb | 118 | |
POTLESS_2 | 9:04bfdfc029cb | 119 | //Data LOG |
POTLESS_2 | 9:04bfdfc029cb | 120 | char to_store[50]; |
POTLESS_2 | 9:04bfdfc029cb | 121 | time_t seconds; |
POTLESS_2 | 25:322ef9488e65 | 122 | char Log_File_Name[] = " "; |
POTLESS_2 | 42:3591ec9903b4 | 123 | int count = 0; |
POTLESS_2 | 42:3591ec9903b4 | 124 | 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 | 125 | |
POTLESS_2 | 10:aca745a66d51 | 126 | //Contrôle des servos |
POTLESS_2 | 56:61b0f4d6a890 | 127 | float Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 56:61b0f4d6a890 | 128 | float volet_poumon_Position; |
POTLESS_2 | 62:891379d80b1b | 129 | |
POTLESS_2 | 56:61b0f4d6a890 | 130 | float Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 56:61b0f4d6a890 | 131 | float volet_fuite_Position; |
POTLESS_2 | 62:891379d80b1b | 132 | |
potless | 45:61ba3cc4fc55 | 133 | float Volets_Speed = 1; |
POTLESS_2 | 62:891379d80b1b | 134 | float Volet_DeadBand = 5; |
POTLESS_2 | 10:aca745a66d51 | 135 | |
POTLESS_2 | 12:7f3aadd79f89 | 136 | //Paramètre du PID |
POTLESS_2 | 81:83567a0ce82c | 137 | float Kc = 0.005; |
POTLESS_2 | 81:83567a0ce82c | 138 | float Ti = 0.1; |
POTLESS_2 | 81:83567a0ce82c | 139 | float Td = 0.0; |
POTLESS_2 | 78:674882631acc | 140 | float RATE_PID = 10.0; |
POTLESS_2 | 12:7f3aadd79f89 | 141 | float Commande_PID; |
POTLESS_2 | 43:5ae8baf28e32 | 142 | int consigne = 210; |
POTLESS_2 | 15:efd3b3bf3f37 | 143 | float Max_Input = 1000; |
POTLESS_2 | 15:efd3b3bf3f37 | 144 | float Min_Input = 80; |
POTLESS_2 | 84:49f0acf09f67 | 145 | float Borne = 5; |
POTLESS_2 | 84:49f0acf09f67 | 146 | float Max_Output = 90 - Borne;//Vérifier la valeur pour angle à laisser ouvert... |
POTLESS_2 | 84:49f0acf09f67 | 147 | float Min_Output = 0 + Borne; |
POTLESS_2 | 10:aca745a66d51 | 148 | |
POTLESS_2 | 12:7f3aadd79f89 | 149 | //Init PID |
POTLESS_2 | 17:bef8abc445f2 | 150 | PID control_Servo(Kc, Ti, Td, RATE_PID); |
POTLESS_2 | 10:aca745a66d51 | 151 | |
POTLESS_2 | 19:cac3761a5d0b | 152 | //Boolean du status de l'appareil, en mode SECU ou nominal |
POTLESS_2 | 19:cac3761a5d0b | 153 | bool EN_MODE_SECU = false; |
POTLESS_2 | 31:231a96d1d1c8 | 154 | |
POTLESS_2 | 43:5ae8baf28e32 | 155 | //Test voltage piles |
POTLESS_2 | 43:5ae8baf28e32 | 156 | AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG); |
POTLESS_2 | 31:231a96d1d1c8 | 157 | |
POTLESS_2 | 31:231a96d1d1c8 | 158 | int Vusb = 1; |
POTLESS_2 | 31:231a96d1d1c8 | 159 | int VPiles = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 160 | float VPiles_val = 1; |
POTLESS_2 | 18:bfd78c05b589 | 161 | |
POTLESS_2 | 58:694d4d00407c | 162 | bool flag_USB = false; |
POTLESS_2 | 59:fd64ca9dae27 | 163 | bool flag_Piles = false; |
POTLESS_2 | 58:694d4d00407c | 164 | |
POTLESS_2 | 56:61b0f4d6a890 | 165 | //Commande à envoyer à l'IHM |
POTLESS_2 | 80:545af6e94aa5 | 166 | //0 -> Marche normale |
POTLESS_2 | 80:545af6e94aa5 | 167 | //1 -> Mise en veille |
POTLESS_2 | 80:545af6e94aa5 | 168 | //2 -> Perte alim |
POTLESS_2 | 56:61b0f4d6a890 | 169 | //3 -> Big problème |
POTLESS_2 | 80:545af6e94aa5 | 170 | //4 -> Reset |
POTLESS_2 | 56:61b0f4d6a890 | 171 | int Commande_IHM = 0; |
potless | 48:9ceb095f397a | 172 | |
POTLESS_2 | 70:0ae5fd4f826c | 173 | //Pin connexion USB et Piles |
POTLESS_2 | 70:0ae5fd4f826c | 174 | //DigitalIn vusb(PIN_V_USB_DIGI); |
POTLESS_2 | 70:0ae5fd4f826c | 175 | //DigitalIn vpiles(PIN_V_PILES_DIGI); |
POTLESS_2 | 70:0ae5fd4f826c | 176 | |
POTLESS_2 | 43:5ae8baf28e32 | 177 | //Interruption pin |
POTLESS_2 | 59:fd64ca9dae27 | 178 | InterruptIn vpiles_off_on(PIN_V_PILES_DIGI); |
POTLESS_2 | 70:0ae5fd4f826c | 179 | InterruptIn vusb_off_on(PIN_V_USB_DIGI); |
POTLESS_2 | 21:b8900130ca05 | 180 | |
POTLESS_2 | 57:a0827fa46b03 | 181 | //Pin enable du régulateur 5 v |
POTLESS_2 | 57:a0827fa46b03 | 182 | DigitalOut E5V(PA_4); |
POTLESS_2 | 57:a0827fa46b03 | 183 | |
POTLESS_2 | 57:a0827fa46b03 | 184 | //Pin enable du régulateur 3.3 v |
POTLESS_2 | 58:694d4d00407c | 185 | DigitalOut E3V(PB_11, PullDown); |
POTLESS_2 | 57:a0827fa46b03 | 186 | |
POTLESS_2 | 57:a0827fa46b03 | 187 | //Pin du Buzzer |
POTLESS_2 | 57:a0827fa46b03 | 188 | Beep buzzer(PC_8); |
POTLESS_2 | 57:a0827fa46b03 | 189 | |
POTLESS_2 | 58:694d4d00407c | 190 | //Déclaration des Threads |
POTLESS_2 | 62:891379d80b1b | 191 | Thread thread_Secu; |
POTLESS_2 | 62:891379d80b1b | 192 | Thread thread_Head; |
POTLESS_2 | 62:891379d80b1b | 193 | Thread thread_Volets_POUMON; |
POTLESS_2 | 62:891379d80b1b | 194 | Thread thread_Volets_FUITE; |
POTLESS_2 | 76:9dc83d5cf075 | 195 | Thread thread_PID; |
POTLESS_2 | 74:f4704f312116 | 196 | |
POTLESS_2 | 74:f4704f312116 | 197 | //Récap des fonctions |
POTLESS_2 | 74:f4704f312116 | 198 | void Save_Pos();//Sauvegarde des positions moteurs |
POTLESS_2 | 74:f4704f312116 | 199 | void Mode_SECU();//Mise en secu des moteurs |
POTLESS_2 | 74:f4704f312116 | 200 | void Sleep_IHM();//Mise en veille IHM, envoie de la consigne sur son port série |
POTLESS_2 | 80:545af6e94aa5 | 201 | void Sleep_HIGH_WakeUp();//Mise en veille MCU avec réveille sur front haut |
POTLESS_2 | 74:f4704f312116 | 202 | void Sleep_LOW_WakeUp();//Mise en veille MCU avec réveille sur front bas. BABEFACE |
POTLESS_2 | 74:f4704f312116 | 203 | void ALIM_is_unplugged();//Appelée par l'intéruption. Passe juste un FLAG à false |
POTLESS_2 | 74:f4704f312116 | 204 | void ALIM_unplugged();//Appelée par le sécu THREAD si le FLAG ci-dessus passe a false |
POTLESS_2 | 74:f4704f312116 | 205 | void Stop_Sequence();//Enchainement des fonction amenant à l'arrêt de l'appareil |
POTLESS_2 | 74:f4704f312116 | 206 | void Affichage();//Affichage complet du Debug dans le Terminal...ne pas utiliser car trop lent...préférer le même sur l'IHM |
POTLESS_2 | 74:f4704f312116 | 207 | void Traceur_Arduino();//Envoies des Data pour être interprétées par le traceur Arduino |
POTLESS_2 | 74:f4704f312116 | 208 | int Power_Test(DigitalIn& pin);//Test une pin Digital..Renvoie 1 ou 0. Pas utilisée, on utilise les intérruptions |
POTLESS_2 | 74:f4704f312116 | 209 | float Power_Test(AnalogIn& pin);//Lecture d'une pin analogique. Pas encore utilisée |
POTLESS_2 | 74:f4704f312116 | 210 | bool Check();//A remplir de paramètres qui renvoie true s'ils sont bon, false s'ils sont hors limites |
POTLESS_2 | 74:f4704f312116 | 211 | void Calcul_OTU();//Calcul des OTU, commandée par un Tcker toutes les 60 s |
POTLESS_2 | 74:f4704f312116 | 212 | void SENSORS_thread();//Thread d'intérogation des capteurs. Appelé tous les ref_time |
POTLESS_2 | 74:f4704f312116 | 213 | void GO_TO_thread_POUMON();//Thread d'asservissement en position du volet Poumon. Appelé en permanence, priorité haute |
POTLESS_2 | 74:f4704f312116 | 214 | void GO_TO_thread_FUITE();//Thread d'asservissement en position du volet Fuite. Appelé en permanence, priorité haute |
POTLESS_2 | 74:f4704f312116 | 215 | void SECU_thread();//Thread de contrôle des paramètres devant entrainer une réaction de sécurité. Pour le moment capture du Flag de l'alim débranchée |
POTLESS_2 | 78:674882631acc | 216 | void PID_thread();//Thread de calcul du PID |
POTLESS_2 | 74:f4704f312116 | 217 | void callbackParam();//Callback de l'intéruption des com sur le port USD |
POTLESS_2 | 74:f4704f312116 | 218 | void callbackIHM();//Callback de l'intéruption des com sur le port IHM |
POTLESS_2 | 74:f4704f312116 | 219 | void Decoding_Message(char message []);//Décodage des message reçu par le port USB |
POTLESS_2 | 74:f4704f312116 | 220 | void Decoding_IHM(char message []);//Décodage des message reçu par le port IHM. Uniquement le transfert sur clef USB pour le moment |
POTLESS_2 | 74:f4704f312116 | 221 | void Create_File_Name_Date();//Création d'un nom de fichier par date |
POTLESS_2 | 74:f4704f312116 | 222 | void Create_File_Name_Index();//Création d'un nom de fichier par Index |
POTLESS_2 | 74:f4704f312116 | 223 | |
POTLESS_2 | 72:6d5590dbe13e | 224 | void Save_Pos() |
POTLESS_2 | 68:7f4ab9c03b32 | 225 | { |
POTLESS_2 | 68:7f4ab9c03b32 | 226 | |
POTLESS_2 | 68:7f4ab9c03b32 | 227 | //Enregistrement position des servos sans mettre en sécu |
POTLESS_2 | 71:23e7435e236f | 228 | UTILS::EffacePage(2, PAGE_POUMON_ADDR, 1); |
POTLESS_2 | 68:7f4ab9c03b32 | 229 | |
POTLESS_2 | 71:23e7435e236f | 230 | int Pos_P = Servo_Poumon.getPulses(); |
POTLESS_2 | 68:7f4ab9c03b32 | 231 | UTILS::Write(VOLET_POUMON_ADDR, Pos_P); |
POTLESS_2 | 71:23e7435e236f | 232 | DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos_P); |
POTLESS_2 | 76:9dc83d5cf075 | 233 | |
POTLESS_2 | 71:23e7435e236f | 234 | UTILS::EffacePage(2, PAGE_FUITE_ADDR, 1); |
POTLESS_2 | 76:9dc83d5cf075 | 235 | |
POTLESS_2 | 71:23e7435e236f | 236 | int Pos_F = Servo_Fuite.getPulses(); |
POTLESS_2 | 68:7f4ab9c03b32 | 237 | UTILS::Write(VOLET_FUITE_ADDR, Pos_F); |
POTLESS_2 | 71:23e7435e236f | 238 | DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos_F); |
POTLESS_2 | 68:7f4ab9c03b32 | 239 | |
POTLESS_2 | 68:7f4ab9c03b32 | 240 | } |
POTLESS_2 | 68:7f4ab9c03b32 | 241 | |
POTLESS_2 | 72:6d5590dbe13e | 242 | //Passage en mode SECU |
POTLESS_2 | 72:6d5590dbe13e | 243 | void Mode_SECU() |
POTLESS_2 | 56:61b0f4d6a890 | 244 | { |
POTLESS_2 | 68:7f4ab9c03b32 | 245 | |
POTLESS_2 | 72:6d5590dbe13e | 246 | //Mise du PID en mode manuel (desactivation...) |
POTLESS_2 | 72:6d5590dbe13e | 247 | FLAG_PID = 0; |
POTLESS_2 | 68:7f4ab9c03b32 | 248 | |
POTLESS_2 | 71:23e7435e236f | 249 | //On coupe les thread car on va utiliser une autre fonction |
POTLESS_2 | 71:23e7435e236f | 250 | thread_Volets_POUMON.terminate(); |
POTLESS_2 | 71:23e7435e236f | 251 | thread_Volets_FUITE.terminate(); |
POTLESS_2 | 68:7f4ab9c03b32 | 252 | |
POTLESS_2 | 72:6d5590dbe13e | 253 | //A fond et avec une erreur tolérée de +- 5 deg autour du Home. Cohérent avec le future init qui recherche une erreur > 5 deg |
POTLESS_2 | 71:23e7435e236f | 254 | Volets_Speed = 1; |
POTLESS_2 | 71:23e7435e236f | 255 | Volet_DeadBand = 10; |
POTLESS_2 | 76:9dc83d5cf075 | 256 | |
POTLESS_2 | 68:7f4ab9c03b32 | 257 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 68:7f4ab9c03b32 | 258 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 76:9dc83d5cf075 | 259 | |
POTLESS_2 | 71:23e7435e236f | 260 | Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 76:9dc83d5cf075 | 261 | |
POTLESS_2 | 71:23e7435e236f | 262 | Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 76:9dc83d5cf075 | 263 | |
POTLESS_2 | 72:6d5590dbe13e | 264 | Save_Pos(); |
POTLESS_2 | 76:9dc83d5cf075 | 265 | |
POTLESS_2 | 72:6d5590dbe13e | 266 | OUTPUT(" Volet poumon en sécu\r\n"); |
POTLESS_2 | 72:6d5590dbe13e | 267 | OUTPUT(" Volet fuite en sécu\r\n"); |
POTLESS_2 | 72:6d5590dbe13e | 268 | |
POTLESS_2 | 72:6d5590dbe13e | 269 | Servo_Poumon.Sleep(); |
POTLESS_2 | 72:6d5590dbe13e | 270 | Servo_Fuite.Sleep(); |
POTLESS_2 | 72:6d5590dbe13e | 271 | } |
POTLESS_2 | 72:6d5590dbe13e | 272 | |
POTLESS_2 | 79:d22473a0e20d | 273 | void Sleep_IHM(int commande) |
POTLESS_2 | 72:6d5590dbe13e | 274 | { |
POTLESS_2 | 72:6d5590dbe13e | 275 | //Mise en veille de l'IHM |
POTLESS_2 | 80:545af6e94aa5 | 276 | IHM("<0/0/0 0-0-0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", commande); |
POTLESS_2 | 76:9dc83d5cf075 | 277 | |
POTLESS_2 | 72:6d5590dbe13e | 278 | wait(0.5); |
POTLESS_2 | 76:9dc83d5cf075 | 279 | |
POTLESS_2 | 75:eec3e587c8b8 | 280 | HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4|GPIO_PIN_5); |
POTLESS_2 | 76:9dc83d5cf075 | 281 | |
POTLESS_2 | 72:6d5590dbe13e | 282 | // mise à zero UART IHM pour éviter son redémarrage intempestif (le tx suffirait) |
POTLESS_2 | 75:eec3e587c8b8 | 283 | HAL_PWREx_EnablePullUpPullDownConfig(); |
POTLESS_2 | 72:6d5590dbe13e | 284 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_4); |
POTLESS_2 | 72:6d5590dbe13e | 285 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_C, PWR_GPIO_BIT_5); |
POTLESS_2 | 76:9dc83d5cf075 | 286 | |
POTLESS_2 | 72:6d5590dbe13e | 287 | } |
POTLESS_2 | 72:6d5590dbe13e | 288 | |
POTLESS_2 | 81:83567a0ce82c | 289 | void Alarm_IHM() |
POTLESS_2 | 81:83567a0ce82c | 290 | { |
POTLESS_2 | 81:83567a0ce82c | 291 | IHM("<0/0/0 0-0-0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", 6); |
POTLESS_2 | 81:83567a0ce82c | 292 | } |
POTLESS_2 | 81:83567a0ce82c | 293 | |
POTLESS_2 | 80:545af6e94aa5 | 294 | void Sleep_HIGH_WakeUp() |
POTLESS_2 | 72:6d5590dbe13e | 295 | { |
POTLESS_2 | 76:9dc83d5cf075 | 296 | |
POTLESS_2 | 72:6d5590dbe13e | 297 | E5V = 0; |
POTLESS_2 | 76:9dc83d5cf075 | 298 | |
POTLESS_2 | 59:fd64ca9dae27 | 299 | UTILS::UnMount_Flash(); |
POTLESS_2 | 76:9dc83d5cf075 | 300 | |
POTLESS_2 | 59:fd64ca9dae27 | 301 | DEBUG(" Mise en veille...\r\n"); |
POTLESS_2 | 76:9dc83d5cf075 | 302 | |
POTLESS_2 | 62:891379d80b1b | 303 | //Mise en veille |
potless | 60:e2922f9e309c | 304 | HAL_PWREx_EnablePullUpPullDownConfig() ; |
potless | 60:e2922f9e309c | 305 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); |
potless | 60:e2922f9e309c | 306 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 |
potless | 60:e2922f9e309c | 307 | // Clear wake up Flag |
potless | 60:e2922f9e309c | 308 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
potless | 60:e2922f9e309c | 309 | // Enable wakeup pin WKUP2 |
potless | 60:e2922f9e309c | 310 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // high est la valeur par défaut |
potless | 60:e2922f9e309c | 311 | // Set RTC back-up register RTC_BKP31R to indicate |
potless | 60:e2922f9e309c | 312 | //later on that system has entered shutdown mode |
potless | 60:e2922f9e309c | 313 | WRITE_REG( RTC->BKP31R, 0x1 ); |
POTLESS_2 | 76:9dc83d5cf075 | 314 | |
potless | 60:e2922f9e309c | 315 | //Enter shutdown mode |
POTLESS_2 | 71:23e7435e236f | 316 | E3V=0; |
POTLESS_2 | 72:6d5590dbe13e | 317 | //n’est pas exécuté à cause du E3V=0 précédent |
POTLESS_2 | 72:6d5590dbe13e | 318 | HAL_PWREx_EnterSHUTDOWNMode(); |
POTLESS_2 | 76:9dc83d5cf075 | 319 | |
POTLESS_2 | 56:61b0f4d6a890 | 320 | } |
POTLESS_2 | 58:694d4d00407c | 321 | |
POTLESS_2 | 72:6d5590dbe13e | 322 | void Sleep_LOW_WakeUp() |
POTLESS_2 | 71:23e7435e236f | 323 | { |
POTLESS_2 | 72:6d5590dbe13e | 324 | E5V = 0; |
POTLESS_2 | 76:9dc83d5cf075 | 325 | |
POTLESS_2 | 72:6d5590dbe13e | 326 | UTILS::UnMount_Flash(); |
POTLESS_2 | 76:9dc83d5cf075 | 327 | |
POTLESS_2 | 72:6d5590dbe13e | 328 | DEBUG(" Mise en veille...\r\n"); |
POTLESS_2 | 76:9dc83d5cf075 | 329 | |
POTLESS_2 | 72:6d5590dbe13e | 330 | UTILS::EffacePage(2, PAGE_FLAG_ADDR, 1); |
POTLESS_2 | 72:6d5590dbe13e | 331 | |
POTLESS_2 | 72:6d5590dbe13e | 332 | UTILS::Write(FLAG_ADDR, 0xBABEFACE); |
POTLESS_2 | 72:6d5590dbe13e | 333 | |
POTLESS_2 | 72:6d5590dbe13e | 334 | //Mise en veille |
POTLESS_2 | 75:eec3e587c8b8 | 335 | HAL_PWREx_EnablePullUpPullDownConfig(); |
POTLESS_2 | 72:6d5590dbe13e | 336 | HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A, PWR_GPIO_BIT_0); |
POTLESS_2 | 72:6d5590dbe13e | 337 | HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // pour PA_0 |
POTLESS_2 | 72:6d5590dbe13e | 338 | // Clear wake up Flag |
POTLESS_2 | 72:6d5590dbe13e | 339 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1); |
POTLESS_2 | 72:6d5590dbe13e | 340 | // Enable wakeup pin WKUP2 |
POTLESS_2 | 72:6d5590dbe13e | 341 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); // high est la valeur par défaut |
POTLESS_2 | 72:6d5590dbe13e | 342 | // Set RTC back-up register RTC_BKP31R to indicate |
POTLESS_2 | 72:6d5590dbe13e | 343 | //later on that system has entered shutdown mode |
POTLESS_2 | 72:6d5590dbe13e | 344 | WRITE_REG( RTC->BKP31R, 0x1 ); |
POTLESS_2 | 76:9dc83d5cf075 | 345 | |
POTLESS_2 | 72:6d5590dbe13e | 346 | //Enter shutdown mode |
POTLESS_2 | 80:545af6e94aa5 | 347 | E3V=0; |
POTLESS_2 | 72:6d5590dbe13e | 348 | //Enter shutdown mode |
POTLESS_2 | 72:6d5590dbe13e | 349 | HAL_PWREx_EnterSHUTDOWNMode(); |
POTLESS_2 | 72:6d5590dbe13e | 350 | } |
POTLESS_2 | 76:9dc83d5cf075 | 351 | |
POTLESS_2 | 76:9dc83d5cf075 | 352 | void ALIM_is_unplugged() |
POTLESS_2 | 72:6d5590dbe13e | 353 | { |
POTLESS_2 | 72:6d5590dbe13e | 354 | ALIM_UNPLUGGED = true; |
POTLESS_2 | 76:9dc83d5cf075 | 355 | } |
POTLESS_2 | 72:6d5590dbe13e | 356 | |
POTLESS_2 | 72:6d5590dbe13e | 357 | void ALIM_unplugged() |
POTLESS_2 | 52:4e36a88711d6 | 358 | { |
POTLESS_2 | 72:6d5590dbe13e | 359 | DEBUG(" L'alimentation a été débranchée.\n"); |
POTLESS_2 | 76:9dc83d5cf075 | 360 | |
POTLESS_2 | 71:23e7435e236f | 361 | buzzer.beep(1000,0.1); |
POTLESS_2 | 76:9dc83d5cf075 | 362 | |
POTLESS_2 | 79:d22473a0e20d | 363 | Sleep_IHM(2); |
POTLESS_2 | 76:9dc83d5cf075 | 364 | |
POTLESS_2 | 72:6d5590dbe13e | 365 | Mode_SECU(); |
POTLESS_2 | 76:9dc83d5cf075 | 366 | |
POTLESS_2 | 80:545af6e94aa5 | 367 | Sleep_HIGH_WakeUp(); |
POTLESS_2 | 76:9dc83d5cf075 | 368 | |
POTLESS_2 | 72:6d5590dbe13e | 369 | } |
POTLESS_2 | 72:6d5590dbe13e | 370 | |
POTLESS_2 | 72:6d5590dbe13e | 371 | //Sequence d'arrêt demandé par commande "sleep" |
POTLESS_2 | 72:6d5590dbe13e | 372 | void Stop_Sequence() |
POTLESS_2 | 72:6d5590dbe13e | 373 | { |
POTLESS_2 | 72:6d5590dbe13e | 374 | OUTPUT(" Mise en veille de l'appareil.\r\n"); |
POTLESS_2 | 80:545af6e94aa5 | 375 | |
POTLESS_2 | 80:545af6e94aa5 | 376 | buzzer.beep(1000,0.1); |
POTLESS_2 | 76:9dc83d5cf075 | 377 | |
POTLESS_2 | 79:d22473a0e20d | 378 | Sleep_IHM(1); |
POTLESS_2 | 76:9dc83d5cf075 | 379 | |
POTLESS_2 | 72:6d5590dbe13e | 380 | Mode_SECU(); |
POTLESS_2 | 72:6d5590dbe13e | 381 | |
POTLESS_2 | 72:6d5590dbe13e | 382 | Sleep_LOW_WakeUp(); |
POTLESS_2 | 52:4e36a88711d6 | 383 | } |
POTLESS_2 | 47:89a088bc8866 | 384 | |
POTLESS_2 | 29:5b822d18bce6 | 385 | void Affichage() |
POTLESS_2 | 53:84571a5e2cda | 386 | { |
POTLESS_2 | 42:3591ec9903b4 | 387 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 388 | serialMonit.printf(" CO2 = %d ppm\r\n" , co2); |
POTLESS_2 | 29:5b822d18bce6 | 389 | serialMonit.printf(" PPO2 = %d mb\r\n", ppO2); |
POTLESS_2 | 31:231a96d1d1c8 | 390 | serialMonit.printf(" OTU = %d \r\n", (int)OTU); |
POTLESS_2 | 29:5b822d18bce6 | 391 | serialMonit.printf(" Pression = %f msw\r\n", pression); |
POTLESS_2 | 29:5b822d18bce6 | 392 | serialMonit.printf(" Temp MS5837 = %f C\r\n", Temp1); |
POTLESS_2 | 29:5b822d18bce6 | 393 | serialMonit.printf(" Temp HTU21D = %f C\n\r", Temp2); |
POTLESS_2 | 29:5b822d18bce6 | 394 | serialMonit.printf(" Humidity = %d %%\n\r", Humid); |
POTLESS_2 | 42:3591ec9903b4 | 395 | //serialMonit.printf("\n\r"); |
POTLESS_2 | 29:5b822d18bce6 | 396 | serialMonit.printf(" Cell O2 n 1 = %d\r\n" , CellO2_1); |
POTLESS_2 | 29:5b822d18bce6 | 397 | serialMonit.printf(" Cell O2 n 2 = %d\r\n" , CellO2_2); |
POTLESS_2 | 42:3591ec9903b4 | 398 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 399 | serialMonit.printf(" Volet Poumon = %f\r\n" , volet_poumon_Position); |
POTLESS_2 | 29:5b822d18bce6 | 400 | serialMonit.printf(" Volet Fuite = %f\r\n" , volet_fuite_Position); |
POTLESS_2 | 42:3591ec9903b4 | 401 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 402 | serialMonit.printf(" Temps d execution de la boucle = %f seconde(s)\r\n", (RATE + RATE_TRUE / 1000)); |
POTLESS_2 | 42:3591ec9903b4 | 403 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 404 | if (FLAG_REC) serialMonit.printf(" Chaine enregistrée = %s\r\n", to_store); |
POTLESS_2 | 30:7a16a66d76f3 | 405 | else serialMonit.printf(" Pas d'enregistrement en cours."); |
POTLESS_2 | 42:3591ec9903b4 | 406 | //serialMonit.printf("\r\n"); |
POTLESS_2 | 42:3591ec9903b4 | 407 | serialMonit.printf(" V_USB = %f\r\n", Vusb); |
POTLESS_2 | 42:3591ec9903b4 | 408 | //serialMonit.printf("\r\n\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 409 | fflush(stdout); |
POTLESS_2 | 29:5b822d18bce6 | 410 | } |
POTLESS_2 | 29:5b822d18bce6 | 411 | |
POTLESS_2 | 76:9dc83d5cf075 | 412 | void Traceur_Arduino() |
POTLESS_2 | 76:9dc83d5cf075 | 413 | { |
POTLESS_2 | 76:9dc83d5cf075 | 414 | /* |
POTLESS_2 | 76:9dc83d5cf075 | 415 | //Important pour PID |
POTLESS_2 | 76:9dc83d5cf075 | 416 | TRACEUR("%d, ", ppO2); |
POTLESS_2 | 76:9dc83d5cf075 | 417 | TRACEUR("%d, ", consigne); |
POTLESS_2 | 76:9dc83d5cf075 | 418 | |
POTLESS_2 | 76:9dc83d5cf075 | 419 | //TODO à commenter je pense... |
POTLESS_2 | 76:9dc83d5cf075 | 420 | TRACEUR("%d, " , co2); |
POTLESS_2 | 76:9dc83d5cf075 | 421 | TRACEUR("%d, ", (int)OTU); |
POTLESS_2 | 76:9dc83d5cf075 | 422 | TRACEUR("%f, ", pression); |
POTLESS_2 | 76:9dc83d5cf075 | 423 | TRACEUR("%f, ", Temp1); |
POTLESS_2 | 76:9dc83d5cf075 | 424 | TRACEUR("%f, ", Temp2); |
POTLESS_2 | 76:9dc83d5cf075 | 425 | TRACEUR("%d, ", Humid); |
POTLESS_2 | 76:9dc83d5cf075 | 426 | TRACEUR("%d, " , CellO2_1); |
POTLESS_2 | 76:9dc83d5cf075 | 427 | TRACEUR("%d, " , CellO2_2); |
POTLESS_2 | 76:9dc83d5cf075 | 428 | TRACEUR("%f, " , volet_poumon_Position); |
POTLESS_2 | 76:9dc83d5cf075 | 429 | TRACEUR("%f, " , volet_fuite_Position); |
POTLESS_2 | 76:9dc83d5cf075 | 430 | |
POTLESS_2 | 76:9dc83d5cf075 | 431 | |
POTLESS_2 | 76:9dc83d5cf075 | 432 | //Toujours finir par \r\n |
POTLESS_2 | 76:9dc83d5cf075 | 433 | TRACEUR("\r\n"); |
POTLESS_2 | 76:9dc83d5cf075 | 434 | */ |
POTLESS_2 | 69:9afe54d53bb0 | 435 | //Important pour PID |
POTLESS_2 | 69:9afe54d53bb0 | 436 | TRACEUR_DEBUG("%d, ", ppO2); |
POTLESS_2 | 69:9afe54d53bb0 | 437 | TRACEUR_DEBUG("%d, ", consigne); |
potless | 73:2bbea82bf1e5 | 438 | TRACEUR_DEBUG("%f, " , volet_poumon_Position); |
POTLESS_2 | 76:9dc83d5cf075 | 439 | |
POTLESS_2 | 69:9afe54d53bb0 | 440 | /* |
POTLESS_2 | 69:9afe54d53bb0 | 441 | //TODO à commenter je pense... |
POTLESS_2 | 69:9afe54d53bb0 | 442 | TRACEUR_DEBUG("%d, " , co2); |
POTLESS_2 | 69:9afe54d53bb0 | 443 | TRACEUR_DEBUG("%d, ", (int)OTU); |
POTLESS_2 | 69:9afe54d53bb0 | 444 | TRACEUR_DEBUG("%f, ", pression); |
POTLESS_2 | 69:9afe54d53bb0 | 445 | TRACEUR_DEBUG("%f, ", Temp1); |
POTLESS_2 | 69:9afe54d53bb0 | 446 | TRACEUR_DEBUG("%f, ", Temp2); |
POTLESS_2 | 69:9afe54d53bb0 | 447 | TRACEUR_DEBUG("%d, ", Humid); |
POTLESS_2 | 69:9afe54d53bb0 | 448 | TRACEUR_DEBUG("%d, " , CellO2_1); |
POTLESS_2 | 69:9afe54d53bb0 | 449 | TRACEUR_DEBUG("%d, " , CellO2_2); |
POTLESS_2 | 69:9afe54d53bb0 | 450 | TRACEUR_DEBUG("%f, " , volet_poumon_Position); |
POTLESS_2 | 69:9afe54d53bb0 | 451 | TRACEUR_DEBUG("%f, " , volet_fuite_Position); |
POTLESS_2 | 68:7f4ab9c03b32 | 452 | */ |
POTLESS_2 | 76:9dc83d5cf075 | 453 | |
POTLESS_2 | 68:7f4ab9c03b32 | 454 | //Toujours finir par \r\n |
POTLESS_2 | 76:9dc83d5cf075 | 455 | TRACEUR_DEBUG("\r\n"); |
POTLESS_2 | 19:cac3761a5d0b | 456 | } |
POTLESS_2 | 19:cac3761a5d0b | 457 | |
POTLESS_2 | 18:bfd78c05b589 | 458 | |
POTLESS_2 | 31:231a96d1d1c8 | 459 | //Fonction test de valeur d'entrée digitale |
POTLESS_2 | 29:5b822d18bce6 | 460 | int Power_Test(DigitalIn& pin) |
POTLESS_2 | 20:5f79fb4565a7 | 461 | { |
POTLESS_2 | 29:5b822d18bce6 | 462 | pin.mode(PullDown); |
POTLESS_2 | 34:26f6e3dbefb9 | 463 | |
POTLESS_2 | 34:26f6e3dbefb9 | 464 | if(!pin) { |
POTLESS_2 | 68:7f4ab9c03b32 | 465 | //Stop_Sequence(); |
POTLESS_2 | 34:26f6e3dbefb9 | 466 | return 0; |
POTLESS_2 | 34:26f6e3dbefb9 | 467 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 468 | return 1; |
POTLESS_2 | 34:26f6e3dbefb9 | 469 | } |
POTLESS_2 | 20:5f79fb4565a7 | 470 | } |
POTLESS_2 | 20:5f79fb4565a7 | 471 | |
POTLESS_2 | 31:231a96d1d1c8 | 472 | //Fonction test de valeur d'entrée analogique |
POTLESS_2 | 31:231a96d1d1c8 | 473 | float Power_Test(AnalogIn& pin) |
POTLESS_2 | 31:231a96d1d1c8 | 474 | { |
POTLESS_2 | 31:231a96d1d1c8 | 475 | float Val = pin.read(); |
POTLESS_2 | 31:231a96d1d1c8 | 476 | return Val; |
POTLESS_2 | 31:231a96d1d1c8 | 477 | } |
POTLESS_2 | 31:231a96d1d1c8 | 478 | |
POTLESS_2 | 18:bfd78c05b589 | 479 | //Contrôle du status de l'appareil / des constantes |
POTLESS_2 | 18:bfd78c05b589 | 480 | bool Check() |
POTLESS_2 | 18:bfd78c05b589 | 481 | { |
POTLESS_2 | 18:bfd78c05b589 | 482 | if (ppO2 > 100) |
POTLESS_2 | 19:cac3761a5d0b | 483 | return true;//Situation OK |
POTLESS_2 | 18:bfd78c05b589 | 484 | else |
POTLESS_2 | 19:cac3761a5d0b | 485 | return false;//Situation dégradée |
POTLESS_2 | 18:bfd78c05b589 | 486 | } |
POTLESS_2 | 18:bfd78c05b589 | 487 | |
POTLESS_2 | 18:bfd78c05b589 | 488 | //Calcul des OTU |
POTLESS_2 | 58:694d4d00407c | 489 | void Calcul_OTU() |
POTLESS_2 | 18:bfd78c05b589 | 490 | { |
POTLESS_2 | 18:bfd78c05b589 | 491 | /* |
POTLESS_2 | 18:bfd78c05b589 | 492 | La formule suivante permet de calculer la quantité d' OTU accumulée |
POTLESS_2 | 18:bfd78c05b589 | 493 | OTU = T * (2* PpO2 -1)0,83 |
POTLESS_2 | 18:bfd78c05b589 | 494 | avec : |
POTLESS_2 | 18:bfd78c05b589 | 495 | T = temps de plongée en minutes |
POTLESS_2 | 18:bfd78c05b589 | 496 | PpO2 = pression partielle d’ oxygène en bars |
POTLESS_2 | 18:bfd78c05b589 | 497 | */ |
POTLESS_2 | 18:bfd78c05b589 | 498 | |
POTLESS_2 | 19:cac3761a5d0b | 499 | if (ppO2 > 500) { |
POTLESS_2 | 18:bfd78c05b589 | 500 | float val = (2 * (float)ppO2/1000 - 1);//je divise par 1000 car la PP est en mb... |
POTLESS_2 | 58:694d4d00407c | 501 | OTU += pow(val, EXP_OTU);//T = 1 car le ticker est executé toutes les 60 secondes, 1 minute.... |
POTLESS_2 | 19:cac3761a5d0b | 502 | } |
POTLESS_2 | 18:bfd78c05b589 | 503 | } |
POTLESS_2 | 10:aca745a66d51 | 504 | |
POTLESS_2 | 17:bef8abc445f2 | 505 | //Thread d'intérogation des capteurs, positions servo |
POTLESS_2 | 34:26f6e3dbefb9 | 506 | void SENSORS_thread() |
POTLESS_2 | 6:ebed9093d661 | 507 | { |
POTLESS_2 | 7:ad15c386e960 | 508 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 509 | //DEEP_DEBUG(" SENSORS_thread\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 510 | |
POTLESS_2 | 7:ad15c386e960 | 511 | //CO2 sur Cozir |
POTLESS_2 | 7:ad15c386e960 | 512 | co2 = sensors.requestCO2(); |
POTLESS_2 | 7:ad15c386e960 | 513 | //P / T sur MS5837 |
POTLESS_2 | 7:ad15c386e960 | 514 | pression = sensors.requestPress(); |
POTLESS_2 | 9:04bfdfc029cb | 515 | Temp1 = sensors.requestTemp(); |
POTLESS_2 | 7:ad15c386e960 | 516 | //PPO2 sur ADS1015 |
POTLESS_2 | 33:f5d4bae05f16 | 517 | if (FLAG_O2) ppO2 = sensors.requestPpO2(); |
POTLESS_2 | 7:ad15c386e960 | 518 | //Cell O2 en mV |
POTLESS_2 | 33:f5d4bae05f16 | 519 | if (FLAG_O2) CellO2_1 = sensors.requestCellO2_1(); |
POTLESS_2 | 33:f5d4bae05f16 | 520 | if (FLAG_O2) CellO2_2 = sensors.requestCellO2_2(); |
POTLESS_2 | 9:04bfdfc029cb | 521 | |
POTLESS_2 | 8:a750d531b381 | 522 | //HTU21D |
POTLESS_2 | 9:04bfdfc029cb | 523 | Temp2 = temphumid.sample_ctemp(); |
POTLESS_2 | 9:04bfdfc029cb | 524 | Humid = temphumid.sample_humid(); |
POTLESS_2 | 9:04bfdfc029cb | 525 | |
POTLESS_2 | 10:aca745a66d51 | 526 | //Retour position des servos |
POTLESS_2 | 17:bef8abc445f2 | 527 | volet_poumon_Position = Servo_Poumon.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 528 | volet_fuite_Position = Servo_Fuite.Get_Position(); |
POTLESS_2 | 43:5ae8baf28e32 | 529 | |
POTLESS_2 | 43:5ae8baf28e32 | 530 | //Calcul des OTU |
POTLESS_2 | 58:694d4d00407c | 531 | //Calcul_OTU(); |
potless | 65:c7d09a1fbef3 | 532 | wait(Ref_Time); |
POTLESS_2 | 19:cac3761a5d0b | 533 | } |
POTLESS_2 | 19:cac3761a5d0b | 534 | } |
POTLESS_2 | 12:7f3aadd79f89 | 535 | |
POTLESS_2 | 57:a0827fa46b03 | 536 | void GO_TO_thread_POUMON() |
POTLESS_2 | 19:cac3761a5d0b | 537 | { |
POTLESS_2 | 19:cac3761a5d0b | 538 | while (true) { |
POTLESS_2 | 57:a0827fa46b03 | 539 | //DEEP_DEBUG(" GO_TO_Thread_POUMON\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 540 | |
POTLESS_2 | 83:855eb58c017d | 541 | Servo_Poumon.Go_To_Prop(&serialMonit, Consigne_poumon); |
POTLESS_2 | 62:891379d80b1b | 542 | //Servo_Poumon.Go_To_PID(Consigne_poumon, Volet_DeadBand);//Nécessite de déclarer un dernier terme true dans l'init du moteur |
POTLESS_2 | 63:69f6d600807e | 543 | //Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 68:7f4ab9c03b32 | 544 | |
POTLESS_2 | 57:a0827fa46b03 | 545 | } |
POTLESS_2 | 57:a0827fa46b03 | 546 | } |
POTLESS_2 | 57:a0827fa46b03 | 547 | |
POTLESS_2 | 57:a0827fa46b03 | 548 | void GO_TO_thread_FUITE() |
POTLESS_2 | 57:a0827fa46b03 | 549 | { |
POTLESS_2 | 57:a0827fa46b03 | 550 | while (true) { |
POTLESS_2 | 57:a0827fa46b03 | 551 | //DEEP_DEBUG(" GO_TO_Thread_FUITE\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 552 | |
POTLESS_2 | 83:855eb58c017d | 553 | Servo_Fuite.Go_To_Prop(&serialMonit, Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 554 | //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand); |
POTLESS_2 | 63:69f6d600807e | 555 | //Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand); |
POTLESS_2 | 68:7f4ab9c03b32 | 556 | |
POTLESS_2 | 15:efd3b3bf3f37 | 557 | } |
potless | 2:4a8bf1d53439 | 558 | } |
POTLESS_2 | 4:d84250f67dec | 559 | |
POTLESS_2 | 20:5f79fb4565a7 | 560 | void SECU_thread() |
POTLESS_2 | 20:5f79fb4565a7 | 561 | { |
POTLESS_2 | 34:26f6e3dbefb9 | 562 | while (true) { |
POTLESS_2 | 58:694d4d00407c | 563 | //Mettre toutes les vérifs de sécu.... |
POTLESS_2 | 72:6d5590dbe13e | 564 | if (ALIM_UNPLUGGED) ALIM_unplugged(); |
POTLESS_2 | 20:5f79fb4565a7 | 565 | } |
POTLESS_2 | 20:5f79fb4565a7 | 566 | } |
POTLESS_2 | 20:5f79fb4565a7 | 567 | |
POTLESS_2 | 76:9dc83d5cf075 | 568 | void PID_thread() |
POTLESS_2 | 76:9dc83d5cf075 | 569 | { |
POTLESS_2 | 76:9dc83d5cf075 | 570 | while (true) { |
POTLESS_2 | 76:9dc83d5cf075 | 571 | if (FLAG_PID == 1 && EN_MODE_SECU == false) { |
POTLESS_2 | 76:9dc83d5cf075 | 572 | control_Servo.setProcessValue(ppO2); |
POTLESS_2 | 76:9dc83d5cf075 | 573 | //Nouvelle sortie servo poumon si on est pas en mode SECU |
POTLESS_2 | 76:9dc83d5cf075 | 574 | Consigne_poumon = 90 - control_Servo.compute(); |
POTLESS_2 | 76:9dc83d5cf075 | 575 | // mode volets asservis (simule un seul moteur) |
POTLESS_2 | 76:9dc83d5cf075 | 576 | Consigne_fuite = 90 - Consigne_poumon; |
POTLESS_2 | 76:9dc83d5cf075 | 577 | wait(RATE_PID); |
POTLESS_2 | 76:9dc83d5cf075 | 578 | } |
POTLESS_2 | 76:9dc83d5cf075 | 579 | } |
POTLESS_2 | 76:9dc83d5cf075 | 580 | } |
POTLESS_2 | 76:9dc83d5cf075 | 581 | |
POTLESS_2 | 57:a0827fa46b03 | 582 | //Callback de l'intérruption des envois de commandes depuis le terminal / WINDEV |
POTLESS_2 | 6:ebed9093d661 | 583 | void callbackParam() |
POTLESS_2 | 34:26f6e3dbefb9 | 584 | { |
POTLESS_2 | 40:32d89e04ead1 | 585 | |
POTLESS_2 | 34:26f6e3dbefb9 | 586 | while(serialMonit.readable()) { |
POTLESS_2 | 40:32d89e04ead1 | 587 | if ((indexParam == sizeParam) || newParamFlag == true) { //éviter la saturation du buffer |
POTLESS_2 | 29:5b822d18bce6 | 588 | char char_flush = serialMonit.getc(); |
POTLESS_2 | 40:32d89e04ead1 | 589 | } else { |
POTLESS_2 | 29:5b822d18bce6 | 590 | param [indexParam ++] = serialMonit.getc();//chargement du buffer dans le message |
POTLESS_2 | 40:32d89e04ead1 | 591 | if ((indexParam == sizeParam) || (param[indexParam - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 40:32d89e04ead1 | 592 | param[indexParam] = 0; |
POTLESS_2 | 40:32d89e04ead1 | 593 | newParamFlag = true; |
POTLESS_2 | 40:32d89e04ead1 | 594 | } |
POTLESS_2 | 56:61b0f4d6a890 | 595 | } |
POTLESS_2 | 56:61b0f4d6a890 | 596 | } |
POTLESS_2 | 56:61b0f4d6a890 | 597 | } |
POTLESS_2 | 56:61b0f4d6a890 | 598 | |
POTLESS_2 | 56:61b0f4d6a890 | 599 | //Callback de l'intérruption des envois de commandes depuis l'IHM |
POTLESS_2 | 56:61b0f4d6a890 | 600 | void callbackIHM() |
POTLESS_2 | 56:61b0f4d6a890 | 601 | { |
POTLESS_2 | 56:61b0f4d6a890 | 602 | |
POTLESS_2 | 56:61b0f4d6a890 | 603 | while(display.readable()) { |
POTLESS_2 | 56:61b0f4d6a890 | 604 | if ((indexIHM == sizeIHM) || newIHMFlag == true) { //éviter la saturation du buffer |
POTLESS_2 | 58:694d4d00407c | 605 | NVIC_DisableIRQ(USART3_IRQn); |
POTLESS_2 | 56:61b0f4d6a890 | 606 | char char_flush = display.getc(); |
POTLESS_2 | 56:61b0f4d6a890 | 607 | NVIC_EnableIRQ(USART3_IRQn); |
POTLESS_2 | 56:61b0f4d6a890 | 608 | } else { |
POTLESS_2 | 56:61b0f4d6a890 | 609 | NVIC_DisableIRQ(USART3_IRQn); |
POTLESS_2 | 56:61b0f4d6a890 | 610 | IHM [indexIHM ++] = display.getc();//chargement du buffer dans le message |
POTLESS_2 | 56:61b0f4d6a890 | 611 | if ((indexIHM == sizeIHM) || (IHM[indexIHM - 1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... |
POTLESS_2 | 56:61b0f4d6a890 | 612 | IHM[indexIHM] = 0; |
POTLESS_2 | 56:61b0f4d6a890 | 613 | newIHMFlag = true; |
POTLESS_2 | 56:61b0f4d6a890 | 614 | } |
POTLESS_2 | 56:61b0f4d6a890 | 615 | NVIC_EnableIRQ(USART3_IRQn); |
POTLESS_2 | 34:26f6e3dbefb9 | 616 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 617 | } |
POTLESS_2 | 6:ebed9093d661 | 618 | } |
POTLESS_2 | 4:d84250f67dec | 619 | |
POTLESS_2 | 9:04bfdfc029cb | 620 | void Decoding_Message(char message []) |
POTLESS_2 | 9:04bfdfc029cb | 621 | { |
POTLESS_2 | 9:04bfdfc029cb | 622 | |
POTLESS_2 | 42:3591ec9903b4 | 623 | char com[20] = ""; |
POTLESS_2 | 42:3591ec9903b4 | 624 | char numb[30] = ""; |
POTLESS_2 | 36:1f5e2247b073 | 625 | |
POTLESS_2 | 34:26f6e3dbefb9 | 626 | sscanf(message,"%s %s",&com , &numb); |
POTLESS_2 | 36:1f5e2247b073 | 627 | |
POTLESS_2 | 56:61b0f4d6a890 | 628 | DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 36:1f5e2247b073 | 629 | |
POTLESS_2 | 43:5ae8baf28e32 | 630 | OUTPUT("?\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 631 | |
POTLESS_2 | 30:7a16a66d76f3 | 632 | if (0 == strcmp(com, "secu")) { |
POTLESS_2 | 19:cac3761a5d0b | 633 | Mode_SECU(); |
POTLESS_2 | 68:7f4ab9c03b32 | 634 | } else if (0 == strcmp(com, "save_pos")) { |
POTLESS_2 | 72:6d5590dbe13e | 635 | Save_Pos(); |
POTLESS_2 | 68:7f4ab9c03b32 | 636 | } else if (0 == strcmp(com, "trace")) { |
POTLESS_2 | 76:9dc83d5cf075 | 637 | if (FLAG_TRACE) { |
POTLESS_2 | 68:7f4ab9c03b32 | 638 | FLAG_TRACE = false; |
POTLESS_2 | 68:7f4ab9c03b32 | 639 | OUTPUT(" Arrêt du tracé Arduino.\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 640 | } else { |
POTLESS_2 | 68:7f4ab9c03b32 | 641 | FLAG_TRACE = true; |
POTLESS_2 | 69:9afe54d53bb0 | 642 | OUTPUT(" Démarrage du tracé Arduino.\r\n"); |
POTLESS_2 | 76:9dc83d5cf075 | 643 | } |
POTLESS_2 | 74:f4704f312116 | 644 | } else if (0 == strcmp(com, "ping")) { |
POTLESS_2 | 71:23e7435e236f | 645 | E3V = 0; |
POTLESS_2 | 80:545af6e94aa5 | 646 | } else if (0 == strcmp(com, "res_ihm")) { |
POTLESS_2 | 80:545af6e94aa5 | 647 | IHM("<0/0/0 0-0-0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", 4); |
POTLESS_2 | 80:545af6e94aa5 | 648 | } else if (0 == strcmp(com, "page_ihm")) { |
POTLESS_2 | 81:83567a0ce82c | 649 | IHM("<0/0/0 0-0-0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", 5); |
POTLESS_2 | 81:83567a0ce82c | 650 | } else if (0 == strcmp(com, "alarm")) { |
POTLESS_2 | 81:83567a0ce82c | 651 | Commande_IHM = 6; |
POTLESS_2 | 81:83567a0ce82c | 652 | } else if (0 == strcmp(com, "alarm_fat")) { |
POTLESS_2 | 81:83567a0ce82c | 653 | Commande_IHM = 7; |
POTLESS_2 | 81:83567a0ce82c | 654 | } else if (0 == strcmp(com, "ack_alarm")) { |
POTLESS_2 | 81:83567a0ce82c | 655 | Commande_IHM = 8; |
POTLESS_2 | 74:f4704f312116 | 656 | } else if (0 == strcmp(com, "arnsrs_id")) { |
POTLESS_2 | 58:694d4d00407c | 657 | OUTPUT(" Changement de l'ID de l'appareil pour le N°: %s\r\n", numb); |
POTLESS_2 | 58:694d4d00407c | 658 | //UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID"); |
POTLESS_2 | 71:23e7435e236f | 659 | UTILS::EffacePage(2, PAGE_ID_ADDR, 1); |
POTLESS_2 | 58:694d4d00407c | 660 | UTILS::Write(ID_ARNSRS_ADDR, (uint64_t) atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 661 | } else if (0 == strcmp(com, "monit")) { |
POTLESS_2 | 43:5ae8baf28e32 | 662 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 663 | FLAG_WINDEV = true; |
POTLESS_2 | 43:5ae8baf28e32 | 664 | } else if (0 == strcmp(com, "debug")) { |
POTLESS_2 | 43:5ae8baf28e32 | 665 | FLAG_AFF = false; |
POTLESS_2 | 43:5ae8baf28e32 | 666 | FLAG_WINDEV = false; |
POTLESS_2 | 74:f4704f312116 | 667 | } else if (0 == strcmp(com, "head_id")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 668 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 43:5ae8baf28e32 | 669 | OUTPUT("Changement de l'ID de la tête capteur pour le N°: %s\r\n", numb); |
POTLESS_2 | 34:26f6e3dbefb9 | 670 | UTILS::write_EEPROM(numb, HEAD_ID); |
POTLESS_2 | 74:f4704f312116 | 671 | } else if (0 == strcmp(com, "o2_1_id")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 672 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 673 | UTILS::write_EEPROM(numb, CELL_O2_1_ID); |
POTLESS_2 | 74:f4704f312116 | 674 | } else if (0 == strcmp(com, "o2_2_id")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 675 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 676 | UTILS::write_EEPROM(numb, CELL_O2_2_ID); |
POTLESS_2 | 74:f4704f312116 | 677 | } else if (0 == strcmp(com, "co2_id")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 678 | //On l'enregistre dans l'eeprom |
POTLESS_2 | 34:26f6e3dbefb9 | 679 | UTILS::write_EEPROM(numb, CO2_ID); |
POTLESS_2 | 74:f4704f312116 | 680 | } else if (0 == strcmp(com, "calib_o2")) { |
POTLESS_2 | 33:f5d4bae05f16 | 681 | FLAG_O2 = false; |
POTLESS_2 | 33:f5d4bae05f16 | 682 | wait_ms(100); |
POTLESS_2 | 42:3591ec9903b4 | 683 | float Val = sensors.Calibrate_O2(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 684 | OUTPUT(" Calibration O2 dans l'air = %f\r\n", Val); |
POTLESS_2 | 33:f5d4bae05f16 | 685 | wait_ms(100); |
POTLESS_2 | 33:f5d4bae05f16 | 686 | FLAG_O2 = true; |
POTLESS_2 | 74:f4704f312116 | 687 | } else if (0 == strcmp(com, "calib_co2")) { |
POTLESS_2 | 43:5ae8baf28e32 | 688 | int Val = sensors.Calibrate_CO2(); |
POTLESS_2 | 43:5ae8baf28e32 | 689 | OUTPUT(" Calibration CO2 dans l'air = %d\r\n", Val); |
POTLESS_2 | 34:26f6e3dbefb9 | 690 | } else if (0 == strcmp(com, "flash_i")) { |
POTLESS_2 | 42:3591ec9903b4 | 691 | UTILS::Flash_Infos(&serialMonit); |
POTLESS_2 | 36:1f5e2247b073 | 692 | } else if (0 == strcmp(com, "flash_u")) { |
POTLESS_2 | 43:5ae8baf28e32 | 693 | OUTPUT(" Démontage de la Flash.\r\n"); |
POTLESS_2 | 36:1f5e2247b073 | 694 | FLAG_REC = false; |
POTLESS_2 | 36:1f5e2247b073 | 695 | UTILS::UnMount_Flash(); |
POTLESS_2 | 36:1f5e2247b073 | 696 | } else if (0 == strcmp(com, "flash_m")) { |
POTLESS_2 | 43:5ae8baf28e32 | 697 | OUTPUT(" Montage de la Flash.\r\n"); |
POTLESS_2 | 40:32d89e04ead1 | 698 | UTILS::Mount_Flash(); |
POTLESS_2 | 74:f4704f312116 | 699 | } else if (0 == strcmp(com, "check_f")) { |
POTLESS_2 | 58:694d4d00407c | 700 | OUTPUT(" ARNSRS ID = %d\r\n", (int) UTILS::Read(ID_ARNSRS_ADDR)); |
POTLESS_2 | 58:694d4d00407c | 701 | OUTPUT(" Dernière Position volet poumon enregistrée = %d\r\n", (int) UTILS::Read(VOLET_POUMON_ADDR)); |
POTLESS_2 | 58:694d4d00407c | 702 | OUTPUT(" Dernière Position volet fuite enregistrée = %d\r\n", (int) UTILS::Read(VOLET_FUITE_ADDR)); |
POTLESS_2 | 35:a209a192f431 | 703 | } else if (0 == strcmp(com, "check_E")) { |
POTLESS_2 | 42:3591ec9903b4 | 704 | sensors.Sensor_head_check(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 705 | } else if (0 == strcmp(com, "rec")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 706 | if (FLAG_REC) { |
POTLESS_2 | 34:26f6e3dbefb9 | 707 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 708 | OUTPUT(" Arrêt du Data Logging.\r\n"); |
POTLESS_2 | 34:26f6e3dbefb9 | 709 | } else { |
POTLESS_2 | 34:26f6e3dbefb9 | 710 | FLAG_REC = true; |
POTLESS_2 | 43:5ae8baf28e32 | 711 | OUTPUT(" Démarrage Data Logging dans %s\r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 712 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 713 | } else if (0 == strcmp(com, "help")) { |
POTLESS_2 | 29:5b822d18bce6 | 714 | FLAG_AFF = false; |
POTLESS_2 | 42:3591ec9903b4 | 715 | UTILS::Help(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 716 | } else if (0 == strcmp(com, "start")) { |
POTLESS_2 | 29:5b822d18bce6 | 717 | FLAG_AFF = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 718 | } else if (0 == strcmp(com, "stop")) { |
POTLESS_2 | 29:5b822d18bce6 | 719 | FLAG_AFF = false; |
POTLESS_2 | 40:32d89e04ead1 | 720 | //UTILS::Help(); |
POTLESS_2 | 36:1f5e2247b073 | 721 | } else if (0 == strcmp(com, "flash_c")) { |
POTLESS_2 | 29:5b822d18bce6 | 722 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 723 | UTILS::Clean_Flash(); |
POTLESS_2 | 42:3591ec9903b4 | 724 | } else if (0 == strcmp(com, "flash_f")) { |
POTLESS_2 | 34:26f6e3dbefb9 | 725 | FLAG_REC = false; |
POTLESS_2 | 43:5ae8baf28e32 | 726 | UTILS::Clean_Flash_All(); |
POTLESS_2 | 42:3591ec9903b4 | 727 | } else if (0 == strcmp(com, "dir")) { |
POTLESS_2 | 43:5ae8baf28e32 | 728 | FLAG_WINDEV = false; |
POTLESS_2 | 56:61b0f4d6a890 | 729 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 730 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 731 | wait(0.5); |
POTLESS_2 | 42:3591ec9903b4 | 732 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 42:3591ec9903b4 | 733 | } else if (0 == strcmp(com, "get")) { |
POTLESS_2 | 29:5b822d18bce6 | 734 | wait_ms(100); |
POTLESS_2 | 43:5ae8baf28e32 | 735 | char filename[20]; |
POTLESS_2 | 43:5ae8baf28e32 | 736 | UTILS::Read_Flash_File(&serialMonit, numb); |
POTLESS_2 | 43:5ae8baf28e32 | 737 | wait_ms(100); |
POTLESS_2 | 34:26f6e3dbefb9 | 738 | } else if (0 == strcmp(com, "del")) { |
POTLESS_2 | 29:5b822d18bce6 | 739 | FLAG_REC = false; |
POTLESS_2 | 29:5b822d18bce6 | 740 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 741 | UTILS::Delete_Flash_File(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 742 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 743 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 744 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 31:231a96d1d1c8 | 745 | FLAG_REC = true; |
POTLESS_2 | 34:26f6e3dbefb9 | 746 | } else if (0 == strcmp(com, "file_s")) { |
POTLESS_2 | 31:231a96d1d1c8 | 747 | char filename[20]; |
POTLESS_2 | 42:3591ec9903b4 | 748 | UTILS::Get_File_Size(&serialMonit, numb); |
POTLESS_2 | 74:f4704f312116 | 749 | } else if (0 == strcmp(com, "calib_pou")) { |
POTLESS_2 | 59:fd64ca9dae27 | 750 | volet_poumon_Position = 0; |
POTLESS_2 | 59:fd64ca9dae27 | 751 | Servo_Poumon.reset(); |
POTLESS_2 | 58:694d4d00407c | 752 | Consigne_poumon = HOME_SERVO_POUMON; |
POTLESS_2 | 43:5ae8baf28e32 | 753 | OUTPUT(" Volet poumon Calibré.\r\n"); |
POTLESS_2 | 74:f4704f312116 | 754 | } else if (0 == strcmp(com, "calib_fui")) { |
POTLESS_2 | 59:fd64ca9dae27 | 755 | volet_fuite_Position = 0; |
POTLESS_2 | 59:fd64ca9dae27 | 756 | Servo_Fuite.reset(); |
POTLESS_2 | 58:694d4d00407c | 757 | Consigne_fuite = HOME_SERVO_FUITE; |
POTLESS_2 | 43:5ae8baf28e32 | 758 | OUTPUT(" Volet fuite Calibré.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 759 | } else if (0 == strcmp(com, "sleep")) { |
POTLESS_2 | 19:cac3761a5d0b | 760 | Stop_Sequence(); |
POTLESS_2 | 29:5b822d18bce6 | 761 | } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s " |
POTLESS_2 | 34:26f6e3dbefb9 | 762 | set_time(atoi(numb)); |
POTLESS_2 | 43:5ae8baf28e32 | 763 | OUTPUT(" La RTC a été mise à l'heure.\r\n"); |
POTLESS_2 | 29:5b822d18bce6 | 764 | } else if (0 == strcmp(com, "c_pou")) { |
POTLESS_2 | 43:5ae8baf28e32 | 765 | Consigne_poumon = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 766 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 767 | } else if (0 == strcmp(com, "c_fui")) { |
POTLESS_2 | 43:5ae8baf28e32 | 768 | Consigne_fuite = atof(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 769 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 43:5ae8baf28e32 | 770 | } else if (0 == strcmp(com, "mp_pou")) { |
POTLESS_2 | 41:51ba69648f9d | 771 | Consigne_poumon += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 772 | DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); |
POTLESS_2 | 43:5ae8baf28e32 | 773 | } else if (0 == strcmp(com, "mp_fui")) { |
POTLESS_2 | 41:51ba69648f9d | 774 | Consigne_fuite += atof(numb); |
POTLESS_2 | 33:f5d4bae05f16 | 775 | DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); |
POTLESS_2 | 29:5b822d18bce6 | 776 | } else if (0 == strcmp(com, "reset")) { |
POTLESS_2 | 43:5ae8baf28e32 | 777 | FLAG_REC = false; |
POTLESS_2 | 71:23e7435e236f | 778 | //Mode_SECU(); |
POTLESS_2 | 36:1f5e2247b073 | 779 | UTILS::UnMount_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 780 | OUTPUT(" Reset de l'appareil.\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 781 | wait(1); |
POTLESS_2 | 10:aca745a66d51 | 782 | NVIC_SystemReset(); |
POTLESS_2 | 84:49f0acf09f67 | 783 | } else if (0 == strcmp(com, "pid_r")) { |
POTLESS_2 | 84:49f0acf09f67 | 784 | control_Servo.reset(); |
POTLESS_2 | 84:49f0acf09f67 | 785 | OUTPUT(" RESET PID\r\n"); |
POTLESS_2 | 74:f4704f312116 | 786 | } else if (0 == strcmp(com, "kc")) { |
POTLESS_2 | 43:5ae8baf28e32 | 787 | Kc = atof(numb); |
POTLESS_2 | 84:49f0acf09f67 | 788 | //control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 789 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 56:61b0f4d6a890 | 790 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f\r\n", Kc, Ti, Td); |
POTLESS_2 | 74:f4704f312116 | 791 | } else if (0 == strcmp(com, "ti")) { |
POTLESS_2 | 43:5ae8baf28e32 | 792 | Ti = atof(numb); |
POTLESS_2 | 84:49f0acf09f67 | 793 | //control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 794 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 56:61b0f4d6a890 | 795 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f\r\n", Kc, Ti, Td); |
POTLESS_2 | 74:f4704f312116 | 796 | } else if (0 == strcmp(com, "td")) { |
POTLESS_2 | 43:5ae8baf28e32 | 797 | Td = atof(numb); |
POTLESS_2 | 84:49f0acf09f67 | 798 | //control_Servo.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 799 | control_Servo.setTunings(Kc, Ti, Td); |
POTLESS_2 | 56:61b0f4d6a890 | 800 | OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f\r\n", Kc, Ti, Td); |
POTLESS_2 | 74:f4704f312116 | 801 | } else if (0 == strcmp(com, "cons")) { |
POTLESS_2 | 43:5ae8baf28e32 | 802 | consigne = atoi(numb); |
POTLESS_2 | 43:5ae8baf28e32 | 803 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 56:61b0f4d6a890 | 804 | OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d\r\n", consigne); |
POTLESS_2 | 76:9dc83d5cf075 | 805 | } else if (0 == strcmp(com, "rate")) { |
POTLESS_2 | 76:9dc83d5cf075 | 806 | RATE_PID = atof(numb); |
POTLESS_2 | 84:49f0acf09f67 | 807 | //control_Servo.reset(); |
POTLESS_2 | 76:9dc83d5cf075 | 808 | control_Servo.setInterval(RATE_PID); |
POTLESS_2 | 78:674882631acc | 809 | OUTPUT(" MAJ RATE PID --> Rate = %f\r\n", RATE_PID); |
POTLESS_2 | 84:49f0acf09f67 | 810 | } else if (0 == strcmp(com, "bornes")) { |
POTLESS_2 | 84:49f0acf09f67 | 811 | Borne = atof(numb); |
POTLESS_2 | 84:49f0acf09f67 | 812 | Min_Output = 0 + Borne; |
POTLESS_2 | 84:49f0acf09f67 | 813 | Max_Output = 90 - Borne; |
POTLESS_2 | 84:49f0acf09f67 | 814 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 84:49f0acf09f67 | 815 | OUTPUT(" MAJ LIMITE OUTPUT PID --> Min_Output = %f Max_Output = %f\r\n", Min_Output, Max_Output); |
potless | 49:a7432da60647 | 816 | } else if (0 == strcmp(com, "dfu")) { |
POTLESS_2 | 53:84571a5e2cda | 817 | OUTPUT(" Passage en DFU...\r\n"); |
POTLESS_2 | 58:694d4d00407c | 818 | FLAG_REC = false; |
POTLESS_2 | 58:694d4d00407c | 819 | Mode_SECU(); |
POTLESS_2 | 58:694d4d00407c | 820 | UTILS::UnMount_Flash(); |
POTLESS_2 | 71:23e7435e236f | 821 | UTILS::EffacePage(2, PAGE_FLAG_ADDR, 1); |
POTLESS_2 | 71:23e7435e236f | 822 | UTILS::Write(FLAG_ADDR, 0xDEADBEEF); |
POTLESS_2 | 58:694d4d00407c | 823 | wait(1); |
POTLESS_2 | 58:694d4d00407c | 824 | NVIC_SystemReset(); |
POTLESS_2 | 74:f4704f312116 | 825 | } else if (0 == strcmp(com, "pid")) { |
POTLESS_2 | 43:5ae8baf28e32 | 826 | if (FLAG_PID == 1) { |
POTLESS_2 | 56:61b0f4d6a890 | 827 | OUTPUT(" PID OFF\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 828 | FLAG_PID = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 829 | } else if (FLAG_PID == 0) { |
POTLESS_2 | 56:61b0f4d6a890 | 830 | OUTPUT(" PID ON\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 831 | FLAG_PID = 1; |
POTLESS_2 | 43:5ae8baf28e32 | 832 | } |
POTLESS_2 | 12:7f3aadd79f89 | 833 | } else { |
POTLESS_2 | 74:f4704f312116 | 834 | OUTPUT(" Commande COZIR, commande érronée....\r\n"); |
POTLESS_2 | 9:04bfdfc029cb | 835 | sensors.cozirSend(message); |
POTLESS_2 | 9:04bfdfc029cb | 836 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 837 | |
POTLESS_2 | 9:04bfdfc029cb | 838 | strcpy(param," "); |
POTLESS_2 | 9:04bfdfc029cb | 839 | indexParam = 0; |
POTLESS_2 | 9:04bfdfc029cb | 840 | newParamFlag = false; |
POTLESS_2 | 9:04bfdfc029cb | 841 | } |
POTLESS_2 | 9:04bfdfc029cb | 842 | |
POTLESS_2 | 56:61b0f4d6a890 | 843 | void Decoding_IHM(char message []) |
POTLESS_2 | 56:61b0f4d6a890 | 844 | { |
POTLESS_2 | 56:61b0f4d6a890 | 845 | |
POTLESS_2 | 56:61b0f4d6a890 | 846 | char com[20] = ""; |
POTLESS_2 | 56:61b0f4d6a890 | 847 | char numb[30] = ""; |
POTLESS_2 | 56:61b0f4d6a890 | 848 | |
POTLESS_2 | 56:61b0f4d6a890 | 849 | sscanf(message,"%s %s",&com , &numb); |
POTLESS_2 | 56:61b0f4d6a890 | 850 | |
POTLESS_2 | 56:61b0f4d6a890 | 851 | DEEP_DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); |
POTLESS_2 | 56:61b0f4d6a890 | 852 | |
POTLESS_2 | 56:61b0f4d6a890 | 853 | OUTPUT("?\r\n"); |
POTLESS_2 | 56:61b0f4d6a890 | 854 | |
POTLESS_2 | 68:7f4ab9c03b32 | 855 | if (0 == strcmp(com, "USB")) { |
POTLESS_2 | 68:7f4ab9c03b32 | 856 | OUTPUT(" Passage en Mode Transfert Flash To USB...\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 857 | FLAG_REC = false; |
POTLESS_2 | 81:83567a0ce82c | 858 | Mode_SECU(); |
POTLESS_2 | 68:7f4ab9c03b32 | 859 | UTILS::UnMount_Flash(); |
POTLESS_2 | 68:7f4ab9c03b32 | 860 | UTILS::FLASH_set_boot_bank(2); |
POTLESS_2 | 71:23e7435e236f | 861 | NVIC_SystemReset(); |
POTLESS_2 | 81:83567a0ce82c | 862 | } else if (0 == strcmp(com, "res_otu")) { |
POTLESS_2 | 81:83567a0ce82c | 863 | OTU = 0; |
POTLESS_2 | 81:83567a0ce82c | 864 | } else if (0 == strcmp(com, "cons")) { |
POTLESS_2 | 81:83567a0ce82c | 865 | consigne = atoi(numb); |
POTLESS_2 | 81:83567a0ce82c | 866 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 81:83567a0ce82c | 867 | OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d\r\n", consigne); |
POTLESS_2 | 81:83567a0ce82c | 868 | } else if (0 == strcmp(com, "reset")) { |
POTLESS_2 | 81:83567a0ce82c | 869 | NVIC_SystemReset(); |
POTLESS_2 | 81:83567a0ce82c | 870 | } else if (0 == strcmp(com, "sleep")) { |
POTLESS_2 | 81:83567a0ce82c | 871 | Stop_Sequence(); |
POTLESS_2 | 56:61b0f4d6a890 | 872 | } |
POTLESS_2 | 56:61b0f4d6a890 | 873 | |
POTLESS_2 | 56:61b0f4d6a890 | 874 | strcpy(IHM," "); |
POTLESS_2 | 56:61b0f4d6a890 | 875 | indexIHM = 0; |
POTLESS_2 | 56:61b0f4d6a890 | 876 | newIHMFlag = false; |
POTLESS_2 | 56:61b0f4d6a890 | 877 | } |
POTLESS_2 | 56:61b0f4d6a890 | 878 | |
POTLESS_2 | 26:a2fe19341f92 | 879 | void Create_File_Name_Date() |
POTLESS_2 | 25:322ef9488e65 | 880 | { |
POTLESS_2 | 25:322ef9488e65 | 881 | //Du nom du fichier Date / heure |
POTLESS_2 | 25:322ef9488e65 | 882 | seconds = time(NULL); |
POTLESS_2 | 25:322ef9488e65 | 883 | char Time[40]; |
POTLESS_2 | 25:322ef9488e65 | 884 | strftime(Time, 40, "%a_%d_%m_%Y_%H%M", localtime(&seconds)); |
POTLESS_2 | 42:3591ec9903b4 | 885 | sprintf(Log_File_Name, "%s_LOG.csv", Time); |
POTLESS_2 | 42:3591ec9903b4 | 886 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 887 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 888 | |
POTLESS_2 | 26:a2fe19341f92 | 889 | void Create_File_Name_Index() |
POTLESS_2 | 26:a2fe19341f92 | 890 | { |
POTLESS_2 | 26:a2fe19341f92 | 891 | //Du nom du fichier par Index |
POTLESS_2 | 42:3591ec9903b4 | 892 | sprintf(Log_File_Name, "LOG_%d.csv", UTILS::File_Index()); |
POTLESS_2 | 34:26f6e3dbefb9 | 893 | DEBUG(" Nouveau fichier LOG = %s \r\n", Log_File_Name); |
POTLESS_2 | 34:26f6e3dbefb9 | 894 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 895 | |
potless | 48:9ceb095f397a | 896 | |
POTLESS_2 | 4:d84250f67dec | 897 | int main() |
POTLESS_2 | 12:7f3aadd79f89 | 898 | { |
POTLESS_2 | 68:7f4ab9c03b32 | 899 | |
POTLESS_2 | 40:32d89e04ead1 | 900 | HAL_Init(); |
POTLESS_2 | 40:32d89e04ead1 | 901 | __HAL_RCC_PWR_CLK_ENABLE(); |
potless | 37:f9461c6592f2 | 902 | HAL_PWR_EnableBkUpAccess(); |
POTLESS_2 | 76:9dc83d5cf075 | 903 | |
POTLESS_2 | 72:6d5590dbe13e | 904 | //Vérifications Flag de démarrage |
POTLESS_2 | 72:6d5590dbe13e | 905 | UTILS::START_FLAG(); |
POTLESS_2 | 76:9dc83d5cf075 | 906 | |
POTLESS_2 | 56:61b0f4d6a890 | 907 | E5V = 1; |
POTLESS_2 | 57:a0827fa46b03 | 908 | E3V = 1; |
POTLESS_2 | 40:32d89e04ead1 | 909 | |
POTLESS_2 | 58:694d4d00407c | 910 | if (PIN_V_USB_DIGI) flag_USB = true; |
POTLESS_2 | 59:fd64ca9dae27 | 911 | if (PIN_V_PILES_DIGI) flag_Piles = true; |
POTLESS_2 | 58:694d4d00407c | 912 | |
POTLESS_2 | 68:7f4ab9c03b32 | 913 | //UTILS::PVD_Config(); |
POTLESS_2 | 58:694d4d00407c | 914 | |
POTLESS_2 | 56:61b0f4d6a890 | 915 | buzzer.beep(1000,0.5); |
POTLESS_2 | 58:694d4d00407c | 916 | |
POTLESS_2 | 43:5ae8baf28e32 | 917 | //Ci-dessous commande pour formater une nouvelle carte |
POTLESS_2 | 68:7f4ab9c03b32 | 918 | //UTILS::Format_Flash(); |
POTLESS_2 | 43:5ae8baf28e32 | 919 | |
POTLESS_2 | 43:5ae8baf28e32 | 920 | //Montage Flash |
POTLESS_2 | 43:5ae8baf28e32 | 921 | UTILS::Mount_Flash(); |
POTLESS_2 | 68:7f4ab9c03b32 | 922 | |
POTLESS_2 | 58:694d4d00407c | 923 | /* |
POTLESS_2 | 58:694d4d00407c | 924 | if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { |
POTLESS_2 | 58:694d4d00407c | 925 | UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); |
POTLESS_2 | 58:694d4d00407c | 926 | DEBUG("ARNSRS ID forcée à 000\r\n"); |
POTLESS_2 | 58:694d4d00407c | 927 | } |
POTLESS_2 | 58:694d4d00407c | 928 | */ |
POTLESS_2 | 68:7f4ab9c03b32 | 929 | |
POTLESS_2 | 58:694d4d00407c | 930 | //pour le premier lancement quand l'appareil n'a pas d'ID. |
POTLESS_2 | 58:694d4d00407c | 931 | //int ID = 0; |
POTLESS_2 | 58:694d4d00407c | 932 | //UTILS::Write(ADRESSE_ID, ID); |
POTLESS_2 | 12:7f3aadd79f89 | 933 | |
POTLESS_2 | 57:a0827fa46b03 | 934 | DEBUG("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n"); |
POTLESS_2 | 58:694d4d00407c | 935 | |
POTLESS_2 | 34:26f6e3dbefb9 | 936 | |
POTLESS_2 | 43:5ae8baf28e32 | 937 | //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème... |
POTLESS_2 | 43:5ae8baf28e32 | 938 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 939 | char YEAR[10]; |
POTLESS_2 | 43:5ae8baf28e32 | 940 | strftime(YEAR, 10, "%D", localtime(&seconds)); |
potless | 73:2bbea82bf1e5 | 941 | if (0 == strcmp(YEAR, " 01/01/70 ")) |
potless | 73:2bbea82bf1e5 | 942 | DEBUG(" Vous devez régler la RTC...\r\n\r\n"); |
POTLESS_2 | 18:bfd78c05b589 | 943 | |
POTLESS_2 | 43:5ae8baf28e32 | 944 | bool calib_O2 = false; |
POTLESS_2 | 43:5ae8baf28e32 | 945 | bool calib_CO2 = false; |
POTLESS_2 | 18:bfd78c05b589 | 946 | |
POTLESS_2 | 62:891379d80b1b | 947 | sensors.Sensors_INIT(calib_O2, calib_CO2); |
POTLESS_2 | 43:5ae8baf28e32 | 948 | |
POTLESS_2 | 43:5ae8baf28e32 | 949 | wait(1); |
POTLESS_2 | 43:5ae8baf28e32 | 950 | |
POTLESS_2 | 43:5ae8baf28e32 | 951 | //Création du nouveau fichier LOG par index / par date. |
POTLESS_2 | 82:5a0589682877 | 952 | Create_File_Name_Index(); |
POTLESS_2 | 82:5a0589682877 | 953 | //Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 954 | |
POTLESS_2 | 43:5ae8baf28e32 | 955 | //Création et écriture du header du fichier LOG |
POTLESS_2 | 43:5ae8baf28e32 | 956 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 42:3591ec9903b4 | 957 | |
POTLESS_2 | 58:694d4d00407c | 958 | /* |
POTLESS_2 | 43:5ae8baf28e32 | 959 | Servo_Poumon.Init("Servo_Poumon.sys"); |
POTLESS_2 | 43:5ae8baf28e32 | 960 | Servo_Fuite.Init("Servo_Fuite.sys"); |
POTLESS_2 | 15:efd3b3bf3f37 | 961 | |
POTLESS_2 | 58:694d4d00407c | 962 | Servo_Poumon.Init(VOLET_POUMON_ADDR); |
POTLESS_2 | 58:694d4d00407c | 963 | Servo_Fuite.Init(VOLET_FUITE_ADDR); |
POTLESS_2 | 58:694d4d00407c | 964 | */ |
POTLESS_2 | 58:694d4d00407c | 965 | |
POTLESS_2 | 57:a0827fa46b03 | 966 | DEBUG(" Demarrage des threads...\r\n\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 967 | |
POTLESS_2 | 68:7f4ab9c03b32 | 968 | /* |
POTLESS_2 | 68:7f4ab9c03b32 | 969 | |
POTLESS_2 | 62:891379d80b1b | 970 | Pour mémoire, les réglage de priorité des thread |
POTLESS_2 | 68:7f4ab9c03b32 | 971 | |
POTLESS_2 | 68:7f4ab9c03b32 | 972 | osPriorityIdle = -3, ///< priority: idle (lowest) |
POTLESS_2 | 68:7f4ab9c03b32 | 973 | osPriorityLow = -2, ///< priority: low |
POTLESS_2 | 68:7f4ab9c03b32 | 974 | osPriorityBelowNormal = -1, ///< priority: below normal |
POTLESS_2 | 68:7f4ab9c03b32 | 975 | osPriorityNormal = 0, ///< priority: normal (default) |
POTLESS_2 | 68:7f4ab9c03b32 | 976 | osPriorityAboveNormal = +1, ///< priority: above normal |
POTLESS_2 | 68:7f4ab9c03b32 | 977 | osPriorityHigh = +2, ///< priority: high |
POTLESS_2 | 68:7f4ab9c03b32 | 978 | osPriorityRealtime = +3, ///< priority: realtime (highest) |
POTLESS_2 | 68:7f4ab9c03b32 | 979 | osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority |
POTLESS_2 | 62:891379d80b1b | 980 | */ |
POTLESS_2 | 68:7f4ab9c03b32 | 981 | |
POTLESS_2 | 62:891379d80b1b | 982 | thread_Volets_POUMON.set_priority(osPriorityHigh); |
POTLESS_2 | 68:7f4ab9c03b32 | 983 | |
POTLESS_2 | 62:891379d80b1b | 984 | thread_Volets_POUMON.start(callback(GO_TO_thread_POUMON)); |
POTLESS_2 | 68:7f4ab9c03b32 | 985 | |
POTLESS_2 | 62:891379d80b1b | 986 | DEBUG(" Contrôle volet Poumon démarré\r\n\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 987 | |
POTLESS_2 | 43:5ae8baf28e32 | 988 | wait(1); |
POTLESS_2 | 68:7f4ab9c03b32 | 989 | |
POTLESS_2 | 62:891379d80b1b | 990 | thread_Volets_FUITE.set_priority(osPriorityHigh); |
POTLESS_2 | 68:7f4ab9c03b32 | 991 | |
POTLESS_2 | 62:891379d80b1b | 992 | thread_Volets_FUITE.start(callback(GO_TO_thread_FUITE)); |
POTLESS_2 | 68:7f4ab9c03b32 | 993 | |
POTLESS_2 | 62:891379d80b1b | 994 | DEBUG(" Contrôle volet Fuite démarré\r\n\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 995 | |
POTLESS_2 | 62:891379d80b1b | 996 | wait(1); |
POTLESS_2 | 68:7f4ab9c03b32 | 997 | |
POTLESS_2 | 62:891379d80b1b | 998 | thread_Secu.set_priority(osPriorityNormal); |
POTLESS_2 | 68:7f4ab9c03b32 | 999 | |
POTLESS_2 | 62:891379d80b1b | 1000 | thread_Secu.start(callback(SECU_thread)); |
POTLESS_2 | 68:7f4ab9c03b32 | 1001 | |
POTLESS_2 | 62:891379d80b1b | 1002 | DEBUG(" Contrôle des paramètres de sécu démarré\r\n\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 1003 | |
POTLESS_2 | 62:891379d80b1b | 1004 | wait(1); |
POTLESS_2 | 68:7f4ab9c03b32 | 1005 | |
POTLESS_2 | 62:891379d80b1b | 1006 | thread_Head.set_priority(osPriorityNormal); |
POTLESS_2 | 68:7f4ab9c03b32 | 1007 | |
POTLESS_2 | 43:5ae8baf28e32 | 1008 | thread_Head.start(callback(SENSORS_thread)); |
POTLESS_2 | 68:7f4ab9c03b32 | 1009 | |
POTLESS_2 | 56:61b0f4d6a890 | 1010 | DEBUG(" Tête capteurs démarrée\r\n\r\n"); |
POTLESS_2 | 68:7f4ab9c03b32 | 1011 | |
POTLESS_2 | 43:5ae8baf28e32 | 1012 | wait(1); |
POTLESS_2 | 9:04bfdfc029cb | 1013 | |
POTLESS_2 | 43:5ae8baf28e32 | 1014 | //Init PID |
POTLESS_2 | 43:5ae8baf28e32 | 1015 | //Entrée PPO2 entre 100 et 1000 mb |
POTLESS_2 | 43:5ae8baf28e32 | 1016 | control_Servo.setInputLimits(Min_Input, Max_Input); |
POTLESS_2 | 43:5ae8baf28e32 | 1017 | //Sortie servo entre 0 et 100 % |
POTLESS_2 | 43:5ae8baf28e32 | 1018 | control_Servo.setOutputLimits(Min_Output, Max_Output); |
POTLESS_2 | 57:a0827fa46b03 | 1019 | //Reglage de l'interval du PID |
POTLESS_2 | 57:a0827fa46b03 | 1020 | control_Servo.setInterval(RATE_PID); |
POTLESS_2 | 43:5ae8baf28e32 | 1021 | //Consigne à x mb |
POTLESS_2 | 43:5ae8baf28e32 | 1022 | control_Servo.setSetPoint(consigne); |
POTLESS_2 | 57:a0827fa46b03 | 1023 | //Mode auto au démarrage |
POTLESS_2 | 58:694d4d00407c | 1024 | control_Servo.setMode(AUTO_MODE); |
POTLESS_2 | 79:d22473a0e20d | 1025 | |
POTLESS_2 | 76:9dc83d5cf075 | 1026 | thread_PID.set_priority(osPriorityNormal); |
POTLESS_2 | 34:26f6e3dbefb9 | 1027 | |
POTLESS_2 | 76:9dc83d5cf075 | 1028 | thread_PID.start(callback(PID_thread)); |
POTLESS_2 | 79:d22473a0e20d | 1029 | |
POTLESS_2 | 77:0cecc4adbab2 | 1030 | DEBUG(" PID thread démarré\r\n\r\n"); |
POTLESS_2 | 77:0cecc4adbab2 | 1031 | |
POTLESS_2 | 77:0cecc4adbab2 | 1032 | wait(1); |
POTLESS_2 | 79:d22473a0e20d | 1033 | |
POTLESS_2 | 56:61b0f4d6a890 | 1034 | DEBUG(" Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n"); |
POTLESS_2 | 7:ad15c386e960 | 1035 | |
POTLESS_2 | 46:28298df0ac55 | 1036 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 1037 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 1038 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 43:5ae8baf28e32 | 1039 | |
POTLESS_2 | 47:89a088bc8866 | 1040 | serialMonit.attach(&callbackParam); |
POTLESS_2 | 58:694d4d00407c | 1041 | |
POTLESS_2 | 56:61b0f4d6a890 | 1042 | display.attach(&callbackIHM); |
POTLESS_2 | 68:7f4ab9c03b32 | 1043 | |
POTLESS_2 | 58:694d4d00407c | 1044 | OTU_Ticker.attach(&Calcul_OTU, 60); |
POTLESS_2 | 68:7f4ab9c03b32 | 1045 | |
POTLESS_2 | 72:6d5590dbe13e | 1046 | vusb_off_on.fall(&ALIM_is_unplugged); |
POTLESS_2 | 68:7f4ab9c03b32 | 1047 | |
POTLESS_2 | 72:6d5590dbe13e | 1048 | vpiles_off_on.fall(&ALIM_is_unplugged); |
POTLESS_2 | 80:545af6e94aa5 | 1049 | |
POTLESS_2 | 80:545af6e94aa5 | 1050 | IHM("<0/0/0 0-0-0 ;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;%d>\r\n", 4); |
POTLESS_2 | 80:545af6e94aa5 | 1051 | |
POTLESS_2 | 56:61b0f4d6a890 | 1052 | buzzer.beep(1000,0.3); |
POTLESS_2 | 56:61b0f4d6a890 | 1053 | wait_ms(500); |
POTLESS_2 | 56:61b0f4d6a890 | 1054 | buzzer.beep(1000,0.3); |
POTLESS_2 | 58:694d4d00407c | 1055 | |
POTLESS_2 | 43:5ae8baf28e32 | 1056 | while (true) { |
POTLESS_2 | 36:1f5e2247b073 | 1057 | |
POTLESS_2 | 43:5ae8baf28e32 | 1058 | //Démarrage du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 43:5ae8baf28e32 | 1059 | REAL_RATE.start(); |
POTLESS_2 | 36:1f5e2247b073 | 1060 | |
POTLESS_2 | 43:5ae8baf28e32 | 1061 | if (newParamFlag) { |
POTLESS_2 | 43:5ae8baf28e32 | 1062 | DEEP_DEBUG(" From PC = %s\r\n", param); |
POTLESS_2 | 43:5ae8baf28e32 | 1063 | Decoding_Message(param); |
POTLESS_2 | 43:5ae8baf28e32 | 1064 | } |
POTLESS_2 | 58:694d4d00407c | 1065 | |
POTLESS_2 | 56:61b0f4d6a890 | 1066 | if (newIHMFlag) { |
POTLESS_2 | 56:61b0f4d6a890 | 1067 | DEEP_DEBUG(" From IHM = %s\r\n", IHM); |
POTLESS_2 | 56:61b0f4d6a890 | 1068 | Decoding_IHM(IHM); |
POTLESS_2 | 56:61b0f4d6a890 | 1069 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 1070 | |
POTLESS_2 | 43:5ae8baf28e32 | 1071 | //Fabrication de la chaine Date / heure |
POTLESS_2 | 43:5ae8baf28e32 | 1072 | seconds = time(NULL); |
POTLESS_2 | 43:5ae8baf28e32 | 1073 | char Time_buf[32]; |
POTLESS_2 | 43:5ae8baf28e32 | 1074 | strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); |
POTLESS_2 | 19:cac3761a5d0b | 1075 | |
POTLESS_2 | 56:61b0f4d6a890 | 1076 | //Fabrication de la chaine de com |
POTLESS_2 | 71:23e7435e236f | 1077 | sprintf(to_store,"<%s;%d;%d;%.1f;%d;%.2f;%.2f;%d;%d;%d;%.2f;%.2f;%d;%.3f;%.3f;%.3f;%d;%d>", |
POTLESS_2 | 43:5ae8baf28e32 | 1078 | Time_buf, |
POTLESS_2 | 43:5ae8baf28e32 | 1079 | co2, |
POTLESS_2 | 43:5ae8baf28e32 | 1080 | ppO2, |
POTLESS_2 | 43:5ae8baf28e32 | 1081 | pression, |
POTLESS_2 | 43:5ae8baf28e32 | 1082 | (int)OTU, |
POTLESS_2 | 43:5ae8baf28e32 | 1083 | Temp1, |
POTLESS_2 | 43:5ae8baf28e32 | 1084 | Temp2, |
POTLESS_2 | 43:5ae8baf28e32 | 1085 | Humid, |
POTLESS_2 | 43:5ae8baf28e32 | 1086 | CellO2_1, |
POTLESS_2 | 43:5ae8baf28e32 | 1087 | CellO2_2, |
POTLESS_2 | 43:5ae8baf28e32 | 1088 | volet_poumon_Position, |
POTLESS_2 | 43:5ae8baf28e32 | 1089 | volet_fuite_Position, |
POTLESS_2 | 43:5ae8baf28e32 | 1090 | FLAG_PID, |
POTLESS_2 | 43:5ae8baf28e32 | 1091 | Kc, |
POTLESS_2 | 43:5ae8baf28e32 | 1092 | Ti, |
POTLESS_2 | 43:5ae8baf28e32 | 1093 | Td, |
POTLESS_2 | 56:61b0f4d6a890 | 1094 | consigne, |
POTLESS_2 | 56:61b0f4d6a890 | 1095 | Commande_IHM |
POTLESS_2 | 58:694d4d00407c | 1096 | ); |
POTLESS_2 | 15:efd3b3bf3f37 | 1097 | |
POTLESS_2 | 15:efd3b3bf3f37 | 1098 | |
POTLESS_2 | 43:5ae8baf28e32 | 1099 | //Pour windev |
POTLESS_2 | 43:5ae8baf28e32 | 1100 | if (FLAG_WINDEV) { |
POTLESS_2 | 43:5ae8baf28e32 | 1101 | OUTPUT("%s\r\n", to_store); |
POTLESS_2 | 43:5ae8baf28e32 | 1102 | } |
POTLESS_2 | 53:84571a5e2cda | 1103 | |
POTLESS_2 | 43:5ae8baf28e32 | 1104 | //Pour l'IHM |
POTLESS_2 | 46:28298df0ac55 | 1105 | if (FLAG_DISPLAY) { |
POTLESS_2 | 46:28298df0ac55 | 1106 | IHM("%s\r\n", to_store); |
POTLESS_2 | 46:28298df0ac55 | 1107 | } |
POTLESS_2 | 53:84571a5e2cda | 1108 | |
POTLESS_2 | 43:5ae8baf28e32 | 1109 | //Vers le moniteur série |
POTLESS_2 | 43:5ae8baf28e32 | 1110 | if (FLAG_AFF) { |
POTLESS_2 | 43:5ae8baf28e32 | 1111 | Affichage(); |
POTLESS_2 | 43:5ae8baf28e32 | 1112 | } |
POTLESS_2 | 76:9dc83d5cf075 | 1113 | |
POTLESS_2 | 68:7f4ab9c03b32 | 1114 | //Vers le traceur série |
POTLESS_2 | 68:7f4ab9c03b32 | 1115 | if (FLAG_TRACE) { |
POTLESS_2 | 68:7f4ab9c03b32 | 1116 | Traceur_Arduino(); |
POTLESS_2 | 68:7f4ab9c03b32 | 1117 | } |
POTLESS_2 | 68:7f4ab9c03b32 | 1118 | |
POTLESS_2 | 43:5ae8baf28e32 | 1119 | //Enregistrement de la chaine |
POTLESS_2 | 43:5ae8baf28e32 | 1120 | if (FLAG_REC) { |
POTLESS_2 | 43:5ae8baf28e32 | 1121 | UTILS::Write_Flash_File(to_store, Log_File_Name); |
POTLESS_2 | 43:5ae8baf28e32 | 1122 | count ++; |
POTLESS_2 | 43:5ae8baf28e32 | 1123 | if (count > Max_Log_Size) { |
POTLESS_2 | 84:49f0acf09f67 | 1124 | Create_File_Name_Index(); |
POTLESS_2 | 84:49f0acf09f67 | 1125 | //Create_File_Name_Date(); |
POTLESS_2 | 43:5ae8baf28e32 | 1126 | sensors.Create_Header(Log_File_Name); |
POTLESS_2 | 43:5ae8baf28e32 | 1127 | count = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 1128 | OUTPUT("$\r\n"); |
POTLESS_2 | 43:5ae8baf28e32 | 1129 | wait(0.5); |
POTLESS_2 | 43:5ae8baf28e32 | 1130 | UTILS::Dir_Flash(&serialMonit); |
POTLESS_2 | 34:26f6e3dbefb9 | 1131 | } |
POTLESS_2 | 34:26f6e3dbefb9 | 1132 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1133 | |
POTLESS_2 | 76:9dc83d5cf075 | 1134 | /* |
POTLESS_2 | 76:9dc83d5cf075 | 1135 | //Update du PID |
POTLESS_2 | 76:9dc83d5cf075 | 1136 | if (FLAG_PID == 1 && EN_MODE_SECU == false) { |
POTLESS_2 | 76:9dc83d5cf075 | 1137 | control_Servo.setProcessValue(ppO2); |
POTLESS_2 | 76:9dc83d5cf075 | 1138 | //Nouvelle sortie servo poumon si on est pas en mode SECU |
POTLESS_2 | 76:9dc83d5cf075 | 1139 | Consigne_poumon = 90 - control_Servo.compute(); |
POTLESS_2 | 76:9dc83d5cf075 | 1140 | // mode volets asservis (simule un seul moteur) |
POTLESS_2 | 76:9dc83d5cf075 | 1141 | Consigne_fuite = 90 - Consigne_poumon; |
POTLESS_2 | 76:9dc83d5cf075 | 1142 | } |
POTLESS_2 | 76:9dc83d5cf075 | 1143 | */ |
POTLESS_2 | 79:d22473a0e20d | 1144 | |
POTLESS_2 | 43:5ae8baf28e32 | 1145 | //Arrêt du Timer mesurant le temps d'éxecution du code |
POTLESS_2 | 43:5ae8baf28e32 | 1146 | REAL_RATE.stop(); |
POTLESS_2 | 43:5ae8baf28e32 | 1147 | //Définition de la nouvelle valeur du temps d'échantillonage du PID. |
POTLESS_2 | 43:5ae8baf28e32 | 1148 | RATE = REAL_RATE.read(); |
POTLESS_2 | 43:5ae8baf28e32 | 1149 | //Reset du Timer |
POTLESS_2 | 43:5ae8baf28e32 | 1150 | REAL_RATE.reset(); |
POTLESS_2 | 43:5ae8baf28e32 | 1151 | |
POTLESS_2 | 43:5ae8baf28e32 | 1152 | //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... |
POTLESS_2 | 43:5ae8baf28e32 | 1153 | if (Ref_Time > RATE) { |
POTLESS_2 | 43:5ae8baf28e32 | 1154 | RATE_TRUE = (Ref_Time - RATE) * 1000; |
POTLESS_2 | 43:5ae8baf28e32 | 1155 | } else { |
POTLESS_2 | 43:5ae8baf28e32 | 1156 | RATE_TRUE = 0; |
POTLESS_2 | 43:5ae8baf28e32 | 1157 | |
POTLESS_2 | 43:5ae8baf28e32 | 1158 | DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); |
POTLESS_2 | 43:5ae8baf28e32 | 1159 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1160 | |
POTLESS_2 | 43:5ae8baf28e32 | 1161 | wait_ms(RATE_TRUE); |
POTLESS_2 | 34:26f6e3dbefb9 | 1162 | } |
POTLESS_2 | 4:d84250f67dec | 1163 | } |
POTLESS_2 | 43:5ae8baf28e32 | 1164 | |
POTLESS_2 | 43:5ae8baf28e32 | 1165 |