Update RadioController.cs for V4 Format

This commit is contained in:
Andrea Santaniello 2025-01-08 16:38:43 +01:00 committed by GitHub
parent 25510f8e19
commit f8389e0ddf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,10 +44,10 @@ public class RadioController : IDisposable
} }
private RadioMode currentMode = RadioMode.STARTUP; private RadioMode currentMode = RadioMode.STARTUP;
private const int MIN_FIRMWARE_VER = 1; private const int MIN_FIRMWARE_VER = 4;
private string versionStrBuffer = ""; private string versionStrBuffer = "";
private const int AUDIO_SAMPLE_RATE = 44100; private const int AUDIO_SAMPLE_RATE = 16000;
// Synchronization locks // Synchronization locks
private readonly object _syncLock = new object(); private readonly object _syncLock = new object();
@ -148,13 +148,14 @@ public class RadioController : IDisposable
} }
/// <summary> /// <summary>
/// Tunes the radio to the specified frequencies with tone and squelch level. /// Tunes the radio to the specified frequencies with tone, squelch level, and bandwidth.
/// </summary> /// </summary>
/// <param name="txFrequencyStr">Transmit frequency as a string (e.g., "146.520").</param> /// <param name="txFrequencyStr">Transmit frequency as a string (e.g., "146.520").</param>
/// <param name="rxFrequencyStr">Receive frequency as a string (e.g., "146.520").</param> /// <param name="rxFrequencyStr">Receive frequency as a string (e.g., "146.520").</param>
/// <param name="tone">Tone value as an integer (00 to 99).</param> /// <param name="tone">Tone value as an integer (00 to 99).</param>
/// <param name="squelchLevel">Squelch level as an integer (0 to 9).</param> /// <param name="squelchLevel">Squelch level as an integer (0 to 9).</param>
public void TuneToFrequency(string txFrequencyStr, string rxFrequencyStr, int tone, int squelchLevel) /// <param name="wideband">True for 25kHz bandwidth, false for 12.5kHz bandwidth.</param>
public void TuneToFrequency(string txFrequencyStr, string rxFrequencyStr, int tone, int squelchLevel, bool wideband)
{ {
if (string.IsNullOrWhiteSpace(txFrequencyStr)) if (string.IsNullOrWhiteSpace(txFrequencyStr))
throw new ArgumentException("Transmit frequency cannot be null or empty.", nameof(txFrequencyStr)); throw new ArgumentException("Transmit frequency cannot be null or empty.", nameof(txFrequencyStr));
@ -172,8 +173,9 @@ public class RadioController : IDisposable
if (squelchStr.Length != 1) if (squelchStr.Length != 1)
throw new ArgumentException("Squelch level must be a single digit (0-9).", nameof(squelchLevel)); throw new ArgumentException("Squelch level must be a single digit (0-9).", nameof(squelchLevel));
// Build parameters string // Build parameters string with bandwidth setting
string paramsStr = txFrequencyStr + rxFrequencyStr + toneStr + squelchStr; string bandwidthSetting = wideband ? "W" : "N";
string paramsStr = txFrequencyStr + rxFrequencyStr + toneStr + squelchStr + bandwidthSetting;
SendCommand(ESP32Command.TUNE_TO, paramsStr); SendCommand(ESP32Command.TUNE_TO, paramsStr);
} }
@ -256,7 +258,7 @@ public class RadioController : IDisposable
} }
else if (mode == RadioMode.STARTUP) else if (mode == RadioMode.STARTUP)
{ {
// Handle firmware version check // Handle firmware version check with updated minimum version
string dataStr = System.Text.Encoding.UTF8.GetString(data); string dataStr = System.Text.Encoding.UTF8.GetString(data);
lock (_versionStrBufferLock) lock (_versionStrBufferLock)
{ {
@ -271,7 +273,7 @@ public class RadioController : IDisposable
{ {
if (verInt < MIN_FIRMWARE_VER) if (verInt < MIN_FIRMWARE_VER)
{ {
OnErrorOccurred(new ErrorEventArgs(new InvalidOperationException("Unsupported firmware version."))); OnErrorOccurred(new ErrorEventArgs(new InvalidOperationException($"Unsupported firmware version. Version 4 or higher is required.")));
} }
else else
{ {
@ -279,7 +281,6 @@ public class RadioController : IDisposable
{ {
currentMode = RadioMode.RX; currentMode = RadioMode.RX;
} }
// No need to initialize audio playback
} }
} }
else else