core: client API Majestic, modèles et CLI check

- libopenpu : validation VIN, modèles JSON (getAvailableUpdate, devices),
  classification ecuType -> type/guide, sélection des mises à jour
- couche Transport abstraite + implémentation libcurl (proxy env, redirections,
  streaming, timeout d'inactivité)
- tolérance au EOF TLS sans close_notify de la passerelle Majestic, limitée
  aux corps délimités par la fermeture (ni Content-Length ni chunked)
- openpu-cli : check / raw-devices / raw-updates
- tests doctest (VIN, parsing, classification, client API avec faux transport),
  fixtures dont une capture réelle anonymisée (NAC wave 2)
- qualité : presets CMake (debug, asan, tidy), .clang-tidy, tools/check.sh
  (tests, ASan/UBSan, valgrind, clang-tidy, cppcheck)
- validé contre l'API réelle sur 3 véhicules (NAC w4, RCC, NAC w2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
yann64andClaude Opus 5.5 committed 2026-11-28 17:45:27 +01:00
1 parent 660a420a3e
commit 95704f9882
28 files changed
+1877 -2

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
add_executable(openpu-cli main.cpp)
target_link_libraries(openpu-cli PRIVATE openpu_core openpu_warnings)
install(TARGETS openpu-cli RUNTIME DESTINATION bin)
+109
View File
@@ -0,0 +1,109 @@
// openpu-cli — command-line front-end of libopenpu.
#include "openpu/api_client.hpp"
#include "openpu/vin.hpp"
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
namespace {
void usage()
{
std::cerr << "usage: openpu-cli [--verbose] <command> [args]\n"
"\n"
"commands:\n"
" check <VIN> identify the head unit and list available updates\n"
" raw-devices <VIN> print the raw devices/{VIN} response\n"
" raw-updates <VIN> print the raw getAvailableUpdate response (all software types)\n"
"\n"
"environment: OPENPU_DEVICES_URL, OPENPU_UPDATES_URL, OPENPU_CLIENT_ID,\n"
" http_proxy, https_proxy, no_proxy\n";
}
std::string humanSize(std::uint64_t bytes)
{
const char* units[] = {"B", "KB", "MB", "GB", "TB"};
auto value = static_cast<double>(bytes);
std::size_t unit = 0;
while (value >= 1000.0 && unit + 1 < std::size(units)) {
value /= 1000.0;
++unit;
}
char buf[32];
(void)std::snprintf(buf, sizeof buf, unit == 0 ? "%.0f %s" : "%.2f %s", value, units[unit]);
return buf;
}
void printUpdate(const char* label, const std::optional<openpu::UpdateInfo>& u)
{
if (!u) {
std::cout << label << ": none\n";
return;
}
std::cout << label << ": " << u->version << " (" << u->softwareType << ", " << humanSize(u->size)
<< ", " << (u->date.empty() ? "no date" : u->date) << ")\n";
}
int printRaw(const openpu::HttpResponse& r)
{
std::cerr << "HTTP " << r.status << '\n';
std::cout << r.body << '\n';
return r.status >= 200 && r.status < 300 ? 0 : 1;
}
} // namespace
int main(int argc, char** argv)
{
std::vector<std::string> args(argv + 1, argv + argc);
openpu::CurlOptions curlOptions;
if (!args.empty() && args.front() == "--verbose") {
curlOptions.verbose = true;
args.erase(args.begin());
}
if (args.size() != 2) {
usage();
return 2;
}
const std::string& command = args[0];
const std::string vin = openpu::normalizeVin(args[1]);
if (!openpu::isValidVin(vin)) {
std::cerr << "error: invalid VIN (expected V[FR]3 followed by 14 letters/digits)\n";
return 2;
}
auto transport = openpu::makeCurlTransport(curlOptions);
openpu::ApiClient api(*transport, openpu::ApiConfig::fromEnvironment());
try {
if (command == "raw-devices")
return printRaw(api.rawDevices(vin));
if (command == "raw-updates")
return printRaw(api.rawUpdates(vin, openpu::software::all()));
if (command != "check") {
usage();
return 2;
}
const openpu::VehicleCheck check = api.checkVehicle(vin);
if (!check.exists) {
std::cout << "vehicle not found\n";
return 1;
}
if (check.type == openpu::HeadUnitType::Unknown) {
std::cout << "vehicle found, but its head unit is not supported\n";
return 1;
}
std::cout << "head unit: " << openpu::headUnitTypeName(check.type) << "\nguide: " << check.guideKey << '\n';
const openpu::AvailableUpdates updates = api.getUpdates(vin, check.type);
printUpdate("firmware", updates.firmware);
printUpdate("map", updates.map);
return 0;
} catch (const openpu::ApiError& e) {
std::cerr << "error: " << e.what() << '\n';
return 1;
}
}