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