SharpCAT/Server
copilot-swe-agent[bot] 1e54b4ca10 Add SerialController with GET /api/serial/ports endpoint
Co-authored-by: ekinnee <1707617+ekinnee@users.noreply.github.com>
2025-08-07 03:17:42 +00:00
..
Controllers Add SerialController with GET /api/serial/ports endpoint 2025-08-07 03:17:42 +00:00
Models Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
Properties Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
Services Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
appsettings.Development.json Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
appsettings.json Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
Program.cs Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
README.md Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
Server.csproj Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00
SharpCAT.Server.http Move SharpCAT.Server contents to top-level Server directory with updated namespaces 2025-08-07 00:31:29 +00:00

SharpCAT Server

A cross-platform ASP.NET Core Web API server that provides REST endpoints for CAT (Computer Aided Transceiver) control using the SharpCAT library.

Features

  • Cross-platform: Works on Windows, Linux, and macOS
  • REST API: Clean, documented REST endpoints for radio control
  • Serial Communication: Leverages the SharpCAT core library for serial port operations
  • Swagger Documentation: Built-in API documentation and testing interface
  • Error Handling: Comprehensive error handling and logging

API Endpoints

Serial Port Management

  • GET /api/cat/ports - List all available serial ports
  • POST /api/cat/open - Open and configure a serial port
  • POST /api/cat/close - Close the currently opened port
  • GET /api/cat/status - Get current port connection status

CAT Commands

  • POST /api/cat/command - Send arbitrary CAT commands to the radio

Health Check

  • GET /health - Simple health check endpoint

Quick Start

Prerequisites

Running the Server

  1. Navigate to the server directory:

    cd Server/SharpCAT.Server
    
  2. Build and run the server:

    dotnet run
    
  3. The server will start and listen on http://localhost:5188 by default

  4. Open your browser to http://localhost:5188 to access the Swagger UI for interactive API documentation

Example Usage

List Available Ports

curl http://localhost:5188/api/cat/ports

Open a Serial Port

curl -X POST http://localhost:5188/api/cat/open \
  -H "Content-Type: application/json" \
  -d '{
    "portName": "COM3",
    "baudRate": 9600,
    "parity": "None",
    "stopBits": "One",
    "handshake": "None"
  }'

Send a CAT Command

curl -X POST http://localhost:5188/api/cat/command \
  -H "Content-Type: application/json" \
  -d '{"command": "FA;"}'

Check Status

curl http://localhost:5188/api/cat/status

Configuration

Port Configuration Options

When opening a port, you can configure:

  • Port Name: Serial port name (e.g., "COM1" on Windows, "/dev/ttyUSB0" on Linux)
  • Baud Rate: Communication speed (default: 9600)
  • Parity: Error checking method (None, Odd, Even, Mark, Space)
  • Stop Bits: Number of stop bits (None, One, Two, OnePointFive)
  • Handshake: Flow control method (None, XOnXOff, RequestToSend, RequestToSendXOnXOff)

Logging

The server uses ASP.NET Core's built-in logging. Log levels can be configured in appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "SharpCAT.Server": "Debug"
    }
  }
}

Development

Building from Source

  1. Ensure you have the .NET 8.0 SDK installed
  2. Clone the repository
  3. Navigate to the project root
  4. Build the solution:
    dotnet build
    

Project Structure

Server/SharpCAT.Server/
├── Controllers/
│   └── CatController.cs          # Main API controller
├── Models/
│   └── ApiModels.cs             # Request/response models
├── Services/
│   ├── ISerialCommunicationService.cs    # Service interface
│   └── SerialCommunicationService.cs     # Service implementation
├── Program.cs                   # Application entry point
└── SharpCAT.Server.csproj      # Project file

Dependencies

  • Microsoft.AspNetCore.OpenApi - OpenAPI support
  • Swashbuckle.AspNetCore - Swagger documentation
  • SharpCAT - Core CAT control library

License

This project follows the same license as the parent SharpCAT project.

Contributing

Contributions are welcome! Please follow the existing code style and add appropriate tests for new features.