This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSerialControllerPlugin.cs
104 lines (88 loc) · 2.76 KB
/
SerialControllerPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.ComponentModel;
using System.Windows.Forms;
using SDRSharp.Common;
using SDRSharp.Radio;
namespace SDRSharp.SerialController
{
public class SerialControllerPlugin: ISharpPlugin,SerialRadioInterface
{
private const string _displayName = "SerialController";
private ISharpControl _control;
private SerialControllerPanel _controlPanel;
private SerialPortCtrl _serialPort;
private ProtocolInterface _Protocol;
long _LastRadioFrequency;
DetectorType _LastRadioMode;
public string DisplayName
{
get { return _displayName; }
}
public bool HasGui
{
get { return true; }
}
public UserControl Gui
{
get { return _controlPanel; }
}
public void Initialize(ISharpControl control)
{
_control = control;
_control.PropertyChanged += PropertyChangedHandler;
_LastRadioFrequency = _control.Frequency;
_LastRadioMode = _control.DetectorType;
_Protocol = new Protocol_TS50(this);
_serialPort = new SerialPortCtrl(_Protocol);
_controlPanel = new SerialControllerPanel(_serialPort);
_controlPanel.readSettings();
}
public void Close()
{
_serialPort.closePort();
_controlPanel.saveSettings();
}
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);
if (! string.IsNullOrEmpty(response))
_serialPort.DataTransmit(response);
}
}
public long RadioFrequency
{
get {
return _control.Frequency;
}
set {
_LastRadioFrequency = value;
_controlPanel.addToLogList(value.ToString("N0")+" Hz");
_control.Frequency = value;
}
}
public DetectorType RadioMode
{
get {
return _control.DetectorType;
}
set {
_LastRadioMode = value;
_controlPanel.addToLogList(value.ToString());
_control.DetectorType = value;
}
}
}
}