mirror of
https://github.com/UzixLS/sdrsharp-catcontroller.git
synced 2025-07-18 14:51:28 +03:00
improve hamlib compatibility (#3)
This commit is contained in:
@ -1,27 +1,25 @@
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SerialController")]
|
||||
[assembly: AssemblyDescription("Serial port controller for SDR#")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SerialController")]
|
||||
[assembly: AssemblyCopyright("Copyright © Pawel Walczak 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: AssemblyTitle ("SerialController")]
|
||||
[assembly: AssemblyDescription ("Serial port controller for SDR#")]
|
||||
[assembly: AssemblyConfiguration ("")]
|
||||
[assembly: AssemblyCompany ("")]
|
||||
[assembly: AssemblyProduct ("SerialController")]
|
||||
[assembly: AssemblyCopyright ("")]
|
||||
[assembly: AssemblyTrademark ("")]
|
||||
[assembly: AssemblyCulture ("")]
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: ComVisible (false)]
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a69bd5ae-f03a-4dcf-856d-4303bf64e2a3")]
|
||||
|
||||
[assembly: Guid ("a69bd5ae-f03a-4dcf-856d-4303bf64e2a3")]
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
@ -32,5 +30,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion ("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion ("1.0.0.0")]
|
||||
|
@ -11,6 +11,7 @@ namespace SDRSharp.SerialController
|
||||
public interface ProtocolInterface
|
||||
{
|
||||
string EndMarker { get; }
|
||||
int MaxLen { get; }
|
||||
string PktTransmitter(string ChangedProperty);
|
||||
string PktReceiver(string ReveivedData);
|
||||
}
|
||||
|
@ -22,23 +22,28 @@ namespace SDRSharp.SerialController
|
||||
{DetectorType.LSB, 1},
|
||||
{DetectorType.USB, 2},
|
||||
{DetectorType.CW, 3},
|
||||
{DetectorType.RAW, 4}
|
||||
{DetectorType.RAW, 8}
|
||||
};
|
||||
static readonly Dictionary<uint, DetectorType> int2mode = new Dictionary<uint, DetectorType> {
|
||||
{1, DetectorType.LSB},
|
||||
{2, DetectorType.USB},
|
||||
{3, DetectorType.CW},
|
||||
{4, DetectorType.NFM},
|
||||
{5, DetectorType.AM}
|
||||
{5, DetectorType.AM},
|
||||
{8, DetectorType.RAW}
|
||||
};
|
||||
|
||||
public string EndMarker { get { return ";"; } }
|
||||
public int MaxLen { get { return 255; } }
|
||||
|
||||
SerialRadioInterface _radio;
|
||||
bool _DetectorSetFailure;
|
||||
|
||||
|
||||
public Protocol_TS50(SerialRadioInterface radio)
|
||||
{
|
||||
_radio = radio;
|
||||
_DetectorSetFailure = false;
|
||||
}
|
||||
|
||||
public string PktTransmitter(string ChangedProperty)
|
||||
@ -63,22 +68,54 @@ namespace SDRSharp.SerialController
|
||||
response += "IF";
|
||||
response += String.Format("{0:00000000000}", _radio.RadioFrequency);
|
||||
response += "0000000000000000";
|
||||
response += mode2int[_radio.RadioMode];
|
||||
if ( _DetectorSetFailure)
|
||||
response += 0;
|
||||
else
|
||||
response += mode2int[_radio.RadioMode];
|
||||
response += "0000000";
|
||||
response += EndMarker;
|
||||
}
|
||||
if (ReceivedData.StartsWith("FA", StringComparison.Ordinal)) {
|
||||
else if (ReceivedData == "FA") {
|
||||
response += "FA";
|
||||
response += String.Format("{0:00000000000}", _radio.RadioFrequency);
|
||||
response += EndMarker;
|
||||
}
|
||||
else if (ReceivedData.StartsWith("FA", StringComparison.Ordinal)) {
|
||||
long freq;
|
||||
if (long.TryParse(ReceivedData.Substring(2), out freq)) {
|
||||
_radio.RadioFrequency = freq;
|
||||
}
|
||||
}
|
||||
if (ReceivedData.StartsWith("MD", StringComparison.Ordinal)) {
|
||||
else if (ReceivedData == "MD") {
|
||||
response += "MD";
|
||||
if (_DetectorSetFailure)
|
||||
response += 0;
|
||||
else
|
||||
response += mode2int[_radio.RadioMode];
|
||||
response += EndMarker;
|
||||
}
|
||||
else if (ReceivedData.StartsWith("MD", StringComparison.Ordinal)) {
|
||||
uint mode;
|
||||
if (uint.TryParse(ReceivedData.Substring(2), out mode)) {
|
||||
_radio.RadioMode = int2mode[mode];
|
||||
try {
|
||||
_radio.RadioMode = int2mode[mode];
|
||||
_DetectorSetFailure = false;
|
||||
}
|
||||
catch {
|
||||
_DetectorSetFailure = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ReceivedData == "ID") {
|
||||
response += "ID";
|
||||
response += "021"; //XXX: TS-590S value, idk what's should be there for TS-50
|
||||
response += EndMarker;
|
||||
}
|
||||
else if (ReceivedData == "RX") {
|
||||
response += "RX";
|
||||
response += EndMarker;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,10 @@ namespace SDRSharp.SerialController
|
||||
private SerialPortCtrl _serialPort;
|
||||
private ProtocolInterface _Protocol;
|
||||
|
||||
long _LastRadioFrequency;
|
||||
DetectorType _LastRadioMode;
|
||||
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get { return _displayName; }
|
||||
@ -36,6 +40,8 @@ namespace SDRSharp.SerialController
|
||||
{
|
||||
_control = control;
|
||||
_control.PropertyChanged += PropertyChangedHandler;
|
||||
_LastRadioFrequency = _control.Frequency;
|
||||
_LastRadioMode = _control.DetectorType;
|
||||
_Protocol = new Protocol_TS50(this);
|
||||
_serialPort = new SerialPortCtrl(_Protocol);
|
||||
_controlPanel = new SerialControllerPanel(_serialPort);
|
||||
@ -51,6 +57,17 @@ namespace SDRSharp.SerialController
|
||||
|
||||
void PropertyChangedHandler(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case "Frequency":
|
||||
if (_LastRadioFrequency == _control.Frequency)
|
||||
return;
|
||||
break;
|
||||
case "DetectorType":
|
||||
if( _LastRadioMode == _control.DetectorType)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
if (_serialPort.IsOpen)
|
||||
{
|
||||
string response = _Protocol.PktTransmitter(e.PropertyName);
|
||||
@ -65,6 +82,7 @@ namespace SDRSharp.SerialController
|
||||
return _control.Frequency;
|
||||
}
|
||||
set {
|
||||
_LastRadioFrequency = value;
|
||||
_controlPanel.addToLogList(value.ToString("N0")+" Hz");
|
||||
_control.Frequency = value;
|
||||
}
|
||||
@ -76,6 +94,7 @@ namespace SDRSharp.SerialController
|
||||
return _control.DetectorType;
|
||||
}
|
||||
set {
|
||||
_LastRadioMode = value;
|
||||
_controlPanel.addToLogList(value.ToString());
|
||||
_control.DetectorType = value;
|
||||
}
|
||||
|
@ -19,10 +19,12 @@ namespace SDRSharp.SerialController
|
||||
|
||||
SerialPort _port;
|
||||
ProtocolInterface _protocol;
|
||||
string _received;
|
||||
|
||||
public SerialPortCtrl(ProtocolInterface protocol)
|
||||
{
|
||||
_protocol = protocol;
|
||||
_received = "";
|
||||
}
|
||||
|
||||
public static string[] GetAllPorts()
|
||||
@ -82,22 +84,22 @@ namespace SDRSharp.SerialController
|
||||
|
||||
void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
|
||||
{
|
||||
string data = "";
|
||||
while (data.IndexOf(_protocol.EndMarker) < 0) {
|
||||
byte[] bytes = new byte[_port.BytesToRead+32];
|
||||
try {
|
||||
_port.Read(bytes, 0, _port.BytesToRead);
|
||||
}
|
||||
catch (Exception) {
|
||||
return;
|
||||
}
|
||||
data += System.Text.Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
data = data.Substring(0, data.IndexOf(_protocol.EndMarker));
|
||||
while (_port.BytesToRead > 0) {
|
||||
if (_received.Length > _protocol.MaxLen)
|
||||
_received = "";
|
||||
|
||||
string response = _protocol.PktReceiver(data);
|
||||
if (! string.IsNullOrEmpty(response))
|
||||
DataTransmit(response);
|
||||
string input = ((char)_port.ReadChar()).ToString();
|
||||
if (input == _protocol.EndMarker) {
|
||||
string response = _protocol.PktReceiver(_received);
|
||||
if (! string.IsNullOrEmpty(response)) {
|
||||
DataTransmit(response);
|
||||
}
|
||||
_received = "";
|
||||
}
|
||||
else {
|
||||
_received += input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DataTransmit(string data)
|
||||
|
Reference in New Issue
Block a user