-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainForm.cs
534 lines (449 loc) · 18.7 KB
/
MainForm.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace CellInfo
{
public partial class MainForm : Form
{
private bool flg = false;
private bool Record_flag = false;
private int delt_t = 300;
private int RefreshInterval = 1000;
PortConfigure Portconfigure = new PortConfigure();
Serving_Zone Servingfrm = new Serving_Zone();
Neighbor_Zone Neighborfrm = new Neighbor_Zone();
Wave_Zone Wavefrm = new Wave_Zone();
TCH_Zone TCHfrm = new TCH_Zone();
ComPortClass Serialport = new ComPortClass();
ErrorReportForm ErrorReportfrm = new ErrorReportForm();
ListInfo listInform = new ListInfo();
static public string PortStatusLabel = "SerialPort's Status";
private string[] result;
private string[] result1;
private string[] resultBackup;
private string[] result1Backup;
private string ServingCellInfo;
private string NeighborCellInfo;
private string[] temp = new string[12];
private string[,] temp2 = new string[6, 8];
public MainForm()
{
InitializeComponent();
InitializeForms();
}
/// <summary>
/// 窗体初始化
/// </summary>
private void InitializeForms()
{
timer1.Enabled = false;
Servingfrm.MdiParent = this;
Servingfrm.Show();
Servingfrm.Bounds = new Rectangle(0, 0, 410, 340);
Neighborfrm.MdiParent = this;
Neighborfrm.Show();
Neighborfrm.Bounds = new Rectangle(0, 340, 540, 280);
Wavefrm.MdiParent = this;
Wavefrm.Show();
Wavefrm.Bounds = new Rectangle(410, 0, 550, 340);
TCHfrm.MdiParent = this;
TCHfrm.Show();
TCHfrm.Bounds = new Rectangle(540, 340, 420, 240);
this.toolStripStatusLabel1.Text = PortStatusLabel;
}
/// <summary>
/// 菜单栏“记录历史信息”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void exportToolStripMenuItem_Click(object sender, EventArgs e)
{
Record_flag = true;
/* saveFileDialog1.Title = "设置历史记录文件的存储路径";
saveFileDialog1.Filter = "历史记录文件(*.xml)|*.xml|All files(*.*)|*.*";
saveFileDialog1.InitialDirectory = @"c:\";
saveFileDialog1.ShowDialog();
string FileNamePath = saveFileDialog1.FileName.ToString();
string FilePath = FileNamePath.Substring(FileNamePath.LastIndexOf("\\") + 1);
recorder.infoRecorder.setSignalFilePath(FilePath);
*/ }
/// <summary>
/// 显示当前小区信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 当前小区ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Servingfrm == null || Servingfrm.IsDisposed)
{
Servingfrm = new Serving_Zone();
}
Servingfrm.MdiParent = this;
Servingfrm.Show();
Servingfrm.Bounds = new Rectangle(0, 0, 410, 340);
}
/// <summary>
/// 显示邻居小区信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 邻居小区ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Neighborfrm == null || Neighborfrm.IsDisposed)
{
Neighborfrm = new Neighbor_Zone();
}
Neighborfrm.MdiParent = this;
Neighborfrm.Show();
Neighborfrm.Bounds = new Rectangle(0, 340, 540, 280);
}
/// <summary>
/// 显示当前业务信道基本信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 业务信道_Click(object sender, EventArgs e)
{
if (TCHfrm == null || TCHfrm.IsDisposed)
{
TCHfrm = new TCH_Zone();
}
TCHfrm.MdiParent = this;
TCHfrm.Show();
TCHfrm.Bounds = new Rectangle(540,340, 420, 240);
}
/// <summary>
/// 显示当前小区和邻居小区波形图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 波形图ToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (Wavefrm == null || Wavefrm.IsDisposed)
{
Wavefrm = new Wave_Zone();
}
Wavefrm.MdiParent = this;
Wavefrm.Show();
Wavefrm.Bounds = new Rectangle(410, 0, 550, 340);
}
/// <summary>
/// 显示错误报告信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 错误报告ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ErrorReportfrm == null || ErrorReportfrm.IsDisposed)
{
ErrorReportfrm = new ErrorReportForm();
}
ErrorReportfrm.MdiParent = this; //建立父子关系
ErrorReportfrm.Show(); //显示子窗口
ErrorReportfrm.Bounds = new Rectangle(0, 390, 547, 199);
}
/// <summary>
/// 层叠当前子窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 层叠窗口ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
/// <summary>
/// 水平平铺当前子窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 水平平铺ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}
/// <summary>
/// 垂直平铺当前子窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 垂直平铺ToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
/// <summary>
/// 关闭所有当前子窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 关闭所有子窗口ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form[] frmList = this.MdiChildren;
foreach (Form frm in frmList)
{
frm.Close();
}
}
/// <summary>
/// 串口设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton1_Click(object sender, EventArgs e)
{
Portconfigure.ShowDialog();
toolStripStatusLabel1.Text = "";
if (Portconfigure.portName == "")
{
toolStripStatusLabel1.Text = "No COM Port Found!";
}
flg = true;
}
/// <summary>
/// 开始运行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (flg)
{
Serialport.Port_Assignment(Portconfigure.portName, Portconfigure.baudRate, Portconfigure.handShake, Portconfigure.parity, Portconfigure.dataBits, Portconfigure.stopBits);
// toolStripStatusLabel1.Text = "Port Name:" + Portconfigure.portName +"; Baud Rate:" + Portconfigure.baudRate + "; Handshake:" + Portconfigure.handShake + "; Parity:" + Portconfigure.parity + "; Data Bits:" + Convert.ToString(Portconfigure.dataBits) + "; Stop Bits:" + Portconfigure.stopBits;
//采样刷新
timer1.Interval = RefreshInterval;
timer1.Enabled = true;
}
else
{
MessageBox.Show("请先进行串口设置", "提示信息");
}
}
/// <summary>
/// 串口信息更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
Serialport.OpenComPort();
try
{
ServingCellInfo = Serialport.AT_Serving(delt_t);
NeighborCellInfo = Serialport.AT_Neighbor(delt_t);
result = FileOperate.DataPull(ServingCellInfo);
result1 = FileOperate.DataPull(NeighborCellInfo);
if (result[26] != "ChMod")
{
Servingfrm.Serving_Assignment(result);
Neighborfrm.Neighbor_Assignment(result1);
Wavefrm.Wave_Assignment(result, result1);
Wavefrm.TimerStart();
//数据备份
resultBackup = result;
result1Backup = result1;
if (Record_flag)
{
for (int i = 0; i <= recorder.infoRecorder.signalDetail.GetLength(0) - 1; i++)
{
temp[i] = result[i + 26];
}
recorder.infoRecorder.writeSignalToXml(temp);
for (int i = 0; i <= 2; i++)
{
for (int j = 0; j <= recorder.infoRecorder.neighborDetail.GetLength(0) - 1; j++)
{
temp2[i, j] = Convert.ToString(result1[j + 9 + i * 8]);
temp2[i + 3, j] = Convert.ToString(result1[j + 9 + i * 8]);
}
}
recorder.infoRecorder.writeNeighborToXml(temp2);
}
//while (result[39] != "No" && result[39] != "Limited" && result[39] != "Cell" && result[39] != "I")
//{
// TCHfrm.TCH_Assignment(result);
//}
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
Servingfrm.Serving_Assignment(resultBackup);
Neighborfrm.Neighbor_Assignment(result1Backup);
}
}
private void 历史记录ToolStripMenuItem_Click(object sender, EventArgs e)
{
//获得文件路径
//localFilePath = saveFileDialog1.FileName.ToString();
//获取文件名,不带路径
//fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
//获取文件路径,不带文件名
//FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
saveFileDialog1.Title = "导出历史记录文件";
saveFileDialog1.Filter = "历史记录文件(*.xml)|*.xml|All files(*.*)|*.*";
// string SavePath = saveFileDialog1.FileName;
saveFileDialog1.InitialDirectory = @"c:\";
saveFileDialog1.ShowDialog();
string FileNamePath = saveFileDialog1.FileName.ToString();
string FilePath = FileNamePath.Substring(FileNamePath.LastIndexOf("\\") + 1);
recorder.infoRecorder.setSignalFilePath(FilePath);
}
/// <summary>
/// 菜单栏串口设置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 串口配置ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Portconfigure == null || Portconfigure.IsDisposed)
{
Portconfigure = new PortConfigure();
}
Portconfigure.ShowDialog();
toolStripStatusLabel1.Text = "";
if (Portconfigure.portName == "")
{
toolStripStatusLabel1.Text = "No COM Port Found!";
}
flg = true;
}
/// <summary>
/// 系统菜单栏路径配置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 路径配置ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 开始测试菜单栏
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 开始测试ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (flg)
{
Serialport.Port_Assignment(Portconfigure.portName, Portconfigure.baudRate, Portconfigure.handShake, Portconfigure.parity, Portconfigure.dataBits, Portconfigure.stopBits);
toolStripStatusLabel1.Text = "Port Name:" + Portconfigure.portName + "; Baud Rate:" + Portconfigure.baudRate + "; Handshake:" + Portconfigure.handShake + "; Parity:" + Portconfigure.parity + "; Data Bits:" + Convert.ToString(Portconfigure.dataBits) + "; Stop Bits:" + Portconfigure.stopBits;
//采样刷新
timer1.Interval = 1000;
timer1.Enabled = true;
}
else
{
MessageBox.Show("请先进行串口设置", "提示信息");
}
}
/// <summary>
/// 工具栏“停止”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton8_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
Wavefrm.TimerEnd();
// Application.Exit();
}
/// <summary>
/// 菜单栏“系统退出”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 系统退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
// timer1.Enabled = false;
Application.Exit();
}
/// <summary>
/// 历史菜单栏->导入波形图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 波形图ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listInform == null || listInform.IsDisposed)
{
listInform = new ListInfo();
listInform.Show();
}
listInform.MdiParent = this;
listInform.Show();
listInform.Bounds = new Rectangle(0, 340, 500, 410);
}
/// <summary>
/// 历史菜单栏->导入当前小区历史信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void servingZoneToolStripMenuItem_Click(object sender, EventArgs e)
{
//"chann", "rs", "dBm", "MCC", "MNC", "LAC", "cell", "NCC", "BCC", "PWR", "RXLev", "C1"
openFileDialog1.Title = "导出历史记录文件";
openFileDialog1.Filter = "当前小区信息历史记录文件(*.xml)|*.xml|All files(*.*)|*.*";
openFileDialog1.InitialDirectory = @"c:\";
openFileDialog1.ShowDialog();
ServingZone_Info ServingXml = new ServingZone_Info();
ServingXml.MdiParent = this;
string[] servingTemp;
string servingTime;
int i;
recorder.infoRecorder.signalFilePath = openFileDialog1.FileName.ToString();
while (recorder.infoRecorder.getNextSignalData(out servingTemp, out servingTime) != 1)
{
DataRow Servingrow = ServingXml.dt.NewRow();
ServingXml.dt.Rows.Add(Servingrow);
Servingrow["Time"] = servingTime;
for (i = 0; i <= recorder.infoRecorder.signalDetail.GetLength(0) - 1; i++)
{
Servingrow[recorder.infoRecorder.signalDetail[i]] = servingTemp[i];
}
Thread.Sleep(200);
}
ServingXml.Show();
}
/// <summary>
/// 历史菜单栏导入->邻居小区历史信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void neighborZoneToolStripMenuItem_Click(object sender, EventArgs e)
{
NeighborZone_Info NeighborXml = new NeighborZone_Info();
NeighborXml.MdiParent = this;
openFileDialog2.Title = "导出历史记录文件";
openFileDialog2.Filter = "当前小区信息历史记录文件(*.xml)|*.xml|All files(*.*)|*.*";
openFileDialog2.InitialDirectory = @"c:\";
openFileDialog2.ShowDialog();
recorder.infoRecorder.neighborFilePath = openFileDialog2.FileName.ToString();
string[,] neighborTemp;
string neighborTime;
int i, j, k = 0;
while (recorder.infoRecorder.getNextNeighborData(out neighborTemp, out neighborTime) != 1)
{
DataRow Neighborrow = NeighborXml.dt.NewRow();
NeighborXml.dt.Rows.Add(Neighborrow);
Neighborrow["Time"] = neighborTime;
Neighborrow["Cell Num"] = ++k;
for (j = 0; j < 6; j++)
{
for (i = 0; i <= recorder.infoRecorder.neighborDetail.GetLength(0) - 1; i++)
{
Neighborrow[recorder.infoRecorder.neighborDetail[i]] = neighborTemp[j, i];
}
Thread.Sleep(200);
}
}
NeighborXml.Show();
}
private void toolStripButton9_Click(object sender, EventArgs e)
{
Record_flag = true;
}
}
}