Blame view

printx.c 1.5 KB
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
  
80e0082e   henyxia   Some fixes, separ...
14
  FILE* logfiles[5] = {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"};
b8e91a2f   henyxia   Displaying everyt...
16
17
  char f_name[6][5] = {"MAIN", "UI  ", "NFC ", "HVC ", "BUS ", "TEMP"};
  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()
  {
b8e91a2f   henyxia   Displaying everyt...
30
31
  	//char	filename[FILENAME_LENGTH];
  	//time_t	now = time(NULL);
ae25085d   henyxia   Output function done
32
  
b8e91a2f   henyxia   Displaying everyt...
33
34
35
36
  	//strftime(filename, FILENAME_LENGTH, "%F-%T:%d", localtime(&now));
  	//setStartTime(filename);
  	//strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now));
  	//strcat(filename, ".log");
ae25085d   henyxia   Output function done
37
  
b8e91a2f   henyxia   Displaying everyt...
38
39
  	logfiles[5] = fopen("temp.log", "a");
  	if(logfiles[5] == NULL)
ae25085d   henyxia   Output function done
40
  	{
b8e91a2f   henyxia   Displaying everyt...
41
  		printf("Unable to open the temperature log file\n");
ae25085d   henyxia   Output function done
42
43
44
  		return false;
  	}
  
c21a2c16   henyxia   Re added timestam...
45
  
ae25085d   henyxia   Output function done
46
47
48
49
50
  	return true;
  }
  
  void closeLog()
  {
b8e91a2f   henyxia   Displaying everyt...
51
  	fclose(logfiles[5]);
ae25085d   henyxia   Output function done
52
53
  }
  
297a72df   henyxia   Added sender
54
  void printx(severity s, msgfrom from, char* str, ...)
ae25085d   henyxia   Output function done
55
  {
19082eeb   henyxia   UI design not wor...
56
  	char	buffer1[MAX_BUFFER];
ea1218f1   henyxia   UI finished
57
  	char	buffer2[MAX_BUFFER];
ae25085d   henyxia   Output function done
58
  	va_list	arglist;
ae25085d   henyxia   Output function done
59
  	va_start(arglist, str);
19082eeb   henyxia   UI design not wor...
60
  	vsprintf(buffer1, str, arglist);
b8e91a2f   henyxia   Displaying everyt...
61
62
63
  	gettimeofday(&tv,NULL);
  	fprintf(logfiles[5], "[%10ld] : %s", tv.tv_usec, buffer1);
  	fflush(logfiles[5]);
3bdc9daf   henyxia   NFC Added
64
  	sprintf(buffer2, "[%s] %s%s%s", f_name[from], s_color[s], buffer1, S_RESET);
80e0082e   henyxia   Some fixes, separ...
65
66
  	if(s>DEBUG)
  		printf("%s", buffer2);
ae25085d   henyxia   Output function done
67
68
  	va_end(arglist);
  }