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