-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathForm1.cs
295 lines (246 loc) · 8.78 KB
/
Form1.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
using Shimmer32FeetAPI.Radios;
using ShimmerAPI.Protocols;
using ShimmerAPI.Radios;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace SpeedTestExample
{
public partial class Form1 : Form
{
private static bool canUpdate = true;
public Form1()
{
InitializeComponent();
}
System.Threading.Timer timer = new System.Threading.Timer(EnableUpdate, null, 0, 1000); // Enable update every second
private static void EnableUpdate(object state)
{
canUpdate = true; // Enable update every second
}
SerialPortRadio radio;
SpeedTestProtocol SerialPortSpeedTestProtocol;
SpeedTestProtocol BLE32FeetSpeedTestProtocol;
SpeedTestProtocol TestRadioSpeedTestProtocol;
BLE32FeetRadio radioBLE;
TestRadio testRadio;
private void button1_Click(object sender, EventArgs e)
{
if (radio != null)
{
radio.RadioStatusChanged -= RadioStateChanged;
}
radio = new SerialPortRadio(textBox2.Text);
radio.RadioStatusChanged += RadioStateChanged;
if (SerialPortSpeedTestProtocol != null)
{
SerialPortSpeedTestProtocol.ResultUpdate -= ResultUpdated;
}
SerialPortSpeedTestProtocol = new SpeedTestProtocol(radio);
SerialPortSpeedTestProtocol.ResultUpdate += ResultUpdated;
SerialPortSpeedTestProtocol.Connect();
}
private void ResultUpdated(object sender, string e)
{
if (canUpdate)
{
SetTextResult(e);
canUpdate = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
SerialPortSpeedTestProtocol.StartTestSignal();
}
private void button4_Click(object sender, EventArgs e)
{
if (radioBLE != null)
{
radioBLE.RadioStatusChanged -= RadioStateChanged;
}
radioBLE = new BLE32FeetRadio(textBox1.Text, BLE32FeetRadio.DeviceType.Shimmer3BLE);
radioBLE.RadioStatusChanged += RadioStateChanged;
if (BLE32FeetSpeedTestProtocol != null)
{
BLE32FeetSpeedTestProtocol.ResultUpdate -= ResultUpdated;
}
BLE32FeetSpeedTestProtocol = new SpeedTestProtocol(radioBLE);
BLE32FeetSpeedTestProtocol.ResultUpdate += ResultUpdated;
BLE32FeetSpeedTestProtocol.Connect();
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.label5.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.label5.Text = text;
}
}
delegate void SetTextResultCallback(string text);
private void SetTextResult(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.label5.InvokeRequired)
{
SetTextResultCallback d = new SetTextResultCallback(SetTextResult);
this.Invoke(d, new object[] { text });
}
else
{
this.label8.Text = text;
}
}
private void RadioStateChanged(object sender, AbstractRadio.RadioStatus e)
{
SetText(e.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StartTestSignal();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
SerialPortSpeedTestProtocol.StopTestSignal();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
SerialPortSpeedTestProtocol.Disconnect();
}
private void button8_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StopTestSignal();
}
private void button7_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.Disconnect();
}
private void button12_Click(object sender, EventArgs e)
{
if (testRadio != null)
{
testRadio.RadioStatusChanged -= RadioStateChanged;
}
testRadio = new TestRadio();
testRadio.RadioStatusChanged += RadioStateChanged;
if (TestRadioSpeedTestProtocol != null)
{
TestRadioSpeedTestProtocol.ResultUpdate -= ResultUpdated;
}
TestRadioSpeedTestProtocol = new SpeedTestProtocol(testRadio);
TestRadioSpeedTestProtocol.ResultUpdate += ResultUpdated;
TestRadioSpeedTestProtocol.Connect();
}
private void button11_Click(object sender, EventArgs e)
{
TestRadioSpeedTestProtocol.StartTestSignal();
}
private void button10_Click(object sender, EventArgs e)
{
TestRadioSpeedTestProtocol.StopTestSignal();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void button16_Click(object sender, EventArgs e)
{
if (radioBLE != null)
{
radioBLE.RadioStatusChanged -= RadioStateChanged;
}
radioBLE = new BLE32FeetRadio(textBox3.Text, BLE32FeetRadio.DeviceType.Shimmer3R);
radioBLE.RadioStatusChanged += RadioStateChanged;
if (BLE32FeetSpeedTestProtocol != null)
{
BLE32FeetSpeedTestProtocol.ResultUpdate -= ResultUpdated;
}
BLE32FeetSpeedTestProtocol = new SpeedTestProtocol(radioBLE);
BLE32FeetSpeedTestProtocol.ResultUpdate += ResultUpdated;
BLE32FeetSpeedTestProtocol.Connect();
}
private void button15_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StartTestSignal();
}
private void button14_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StopTestSignal();
}
private void button13_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.Disconnect();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void label8_Click(object sender, EventArgs e)
{
}
private void button9_Click(object sender, EventArgs e)
{
testRadio.Disconnect();
}
private void button20_Click(object sender, EventArgs e)
{
if (radioBLE != null)
{
radioBLE.RadioStatusChanged -= RadioStateChanged;
}
radioBLE = new BLE32FeetRadio(textBox4.Text, BLE32FeetRadio.DeviceType.Verisense);
radioBLE.RadioStatusChanged += RadioStateChanged;
if (BLE32FeetSpeedTestProtocol != null)
{
BLE32FeetSpeedTestProtocol.ResultUpdate -= ResultUpdated;
}
BLE32FeetSpeedTestProtocol = new SpeedTestProtocol(radioBLE);
BLE32FeetSpeedTestProtocol.ResultUpdate += ResultUpdated;
BLE32FeetSpeedTestProtocol.Connect();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void button19_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StartTestSignal();
}
private void button18_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StopTestSignal();
}
private void button17_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.Disconnect();
}
}
}