mbed-os github
Dependencies: ADS1015 Faulhaber HTU21D_mod MS5837_potless Sensor_Head_RevB_3 USBDevice_dfu Utilsdfu beep
Fork of ARNSRS_testDFU by
Diff: main.cpp
- Revision:
- 43:5ae8baf28e32
- Parent:
- 42:3591ec9903b4
- Child:
- 44:5cd6f84a62ec
diff -r 3591ec9903b4 -r 5ae8baf28e32 main.cpp --- a/main.cpp Mon Apr 09 06:52:00 2018 +0000 +++ b/main.cpp Thu May 03 08:44:07 2018 +0000 @@ -11,55 +11,40 @@ #define nSleep_SERVO_POUMON PC_6 #define FWD_SERVO_POUMON PB_14 #define REV_SERVO_POUMON PB_13 -#define Channel_A_SERVO_POUMON PB_1 -#define Channel_B_SERVO_POUMON PB_2 +#define Channel_A_SERVO_POUMON PB_2 +#define Channel_B_SERVO_POUMON PB_1 #define HOME_SERVO_POUMON 0 #define PWM_SERVO_FUITE PB_10 -#define nSleep_SERVO_FUITE PC_5 +#define nSleep_SERVO_FUITE PB_0 #define FWD_SERVO_FUITE PB_4 #define REV_SERVO_FUITE PB_5 -#define Channel_A_SERVO_FUITE PB_8 -#define Channel_B_SERVO_FUITE PB_9 +#define Channel_A_SERVO_FUITE PC_9 +#define Channel_B_SERVO_FUITE PA_8 #define HOME_SERVO_FUITE 90 -//Ecrit dans le moniteur série de la tablette à 115200 bds si sur 1, penser à mettre NEED_CONSOLE_OUTPUT à 0 -#define NEED_ANDROID_OUTPUT 0 - -//Mode PID, STD à commenter / décommenter -#define STD_MODE -//#define PID_MODE - -#ifdef STD_MODE -int MODE_FLAG = 0; -#endif +//Pin de test des alims +#define PIN_V_PILES_ANALOG PA_1 +#define PIN_V_PILES_DIGI PC_3 +#define PIN_V_USB_DIGI PA_0 -#ifdef PID_MODE -int MODE_FLAG = 2; -#endif - -#if NEED_ANDROID_OUTPUT -#define ANDROID(...) { android.printf(__VA_ARGS__); } -#else -#define ANDROID(...) -#endif - -#if DEBUG_MODE -#define DEBUG(...) { printf(__VA_ARGS__); fflush(stdout);} -#else -#define DEBUG(...) -#endif - +#define OUTPUT(...) { NVIC_DisableIRQ(USART3_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} +//#define OUTPUT(...) { NVIC_DisableIRQ(USART2_IRQn); serialMonit.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART2_IRQn);} +//#define IHM(...) { NVIC_DisableIRQ(USART3_IRQn); display.printf(__VA_ARGS__); fflush(stdout);NVIC_EnableIRQ(USART3_IRQn);} //PinName pwm, PinName nSleep, PinName fwd, PinName rev, PinName channelA, PinName channelB, int pulsesPerRev, int Rapport, Encoding encoding = X2_ENCODING 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); -//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); +Faulhaber Servo_Fuite("Servo_Fuite", PWM_SERVO_FUITE, nSleep_SERVO_FUITE, FWD_SERVO_FUITE, REV_SERVO_FUITE, Channel_A_SERVO_FUITE, Channel_B_SERVO_FUITE, 16, 207, Faulhaber::X2_ENCODING); //Moniteur série, Serial 2 -Serial serialMonit(PC_10,PC_11,115200); +Serial serialMonit(PC_10, PC_11, 115200); +//Serial serialMonit(PA_2, PA_3,115200); -//COM Série vers Android, Serial 3 -Serial android(PA_2, PA_3,115200); +//Communication avec l'IHM +//Serial display(PC_4, PC_5, 115200); + +//Moniteur pour le debug avec une nucleo, a commenter avec la carte definitive +Serial serial(USBTX, USBRX, 115200); //Init de la lib ARNSRS; SENSOR_HEAD_REV_B sensors; @@ -70,15 +55,8 @@ volatile int indexParam = 0; bool newParamFlag = false; -//pour Commandes Android -const int sizeAndroid = 20; -char Android[sizeAndroid]; -volatile int indexAndroid = 0; -bool newAndroidFlag = false; -char to_android[100]; - -//Flag pour interrompre l'affichage si on veut... -bool FLAG_FIRST_LOOP = true; +//Flag PID ON / OFF +int FLAG_PID = 0; //Flag pour interrompre l'affichage si on veut... bool FLAG_AFF = false; @@ -86,6 +64,9 @@ //Flag pour envoyer à l'app windev... bool FLAG_WINDEV = false; +//Flag pour envoyer à l'IHM... +bool FLAG_DISPLAY = false; + //Flag pour interrompre l'enregistrement si on veut... bool FLAG_REC = true; @@ -130,14 +111,13 @@ float Volets_Speed = 0.1; float Volet_DeadBand = 5; -#ifdef PID_MODE //Paramètre du PID float Kc = 40; float Ti = 0; float Td = 0; float RATE_PID = Ref_Time; float Commande_PID; -float consigne = 210; +int consigne = 210; float Max_Input = 1000; float Min_Input = 80; float Max_Output = 85;//Vérifier la valeur pour angle à laisser ouvert... @@ -145,29 +125,27 @@ //Init PID PID control_Servo(Kc, Ti, Td, RATE_PID); -#endif //Boolean du status de l'appareil, en mode SECU ou nominal bool EN_MODE_SECU = false; //Test des alim -//DigitalIn V_USB(PA_0, PullUp); +DigitalIn V_USB_DIGI(PIN_V_USB_DIGI); +DigitalIn V_PILES_DIGI(PIN_V_PILES_DIGI); -DigitalIn V_PILES_2(PC_3); -AnalogIn V_PILES(PA_1); +//Test voltage piles +AnalogIn V_PILES_ANALOG(PIN_V_PILES_ANALOG); int Vusb = 1; int VPiles = 1; -float VPiles_2 = 1; +float VPiles_val = 1; -//Interruption user button -InterruptIn button(USER_BUTTON); -InterruptIn vpile_off_on(PA_0); // TODO mettre un define sur PA_0 -volatile int GO = 0; +//Interruption pin +InterruptIn vpile_off_on(PIN_V_PILES_DIGI); +InterruptIn vusb_off_on(PIN_V_USB_DIGI); void Affichage() { - NVIC_DisableIRQ(USART3_IRQn); //serialMonit.printf("\r\n"); serialMonit.printf(" CO2 = %d ppm\r\n" , co2); serialMonit.printf(" PPO2 = %d mb\r\n", ppO2); @@ -191,32 +169,16 @@ serialMonit.printf(" V_USB = %f\r\n", Vusb); //serialMonit.printf("\r\n\r\n"); fflush(stdout); - NVIC_EnableIRQ(USART3_IRQn); } -void pressed() -{ - GO = GO + 1; - if (GO > 1) NVIC_SystemReset(); -} - -//Pas nécessaire -/* -void retour_alim() -{ - DEBUG("-------------- interruption retour alim en cours ---------------\r\n"); - NVIC_SystemReset(); -} -*/ - //Passage en mode SECU void Mode_SECU() { -#ifdef PID_MODE + //Mise du PID en mode manuel (desactivation...) control_Servo.setMode(MANUAL_MODE); -#endif + Consigne_poumon = HOME_SERVO_POUMON; Consigne_fuite = HOME_SERVO_FUITE; @@ -226,32 +188,39 @@ while(1) { wait_ms(100); if (Servo_Poumon.Pos_OK() == true) break; - //if (Servo_Poumon.Pos_OK() == true && Servo_Fuite.Pos_OK() == true) break; + if (Servo_Fuite.Pos_OK() == true) break; } - DEBUG("-------------- Appareil en mode SECU ---------------\r\n"); + + OUTPUT(" Appareil en mode SECU\r\n"); wait_ms(100); EN_MODE_SECU = true; + wait_ms(100); - int Pos = Servo_Poumon.getPulses(); - UTILS::Store_A_Val((float)Pos, "Servo_Poumon.sys"); - DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos); - //Pos = Servo_Fuite.getPulses(); - //UTILS::Store_A_Val((float)Pos, "Servo_Fuite"); - //DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos); + int Pos_P = Servo_Poumon.getPulses(); + UTILS::Store_A_Val((float)Pos_P, "Servo_Poumon.sys"); + DEBUG(" position volet poumon sauvegardée = %d pulse(s)\r\n", Pos_P); + + int Pos_F = Servo_Fuite.getPulses(); + UTILS::Store_A_Val((float)Pos_F, "Servo_Fuite.sys"); + DEBUG(" position volet fuite sauvegardée = %d pulse(s)\r\n", Pos_F); + Servo_Poumon.Sleep(); + Servo_Fuite.Sleep(); } //Sequence d'arrêt void Stop_Sequence() { + OUTPUT(" Mise en veille de l'appareil.\r\n"); + + wait(1); + Mode_SECU(); //ejection de la flash pour pas crasher le system de fichiers UTILS::UnMount_Flash(); - DEBUG("----------------ARRET DE L'APPAREIL--------------------\r\n"); - // préparation deepsleep /* @@ -281,6 +250,8 @@ // Enable wakeup pin WKUP2 HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW); // low parce qu'on veut que ça redémarre avec le user button TODO à passer sur High pour que ça redémarrage avec l'arrivée du hus sur l'USB */ + HAL_PWREx_EnablePullUpPullDownConfig() ; + HAL_PWREx_EnableGPIOPullDown(PWR_GPIO_A,PWR_GPIO_BIT_0); HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // pour PA_0 // Clear wake up Flag @@ -366,7 +337,10 @@ //Retour position des servos volet_poumon_Position = Servo_Poumon.Get_Position(); - //volet_fuite_Position = Servo_Fuite.Get_Position(); + volet_fuite_Position = Servo_Fuite.Get_Position(); + + //Calcul des OTU + Calcul_OTU(); } } @@ -381,21 +355,15 @@ Servo_Poumon.Go_To(Consigne_poumon, Volets_Speed, Volet_DeadBand); //Servo_Fuite.Go_To_Prop(Consigne_fuite); - //Servo_Fuite.Go_To_PID(Consigne_fuite); - //Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand ); + //Servo_Fuite.Go_To_PID(Consigne_fuite, Volet_DeadBand); + Servo_Fuite.Go_To(Consigne_fuite, Volets_Speed, Volet_DeadBand ); } } void SECU_thread() { while (true) { - //DEEP_DEBUG(" SECU_Thread\r\n"); - //Alim USB - //Vusb = Power_Test(V_USB); - //VPiles = Power_Test(V_PILES); - //Divers problèmes à implémenter - //if(!Check()) Mode_SECU(); } } @@ -421,21 +389,6 @@ } } -//Callback de l'intérruption des envois de commandes depuis Android -void callbackAndroid() -{ - while(android.readable()) { - if (indexAndroid == sizeAndroid) //éviter la saturation du buffer - android.getc(); - else - Android [indexAndroid++] = android.getc();//chargement du buffer dans le message - if ((indexAndroid == sizeAndroid) || (Android[indexAndroid -1] == '\n')) {//le message est complet ou nouvelle ligne ou autre si on veut... - Android[indexAndroid] = 0; - newAndroidFlag = true; - } - } -} - void Decoding_Message(char message []) { @@ -447,22 +400,27 @@ DEEP_DEBUG("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); //serialMonit.printf("\r\n Commande = %s Valeur = %s \r\n\r\n", com, numb); + OUTPUT("?\r\n"); + if (0 == strcmp(com, "secu")) { Mode_SECU(); } else if (0 == strcmp(com, "PING")) { - NVIC_DisableIRQ(USART3_IRQn); - serialMonit.printf("$"); - NVIC_EnableIRQ(USART3_IRQn); + FLAG_PID = 0; + FLAG_AFF = false; + FLAG_WINDEV = false; + control_Servo.setMode(MANUAL_MODE); } else if (0 == strcmp(com, "ARNSRS_ID")) { + OUTPUT("Changement de l'ID de l'appareil pour le N°: %s?\r\n", numb); UTILS::Store_A_Val(atoi(numb), "ARNSRS_ID"); - } else if (0 == strcmp(com, "monit")) { - FLAG_AFF = false; - FLAG_WINDEV = true; - } else if (0 == strcmp(com, "debug")) { - FLAG_AFF = false; - FLAG_WINDEV = false; + } else if (0 == strcmp(com, "monit")) { + FLAG_AFF = false; + FLAG_WINDEV = true; + } else if (0 == strcmp(com, "debug")) { + FLAG_AFF = false; + FLAG_WINDEV = false; } else if (0 == strcmp(com, "Head_ID")) { //On l'enregistre dans l'eeprom + OUTPUT("Changement de l'ID de la tête capteur pour le N°: %s\r\n", numb); UTILS::write_EEPROM(numb, HEAD_ID); } else if (0 == strcmp(com, "O2_1_ID")) { //On l'enregistre dans l'eeprom @@ -477,32 +435,34 @@ FLAG_O2 = false; wait_ms(100); float Val = sensors.Calibrate_O2(atoi(numb)); - serialMonit.printf(" Calibration O2 dans l'air = %f\r\n", Val); + OUTPUT(" Calibration O2 dans l'air = %f\r\n", Val); wait_ms(100); FLAG_O2 = true; } else if (0 == strcmp(com, "calib_CO2_A")) { - int Val = sensors.Calibrate_CO2(); - serialMonit.printf(" Calibration CO2 dans l'air = %d\r\n", Val); + int Val = sensors.Calibrate_CO2(); + OUTPUT(" Calibration CO2 dans l'air = %d\r\n", Val); } else if (0 == strcmp(com, "flash_i")) { UTILS::Flash_Infos(&serialMonit); } else if (0 == strcmp(com, "flash_u")) { + OUTPUT(" Démontage de la Flash.\r\n"); FLAG_REC = false; UTILS::UnMount_Flash(); } else if (0 == strcmp(com, "flash_m")) { + OUTPUT(" Montage de la Flash.\r\n"); UTILS::Mount_Flash(); } else if (0 == strcmp(com, "check_F")) { - serialMonit.printf(" ARNSRS_ID.sys = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID.sys")); - serialMonit.printf(" Servo_Poumon.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon.sys")); - //serialMonit.printf("Servo_Fuite.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite"); + OUTPUT(" ARNSRS_ID.sys = %d\r\n", (int)UTILS::Read_A_Val("ARNSRS_ID.sys")); + OUTPUT(" Servo_Poumon.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Poumon.sys")); + OUTPUT(" Servo_Fuite.sys = %d\r\n", (int)UTILS::Read_A_Val("Servo_Fuite.sys")); } else if (0 == strcmp(com, "check_E")) { sensors.Sensor_head_check(&serialMonit); } else if (0 == strcmp(com, "rec")) { if (FLAG_REC) { FLAG_REC = false; - serialMonit.printf(" Arrêt du Data Logging.\r\n"); + OUTPUT(" Arrêt du Data Logging.\r\n"); } else { FLAG_REC = true; - serialMonit.printf(" Démarrage Data Logging dans %s\r\n", Log_File_Name); + OUTPUT(" Démarrage Data Logging dans %s\r\n", Log_File_Name); } } else if (0 == strcmp(com, "help")) { FLAG_AFF = false; @@ -514,25 +474,27 @@ //UTILS::Help(); } else if (0 == strcmp(com, "flash_c")) { FLAG_REC = false; - //serialMonit.printf("$"); UTILS::Clean_Flash(); } else if (0 == strcmp(com, "flash_f")) { FLAG_REC = false; - //serialMonit.printf("$"); - UTILS::Clean_Flash_All(); + UTILS::Clean_Flash_All(); } else if (0 == strcmp(com, "dir")) { + FLAG_WINDEV = false; + OUTPUT("$\r\n"); + wait(0.5); UTILS::Dir_Flash(&serialMonit); } else if (0 == strcmp(com, "get")) { - int mark = 0; wait_ms(100); - char filename[20]; - UTILS::Read_Flash_File(&serialMonit, numb); - wait_ms(100); + char filename[20]; + UTILS::Read_Flash_File(&serialMonit, numb); + wait_ms(100); } else if (0 == strcmp(com, "del")) { FLAG_REC = false; char filename[20]; UTILS::Delete_Flash_File(numb); - //UTILS::Dir_Flash(&serialMonit); + OUTPUT("$\r\n"); + wait(0.5); + UTILS::Dir_Flash(&serialMonit); FLAG_REC = true; } else if (0 == strcmp(com, "file_s")) { char filename[20]; @@ -541,25 +503,66 @@ Consigne_poumon = 0; volet_poumon_Position = 0; Servo_Poumon.reset(); + OUTPUT(" Volet poumon Calibré.\r\n"); } else if (0 == strcmp(com, "calib_f")) { Consigne_fuite = 0; volet_fuite_Position = 0; - //Servo_Fuite.reset(); + Servo_Fuite.reset(); + OUTPUT(" Volet fuite Calibré.\r\n"); } else if (0 == strcmp(com, "sleep")) { Stop_Sequence(); } else if (0 == strcmp(com, "time")) {//Depuis terminal MAC taper : " date +%s " set_time(atoi(numb)); - serialMonit.printf(" La RTC a été mise à l'heure.\r\n"); + OUTPUT(" La RTC a été mise à l'heure.\r\n"); } else if (0 == strcmp(com, "c_pou")) { + Consigne_poumon = atof(numb); + DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); + } else if (0 == strcmp(com, "c_fui")) { + Consigne_fuite = atof(numb); + DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); + } else if (0 == strcmp(com, "mp_pou")) { Consigne_poumon += atof(numb); DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); - } else if (0 == strcmp(com, "c_fui")) { + } else if (0 == strcmp(com, "mp_fui")) { Consigne_fuite += atof(numb); DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); } else if (0 == strcmp(com, "reset")) { + FLAG_REC = false; UTILS::UnMount_Flash(); + OUTPUT(" Reset de l'appareil.\r\n"); + wait(1); NVIC_SystemReset(); + } else if (0 == strcmp(com, "Kc")) { + Kc = atof(numb); + control_Servo.reset(); + control_Servo.setTunings(Kc, Ti, Td); + OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); + } else if (0 == strcmp(com, "Ti")) { + Ti = atof(numb); + control_Servo.reset(); + control_Servo.setTunings(Kc, Ti, Td); + OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); + } else if (0 == strcmp(com, "Td")) { + Td = atof(numb); + control_Servo.reset(); + control_Servo.setTunings(Kc, Ti, Td); + OUTPUT(" MAJ PID --> Kc = %f Ti = %f Td = %f?\r\n", Kc, Ti, Td); + } else if (0 == strcmp(com, "Cons")) { + consigne = atoi(numb); + control_Servo.setSetPoint(consigne); + OUTPUT(" MAJ CONSIGNE PID --> Consigne = %d?\r\n", consigne); + } else if (0 == strcmp(com, "PID")) { + if (FLAG_PID == 1) { + control_Servo.setMode(MANUAL_MODE); + OUTPUT(" PID OFF?\r\n"); + FLAG_PID = 0; + } else if (FLAG_PID == 0) { + control_Servo.setMode(AUTO_MODE); + OUTPUT(" PID ON?\r\n"); + FLAG_PID = 1; + } } else { + sensors.cozirSend(message); } @@ -568,58 +571,6 @@ newParamFlag = false; } -void Decoding_Message_Android(char message []) -{ - char *commande = 0; - float valeur = 0; - - sscanf(message,"%s %f",&commande , &valeur); - - if ((char)commande == 'T') { - set_time(valeur); - } else if ((char)commande == 'I') { - Consigne_poumon = (float)valeur; - DEBUG(" Servo Poumon = %f\r\n", Consigne_poumon); - } else if ((char)commande == 'O') { - Consigne_fuite = (float)valeur; - DEBUG(" Servo Fuite = %f\r\n", Consigne_fuite); - ///////////////////////////////////////// - //Pour rajouter une commande - //} else if ((char)commande == 'X') { - // attribuer à une VARIABLE = valeur; - // ou une action, avec ou sans valeur - ///////////////////////////////////////// - } else if ((char)commande == 'R') { - NVIC_SystemReset(); - } -#ifdef PID_MODE - else if ((char)commande == 'p') { - Kc = (float)valeur; - control_Servo.reset(); - control_Servo.setTunings(Kc, Ti, Td); - DEBUG" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); - } else if ((char)commande == 'i') { - Ti = (float)valeur; - control_Servo.reset(); - control_Servo.setTunings(Kc, Ti, Td); - DEBUG(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); - } else if ((char)commande == 'd') { - Td = (float)valeur; - control_Servo.reset(); - control_Servo.setTunings(Kc, Ti, Td); - DEBUG(" UPDATE PID --> Kc = %f Ti = %f Td = %f\r\n\n", Kc, Ti, Td); - } else if ((char)commande == 'c') { - consigne = valeur; - control_Servo.setSetPoint(consigne); - DEBUG(" UPDATE CONSIGNE PID --> Consigne = %d\r\n\n", consigne); - } -#endif - - strcpy(Android," "); - indexAndroid = 0; - newAndroidFlag = false; -} - void Create_File_Name_Date() { //Du nom du fichier Date / heure @@ -642,286 +593,222 @@ HAL_Init(); - //V_USB.mode(PullDown); // on force à zero tant que l'alim par les piles n'est pas en place - - button.fall(&pressed); - //vpile_off_on.rise (&retour_alim); - __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWR_EnableBkUpAccess(); - int count = 0; + //Ci-dessous commande pour formater une nouvelle carte + //UTILS::Format_Flash(); + + //Montage Flash + UTILS::Mount_Flash(); - while (1) { - - if (count == 0) { - serialMonit.printf("\r\n Appuyez sur le User Button pour commencer...\r\n\r\n"); - } - count = 1; + //Liste des fichiers sur la Flash + //UTILS::Dir_Flash(&serialMonit); - if (GO == 1) { + if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { + UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); + DEBUG("ARNSRS ID forcée à 000\r\n"); + } - wait(1); + //OUTPUT("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n"); - serialMonit.attach(&callbackParam, Serial::RxIrq); + //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème... + seconds = time(NULL); + char YEAR[10]; + strftime(YEAR, 10, "%D", localtime(&seconds)); + if (0 == strcmp(YEAR, "01/01/70")); //OUTPUT(" Vous devez régler la RTC...\r\n\r\n"); - android.attach(&callbackAndroid, Serial::RxIrq); + bool calib_O2 = false; + bool calib_CO2 = false; - //Ci-dessous commande pour formater une nouvelle carte - //UTILS::Format_Flash(); + /* + Par défaut les valeur en cas de calibration sur true sont les suivant - //Montage Flash - UTILS::Mount_Flash(); + nbCalibO2 = 5 + Mode = SPOOLING + Filtre = DIGI_FILTER32 + CalibrationCO2 = "CALIB_AIR" - //Liste des fichiers sur la Flash - //UTILS::Dir_Flash(&serialMonit); + Parfois la calibration du Cozir coince...faire reset et relancer... + + Pour calibrer avec ces paramètres : - if (UTILS::File_Exist("ARNSRS_ID.sys") == false) { - UTILS::Store_A_Val(000, "ARNSRS_ID.sys"); - DEBUG("ARNSRS ID forcée à 000\r\n"); - } - - serialMonit.printf("\r\n\r\n Démarrage de l'appareil, veuillez patienter...\r\n\r\n"); + sensors.Sensors_INIT(true, true); + + Pour changer utiliser la syntaxe suivante : + + sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); + + */ + + sensors.Sensors_INIT(calib_O2, calib_CO2); + + wait(1); + + //Création du nouveau fichier LOG par index / par date. + //Create_File_Name_Index(); + Create_File_Name_Date(); + + //Création et écriture du header du fichier LOG + sensors.Create_Header(Log_File_Name); - //Vérification RTC, si on est le 01/01/70, c'est qu'il y a un problème... - seconds = time(NULL); - char YEAR[10]; - strftime(YEAR, 10, "%D", localtime(&seconds)); - if (0 == strcmp(YEAR, "01/01/70")) serialMonit.printf(" Vous devez régler la RTC...\r\n"); - - - bool calib_O2 = false; - bool calib_CO2 = false; + Servo_Poumon.Init("Servo_Poumon.sys"); + Servo_Fuite.Init("Servo_Fuite.sys"); - /* - Par défaut les valeur en cas de calibration sur true sont les suivant + //OUTPUT(" Demarrage des threads...\r\n\r\n"); + + /* + + Pour mémoire, les réglage de priorité des thread - nbCalibO2 = 5 - Mode = SPOOLING - Filtre = DIGI_FILTER32 - CalibrationCO2 = "CALIB_AIR" + osPriorityIdle = -3, ///< priority: idle (lowest) + osPriorityLow = -2, ///< priority: low + osPriorityBelowNormal = -1, ///< priority: below normal + osPriorityNormal = 0, ///< priority: normal (default) + osPriorityAboveNormal = +1, ///< priority: above normal + osPriorityHigh = +2, ///< priority: high + osPriorityRealtime = +3, ///< priority: realtime (highest) + osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority + */ - Parfois la calibration du Cozir coince...faire reset et relancer... - - Pour calibrer avec ces paramètres : - - sensors.Sensors_INIT(true, true); - - Pour changer utiliser la syntaxe suivante : + wait(1); - sensors.Sensors_INIT(true, true, true, 5, SPOOLING, DIGI_FILTER32, CALIB_AIR); + Thread thread_Volets(osPriorityNormal); + + thread_Volets.start(callback(GO_TO_thread)); - */ + //OUTPUT(" Contrôle des volets démarré\r\n\r\n"); + + wait(1); - sensors.Sensors_INIT(calib_O2, calib_CO2); - wait(1); + Thread thread_Secu(osPriorityNormal); + + thread_Secu.start(callback(SECU_thread)); - //Création du nouveau fichier LOG par index / par date. - //Create_File_Name_Index(); - Create_File_Name_Date(); + //OUTPUT(" Contrôle des paramètres de sécu démarré\r\n\r\n"); + + wait(1); + + Thread thread_Head(osPriorityNormal); - //Création et écriture du header du fichier LOG - sensors.Create_Header(Log_File_Name); + thread_Head.start(callback(SENSORS_thread)); - Servo_Poumon.Init("Servo_Poumon.sys"); - //Servo_Fuite.Init("Servo_Fuite"); + //OUTPUT(" Tête capteurs démarrée\r\n\r\n"); + + wait(1); - serialMonit.printf(" Demarrage des threads...\r\n\r\n"); + //Init PID + //Entrée PPO2 entre 100 et 1000 mb + control_Servo.setInputLimits(Min_Input, Max_Input); + //Sortie servo entre 0 et 100 % + control_Servo.setOutputLimits(Min_Output, Max_Output); + //Mode auto au démarrage + control_Servo.setMode(MANUAL_MODE); + //Consigne à x mb + control_Servo.setSetPoint(consigne); - /* - - Pour mémoire, les réglage de priorité des thread + //OUTPUT(" Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n"); - osPriorityIdle = -3, ///< priority: idle (lowest) - osPriorityLow = -2, ///< priority: low - osPriorityBelowNormal = -1, ///< priority: below normal - osPriorityNormal = 0, ///< priority: normal (default) - osPriorityAboveNormal = +1, ///< priority: above normal - osPriorityHigh = +2, ///< priority: high - osPriorityRealtime = +3, ///< priority: realtime (highest) - osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority - */ - - wait(1); + + OUTPUT("$\r\n"); + wait(0.5); + UTILS::Dir_Flash(&serialMonit); + + serialMonit.attach(&callbackParam, Serial::RxIrq); + while (true) { - Thread thread_Volets(osPriorityNormal); + //Démarrage du Timer mesurant le temps d'éxecution du code + REAL_RATE.start(); - thread_Volets.start(callback(GO_TO_thread)); + if (newParamFlag) { + DEEP_DEBUG(" From PC = %s\r\n", param); + Decoding_Message(param); + } - serialMonit.printf(" Volets thread démarré\r\n\r\n"); - - wait(1); - - Thread thread_Secu(osPriorityNormal); - - thread_Secu.start(callback(SECU_thread)); - - serialMonit.printf(" Secu thread démarré\r\n\r\n"); + //Fabrication de la chaine Date / heure + seconds = time(NULL); + char Time_buf[32]; + strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); - wait(1); - - Thread thread_Head(osPriorityNormal); - - thread_Head.start(callback(SENSORS_thread)); - - serialMonit.printf(" Info thread démarré\r\n\r\n"); - - wait(1); + //Fabrication de la chaine à enregistrer + sprintf(to_store,"<%s;%d;%d;%.2f;%d;%.2f;%.2f;%d;%d;%d;%.2f;%.2f;%d;%.3f;%.3f;%.3f;%d>", + Time_buf, + co2, + ppO2, + pression, + (int)OTU, + Temp1, + Temp2, + Humid, + CellO2_1, + CellO2_2, + volet_poumon_Position, + volet_fuite_Position, + FLAG_PID, + Kc, + Ti, + Td, + consigne + ); -#ifdef PID_MODE - //Init PID - //Entrée PPO2 entre 100 et 1000 mb - control_Servo.setInputLimits(Min_Input, Max_Input); - //Sortie servo entre 0 et 100 % - control_Servo.setOutputLimits(Min_Output, Max_Output); - //Mode auto au démarrage - control_Servo.setMode(AUTO_MODE); - //Consigne à x mb - control_Servo.setSetPoint(consigne); -#endif - - serialMonit.printf(" Threads démarrés.....\r\n\r\n Cliquez sur le bouton help pour voir la liste des \r\n commandes administrateur disponibles.\r\n$"); - - while (true) { - - //Démarrage du Timer mesurant le temps d'éxecution du code - REAL_RATE.start(); - - if (newParamFlag) { - DEEP_DEBUG(" From PC = %s\r\n", param); - Decoding_Message(param); - } - - if (newAndroidFlag) { - DEEP_DEBUG(" From Android = %s\r\n", Android); - Decoding_Message_Android(Android); - } - - //Fabrication de la chaine Date / heure - seconds = time(NULL); - char Time_buf[32]; - strftime(Time_buf, 32, "%D %I-%M-%S ", localtime(&seconds)); + //Pour windev + if (FLAG_WINDEV) { + OUTPUT("%s\r\n", to_store); + } + + //Pour l'IHM + //if (FLAG_DISPLAY) { + // IHM("%s\r\n", to_store); + //} + + //Vers le moniteur série + if (FLAG_AFF) { + NVIC_DisableIRQ(USART3_IRQn); + Affichage(); + NVIC_EnableIRQ(USART3_IRQn); + } -#ifdef PID_MODE - //Fabrication de la chaine à enregistrer - sprintf(to_store,"%s:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f:%d:%.3f:%.3f:%.3f:%d", - Time_buf, - co2, - ppO2, - pression, - Temp1, - Temp2, - Humid, - CellO2_1, - CellO2_2, - volet_poumon_Position, - volet_fuite_Position, - MODE_FLAG, - Kc, - Ti, - Td, - (int)consigne - ); -#endif -#ifndef PID_MODE - //Fabrication de la chaine à enregistrer sans les variables du PID - sprintf(to_store,"%s;%d;%d;%.2f;%.2f;%.2f;%d;%d;%d;%.2f;%.2f;%d;%.3f;%.3f;%.3f;%d", - Time_buf, - co2, - ppO2, - pression, - Temp1, - Temp2, - Humid, - CellO2_1, - CellO2_2, - volet_poumon_Position, - volet_fuite_Position, - MODE_FLAG, - 0.0, - 0.0, - 0.0, - 0 - ); -#endif - char to_slave[50]; - //Fabrication de la chaine pour l'IHM - sprintf(to_slave,"<%d:%d:%d:%.2f:%.2f:%.2f:%d:%d:%d:%.2f:%.2f>\r\n", - co2, - ppO2, - (int)OTU, - pression, - Temp1, - Temp2, - Humid, - CellO2_1, - CellO2_2, - volet_poumon_Position, - volet_fuite_Position); - - //Pour Android on ajoute < et > pour décoder l'arrivée du message - if (NEED_ANDROID_OUTPUT == 1) { - //sprintf(to_android,"<%s>",to_store); - //ANDROID(to_slave); - } - - //Pour windev la même chose que pour l'écran - if (FLAG_WINDEV) { - NVIC_DisableIRQ(USART3_IRQn); - serialMonit.printf(to_slave); - NVIC_EnableIRQ(USART3_IRQn); - } - - //Calcul des OTU - Calcul_OTU(); - - //Vers le moniteur série - if (FLAG_AFF) { - NVIC_DisableIRQ(USART3_IRQn); - Affichage(); - NVIC_EnableIRQ(USART3_IRQn); - } - - //Enregistrement de la chaine - if (FLAG_REC) { - UTILS::Write_Flash_File(to_store, Log_File_Name); - count ++; - if (count > Max_Log_Size) { - Create_File_Name_Date(); - sensors.Create_Header(Log_File_Name); - count = 0; - } - } - -#ifdef PID_MODE - //Update du PID - control_Servo.setProcessValue(ppO2); - //Nouvelle sortie servo fuite si on est pas en mode SECU - if(!EN_MODE_SECU) Consigne_fuite = control_Servo.compute(); -#endif - - //Arrêt du Timer mesurant le temps d'éxecution du code - REAL_RATE.stop(); - //Définition de la nouvelle valeur du temps d'échantillonage du PID. - RATE = REAL_RATE.read(); - //Reset du Timer - REAL_RATE.reset(); - - //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... - if (Ref_Time > RATE) { - RATE_TRUE = (Ref_Time - RATE) * 1000; - } else { - RATE_TRUE = 0; -#ifdef PID_MODE - control_Servo.setInterval(RATE); -#endif - DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); - } - - wait_ms(RATE_TRUE); + //Enregistrement de la chaine + if (FLAG_REC) { + UTILS::Write_Flash_File(to_store, Log_File_Name); + count ++; + if (count > Max_Log_Size) { + Create_File_Name_Date(); + sensors.Create_Header(Log_File_Name); + count = 0; + OUTPUT("$\r\n"); + wait(0.5); + UTILS::Dir_Flash(&serialMonit); } } + + //Update du PID + control_Servo.setProcessValue(ppO2); + //Nouvelle sortie servo fuite si on est pas en mode SECU + if(!EN_MODE_SECU) Consigne_fuite = control_Servo.compute(); + + //Arrêt du Timer mesurant le temps d'éxecution du code + REAL_RATE.stop(); + //Définition de la nouvelle valeur du temps d'échantillonage du PID. + RATE = REAL_RATE.read(); + //Reset du Timer + REAL_RATE.reset(); + + //Pour ralentir le code à Ref_Time seconde fixe quelque soit les intéruptions du loop.... + if (Ref_Time > RATE) { + RATE_TRUE = (Ref_Time - RATE) * 1000; + } else { + RATE_TRUE = 0; + + //control_Servo.setInterval(RATE); + + DEEP_DEBUG("Pour ralentir le code, Ref_Time doit être supérieur à %f seconde(s)\r\n\n", RATE); + } + + wait_ms(RATE_TRUE); } } + +