# irnas/ppk2-api-python architecture

> Architecture diagram of the GitHub repository irnas/ppk2-api-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/irnas/ppk2-api-python
- Repository: https://github.com/irnas/ppk2-api-python

## Overview

This Python library automates power measurements with a Nordic PPK2 over serial. The main workflow initializes the device, configures source-meter mode and voltage, starts acquisition, collects and decodes samples, then exposes current, power, and charge summaries and optionally writes samples to CSV. The API also documents a buffered multiprocessing variant and device discovery. The README describes broader GUI-like functionality and selectable-format logging as in progress; those capabilities are not detailed in the sampled implementation. Connections below follow shown calls or README statements.

Main entry points: [`src/power_profiler.py`](https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py) (PowerProfiler), [`src/ppk2_api/ppk2_api.py`](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py) (PPK2 API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_profiler["Power profiling"]
  node_profiler["PowerProfiler<br/>[power_profiler.py]"]
  node_measurement_loop["Measurement loop<br/>[power_profiler.py]"]
  node_summaries["Measurement summaries<br/>[power_profiler.py]"]
  node_csv["CSV logging<br/>[power_profiler.py]"]
  node_logging_format["Selectable log formats<br/>[power_profiler.py]"]
end

subgraph group_api["PPK2 API"]
  node_api["PPK2 API<br/>[ppk2_api.py]"]
  node_device_discovery["Device discovery<br/>[ppk2_api.py]"]
  node_device_control["Mode and power control<br/>[ppk2_api.py]"]
  node_sample_processing["Sample processing<br/>[ppk2_api.py]"]
  node_buffered_reader["Buffered reader<br/>[ppk2_api.py]"]
  node_gui_capabilities["Profiler GUI features<br/>[ppk2_api.py]"]
end

subgraph group_device["Hardware"]
  node_serial["Serial interface"]
  node_ppk2{{"PPK2 device"}}
end

node_user(("Python caller"))

node_user -->|"initializes or controls"| node_profiler
node_profiler -->|"discovers device"| node_device_discovery
node_profiler -->|"configures and controls"| node_api
node_api -->|"reads and writes"| node_serial
node_serial -->|"communicates with"| node_ppk2
node_profiler -->|"starts thread"| node_measurement_loop
node_measurement_loop -->|"fetches and decodes"| node_api
node_measurement_loop -->|"appends samples"| node_profiler
node_profiler -->|"provides metrics"| node_summaries
node_profiler -->|"writes samples"| node_csv
node_user -->|"may use variant"| node_buffered_reader
node_user -.->|"requests format"| node_logging_format
node_user -.->|"may use capabilities"| node_gui_capabilities

click node_profiler "https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py"
click node_measurement_loop "https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py"
click node_summaries "https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py"
click node_csv "https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py"
click node_api "https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py"
click node_device_discovery "https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py"
click node_device_control "https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py"
click node_sample_processing "https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py"
click node_buffered_reader "https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py"
click node_logging_format "https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py"
click node_gui_capabilities "https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py"

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_profiler,node_measurement_loop,node_summaries,node_csv,node_logging_format toneBlue
class node_api,node_device_discovery,node_device_control,node_sample_processing,node_buffered_reader,node_gui_capabilities toneAmber
class node_serial,node_ppk2 toneMint
class node_user toneIndigo
```

## Components

### Power profiling

- [PowerProfiler](https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py): `src/power_profiler.py`
- [Measurement loop](https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py): `src/power_profiler.py`
- [Measurement summaries](https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py): `src/power_profiler.py`
- [CSV logging](https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py): `src/power_profiler.py`
- [Selectable log formats](https://github.com/irnas/ppk2-api-python/blob/master/src/power_profiler.py): `src/power_profiler.py`

### PPK2 API

- [PPK2 API](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py): `src/ppk2_api/ppk2_api.py`
- [Device discovery](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py): `src/ppk2_api/ppk2_api.py`
- [Mode and power control](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py): `src/ppk2_api/ppk2_api.py`
- [Sample processing](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py): `src/ppk2_api/ppk2_api.py`
- [Buffered reader](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py): `src/ppk2_api/ppk2_api.py`
- [Profiler GUI features](https://github.com/irnas/ppk2-api-python/blob/master/src/ppk2_api/ppk2_api.py): `src/ppk2_api/ppk2_api.py`

### Hardware

- **Serial interface**
- **PPK2 device**

### Other components

- **Python caller**

## Connections

- Python caller → PowerProfiler: initializes or controls (evidence: `src/power_profiler.py`)
- PowerProfiler → Device discovery: discovers device (evidence: `src/power_profiler.py`)
- PowerProfiler → PPK2 API: configures and controls (evidence: `src/power_profiler.py`)
- PPK2 API → Serial interface: reads and writes (evidence: `src/ppk2_api/ppk2_api.py`)
- Serial interface → PPK2 device: communicates with
- PowerProfiler → Measurement loop: starts thread (evidence: `src/power_profiler.py`)
- Measurement loop → PPK2 API: fetches and decodes (evidence: `src/power_profiler.py`)
- Measurement loop → PowerProfiler: appends samples (evidence: `src/power_profiler.py`)
- PowerProfiler → Measurement summaries: provides metrics (evidence: `src/power_profiler.py`)
- PowerProfiler → CSV logging: writes samples (evidence: `src/power_profiler.py`)
- Python caller → Buffered reader: may use variant (evidence: `README.md`)
- Python caller → Selectable log formats: requests format (evidence: `README.md`)
- Python caller → Profiler GUI features: may use capabilities (evidence: `README.md`)
