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