This repository was archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProtocol_TS50.cs
More file actions
123 lines (112 loc) · 3.22 KB
/
Protocol_TS50.cs
File metadata and controls
123 lines (112 loc) · 3.22 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Created by SharpDevelop.
* User: uzix
* Date: 02.05.2016
* Time: 17:00
*/
using System;
using System.Collections.Generic;
using SDRSharp.Radio;
namespace SDRSharp.SerialController
{
public class Protocol_TS50 : ProtocolInterface
{
static readonly Dictionary<DetectorType, uint> mode2int = new Dictionary<DetectorType, uint> {
{DetectorType.NFM, 4},
{DetectorType.WFM, 4},
{DetectorType.AM, 5},
{DetectorType.DSB, 5},
{DetectorType.LSB, 1},
{DetectorType.USB, 2},
{DetectorType.CW, 3},
{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},
{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)
{
string response = "";
switch (ChangedProperty)
{
case "Frequency":
response = "FA" + String.Format("{0:00000000000}", _radio.RadioFrequency) + ";";
break;
case "DetectorType":
response = "MD" + mode2int[_radio.RadioMode] + ";";
break;
}
return response;
}
public string PktReceiver(string ReceivedData)
{
string response = "";
if (ReceivedData.StartsWith("IF", StringComparison.Ordinal)) {
response += "IF";
response += String.Format("{0:00000000000}", _radio.RadioFrequency);
response += "0000000000000000";
if ( _DetectorSetFailure)
response += 0;
else
response += mode2int[_radio.RadioMode];
response += "0000000";
response += EndMarker;
}
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;
}
}
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)) {
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;
}
}
}