Commit 846585f9ccacd0022ecbbb6806071766ef90dcdd

Authored by henyxia
1 parent 5dd66ab0

Fixed some printx

Added timer for the log
Added 35s command on heat
Showing 4 changed files with 22 additions and 8 deletions   Show diff stats
.gitignore
... ... @@ -2,3 +2,4 @@
2 2 *.o
3 3 tweekd
4 4 *.log
  5 +*.csv
... ...
... ... @@ -35,36 +35,42 @@ void processCmd(char* buffer)
35 35 }
36 36 else if(strcmp(buffer, "setpumpon") == 0)
37 37 {
38   - printx(INFO, BUS, "Setting PUMP ON");
  38 + printx(INFO, BUS, "Setting PUMP ON\n");
39 39 setPumpWantedState(true);
40 40 }
41 41 else if(strcmp(buffer, "setpumpoff") == 0)
42 42 {
43   - printx(INFO, BUS, "Setting PUMP OFF");
  43 + printx(INFO, BUS, "Setting PUMP OFF\n");
44 44 setPumpWantedState(false);
45 45 }
46 46 else if(strcmp(buffer, "setheaton") == 0)
47 47 {
48   - printx(INFO, BUS, "Setting HEAT ON");
  48 + printx(INFO, BUS, "Setting HEAT ON\n");
49 49 setHeatWantedState(true);
50 50 }
51 51 else if(strcmp(buffer, "setheatoff") == 0)
52 52 {
53   - printx(INFO, BUS, "Setting HEAT OFF");
  53 + printx(INFO, BUS, "Setting HEAT OFF\n");
54 54 setHeatWantedState(false);
55 55 }
56 56 else if(strcmp(buffer, "setheaton5s") == 0)
57 57 {
58   - printx(INFO, BUS, "Setting HEAT ON for 5 secs");
  58 + printx(INFO, BUS, "Setting HEAT ON for 5 secs\n");
59 59 setHeatTimer(5);
60 60 setHeatWantedState(true);
61 61 }
62 62 else if(strcmp(buffer, "setpumpon5s") == 0)
63 63 {
64   - printx(INFO, BUS, "Setting PUMP ON for 5 secs");
  64 + printx(INFO, BUS, "Setting PUMP ON for 5 secs\n");
65 65 setPumpTimer(5);
66 66 setPumpWantedState(true);
67 67 }
  68 + else if(strcmp(buffer, "setheaton35s") == 0)
  69 + {
  70 + printx(INFO, BUS, "Setting HEAT ON for 35 secs\n");
  71 + setHeatTimer(35);
  72 + setHeatWantedState(true);
  73 + }
68 74  
69 75 //printx(DEBUG, BUS, "STRLEN : %d and strcmp ret %d", strlen(buffer), strcmp(buffer, "quit"));
70 76 }
... ... @@ -81,7 +87,8 @@ void* processBus(void* we)
81 87 printx(DEBUG, BUS, "Event receved !\n");
82 88 busFree = false;
83 89 lseek(bus, 0, SEEK_SET);
84   - printx(DEBUG, BUS, "Data read %d\n", read(bus, buffer, CMD_MAX));
  90 + read(bus, buffer, CMD_MAX);
  91 + //printx(DEBUG, BUS, "Data read %d\n", read(bus, buffer, CMD_MAX));
85 92 ftruncate(bus, 0);
86 93 sync();
87 94 processCmd(buffer);
... ...
... ... @@ -104,6 +104,7 @@ void* processHVC(void* we)
104 104 sendData(&hvc_fd, GET_TEMP);
105 105 data = getData(&hvc_fd);
106 106 setTemp(data);
  107 + printx(DEBUG, HVC, "TEMP %d\n", data);
107 108  
108 109 if(tHeatTimer > 0)
109 110 {
... ... @@ -112,6 +113,7 @@ void* processHVC(void* we)
112 113 {
113 114 wHeat = false;
114 115 tHeatTimer = 0;
  116 + printx(INFO, HVC, "Shutting down HEAT according to timer\n");
115 117 }
116 118  
117 119 }
... ... @@ -123,6 +125,7 @@ void* processHVC(void* we)
123 125 {
124 126 wPump = false;
125 127 tPumpTimer = 0;
  128 + printx(INFO, HVC, "Shutting down PUMP according to timer\n");
126 129 }
127 130 }
128 131  
... ...
printx.c
... ... @@ -14,6 +14,7 @@
14 14 FILE* logfile = NULL;
15 15 char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"};
16 16 char f_name[5][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS "};
  17 +time_t start;
17 18  
18 19 void removeCharFromString(char c, char *str)
19 20 {
... ... @@ -26,6 +27,7 @@ void removeCharFromString(char c, char *str)
26 27  
27 28 bool initLog()
28 29 {
  30 + start = clock();
29 31 char filename[FILENAME_LENGTH];
30 32 time_t now = time(NULL);
31 33  
... ... @@ -53,10 +55,11 @@ void printx(severity s, msgfrom from, char* str, ...)
53 55 {
54 56 char buffer1[MAX_BUFFER];
55 57 char buffer2[MAX_BUFFER];
  58 + time_t now = clock();
56 59 va_list arglist;
57 60 va_start(arglist, str);
58 61 vsprintf(buffer1, str, arglist);
59   - fprintf(logfile, buffer1);
  62 + fprintf(logfile, "[%6lu] %s", (now - start)/CLOCKS_PER_SEC , buffer1);
60 63 fflush(logfile);
61 64 sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET);
62 65 removeCharFromString('\n', buffer2);
... ...