Subversion Repositories Projects

Rev

Rev 500 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "FlightLog.h"
//TODO: real logging with
//    * more log levels (arent info, warning and error enough?)
//    * logging in file
//    * the current timestamp
//    * normal difference between log and error messages
//    * and so on
#include <iostream>
#include "Colors.h"
#include <string>

//#include <ctime>
#include <sys/time.h>

void print_data(char * data, std::string type, char * color) {
    char buffer [20];
    timeval timestamp;
    gettimeofday(&timestamp, 0);
    sprintf(buffer, "%i.%03i", timestamp.tv_sec, (timestamp.tv_usec+500)/1000);
//alternative to show human readable output
/*
    time_t rawtime;
    struct tm * timeinfo;
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );

    strftime(buffer, 100, "%x %X", timeinfo);
*/


    #ifdef USE_COLOR
        std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl;
    #else
        std::cout  << buffer << " " << type << ": " << data << std::endl;
    #endif
}

void FlightLog::log_data(char * data, int length) {
    printf("raw data:");
    for( int i = 0 ; i < length; i++ ){
        printf("%c", data[i]);
    }
    printf(" hex:");
    for( int i = 0 ; i < length ; i++ ){
        printf( "%02hhx " , data[i] );
    }
    printf( "\n" );
}

void FlightLog::info(char * data) {
    print_data(data, "INFO", INFO_COLOR);
}

void FlightLog::info_FC(char * data) {
    print_data(data, "INFO FC", INFO_FC_COLOR);
}

void FlightLog::info_NC(char * data) {
    print_data(data, "INFO NC", INFO_NC_COLOR);
}

void FlightLog::info_GPS(char * data) {
    print_data(data, "INFO GPS", INFO_GPS_COLOR);
}

void FlightLog::info_MK3(char * data) {
    print_data(data, "INFO MK3", INFO_MK3_COLOR);
}

void FlightLog::warning(char * data) {
    print_data(data, "WARNING", WARNING_COLOR);
}

void FlightLog::error(char * data) {
    print_data(data, "ERROR", ERROR_COLOR);
}