# fossasia/pslab-android architecture

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

- Interactive diagram: https://gitdiagram.com/fossasia/pslab-android
- Repository: https://github.com/fossasia/pslab-android

## Overview

##### Main Components Identification

The system should be divided into these major components:

a) User Interface Layer
- Activities (under app/src/main/java/io/pslab/activity)
- Fragments (under app/src/main/java/io/pslab/fragment)
- Adapters (under app/src/main/java/io/pslab/adapters)

b) Communication Layer
- Communication handlers (under app/src/main/java/io/pslab/communication)
- Protocol implementations
- USB/OTG connection management

c) Hardware Interface Layer
- Sensor implementations (under app/src/main/java/io/pslab/communication/sensors)
- Peripheral handlers (under app/src/main/java/io/pslab/communication/peripherals)
- Analog/Digital channel management

d) Data Management Layer
- Data models (under app/src/main/java/io/pslab/models)
- Data logging and export functionality
- CSV handling

**[User Interface Layer]**
- ↑↓
**[Communication Layer]**
- ↑↓
**[Hardware Interface Layer]**
- ↑↓
**[PSLab Hardware Device]**

##### Detailed Component Breakdown

Relationships between components:

**[Activities & Fragments] ←→ [Data Models]**
- ↓
**[Communication Handler]**
- ↓
**[Protocol Layer (PacketHandler)]**
- ↓
**[Hardware Abstractions]**
- ↙    ↓    ↘
**[Sensors] [Peripherals] [Channels]**
- ↓
**[USB/OTG Interface]**
- ↓
**[PSLab Hardware]**

##### Specific Features

- Instrument interfaces (Oscilloscope, Multimeter, etc.)
- Sensor management system
- Data logging and export functionality
- Communication protocols (I2C, SPI)
- Real-time data visualization
- Storage and persistence mechanisms

##### Implementation Notes

- Use UML notation for clarity
- Brief descriptions for major components
- Version compatibility (API Level 23-31)
- Critical paths for data flow
- Public interfaces vs internal implementations

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI["User Interface Layer"]
        direction TB
        Activities["Activities"]:::ui
        Fragments["Fragments"]:::ui
        Adapters["Adapters"]:::ui
        Instruments["Instrument Interfaces"]:::ui
        subgraph InstrumentComponents["Instruments"]
            direction TB
            Osc["Oscilloscope"]:::ui
            Multi["Multimeter"]:::ui
            Wave["Wave Generator"]:::ui
            Logic["Logic Analyzer"]:::ui
        end
    end

    subgraph Comm["Communication Layer"]
        direction TB
        CommHandler["Communication Handler"]:::comm
        Protocol["Protocol Handler"]:::comm
        USB["USB/OTG Interface"]:::comm
    end

    subgraph Hardware["Hardware Interface Layer"]
        direction TB
        SensorMgmt["Sensor Management"]:::hw
        Peripherals["Peripherals"]:::hw
        Channels["Channels"]:::hw
        subgraph Protocols["Communication Protocols"]
            direction TB
            I2C["I2C"]:::hw
            SPI["SPI"]:::hw
        end
    end

    subgraph Data["Data Management Layer"]
        direction TB
        Models["Data Models"]:::data
        DataLog["Data Logging"]:::data
        CSV["CSV Handler"]:::data
    end

    Device["PSLab Hardware Device"]:::device

    %% Relationships
    UI --> Comm
    Comm --> Hardware
    Hardware --> Device
    UI <--> Data
    Comm <--> Data

    %% Click Events
    click Activities "https://github.com/fossasia/pslab-android/tree/development/app/src/main/java/io/pslab/activity/"
    click Fragments "https://github.com/fossasia/pslab-android/tree/development/app/src/main/java/io/pslab/fragment/"
    click Adapters "https://github.com/fossasia/pslab-android/tree/development/app/src/main/java/io/pslab/adapters/"
    click CommHandler "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/communication/CommunicationHandler.java"
    click Protocol "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/communication/PacketHandler.java"
    click USB "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/receivers/USBDetachReceiver.java"
    click SensorMgmt "https://github.com/fossasia/pslab-android/tree/development/app/src/main/java/io/pslab/communication/sensors/"
    click Peripherals "https://github.com/fossasia/pslab-android/tree/development/app/src/main/java/io/pslab/communication/peripherals/"
    click Models "https://github.com/fossasia/pslab-android/tree/development/app/src/main/java/io/pslab/models/"
    click DataLog "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/LocalDataLog.java"
    click CSV "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/others/CSVLogger.java"
    click Osc "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/activity/OscilloscopeActivity.java"
    click Multi "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/activity/MultimeterActivity.java"
    click Wave "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/activity/WaveGeneratorActivity.java"
    click Logic "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/activity/LogicalAnalyzerActivity.java"
    click I2C "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/communication/peripherals/I2C.java"
    click SPI "https://github.com/fossasia/pslab-android/blob/development/app/src/main/java/io/pslab/communication/peripherals/SPI.java"

    %% Styling
    classDef ui fill:#2196F3,stroke:#1565C0,color:white
    classDef comm fill:#4CAF50,stroke:#2E7D32,color:white
    classDef hw fill:#FF9800,stroke:#EF6C00,color:white
    classDef data fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef device fill:#757575,stroke:#424242,color:white

    %% Legend
    subgraph Legend
        direction TB
        UI_L["UI Components"]:::ui
        COMM_L["Communication Components"]:::comm
        HW_L["Hardware Components"]:::hw
        DATA_L["Data Components"]:::data
        DEV_L["Hardware Device"]:::device
    end
```
