-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRDSOutputPanel.cs
More file actions
213 lines (158 loc) · 4.63 KB
/
RDSOutputPanel.cs
File metadata and controls
213 lines (158 loc) · 4.63 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
using SDRSharp.Common;
using SDRSharp.Radio;
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Timers;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
//using System.Text;
namespace SDRSharp.RDSOutput
{
public partial class RDSOutputPanel : UserControl
{
private readonly ISharpControl _controlInterface;
private bool m_terminalIsOpen = false;
ServerTerminal m_serverTerminal;
public RDSOutputPanel()
{
InitializeComponent();
}
public RDSOutputPanel(ISharpControl control)
{
try
{
this.InitializeComponent();
this._controlInterface = control;
}
catch (Exception ex)
{
string text = string.Format("Error {0}", ex.Message);
MessageBox.Show(text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
static void SendUdp2(int srcPort, string dstIp, int dstPort, byte[] sendBytes)
{
IPEndPoint Dymola = new IPEndPoint(IPAddress.Parse (dstIp), dstPort);
using(UdpClient udpClient = new UdpClient(srcPort))
{
udpClient.Send(sendBytes, sendBytes.Length, Dymola);
}
}
public void printData(ref RdsFrame _rdsFrame)
{
if(m_terminalIsOpen)
{
if (checkBoxRFtapOn.Checked == true) {
byte[] header = {
0x52,
0x46,
0x74,
0x61,
4,
0,
0,
0,
0x10,
0,
3,
0xFF,
0x72,
0x64,
0x73,
0
};
byte[] payload = {0,0,0,0,0,0,0,0,0x41,0x42,0x43,0x44};
MemoryStream MS = new MemoryStream();
BinaryWriter Writer1 = new BinaryWriter(MS);
Writer1.Write(header);
payload[0] = (byte) (_rdsFrame.GroupA >> 8 );
payload[1] = (byte) (_rdsFrame.GroupA & 0x00FF );
payload[2] = (byte) (_rdsFrame.GroupB >> 8 );
payload[3] = (byte) (_rdsFrame.GroupB & 0x00FF );
payload[4] = (byte) (_rdsFrame.GroupC >> 8 );
payload[5] = (byte) (_rdsFrame.GroupC & 0x00FF );
payload[6] = (byte) (_rdsFrame.GroupD >> 8 );
payload[7] = (byte) (_rdsFrame.GroupD & 0x00FF );
Writer1.Write(payload);
var byts = MS.ToArray();
SendUdp2(56148, "101.64.121.21", 52001, byts);
MS.Dispose();
}
m_serverTerminal.SendMessage("G:\r\n");
m_serverTerminal.SendMessage(_rdsFrame.GroupA.ToString("X4"));
m_serverTerminal.SendMessage(_rdsFrame.GroupB.ToString("X4"));
m_serverTerminal.SendMessage(_rdsFrame.GroupC.ToString("X4"));
m_serverTerminal.SendMessage(_rdsFrame.GroupD.ToString("X4"));
m_serverTerminal.SendMessage("\r\n\r\n");
}
}
void m_Terminal_ClientDisConnected(System.Net.Sockets.Socket socket)
{
PublishMessage(listBox1 , string.Format("Client {0} disconnected!", socket.LocalEndPoint));
}
void m_Terminal_ClientConnected(System.Net.Sockets.Socket socket)
{
PublishMessage(listBox1, string.Format("Client {0} connected!", socket.LocalEndPoint));
}
private void createTerminal(int alPort)
{
m_serverTerminal = new ServerTerminal();
m_serverTerminal.ClientConnect += m_Terminal_ClientConnected;
m_serverTerminal.ClientDisconnect += m_Terminal_ClientDisConnected;
m_serverTerminal.StartListen(alPort);
m_terminalIsOpen = true;
}
private void closeTerminal()
{
m_terminalIsOpen = false;
m_serverTerminal.ClientConnect -= new TCPTerminal_ConnectDel(m_Terminal_ClientConnected);
m_serverTerminal.ClientDisconnect -= new TCPTerminal_DisconnectDel(m_Terminal_ClientDisConnected);
m_serverTerminal.Close();
}
private void PublishMessage(ListBox listBox, string mes)
{
if (InvokeRequired)
{
BeginInvoke((ThreadStart) delegate { PublishMessage(listBox, mes); });
return;
}
listBox.Items.Add(mes);
}
void CheckBoxRFtapOnCheckedChanged(object sender, EventArgs e)
{
/*
if (checkBoxPlugOn.Checked == true) {
try {
int alPort = 23;
createTerminal(alPort);
} catch (Exception se) {
MessageBox.Show(se.Message);
}
}
else
{
closeTerminal();
}*/
}
void CheckBoxPDSSpyOnCheckedChanged(object sender, EventArgs e)
{
if (checkBoxRDSSpyOn.Checked == true) {
try {
const int alPort = 23;
createTerminal(alPort);
} catch (Exception se) {
MessageBox.Show(se.Message);
}
}
else
{
closeTerminal();
}
}
}
}