-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtlog.h
More file actions
47 lines (39 loc) · 1.28 KB
/
tlog.h
File metadata and controls
47 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
per-connection MAVProxy-format tlog writer
on-disk format: a sequence of records, each
8-byte big-endian uint64 timestamp (microseconds since epoch)
raw MAVLink frame bytes
matches what pymavlink's mavlogfile reader and mavlogdump.py expect.
*/
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
class TlogWriter {
public:
TlogWriter() = default;
~TlogWriter();
TlogWriter(const TlogWriter &) = delete;
TlogWriter &operator=(const TlogWriter &) = delete;
/*
open logs/<port2>/<YYYY-MM-DD>/sessionN.tlog. The caller supplies
session_n via the shared next_session_n() helper so the paired
.tlog / .bin files for one child fork share their N. Creates parent
dirs as needed. Returns true on success.
*/
bool open(uint32_t port2, unsigned session_n,
const char *base_dir = "logs");
/*
write a complete MAVLink frame, prefixed with an 8-byte big-endian
microsecond timestamp from gettimeofday().
*/
void write_frame(const uint8_t *frame, size_t len);
/*
close: fflush + fsync + fclose. Safe to call multiple times; called
from the destructor.
*/
void close();
bool is_open() const { return fp != nullptr; }
private:
FILE *fp = nullptr;
};