# gremsy/gsdk architecture

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

- Interactive diagram: https://gitdiagram.com/gremsy/gsdk
- Repository: https://github.com/gremsy/gsdk

## Overview

##### Main Components
- Serial Communication Layer: Represented by files such as “serial_port.cpp” and “serial_port.h”, this component abstracts the USB/TTL serial port communication.
- MAVLink Message Processing: Show a module that includes the MAVLink subdirectory (inside “src/mavlink”) and its numerous header files for different protocols and message definitions. This handles encoding and decoding of MAVLink messages.
- Gimbal Interface & Protocol: Components like “gimbal_interface.cpp/h”, “gimbal_protocol.cpp/h”, and version-specific implementations (v1 and v2) that manage the core logic for communicating with and controlling the gimbal.
- Bootloader/Firmware Upgrade Module: Files such as “bootloader.cpp/h” (and the “upgrade_gimbal” example) are solely dedicated to upgrading firmware and handling bootloader mode.
- Auxiliary Utilities: Parsers (in “src/parsers”), and any additional support functions.

##### Relationships and Interactions
- The Application Core (command handler/menu) receives user input (e.g., selecting a gimbal mode or firmware upgrade).
- It then calls the Gimbal Interface, which in turn utilizes the Serial Communication Layer to send/receive data via the UART interface.
- The MAVLink processing module wraps around these interactions, translating the internal commands and messages into proper MAVLink packets using the numerous MAVLink definitions.
- For firmware upgrades, the core shifts to bootloader functionality where the Bootloader Module handles hex file parsing, connection initiation, and flashing via a dedicated protocol.
- An examples branch demonstrates how different operations (such as saving parameters or performing an upgrade) reuse the core modules and interact with hardware.

##### Architectural Patterns and Design Principles
- Layered Architecture: Organize components into distinct layers (UI/Command Layer, Communication Layer, Protocol/MAVLink Layer, and Hardware Abstraction Layer).
- Modular Structure: Note how the code is modularized; for instance, MAVLink messages are separated by protocol version and type.
- Clear Separation of Concerns: The project distinguishes between normal gimbal operation (configuration, commands, status monitoring) and the firmware upgrade process.

##### Relevant Technologies, Frameworks, and Libraries
- CMake is used for build configuration (evident from the top-level “CMakeLists.txt” files).
- The C++ standard libraries, along with platform-specific (Unix) serial port handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Layer"
        UI["Menu/Command Handler"]:::ui
    end

    subgraph "Communication & Control Layer"
        GIM["Gimbal Interface & Protocol"]:::gimbal
        MAV["MAVLink Encoding/Decoding"]:::mavlink
        UTIL["Auxiliary Utilities"]:::utils
    end

    subgraph "Hardware Interaction Layer"
        SERIAL["Serial Port Abstraction"]:::serial
    end

    subgraph "Firmware Upgrade"
        BOOT["Bootloader/Firmware Upgrade Module"]:::bootloader
        EX["Upgrade Gimbal Example"]:::example
    end

    %% Relationships
    UI -->|"calls"| GIM
    UI -->|"initiates"| BOOT
    GIM -->|"communicates"| SERIAL
    SERIAL -->|"sends/receives"| GIM
    GIM -->|"encodes/decodes"| MAV
    GIM -->|"utilizes"| UTIL
    EX -->|"demonstrates_usage"| BOOT

    %% Click Events
    click UI "https://github.com/gremsy/gsdk/blob/master/mavlink_control.cpp"
    click SERIAL "https://github.com/gremsy/gsdk/blob/master/src/serial_port.cpp"
    click MAV "https://github.com/gremsy/gsdk/tree/master/src/mavlink"
    click GIM "https://github.com/gremsy/gsdk/blob/master/src/gimbal_interface.cpp"
    click BOOT "https://github.com/gremsy/gsdk/blob/master/src/bootloader.cpp"
    click EX "https://github.com/gremsy/gsdk/tree/master/examples/upgrade_gimbal"
    click UTIL "https://github.com/gremsy/gsdk/blob/master/src/parsers/utils.cpp"

    %% Styles
    classDef ui fill:#b3ffb3,stroke:#000,stroke-width:2px;
    classDef gimbal fill:#ffd699,stroke:#e68a00,stroke-width:2px;
    classDef serial fill:#cce6ff,stroke:#004080,stroke-width:2px;
    classDef mavlink fill:#e6ccff,stroke:#663399,stroke-width:2px;
    classDef bootloader fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef utils fill:#f2f2f2,stroke:#666,stroke-width:2px;
    classDef example fill:#d9ead3,stroke:#38761d,stroke-width:2px;
```
