Skip to content

Commit

Permalink
logger: add a file magic
Browse files Browse the repository at this point in the history
  • Loading branch information
bkueng authored and LorenzMeier committed May 22, 2016
1 parent 5cf8081 commit 1719d9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/modules/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ enum class MessageType : uint8_t {

/* declare message data structs with byte alignment (no padding) */
#pragma pack(push, 1)

/** first bytes of the file */
struct message_file_header_s {
uint8_t magic[8];
uint64_t timestamp;
};

struct message_format_s {
uint8_t msg_type = static_cast<uint8_t>(MessageType::FORMAT);
uint16_t msg_size;
Expand Down Expand Up @@ -849,6 +856,7 @@ void Logger::start_log()
mavlink_log_info(&_mavlink_log_pub, "[logger] file: %s", file_name);

_writer.start_log(file_name);
write_header();
write_version();
write_formats();
write_parameters();
Expand Down Expand Up @@ -926,6 +934,23 @@ void Logger::write_info(const char *name, const char *value)
_writer.unlock();
}

void Logger::write_header()
{
message_file_header_s header;
header.magic[0] = 'U';
header.magic[1] = 'L';
header.magic[2] = 'o';
header.magic[3] = 'g';
header.magic[4] = 0x01;
header.magic[5] = 0x12;
header.magic[6] = 0x35;
header.magic[7] = 0x00; //file version 0
header.timestamp = hrt_absolute_time();
_writer.lock();
write_wait(&header, sizeof(header));
_writer.unlock();
}

/* write version info messages */
void Logger::write_version()
{
Expand Down
5 changes: 5 additions & 0 deletions src/modules/logger/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ class Logger

void stop_log();

/**
* write the file header with file magic and timestamp.
*/
void write_header();

void write_formats();

void write_version();
Expand Down

0 comments on commit 1719d9a

Please sign in to comment.