# phuonghoang2502/in_vehicle_infotainment architecture

> Architecture diagram of the GitHub repository phuonghoang2502/in_vehicle_infotainment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phuonghoang2502/in_vehicle_infotainment
- Repository: https://github.com/phuonghoang2502/in_vehicle_infotainment

## Overview

##### Project type and purpose
- This is a full-stack, embedded In-Car Infotainment system built on Qt/QML for the UI and C++ for back-end “units,” communicating over CAN (SocketCAN/QtSerialBus) to an STM32 microcontroller and peripherals.

##### File structure
- Top-level “Infotainment-QT” holds the main QtQuick UI (QML + C++ CanController).
- “Infotainment” folder contains multiple C++ service modules (CANSender, HeadUnit, IPCManager, IVICompositor, InstrumentCluster, PDCUnit, PiracerController, PiracerSender, RemoteSpeaker) plus the top-level main.qml and main.cpp.
- Each service module pairs a QtClass (QML bridge) with a SenderClass (CAN or IPC publisher) and StubImpl (host-side test stub).
- Build files (.pro, qml.qrc) and scripts (enable_can.sh, vcan.sh) show deployment choices.

##### Extract additional insights from README
- UI uses QtQuick Controls and QtSerialBus for CAN.
- Virtual CAN (vcan0) for host simulation.
- STM32 firmware sits on the bus side (MCP2515 CAN, LDR, ADC, ultrasonic sensor).

- Qt UI Layer
– Infotainment-QT QML screens (Cluster, Home, Navigation, Settings)
– main.qml + CanController (Infotainment-QT/CanController.cpp)
- Application Logic Layer
– C++ Qt classes for each “unit”:
- HeadUnitQtClass
- IVICompositorQtClass
- InstrumentClusterQtClass
- PDCUnitQtClass
- IPCManagerSenderClass
- PiracerController & PiracerSender
- RemoteSpeaker
– Each publishes/subscribes on CAN via QtSerialBus
- CAN Communication Layer
– QtSerialBus / SocketCAN interface
– Virtual CAN adapter (vcan0) or MCP2515 hardware
- Embedded Firmware Layer
– STM32 CAN drivers for MCP2515, sensor drivers (LDR, ADC, HC-SR04)
- Physical Hardware Layer
– Actual CAN bus wiring, MCP2515 module, sensors, actuators

– UI events → C++ QtClass → SenderClass → QtSerialBus → CAN bus
– CAN bus ↔ StubImpl (for host simulation) / real STM32 firmware
– Firmware ↔ sensors/peripherals → CAN bus → back to Qt services → UI updates

c. Architectural patterns & design principles
– MVC/MVVM: QML view + C++ model/controllers
– Micro-service style: each “unit” (HeadUnit, IVICompositor, etc.) is an isolated publisher/subscriber on the CAN bus
– Abstraction for testing: StubImpl classes swap out real CAN endpoints

d. Key technologies/frameworks
– QtQuick Controls 2, QML
– QtSerialBus (CAN)
– SocketCAN (vcan0 or MCP2515 hardware)
– STM32 HAL libraries (for firmware)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "Qt UI Layer"
        direction TB
        MainQML["main.qml"]:::ui
        MainCPP["main.cpp"]:::ui
        CanController["CanController.cpp/.h"]:::ui
        ClusterScreen["ClusterScreen.qml"]:::ui
        HomeScreen["HomeScreen.qml"]:::ui
        NavigationScreen["NavigationScreen.qml"]:::ui
        VideoSplash["VideoSplash.qml"]:::ui
    end

    %% Application Logic Layer
    subgraph "Application Logic Layer"
        direction TB
        CANSender["CANSender"]:::service
        HeadUnit["HeadUnitQtClass/Sender/Stub"]:::service
        IVICompositor["IVICompositorQtClass/Stub"]:::service
        InstrumentCluster["InstrumentClusterQtClass/Sender/Stub"]:::service
        PDCUnit["PDCUnitQtClass/Sender/Stub"]:::service
        IPCManager["IPCManager/Sender/Stub"]:::service
        PiracerController["PiracerController/Controller/Stub"]:::service
        PiracerSender["PiracerSender/PiracerClass/Stub"]:::service
        RemoteSpeaker["RemoteSpeaker/RemoteSpeaker/DataBuffer/Stub"]:::service
    end

    %% Communication Layer
    subgraph "CAN Communication Layer"
        direction TB
        QtSerialBus["QtSerialBus/SocketCAN"]:::comm
        VirtualCAN["vcan0 (Virtual CAN)"]:::comm
        MCP2515["MCP2515 CAN Interface"]:::comm
    end

    %% Firmware Layer
    subgraph "Embedded Firmware Layer"
        direction TB
        STM32Drivers["STM32 CAN Drivers"]:::firmware
        SensorDrivers["Sensors (LDR, ADC, Ultrasonic)"]:::firmware
    end

    %% Hardware Layer
    subgraph "Physical Hardware Layer"
        direction TB
        CANBus["CAN Bus Wiring"]:::hardware
        Sensors["Physical Sensors/Actuators"]:::hardware
    end

    %% Data Flow
    MainQML -->|"UI event"| HeadUnit
    MainQML -->|"UI event"| IVICompositor
    MainQML -->|"UI event"| InstrumentCluster
    MainQML -->|"UI event"| PDCUnit
    MainQML -->|"UI event"| IPCManager
    MainQML -->|"UI event"| PiracerController
    MainQML -->|"UI event"| PiracerSender
    MainQML -->|"UI event"| RemoteSpeaker
    MainCPP -->|initializes| CanController
    CanController -->|controls| HeadUnit
    CanController -->|controls| IVICompositor
    CanController -->|controls| InstrumentCluster
    CanController -->|controls| PDCUnit
    CanController -->|controls| IPCManager
    CanController -->|controls| PiracerController
    CanController -->|controls| PiracerSender
    CanController -->|controls| RemoteSpeaker

    HeadUnit -->|"publish/subscribe"| QtSerialBus
    IVICompositor -->|"publish/subscribe"| QtSerialBus
    InstrumentCluster -->|"publish/subscribe"| QtSerialBus
    PDCUnit -->|"publish/subscribe"| QtSerialBus
    IPCManager -->|"publish/subscribe"| QtSerialBus
    PiracerController -->|"publish/subscribe"| QtSerialBus
    PiracerSender -->|"publish/subscribe"| QtSerialBus
    RemoteSpeaker -->|"publish/subscribe"| QtSerialBus

    QtSerialBus -->|"via vcan0"| VirtualCAN
    QtSerialBus -->|"via MCP2515"| MCP2515

    VirtualCAN -->|"test stub"| CANSender
    VirtualCAN -->|"test stub"| HeadUnit
    VirtualCAN -->|"test stub"| IVICompositor
    VirtualCAN -->|"test stub"| InstrumentCluster
    VirtualCAN -->|"test stub"| PDCUnit
    VirtualCAN -->|"test stub"| IPCManager
    VirtualCAN -->|"test stub"| PiracerController
    VirtualCAN -->|"test stub"| PiracerSender
    VirtualCAN -->|"test stub"| RemoteSpeaker

    MCP2515 -->|"to bus"| CANBus
    CANBus -->|"to firmware"| STM32Drivers
    STM32Drivers -->|"interacts"| SensorDrivers
    SensorDrivers -->|"sensor data"| CANBus
    CANBus -->|"to services"| QtSerialBus

    %% Click Events UI
    click MainQML "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/main.qml"
    click MainCPP "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/main.cpp"
    click CanController "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/CanController.cpp"
    click ClusterScreen "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/ClusterScreen.qml"
    click HomeScreen "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/HomeScreen.qml"
    click NavigationScreen "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/NavigationScreen.qml"
    click VideoSplash "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment-QT/VideoSplash.qml"

    %% Click Events Services
    click CANSender "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/CANSender/CANSender.cpp"
    click CANSender "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/CANSender/CANSenderStubImpl.cpp"
    click HeadUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/HeadUnit/HeadUnitQtClass.cpp"
    click HeadUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/HeadUnit/HeadUnitQtClass.hpp"
    click HeadUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/HeadUnit/HeadUnitSenderClass.cpp"
    click HeadUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/HeadUnit/HeadUnitSenderClass.hpp"
    click HeadUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/HeadUnit/HeadUnitStubImpl.cpp"
    click IVICompositor "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/IVICompositor/IVICompositorQtClass.cpp"
    click IVICompositor "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/IVICompositor/IVICompositorQtClass.hpp"
    click IVICompositor "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/IVICompositor/IVICompositorStubImpl.cpp"
    click InstrumentCluster "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/InstrumentCluster/InstrumentClusterQtClass.cpp"
    click InstrumentCluster "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/InstrumentCluster/InstrumentClusterQtClass.hpp"
    click InstrumentCluster "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/InstrumentCluster/InstrumentClusterSenderClass.cpp"
    click InstrumentCluster "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/InstrumentCluster/InstrumentClusterSenderClass.hpp"
    click InstrumentCluster "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/InstrumentCluster/InstrumentClusterStubImpl.cpp"
    click PDCUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/PDCUnit/PDCUnitQtClass.cpp"
    click PDCUnit "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/PDCUnit/PDCUnitQtClass.hpp"
    click IPCManager "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/IPCManager/IPCManager.cpp"
    click IPCManager "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/IPCManager/IPCManagerSenderClass.cpp"
    click IPCManager "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/IPCManager/IPCManagerSenderClass.hpp"
    click PiracerController "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/PiracerController/ControllerClass.cpp"
    click PiracerController "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/PiracerController/ControllerClass.hpp"
    click PiracerSender "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/PiracerSender/PiracerClass.cpp"
    click PiracerSender "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/PiracerSender/PiracerClass.hpp"
    click RemoteSpeaker "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/RemoteSpeaker/RemoteSpeaker.cpp"
    click RemoteSpeaker "https://github.com/phuonghoang2502/in_vehicle_infotainment/blob/main/Infotainment/RemoteSpeaker/DataBuffer.cpp"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085
    classDef service fill:#d4edda,stroke:#155724,color:#155724
    classDef comm fill:#fff3cd,stroke:#856404,color:#856404
    classDef firmware fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef hardware fill:#f8f9fa,stroke:#343a40,color:#343a40
```
