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

+105
View File
@@ -0,0 +1,105 @@
#pragma once
#include <cstdint>
#include <optional>
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>
namespace openpu {
/// Software types understood by the Majestic `getAvailableUpdate` endpoint.
namespace software {
inline constexpr std::string_view FirmwareNac = "ovip-int-firmware-version";
inline constexpr std::string_view FirmwareRcc = "rcc-firmware";
inline constexpr std::string_view FirmwareAio = "aio-firmware";
inline constexpr std::string_view CronyNav = "crony2-software-nav";
inline constexpr std::string_view CronyNonav = "crony2-software-nonav";
inline constexpr std::string_view MapEurope = "map-eur";
inline constexpr std::string_view MapCrony = "crony2-map-western_europe";
/// All software types, in the order used when probing a new vehicle.
const std::vector<std::string>& all();
} // namespace software
/// Head-unit family. String form matches the `type` field of the original vehicles.json.
enum class HeadUnitType { Unknown, Nac, Rcc, Aio, CronyNav, CronyNonav };
std::string_view headUnitTypeName(HeadUnitType type);
HeadUnitType headUnitTypeFromString(std::string_view s);
/// Thrown when a backend JSON document cannot be interpreted.
class ParseError : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
struct UpdateInfo {
std::string softwareType;
std::string updateId;
std::string version;
std::string date;
std::string url; ///< updateURL (redirects to the CDN)
std::string licenseUrl; ///< licenseURL (only meaningful for firmware)
std::uint64_t size = 0; ///< bytes, as announced by the backend
};
struct SoftwareEntry {
std::string softwareType;
std::string requestResult;
std::string currentVersion;
std::vector<UpdateInfo> updates;
};
struct UpdateListResponse {
std::string requestResult;
std::string installerUrl;
std::string vin;
std::vector<SoftwareEntry> software;
};
struct DevicesResponse {
std::string vin;
std::string requestDate;
std::vector<std::string> ecuTypes;
};
struct VehicleCheck {
bool exists = false;
HeadUnitType type = HeadUnitType::Unknown;
std::string guideKey; ///< i18n key of the installation guide (e.g. "path_guide_rcc"), may be empty
};
struct AvailableUpdates {
std::optional<UpdateInfo> firmware;
std::optional<UpdateInfo> map;
};
/// Firmware and (optional) map software types to request for a given head unit.
struct SoftwarePair {
std::string firmware;
std::optional<std::string> map;
};
SoftwarePair softwareTypesFor(HeadUnitType type);
UpdateListResponse parseUpdateList(std::string_view json);
DevicesResponse parseDevices(std::string_view json);
std::string buildUpdateRequest(std::string_view vin, const std::vector<std::string>& softwareTypes);
/// Head-unit family from an ECU type string such as "NAC_EU_WAVE4" (Unknown if unsupported).
HeadUnitType ecuFamily(std::string_view ecuType);
/// Reproduces the original vehicle check logic (devices + all-types update probe).
VehicleCheck classifyVehicle(const UpdateListResponse& updates, const DevicesResponse& devices);
/// Usable update of a given software type, if any.
std::optional<UpdateInfo> pickUpdate(const UpdateListResponse& response, std::string_view softwareType);
/// Firmware/map updates for a vehicle of the given type.
AvailableUpdates selectUpdates(const UpdateListResponse& response, HeadUnitType type);
/// Basic absolute http(s) URL check, equivalent to the `is-url` package for our needs.
bool isHttpUrl(std::string_view url);
} // namespace openpu