Rev 500 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 500 | Rev 513 | ||
---|---|---|---|
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 [100]; |
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.%03i", timestamp.tv_sec, (timestamp.tv_usec+500)/1000); |
- | 20 | //alternative to show human readable output |
|
20 | /* |
21 | /* |
21 | time_t rawtime; |
22 | time_t rawtime; |
22 | struct tm * timeinfo; |
23 | struct tm * timeinfo; |
23 | time ( &rawtime ); |
24 | time ( &rawtime ); |
24 | timeinfo = localtime ( &rawtime ); |
25 | timeinfo = localtime ( &rawtime ); |
25 | 26 | ||
26 | strftime(buffer, 100, "%x %X", timeinfo); |
27 | strftime(buffer, 100, "%x %X", timeinfo); |
27 | */ |
28 | */ |
28 | 29 | ||
29 | #ifdef USE_COLOR |
30 | #ifdef USE_COLOR |
30 | std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl; |
31 | std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl; |
31 | #else |
32 | #else |
32 | std::cout << buffer << " " << type << ": " << data << std::endl; |
33 | std::cout << buffer << " " << type << ": " << data << std::endl; |
33 | #endif |
34 | #endif |
34 | } |
35 | } |
- | 36 | ||
- | 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:"); |
|
- | 43 | for( int i = 0 ; i < length ; i++ ){ |
|
- | 44 | printf( "%02hhx " , data[i] ); |
|
- | 45 | } |
|
- | 46 | printf( "\n" ); |
|
- | 47 | } |
|
35 | 48 | ||
36 | void FlightLog::info(char * data) { |
49 | void FlightLog::info(char * data) { |
37 | print_data(data, "INFO", INFO_COLOR); |
50 | print_data(data, "INFO", INFO_COLOR); |
38 | } |
51 | } |
- | 52 | ||
- | 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 | } |
|
39 | 68 | ||
40 | void FlightLog::warning(char * data) { |
69 | void FlightLog::warning(char * data) { |
41 | print_data(data, "WARNING", WARNING_COLOR); |
70 | print_data(data, "WARNING", WARNING_COLOR); |
42 | } |
71 | } |
43 | 72 | ||
44 | void FlightLog::error(char * data) { |
73 | void FlightLog::error(char * data) { |
45 | print_data(data, "ERROR", ERROR_COLOR); |
74 | print_data(data, "ERROR", ERROR_COLOR); |
46 | } |
75 | } |