From 717e403d12969cf1635e26be26944ee8daf89593 Mon Sep 17 00:00:00 2001 From: henyxia Date: Wed, 6 May 2015 17:00:50 +0200 Subject: [PATCH] Sperated output --- heat.c | 61 +++++++++++++++++++++++++++++++++++++++++++------------------ hvc.c | 9 ++++++--- main.c | 6 +++++- printx.c | 20 ++++++++++++++++++-- printx.h | 2 +- pump.c | 20 ++++++++++---------- 6 files changed, 83 insertions(+), 35 deletions(-) diff --git a/heat.c b/heat.c index 478459b..5a18d6d 100644 --- a/heat.c +++ b/heat.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "hvc.h" #include "heat.h" #include "pump.h" @@ -60,7 +61,7 @@ void resetHeatOk(void) bool isHeatOk(void) { - return heat_ok; + return (tAct > T_STEP_THRESH && tAct < T_HOLD_THRESH); } void* processHeat(void* arg) @@ -72,12 +73,13 @@ void* processHeat(void* arg) //Chaufffe initiale if (task[0]) { + printx(INFO, HEAT, "Entering in task 0\n"); tTask = clock(); if (tAct < T_INIT_THRESH) { setHeatOn(); - printx(INFO, BUS, "Début chauffe initiale 0\n"); + printx(INFO, HEAT, "Début chauffe initiale 0\n"); task[0] = false; task[1] = true; } @@ -91,6 +93,7 @@ void* processHeat(void* arg) else if (task[1]) { + printx(INFO, HEAT, "Entering in task 1\n"); tTask = clock(); task[1] = false; task[2] = true; @@ -98,10 +101,12 @@ void* processHeat(void* arg) else if (task[2]) { + printx(INFO, HEAT, "Entering in task 2\n"); + printx(INFO, HEAT, "Time heating : %d (%d - %d) / %d\n", (tNow - tTask) / CLOCKS_PER_SEC, tNow, tTask, CLOCKS_PER_SEC); if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_HEAT_TIME ) { setHeatOff(); - printx(INFO, BUS, "Fin chauffe initiale 1\n"); + printx(INFO, HEAT, "Fin chauffe initiale 1\n"); task[2] = false; task[3] = true; } @@ -109,6 +114,7 @@ void* processHeat(void* arg) else if (task[3]) { + printx(INFO, HEAT, "Entering in task 3\n"); tTask = clock(); task[3] = false; task[4] = true; @@ -116,9 +122,10 @@ void* processHeat(void* arg) else if (task[4]) { + printx(INFO, HEAT, "Entering in task 4\n"); if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME ) { - printx(INFO, BUS, "Fin attente %d sec 2\n", INIT_WAIT_TIME); + printx(INFO, HEAT, "Fin attente %d sec 2\n", INIT_WAIT_TIME); task[4] = false; task[5] = true; } @@ -128,6 +135,7 @@ void* processHeat(void* arg) //Chauffe par palier else if (task[5]) { + printx(INFO, HEAT, "Entering in task 5\n"); tTask = clock(); task[5] = false; task[6] = true; @@ -136,9 +144,10 @@ void* processHeat(void* arg) else if (task[6]) { + printx(INFO, HEAT, "Entering in task 6\n"); if (tAct < T_STEP_THRESH) { - printx(INFO, BUS, "Début Chauffe par palier 3\n"); + printx(INFO, HEAT, "Début Chauffe par palier 3\n"); setHeatOn(); task[6] = false; task[7] = true; @@ -153,6 +162,7 @@ void* processHeat(void* arg) else if (task[7]) { + printx(INFO, HEAT, "Entering in task 7\n"); tTask = clock(); task[7] = false; task[8] = true; @@ -160,9 +170,10 @@ void* processHeat(void* arg) else if (task[8]) { + printx(INFO, HEAT, "Entering in task 8\n"); if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME ) { - printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4\n"); + printx(INFO, HEAT, "Fin de chauffe palier intermédiaire 4\n"); setHeatOff(); task[8] = false; task[9] = true; @@ -171,6 +182,7 @@ void* processHeat(void* arg) else if (task[9]) { + printx(INFO, HEAT, "Entering in task 9\n"); tTask = clock(); task[9] = false; task[10] = true; @@ -178,9 +190,10 @@ void* processHeat(void* arg) else if (task[10]) { + printx(INFO, HEAT, "Entering in task 10\n"); if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME ) { - printx(INFO, BUS, "Fin d'attente palier intermédiaire 5\n"); + printx(INFO, HEAT, "Fin d'attente palier intermédiaire 5\n"); if ( tAct < T_STEP_THRESH ) { @@ -200,6 +213,7 @@ void* processHeat(void* arg) // Maintien au chaud else if (task[11]) { + printx(INFO, HEAT, "Entering in task 11\n"); tTask = clock(); task[11] = false; task[12] = true; @@ -207,7 +221,8 @@ void* processHeat(void* arg) else if (task[12]) { - printx(INFO, BUS, "Début Maintien au chaud 6\n"); + printx(INFO, HEAT, "Entering in task 12\n"); + printx(INFO, HEAT, "Début Maintien au chaud 6\n"); setHeatOk(); task[12]=false; task[13]=true; @@ -215,20 +230,22 @@ void* processHeat(void* arg) else if (task[13]) { + printx(INFO, HEAT, "Entering in task 13\n"); tTask = clock(); task[13] = false; task[14] = true; } else if (task[14]) - { + { + printx(INFO, HEAT, "Entering in task 14\n"); if(hold_heat) { if( (tAct < T_HOLD_THRESH)) { if (!isPumpOn()) { - printx(INFO, BUS, "Début Chauffe maintien sans pompe 7\n"); + printx(INFO, HEAT, "Début Chauffe maintien sans pompe 7\n"); setHeatOn(); task[14] = false; task[15] = true; @@ -236,7 +253,7 @@ void* processHeat(void* arg) else { - printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'\n"); + printx(INFO, HEAT, "Début Chauffe maintien avec pompe 7'\n"); setHeatOn(); task[14]=false; task[19]=true; //Numéro de tache "T HOLD_HEAT_TIME ) { - printx(INFO, BUS, "Fin chauffe maintien sans pompe 8\n"); + printx(INFO, HEAT, "Fin chauffe maintien sans pompe 8\n"); setHeatOff(); task[16] = false; task[17] = true; @@ -274,6 +293,7 @@ void* processHeat(void* arg) else if (task[17]) { + printx(INFO, HEAT, "Entering in task 17\n"); tTask = clock(); task[17] = false; task[18] = true; @@ -281,11 +301,12 @@ void* processHeat(void* arg) else if (task[18]) { + printx(INFO, HEAT, "Entering in task 18\n"); if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_WAIT_TIME ) { if ( tAct < T_HOLD_THRESH) { - printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9\n"); + printx(INFO, HEAT, "Fin d'attente chauffe intermédiaire maintien 9\n"); task[18] = false; task[11] = true; //Retour au début de "Maintien au chaud" } @@ -295,6 +316,7 @@ void* processHeat(void* arg) //Maintien au chaud avec pompage else if (task[19]) { + printx(INFO, HEAT, "Entering in task 19\n"); tTask = clock(); task[19] = false; task[20] = true; @@ -302,9 +324,10 @@ void* processHeat(void* arg) else if (task[20]) { + printx(INFO, HEAT, "Entering in task 20\n"); if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME ) { - printx(INFO, BUS, "Fin chauffe maintien avec pompe 10\n"); + printx(INFO, HEAT, "Fin chauffe maintien avec pompe 10\n"); setHeatOff(); task[20] = false; task[21] = true; @@ -313,6 +336,7 @@ void* processHeat(void* arg) else if (task[21]) { + printx(INFO, HEAT, "Entering in task 21\n"); tTask = clock(); task[21] = false; task[22] = true; @@ -320,11 +344,12 @@ void* processHeat(void* arg) else if (task[22]) { + printx(INFO, HEAT, "Entering in task 22\n"); if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_WAIT_TIME ) { if ( tAct < T_HOLD_THRESH) { - printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11\n"); + printx(INFO, HEAT, "Fin d'attente chauffe intermédiaire maintien avec pompe 11\n"); task[22] = false; task[11] = true; //Retour au début de "Maintien au chaud" } @@ -334,6 +359,7 @@ void* processHeat(void* arg) //Fin de maintien au chaud (demandé par l'extérieur) et reboucle quand hold_heat est remis else if(task[23]) { + printx(INFO, HEAT, "Entering in task 23\n"); setHeatOff(); heat_ok=false; @@ -351,8 +377,7 @@ void* processHeat(void* arg) //task[]=false; //task[]=true; } - - + usleep(20000); } diff --git a/hvc.c b/hvc.c index b4ff0ef..c829cac 100644 --- a/hvc.c +++ b/hvc.c @@ -128,7 +128,8 @@ bool initHVC() sendData(&hvc_fd, GET_PUMP); data = getData(&hvc_fd); - previousPumpState = data == PUMP_STATE_HIGH; + previousPumpState = (data == PUMP_STATE_HIGH); + printf("Data received from HVC for PUMP %02x\n", data); return true; } @@ -187,12 +188,14 @@ void* processHVC(void* we) } // Querying pump state - sendData(&hvc_fd, GET_TEMP); + sendData(&hvc_fd, GET_PUMP); data = getData(&hvc_fd); - pumpState = data == PUMP_STATE_HIGH; + pumpState = (data == PUMP_STATE_HIGH); + printx(DEBUG, HVC, "PUMP %d %d Flow : %d\n", previousPumpState, pumpState, pumped); if(pumpState ^ previousPumpState) pumped++; previousPumpState = pumpState; + actDeb(pumped); usleep(HVC_POLLING_TIME); } diff --git a/main.c b/main.c index e59ef7e..79a3771 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,7 @@ int main(void) pthread_t tBUS; pthread_t tHVC; pthread_t tHeat; + pthread_t tPump; initUILog(); if(!initLog()) { @@ -48,8 +49,11 @@ int main(void) pthread_create(&tHVC, NULL, processHVC, NULL); initProcessHeat(); initProcessPump(); - //setPumpOn(); pthread_create(&tHeat, NULL, processHeat, NULL); + pthread_create(&tPump, NULL, processPump, NULL); + + setVolWanted(1); + setCoffeeWanted(); pthread_join(tUI, NULL); closeLog(); diff --git a/printx.c b/printx.c index 61af8bb..830ec1a 100644 --- a/printx.c +++ b/printx.c @@ -11,9 +11,9 @@ #define S_RESET "\33[0m" #define MAX_BUFFER 128 -FILE* logfiles[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; +FILE* logfiles[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"}; -char f_name[6][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS ", "TEMP"}; +char f_name[8][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS ", "TEMP", "PUMP", "HEAT"}; struct timeval tv; void removeCharFromString(char c, char *str) @@ -68,6 +68,20 @@ bool initLog() return false; } + logfiles[6] = fopen("log/pump.log", "a"); + if(logfiles[6] == NULL) + { + printf("Unable to open the pump log file\n"); + return false; + } + + logfiles[7] = fopen("log/heat.log", "a"); + if(logfiles[7] == NULL) + { + printf("Unable to open the heat log file\n"); + return false; + } + return true; } @@ -79,6 +93,8 @@ void closeLog() fclose(logfiles[3]); fclose(logfiles[4]); fclose(logfiles[5]); + fclose(logfiles[6]); + fclose(logfiles[7]); } void printx(severity s, msgfrom from, char* str, ...) diff --git a/printx.h b/printx.h index 8144037..b685b00 100644 --- a/printx.h +++ b/printx.h @@ -10,7 +10,7 @@ typedef enum typedef enum { - MAIN, UI, NFC, HVC, BUS, TEMP + MAIN, UI, NFC, HVC, BUS, TEMP, PUMP, HEAT }msgfrom; bool initLog(); diff --git a/pump.c b/pump.c index 195dfb5..b2d47bf 100644 --- a/pump.c +++ b/pump.c @@ -78,7 +78,7 @@ void* processPump(void* arg) { if (coffee_wanted) { - printx(INFO, BUS, "Demande de café prise en compte 1\n"); + printx(INFO, PUMP, "Demande de café prise en compte 1\n"); taskP[0]=false; taskP[1]=true; } @@ -88,14 +88,14 @@ void* processPump(void* arg) { if (isHeatOk()) { - printx(INFO, BUS, "Chauffe eau a bonne temperature OK 2\n"); + printx(INFO, PUMP, "Chauffe eau a bonne temperature OK 2\n"); taskP[1]=false; taskP[3]=true; } else { - printx(INFO, BUS, "Attente chauffe eau a bonne temperature 2'\n"); + printx(INFO, PUMP, "Attente chauffe eau a bonne temperature 2'\n"); taskP[1]=false; taskP[2]=true; } @@ -113,7 +113,7 @@ void* processPump(void* arg) else if (taskP[3]) { tTaskP = clock(); - printx(INFO, BUS, "Distribution de l'eau Pompe ON 3\n"); + printx(INFO, PUMP, "Distribution de l'eau Pompe ON 3\n"); taskP[3]=false; taskP[4]=true; } @@ -125,14 +125,14 @@ void* processPump(void* arg) if (volDeb > volWanted) { - printx(INFO, BUS, "Fin de Distribution de l'eau Pompe OFF 4\n"); + printx(INFO, PUMP, "Fin de Distribution de l'eau Pompe OFF 4\n"); taskP[4]=false; taskP[5]=true; } else if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 ) { - printx(INFO, BUS, "Pompe utilisée depuis plus d'1 min, mise en pause 4'\n"); + printx(INFO, PUMP, "Pompe utilisée depuis plus d'1 min, mise en pause 4'\n"); taskP[4]=false; taskP[6]=false; } @@ -143,7 +143,7 @@ void* processPump(void* arg) setPumpOff(); pump_on=false; - printx(INFO, BUS, "Cafe servi 5\n"); + printx(INFO, PUMP, "Cafe servi 5\n"); volWanted=0; coffee_wanted=false; @@ -156,7 +156,7 @@ void* processPump(void* arg) setPumpOff(); pump_on=false; - printx(INFO, BUS, "En pause, Pompe OFF 6"); + printx(INFO, PUMP, "En pause, Pompe OFF 6"); tTaskP = clock(); taskP[6]=false; @@ -167,13 +167,13 @@ void* processPump(void* arg) { if ( ((tNowP - tTaskP) / CLOCKS_PER_SEC) > 60 ) { - printx(INFO, BUS, "Pause terminée 7\n"); + printx(INFO, PUMP, "Pause terminée 7\n"); taskP[7]=false; taskP[4]=true; } } - sleep(50); + usleep(20000); } return NULL; -- libgit2 0.21.2