# osqzss/gps-sdr-sim architecture

> Architecture diagram of the GitHub repository osqzss/gps-sdr-sim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/osqzss/gps-sdr-sim
- Repository: https://github.com/osqzss/gps-sdr-sim

## Overview

##### Main Components
- Core Simulation Engine: At the heart of the application is the gpssim.c module, which reads satellite navigation (RINEX) files (e.g., “brdc0010.22n”) and user motion files (in CSV or NMEA format) to compute pseudoranges and Doppler shifts.
- Argument Parsing & Configuration: Modules like getopt.c/getopt.h handle command-line arguments that specify simulation parameters, input file paths, sample rates, simulation duration, and output file formats.
- User Motion Processing: There is support for both static (direct location input) and dynamic motion (CSV/NMEA input) to control the simulated user trajectory.
- Signal Generation Module: After processing inputs, the simulation engine computes the necessary GPS signal components (I/Q samples) based on the input ephemeris, and applies modulation schemes to form baseband signals.
- SDR Interface/Player Components: Under the “player” directory (and sub-folders like “limeplayer_win” and “plutoplayer_win”), there are implementations that tailor the output I/Q data for specific SDR hardware platforms. These modules provide the necessary companion utilities to “play back” or transmit the generated GPS signal.
- Additional Support/Utility Modules:
- “extclk” directory – appears to contain configuration or binary files (possibly related to external clock settings).
- “rtk” directory – holds observation files, navigational logs, and possibly RTK post-processing examples.
- “satgen” directory – contains code and assets for satellite generation and/or simulation of satellite data (likely to simulate alternative satellite constellations or provide additional test data).

##### Component Relationships & Data Flow
- Input Layer: Accepts GPS broadcast ephemeris files, user motion input (CSV, NMEA, or static values), and configuration parameters.
- Processing Layer: The core simulation engine (gpssim.c) reads and parses inputs, applies the GPS signal simulation algorithm (computing pseudoranges, Doppler shifts, etc.), and optionally adjusts its behavior based on user-defined parameters (like simulation time, sample rate, IQ bit-depth, etc.).
- Output Layer: The simulation produces digitized I/Q samples saved to a file (default “gpssim.bin”), which is then piped into one of several “player” utilities. Depending on the target hardware, these utilities (e.g., bladeplayer for bladeRF, plutoplayer for ADALM-Pluto, hackplayer for HackRF) adjust or format the raw data for transmission.
- External Interfaces: The SDR hardware platforms interface with the transmitted I/Q data. Each player module is designed to handle the specific requirements of its target hardware (for example, data bits or sample rate conversions).

##### Important Architectural Patterns & Design Principles
- Modularity: The system clearly breaks out core simulation tasks from hardware-specific playback/streaming components. Such separation enables independent development and easier extension to support additional SDR platforms.
- Layered System: Consider showing a layered design – inputs (files and arguments), processing (core signal generation algorithm), and outputs (player modules and hardware interfaces).

##### Relevant Technologies, Frameworks, or Libraries
- C programming language is used for core simulation (gpssim.c).
- GCC for building under Linux, and Visual Studio for Windows builds.
- Makefiles as build scripts are present both at the root and within subdirectories (e.g., in “player” and “satgen”).
- External tools and utilities: Scripts for SDR platforms (bladeRF-cli script, HackRF commands, UHD tools, etc.) which should be mentioned as part of the system integration.

- Input Files (Ephemeris, User Motion, NMEA streams)
- Core Simulation (gpssim.c and supporting modules)
- Data Processing (Argument parsing via getopt, motion file processing, signal generation)
- Output Module (I/Q sample generation – gpssim.bin)
- Player Utility Modules (bladeplayer, hackplayer, plutoplayer, limeplayer, etc.)
- Hardware Interfaces (ADALM-Pluto, bladeRF, HackRF, USRP, LimeSDR)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        A1["Ephemeris Files (e.g. brdc0010.22n)"]:::input
        A2["User Motion File: circle.csv"]:::input
        A3["User Motion File: circle_llh.csv"]:::input
        A4["Command-line & Config Parameters"]:::input
    end

    %% Processing Layer
    subgraph "Processing Layer"
        B1["Core Simulation Engine (gpssim.c)"]:::process
        subgraph "Argument Parsing (Root)"
            B2a["getopt.c (Root)"]:::process
            B2b["getopt.h (Root)"]:::process
        end
        %% Signal generation is integrated in Core Simulation Engine
        B4["I/Q Output File (gpssim.bin)"]:::output
    end

    %% Player Modules Layer
    subgraph "Player Modules"
        C1["BladeRF Player"]:::player
        C2["HackRF Player"]:::player
        C3["LimeSDR Player (Linux)"]:::player
        C4["LimeSDR Player (Windows)"]:::player
        C5["ADALM-Pluto Player (Linux)"]:::player
        C6["ADALM-Pluto Player (Windows)"]:::player
    end

    %% Additional Argument Parsing for Players
    subgraph "Player Argument Parsing"
        D1["getopt.c (LimeSDR Player)"]:::process
        D2["getopt.h (LimeSDR Player)"]:::process
        D3["getopt.c (Pluto Player)"]:::process
        D4["getopt.h (Pluto Player)"]:::process
    end

    %% Hardware Interfaces
    subgraph "SDR Hardware Interfaces"
        F1["ADALM-Pluto Hardware"]:::hardware
        F2["bladeRF Hardware"]:::hardware
        F3["HackRF Hardware"]:::hardware
        F4["LimeSDR Hardware"]:::hardware
        F5["USRP Hardware"]:::hardware
    end

    %% Build & Deployment Tools
    subgraph "Build & Deployment Tools"
        E1["External Clock Support (extclk)"]:::build
        E2["RTK Support (rtk)"]:::build
        E3["Satellite Data Generation (satgen)"]:::build
    end

    %% Connections from Input Layer to Processing Layer
    A1 --> B1
    A2 --> B1
    A3 --> B1
    A4 --> B1
    B2a --> B1
    B2b --> B1
    B1 --> B4

    %% Connections from Processing Layer to Player Modules
    B4 --> C1
    B4 --> C2
    B4 --> C3
    B4 --> C4
    B4 --> C5
    B4 --> C6

    %% Connections from Additional Argument Parsing to corresponding Players
    D1 --- C4
    D2 --- C4
    D3 --- C6
    D4 --- C6

    %% Connections from Player Modules to Hardware Interfaces
    C1 --> F2
    C2 --> F3
    C3 --> F4
    C4 --> F4
    C5 --> F1
    C6 --> F1

    %% Build Tools support the Processing Layer
    E1 --- B1
    E2 --- B1
    E3 --- B1

    %% Optionally, connect Build Tools to Player Modules (for build scripts)
    E1 --- C1
    E1 --- C2
    E1 --- C3
    E1 --- C4
    E1 --- C5
    E1 --- C6

    %% Click Events
    click B1 "https://github.com/osqzss/gps-sdr-sim/blob/master/gpssim.c"
    click B2a "https://github.com/osqzss/gps-sdr-sim/blob/master/getopt.c"
    click B2b "https://github.com/osqzss/gps-sdr-sim/blob/master/getopt.h"
    click A2 "https://github.com/osqzss/gps-sdr-sim/blob/master/circle.csv"
    click A3 "https://github.com/osqzss/gps-sdr-sim/blob/master/circle_llh.csv"
    click C1 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/bladeplayer.c"
    click C2 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/hackplayer.c"
    click C3 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/limeplayer.c"
    click C4 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/limeplayer_win/limeplayer.c"
    click C5 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/plutoplayer.c"
    click C6 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/plutoplayer_win/plutoplayer.c"
    click D1 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/limeplayer_win/getopt.c"
    click D2 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/limeplayer_win/getopt.h"
    click D3 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/plutoplayer_win/getopt.c"
    click D4 "https://github.com/osqzss/gps-sdr-sim/blob/master/player/plutoplayer_win/getopt.h"
    click E1 "https://github.com/osqzss/gps-sdr-sim/tree/master/extclk"
    click E2 "https://github.com/osqzss/gps-sdr-sim/tree/master/rtk"
    click E3 "https://github.com/osqzss/gps-sdr-sim/tree/master/satgen"

    %% Styles
    classDef input fill:#add8e6,stroke:#000,stroke-width:1px
    classDef process fill:#90ee90,stroke:#000,stroke-width:1px
    classDef output fill:#ffff99,stroke:#000,stroke-width:1px
    classDef player fill:#dda0dd,stroke:#000,stroke-width:1px
    classDef build fill:#ffb6c1,stroke:#000,stroke-width:1px
    classDef hardware fill:#d3d3d3,stroke:#000,stroke-width:1px
```
