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