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>
34 lines
823 B
C++
34 lines
823 B
C++
#include "../src/serial.h"
|
|
#include <cassert>
|
|
#include <chrono>
|
|
#include <string>
|
|
#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);
|
|
|
|
// Pre-load a canned response into the master's read buffer.
|
|
const char* resp = "hello world#";
|
|
assert(write(slave, resp, 12) == 12);
|
|
|
|
Serial s = Serial::fromFd(master);
|
|
std::string got = s.readUntil("#", 1000ms);
|
|
assert(got == "hello world#");
|
|
|
|
// Timeout path: nothing more to read, returns what it has within the window.
|
|
std::string none = s.readUntil("#", 100ms);
|
|
assert(none.empty());
|
|
|
|
close(slave);
|
|
return 0;
|
|
}
|