mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-22 11:53:54 +08:00
* fix dangling pointer problem * logger_build_init_data() has same problem * return kj::Array<capnp::byte> * Revert "return kj::Array<capnp::byte>" This reverts commit 4df4685bfcaba0c5400e2690440a74c32ff75afa. * Empty commit,trigger Build * fix each segment in a route having a different initial logMonoTime
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
#include <assert.h>
|
|
#include <string>
|
|
#include <cstdio>
|
|
|
|
#include <bzlib.h>
|
|
|
|
#include "common/swaglog.h"
|
|
#include "common/util.h"
|
|
#include "messaging.hpp"
|
|
#include "logger.h"
|
|
|
|
int main(int argc, char** argv) {
|
|
char filename[64] = {'\0'};
|
|
|
|
time_t rawtime = time(NULL);
|
|
struct tm timeinfo;
|
|
|
|
localtime_r(&rawtime, &timeinfo);
|
|
strftime(filename, sizeof(filename),
|
|
"%Y-%m-%d--%H-%M-%S.bz2", &timeinfo);
|
|
|
|
std::string path = LOG_ROOT + "/boot/" + std::string(filename);
|
|
LOGW("bootlog to %s", path.c_str());
|
|
|
|
// Open bootlog
|
|
int r = logger_mkpath((char*)path.c_str());
|
|
assert(r == 0);
|
|
|
|
FILE * file = fopen(path.c_str(), "wb");
|
|
assert(file != nullptr);
|
|
|
|
// Open as bz2
|
|
int bzerror;
|
|
BZFILE* bz_file = BZ2_bzWriteOpen(&bzerror, file, 9, 0, 30);
|
|
assert(bzerror == BZ_OK);
|
|
|
|
// Write initdata
|
|
kj::Array<capnp::word> init_msg = logger_build_init_data();
|
|
auto bytes = init_msg.asBytes();
|
|
BZ2_bzWrite(&bzerror, bz_file, bytes.begin(), bytes.size());
|
|
assert(bzerror == BZ_OK);
|
|
|
|
// Write bootlog
|
|
kj::Array<capnp::word> boot_msg = logger_build_boot();
|
|
bytes = boot_msg.asBytes();
|
|
BZ2_bzWrite(&bzerror, bz_file, bytes.begin(), bytes.size());
|
|
assert(bzerror == BZ_OK);
|
|
|
|
// Close bz2 and file
|
|
BZ2_bzWriteClose(&bzerror, bz_file, 0, NULL, NULL);
|
|
assert(bzerror == BZ_OK);
|
|
|
|
fclose(file);
|
|
return 0;
|
|
}
|