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