# trentseed/bmw_e46_android_rpi_ibus_controller architecture

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

- Interactive diagram: https://gitdiagram.com/trentseed/bmw_e46_android_rpi_ibus_controller
- Repository: https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller

## Overview

##### Project type and purpose
- This is an IoT-style, full-stack “connected car” system.
- Purpose: Provide an Android (tablet/phone) + Android Wear UI to control a BMW’s IBUS network via a Raspberry Pi acting as a bridge between Bluetooth and the car’s IBUS USB adapter, running a Python-based controller service.

##### File structure
- connected_car_app/
- app/           → Android mobile/tablet application (Activities, Adapters, layouts, resources)
- common/        → Shared Android library: BluetoothInterface, IBUSPacket, ControllerMessage, etc.
- ibuswear/      → Android Wear standalone app (Fragments, layouts, grid pager)
- connected_car_controller/
- controllers/   → Model-specific logic (base, BMW e46 implementation)
- interfaces/    → Abstractions for BT, CAN bus, IBUS protocols
- start_controller.py → Entry point for Python app (CLI “bmw-e46” driver)
- etc/config.ini → Runtime configuration (BT MAC, ports)
- Dockerfile + docker-compose.yml → Containerized deployment
- tests/             → Unit tests for controllers and interfaces
- setup.py, requirements.txt → Packaging and Python dependencies

##### README for additional insights
- Three physical/hardware components: Android Tablet, Raspberry Pi, IBUS USB Adapter
- Bluetooth pairing used between Android devices and Pi
- Optionally containerized via Docker
- Workflow: UI ↔ Bluetooth ↔ Python controller ↔ USB/UART ↔ IBUS network

- Blue for Android components
- Green for Python/controller components
- Gray for hardware (Bluetooth radio, USB Adapter, IBUS network)
- Annotations of protocols/ports (e.g., Bluetooth SPP UUID, USB-tty device, config.ini path)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Android (Client)"
        direction TB
        MobileApp["Android Mobile/Tablet App"]:::frontend
        WearApp["Android Wear App"]:::frontend
        SharedLib["Shared Android Library"]:::frontend
        AndroidBT["BluetoothInterface"]:::frontend
        Packet["IBUSPacket"]:::frontend
        Msg["ControllerMessage"]:::frontend
    end

    subgraph "Raspberry Pi (Edge Server)"
        direction TB
        subgraph "Docker Container"
            direction TB
            Start["start_controller.py (Entry Point)"]:::controller
            ControllersDir["controllers/"]:::controller
            BMWe46["e46.py (BMW e46 Controller)"]:::controller
            Factory["factory.py (Controller Factory)"]:::controller
            InterfacesDir["interfaces/"]:::controller
            PyBT["bt.py (Bluetooth Interface)"]:::controller
            PyIBUS["ibus.py (IBUS Interface)"]:::controller
            PyCAN["canbus.py (CANBus Interface)"]:::controller
            Config["config.ini"]:::controller
        end
        Dockerfile["Dockerfile"]:::controller
        Compose["docker-compose.yml"]:::controller
        Tests["unit tests/"]:::controller
    end

    subgraph "Hardware"
        direction TB
        BluetoothRadio["Bluetooth Radio"]:::hardware
        USBAdapter["IBUS USB Adapter"]:::hardware
        IBUSNet["BMW IBUS Network"]:::hardware
    end

    MobileApp -->|"uses"| AndroidBT
    MobileApp -->|"uses"| Packet
    MobileApp -->|"uses"| Msg
    WearApp -->|"uses"| AndroidBT
    WearApp -->|"uses"| Packet
    WearApp -->|"uses"| Msg
    SharedLib -->|"provides"| AndroidBT
    SharedLib -->|"provides"| Packet
    SharedLib -->|"provides"| Msg

    AndroidBT -->|"SPP over Bluetooth"| BluetoothRadio
    BluetoothRadio -->|"SPP"| PyBT
    PyBT -->|"delivers UI commands"| Factory
    Factory -->|"selects controller"| BMWe46
    BMWe46 -->|"issues IBUS frames"| PyIBUS
    PyIBUS -->|"USB UART"| USBAdapter
    USBAdapter -->|"on IBUS"| IBUSNet
    IBUSNet -->|"response frames"| USBAdapter
    USBAdapter -->|"to interface"| PyIBUS
    PyIBUS -->|"to controller"| PyBT
    PyBT -->|"to UI"| BluetoothRadio
    BluetoothRadio -->|"to UI"| MobileApp
    BluetoothRadio -->|"to UI"| WearApp

    click MobileApp "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_app/app"
    click WearApp "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_app/ibuswear"
    click SharedLib "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_app/common"
    click AndroidBT "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_app/common/src/main/java/com/trentseed/bmw_rpi_ibus_controller/common/BluetoothInterface.java"
    click Packet "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_app/common/src/main/java/com/trentseed/bmw_rpi_ibus_controller/common/IBUSPacket.java"
    click Msg "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_app/common/src/main/java/com/trentseed/bmw_rpi_ibus_controller/common/ControllerMessage.java"
    click Start "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/start_controller.py"
    click ControllersDir "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_controller/controllers/"
    click BMWe46 "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/controllers/bmw/e46.py"
    click Factory "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/controllers/factory.py"
    click InterfacesDir "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_controller/interfaces/"
    click PyBT "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/interfaces/bt.py"
    click PyIBUS "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/interfaces/ibus.py"
    click PyCAN "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/interfaces/canbus.py"
    click Config "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/etc/config.ini"
    click Dockerfile "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_controller/Dockerfile"
    click Compose "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/blob/master/connected_car_controller/docker-compose.yml"
    click Tests "https://github.com/trentseed/bmw_e46_android_rpi_ibus_controller/tree/master/connected_car_controller/test/unit"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef controller fill:#90EE90,stroke:#333,stroke-width:1px
    classDef hardware fill:#D3D3D3,stroke:#333,stroke-width:1px
```
