# sharkbia/ptz-control-system architecture

> Architecture diagram of the GitHub repository sharkbia/ptz-control-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sharkbia/ptz-control-system
- Repository: https://github.com/sharkbia/ptz-control-system

## Overview

PTZ 云台控制系统 provides a GUI for configuring communications and controlling a pan-tilt head. The main workflow initializes GS-232B and Pelco-D connections, receives and parses GS-232B commands, translates angle queries or settings into Pelco-D packets, and returns responses; the UI also exposes manual controls and logs. The tree and excerpts support this control path and serial/TCP/UDP transports. UI configuration, persistence, and some capabilities are documented or visible only in partial excerpts, so their internal wiring is shown only where supported.

Main entry points: [`core/controller.py`](https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py) (Control system), [`ui/main_window.py`](https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py) (Main window), [`hardware/interfaces.py`](https://github.com/sharkbia/ptz-control-system/blob/main/hardware/interfaces.py) (GS-232B transport), [`core/protocols.py`](https://github.com/sharkbia/ptz-control-system/blob/main/core/protocols.py) (Pelco-D protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["GUI and configuration"]
  node_entry["Application entry<br/>[main.py]"]
  node_window["Main window<br/>[main_window.py]"]
  node_settings["Device settings<br/>[main_window.py]"]
  node_configfile["Saved configuration"]
  node_logview["Log display<br/>[main_window.py]"]
end

subgraph group_control["Command control"]
  node_controller["Control system<br/>[controller.py]"]
  node_commandparse["GS-232B parsing<br/>[protocols.py]"]
  node_commanddispatch["Command dispatch<br/>[controller.py]"]
  node_anglecontrol["Angle control<br/>[controller.py]"]
  node_pelcod["Pelco-D protocol<br/>[protocols.py]"]
end

subgraph group_hardware["Hardware communications"]
  node_gs232["GS-232B transport<br/>[interfaces.py]"]
  node_transport["Serial/TCP/UDP<br/>[interfaces.py]"]
end

node_operator(("Operator"))
node_rotator(("GS-232B client"))
node_ptz(("PTZ head"))

node_operator -->|"operates"| node_window
node_entry -->|"launches"| node_window
node_window -->|"configures"| node_settings
node_settings -->|"saves/loads"| node_configfile
node_window -->|"starts/stops"| node_controller
node_window -->|"manual angle"| node_controller
node_controller -->|"creates"| node_gs232
node_controller -->|"constructs"| node_pelcod
node_gs232 -->|"uses"| node_transport
node_pelcod -->|"uses"| node_transport
node_rotator -->|"sends commands"| node_gs232
node_gs232 -->|"receives bytes"| node_controller
node_controller -->|"parses bytes"| node_commandparse
node_controller -->|"dispatches commands"| node_commanddispatch
node_commanddispatch -->|"handles angles"| node_anglecontrol
node_anglecontrol -->|"queries/sets angles"| node_pelcod
node_pelcod -->|"sends packets"| node_transport
node_transport -->|"communicates"| node_ptz
node_controller -->|"sends responses"| node_gs232
node_controller -->|"logs messages"| node_logview
node_transport -->|"logs errors"| node_logview

click node_entry "https://github.com/sharkbia/ptz-control-system/blob/main/main.py"
click node_window "https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py"
click node_settings "https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py"
click node_logview "https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py"
click node_controller "https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py"
click node_commandparse "https://github.com/sharkbia/ptz-control-system/blob/main/core/protocols.py"
click node_commanddispatch "https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py"
click node_anglecontrol "https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py"
click node_pelcod "https://github.com/sharkbia/ptz-control-system/blob/main/core/protocols.py"
click node_gs232 "https://github.com/sharkbia/ptz-control-system/blob/main/hardware/interfaces.py"
click node_transport "https://github.com/sharkbia/ptz-control-system/blob/main/hardware/interfaces.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_entry,node_window,node_settings,node_configfile,node_logview,node_rotator toneBlue
class node_controller,node_commandparse,node_commanddispatch,node_anglecontrol,node_pelcod toneAmber
class node_gs232,node_transport toneMint
class node_operator,node_ptz toneIndigo
```

## Components

### GUI and configuration

- [Application entry](https://github.com/sharkbia/ptz-control-system/blob/main/main.py): `main.py`
- [Main window](https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py): `ui/main_window.py`
- [Device settings](https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py): `ui/main_window.py`
- **Saved configuration**
- [Log display](https://github.com/sharkbia/ptz-control-system/blob/main/ui/main_window.py): `ui/main_window.py`

### Command control

- [Control system](https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py): `core/controller.py`
- [GS-232B parsing](https://github.com/sharkbia/ptz-control-system/blob/main/core/protocols.py): `core/protocols.py`
- [Command dispatch](https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py): `core/controller.py`
- [Angle control](https://github.com/sharkbia/ptz-control-system/blob/main/core/controller.py): `core/controller.py`
- [Pelco-D protocol](https://github.com/sharkbia/ptz-control-system/blob/main/core/protocols.py): `core/protocols.py`

### Hardware communications

- [GS-232B transport](https://github.com/sharkbia/ptz-control-system/blob/main/hardware/interfaces.py): `hardware/interfaces.py`
- [Serial/TCP/UDP](https://github.com/sharkbia/ptz-control-system/blob/main/hardware/interfaces.py): `hardware/interfaces.py`

### Other components

- **Operator**
- **GS-232B client**
- **PTZ head**

## Connections

- Operator → Main window: operates
- Application entry → Main window: launches
- Main window → Device settings: configures
- Device settings → Saved configuration: saves/loads
- Main window → Control system: starts/stops
- Main window → Control system: manual angle
- Control system → GS-232B transport: creates
- Control system → Pelco-D protocol: constructs
- GS-232B transport → Serial/TCP/UDP: uses
- Pelco-D protocol → Serial/TCP/UDP: uses
- GS-232B client → GS-232B transport: sends commands
- GS-232B transport → Control system: receives bytes
- Control system → GS-232B parsing: parses bytes
- Control system → Command dispatch: dispatches commands
- Command dispatch → Angle control: handles angles
- Angle control → Pelco-D protocol: queries/sets angles
- Pelco-D protocol → Serial/TCP/UDP: sends packets
- Serial/TCP/UDP → PTZ head: communicates
- Control system → GS-232B transport: sends responses
- Control system → Log display: logs messages
- Serial/TCP/UDP → Log display: logs errors
