# aboeinas/pump architecture

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

- Interactive diagram: https://gitdiagram.com/aboeinas/pump
- Repository: https://github.com/aboeinas/pump

## Overview

##### Main System Components

a) Hardware Layer:
- Insulin Pump Physical Components (represented by STL files)
- Piston mechanism
- Case and sleeve components
- Servo components
- PCB Components (from schematic)
- 3.3V Voltage Regulator
- Dual H-Bridge motor driver
- Rotary Position Sensor
- Simblee microcontroller

b) Firmware Layer (Simblee Arduino):
- Core Control Systems
- Motor Control (DCMotorDualEncoderPiston, DoseMotor)
- Encoder Systems (DualEncoder, ServoEncoder)
- Basal Delivery System (BasalModel, BasalMessageProcessor)
- Communication Module
- Security Module (AES encryption)

c) Android Communication Layer:
- Bluetooth Communication Interface
- Message Handlers
- Basal-related messages
- Dose-related messages
- State monitoring messages

**[Android Application Layer]**
- ↕
- Bluetooth
- ↕
**[Firmware Control Layer]**
- ↕
**[Hardware Components Layer]**

##### Specific Elements

a) Hardware Layer (Bottom):
- Sensor inputs and actuator outputs
- PCB components and their interconnections

b) Firmware Layer (Middle):
- Create modules for:
- Motor Control System
- Encoder Management
- Basal Delivery Control
- Communication Handler
- Security Module
- Internal data flow between modules

c) Communication Layer (Top):
- Android interface components
- Message processors
- Bluetooth communication protocol

##### Important Relationships to Highlight

- Bluetooth communication flow between Android and Simblee
- Motor control feedback loop with encoders
- Basal delivery control system interaction with motor control
- Security layer integration points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef hardware fill:#D3D3D3,stroke:#333
    classDef pcb fill:#FFE4B5,stroke:#333
    classDef firmware fill:#90EE90,stroke:#333
    classDef communication fill:#87CEEB,stroke:#333
    classDef security fill:#FFB6C1,stroke:#333
    classDef android fill:#DDA0DD,stroke:#333

    %% Android Layer
    subgraph AndroidLayer
        AndroidApp["Android Application"]:::android
        BTInterface["Bluetooth Interface"]:::communication
        MessageHandlers["Message Handlers"]:::communication
        BasalMsg["Basal Messages"]:::communication
        DoseMsg["Dose Messages"]:::communication
        StateMsg["State Messages"]:::communication
    end

    %% Firmware Layer
    subgraph FirmwareLayer
        CommModule["Communication Module"]:::communication
        Security["Security/AES"]:::security
        CoreControl["Core Control Systems"]:::firmware
        MotorControl["Motor Control"]:::firmware
        EncoderSys["Encoder Systems"]:::firmware
        BasalDelivery["Basal Delivery"]:::firmware
        Setup["Setup"]:::firmware
        SelfTest["Self Test"]:::firmware
    end

    %% Hardware Layer
    subgraph HardwareLayer
        subgraph PCBComponents
            VoltageReg["3.3V Regulator"]:::pcb
            HBridge["Dual H-Bridge"]:::pcb
            RotarySensor["Rotary Position Sensor"]:::pcb
            Simblee["Simblee Controller"]:::pcb
        end

        subgraph PhysicalComponents
            Piston["Piston Mechanism"]:::hardware
            Case["Case Components"]:::hardware
            Servo["Servo Components"]:::hardware
        end
    end

    %% Relationships
    AndroidApp --> BTInterface
    BTInterface --> MessageHandlers
    MessageHandlers --> BasalMsg & DoseMsg & StateMsg
    BasalMsg & DoseMsg & StateMsg --> CommModule
    CommModule --> Security
    Security --> CoreControl
    CoreControl --> MotorControl & EncoderSys & BasalDelivery
    Setup --> CoreControl
    SelfTest --> CoreControl
    MotorControl --> HBridge
    EncoderSys --> RotarySensor
    HBridge --> Servo
    Servo --> Piston
    VoltageReg --> Simblee
    Simblee --> CommModule

    %% Click Events
    click BTInterface "https://github.com/aboeinas/Pump/blob/main/android_communication/PumpBluetooth.java"
    click BasalMsg "https://github.com/aboeinas/Pump/blob/main/android_communication/BasalRxMessage.java"
    click DoseMsg "https://github.com/aboeinas/Pump/blob/main/android_communication/DoseTxMessage.java"
    click StateMsg "https://github.com/aboeinas/Pump/blob/main/android_communication/PumpStateRxMessage.java"
    click Security "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/aes.h"
    click MotorControl "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/DCMotorDualEncoderPiston.h"
    click EncoderSys "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/DualEncoder.h"
    click BasalDelivery "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/BasalModel.h"
    click CommModule "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/Communication.ino"
    click Setup "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/Setup.ino"
    click SelfTest "https://github.com/aboeinas/Pump/blob/main/simblee_top_arduino/SelfTest.ino"
    click VoltageReg "https://github.com/aboeinas/Pump/blob/main/pcb_schematic/components/3.3V Voltage Regulator LD1117S33CTR.pdf"
    click HBridge "https://github.com/aboeinas/Pump/blob/main/pcb_schematic/components/Dual H-Bridge drv8835 (VCC!=VM).pdf"
    click RotarySensor "https://github.com/aboeinas/Pump/blob/main/pcb_schematic/components/Rotary Position Sensor - ARE0000CE3.pdf"
    click Piston "https://github.com/aboeinas/Pump/blob/main/piston v17.stl"
    click Case "https://github.com/aboeinas/Pump/blob/main/Single Piston v17 case.stl"
    click Servo "https://github.com/aboeinas/Pump/blob/main/servo cog dual encoder.stl"
```
