Implement bfebbx: Betaflight blackbox extractor
Cross-platform (macOS + Linux) C++17 CLI that extracts a Betaflight FC's blackbox log in one command: auto-detect the serial port, read craft_name over the Betaflight CLI, send `msc` to reboot into USB mass storage, wait for the volume to mount, copy btfl_all.bbl to <craft_name>_<YYYYMMDD>_<HHMMSS>.bbl, and eject. Native throughout (termios serial, getmntinfo/proc-mounts mount detection, DiskArbitration/umount eject); the only subprocess is the Linux udisksctl eject fallback. Includes CMake/ctest build, unit tests for the pure logic (naming, craft_name parsing, mount diff, serial via pty, CLI parsing), README with a manual hardware integration procedure, and design/plan docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
tests/test_betaflight_proto.cpp
Normal file
38
tests/test_betaflight_proto.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "../src/betaflight.h"
|
||||
#include "../src/serial.h"
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <util.h>
|
||||
#else
|
||||
#include <pty.h>
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
using namespace bfebbx;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
int master = -1, slave = -1;
|
||||
assert(openpty(&master, &slave, nullptr, nullptr, nullptr) == 0);
|
||||
|
||||
// Set slave to raw mode to disable line-ending translation
|
||||
struct termios tio;
|
||||
assert(tcgetattr(slave, &tio) == 0);
|
||||
cfmakeraw(&tio);
|
||||
assert(tcsetattr(slave, TCSANOW, &tio) == 0);
|
||||
|
||||
// FC echoes the command then reports the value and a prompt.
|
||||
const char* canned = "# get craft_name\r\ncraft_name = TESTQUAD\r\n# ";
|
||||
ssize_t len = static_cast<ssize_t>(std::string(canned).size());
|
||||
assert(write(slave, canned, static_cast<size_t>(len)) == len);
|
||||
|
||||
Serial s = Serial::fromFd(master);
|
||||
auto name = getCraftName(s, 1000ms);
|
||||
assert(name.has_value());
|
||||
assert(name.value() == "TESTQUAD");
|
||||
|
||||
close(slave);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user