Rev 513 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
500 | Brean | 1 | #include "FlightLog.h" |
2 | //TODO: real logging with |
||
3 | // * more log levels (arent info, warning and error enough?) |
||
4 | // * logging in file |
||
5 | // * the current timestamp |
||
6 | // * normal difference between log and error messages |
||
7 | // * and so on |
||
8 | #include <iostream> |
||
9 | #include "Colors.h" |
||
10 | #include <string> |
||
11 | |||
12 | //#include <ctime> |
||
13 | #include <sys/time.h> |
||
14 | |||
15 | void print_data(char * data, std::string type, char * color) { |
||
513 | Brean | 16 | char buffer [20]; |
500 | Brean | 17 | timeval timestamp; |
18 | gettimeofday(×tamp, 0); |
||
524 | Brean | 19 | sprintf(buffer, "%i.%07i", timestamp.tv_sec, timestamp.tv_usec); |
513 | Brean | 20 | //alternative to show human readable output |
500 | Brean | 21 | /* |
22 | time_t rawtime; |
||
23 | struct tm * timeinfo; |
||
24 | time ( &rawtime ); |
||
25 | timeinfo = localtime ( &rawtime ); |
||
26 | |||
27 | strftime(buffer, 100, "%x %X", timeinfo); |
||
28 | */ |
||
29 | |||
30 | #ifdef USE_COLOR |
||
31 | std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl; |
||
32 | #else |
||
33 | std::cout << buffer << " " << type << ": " << data << std::endl; |
||
34 | #endif |
||
35 | } |
||
36 | |||
513 | Brean | 37 | void FlightLog::log_data(char * data, int length) { |
38 | printf("raw data:"); |
||
39 | for( int i = 0 ; i < length; i++ ){ |
||
40 | printf("%c", data[i]); |
||
41 | } |
||
42 | printf(" hex:"); |
||
524 | Brean | 43 | for( int i = 0 ; i < length ; i++ ){ |
44 | printf( "%02hhx " , data[i] ); |
||
513 | Brean | 45 | } |
46 | printf( "\n" ); |
||
47 | } |
||
48 | |||
500 | Brean | 49 | void FlightLog::info(char * data) { |
50 | print_data(data, "INFO", INFO_COLOR); |
||
51 | } |
||
52 | |||
513 | Brean | 53 | void FlightLog::info_FC(char * data) { |
54 | print_data(data, "INFO FC", INFO_FC_COLOR); |
||
55 | } |
||
56 | |||
57 | void FlightLog::info_NC(char * data) { |
||
58 | print_data(data, "INFO NC", INFO_NC_COLOR); |
||
59 | } |
||
60 | |||
61 | void FlightLog::info_GPS(char * data) { |
||
62 | print_data(data, "INFO GPS", INFO_GPS_COLOR); |
||
63 | } |
||
64 | |||
65 | void FlightLog::info_MK3(char * data) { |
||
66 | print_data(data, "INFO MK3", INFO_MK3_COLOR); |
||
67 | } |
||
68 | |||
500 | Brean | 69 | void FlightLog::warning(char * data) { |
70 | print_data(data, "WARNING", WARNING_COLOR); |
||
71 | } |
||
72 | |||
73 | void FlightLog::error(char * data) { |
||
74 | print_data(data, "ERROR", ERROR_COLOR); |
||
75 | } |