mirror of
https://github.com/ekinnee/SharpCAT.git
synced 2026-04-09 08:23:37 +00:00
Add SharpCAT.Client library with full API implementation
Co-authored-by: ekinnee <1707617+ekinnee@users.noreply.github.com>
This commit is contained in:
parent
1c02dc4cac
commit
99ac9e3b59
6 changed files with 820 additions and 0 deletions
216
Client/Models/ApiModels.cs
Normal file
216
Client/Models/ApiModels.cs
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SharpCAT.Client.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Parity settings for serial communication
|
||||
/// </summary>
|
||||
public enum Parity
|
||||
{
|
||||
/// <summary>
|
||||
/// No parity checking
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// Odd parity checking
|
||||
/// </summary>
|
||||
Odd = 1,
|
||||
/// <summary>
|
||||
/// Even parity checking
|
||||
/// </summary>
|
||||
Even = 2,
|
||||
/// <summary>
|
||||
/// Mark parity checking
|
||||
/// </summary>
|
||||
Mark = 3,
|
||||
/// <summary>
|
||||
/// Space parity checking
|
||||
/// </summary>
|
||||
Space = 4
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop bits settings for serial communication
|
||||
/// </summary>
|
||||
public enum StopBits
|
||||
{
|
||||
/// <summary>
|
||||
/// No stop bits
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// One stop bit
|
||||
/// </summary>
|
||||
One = 1,
|
||||
/// <summary>
|
||||
/// Two stop bits
|
||||
/// </summary>
|
||||
Two = 2,
|
||||
/// <summary>
|
||||
/// One and a half stop bits
|
||||
/// </summary>
|
||||
OnePointFive = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handshake settings for serial communication
|
||||
/// </summary>
|
||||
public enum Handshake
|
||||
{
|
||||
/// <summary>
|
||||
/// No flow control
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// XOn/XOff software flow control
|
||||
/// </summary>
|
||||
XOnXOff = 1,
|
||||
/// <summary>
|
||||
/// RTS hardware flow control
|
||||
/// </summary>
|
||||
RequestToSend = 2,
|
||||
/// <summary>
|
||||
/// Both RTS and XOn/XOff flow control
|
||||
/// </summary>
|
||||
RequestToSendXOnXOff = 3
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response model for listing available serial ports
|
||||
/// </summary>
|
||||
public class PortListResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Array of available serial port names
|
||||
/// </summary>
|
||||
public string[] Ports { get; set; } = new string[0];
|
||||
|
||||
/// <summary>
|
||||
/// Number of available ports
|
||||
/// </summary>
|
||||
public int Count => Ports.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for opening a serial port
|
||||
/// </summary>
|
||||
public class OpenPortRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the serial port to open (e.g., "COM1", "/dev/ttyUSB0")
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string PortName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Baud rate for communication (default: 9600)
|
||||
/// </summary>
|
||||
public int BaudRate { get; set; } = 9600;
|
||||
|
||||
/// <summary>
|
||||
/// Parity setting (default: None)
|
||||
/// </summary>
|
||||
public Parity Parity { get; set; } = Parity.None;
|
||||
|
||||
/// <summary>
|
||||
/// Stop bits setting (default: One)
|
||||
/// </summary>
|
||||
public StopBits StopBits { get; set; } = StopBits.One;
|
||||
|
||||
/// <summary>
|
||||
/// Handshake setting (default: None)
|
||||
/// </summary>
|
||||
public Handshake Handshake { get; set; } = Handshake.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response model for port operations
|
||||
/// </summary>
|
||||
public class PortOperationResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the operation was successful
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable message about the operation
|
||||
/// </summary>
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the port that was operated on
|
||||
/// </summary>
|
||||
public string? PortName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current status of the port (open/closed)
|
||||
/// </summary>
|
||||
public bool IsOpen { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request model for sending CAT commands
|
||||
/// </summary>
|
||||
public class SendCommandRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// CAT command string to send to the radio
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Command { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response model for CAT command operations
|
||||
/// </summary>
|
||||
public class CommandResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if the command was sent successfully
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The command that was sent
|
||||
/// </summary>
|
||||
public string Command { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Response received from the radio (if any)
|
||||
/// </summary>
|
||||
public string? Response { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable message about the operation
|
||||
/// </summary>
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp when the command was executed
|
||||
/// </summary>
|
||||
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response model for errors
|
||||
/// </summary>
|
||||
public class ErrorResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Error message
|
||||
/// </summary>
|
||||
public string Error { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Additional details about the error
|
||||
/// </summary>
|
||||
public string? Details { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp when the error occurred
|
||||
/// </summary>
|
||||
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue