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