Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/tyler #5

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run Ruff Linter

on:
pull_request:
branches:
- main
- dev

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/pypoetry
~/.cache/pip
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev

- name: Run ruff linter
run: |
poetry run ruff check .
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run Tests

on:
pull_request:
branches:
- main
- dev

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/pypoetry
~/.cache/pip
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev

- name: Run tests
run: |
poetry run pytest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

poetry.lock
*_pb2.py
.ruff_cache/
142 changes: 141 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,141 @@
# rtt-lora-comms-package
# Radio Telemetry Tracker Drone Communications Package (Comms Package)

The **Radio Telemetry Tracker Drone Communications Package** is a Python-based library designed to facilitate the transmission, reception, and handling of protobuf-based radio packets between a drone's field device software ([FDS](https://github.com/UCSD-E4E/radio-telemetry-tracker-drone-fds)) and the ground control station ([GCS](https://github.com/UCSD-E4E/radio-telemetry-tracker-drone-gcs)). It implements reliable communication through packet acknowledgements, serialization/deserialization of Protobuf messages, and provides an extendable structure for new message types.

> Note: This package is not intended for end-user use in standalone mode. Rather, it is a shared component that is consumed by the FDS and GCS repositories. Therefore, detailed user-facing instructions are provided in the respective repositories where this package is integrated.

## Table of Contents
- [Radio Telemetry Tracker Drone Communications Package (Comms Package)](#radio-telemetry-tracker-drone-communications-package-comms-package)
- [Table of Contents](#table-of-contents)
- [Overview](#overview)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Troubleshooting](#troubleshooting)
- [License](#license)

## Overview

This package provides:

- **Packet Definitions**: Protobuf message definitions for radio telemetry data and requests
- **Codec**: Encoding/decoding logic with framing, CRC checks, and synchronization markers
- **Radio Interfaces**:
- **SerialRadioInterface**: For physical serial (UART) connections
- **SimulatedRadioInterface**: For TCP-based simulation and testing
- **Packet Management**: Reliable transmission with retry and acknowledgment (ACK) mechanisms
- **DroneComms Class**: High-level API with typed handlers and callback registration

## Prerequisites

- Python 3.12 or later
- Poetry 1.8 or later
- For serial communication: `pyserial`
- For protocol buffers: `protobuf`, `grpcio-tools`

## Installation

1. Add as a dependency to your project:

```bash
poetry add git+https://github.com/UCSD-E4E/radio-telemetry-tracker-drone-comms-package.git
```

2. Or clone for development:
```bash
git clone https://github.com/UCSD-E4E/radio-telemetry-tracker-drone-comms-package.git
cd radio-telemetry-tracker-drone-comms-package
poetry install
```

## Configuration

The library supports two interface types:

1. **Serial Interface**:

```python
from radio_telemetry_tracker_drone_comms_package import RadioConfig

config = RadioConfig(
interface_type="serial",
port="/dev/ttyUSB0", # Serial port
baudrate=56700, # Communication speed
)
```

2. **Simulated Interface** (for testing):

```python
config = RadioConfig(
interface_type="simulated",
host="localhost", # TCP host
tcp_port=50000, # TCP port
server_mode=False, # Client/server mode
)
```

## Usage

Basic usage pattern:

```python
from radio_telemetry_tracker_drone_comms_package import DroneComms, RadioConfig, GPSData
```

1. **Initialize communications**:
```python
config = RadioConfig(interface_type="serial", port="/dev/ttyUSB0")
comms = DroneComms(radio_config=config)
```

2. **Register handlers for incoming packets**:
```python
def on_gps_data(data: GPSData):
print(f"GPS: {data.easting}, {data.northing}, {data.altitude}")

comms.register_gps_handler(on_gps_data)
```

3. **Start communication**:
```python
comms.start() # Opens the radio interface and starts Rx/Tx threads
```

4. **Send packets as needed**:
```python
comms.send_sync_request(SyncRequestData())
```

5. **Clean up when done**:
```python
comms.stop() # Closes the radio interface and stops threads
```


## Troubleshooting

Common issues and solutions:

- **No Packets Received**
- Check physical connections (serial) or network connectivity (TCP)
- Verify correct port/baudrate settings
- Look for exceptions in logs

- **CRC Errors**
- Ensure matching Protobuf versions between FDS and GCS
- Check for packet framing issues
- Verify byte order consistency

- **Timeouts**
- Increase `read_timeout` or `ack_timeout` for slow/unreliable links
- Check for network congestion or interference
- Verify both ends are running and properly configured

## License

This project is licensed under the terms specified in the [LICENSE](LICENSE) file.



20 changes: 0 additions & 20 deletions poetry.lock

This file was deleted.

29 changes: 26 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
[tool.poetry]
name = "rtt-sik-comms-package"
name = "radio-telemetry-tracker-drone-comms-package"
version = "0.1.0"
description = ""
authors = ["Tyler Flar <[email protected]>"]
license = "MIT"
readme = "README.md"
license = "Other"
packages = [
{ include = "radio_telemetry_tracker_drone_comms_package" },
]

[tool.poetry.dependencies]
python = "^3.12"
pyserial = "^3.5"
protobuf = "^5.29.2"
grpcio-tools = "^1.68.1"


[tool.poetry.group.dev.dependencies]
ruff = "^0.8.3"
pytest = "^8.3.3"
pytest-mock = "^3.14.0"

[tool.ruff]
line-length = 120
exclude = ["radio_telemetry_tracker_drone_comms_package/proto/packets_pb2.py"]

[tool.ruff.lint]
select = ["ALL"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--maxfail=5 --tb=short"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
42 changes: 42 additions & 0 deletions radio_telemetry_tracker_drone_comms_package/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""radio_telemetry_tracker_drone_comms_package.

Package initialization for the Radio Telemetry Tracker Drone Comms Package.
"""

__version__ = "0.1.0"

from radio_telemetry_tracker_drone_comms_package.data_models import (
ConfigRequestData,
ConfigResponseData,
ErrorData,
GPSData,
LocEstData,
PingData,
StartRequestData,
StartResponseData,
StopRequestData,
StopResponseData,
SyncRequestData,
SyncResponseData,
)
from radio_telemetry_tracker_drone_comms_package.drone_comms import (
DroneComms,
RadioConfig,
)

__all__ = [
"ConfigRequestData",
"ConfigResponseData",
"DroneComms",
"ErrorData",
"GPSData",
"LocEstData",
"PingData",
"RadioConfig",
"StartRequestData",
"StartResponseData",
"StopRequestData",
"StopResponseData",
"SyncRequestData",
"SyncResponseData",
]
Loading
Loading