Commit ae25085d7ecf0ae117b141181989d78c3cd3e365

Authored by henyxia
1 parent d3b85bf5

Output function done

README fixed
Makefile adapted
Showing 5 changed files with 76 additions and 19 deletions   Show diff stats
1 -CC= gcc  
2 -CC_FLAGS=-c -Wall -Werror -g  
3 -CC_LIBS=$(NFC_PROXMARK_LIB)  
4 -INCLUDES=-I../nfc_proxmark3_driver 1 +CC=gcc
  2 +CC_FLAGS=-c -Wall -Werror
  3 +CC_LIBS=
  4 +INCLUDES=
5 5
6 -SOURCES=main.c 6 +SOURCES=main.c printx.c
7 OBJECTS=$(SOURCES:.c=.o) 7 OBJECTS=$(SOURCES:.c=.o)
8 -NFC_PROXMARK_LIB=-L../nfc_proxmark3_driver -lnfcproxmark3driver  
9 OUTPUT=tweekd 8 OUTPUT=tweekd
10 9
11 all: $(SOURCES) $(OUTPUT) 10 all: $(SOURCES) $(OUTPUT)
@@ -14,7 +13,7 @@ $(OUTPUT): $(OBJECTS) @@ -14,7 +13,7 @@ $(OUTPUT): $(OBJECTS)
14 $(CC) $(OBJECTS) $(CC_LIBS) -o $@ 13 $(CC) $(OBJECTS) $(CC_LIBS) -o $@
15 14
16 %.o: %.c 15 %.o: %.c
17 - $(CC) -c $(INCLUDES) $(CC_FLAGS) $< -o $@ 16 + $(CC) $(INCLUDES) $(CC_FLAGS) $< -o $@
18 17
19 clear: 18 clear:
20 rm -f $(OUTPUT) $(OBJECTS) 19 rm -f $(OUTPUT) $(OBJECTS)
1 # tweekd 1 # tweekd
2 -Tweekd is a projet of an automated coffee dispenser 2 +Tweekd is a project of an automated coffee dispenser
1 #include <stdio.h> 1 #include <stdio.h>
2 -#include <version.h>  
3 -#include <transfer.h> 2 +#include "printx.h"
4 3
5 int main(void) 4 int main(void)
6 { 5 {
7 - printf("Tweekd starting\n");  
8 - if(initializeProxmark() != 0)  
9 - {  
10 - printf("Initialization failed\n");  
11 - return 1;  
12 - }  
13 - printf("[NFC]\t: HW version\n");  
14 - proxVersion();  
15 - stopProxmark(); 6 + initLog();
  7 + printx(INFO, "Tweekd starting\n");
  8 + closeLog();
16 return 0; 9 return 0;
17 } 10 }
printx.c 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <stdarg.h>
  4 +#include <stdbool.h>
  5 +#include <string.h>
  6 +#include <time.h>
  7 +#include "printx.h"
  8 +
  9 +#define FILENAME_LENGTH 24
  10 +#define S_RESET "\33[0m"
  11 +#define MAX_BUFFER 128
  12 +
  13 +FILE* logfile = NULL;
  14 +char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"};
  15 +
  16 +bool initLog()
  17 +{
  18 + char filename[FILENAME_LENGTH];
  19 + time_t now = time(NULL);
  20 +
  21 + strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now));
  22 + strcat(filename, ".log");
  23 +
  24 + logfile = fopen(filename, "w");
  25 + if(logfile == NULL)
  26 + {
  27 + printf("Unable to open the log file\n");
  28 + return false;
  29 + }
  30 +
  31 + return true;
  32 +}
  33 +
  34 +void closeLog()
  35 +{
  36 + fclose(logfile);
  37 +}
  38 +
  39 +void printx(severity s, char* str, ...)
  40 +{
  41 + char buffer[MAX_BUFFER];
  42 + va_list arglist;
  43 + va_start(arglist, str);
  44 + vsprintf(buffer, str, arglist);
  45 + fprintf(logfile, buffer);
  46 + printf(s_color[s]);
  47 + printf(buffer);
  48 + printf(S_RESET);
  49 + va_end(arglist);
  50 +}
printx.h 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +#ifndef __PRINTX_H__
  2 +#define __PRINTX_H__
  3 +
  4 +#include <stdbool.h>
  5 +
  6 +typedef enum
  7 +{
  8 + ERROR, WARNING, INFO, DEBUG
  9 +}severity;
  10 +
  11 +bool initLog();
  12 +void printx(severity, char*, ...);
  13 +void closeLog();
  14 +
  15 +#endif