# sebaubuntu/simplesimhubarduino architecture

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

- Interactive diagram: https://gitdiagram.com/sebaubuntu/simplesimhubarduino
- Repository: https://github.com/sebaubuntu/simplesimhubarduino

## Overview

##### Project Type and Purpose
- This is an embedded integration adapter for Arduino (SimpleSimHubArduino).
- It reads game telemetry from SimHub over the custom serial protocol, decodes it, and drives a car instrument cluster via a CAN bus (MCP2515 CAN controller).

##### File Structure Analysis
- Top-level files:
- SimpleSimHubArduino.ino – main Arduino sketch
- Various headers (.h) implementing serial I/O, protocol, debouncing, ring buffer, button handling, LED backpack driver, PWM frequency helper
- src/ directory – C++ modules:
- CanFuzzer (generates CAN frames)
- MessageDebouncer (debounces incoming CAN messages)
- StateHolder (holds decoded SimHub state)
- Cluster.h (abstract cluster interface)
- src/clusters/ – one subfolder per supported car cluster (Citroën C5 II, Peugeot 208 I, 3008 I, multifunction display), each with its own Cluster.h, commands.h, README
- Configuration: SHCustomProtocol.h selects which cluster to compile in

##### README Insights
- Explains hardware BOM (Arduino, MCP2515, cluster, wiring)
- Defines the SimHub custom protocol format (semicolon-separated telemetry values)
- Usage steps: install libraries, enable cluster, wire, upload, configure SimHub

##### Main Components
a. External Systems & Hardware
- PC running SimHub (sends telemetry via USB-serial)
- Arduino board (runs the sketch)
- MCP2515 CAN module (connected via SPI)
- Car instrument cluster (12 V CAN bus node)
b. Software Modules on Arduino
- Serial I/O & SHCustomProtocol parser (reads raw custom message, populates State struct)
- StateHolder (central store for all telemetry variables)
- MessageDebouncer (filters incoming CAN if two-way communication is needed)
- CanFuzzer / Cluster command generator (translates State into CAN frames using cluster’s commands.h)
- MCP2515 library interface (sends frames onto CAN bus)
- Cluster-specific logic (in src/clusters/…) selected at compile time

##### Architectural Patterns & Design Principles
- Modular abstraction of clusters: common interface (Cluster.h) + per-cluster commands file
- Separation of concerns: parsing, state management, message generation, hardware I/O
- Compile-time feature selection: only include one cluster implementation to reduce code size
- Debouncing filter for CAN bus noise or two-way messages

##### Essential Elements
- Component labels (e.g., “SHCustomProtocol Parser,” “StateHolder”)
- Notes on configuration: “Enabled via SHCustomProtocol.h”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems & Hardware
    PC["PC running SimHub"]:::hardware
    Arduino["Arduino Board"]:::hardware
    MCP2515["MCP2515 CAN Module<br/>(SPI)"]:::hardware
    ClusterCar["Car Instrument Cluster<br/>(CAN Bus)"]:::hardware

    %% Software Modules on Arduino
    subgraph "Arduino Software" 
        direction TB
        subgraph "Protocol & Parsing" 
            direction TB
            Parser["SHCustomProtocol Parser<br/>& Serial I/O"]:::software
        end
        subgraph "State Management"
            StateHolder["StateHolder<br/>(Telemetry Store)"]:::software
        end
        subgraph "Message Processing"
            Debouncer["MessageDebouncer<br/>(CAN Filter)"]:::software
            Fuzzer["CanFuzzer / Cluster Cmd Generator"]:::software
        end
        subgraph "Cluster Logic<br/>(compile-time selected)"
            direction TB
            ClusterInterface["Cluster Interface<br/>(Cluster.h)"]:::software
            subgraph "Cluster Commands"
                direction TB
                Citroen["Citroën C5 II"]:::software
                Peugeot208["Peugeot 208 I"]:::software
                Peugeot3008["Peugeot 3008 I"]:::software
                MultiDisplay["Peugeot Multifunc. Disp."]:::software
            end
        end
    end

    %% Connections & Data Flow
    PC -->|"Telemetry data<br/>(USB Serial)"| Parser
    Parser -->|"Parsed values"| StateHolder
    StateHolder -->|"State update"| Fuzzer
    Fuzzer -->|"CAN frames"| MCP2515
    MCP2515 -->|"SPI"| Arduino
    MCP2515 -->|"CAN bus"| ClusterCar
    ClusterCar -->|"Optional readback"| Debouncer
    Debouncer -->|"Filtered CAN"| StateHolder

    %% Click Events
    click Parser "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/SHCustomProtocol.h"
    click Arduino "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/SimpleSimHubArduino.ino"
    click StateHolder "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/StateHolder.h"
    click Debouncer "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/MessageDebouncer.h"
    click Fuzzer "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/CanFuzzer.h"
    click ClusterInterface "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/Cluster.h"
    click Citroen "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/clusters/citroen_c5_ii/commands.h"
    click Peugeot208 "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/clusters/peugeot_208_i/commands.h"
    click Peugeot3008 "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/clusters/peugeot_3008_i/commands.h"
    click MultiDisplay "https://github.com/sebaubuntu/simplesimhubarduino/blob/main/src/clusters/peugeot_multifunction_display/commands.h"

    %% Styles
    classDef hardware fill:#ffe4b5,stroke:#333,stroke-width:1px
    classDef software fill:#e6e6fa,stroke:#333,stroke-width:1px
```
