ae25085d
henyxia
Output function done
|
1
2
3
4
5
|
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
|
b8e91a2f
henyxia
Displaying everyt...
|
6
|
#include <sys/time.h>
|
ae25085d
henyxia
Output function done
|
7
|
#include "printx.h"
|
ea1218f1
henyxia
UI finished
|
8
|
#include "ui.h"
|
ae25085d
henyxia
Output function done
|
9
10
11
12
13
|
#define FILENAME_LENGTH 24
#define S_RESET "\33[0m"
#define MAX_BUFFER 128
|
717e403d
henyxia
Sperated output
|
14
|
FILE* logfiles[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
ae25085d
henyxia
Output function done
|
15
|
char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"};
|
717e403d
henyxia
Sperated output
|
16
|
char f_name[8][5] = {"MAIN", "UI ", "NFC ", "HVC ", "BUS ", "TEMP", "PUMP", "HEAT"};
|
b8e91a2f
henyxia
Displaying everyt...
|
17
|
struct timeval tv;
|
ae25085d
henyxia
Output function done
|
18
|
|
ea1218f1
henyxia
UI finished
|
19
20
|
void removeCharFromString(char c, char *str)
{
|
fd498c68
henyxia
Some more feature...
|
21
|
int len = strlen(str)+1;
|
ea1218f1
henyxia
UI finished
|
22
23
24
25
|
for(int i=0; i<len; i++)
if(str[i] == c)
strncpy(&str[i],&str[i+1],len-i);
|
ea1218f1
henyxia
UI finished
|
26
27
|
}
|
ae25085d
henyxia
Output function done
|
28
29
|
bool initLog()
{
|
c0152e3d
henyxia
Separated log files
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
logfiles[0] = fopen("log/main.log", "a");
if(logfiles[0] == NULL)
{
printf("Unable to open the main log file\n");
return false;
}
logfiles[1] = fopen("log/ui.log", "a");
if(logfiles[1] == NULL)
{
printf("Unable to open the UI log file\n");
return false;
}
logfiles[2] = fopen("log/nfc.log", "a");
if(logfiles[2] == NULL)
{
printf("Unable to open the NFC log file\n");
return false;
}
|
ae25085d
henyxia
Output function done
|
49
|
|
c0152e3d
henyxia
Separated log files
|
50
51
52
53
54
55
|
logfiles[3] = fopen("log/hvc.log", "a");
if(logfiles[3] == NULL)
{
printf("Unable to open the HVC log file\n");
return false;
}
|
ae25085d
henyxia
Output function done
|
56
|
|
c0152e3d
henyxia
Separated log files
|
57
58
59
60
61
62
63
64
|
logfiles[4] = fopen("log/bus.log", "a");
if(logfiles[4] == NULL)
{
printf("Unable to open the BUS log file\n");
return false;
}
logfiles[5] = fopen("log/temp.log", "a");
|
b8e91a2f
henyxia
Displaying everyt...
|
65
|
if(logfiles[5] == NULL)
|
ae25085d
henyxia
Output function done
|
66
|
{
|
b8e91a2f
henyxia
Displaying everyt...
|
67
|
printf("Unable to open the temperature log file\n");
|
ae25085d
henyxia
Output function done
|
68
69
70
|
return false;
}
|
717e403d
henyxia
Sperated output
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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;
}
|
ae25085d
henyxia
Output function done
|
85
86
87
88
89
|
return true;
}
void closeLog()
{
|
c0152e3d
henyxia
Separated log files
|
90
91
92
93
94
|
fclose(logfiles[0]);
fclose(logfiles[1]);
fclose(logfiles[2]);
fclose(logfiles[3]);
fclose(logfiles[4]);
|
b8e91a2f
henyxia
Displaying everyt...
|
95
|
fclose(logfiles[5]);
|
717e403d
henyxia
Sperated output
|
96
97
|
fclose(logfiles[6]);
fclose(logfiles[7]);
|
ae25085d
henyxia
Output function done
|
98
99
|
}
|
297a72df
henyxia
Added sender
|
100
|
void printx(severity s, msgfrom from, char* str, ...)
|
ae25085d
henyxia
Output function done
|
101
|
{
|
19082eeb
henyxia
UI design not wor...
|
102
|
char buffer1[MAX_BUFFER];
|
ea1218f1
henyxia
UI finished
|
103
|
char buffer2[MAX_BUFFER];
|
ae25085d
henyxia
Output function done
|
104
|
va_list arglist;
|
ae25085d
henyxia
Output function done
|
105
|
va_start(arglist, str);
|
19082eeb
henyxia
UI design not wor...
|
106
|
vsprintf(buffer1, str, arglist);
|
b8e91a2f
henyxia
Displaying everyt...
|
107
|
gettimeofday(&tv,NULL);
|
c0152e3d
henyxia
Separated log files
|
108
109
|
fprintf(logfiles[from], "[%10ld.%06ld] : %s", tv.tv_sec, tv.tv_usec, buffer1);
fflush(logfiles[from]);
|
3bdc9daf
henyxia
NFC Added
|
110
|
sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET);
|
80e0082e
henyxia
Some fixes, separ...
|
111
112
|
if(s>DEBUG)
printf("%s", buffer2);
|
ae25085d
henyxia
Output function done
|
113
114
|
va_end(arglist);
}
|