# cpsdrone/cps architecture

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

- Interactive diagram: https://gitdiagram.com/cpsdrone/cps
- Repository: https://github.com/cpsdrone/cps

## Overview

This repository is a collection of Arduino libraries and communication experiments for the CPS submarine project, not a single submarine application. The clearest end-to-end runtime path in the sampled code is a Raspberry Pi-side SPI client sending an instruction to an Arduino slave, which dispatches it and prepares a response. The README also describes camera streaming, but the tree contains no evident camera or streaming implementation. The graph preserves major library capabilities; several connections are omitted because their source was not sampled.

Main entry points: [`programs/communication_stuff/communication/lib/spi.cpp`](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/lib/spi.cpp) (Host SPI Client), [`programs/communication_stuff/communication/arduino/src/main.cpp`](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/src/main.cpp) (Arduino SPI Slave), [`programs/MORE LIBRARIES/Ethernet/src/EthernetClient.cpp`](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Ethernet/src/EthernetClient.cpp) (Ethernet Client), [`programs/MORE LIBRARIES/Temboo/src/utility/MQTTClient.h`](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Temboo/src/utility/MQTTClient.h) (MQTT Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_comms["SPI Communication"]
  node_spi_host["Host SPI Client<br/>[spi.cpp]"]
  node_spi_header["SPI Interface<br/>[spi.h]"]
  node_arduino_main["Arduino SPI Slave<br/>[main.cpp]"]
  node_ring_buffer["Bounded Buffers<br/>[bounded.hpp]"]
  node_instructions["Slave Instructions"]
  node_examples["Communication Examples<br/>[client.cpp]"]
end

subgraph group_sensing["Sensing And Control"]
  node_lsm_sensor["LSM9DS1 Sensor"]
  node_sensor_api["Sensor API<br/>[Adafruit_Sensor.h]"]
  node_temperature["Temperature Probes"]
  node_pid["PID Controller<br/>[PID_v1.cpp]"]
  node_kalman["Kalman Filter<br/>[Kalman.cpp]"]
  node_servo["Servo Output<br/>[Servo.cpp]"]
  node_robot_text["Robot Text Input"]
end

subgraph group_network["Networking"]
  node_ethernet["Ethernet Client<br/>[EthernetClient.cpp]"]
  node_ethernet_core["Ethernet Core<br/>[Ethernet.h]"]
  node_wifi_client["WiFi Client<br/>[WiFiClient.cpp]"]
  node_wifi_firmware["WiFi Firmware Stack<br/>[main.c]"]
  node_mqtt["MQTT Client<br/>[MQTTClient.h]"]
  node_mqtt_packets["MQTT Packets<br/>[MQTTPacket.h]"]
  node_bridge_http["Bridge HTTP Client<br/>[HttpClient.cpp]"]
end

subgraph group_platform["Platform Interfaces"]
  node_firmata_stream["Firmata Ethernet Stream"]
  node_gsm_client["GSM Client Provider"]
  node_motor_display["MAX7456 Display<br/>[MAX7456.cpp]"]
end

node_host(("Host Application"))

node_host -.->|"requests transfers"| node_spi_host
node_spi_host -.->|"sends instructions"| node_arduino_main
node_arduino_main -->|"uses buffers"| node_ring_buffer
node_arduino_main -->|"dispatches instruction"| node_instructions
node_spi_host -->|"implements interface"| node_spi_header
node_ethernet -->|"uses socket API"| node_ethernet_core
node_mqtt -->|"uses packet types"| node_mqtt_packets
node_bridge_http -.->|"exposes HTTP calls"| node_host
node_firmata_stream -->|"wraps client"| node_ethernet

click node_spi_host "https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/lib/spi.cpp"
click node_spi_header "https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/lib/spi.h"
click node_arduino_main "https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/src/main.cpp"
click node_ring_buffer "https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/lib/bounded.hpp"
click node_instructions "https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/lib/slave_instructions.hpp"
click node_examples "https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/example%20code/client.cpp"
click node_lsm_sensor "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Adafruit_LSM9DS1-master/Adafruit_LSM9DS1.cpp"
click node_sensor_api "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Adafruit_Sensor-master/Adafruit_Sensor.h"
click node_temperature "https://github.com/cpsdrone/cps/blob/master/programs/LIBRARIES/DallasTemperature/DallasTemperature.cpp"
click node_pid "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Arduino-PID-Library-master/PID_v1.cpp"
click node_kalman "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Kalman_Filter_Library-1.0.2/Kalman.cpp"
click node_servo "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Servo/src/avr/Servo.cpp"
click node_robot_text "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Robot_Control/src/utility/RobotTextManager.cpp"
click node_ethernet "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Ethernet/src/EthernetClient.cpp"
click node_ethernet_core "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Ethernet/src/Ethernet.h"
click node_wifi_client "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/WiFi/src/WiFiClient.cpp"
click node_wifi_firmware "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/WiFi/extras/wifiHD/src/main.c"
click node_mqtt "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Temboo/src/utility/MQTTClient.h"
click node_mqtt_packets "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Temboo/src/utility/MQTTPacket.h"
click node_bridge_http "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Bridge/src/HttpClient.cpp"
click node_firmata_stream "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Firmata/utility/EthernetClientStream.h"
click node_gsm_client "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/GSM/src/GSM3ShieldV1ClientProvider.cpp"
click node_motor_display "https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/MAX7456/MAX7456.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spi_host,node_spi_header,node_arduino_main,node_ring_buffer,node_instructions,node_examples toneBlue
class node_lsm_sensor,node_sensor_api,node_temperature,node_pid,node_kalman,node_servo,node_robot_text toneAmber
class node_ethernet,node_ethernet_core,node_wifi_client,node_wifi_firmware,node_mqtt,node_mqtt_packets,node_bridge_http toneMint
class node_firmata_stream,node_gsm_client,node_motor_display toneRose
class node_host toneIndigo
```

## Components

### SPI Communication

- [Host SPI Client](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/lib/spi.cpp): `programs/communication_stuff/communication/lib/spi.cpp`
- [SPI Interface](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/lib/spi.h): `programs/communication_stuff/communication/lib/spi.h`
- [Arduino SPI Slave](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/src/main.cpp): `programs/communication_stuff/communication/arduino/src/main.cpp`
- [Bounded Buffers](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/lib/bounded.hpp): `programs/communication_stuff/communication/arduino/lib/bounded.hpp`
- [Slave Instructions](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/arduino/lib/slave_instructions.hpp): `programs/communication_stuff/communication/arduino/lib/slave_instructions.hpp`
- [Communication Examples](https://github.com/cpsdrone/cps/blob/master/programs/communication_stuff/communication/example%20code/client.cpp): `programs/communication_stuff/communication/example code/client.cpp`

### Sensing And Control

- [LSM9DS1 Sensor](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Adafruit_LSM9DS1-master/Adafruit_LSM9DS1.cpp): `programs/MORE LIBRARIES/Adafruit_LSM9DS1-master/Adafruit_LSM9DS1.cpp`
- [Sensor API](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Adafruit_Sensor-master/Adafruit_Sensor.h): `programs/MORE LIBRARIES/Adafruit_Sensor-master/Adafruit_Sensor.h`
- [Temperature Probes](https://github.com/cpsdrone/cps/blob/master/programs/LIBRARIES/DallasTemperature/DallasTemperature.cpp): `programs/LIBRARIES/DallasTemperature/DallasTemperature.cpp`
- [PID Controller](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Arduino-PID-Library-master/PID_v1.cpp): `programs/MORE LIBRARIES/Arduino-PID-Library-master/PID_v1.cpp`
- [Kalman Filter](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Kalman_Filter_Library-1.0.2/Kalman.cpp): `programs/MORE LIBRARIES/Kalman_Filter_Library-1.0.2/Kalman.cpp`
- [Servo Output](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Servo/src/avr/Servo.cpp): `programs/MORE LIBRARIES/Servo/src/avr/Servo.cpp`
- [Robot Text Input](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Robot_Control/src/utility/RobotTextManager.cpp): `programs/MORE LIBRARIES/Robot_Control/src/utility/RobotTextManager.cpp`

### Networking

- [Ethernet Client](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Ethernet/src/EthernetClient.cpp): `programs/MORE LIBRARIES/Ethernet/src/EthernetClient.cpp`
- [Ethernet Core](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Ethernet/src/Ethernet.h): `programs/MORE LIBRARIES/Ethernet/src/Ethernet.h`
- [WiFi Client](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/WiFi/src/WiFiClient.cpp): `programs/MORE LIBRARIES/WiFi/src/WiFiClient.cpp`
- [WiFi Firmware Stack](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/WiFi/extras/wifiHD/src/main.c): `programs/MORE LIBRARIES/WiFi/extras/wifiHD/src/main.c`
- [MQTT Client](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Temboo/src/utility/MQTTClient.h): `programs/MORE LIBRARIES/Temboo/src/utility/MQTTClient.h`
- [MQTT Packets](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Temboo/src/utility/MQTTPacket.h): `programs/MORE LIBRARIES/Temboo/src/utility/MQTTPacket.h`
- [Bridge HTTP Client](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Bridge/src/HttpClient.cpp): `programs/MORE LIBRARIES/Bridge/src/HttpClient.cpp`

### Platform Interfaces

- [Firmata Ethernet Stream](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/Firmata/utility/EthernetClientStream.h): `programs/MORE LIBRARIES/Firmata/utility/EthernetClientStream.h`
- [GSM Client Provider](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/GSM/src/GSM3ShieldV1ClientProvider.cpp): `programs/MORE LIBRARIES/GSM/src/GSM3ShieldV1ClientProvider.cpp`
- [MAX7456 Display](https://github.com/cpsdrone/cps/blob/master/programs/MORE%20LIBRARIES/MAX7456/MAX7456.cpp): `programs/MORE LIBRARIES/MAX7456/MAX7456.cpp`

### Other components

- **Host Application**

## Connections

- Host Application → Host SPI Client: requests transfers
- Host SPI Client → Arduino SPI Slave: sends instructions
- Arduino SPI Slave → Bounded Buffers: uses buffers (evidence: `programs/communication_stuff/communication/arduino/src/main.cpp`)
- Arduino SPI Slave → Slave Instructions: dispatches instruction (evidence: `programs/communication_stuff/communication/arduino/src/main.cpp`)
- Host SPI Client → SPI Interface: implements interface (evidence: `programs/communication_stuff/communication/lib/spi.cpp`)
- Ethernet Client → Ethernet Core: uses socket API (evidence: `programs/MORE LIBRARIES/Ethernet/src/EthernetClient.cpp`)
- MQTT Client → MQTT Packets: uses packet types (evidence: `programs/MORE LIBRARIES/Temboo/src/utility/MQTTClient.h`)
- Bridge HTTP Client → Host Application: exposes HTTP calls
- Firmata Ethernet Stream → Ethernet Client: wraps client (evidence: `programs/MORE LIBRARIES/Firmata/utility/EthernetClientStream.h`)
