diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 748a794..779911e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -11,7 +11,7 @@ body: attributes: label: Project version description: The release you installed, or the commit you built. - placeholder: 0.12.1-rc.4 + placeholder: 0.13.0-rc.1 validations: required: true - type: input diff --git a/CHANGELOG.md b/CHANGELOG.md index 3da6cf0..cc8163f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,36 @@ QEMU avec les bibliothèques de la voiture). ## [Non publié] +## [0.13.0-rc.1] - 2026-11-15 · PC + +Version candidate : la touche MAP vers la navigation d'Android Auto, les MINI reconnues (marque et écran rond), le +volume et la sourdine comme l'iDrive, en plus des corrections des 0.12.1-rc.1 à rc.4. Testée sur PC et sous QEMU, +**pas encore essayée en voiture** ; une BMW reçoit la même description de voiture qu'avant. + +### Ajouté + +- La touche MAP ouvre la navigation d'Android Auto quand il est à l'écran, comme NAV, au lieu de rendre l'écran à la + carte BMW ; c'est ce que fait l'iDrive avec CarPlay. Seules MENU et OPTION quittent Android Auto + ([#1](https://github.com/Jiraiya43/EntryNav2-Android-Auto/issues/1)). +- MINI : la marque codée dans l'iDrive est lue au démarrage ; une MINI s'annonce « MINI » au téléphone et non plus + « BMW ». Son écran est encadré par un rond qui en cache les bords : le téléphone garde ses boutons hors de 40 colonnes + de chaque côté sur un écran de 1280 de large, 25 sur 800 ([#56](https://github.com/Jiraiya43/EntryNav2-Android-Auto/issues/56), + [#64](https://github.com/Jiraiya43/EntryNav2-Android-Auto/issues/64), [#78](https://github.com/Jiraiya43/EntryNav2-Android-Auto/issues/78)). +- Sourdine sur la pastille du volume : l'appui sur le bouton du volume la bascule dans l'iDrive, un cran de volume la + lève ; la pastille montre le haut-parleur barré. +- Image cassée après une image vidéo perdue : la session redemande une image complète au téléphone, pas dans les + 5 premières secondes de la vidéo et au plus une fois par 10 s. + +### Corrigé + +- Pastille du volume ouverte seule à la connexion, barre vide : la voiture envoie aussi le niveau d'une autre source + (minimum au-dessus de 0), et le même niveau plusieurs fois. Seul le volume de la molette ouvre la pastille, sur un + changement ou juste après une touche de volume, comme la barre de l'iDrive ([#56](https://github.com/Jiraiya43/EntryNav2-Android-Auto/issues/56)). +- Flux chiffré cassé : après 16 trames d'affilée qui ne se déchiffrent pas, la session se termine au lieu de garder + une image figée jusqu'à la limite de silence. +- Journal `[WifiLink]` : plus de faux « signal 0 dBm » (niveau non mesuré par la puce) ni de débit vers le téléphone, + que le pilote ne connaît pas (il donnait 1 Mbit/s partout). + ## [0.12.1-rc.4] - 2026-11-14 · PC Version candidate, pour faire essayer le double appui sur MEDIA après une autre touche sur l'ancien contrôleur (F20 @@ -291,7 +321,8 @@ Première version publique. Essayée sur une BMW G20 de 2019, logiciel iDrive `2 encore suivie sur une voiture. - Voir les [limites connues](ROADMAP.md#limites-connues). -[Non publié]: https://github.com/Jiraiya43/EntryNav2-Android-Auto/compare/v0.12.1-rc.4...HEAD +[Non publié]: https://github.com/Jiraiya43/EntryNav2-Android-Auto/compare/v0.13.0-rc.1...HEAD +[0.13.0-rc.1]: https://github.com/Jiraiya43/EntryNav2-Android-Auto/releases/tag/v0.13.0-rc.1 [0.12.1-rc.4]: https://github.com/Jiraiya43/EntryNav2-Android-Auto/releases/tag/v0.12.1-rc.4 [0.12.1-rc.3]: https://github.com/Jiraiya43/EntryNav2-Android-Auto/releases/tag/v0.12.1-rc.3 [0.12.1-rc.2]: https://github.com/Jiraiya43/EntryNav2-Android-Auto/releases/tag/v0.12.1-rc.2 diff --git a/Makefile b/Makefile index f7af272..a197b08 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ aa-supervisor: $(SUPERVISOR_OBJ) # iDrive PluginApp (installed in /opt/hmi/data/ro/Plugins/EntryAad, loaded by HmiMain3D at boot). Its objects are # position independent and hidden: HmiMain3D only looks up pluginAppInfo, the one symbol the library exports. HMI_SRC = hmiapp/entry_aa_app.cpp hmiapp/bmw_framework.cpp hmiapp/app_log.cpp hmiapp/app_guards.cpp \ - hmiapp/service_link.cpp hmiapp/car_signals.cpp hmiapp/hold_machine.cpp hmiapp/controller_coding.cpp + hmiapp/service_link.cpp hmiapp/car_signals.cpp hmiapp/hold_machine.cpp hmiapp/idrive_coding.cpp HMI_OBJ = $(HMI_SRC:.cpp=.o) HMI_LIBDIRS = -L$(SYSROOT)/opt/hmi/lib -Wl,-rpath-link,$(SYSROOT)/opt/hmi/lib hmiapp: hmiapp/libEntryAad.so @@ -159,6 +159,8 @@ test-host: test-parsers test-spp-host test-kombi-host test-gps-host test-capture ./tests/test-evo-control $(HOST_CXX) $(HOST_FLAGS) tests/test_peek_timing.cpp platform/peek_timing.cpp -o tests/test-peek-timing ./tests/test-peek-timing + $(HOST_CXX) $(HOST_FLAGS) tests/test_volume_state.cpp -o tests/test-volume-state + ./tests/test-volume-state $(HOST_CXX) $(HOST_FLAGS) -Icore/include tests/test_sdr_g20.cpp core/sdr_builder.cpp platform/evo_sdr_sensors.cpp -o tests/test-sdr-g20 ./tests/test-sdr-g20 $(HOST_CXX) $(HOST_FLAGS) -Icore/include tests/test_evo_sdr.cpp core/sdr_builder.cpp platform/evo_sdr_sensors.cpp -o tests/test-evo-sdr diff --git a/ROADMAP.md b/ROADMAP.md index 03a44bd..b969217 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -42,7 +42,6 @@ Un point n'est coché qu'avec une preuve en voiture : un test sur PC ne suffit p | Limite | Cause | Piste | |---|---|---| -| La touche MAP ouvre la carte BMW, pas la navigation d'Android Auto | choix actuel : MAP rend l'écran à l'iDrive | à décider | | Le son passe par le Bluetooth de la voiture : qualité limitée, débuts de messages vocaux coupés | pas de son par le Wi-Fi | son par le Wi-Fi | | Aide au stationnement ouverte sans marche arrière : Android Auto reste en retrait jusqu'à « Ouvrir » | l'écran affiché par l'iDrive n'est pas connu | lire l'état du PDC | | Pendant un appel, la molette agit aussi sur l'écran d'appel de l'iDrive | idem | lire l'écran affiché par l'iDrive | diff --git a/VERSION b/VERSION index ea84728..8eeb28d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.12.1-rc.4 +0.13.0-rc.1 diff --git a/core/aa_channels.cpp b/core/aa_channels.cpp index 260d9b8..2b52298 100644 --- a/core/aa_channels.cpp +++ b/core/aa_channels.cpp @@ -173,8 +173,8 @@ void AASession::onTlsHandshake(const Message& message) { // The description of this car: Google's Desktop Head Unit template, adapted by core/sdr_builder.cpp. void AASession::onDiscovery() { printf("[AASession] >>> Received ServiceDiscoveryRequest from phone! Sending ServiceDiscoveryResponse...\n"); - const Message response = message::discoveryResponse( - buildCarServiceDiscovery(kDhuSdpProtobuf, kDhuSdpProtobufLen, vehicleFile_, softwareVersion_, display_)); + const Message response = message::discoveryResponse(buildCarServiceDiscovery( + kDhuSdpProtobuf, kDhuSdpProtobufLen, vehicleFile_, softwareVersion_, display_, carMake_)); if (sendSealed(channel::kControl, response)) { printf("[AASession] >>> Sent ServiceDiscoveryResponse (%u bytes)\n", static_cast(response.size())); } @@ -253,6 +253,7 @@ void AASession::onSetup(uint8_t channel) { if (channel == channel::kVideo) { sendVideoFocus(true, false); videoReady_ = true; + keyframe_.videoStarted(locationClockMs()); } } diff --git a/core/aa_session.cpp b/core/aa_session.cpp index c2c0f21..9cb48f0 100644 --- a/core/aa_session.cpp +++ b/core/aa_session.cpp @@ -37,6 +37,9 @@ const unsigned kFramesLoggedEvery = 300; const unsigned kKeysLogged = 200; // evo_knob logs every key anyway const unsigned kMovesLogged = 40; const unsigned kMicrophoneLogEvery = 250; +// Encrypted frames in a row that do not decrypt: the TLS stream is broken (a record lost or cut on the way), and no +// later frame will decrypt either. The session ends rather than wait for the silence limit with a frozen picture. +const unsigned kUnreadableLimit = 16; const int kTouchMove = 2; uint64_t monotonicUs() { @@ -61,9 +64,12 @@ AASession::AASession() thread_(0), vehicleFile_(nullptr), softwareVersion_(nullptr), + carMake_(nullptr), longestSilenceMs_(0), lastReceivedMs_(0), videoReady_(false), + projected_(false), + unreadableInARow_(0), mediaMessages_(0), microphoneChunks_(0) { pthread_mutex_init(&lifecycleLock_, nullptr); @@ -125,6 +131,10 @@ void AASession::postVideoFocus(bool projected) { inbox_.postFocus(projected); } +void AASession::postKeyframeRequest() { + inbox_.postKeyframeRequest(); +} + void AASession::postNightMode(bool night) { inbox_.postNight(night); } @@ -211,6 +221,9 @@ bool AASession::start(int client_fd) { assembler_.clear(); inbox_.reset(); videoReady_ = false; + projected_ = false; + keyframe_.reset(); + unreadableInARow_ = 0; microphoneChunks_ = 0; mediaMessages_ = 0; memset(mediaSessions_, 0, sizeof(mediaSessions_)); @@ -441,7 +454,14 @@ AASession::Received AASession::receive(uint8_t& channel, Message& message) { } else if (!tls_.open(&payload[0], payload.size(), plain)) { printf("[AASession] Failed to decrypt encrypted frame (%u bytes).\n", header.length); assembler_.drop(channel); + if (++unreadableInARow_ >= kUnreadableLimit) { + printf("[AASession] %u encrypted frames in a row did not decrypt: the stream is broken, session ends.\n", + unreadableInARow_); + return kLost; + } return kNothing; + } else { + unreadableInARow_ = 0; } switch (assembler_.add(header, plain, message)) { case MessageAssembler::kComplete: @@ -497,6 +517,9 @@ void AASession::sendCarInput() { printf("[AASession] video focus -> phone: %s (unrequested) %s\n", projected ? "FOCUSED/projected" : "UNFOCUSED/native", sent ? "sent" : "SEND FAILED"); } + if (batch.keyframe) { + askKeyframe(); + } for (size_t i = 0; i < batch.keys.size(); ++i) { const CarKey& key = batch.keys[i]; const Message event = key.rotary ? message::rotaryEvent(monotonicUs(), key.keycode, key.delta) @@ -566,10 +589,22 @@ bool AASession::sendSensorEvent(uint32_t type) { bool AASession::sendVideoFocus(bool projected, bool unrequested) { const bool sent = sendSealed(channel::kVideo, message::videoFocusIndication(projected, unrequested)); if (sent) { + projected_ = projected; printf("[AASession] >>> Sent VideoFocusIndication (%s%s) on Channel %u!\n", projected ? "FOCUSED" : "UNFOCUSED", unrequested ? ", unrequested" : "", channel::kVideo); } return sent; } +// A lost frame leaves the picture broken until the phone's next keyframe: the focus is taken away and given back at +// once, which restarts the phone's encoder with one (keyframe_request.hpp). Only while the picture is projected. +void AASession::askKeyframe() { + if (!videoReady_ || !projected_ || !keyframe_.allow(locationClockMs())) { + return; + } + const bool sent = sendVideoFocus(false, true) && sendVideoFocus(true, true); + printf("[AASession] video frame lost: keyframe asked of the phone (focus off and on) %s\n", + sent ? "sent" : "SEND FAILED"); +} + } // namespace aa diff --git a/core/aa_session.hpp b/core/aa_session.hpp index e814257..84f36e2 100644 --- a/core/aa_session.hpp +++ b/core/aa_session.hpp @@ -17,6 +17,7 @@ #include "car_inbox.hpp" #include "car_location.hpp" #include "display_plan.hpp" +#include "keyframe_request.hpp" namespace aa { @@ -65,6 +66,8 @@ class AASession { void setSoftwareVersion(const char* version) { softwareVersion_ = version; } // The panel and the canvas asked of the phone for it (display_plan.hpp). The reference car's by default. void setDisplay(const DisplayPlan& display) { display_ = display; } + // The maker announced to the phone, as iDrive is coded ("MINI"); kept by the caller. Null: "BMW". + void setCarMake(const char* make) { carMake_ = make; } // Car input for the phone, from any thread: queued, then sent by the session thread. void postTouchEvent(const TouchEventOut& ev); @@ -72,6 +75,8 @@ class AASession { void postRelativeEvent(uint32_t keycode, int delta); // rotary steps (keycode 65536, ROTARY_CONTROLLER) // The car takes (false) or gives back (true) the screen: an unrequested video focus indication. void postVideoFocus(bool projected); + // The decoder lost a video frame. Any thread; the session asks the phone for a keyframe when it may. + void postKeyframeRequest(); // The car's day or night, kept across sessions: a NIGHT_MODE event once the phone started that sensor. void postNightMode(bool night); // The car's latest fix (monotonic capture time); an invalid one when the car's feed expired. @@ -114,6 +119,7 @@ class AASession { bool sendLocation(); bool sendSensorEvent(uint32_t type); bool sendVideoFocus(bool projected, bool unrequested); + void askKeyframe(); // One handler per route (aa_channels.cpp); dispatch() is false when the session must end. bool dispatch(uint8_t channel, const Message& message); @@ -150,6 +156,7 @@ class AASession { Callback navigation_; const char* vehicleFile_; const char* softwareVersion_; + const char* carMake_; DisplayPlan display_; CarInbox inbox_; @@ -158,7 +165,10 @@ class AASession { uint64_t lastReceivedMs_; // when the phone last sent anything, 0 before its first byte TlsClient tls_; MessageAssembler assembler_; - bool videoReady_; // the phone set the video channel up: a focus can go + bool videoReady_; // the phone set the video channel up: a focus can go + bool projected_; // the last video focus sent was FOCUSED + KeyframeRequest keyframe_; + unsigned unreadableInARow_; // encrypted frames that did not decrypt since the last one that did uint32_t mediaSessions_[32]; // per channel, the session id of its start indication, echoed in our acks uint32_t mediaMessages_; // media messages received, every channel uint32_t audioMessages_[2]; // guidance (8), media (9) diff --git a/core/car_inbox.cpp b/core/car_inbox.cpp index 8fbe0ee..4276934 100644 --- a/core/car_inbox.cpp +++ b/core/car_inbox.cpp @@ -32,6 +32,7 @@ CarInbox::CarInbox() keyDrops_(0), rotaryDrops_(0), focus_(kFocusNone), + keyframe_(false), night_(-1), nightStarted_(false), nightChanged_(false), @@ -134,6 +135,18 @@ void CarInbox::postFocus(bool projected) { wake(); } +void CarInbox::postKeyframeRequest() { + bool first; + { + MutexLock lock(mutex_); + first = !keyframe_; + keyframe_ = true; + } + if (first) { // a stalled decoder loses frame after frame: one wake is enough + wake(); + } +} + void CarInbox::postNight(bool night) { bool due; { @@ -188,6 +201,8 @@ void CarInbox::take(CarBatch& batch) { batch.keys.swap(keys_); batch.focus = focus_; focus_ = kFocusNone; + batch.keyframe = keyframe_; + keyframe_ = false; batch.nightChanged = nightChanged_ && nightStarted_; nightChanged_ = false; batch.microphone.swap(microphone_); @@ -248,6 +263,7 @@ void CarInbox::reset() { keys_.clear(); keyDrops_ = rotaryDrops_ = 0; focus_ = kFocusNone; + keyframe_ = false; nightStarted_ = nightChanged_ = false; location_.reset(); microphoneOpen_ = false; diff --git a/core/car_inbox.hpp b/core/car_inbox.hpp index 9bb2000..78eeac6 100644 --- a/core/car_inbox.hpp +++ b/core/car_inbox.hpp @@ -30,6 +30,7 @@ struct CarBatch { std::vector touches; std::vector keys; FocusRequest focus; + bool keyframe; // the decoder lost a video frame since the last turn bool nightChanged; // the phone started night mode and the car changed since the last event std::vector> microphone; }; @@ -50,6 +51,7 @@ class CarInbox { void postKey(uint32_t keycode, bool down); void postRotary(uint32_t keycode, int delta); void postFocus(bool projected); + void postKeyframeRequest(); // a video frame was lost: the session decides whether to ask the phone void postNight(bool night); // kept across sessions void postLocation(const CarLocation& location); void postMicrophone(const uint8_t* pcm, size_t size); @@ -83,6 +85,7 @@ class CarInbox { std::vector keys_; unsigned keyDrops_, rotaryDrops_; FocusRequest focus_; + bool keyframe_; int night_; bool nightStarted_, nightChanged_; LocationFeed location_; diff --git a/core/display_plan.hpp b/core/display_plan.hpp index a278004..9130666 100644 --- a/core/display_plan.hpp +++ b/core/display_plan.hpp @@ -6,6 +6,8 @@ // asked for; the phone is told to keep its UI in the top-left part the panel shows (insets, core/sdr_builder.cpp), // and the video surface shows that part only (platform/evo_video.cpp). The reference car is one case of the rule: a // 1280x480 panel in the 1280x720 canvas, its top 480 rows shown. +// A panel partly hidden by its surround (the MINI's round one, platform/car_brand.hpp) keeps the whole picture; the +// phone is only told to keep its UI away from the hidden sides. #ifndef ENTRY_AAD_CORE_DISPLAY_PLAN_HPP #define ENTRY_AAD_CORE_DISPLAY_PLAN_HPP @@ -17,10 +19,12 @@ struct DisplayPlan { uint32_t width, height; // the panel, and the part of the canvas that is shown uint32_t canvasWidth, canvasHeight; // what the phone streams uint32_t resolution; // the canvas as the protocol numbers it: 1, 2 or 3 + uint32_t hiddenSide; // panel columns hidden on each side by the surround // The reference car. - DisplayPlan() : width(1280), height(480), canvasWidth(1280), canvasHeight(720), resolution(2) {} + DisplayPlan() : width(1280), height(480), canvasWidth(1280), canvasHeight(720), resolution(2), hiddenSide(0) {} uint32_t bottomInset() const { return canvasHeight - height; } - uint32_t rightInset() const { return canvasWidth - width; } + uint32_t leftInset() const { return hiddenSide; } + uint32_t rightInset() const { return canvasWidth - width + hiddenSide; } bool reference() const { return width == 1280 && height == 480; } }; @@ -37,6 +41,7 @@ inline bool planDisplay(uint32_t panelWidth, uint32_t panelHeight, DisplayPlan& out.canvasWidth = kCanvas[i][0]; out.canvasHeight = kCanvas[i][1]; out.resolution = i + 1; + out.hiddenSide = 0; return true; } } diff --git a/core/keyframe_request.hpp b/core/keyframe_request.hpp new file mode 100644 index 0000000..3e9859b --- /dev/null +++ b/core/keyframe_request.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2026 Jiraiya43 +// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 +// When the head unit may ask the phone for a new keyframe after the decoder lost a video frame. +#ifndef ENTRY_AAD_CORE_KEYFRAME_REQUEST_HPP +#define ENTRY_AAD_CORE_KEYFRAME_REQUEST_HPP + +#include + +namespace aa { + +// H.264 frames between two keyframes refer to the ones before them: once one is lost, the picture stays broken +// until the phone's next keyframe, which can be seconds away. Android Auto has no message to ask for one, but a +// phone that gets the video focus back starts its encoder again with a keyframe; the session takes the focus away +// and gives it back at once (aa_session.cpp). +// Not during the first seconds of the video, when the phone's own keyframes are still coming, and seldom: a decoder +// short of buffers would otherwise turn every frame into a keyframe, each one larger than the frames it replaces. +// Session thread only; the clock is the caller's, in milliseconds. +class KeyframeRequest { +public: + static const uint64_t kSettleMs = 5000; // after the video was set up + static const uint64_t kSpacingMs = 10000; // between two requests + + KeyframeRequest() : videoSinceMs_(0), lastMs_(0), video_(false), asked_(false) {} + + // The phone set the video channel up: a new stream, nothing asked yet. + void videoStarted(uint64_t nowMs) { + video_ = true; + videoSinceMs_ = nowMs; + asked_ = false; + } + // A new session. + void reset() { video_ = asked_ = false; } + // A frame was lost: true when a request may go now, and it then counts as made. + bool allow(uint64_t nowMs) { + if (!video_ || nowMs - videoSinceMs_ < kSettleMs || (asked_ && nowMs - lastMs_ < kSpacingMs)) { + return false; + } + asked_ = true; + lastMs_ = nowMs; + return true; + } + +private: + uint64_t videoSinceMs_, lastMs_; + bool video_, asked_; +}; + +} // namespace aa + +#endif // ENTRY_AAD_CORE_KEYFRAME_REQUEST_HPP diff --git a/core/sdr_builder.cpp b/core/sdr_builder.cpp index 8d6afad..46755e7 100644 --- a/core/sdr_builder.cpp +++ b/core/sdr_builder.cpp @@ -128,9 +128,9 @@ bool tuneVideoConfig(const pb::Field& config, Bytes& out, const DisplayPlan& dis return false; } Bytes insets; - pb::appendUint(insets, 1, 0); + pb::appendUint(insets, 1, 0); // top pb::appendUint(insets, 2, display.bottomInset()); - pb::appendUint(insets, 3, 0); + pb::appendUint(insets, 3, display.leftInset()); pb::appendUint(insets, 4, display.rightInset()); Bytes rebuilt; pb::appendMessage(rebuilt, kInsetsField, insets); @@ -318,11 +318,15 @@ void setDiscoveryTrim(DiscoveryTrim trim) { } std::vector buildCarServiceDiscovery(const uint8_t* base, size_t baseLen, const char* vehicleFile, - const char* softwareVersion, const DisplayPlan& display) { + const char* softwareVersion, const DisplayPlan& display, + const char* make) { SdrIdentity identity; if (vehicleFile) { identity.loadVehicleFile(vehicleFile); } + if (make && *make) { + identity.carMake = identity.huMake = make; + } if (softwareVersion && *softwareVersion) { identity.swVersion = softwareVersion; } diff --git a/core/sdr_builder.hpp b/core/sdr_builder.hpp index 34d7f3f..ae53b03 100644 --- a/core/sdr_builder.hpp +++ b/core/sdr_builder.hpp @@ -53,9 +53,11 @@ void setDiscoveryTrim(DiscoveryTrim trim); // What the phone is told about this car: the template adapted by every step above. vehicleFile: the model // and year (SdrIdentity::loadVehicleFile), given by the platform; null keeps the default ones. softwareVersion: the // version of the program, announced as the head unit's software version; null keeps "0.0.0". display: the panel -// and the canvas chosen for it; the reference car's when not given. +// and the canvas chosen for it; the reference car's when not given. make: the car's and the head unit's maker as +// iDrive is coded ("MINI"); null keeps "BMW". std::vector buildCarServiceDiscovery(const uint8_t* base, size_t baseLen, const char* vehicleFile, - const char* softwareVersion, const DisplayPlan& display = DisplayPlan()); + const char* softwareVersion, const DisplayPlan& display = DisplayPlan(), + const char* make = nullptr); } // namespace aa diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 2d92921..f09035a 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -42,6 +42,7 @@ Le protocole Android Auto côté voiture, sans rien de propre à BMW. | `car_location.hpp` | Position de la voiture vers le capteur Android Auto | | `crash_handler` | Trace d'un plantage, puis le nettoyage enregistré par la plateforme | | `display_plan.hpp` | Image demandée au téléphone selon la taille de l'écran, et zone montrée | +| `keyframe_request.hpp` | Image vidéo perdue : quand redemander une image complète au téléphone (pas dans les 5 premières secondes, au plus une fois par 10 s) | | `include/` | Modèle de description de la voiture, certificat de l'unité | ## `platform/` : l'EntryNav2 @@ -57,11 +58,13 @@ Le protocole Android Auto côté voiture, sans rien de propre à BMW. | `service_contract.hpp` | Chemins et nom du canal de commande partagés par l'appli iDrive, le superviseur et le service | | `evo_video`, `evo_ilm`, `omap_dmabuf` | Décodage et affichage de la vidéo, gestion de sa couche | | `evo_pill`, `volume_pill.hpp` | Pastille du volume au-dessus d'Android Auto : client Wayland, dessin | +| `volume_state.hpp` | Ce que montre la pastille, comme la barre de l'iDrive : niveau de l'écran avant, changement ou touche de volume, sourdine par le bouton audio | | `evo_knob`, `evo_touch`, `input_mode.hpp` | Entrées : molette, touches, tactile | | `media_recall.hpp` | Double appui sur MEDIA : geste, conditions, demande à usage unique lue par l'appli de l'iDrive | | `vmost_client` | Accès au bus vMOST de la voiture (molette, touches, Wi-Fi), chargé à l'exécution | | `evo_ccs.hpp`, `evo_touch_frame.hpp` | Messages de la molette BMW (deux générations de contrôleur) et trames du tactile | | `controller_layout.hpp` | Quelle touche est chaque bouton, selon le codage de la voiture, comme l'iDrive (contrôleur type G ou F) | +| `car_brand.hpp` | Marque codée dans l'iDrive (BMW ou MINI) : marque annoncée au téléphone, bords de l'écran cachés par le rond des MINI | | `evo_gps` | Lecture passive du GPS de la voiture | | `evo_mic` | Micro de la voiture pour l'Assistant | | `evo_wlan`, `evo_ap` | Wi-Fi de la voiture, allumé comme le fait CarPlay | @@ -88,7 +91,7 @@ Le protocole Android Auto côté voiture, sans rien de propre à BMW. | `pending_restart.hpp` | Redémarrage d'Android Auto quand la case du câble USB change en marche (testé sur PC) | | `service_link` | Lancement du superviseur, commandes au service, arrêt | | `car_signals` | Marche arrière, appels, jour et nuit, mode de conduite, lus dans l'iDrive | -| `controller_coding` | Codage des touches de la voiture, lu dans l'iDrive au démarrage de l'appli, écrit pour le service | +| `idrive_coding` | Codage de la voiture lu dans l'iDrive au démarrage de l'appli et écrit pour le service : touches du contrôleur, marque (BMW ou MINI) | | `app_guards` | Interrupteur, garde-fou contre les plantages, démarrage automatique | | `app_log`, `log_profile.hpp` | Journal de l'appli, profil maintenance | | `popup_peek.hpp`, `cds_parse.hpp` | Fenêtres de l'iDrive par-dessus Android Auto, lecture des données de l'iDrive | @@ -114,6 +117,7 @@ Le protocole Android Auto côté voiture, sans rien de propre à BMW. | `tests/test_wireless_phone.cpp` | Échange Bluetooth du Wi-Fi, octet par octet, comparé à un relevé figé | | `tests/test_kombi_golden.cpp` | Chaque trame envoyée au compteur, octet par octet, comparée à un relevé figé | | `tests/test_peek_timing.cpp`, `tests/test_wireless_lifecycle.cpp` | Effacement de l'image, cycle de vie Bluetooth puis Wi-Fi du service | +| `tests/test_volume_state.cpp` | Pastille du volume : niveau d'une autre source ignoré, répétitions, touches, sourdine | | `tests/test_wifi_link.cpp` | Qualité du Wi-Fi : messages du noyau, ligne de journal, connexion rendue en fin de session | | `tests/test_pending_restart.cpp` | Redémarrage d'Android Auto quand la case du câble USB change en marche | | `tests/test_hold_machine.cpp` | Page vide de l'iDrive : ouverture, démarrage automatique, fenêtres, modes, appels, touches | diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md index dd3977e..8068ef9 100644 --- a/docs/INSTALLATION.md +++ b/docs/INSTALLATION.md @@ -31,7 +31,7 @@ ancienne, suivre celle de l'archive (dans la 0.10.0, le superviseur s'appelle `e Depuis le PC, dans le dossier de l'archive : ```sh -scp entrynav2-android-auto-0.12.1-rc.4-armhf.tar root@169.254.1.0:/tmp/ +scp entrynav2-android-auto-0.13.0-rc.1-armhf.tar root@169.254.1.0:/tmp/ ssh root@169.254.1.0 ``` @@ -43,7 +43,7 @@ encore écrit sur la mémoire flash. Rien n'est modifié pendant cette étape. ```sh -V=0.12.1-rc.4 +V=0.13.0-rc.1 cd /tmp && rm -rf entrynav2-android-auto-$V && tar -xf entrynav2-android-auto-$V-armhf.tar && cd entrynav2-android-auto-$V md5sum -c MD5SUMS head -n 1 /etc/version diff --git a/docs/MAINTENANCE.md b/docs/MAINTENANCE.md index 7b73b10..cd973c4 100644 --- a/docs/MAINTENANCE.md +++ b/docs/MAINTENANCE.md @@ -86,15 +86,15 @@ Journaux activés, le service écrit une ligne `[WifiLink]` quand le téléphone les 10 secondes jusqu'à la fin de la session : ```text -[WifiLink] 5180 MHz; signal -52 dBm (average -51); to the phone 150.0 Mbit/s; from the phone 135.0 Mbit/s; +[WifiLink] 5180 MHz; signal -52 dBm (average -51); from the phone 135.0 Mbit/s; in 10 s: 812 frames sent, 35 retried, 0 lost; on the Wi-Fi for 135 s; TCP round trip 4.2 ms, 0 segment(s) sent again ``` | Partie | Sens | |---|---| | `5180 MHz` | Fréquence du Wi-Fi de la voiture : vers 2400, la bande 2,4 GHz, partagée avec le Bluetooth ; vers 5000, la bande 5 GHz | -| `signal` | Niveau reçu du téléphone, et sa moyenne. Plus le nombre est bas, plus la liaison est fragile (-50 : bon, -80 : faible) | -| `to the phone`, `from the phone` | Débit radio choisi dans chaque sens | +| `signal` | Niveau reçu du téléphone, et sa moyenne. Plus le nombre est bas, plus la liaison est fragile (-50 : bon, -80 : faible). Quand la puce n'a pas mesuré la dernière trame, seule la moyenne est écrite (`average signal`) | +| `from the phone` | Débit radio choisi par le téléphone. Le débit vers le téléphone n'est pas écrit : la puce Wi-Fi le choisit seule et le pilote ne le connaît pas | | `frames sent, retried, lost` | Trames envoyées au téléphone depuis la ligne précédente, réémises, puis abandonnées | | `on the Wi-Fi for` | Temps depuis que le téléphone a rejoint le Wi-Fi. S'il repart de zéro, le téléphone l'a quitté puis rejoint | | `TCP round trip`, `sent again` | Temps d'aller-retour de la connexion Android Auto, et morceaux qu'il a fallu renvoyer | diff --git a/hmiapp/controller_coding.cpp b/hmiapp/controller_coding.cpp deleted file mode 100644 index e350112..0000000 --- a/hmiapp/controller_coding.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2026 Jiraiya43 -// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 -#include "controller_coding.hpp" - -#include -#include -#include -#include - -#include "../platform/controller_layout.hpp" -#include "../platform/service_contract.hpp" -#include "app_log.hpp" - -namespace evo { -namespace app { - -namespace { - -// HmiMain3D's exported template instances (nm -D: weak, defined). The usage object is one pointer-sized value, -// returned in r0 (read in pushbuttonToKeycode: the result of get() is stored, then its address is passed to get()). -const char kGetUsage[] = "_ZN9hmiplugin3getI17IHmiVariantServerEENS_25CPluginInstanceCacheUsageIT_EEv"; -const char kUsageGet[] = "_ZNK9hmiplugin25CPluginInstanceCacheUsageI17IHmiVariantServerE3getEv"; -const unsigned kIsVariantSetSlot = 3; // CHmiVariantServer vtable (libhmicoding.so): isVariantSet(unsigned) -const unsigned kGetRoleSlot = 21; // getRole() - -typedef uintptr_t (*GetUsageFn)(); -typedef void* (*UsageGetFn)(const uintptr_t* usage); -typedef bool (*IsVariantSetFn)(void* server, unsigned id); -typedef int (*GetRoleFn)(void* server); - -} // namespace - -bool writeControllerCoding() { - GetUsageFn getUsage = reinterpret_cast(dlsym(RTLD_DEFAULT, kGetUsage)); - UsageGetFn usageGet = reinterpret_cast(dlsym(RTLD_DEFAULT, kUsageGet)); - void* server = nullptr; - if (getUsage && usageGet) { - const uintptr_t usage = getUsage(); - server = usageGet(&usage); - } - void** vtable = server ? *reinterpret_cast(server) : nullptr; - if (!vtable || !vtable[kIsVariantSetSlot] || !vtable[kGetRoleSlot]) { - alog("controller coding: iDrive's variant server not found (%s %s): the service keeps G-style keys", - getUsage ? "get" : "no get", usageGet ? "usage" : "no usage"); - unlink(contract::kControllerFile); - return false; - } - IsVariantSetFn isSet = reinterpret_cast(vtable[kIsVariantSetSlot]); - GetRoleFn role = reinterpret_cast(vtable[kGetRoleSlot]); - aa::ControllerCoding coding = aa::defaultControllerCoding(); - coding.known = true; - coding.gStyle = isSet(server, aa::kVariantGStyle); - coding.v5141 = isSet(server, aa::kVariant5141); - coding.v4e59 = isSet(server, aa::kVariant4E59); - coding.v4f1e = isSet(server, aa::kVariant4F1E); - coding.v5486 = isSet(server, aa::kVariant5486); - coding.role = role(server); - char line[96]; - aa::formatControllerCoding(coding, line, sizeof(line)); - const char tmp[] = "/tmp/entry-aad-controller.tmp"; - FILE* f = fopen(tmp, "w"); - bool written = f && fprintf(f, "%s\n", line) > 0; - if (f && fclose(f) != 0) { - written = false; - } - if (!written || rename(tmp, contract::kControllerFile) != 0) { - alog("controller coding: %s, not written", line); - unlink(tmp); - return false; - } - alog("controller coding: %s (%s controller)", line, coding.gStyle ? "G-style" : "F-style"); - return true; -} - -} // namespace app -} // namespace evo diff --git a/hmiapp/controller_coding.hpp b/hmiapp/controller_coding.hpp deleted file mode 100644 index 9eed649..0000000 --- a/hmiapp/controller_coding.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2026 Jiraiya43 -// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 -// The car's key coding, read inside iDrive and written for the service (platform/controller_layout.hpp). -// -// iDrive decides which key each controller button is from coding variants (0xB80 G-style controller, and a few -// more), asked from its variant server: hmiplugin::get(), then isVariantSet(id) (vtable slot 3) -// and getRole() (slot 21), as CHmiCCSController::pushbuttonToKeycode does in HmiMain3D. The app runs inside HmiMain3D, -// so it asks the same server; both functions are found with dlsym, nothing is linked. If one is missing or the server -// is not there yet, nothing is written and the service keeps its G-style table. -// Runs on the app thread (onInit). -#ifndef ENTRY_AAD_HMIAPP_CONTROLLER_CODING_HPP -#define ENTRY_AAD_HMIAPP_CONTROLLER_CODING_HPP - -namespace evo { -namespace app { - -// Reads the coding and writes contract::kControllerFile. False: not read (logged), the file is removed. -bool writeControllerCoding(); - -} // namespace app -} // namespace evo - -#endif diff --git a/hmiapp/entry_aa_app.cpp b/hmiapp/entry_aa_app.cpp index 8905fb8..72a388b 100644 --- a/hmiapp/entry_aa_app.cpp +++ b/hmiapp/entry_aa_app.cpp @@ -37,8 +37,8 @@ #include "app_log.hpp" #include "bmw_framework.hpp" #include "car_signals.hpp" -#include "controller_coding.hpp" #include "hold_machine.hpp" +#include "idrive_coding.hpp" #include "mono_clock.hpp" #include "pending_restart.hpp" #include "rhmi_ids.hpp" @@ -355,7 +355,7 @@ bool appOnInit(bmw::PluginApp* self) { addStateHandler(self, kAaState, kHandlerVisible, &onAaVisible); g_initTime = time(nullptr); bool ok = self->onInit(); - writeControllerCoding(); // which key each controller button is on this car, for the service + writeIdriveCoding(); // the car's keys and brand, for the service alog("onInit: handlers registered, base onInit -> %d, start automatically %s, USB cable %s", static_cast(ok), autostartOn() ? "on" : "off", usbCableOn() ? "on" : "off"); g_runApp = self; diff --git a/hmiapp/hold_machine.cpp b/hmiapp/hold_machine.cpp index 1c84d40..6cae337 100644 --- a/hmiapp/hold_machine.cpp +++ b/hmiapp/hold_machine.cpp @@ -124,11 +124,11 @@ void HoldMachine::requestShow() { } // ---- Keys that keep Android Auto on screen ------------------------------------------------------------------------ -// NAV / MEDIA / COM / steering wheel phone opened an Android Auto app, or BACK / tilt left went to it (service file, -// written within the last 2 s). iDrive switched to its own navigation / media / phone screen underneath Android Auto, -// or walked back its history to the screen one of those keys opened (F30, #43: Android Auto stepped aside after BACK -// in its map); put it back on our blank state at once, so the knob does not act on that hidden screen. A key that -// leaves Android Auto (MENU, MAP, OPTION) removes the file in the service first. +// NAV / MAP / MEDIA / COM / steering wheel phone opened an Android Auto app, or BACK / tilt left went to it (service +// file, written within the last 2 s). iDrive switched to its own navigation / media / phone screen underneath Android +// Auto, or walked back its history to the screen one of those keys opened (F30, #43: Android Auto stepped aside after +// BACK in its map); put it back on our blank state at once, so the knob does not act on that hidden screen. A key that +// leaves Android Auto (MENU, OPTION) removes the file in the service first. bool HoldMachine::appKeyRecent() { long age = 0; return io_.appKeyAge(&age) && age <= kAppKeyS; diff --git a/hmiapp/idrive_coding.cpp b/hmiapp/idrive_coding.cpp new file mode 100644 index 0000000..47f7390 --- /dev/null +++ b/hmiapp/idrive_coding.cpp @@ -0,0 +1,121 @@ +// Copyright (c) 2026 Jiraiya43 +// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 +#include "idrive_coding.hpp" + +#include +#include +#include +#include + +#include + +#include "../platform/car_brand.hpp" +#include "../platform/controller_layout.hpp" +#include "../platform/service_contract.hpp" +#include "app_log.hpp" + +namespace evo { +namespace app { + +namespace { + +// HmiMain3D's exported template instances (nm -D: weak, defined). The usage object is one pointer-sized value, +// returned in r0 (read in pushbuttonToKeycode: the result of get() is stored, then its address is passed to get()). +const char kGetUsage[] = "_ZN9hmiplugin3getI17IHmiVariantServerEENS_25CPluginInstanceCacheUsageIT_EEv"; +const char kUsageGet[] = "_ZNK9hmiplugin25CPluginInstanceCacheUsageI17IHmiVariantServerE3getEv"; +const unsigned kIsVariantSetSlot = 3; // CHmiVariantServer vtable (libhmicoding.so): isVariantSet(unsigned) +const unsigned kGetRoleSlot = 21; // getRole() + +typedef uintptr_t (*GetUsageFn)(); +typedef void* (*UsageGetFn)(const uintptr_t* usage); +typedef bool (*IsVariantSetFn)(void* server, unsigned id); +typedef int (*GetRoleFn)(void* server); + +// iDrive's variant server and the two calls asked of it. +class VariantServer { +public: + VariantServer() : self_(nullptr), isSet_(nullptr), role_(nullptr) {} + // False when HmiMain3D does not give it (logged). + bool find() { + GetUsageFn getUsage = reinterpret_cast(dlsym(RTLD_DEFAULT, kGetUsage)); + UsageGetFn usageGet = reinterpret_cast(dlsym(RTLD_DEFAULT, kUsageGet)); + if (getUsage && usageGet) { + const uintptr_t usage = getUsage(); + self_ = usageGet(&usage); + } + void** vtable = self_ ? *reinterpret_cast(self_) : nullptr; + if (!vtable || !vtable[kIsVariantSetSlot] || !vtable[kGetRoleSlot]) { + alog("iDrive coding: variant server not found (%s %s): the service keeps G-style keys and a BMW", + getUsage ? "get" : "no get", usageGet ? "usage" : "no usage"); + return false; + } + isSet_ = reinterpret_cast(vtable[kIsVariantSetSlot]); + role_ = reinterpret_cast(vtable[kGetRoleSlot]); + return true; + } + bool isSet(unsigned id) const { return isSet_(self_, id); } + int role() const { return role_(self_); } + +private: + void* self_; + IsVariantSetFn isSet_; + GetRoleFn role_; +}; + +// One line to path, through a temporary file renamed over it: the service never reads half a line. On failure the +// file is removed, so the service falls back to its default rather than an old value. +bool writeLine(const char* path, const char* line) { + const std::string tmp = std::string(path) + ".tmp"; + FILE* f = fopen(tmp.c_str(), "w"); + bool written = f && fprintf(f, "%s\n", line) > 0; + if (f && fclose(f) != 0) { + written = false; + } + if (!written || rename(tmp.c_str(), path) != 0) { + unlink(tmp.c_str()); + unlink(path); + return false; + } + return true; +} + +bool writeControllerCoding(const VariantServer& server) { + aa::ControllerCoding coding = aa::defaultControllerCoding(); + coding.known = true; + coding.gStyle = server.isSet(aa::kVariantGStyle); + coding.v5141 = server.isSet(aa::kVariant5141); + coding.v4e59 = server.isSet(aa::kVariant4E59); + coding.v4f1e = server.isSet(aa::kVariant4F1E); + coding.v5486 = server.isSet(aa::kVariant5486); + coding.role = server.role(); + char line[96]; + aa::formatControllerCoding(coding, line, sizeof(line)); + const bool written = writeLine(contract::kControllerFile, line); + alog("controller coding: %s (%s controller)%s", line, coding.gStyle ? "G-style" : "F-style", + written ? "" : ", not written"); + return written; +} + +bool writeBrand(const VariantServer& server) { + const aa::CarBrand brand = server.isSet(aa::kVariantBrandMini) ? aa::CarBrand::kMini : aa::CarBrand::kBmw; + const bool written = writeLine(contract::kBrandFile, aa::brandName(brand)); + alog("brand: %s%s", aa::brandName(brand), written ? "" : ", not written"); + return written; +} + +} // namespace + +bool writeIdriveCoding() { + VariantServer server; + if (!server.find()) { + unlink(contract::kControllerFile); + unlink(contract::kBrandFile); + return false; + } + const bool keys = writeControllerCoding(server); + const bool brand = writeBrand(server); + return keys && brand; +} + +} // namespace app +} // namespace evo diff --git a/hmiapp/idrive_coding.hpp b/hmiapp/idrive_coding.hpp new file mode 100644 index 0000000..5a5b8b6 --- /dev/null +++ b/hmiapp/idrive_coding.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2026 Jiraiya43 +// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 +// What the service needs of the car's coding, read inside iDrive and written for it: which key each controller +// button is (platform/controller_layout.hpp) and the brand (platform/car_brand.hpp). +// +// iDrive keeps its coding behind a variant server: hmiplugin::get(), then isVariantSet(id) +// (vtable slot 3) and getRole() (slot 21), as CHmiCCSController::pushbuttonToKeycode does in HmiMain3D. The app runs +// inside HmiMain3D, so it asks the same server; both functions are found with dlsym, nothing is linked. If one is +// missing or the server is not there yet, nothing is written: the service keeps its G-style keys and a BMW. +// Runs on the app thread (onInit). +#ifndef ENTRY_AAD_HMIAPP_IDRIVE_CODING_HPP +#define ENTRY_AAD_HMIAPP_IDRIVE_CODING_HPP + +namespace evo { +namespace app { + +// Reads the coding and writes contract::kControllerFile and contract::kBrandFile. False when either was not written +// (logged); a file not written is removed. +bool writeIdriveCoding(); + +} // namespace app +} // namespace evo + +#endif diff --git a/hmiapp/make_db.py b/hmiapp/make_db.py index 28ad924..6a5b0df 100644 --- a/hmiapp/make_db.py +++ b/hmiapp/make_db.py @@ -37,7 +37,7 @@ 15: "Start automatically", 16: "Help", 17: "USB cable instead of wireless", - 20: "NAV: Android Auto navigation", + 20: "NAV, MAP: Android Auto navigation", 21: "MEDIA: Android Auto media", 22: "COM: Android Auto phone", 23: "MENU: iDrive - BACK: back", @@ -55,7 +55,7 @@ 15: "Demarrage automatique", 16: "Aide", 17: "Cable USB au lieu du sans-fil", - 20: "NAV : navigation Android Auto", + 20: "NAV, MAP : navigation Android Auto", 21: "MEDIA : musique Android Auto", 22: "COM : telephone Android Auto", 23: "MENU : iDrive - BACK : retour", @@ -71,7 +71,7 @@ 15: "Automatisch starten", 16: "Hilfe", 17: "USB-Kabel statt kabellos", - 20: "NAV: Android Auto Navigation", + 20: "NAV, MAP: Android Auto Navigation", 21: "MEDIA: Android Auto Medien", 22: "COM: Android Auto Telefon", 23: "MENU: iDrive - BACK: zurueck", diff --git a/platform/car_brand.hpp b/platform/car_brand.hpp new file mode 100644 index 0000000..a141468 --- /dev/null +++ b/platform/car_brand.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2026 Jiraiya43 +// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 +// The car's brand as iDrive is coded: the maker the phone is told about (Android Auto shows it on its exit icon), and +// the round surround of the MINI's central screen. +// +// iDrive's coding variant HMI_BRAND (libhmicoding.so, its table of coding features): va_HMI_BRAND_bmw 0x1F6, +// va_HMI_BRAND_bmw_i 0x1F7, va_HMI_BRAND_mini 0x1F8, va_HMI_BRAND_rr 0x1F9, va_HMI_BRAND_bmw_m 0xE8D. The iDrive app +// asks its variant server for 0x1F8 (hmiapp/idrive_coding.cpp) and writes contract::kBrandFile; the service reads it at +// start. Without the file (an older app), a BMW. Pure: no I/O. tests/test_evo_sdr.cpp. +#ifndef ENTRY_AAD_PLATFORM_CAR_BRAND_HPP +#define ENTRY_AAD_PLATFORM_CAR_BRAND_HPP + +#include +#include + +namespace aa { + +enum class CarBrand { kBmw, kMini }; + +const unsigned kVariantBrandMini = 0x1F8; // va_HMI_BRAND_mini + +// The maker as the phone is told it, and as the brand file holds it. +inline const char* brandName(CarBrand brand) { + return brand == CarBrand::kMini ? "MINI" : "BMW"; +} + +// The brand file's line: "MINI" or "BMW", an end of line allowed; false otherwise (out unchanged). +inline bool parseCarBrand(const char* text, CarBrand& out) { + if (!text) { + return false; + } + const size_t len = strcspn(text, "\r\n"); + if (len == 4 && !strncmp(text, "MINI", 4)) { + out = CarBrand::kMini; + return true; + } + if (len == 3 && !strncmp(text, "BMW", 3)) { + out = CarBrand::kBmw; + return true; + } + return false; +} + +// The MINI's central screen sits in a round surround that hides about 40 pixels on each side of a 1280-pixel-wide +// panel, and the same share of a narrower one: the width hidden on each side, in panel pixels. 0 on a BMW. +inline uint32_t surroundSide(CarBrand brand, uint32_t panelWidth) { + return brand == CarBrand::kMini ? (40 * panelWidth + 640) / 1280 : 0; +} + +} // namespace aa + +#endif // ENTRY_AAD_PLATFORM_CAR_BRAND_HPP diff --git a/platform/evo_knob.cpp b/platform/evo_knob.cpp index 82eb63d..357a978 100644 --- a/platform/evo_knob.cpp +++ b/platform/evo_knob.cpp @@ -23,6 +23,9 @@ bool decodeVolumeLevel(const VmostMsgView& m, VolumeLevel& out) { if (m.fblock != kAudioMasterFblock || m.fkt != kVolumeLevelFkt || m.op != 0xC || !m.data || m.len < 5) { return false; } + if (m.data[0] > 1 || m.data[1] != 0) { // another display's record, or not a whole record + return false; + } const unsigned value = m.data[2], min = m.data[3], max = m.data[4]; if (max <= min || value < min || value > max) { return false; @@ -35,6 +38,13 @@ bool decodeVolumeLevel(const VmostMsgView& m, VolumeLevel& out) { static const uint16_t kCcs35upFunctions[] = {0xC46, 0xC47, 0xC4F}; // RotaryEncoderState, PushButtonsState(2) +int decodeAudioButton(const VmostMsgView& m) { + return m.fblock == kVolumeFblock && m.inst == kVolumeCsInstance && m.fkt == kAudioButtonFkt && m.op == 0xC && + m.data && m.len >= 1 && m.data[0] == 1 + ? 1 + : 0; +} + int decodeVolumeButton(const VmostMsgView& m, unsigned* steps) { if (m.fblock != kVolumeFblock || m.op != 0xC || !m.data) { return 0; @@ -110,6 +120,8 @@ EvoKnob::EvoKnob() volCb_(nullptr), levelCb_(nullptr), levelUser_(nullptr), + audioButtonCb_(nullptr), + audioButtonUser_(nullptr), levelRegistered_(false), levels_(0), keyCb_(nullptr), @@ -135,20 +147,21 @@ EvoKnob::EvoKnob() } // Controller keys while Android Auto is on screen, as iDrive does for CarPlay (CCarPlayActivity::handleControllerInput: -// NAV -> CarPlay "maps:", COM -> "mobilephone:", MEDIA -> CarPlay, MENU -> leave CarPlay). -// NAV / MEDIA / COM Android Auto's navigation / media / phone app (AA keys NAVIGATION 65538, MEDIA 65537, -// TEL 65540; not KEYCODE_CALL, which made the phone redial on the car). iDrive switches screens -// too (it gets every key): the service keeps Android Auto up and the iDrive app brings iDrive -// back at once. -// MENU / MAP iDrive (Android Auto steps aside). OPTION: the Android Auto menu of the iDrive app. +// NAV and the map key -> CarPlay "maps:", COM -> "mobilephone:", MEDIA -> CarPlay, MENU -> leave CarPlay). +// NAV / MAP / MEDIA / COM Android Auto's navigation (both NAV and MAP) / media / phone app (AA keys NAVIGATION +// 65538, MEDIA 65537, TEL 65540; not KEYCODE_CALL, which made the phone redial on the car). iDrive +// switches screens too (it gets every key): the service keeps Android Auto up and the iDrive app +// brings iDrive back at once. +// MENU iDrive (Android Auto steps aside). OPTION: the Android Auto menu of the iDrive app. // BACK Android Auto's back. void configureHardKeys(aa::CcsDecoder& d) { - static const char* const local[] = {"MENU", "OPTIONS", "MAP"}; + static const char* const local[] = {"MENU", "OPTIONS"}; for (size_t i = 0; i < sizeof(local) / sizeof(local[0]); ++i) { d.setSlotKey(aa::CcsDecoder::slotByName(local[i]), 0); } d.setSlotKey(aa::CcsDecoder::slotByName("COM"), aa::AAK_TEL); d.setSlotKey(aa::CcsDecoder::slotByName("NAV"), aa::AAK_NAVIGATION); + d.setSlotKey(aa::CcsDecoder::slotByName("MAP"), aa::AAK_NAVIGATION); // #1 d.setSlotKey(aa::CcsDecoder::slotByName("MEDIA"), aa::AAK_MEDIA); } @@ -311,7 +324,8 @@ void EvoKnob::onMessage(const VmostMsgView& m) { levelCb_(level, levelUser_); } } else if (levels_ < 50 && m.fkt == kVolumeLevelFkt) { - ELOG("Knob", "volume level message not recognised: operation 0x%x, %u byte(s)", m.op, m.len); + ELOG("Knob", "volume level message not recognised: operation 0x%x, %u byte(s), first 0x%02x", m.op, m.len, + m.data && m.len ? m.data[0] : 0); } return; } @@ -326,6 +340,12 @@ void EvoKnob::onMessage(const VmostMsgView& m) { volCb_(steps, volUser_); } } + if (decodeAudioButton(m)) { + ELOG("Knob", "audio knob pressed (iDrive mutes or unmutes)"); + if (audioButtonCb_) { + audioButtonCb_(audioButtonUser_); + } + } const int tel = decodeTelephoneButton(m); if (tel == 1 && !telDown_) { telDown_ = true; @@ -497,6 +517,13 @@ void EvoKnob::run() { ELOG("Knob", "volume %s 15.%02x function 0x%03x: shadow %s (%d), read (Get) %s (%d)", i == 0 ? "centre console" : "steering wheel", volInst[i], volFkt[i], vr == 0 ? "OK" : "refused", vr, gr == 0 ? "sent" : "not sent", gr); + if (volInst[i] == kVolumeCsInstance && vr == 0) { // the audio knob's push button, same instance + VmostMsgOut bm; + buildVmostGet(bm, kVolumeFblock, kVolumeCsInstance, kAudioButtonFkt, dummy); + const int br = vmost_.send(&bm); + ELOG("Knob", "audio knob button 15.%02x function 0x%03x: read (Get) %s (%d)", kVolumeCsInstance, + kAudioButtonFkt, br == 0 ? "sent" : "not sent", br); + } if (volInst[i] == kVolumeMflInstance && vr == 0) { // steering wheel phone button, same instance VmostMsgOut tm; buildVmostGet(tm, kVolumeFblock, kVolumeMflInstance, kMflTelephoneFkt, dummy); diff --git a/platform/evo_knob.hpp b/platform/evo_knob.hpp index 339b44e..6942b27 100644 --- a/platform/evo_knob.hpp +++ b/platform/evo_knob.hpp @@ -30,6 +30,7 @@ #include "evo_ccs.hpp" #include "input_mode.hpp" #include "vmost_client.hpp" +#include "volume_state.hpp" namespace evo { @@ -64,16 +65,19 @@ const uint16_t kVolumeCsFkt = 0xC01, kVolumeMflFkt = 0x401; int decodeVolumeButton(const VmostMsgView& m, unsigned* steps); // Volume level, read where HmiMain3D's own volume bar reads it: CHmiVolumeIndicatorService watches CPxyAudioMaster -// instance 0, whose init binds fkt 0xC08 (libhmil6services). Array property, record 0: Status = PosX, PosY, value, -// min, max, one byte each (e.g. 01 00 LEVEL 00 MAX). Our copy needs vmostd's filter opened by one Get, as for E5: -// nothing is ever set on the AudioMaster. +// instance 0, whose init binds fkt 0xC08 (libhmil6services). Array property (volume_state.hpp): Status = PosX, PosY, +// then records of value, min, max, one byte each (e.g. 01 00 LEVEL 00 MAX). Only the front display's record, the +// first one (PosX 0: the whole array, its first record; PosX 1: that record alone). Our copy needs vmostd's filter +// opened by one Get, as for E5: nothing is ever set on the AudioMaster. const uint8_t kAudioMasterFblock = 0x20, kAudioMasterInstance = 0x00; const uint16_t kVolumeLevelFkt = 0xC08; -struct VolumeLevel { - unsigned value, min, max; -}; bool decodeVolumeLevel(const VmostMsgView& m, VolumeLevel& out); +// The audio knob's push button (CECenterStack 0x15.0C, fkt 0xC04 PushButtonAudio, bound by CPxyCECenterStack::init): +// Status = one enum byte, 1 pressed. iDrive mutes or unmutes on the press. Returns 1 for a press. +const uint16_t kAudioButtonFkt = 0xC04; +int decodeAudioButton(const VmostMsgView& m); + class EvoKnob { public: using Callback = void (*)(const aa::CcsEvent&, void*); @@ -113,6 +117,12 @@ class EvoKnob { levelCb_ = cb; levelUser_ = user; } + // The audio knob pressed (iDrive mutes or unmutes). Called on the vMOST thread. + using AudioButtonCallback = void (*)(void*); + void setAudioButtonCallback(AudioButtonCallback cb, void* user) { + audioButtonCb_ = cb; + audioButtonUser_ = user; + } // During a phone call (iDrive's call screen) COM and the steering wheel phone button stay with iDrive. void setPhoneToIdrive(bool v) { phoneToIdrive_ = v; } void stop(); @@ -154,6 +164,8 @@ class EvoKnob { VolumeCallback volCb_; VolumeLevelCallback levelCb_; void* levelUser_; + AudioButtonCallback audioButtonCb_; + void* audioButtonUser_; bool levelRegistered_; unsigned levels_; HardKeyCallback keyCb_; diff --git a/platform/evo_video.cpp b/platform/evo_video.cpp index 5a65605..5b94a9b 100644 --- a/platform/evo_video.cpp +++ b/platform/evo_video.cpp @@ -232,10 +232,10 @@ bool EvoVideo::isIdr(const uint8_t* d, size_t n) const { return false; } -bool EvoVideo::postVideoFrame(const uint8_t* data, size_t len, uint64_t pts) { +FrameFate EvoVideo::postVideoFrame(const uint8_t* data, size_t len, uint64_t pts) { (void)pts; if (!running_ || !started_) { - return false; + return FrameFate::kNoStream; } pthread_mutex_lock(&mu_); @@ -269,7 +269,7 @@ bool EvoVideo::postVideoFrame(const uint8_t* data, size_t len, uint64_t pts) { if (bi < 0) { ++framesDropped_; pthread_mutex_unlock(&mu_); - return false; + return FrameFate::kLost; } DmaBufPool::Buf& b = pool_.at(bi); @@ -277,7 +277,7 @@ bool EvoVideo::postVideoFrame(const uint8_t* data, size_t len, uint64_t pts) { ++framesDropped_; pthread_mutex_unlock(&mu_); ELOG("Video", "frame %zu B > buffer %u B", need, b.size); - return false; + return FrameFate::kLost; } size_t off = 0; if (prependCfg) { @@ -300,9 +300,9 @@ bool EvoVideo::postVideoFrame(const uint8_t* data, size_t len, uint64_t pts) { } pthread_cond_signal(&cv_); pthread_mutex_unlock(&mu_); - return false; + return FrameFate::kLost; } - return true; + return FrameFate::kDecoding; } void* EvoVideo::eventStub(void* self) { diff --git a/platform/evo_video.hpp b/platform/evo_video.hpp index 4d67f40..9671a69 100644 --- a/platform/evo_video.hpp +++ b/platform/evo_video.hpp @@ -44,6 +44,14 @@ struct EvoVideoConfig { void setDisplay(uint32_t canvasWidth, uint32_t canvasHeight, uint32_t panelWidth, uint32_t panelHeight); }; +// What became of one frame handed to postVideoFrame. +enum class FrameFate { + kDecoding, // in the decoder + kLost, // dropped (no free buffer in time, larger than a buffer) or refused by the decoder: the frames after it + // refer to a picture the decoder never had + kNoStream, // the decoder is not running +}; + class EvoVideo { public: EvoVideo(); @@ -62,8 +70,7 @@ class EvoVideo { // SPS/PPS (the Android Auto codec config): kept and prepended to the first IDR frame after each (re)start. void postCodecConfig(const uint8_t* data, size_t len); // One H.264 access unit, copied into a free dma-buf and handed to the decoder. - // False when no buffer frees up in time (frame dropped) or the stream is not started. - bool postVideoFrame(const uint8_t* data, size_t len, uint64_t pts); + FrameFate postVideoFrame(const uint8_t* data, size_t len, uint64_t pts); private: static void* eventStub(void* self); diff --git a/platform/main.cpp b/platform/main.cpp index 235dfcf..550da2f 100644 --- a/platform/main.cpp +++ b/platform/main.cpp @@ -8,6 +8,7 @@ // the USB half of a wired one in usb_loop. // clang-format off #include "alps_spp.hpp" +#include "car_brand.hpp" #include "evo_ap.hpp" #include "evo_video.hpp" #include "evo_touch.hpp" @@ -127,6 +128,21 @@ void usage(const char* argv0) { " --alps-pid P --alps-start S --uuid-pair HEX Alps state saved by aa-supervisor, checked before each step\n", argv0); } + +// The brand the iDrive app read in the car's coding (car_brand.hpp). Without the file (an older app), a BMW. +aa::CarBrand readCarBrand() { + aa::CarBrand brand = aa::CarBrand::kBmw; + FILE* f = fopen(evo::contract::kBrandFile, "r"); + char line[16] = {0}; + const bool read = f && fgets(line, sizeof(line), f) && aa::parseCarBrand(line, brand); + if (f) { + fclose(f); + } + if (!read) { + ELOG("Main", "brand not read from %s: BMW", evo::contract::kBrandFile); + } + return brand; +} } // namespace int main(int argc, char** argv) { @@ -242,9 +258,16 @@ int main(int argc, char** argv) { ELOG("Main", "screen %ux%u: the phone is asked for %ux%u%s", display.width, display.height, display.canvasWidth, display.canvasHeight, display.reference() ? "" : " (a size not tried on the reference car)"); } + const aa::CarBrand brand = readCarBrand(); + display.hiddenSide = aa::surroundSide(brand, display.width); + if (display.hiddenSide) { + ELOG("Main", "%s: the round surround hides %u columns on each side, the phone keeps its UI inside", + aa::brandName(brand), display.hiddenSide); + } evo::ServiceApp app(kAaPort, video, &quit); app.videoConfig.setDisplay(display.canvasWidth, display.canvasHeight, display.width, display.height); app.session.setDisplay(display); + app.session.setCarMake(aa::brandName(brand)); app.usbPort = usbPort ? usbPort : ""; app.session.setTouchForwarding(input == evo::INPUT_FORWARD); app.session.setVehicleFile(evo::contract::kVehicle); // the car's model and year, written at installation @@ -314,7 +337,7 @@ int main(int argc, char** argv) { } ELOG("Main", "volume: pill over AA from the first level received (before that: picture dimmed %u ms); driving mode: " - "picture aside %u ms after %u ms; NAV/MEDIA/COM = AA apps, MENU/MAP/OPTION = iDrive", + "picture aside %u ms after %u ms; NAV/MAP/MEDIA/COM = AA apps, MENU/OPTION = iDrive", evo::kVolumePeekMs, evo::kDriveModeShowMs, evo::kDriveModeDelayMs); if (video && !app.pill.start(evo::kPillSurfaceId, app.videoConfig.layerId, app.videoConfig.displayWidth, app.videoConfig.displayHeight)) { @@ -322,6 +345,7 @@ int main(int argc, char** argv) { } knob.setVolumeCallback(evo::ServiceApp::volumeEvent, &app); knob.setVolumeLevelCallback(evo::ServiceApp::volumeLevel, &app); + knob.setAudioButtonCallback(evo::ServiceApp::audioButton, &app); knob.setHardKeyCallback(evo::ServiceApp::hardKey, &app); knob.setAppKeyCallback(evo::ServiceApp::appKey, &app); knob.setMediaCallback(evo::ServiceApp::mediaKey, &app); diff --git a/platform/service_app.cpp b/platform/service_app.cpp index 7830ff9..a7f8b0c 100644 --- a/platform/service_app.cpp +++ b/platform/service_app.cpp @@ -153,7 +153,9 @@ void ServiceApp::frame(uint32_t, const uint8_t* data, size_t len, uint64_t pts, // Phone frames never wait for mu: the main loop holds it while LayerManagerControl runs (show/hide, // opacity), which would stall the picture. ++a->videoFrames; - a->video.postVideoFrame(data, len, pts); + if (a->video.postVideoFrame(data, len, pts) == FrameFate::kLost) { + a->session.postKeyframeRequest(); // the session decides whether and when to ask the phone + } } } @@ -172,7 +174,9 @@ void ServiceApp::touchEvent(const aa::TouchEventOut& ev, void* user) { void ServiceApp::volumeEvent(unsigned steps, void* user) { ServiceApp* a = static_cast(user); pthread_mutex_lock(&a->mu); - const bool start = a->peek.volumeKey(monoMs(), a->pill.ready()); + const uint32_t now = monoMs(); + a->volume.volumeKey(now); + const bool start = a->peek.volumeKey(now, a->pill.ready()); const bool refused = a->peek.dimRefused(); pthread_mutex_unlock(&a->mu); if (start) { @@ -181,29 +185,45 @@ void ServiceApp::volumeEvent(unsigned steps, void* user) { } } -// Volume level from the car (vMOST thread): the pill over Android Auto, which stays opaque. +// Volume level from the car (vMOST thread): the pill over Android Auto, which stays opaque. Only a change, or a level +// right after a volume key, shows; another source's level never does (volume_state.hpp). void ServiceApp::volumeLevel(const VolumeLevel& level, void* user) { ServiceApp* a = static_cast(user); pthread_mutex_lock(&a->mu); const bool first = !a->peek.levelSeen(); const bool ready = a->pill.ready(); - if (a->peek.volumeLevel(ready)) { - a->pill.show(level.value, level.min, level.max); // only takes the pill's own short lock + const VolumeState::Shown shown = a->volume.level(level, monoMs()); + if (shown.show && a->peek.volumeLevel(ready)) { + a->pill.show(shown.level.value, shown.level.min, shown.level.max); // only takes the pill's own short lock } + const bool seen = a->peek.levelSeen(); pthread_mutex_unlock(&a->mu); - if (first) { + if (first && seen) { ELOG("ServiceApp", "volume level received from the car: pill %s", ready ? "on" : "unavailable"); } } -// Hard key iDrive acts on (MENU, MEDIA, NAV, MAP, COM; not forwarded to the phone): the picture steps aside at +// The audio knob pressed (vMOST thread): iDrive mutes or unmutes, the pill shows the speaker crossed out or not. +void ServiceApp::audioButton(void* user) { + ServiceApp* a = static_cast(user); + pthread_mutex_lock(&a->mu); + const VolumeState::Shown shown = a->volume.audioButton(monoMs()); + if (shown.show && a->peek.volumeLevel(a->pill.ready())) { + a->pill.show(shown.level.value, shown.level.min, shown.level.max); + } + const bool muted = a->volume.muted(); + pthread_mutex_unlock(&a->mu); + ELOG("ServiceApp", "audio knob: %s, as iDrive", muted ? "muted" : "sound back"); +} + +// Hard key iDrive acts on (MENU and OPTION, COM during a call; not forwarded to the phone): the picture steps aside at // once, so the result does not depend on timing (observed on the car otherwise: iDrive sometimes came back, // sometimes not). If iDrive stays on the blank Android Auto page the iDrive app opens its main menu. The Android // Auto row brings the phone back. void ServiceApp::hardKey(const char* name, void* user) { // OPTION opens the Android Auto menu of the iDrive app (Stop, start automatically): see the app's hold logic. - // NAV and MEDIA always go to Android Auto (appKey); COM reaches here only during a call. - static const char* const leave[] = {"MENU", "MAP", "COM", "OPTIONS"}; + // NAV, MAP and MEDIA always go to Android Auto (appKey); COM reaches here only during a call. + static const char* const leave[] = {"MENU", "COM", "OPTIONS"}; bool match = false; for (unsigned i = 0; i < sizeof(leave) / sizeof(leave[0]); ++i) { if (!strcmp(name, leave[i])) { diff --git a/platform/service_app.hpp b/platform/service_app.hpp index 243807f..e62baf5 100644 --- a/platform/service_app.hpp +++ b/platform/service_app.hpp @@ -29,6 +29,7 @@ #include "peek_timing.hpp" #include "tcp_server.hpp" #include "usb_loop.hpp" +#include "volume_state.hpp" #include "wifi_link.hpp" #include "wireless_loop.hpp" #include "wireless_setup.hpp" @@ -74,6 +75,7 @@ class ServiceApp : public WirelessHost, public UsbHost { static void touchEvent(const aa::TouchEventOut& ev, void* user); static void volumeEvent(unsigned steps, void* user); static void volumeLevel(const VolumeLevel& level, void* user); + static void audioButton(void* user); static void hardKey(const char* name, void* user); static void knobEvent(const aa::CcsEvent& ev, void* user); static void appKey(const char* name, void* user); @@ -124,6 +126,7 @@ class ServiceApp : public WirelessHost, public UsbHost { bool asking; // service: such a session, not shown yet int pendingFocus; // service: 1 tell the phone FOCUSED, 2 NATIVE (sent from the main loop) PeekTiming peek; // under mu + VolumeState volume; // under mu EvoPill pill; WifiLinkLog wifiLink; // the Wi-Fi link's quality, logged while a wireless session runs unsigned sppLinks, tcpLinks, usbLinks; diff --git a/platform/service_contract.hpp b/platform/service_contract.hpp index 93484c3..87a01a0 100644 --- a/platform/service_contract.hpp +++ b/platform/service_contract.hpp @@ -43,6 +43,7 @@ constexpr char kStateFile[] = "/tmp/entry-aad-state"; // "state pid constexpr char kAppKeyFile[] = "/tmp/entry-aad-appkey"; // NAV/MEDIA/COM/BACK kept Android Auto up constexpr char kDayNightFile[] = "/tmp/entry-aad-daynight"; // day or night, written by the app constexpr char kControllerFile[] = "/tmp/entry-aad-controller"; // the car's key coding, written by the app +constexpr char kBrandFile[] = "/tmp/entry-aad-brand"; // "BMW" or "MINI", as iDrive is coded constexpr char kWirelessLock[] = "/tmp/entry-aad-wireless.lock"; // one wireless start at a time // One-shot double-MEDIA recall request: process id and monotonic timestamp, checked by the iDrive app. constexpr char kMediaRecallFile[] = "/tmp/entry-aad-media-recall"; diff --git a/platform/volume_state.hpp b/platform/volume_state.hpp new file mode 100644 index 0000000..7483dc1 --- /dev/null +++ b/platform/volume_state.hpp @@ -0,0 +1,97 @@ +// Copyright (c) 2026 Jiraiya43 +// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 +// What the volume pill shows, decided as iDrive decides its own volume bar: pure, no clock, no lock. +// +// Read in the reference car's HmiMain3D (iDrive 202111011321) and libhmil6services.so: +// - The level is an array property of the AudioMaster (fkt 0xC08, CPxyAudioMaster::CVisibleVolumeIndicator), one +// record per display: value, min, max (one byte each, 0 to 100). A Status starts with PosX, PosY: PosX 0 carries +// the whole array, PosX n the single record n - 1. The front display's record is the first one +// (CHmiVolumeIndicatorService::copyVolumeIndicatorValuesToStruct, index 0 for this unit's role). +// - iDrive keeps that record in one of two slots by its minimum: 0, the volume the knob turns; above 0, another +// source's (seen on a MINI F57 at connection: 25 between 25 and 100, ten times in four seconds, while the knob's +// volume was 3 between 0 and 100). Only the first slot is the knob's: the other one never shows the pill. +// - The same level comes again without anything changing; iDrive's bar opens on a change or a volume key, so does +// the pill. +// - Mute is iDrive's own: pressing the audio knob (CECenterStack 0x15.0C fkt 0xC04 PushButtonAudio, value 1) toggles +// it (CDevVolumeControl::onPushButtonAudio, then onMuteTriggered); a volume step ends it. The AudioMaster's level +// does not change, so the pill shows the speaker crossed out from the button alone. +// tests/test_volume_state.cpp. +#ifndef ENTRY_AAD_PLATFORM_VOLUME_STATE_HPP +#define ENTRY_AAD_PLATFORM_VOLUME_STATE_HPP + +#include + +namespace evo { + +// One record of the volume level, as the AudioMaster reports it. +struct VolumeLevel { + unsigned value, min, max; +}; + +class VolumeState { +public: + static const uint32_t kKeyWindowMs = 1000; // a level within this of a volume key or the audio button shows + + // What the pill shows after an event: nothing, or a level (value at min for the crossed-out speaker). + struct Shown { + bool show; + VolumeLevel level; + }; + + VolumeState() : known_(false), muted_(false), keyAt_(0) { level_.value = level_.min = level_.max = 0; } + + // A level of the front display. A level of another source (minimum above 0) is not the knob's. + Shown level(const VolumeLevel& reported, uint32_t now) { + if (reported.min != 0) { + return none(); + } + const bool changed = !known_ || reported.value != level_.value || reported.max != level_.max; + level_ = reported; + known_ = true; + if (!changed && !recentKey(now)) { + return none(); + } + return shown(); + } + // A volume step (knob or steering wheel): ends the mute; the level that follows shows. + void volumeKey(uint32_t now) { + muted_ = false; + keyAt_ = nz(now); + } + // The audio knob pressed: mute on or off, shown at once when the level is known. + Shown audioButton(uint32_t now) { + muted_ = !muted_; + keyAt_ = nz(now); + return known_ ? shown() : none(); + } + + bool known() const { return known_; } + bool muted() const { return muted_; } + +private: + static uint32_t nz(uint32_t t) { return t ? t : 1; } // 0 means "no key yet" + bool recentKey(uint32_t now) const { return keyAt_ && now - keyAt_ <= kKeyWindowMs; } // wraps with the clock + static Shown none() { + Shown s; + s.show = false; + s.level.value = s.level.min = s.level.max = 0; + return s; + } + Shown shown() const { + Shown s; + s.show = true; + s.level = level_; + if (muted_) { + s.level.value = level_.min; // the pill crosses the speaker out at its minimum + } + return s; + } + + VolumeLevel level_; + bool known_, muted_; + uint32_t keyAt_; +}; + +} // namespace evo + +#endif // ENTRY_AAD_PLATFORM_VOLUME_STATE_HPP diff --git a/platform/wifi_link.cpp b/platform/wifi_link.cpp index 061232e..48a8dca 100644 --- a/platform/wifi_link.cpp +++ b/platform/wifi_link.cpp @@ -78,9 +78,14 @@ int64_t number(const Attr& a) { return kNoFigure; } -// A signal level: one signed byte, in dBm. +// A signal level: one signed byte, in dBm. mac80211 copies the level the chip gave with the last frame received, and +// the WL18xx leaves it at 0 for frames it did not measure: 0 dBm is never a level received from a phone. int64_t level(const Attr& a) { - return a.len == 1 ? static_cast(a.data[0]) : kNoFigure; + if (a.len != 1) { + return kNoFigure; + } + const int8_t dbm = static_cast(a.data[0]); + return dbm < 0 ? dbm : kNoFigure; } int64_t bitrate(const Attr& nested) { @@ -107,9 +112,6 @@ void stationFigures(const Attr& nested, WifiStation& out) { case NL80211_STA_INFO_SIGNAL_AVG: out.signalAvgDbm = level(a); break; - case NL80211_STA_INFO_TX_BITRATE: - out.txRate = bitrate(a); - break; case NL80211_STA_INFO_RX_BITRATE: out.rxRate = bitrate(a); break; @@ -330,7 +332,6 @@ bool continues(const WifiStation& now, const WifiStation& before) { WifiStation::WifiStation() : signalDbm(kNoFigure), signalAvgDbm(kNoFigure), - txRate(kNoFigure), rxRate(kNoFigure), txFrames(kNoFigure), txRetries(kNoFigure), @@ -396,9 +397,8 @@ std::string describeWifiLink(const WifiSample& now, const WifiSample* before) { add(line, "; ", "signal %lld dBm (average %lld)", phone.signalDbm, phone.signalAvgDbm); } else if (phone.signalDbm != kNoFigure) { add(line, "; ", "signal %lld dBm", phone.signalDbm); - } - if (phone.txRate != kNoFigure) { - add(line, "; ", "to the phone %lld.%lld Mbit/s", phone.txRate / 10, phone.txRate % 10); + } else if (phone.signalAvgDbm != kNoFigure) { + add(line, "; ", "average signal %lld dBm", phone.signalAvgDbm); } if (phone.rxRate != kNoFigure) { add(line, "; ", "from the phone %lld.%lld Mbit/s", phone.rxRate / 10, phone.rxRate % 10); diff --git a/platform/wifi_link.hpp b/platform/wifi_link.hpp index d7c143e..7bee56f 100644 --- a/platform/wifi_link.hpp +++ b/platform/wifi_link.hpp @@ -4,8 +4,10 @@ // Everything here only reads. Two sources, both the kernel's own figures: // - nl80211 (generic netlink), the interface `iw` uses: the phone's station entry on the car's access point (signal, -// bitrates, frames sent, retried and lost) and the access point's frequency; +// bitrate from the phone, frames sent, retried and lost) and the access point's frequency; // https://www.kernel.org/doc/html/latest/userspace-api/netlink/intro.html, include/uapi/linux/nl80211.h +// The rate towards the phone is left out: the WL18xx firmware chooses it, and the driver (wlcore) reported +// 1 Mbit/s on every car, the reference G20 included, whatever was sent. // - TCP_INFO on the Android Auto connection: round trip time and segments sent again. // Nothing identifies the phone in the log: no address is written. #ifndef ENTRY_AAD_PLATFORM_WIFI_LINK_HPP @@ -25,8 +27,8 @@ const int64_t kNoFigure = -0x7fffffffffffffffLL - 1; // a figure the driver did // One phone on the access point, as nl80211 reports it. struct WifiStation { uint8_t mac[6]; - int64_t signalDbm, signalAvgDbm; - int64_t txRate, rxRate; // in 100 kbit/s + int64_t signalDbm, signalAvgDbm; // signalDbm: the last frame received, when the chip measured it + int64_t rxRate; // in 100 kbit/s int64_t txFrames, txRetries, txFailed; // since the phone joined int64_t connectedS; // how long ago that was WifiStation(); diff --git a/tests/test_evo_input.cpp b/tests/test_evo_input.cpp index 344cf4a..4f9ad98 100644 --- a/tests/test_evo_input.cpp +++ b/tests/test_evo_input.cpp @@ -205,8 +205,8 @@ int main() { aa::CcsDecoder hk; evo::configureHardKeys(hk); CHECK(hk.slotKey(aa::CcsDecoder::slotByName("MENU")) == 0 && - hk.slotKey(aa::CcsDecoder::slotByName("OPTIONS")) == 0 && - hk.slotKey(aa::CcsDecoder::slotByName("MAP")) == 0); // iDrive's + hk.slotKey(aa::CcsDecoder::slotByName("OPTIONS")) == 0); // iDrive's + CHECK(hk.slotKey(aa::CcsDecoder::slotByName("MAP")) == aa::AAK_NAVIGATION); // as CarPlay's "maps:" (#1) CHECK(hk.slotKey(aa::CcsDecoder::slotByName("COM")) == aa::AAK_TEL); // not KEYCODE_CALL (phone redialled) CHECK(hk.slotKey(aa::CcsDecoder::slotByName("NAV")) == aa::AAK_NAVIGATION); CHECK(hk.slotKey(aa::CcsDecoder::slotByName("MEDIA")) == aa::AAK_MEDIA); @@ -433,6 +433,18 @@ int main() { lv.fkt = 0xC09; CHECK(!evo::decodeVolumeLevel(lv, level)); lv.fkt = 0xC08; + // The whole array (PosX 0): its first record, the front display's. Another display's record is not ours. + uint8_t whole[8] = {0x00, 0x00, 21, 0, 40, 9, 0, 40}, second[5] = {0x02, 0x00, 9, 0, 40}, + column[5] = {0x01, 0x01, 9, 0, 40}; + lv.data = whole; + lv.len = 8; + CHECK(evo::decodeVolumeLevel(lv, level) && level.value == 21); + lv.len = 5; + lv.data = second; + CHECK(!evo::decodeVolumeLevel(lv, level)); + lv.data = column; + CHECK(!evo::decodeVolumeLevel(lv, level)); + lv.data = ok; static const uint8_t record[2] = {0x01, 0x00}; evo::VmostMsgOut lg; evo::buildVmostGet(lg, 0x20, 0x00, 0xC08, record, 2); @@ -488,6 +500,35 @@ int main() { CHECK(evo::decodeVolumeButton(vv, &st) == 1 && st == 1); vv.len = 2; CHECK(evo::decodeVolumeButton(vv, &st) == 0); // short MFL frame + // The audio knob's push button, CECenterStack 15.0C.C04 [EPushButton]: 1 pressed, 0 released. + { + uint8_t pressed[1] = {1}, released[1] = {0}; + evo::VmostMsgView ab = vv; + ab.inst = 0x0C; + ab.fkt = 0xC04; + ab.len = 1; + ab.data = pressed; + CHECK(evo::decodeAudioButton(ab) == 1 && evo::decodeVolumeButton(ab, &st) == 0); + ab.data = released; + CHECK(evo::decodeAudioButton(ab) == 0); + ab.data = pressed; + ab.inst = 0x02; + CHECK(evo::decodeAudioButton(ab) == 0); // the steering wheel's instance + ab.inst = 0x0C; + ab.op = 0xF; + CHECK(evo::decodeAudioButton(ab) == 0); + ab.op = 0xC; + struct Presses { + static void cb(void* u) { ++*static_cast(u); } + }; + unsigned presses = 0; + evo::EvoKnob kb; + kb.setAudioButtonCallback(Presses::cb, &presses); + kb.onMessage(ab); + ab.data = released; + kb.onMessage(ab); + CHECK(presses == 1); + } struct Count { static void cb(unsigned s, void* u) { *static_cast(u) += s; } }; diff --git a/tests/test_evo_sdr.cpp b/tests/test_evo_sdr.cpp index a733487..2c265ad 100644 --- a/tests/test_evo_sdr.cpp +++ b/tests/test_evo_sdr.cpp @@ -11,6 +11,7 @@ #include #include +#include "car_brand.hpp" #include "dhu_sdp.h" #include "evo_gps.hpp" #include "evo_sdr_sensors.hpp" @@ -260,6 +261,34 @@ int main() { aa::buildCarServiceDiscovery(kDhuSdpProtobuf, kDhuSdpProtobufLen, nullptr, nullptr, wide); CHECK(shown(forWide, s) && s.resolution == 3 && s.marginW == 0 && s.marginH == 0 && s.bottom == 540 && s.right == 480 && s.top == 0 && s.left == 0 && s.touchW == 1920 && s.touchH == 1080); + // The brand file the iDrive app writes: "MINI" or "BMW", nothing else. + aa::CarBrand brand = aa::CarBrand::kBmw; + CHECK(aa::parseCarBrand("MINI\n", brand) && brand == aa::CarBrand::kMini && !strcmp(aa::brandName(brand), "MINI")); + CHECK(aa::parseCarBrand("BMW", brand) && brand == aa::CarBrand::kBmw && !strcmp(aa::brandName(brand), "BMW")); + CHECK(!aa::parseCarBrand("MINIS", brand) && !aa::parseCarBrand("mini", brand) && !aa::parseCarBrand("", brand) && + !aa::parseCarBrand(nullptr, brand) && brand == aa::CarBrand::kBmw); + CHECK(aa::surroundSide(aa::CarBrand::kBmw, 1280) == 0 && aa::surroundSide(aa::CarBrand::kMini, 1280) == 40 && + aa::surroundSide(aa::CarBrand::kMini, 800) == 25); + // A MINI: its round surround hides 40 columns on each side of the 1280x480 panel (25 of an 800x480 one). The + // phone keeps its UI away from them; the canvas, the touchscreen and the bottom inset stay. + aa::DisplayPlan mini = same, smallMini = small; + mini.hiddenSide = aa::surroundSide(aa::CarBrand::kMini, mini.width); + smallMini.hiddenSide = aa::surroundSide(aa::CarBrand::kMini, smallMini.width); + const std::vector forMini = + aa::buildCarServiceDiscovery(kDhuSdpProtobuf, kDhuSdpProtobufLen, nullptr, nullptr, mini, "MINI"); + CHECK(shown(forMini, s) && s.resolution == 2 && s.bottom == 240 && s.left == 40 && s.right == 40 && + s.touchW == 1280 && s.touchH == 720); + CHECK(shown(aa::buildCarServiceDiscovery(kDhuSdpProtobuf, kDhuSdpProtobufLen, nullptr, nullptr, smallMini), s) && + s.left == 25 && s.right == 25 && s.bottom == 0 && s.touchW == 800); + // The maker: "MINI" for the car and the head unit, at the top level and in the head unit info; "BMW" otherwise. + const std::string miniText(forMini.begin(), forMini.end()); + CHECK(plain.find("MINI") == std::string::npos && miniText.find("BMW") == std::string::npos); + size_t makes = 0; + for (size_t at = miniText.find("MINI"); at != std::string::npos; at = miniText.find("MINI", at + 1)) { + ++makes; + } + CHECK(makes == 4); // car make and head unit make, twice each + CHECK(aa::buildCarServiceDiscovery(kDhuSdpProtobuf, kDhuSdpProtobufLen, nullptr, nullptr, same, "") == unversioned); // Nothing but the picture and the touchscreen differs: every other channel is the reference car's. std::vector sensorsA, sensorsB; std::map> reference = channels(unversioned, sensorsA), diff --git a/tests/test_session_phone.cpp b/tests/test_session_phone.cpp index d677426..d71b46b 100644 --- a/tests/test_session_phone.cpp +++ b/tests/test_session_phone.cpp @@ -1017,6 +1017,78 @@ std::string quietPhone() { return std::string(); } +// An encrypted frame the head unit cannot decrypt: a record header TLS would never write. +void unreadable(Phone& phone) { + phone.raw("unreadable", bytes({0x00, kSealed, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04})); +} + +// The TLS stream breaks: 15 unreadable frames in a row are survived, the 16th ends the session. +std::string brokenStream() { + std::vector log; + Link link; + Phone phone(link.phoneFd, log); + phone.handshake(); + phone.discover(); + for (int i = 0; i < 15; ++i) { + unreadable(phone); + } + phone.settle(); // a plain ping, still answered + if (!link.session.isActive() || phone.lost()) { + return "15 unreadable frames ended the session"; + } + unreadable(phone); + if (!waitEnded(link.session)) { + return "the 16th unreadable frame in a row did not end the session"; + } + return std::string(); +} + +// The video focus indications the head unit sent, in order: "1" FOCUSED, "2" UNFOCUSED, each followed by 'u' when +// unrequested. +std::string focusTrail(const std::vector& log, size_t from) { + std::string trail; + for (size_t i = from; i < log.size(); ++i) { + const size_t at = log[i].find("hu ch=6 fl=0b 8008 08"); + if (at != std::string::npos && log[i].size() >= at + 27) { + trail += log[i][at + 22]; + trail += log[i].compare(at + 23, 4, "1001") == 0 ? "u" : ""; + } + } + return trail; +} + +// A frame the decoder lost: no request during the video's first 5 s, then the focus off and on, once in 10 s. +std::string keyframeAfterLoss() { + std::vector log; + Link link; + Phone phone(link.phoneFd, log); + phone.handshake(); + phone.discover(); + phone.send(6, kSealedCtl, bytes({0x00, 0x07, 0x08, 0x00, 0x10, 0x06})); + phone.send(6, kSealed, bytes({0x80, 0x00, 0x08, 0x03})); // video setup: FOCUSED at once + phone.settle(); + size_t from = log.size(); + link.session.postKeyframeRequest(); + phone.settle(); + if (!focusTrail(log, from).empty()) { + return "a keyframe was asked during the video's first seconds: " + focusTrail(log, from); + } + phone.headUnitPings(5200, true); + from = log.size(); + link.session.postKeyframeRequest(); + phone.settle(); + if (focusTrail(log, from) != "2u1u") { + return "after 5 s, focus trail '" + focusTrail(log, from) + "' instead of off then on"; + } + from = log.size(); + link.session.postKeyframeRequest(); + phone.settle(); + if (!focusTrail(log, from).empty() || !link.session.isActive()) { + return "a second request within 10 s was not held back"; + } + return std::string(); +} + struct Scenario { const char* name; void (*run)(std::vector&); @@ -1097,6 +1169,10 @@ int main(int argc, char** argv) { } const std::string quiet = writing ? std::string() : quietPhone(); takeEvents(); + const std::string broken = writing ? std::string() : brokenStream(); + takeEvents(); + const std::string keyframe = writing ? std::string() : keyframeAfterLoss(); + takeEvents(); fflush(stdout); dup2(console, 1); close(sink); @@ -1136,5 +1212,15 @@ int main(int argc, char** argv) { return 1; } puts("PASS session, quiet phone: answered pings keep it, unanswered ones end it within the silence limit"); + if (!broken.empty()) { + printf("FAIL session, broken stream: %s\n", broken.c_str()); + return 1; + } + puts("PASS session, broken stream: 16 encrypted frames in a row that do not decrypt end it, 15 do not"); + if (!keyframe.empty()) { + printf("FAIL session, keyframe after a lost frame: %s\n", keyframe.c_str()); + return 1; + } + puts("PASS session, keyframe after a lost frame: focus off and on, not in the first 5 s, once in 10 s"); return 0; } diff --git a/tests/test_video_presentation.cpp b/tests/test_video_presentation.cpp index fe49a9a..4dc6522 100644 --- a/tests/test_video_presentation.cpp +++ b/tests/test_video_presentation.cpp @@ -103,6 +103,7 @@ static bool configThenIdr() { } int main() { + typedef evo::FrameFate Fate; evo::EvoVideoConfig cfg; evo::EvoVideo video; assert(!video.isReady()); @@ -120,18 +121,18 @@ int main() { // SPS/PPS go in front of the first IDR; a frame the decoder refuses keeps them for the next IDR. video.postCodecConfig(kSpsPps, sizeof(kSpsPps)); - assert(video.postVideoFrame(kSlice, sizeof(kSlice), 0) && decoded == sizeof(kSlice)); + assert(video.postVideoFrame(kSlice, sizeof(kSlice), 0) == Fate::kDecoding && decoded == sizeof(kSlice)); decodeFailures = 1; - assert(!video.postVideoFrame(kIdr, sizeof(kIdr), 0) && configThenIdr()); - assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) && configThenIdr()); - assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) && decoded == sizeof(kIdr)); // sent once + assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) == Fate::kLost && configThenIdr()); + assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) == Fate::kDecoding && configThenIdr()); + assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) == Fate::kDecoding && decoded == sizeof(kIdr)); // sent once video.stop(); assert(!visible && !video.isVisible() && !video.isReady()); - assert(!video.postVideoFrame(kIdr, sizeof(kIdr), 0)); + assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) == Fate::kNoStream); // stopped: nothing lost assert(video.init(cfg) && video.start() && video.isReady()); - assert(opacity == 1.f && video.setOpacity(0.25f) && opacity == 0.25f); // fresh surface, fresh cache - assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) && configThenIdr()); // the new decoder gets SPS/PPS again + assert(opacity == 1.f && video.setOpacity(0.25f) && opacity == 0.25f); // fresh surface, fresh cache + assert(video.postVideoFrame(kIdr, sizeof(kIdr), 0) == Fate::kDecoding && configThenIdr()); // SPS/PPS again video.stop(); puts("PASS video presentation: visibility, opacity cache, camera hide, SPS/PPS after a refused IDR, reconnect"); } diff --git a/tests/test_volume_state.cpp b/tests/test_volume_state.cpp new file mode 100644 index 0000000..4b2a5cc --- /dev/null +++ b/tests/test_volume_state.cpp @@ -0,0 +1,69 @@ +// Copyright (c) 2026 Jiraiya43 +// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 +// What the volume pill shows: the knob's level on a change or after a key, never another source's, and mute. +#include +#include + +#include "volume_state.hpp" + +#define CHECK(x) \ + do { \ + if (!(x)) { \ + fprintf(stderr, "FAIL line %d: %s\n", __LINE__, #x); \ + exit(1); \ + } \ + } while (0) + +namespace { + +evo::VolumeLevel level(unsigned value, unsigned min, unsigned max) { + evo::VolumeLevel l = {value, min, max}; + return l; +} + +bool shows(const evo::VolumeState::Shown& s, unsigned value, unsigned min, unsigned max) { + return s.show && s.level.value == value && s.level.min == min && s.level.max == max; +} + +void atClock(uint32_t t) { + evo::VolumeState v; + CHECK(!v.known() && !v.muted()); + // The MINI F57 at connection: another source's level, again and again, while the knob's volume is 3. + for (int i = 0; i < 10; ++i) { + CHECK(!v.level(level(25, 25, 100), t + 300 * i).show); + } + CHECK(!v.known()); + // The first level of the knob's volume shows; the same one again, nothing having changed, does not. + CHECK(shows(v.level(level(3, 0, 100), t + 4000), 3, 0, 100)); + CHECK(!v.level(level(3, 0, 100), t + 4300).show); + // A change shows. + CHECK(shows(v.level(level(5, 0, 100), t + 5000), 5, 0, 100)); + // A volume key: the next level shows even unchanged (the knob at its end stop), not one past the window. + v.volumeKey(t + 6000); + CHECK(shows(v.level(level(5, 0, 100), t + 6100), 5, 0, 100)); + CHECK(!v.level(level(5, 0, 100), t + 6000 + evo::VolumeState::kKeyWindowMs + 1).show); + // The audio knob: muted, the speaker crossed out at the minimum; the level kept for later. + CHECK(shows(v.audioButton(t + 7000), 0, 0, 100) && v.muted()); + CHECK(shows(v.level(level(5, 0, 100), t + 7100), 0, 0, 100)); // within the button's window: still muted + // Pressed again: the sound back, at its level. + CHECK(shows(v.audioButton(t + 8000), 5, 0, 100) && !v.muted()); + // A volume step ends a mute, as iDrive does. + v.audioButton(t + 9000); + CHECK(v.muted()); + v.volumeKey(t + 9500); + CHECK(!v.muted() && shows(v.level(level(6, 0, 100), t + 9600), 6, 0, 100)); + // The button before any level: muted, nothing to show yet. + evo::VolumeState fresh; + CHECK(!fresh.audioButton(t).show && fresh.muted()); + CHECK(shows(fresh.level(level(8, 0, 40), t + 100), 0, 0, 40)); +} + +} // namespace + +int main() { + atClock(1000); + atClock(0xFFFFF000u); // across the 32-bit wrap of the millisecond clock + atClock(0); // a key at time 0 still counts + puts("PASS volume state: another source's level ignored, repeats held back, keys, mute by the audio knob"); + return 0; +} diff --git a/tests/test_wifi_link.cpp b/tests/test_wifi_link.cpp index 51f7651..ab9ea57 100644 --- a/tests/test_wifi_link.cpp +++ b/tests/test_wifi_link.cpp @@ -86,7 +86,7 @@ evo::WifiStation station(uint32_t frames, uint32_t retries, uint32_t failed, uin void stationMessages() { const evo::WifiStation s = station(5000, 300, 2, 125); CHECK(!memcmp(s.mac, kPhone, sizeof(kPhone))); - CHECK(s.signalDbm == -52 && s.signalAvgDbm == -51 && s.txRate == 1500 && s.rxRate == 1350); + CHECK(s.signalDbm == -52 && s.signalAvgDbm == -51 && s.rxRate == 1350); CHECK(s.txFrames == 5000 && s.txRetries == 300 && s.txFailed == 2 && s.connectedS == 125); // A driver that gives little: what is missing stays "no figure". @@ -98,9 +98,19 @@ void stationMessages() { bare.nested(NL80211_ATTR_STA_INFO, info); evo::WifiStation little; CHECK(evo::parseWifiStation(&bare.bytes[0], bare.bytes.size(), little)); - CHECK(little.signalDbm == -70 && little.signalAvgDbm == evo::kNoFigure && little.txRate == evo::kNoFigure && + CHECK(little.signalDbm == -70 && little.signalAvgDbm == evo::kNoFigure && little.rxRate == evo::kNoFigure && little.txFrames == evo::kNoFigure && little.connectedS == evo::kNoFigure); + // A level of 0 dBm is the WL18xx's "not measured" (seen in every car log): no figure. + Attrs zero; + Attrs zeroInfo; + zeroInfo.u8(NL80211_STA_INFO_SIGNAL, 0); + zeroInfo.u8(NL80211_STA_INFO_SIGNAL_AVG, static_cast(-68)); + zero.put(NL80211_ATTR_MAC, kPhone, sizeof(kPhone)); + zero.nested(NL80211_ATTR_STA_INFO, zeroInfo); + CHECK(evo::parseWifiStation(&zero.bytes[0], zero.bytes.size(), little)); + CHECK(little.signalDbm == evo::kNoFigure && little.signalAvgDbm == -68); + // No station address: not a station. Attrs anonymous; anonymous.nested(NL80211_ATTR_STA_INFO, info); @@ -150,13 +160,13 @@ evo::WifiSample sample(uint32_t atMs, uint32_t frames, uint32_t retries, uint32_ void logLines() { const evo::WifiSample first = sample(1000, 5000, 300, 2, 125, 4250, 3); CHECK(evo::describeWifiLink(first, nullptr) == - "5180 MHz; signal -52 dBm (average -51); to the phone 150.0 Mbit/s; from the phone 135.0 Mbit/s; " + "5180 MHz; signal -52 dBm (average -51); from the phone 135.0 Mbit/s; " "since it joined: 5000 frames sent, 300 retried, 2 lost; on the Wi-Fi for 125 s; " "TCP round trip 4.2 ms, 3 segment(s) sent again since it opened"); // Ten seconds later: what happened in between. const evo::WifiSample second = sample(11040, 5812, 335, 2, 135, 38900, 9); CHECK(evo::describeWifiLink(second, &first) == - "5180 MHz; signal -52 dBm (average -51); to the phone 150.0 Mbit/s; from the phone 135.0 Mbit/s; " + "5180 MHz; signal -52 dBm (average -51); from the phone 135.0 Mbit/s; " "in 10 s: 812 frames sent, 35 retried, 0 lost; on the Wi-Fi for 135 s; " "TCP round trip 38.9 ms, 6 segment(s) sent again"); // The phone left the Wi-Fi and came back: its counters started again, nothing is subtracted. @@ -189,7 +199,12 @@ void logLines() { bare.station.txFrames = bare.station.txRetries = bare.station.txFailed = bare.station.connectedS = evo::kNoFigure; bare.station.signalAvgDbm = bare.station.rxRate = evo::kNoFigure; bare.hasTcp = false; - CHECK(evo::describeWifiLink(bare, nullptr) == "5180 MHz; signal -52 dBm; to the phone 150.0 Mbit/s"); + CHECK(evo::describeWifiLink(bare, nullptr) == "5180 MHz; signal -52 dBm"); + // The chip did not measure the last frame: the average alone. + evo::WifiSample unmeasured = first; + unmeasured.station.signalDbm = evo::kNoFigure; + unmeasured.hasTcp = false; + CHECK(evo::describeWifiLink(unmeasured, nullptr).find("5180 MHz; average signal -51 dBm; from the phone") == 0); } // A TCP connection on loopback: the car's end in car, the phone's in phone.