// SPDX-License-Identifier: MIT #pragma once #include #include #include #include #include #include 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& 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 updates; }; struct UpdateListResponse { std::string requestResult; std::string installerUrl; std::string vin; std::vector software; }; struct DevicesResponse { std::string vin; std::string requestDate; std::vector 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 firmware; std::optional map; }; /// Firmware and (optional) map software types to request for a given head unit. struct SoftwarePair { std::string firmware; std::optional 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& 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 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