Compare commits

..

No commits in common. "9747599c6308914790e165e1823b6adc494d2b80" and "25510f8e19d3a8f7592e201acf8f5dfc34f8f7a7" have entirely different histories.

2 changed files with 13 additions and 14 deletions

View File

@ -1,6 +1,6 @@
# KV4P-Sharp
KV4P-Sharp is a C# library designed to communicate with KV4P USB VHF radios. It facilitates control over radio operations through serial communication but does not handle audio encoding or decoding. Users must manage audio processing separately by encoding/decoding audio data as PCM ~44100~ 16000Hz, 8-bit mono.
KV4P-Sharp is a C# library designed to communicate with KV4P USB VHF radios. It facilitates control over radio operations through serial communication but does not handle audio encoding or decoding. Users must manage audio processing separately by encoding/decoding audio data as PCM 44100Hz, 8-bit mono.
## Features
- Control transmit (PTT) and receive (RX) modes.

View File

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