张泳健 hace 7 años
padre
commit
fc4266ec23

+ 14 - 0
DotNettyFrom.sln.DotSettings.user Ver fichero

@@ -0,0 +1,14 @@
1
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2
+	<s:String x:Key="/Default/Environment/ContinuousTesting/ScopeCriterion/@EntryValue">+SNpzQIAAAD5I2nNAgAAAIlsuiH1vSchAgAAANEO3FwfAAAAQwBvAG4AdABpAG4AdQBvAHUAcwBUAGUAcwB0AGkAbgBnAEgAbwBzAHQAUAByAG8AdgBpAGQAZQByAEkAZAAwh2K/AQAAAOWawpcGAAAATQBTAFQAZQBzAHQAJAAAAEIARQA5ADMARQBFAEMANgAtADUAMwBGADMALQA0ADMAQgA5AC0AQgA0AEIAQgAtADIAOQAxAEMARABBAEUANAA2ADIAOQAwABwAAAAuAE4ARQBUAEYAcgBhAG0AZQB3AG8AcgBrACwAVgBlAHIAcwBpAG8AbgA9AHYANAAuADYALgAxACcAAABEAG8AdABOAGUAdAB0AHkARgByAG8AbQBUAGUAcwB0AHMALgBVAG4AaQB0AFQAZQBzAHQAMQAuAFQAZQBzAHQATQBlAHQAaABvAGQAMQD1vSchAgAAANEO3FwfAAAAQwBvAG4AdABpAG4AdQBvAHUAcwBUAGUAcwB0AGkAbgBnAEgAbwBzAHQAUAByAG8AdgBpAGQAZQByAEkAZAAwh2K/AQAAAOWawpcGAAAATQBTAFQAZQBzAHQAJAAAAEIARQA5ADMARQBFAEMANgAtADUAMwBGADMALQA0ADMAQgA5AC0AQgA0AEIAQgAtADIAOQAxAEMARABBAEUANAA2ADIAOQAwABwAAAAuAE4ARQBUAEYAcgBhAG0AZQB3AG8AcgBrACwAVgBlAHIAcwBpAG8AbgA9AHYANAAuADYALgAxAEMAAABEAG8AdABOAGUAdAB0AHkARgByAG8AbQBUAGUAcwB0AHMALgBnAGUAbgBlAHIAYQB0AGUAYwBtAGQALgBXAGEAdABlAHIAMgBDAG0AZABHAGUAbgBlAHQAbwByAFQAZQBzAHQAcwAuAEcAZQB0AFIAZQBwAGwAeQBDAG0AZABUAGUAcwB0AA==</s:String>
3
+	<s:String x:Key="/Default/Environment/ContinuousTesting/Strategy/@EntryValue">DetectTests</s:String>
4
+	<s:String x:Key="/Default/Environment/ContinuousTesting/TriggerMode/@EntryValue">OnSave</s:String>
5
+	
6
+	
7
+	
8
+	
9
+	
10
+	
11
+	<s:Int64 x:Key="/Default/Environment/ContinuousTestingSessionDescriptor/GroupingIndex/@EntryValue">2</s:Int64>
12
+	<s:Boolean x:Key="/Default/Environment/ContinuousTestingSessionDescriptor/ShowTime/@EntryValue">True</s:Boolean>
13
+	
14
+	</wpf:ResourceDictionary>

+ 15 - 0
DotNettyFrom/DotNettyFrom.csproj Ver fichero

@@ -62,6 +62,9 @@
62 62
     <Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
63 63
       <HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
64 64
     </Reference>
65
+    <Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
66
+      <HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
67
+    </Reference>
65 68
     <Reference Include="System" />
66 69
     <Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
67 70
       <HintPath>..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath>
@@ -129,9 +132,18 @@
129 132
   <ItemGroup>
130 133
     <Compile Include="common\DataModel.cs" />
131 134
     <Compile Include="common\UIInfoModel..cs" />
135
+    <Compile Include="config\ConfigChange.cs" />
132 136
     <Compile Include="config\DBConfig.cs" />
137
+    <Compile Include="config\DtuConfig.cs" />
133 138
     <Compile Include="config\SystemConfig.cs" />
139
+    <Compile Include="config\Water2Config.cs" />
134 140
     <Compile Include="db\DBHelper.cs" />
141
+    <Compile Include="dialog\FrameConfigDialog.cs">
142
+      <SubType>Form</SubType>
143
+    </Compile>
144
+    <Compile Include="dialog\FrameConfigDialog.Designer.cs">
145
+      <DependentUpon>FrameConfigDialog.cs</DependentUpon>
146
+    </Compile>
135 147
     <Compile Include="dialog\HeartBeatTime.cs">
136 148
       <SubType>Form</SubType>
137 149
     </Compile>
@@ -182,6 +194,9 @@
182 194
     <Compile Include="model\WvBean.cs" />
183 195
     <Compile Include="util\HexUtil.cs" />
184 196
     <Compile Include="util\Utils.cs" />
197
+    <EmbeddedResource Include="dialog\FrameConfigDialog.resx">
198
+      <DependentUpon>FrameConfigDialog.cs</DependentUpon>
199
+    </EmbeddedResource>
185 200
     <EmbeddedResource Include="dialog\HeartBeatTime.resx">
186 201
       <DependentUpon>HeartBeatTime.cs</DependentUpon>
187 202
     </EmbeddedResource>

+ 127 - 37
DotNettyFrom/MainForm.Designer.cs Ver fichero

@@ -48,22 +48,31 @@
48 48
             this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
49 49
             this.dtuToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
50 50
             this.water2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
51
-            this.时间TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
51
+            this.配置TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
52 52
             this.RT_HB_Enable = new System.Windows.Forms.ToolStripMenuItem();
53
+            this.LogHbtoolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
53 54
             this.RT_HB_Time = new System.Windows.Forms.ToolStripMenuItem();
54 55
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
56
+            this.FrametoolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
57
+            this.HalfPkgToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
58
+            this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
59
+            this.TSMI_ClearAll = new System.Windows.Forms.ToolStripMenuItem();
55 60
             this.历史HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
56 61
             this.RT_HI_Host = new System.Windows.Forms.ToolStripMenuItem();
57 62
             this.RT_HI_DeviceId = new System.Windows.Forms.ToolStripMenuItem();
58 63
             this.RT_HI_CCID = new System.Windows.Forms.ToolStripMenuItem();
59 64
             this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
60 65
             this.RT_HI_SendData = new System.Windows.Forms.ToolStripMenuItem();
61
-            this.配置CToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
62
-            this.HalfPkgToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
66
+            this.指令MToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
67
+            this.LoginToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
68
+            this.HeartBeatToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
69
+            this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
63 70
             this.statusStrip1 = new System.Windows.Forms.StatusStrip();
64 71
             this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
65 72
             this.StatusItemHbTime = new System.Windows.Forms.ToolStripStatusLabel();
66 73
             this.groupBox1 = new System.Windows.Forms.GroupBox();
74
+            this.BtnFixCmd = new System.Windows.Forms.Button();
75
+            this.BtnAutoUpload = new System.Windows.Forms.Button();
67 76
             this.BtnClearAll = new System.Windows.Forms.Button();
68 77
             this.TbSendData = new System.Windows.Forms.TextBox();
69 78
             this.label5 = new System.Windows.Forms.Label();
@@ -164,7 +173,7 @@
164 173
             this.TbHost.Name = "TbHost";
165 174
             this.TbHost.Size = new System.Drawing.Size(280, 22);
166 175
             this.TbHost.TabIndex = 1;
167
-            this.TbHost.Text = "i.device.yun.vcarefire.com";
176
+            this.TbHost.Text = "127.0.0.1";
168 177
             // 
169 178
             // TbPort
170 179
             // 
@@ -173,7 +182,7 @@
173 182
             this.TbPort.Name = "TbPort";
174 183
             this.TbPort.Size = new System.Drawing.Size(57, 22);
175 184
             this.TbPort.TabIndex = 1;
176
-            this.TbPort.Text = "15443";
185
+            this.TbPort.Text = "15440";
177 186
             this.TbPort.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TbPort_KeyPress);
178 187
             // 
179 188
             // BtnConnection
@@ -226,9 +235,9 @@
226 235
             // 
227 236
             this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
228 237
             this.文件FToolStripMenuItem,
229
-            this.时间TToolStripMenuItem,
238
+            this.配置TToolStripMenuItem,
230 239
             this.历史HToolStripMenuItem,
231
-            this.配置CToolStripMenuItem});
240
+            this.指令MToolStripMenuItem});
232 241
             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
233 242
             this.menuStrip1.Name = "menuStrip1";
234 243
             this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
@@ -248,30 +257,33 @@
248 257
             // dtuToolStripMenuItem
249 258
             // 
250 259
             this.dtuToolStripMenuItem.Checked = true;
251
-            this.dtuToolStripMenuItem.CheckOnClick = true;
252 260
             this.dtuToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
253 261
             this.dtuToolStripMenuItem.Name = "dtuToolStripMenuItem";
254
-            this.dtuToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
255
-            this.dtuToolStripMenuItem.Text = "dtu";
262
+            this.dtuToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
263
+            this.dtuToolStripMenuItem.Text = "Dtu";
256 264
             this.dtuToolStripMenuItem.Click += new System.EventHandler(this.dtuToolStripMenuItem_Click);
257 265
             // 
258 266
             // water2ToolStripMenuItem
259 267
             // 
260
-            this.water2ToolStripMenuItem.CheckOnClick = true;
261 268
             this.water2ToolStripMenuItem.Name = "water2ToolStripMenuItem";
262
-            this.water2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
263
-            this.water2ToolStripMenuItem.Text = "water2";
269
+            this.water2ToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
270
+            this.water2ToolStripMenuItem.Text = "Water2";
264 271
             this.water2ToolStripMenuItem.Click += new System.EventHandler(this.water2ToolStripMenuItem_Click);
265 272
             // 
266
-            // 时间TToolStripMenuItem
273
+            // 配置TToolStripMenuItem
267 274
             // 
268
-            this.时间TToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
275
+            this.配置TToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
269 276
             this.RT_HB_Enable,
277
+            this.LogHbtoolStripMenuItem,
270 278
             this.RT_HB_Time,
271
-            this.toolStripSeparator1});
272
-            this.时间TToolStripMenuItem.Name = "时间TToolStripMenuItem";
273
-            this.时间TToolStripMenuItem.Size = new System.Drawing.Size(59, 21);
274
-            this.时间TToolStripMenuItem.Text = "时间(&T)";
279
+            this.toolStripSeparator1,
280
+            this.FrametoolStripMenuItem1,
281
+            this.HalfPkgToolStripMenuItem,
282
+            this.toolStripSeparator5,
283
+            this.TSMI_ClearAll});
284
+            this.配置TToolStripMenuItem.Name = "配置TToolStripMenuItem";
285
+            this.配置TToolStripMenuItem.Size = new System.Drawing.Size(60, 21);
286
+            this.配置TToolStripMenuItem.Text = "配置(&C)";
275 287
             // 
276 288
             // RT_HB_Enable
277 289
             // 
@@ -279,21 +291,56 @@
279 291
             this.RT_HB_Enable.CheckOnClick = true;
280 292
             this.RT_HB_Enable.CheckState = System.Windows.Forms.CheckState.Checked;
281 293
             this.RT_HB_Enable.Name = "RT_HB_Enable";
282
-            this.RT_HB_Enable.Size = new System.Drawing.Size(141, 22);
294
+            this.RT_HB_Enable.Size = new System.Drawing.Size(180, 22);
283 295
             this.RT_HB_Enable.Text = "启用心跳";
284 296
             this.RT_HB_Enable.Click += new System.EventHandler(this.RT_HB_Enable_Click);
285 297
             // 
298
+            // LogHbtoolStripMenuItem
299
+            // 
300
+            this.LogHbtoolStripMenuItem.CheckOnClick = true;
301
+            this.LogHbtoolStripMenuItem.Name = "LogHbtoolStripMenuItem";
302
+            this.LogHbtoolStripMenuItem.Size = new System.Drawing.Size(180, 22);
303
+            this.LogHbtoolStripMenuItem.Text = "打印心跳";
304
+            this.LogHbtoolStripMenuItem.Click += new System.EventHandler(this.LogHbtoolStripMenuItem_Click);
305
+            // 
286 306
             // RT_HB_Time
287 307
             // 
288 308
             this.RT_HB_Time.Name = "RT_HB_Time";
289
-            this.RT_HB_Time.Size = new System.Drawing.Size(141, 22);
290
-            this.RT_HB_Time.Text = "心跳超时(&H)";
309
+            this.RT_HB_Time.Size = new System.Drawing.Size(180, 22);
310
+            this.RT_HB_Time.Text = "心跳配置(&H)";
291 311
             this.RT_HB_Time.Click += new System.EventHandler(this.RT_HB_Time_Click);
292 312
             // 
293 313
             // toolStripSeparator1
294 314
             // 
295 315
             this.toolStripSeparator1.Name = "toolStripSeparator1";
296
-            this.toolStripSeparator1.Size = new System.Drawing.Size(138, 6);
316
+            this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
317
+            // 
318
+            // FrametoolStripMenuItem1
319
+            // 
320
+            this.FrametoolStripMenuItem1.Name = "FrametoolStripMenuItem1";
321
+            this.FrametoolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
322
+            this.FrametoolStripMenuItem1.Text = "帧配置";
323
+            // 
324
+            // HalfPkgToolStripMenuItem
325
+            // 
326
+            this.HalfPkgToolStripMenuItem.Enabled = false;
327
+            this.HalfPkgToolStripMenuItem.Name = "HalfPkgToolStripMenuItem";
328
+            this.HalfPkgToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
329
+            this.HalfPkgToolStripMenuItem.Text = "半包-粘包";
330
+            this.HalfPkgToolStripMenuItem.Click += new System.EventHandler(this.HalfPkgToolStripMenuItem_Click_1);
331
+            // 
332
+            // toolStripSeparator5
333
+            // 
334
+            this.toolStripSeparator5.Name = "toolStripSeparator5";
335
+            this.toolStripSeparator5.Size = new System.Drawing.Size(177, 6);
336
+            // 
337
+            // TSMI_ClearAll
338
+            // 
339
+            this.TSMI_ClearAll.Name = "TSMI_ClearAll";
340
+            this.TSMI_ClearAll.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.C)));
341
+            this.TSMI_ClearAll.Size = new System.Drawing.Size(180, 22);
342
+            this.TSMI_ClearAll.Text = "清空信息(&A)";
343
+            this.TSMI_ClearAll.Click += new System.EventHandler(this.TSMI_ClearAll_Click);
297 344
             // 
298 345
             // 历史HToolStripMenuItem
299 346
             // 
@@ -340,20 +387,32 @@
340 387
             this.RT_HI_SendData.Text = "发送数据";
341 388
             this.RT_HI_SendData.Click += new System.EventHandler(this.RT_HI_SendData_Click);
342 389
             // 
343
-            // 配置CToolStripMenuItem
390
+            // 指令MToolStripMenuItem
344 391
             // 
345
-            this.配置CToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
346
-            this.HalfPkgToolStripMenuItem});
347
-            this.配置CToolStripMenuItem.Name = "配置CToolStripMenuItem";
348
-            this.配置CToolStripMenuItem.Size = new System.Drawing.Size(60, 21);
349
-            this.配置CToolStripMenuItem.Text = "配置(&C)";
392
+            this.指令MToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
393
+            this.LoginToolStripMenuItem,
394
+            this.HeartBeatToolStripMenuItem,
395
+            this.toolStripSeparator6});
396
+            this.指令MToolStripMenuItem.Name = "指令MToolStripMenuItem";
397
+            this.指令MToolStripMenuItem.Size = new System.Drawing.Size(64, 21);
398
+            this.指令MToolStripMenuItem.Text = "指令(&M)";
350 399
             // 
351
-            // HalfPkgToolStripMenuItem
400
+            // LoginToolStripMenuItem
352 401
             // 
353
-            this.HalfPkgToolStripMenuItem.Name = "HalfPkgToolStripMenuItem";
354
-            this.HalfPkgToolStripMenuItem.Size = new System.Drawing.Size(129, 22);
355
-            this.HalfPkgToolStripMenuItem.Text = "半包-粘包";
356
-            this.HalfPkgToolStripMenuItem.Click += new System.EventHandler(this.HalfPkgToolStripMenuItem_Click);
402
+            this.LoginToolStripMenuItem.Name = "LoginToolStripMenuItem";
403
+            this.LoginToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
404
+            this.LoginToolStripMenuItem.Text = "登录(&L)";
405
+            // 
406
+            // HeartBeatToolStripMenuItem
407
+            // 
408
+            this.HeartBeatToolStripMenuItem.Name = "HeartBeatToolStripMenuItem";
409
+            this.HeartBeatToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
410
+            this.HeartBeatToolStripMenuItem.Text = "心跳(&H)";
411
+            // 
412
+            // toolStripSeparator6
413
+            // 
414
+            this.toolStripSeparator6.Name = "toolStripSeparator6";
415
+            this.toolStripSeparator6.Size = new System.Drawing.Size(114, 6);
357 416
             // 
358 417
             // statusStrip1
359 418
             // 
@@ -382,6 +441,8 @@
382 441
             // 
383 442
             this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
384 443
             | System.Windows.Forms.AnchorStyles.Right)));
444
+            this.groupBox1.Controls.Add(this.BtnFixCmd);
445
+            this.groupBox1.Controls.Add(this.BtnAutoUpload);
385 446
             this.groupBox1.Controls.Add(this.BtnClearAll);
386 447
             this.groupBox1.Controls.Add(this.TbSendData);
387 448
             this.groupBox1.Controls.Add(this.label5);
@@ -406,6 +467,26 @@
406 467
             this.groupBox1.TabStop = false;
407 468
             this.groupBox1.Text = " ";
408 469
             // 
470
+            // BtnFixCmd
471
+            // 
472
+            this.BtnFixCmd.Location = new System.Drawing.Point(750, 45);
473
+            this.BtnFixCmd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
474
+            this.BtnFixCmd.Name = "BtnFixCmd";
475
+            this.BtnFixCmd.Size = new System.Drawing.Size(87, 31);
476
+            this.BtnFixCmd.TabIndex = 13;
477
+            this.BtnFixCmd.Text = "内置指令";
478
+            this.BtnFixCmd.UseVisualStyleBackColor = true;
479
+            // 
480
+            // BtnAutoUpload
481
+            // 
482
+            this.BtnAutoUpload.Location = new System.Drawing.Point(657, 45);
483
+            this.BtnAutoUpload.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
484
+            this.BtnAutoUpload.Name = "BtnAutoUpload";
485
+            this.BtnAutoUpload.Size = new System.Drawing.Size(87, 31);
486
+            this.BtnAutoUpload.TabIndex = 12;
487
+            this.BtnAutoUpload.Text = "主动上报";
488
+            this.BtnAutoUpload.UseVisualStyleBackColor = true;
489
+            // 
409 490
             // BtnClearAll
410 491
             // 
411 492
             this.BtnClearAll.Location = new System.Drawing.Point(564, 45);
@@ -495,7 +576,7 @@
495 576
             this.TbDeviceId.Name = "TbDeviceId";
496 577
             this.TbDeviceId.Size = new System.Drawing.Size(157, 22);
497 578
             this.TbDeviceId.TabIndex = 4;
498
-            this.TbDeviceId.Text = "000000000001";
579
+            this.TbDeviceId.Text = "000000000002";
499 580
             // 
500 581
             // label2
501 582
             // 
@@ -556,7 +637,7 @@
556 637
         private System.Windows.Forms.MenuStrip menuStrip1;
557 638
         private System.Windows.Forms.ToolStripMenuItem 文件FToolStripMenuItem;
558 639
         private System.Windows.Forms.StatusStrip statusStrip1;
559
-        private System.Windows.Forms.ToolStripMenuItem 时间TToolStripMenuItem;
640
+        private System.Windows.Forms.ToolStripMenuItem 配置TToolStripMenuItem;
560 641
         private System.Windows.Forms.ToolStripMenuItem RT_HB_Time;
561 642
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
562 643
         private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
@@ -590,8 +671,17 @@
590 671
         private System.Windows.Forms.ToolStripMenuItem RT_HB_Enable;
591 672
         private System.Windows.Forms.ToolStripMenuItem dtuToolStripMenuItem;
592 673
         private System.Windows.Forms.ToolStripMenuItem water2ToolStripMenuItem;
593
-        private System.Windows.Forms.ToolStripMenuItem 配置CToolStripMenuItem;
594 674
         private System.Windows.Forms.ToolStripMenuItem HalfPkgToolStripMenuItem;
675
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator5;
676
+        private System.Windows.Forms.ToolStripMenuItem TSMI_ClearAll;
677
+        private System.Windows.Forms.Button BtnAutoUpload;
678
+        private System.Windows.Forms.Button BtnFixCmd;
679
+        private System.Windows.Forms.ToolStripMenuItem FrametoolStripMenuItem1;
680
+        private System.Windows.Forms.ToolStripMenuItem 指令MToolStripMenuItem;
681
+        private System.Windows.Forms.ToolStripMenuItem LoginToolStripMenuItem;
682
+        private System.Windows.Forms.ToolStripMenuItem HeartBeatToolStripMenuItem;
683
+        private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
684
+        private System.Windows.Forms.ToolStripMenuItem LogHbtoolStripMenuItem;
595 685
     }
596 686
 }
597 687
 

+ 69 - 39
DotNettyFrom/MainForm.cs Ver fichero

@@ -28,6 +28,7 @@ namespace DotNettyFrom
28 28
         private NettyClient _nettyClient;
29 29
         private string host;
30 30
         private int port;
31
+        
31 32
 
32 33
         #endregion
33 34
 
@@ -47,14 +48,9 @@ namespace DotNettyFrom
47 48
 
48 49
             DbHelper.Init();
49 50
 
50
-
51
-//            DBHelper.ConnectionAccessDb();
52
-
53
-
54 51
             UpdateUiComponent();
55 52
 
56
-            this.Text = "模拟器-DTU";
57
-            CmdGenetor.Genetor = new DtuCmdGenetor();
53
+            ChangeDtu();
58 54
 
59 55
             if ("".Equals(TbDeviceId.Text.Trim()))
60 56
             {
@@ -82,7 +78,17 @@ namespace DotNettyFrom
82 78
 
83 79
         private void CallUI(UIInfoModel value)
84 80
         {
85
-            LBLogShow.Items.Add(value);
81
+            if (value.cmdId != SystemConfig.HeartbeatDownCmdCode)
82
+            {
83
+                LBLogShow.Items.Add(value);
84
+            }
85
+            else
86
+            {
87
+                if (SystemConfig.IsLogHeartBeatInfo)
88
+                {
89
+                    LBLogShow.Items.Add(value);
90
+                }
91
+            }
86 92
             LBLogShow.TopIndex = LBLogShow.Items.Count - 1;
87 93
             if (LBLogShow.Items.Count > SystemConfig.LBLogShowClearCount)
88 94
             {
@@ -105,31 +111,40 @@ namespace DotNettyFrom
105 111
 
106 112
         private void ConnectionActive()
107 113
         {
108
-            TbHost.Enabled = false;
109
-            TbPort.Enabled = false;
110
-            TbDeviceId.Enabled = false;
111
-            TbCCID.Enabled = false;
114
+            TbHost.ReadOnly = true;
115
+            TbPort.ReadOnly = true;
116
+            TbDeviceId.ReadOnly = true;
117
+            TbCCID.ReadOnly = true;
112 118
 
113 119
             BtnConnection.Enabled = false;
114 120
             BtnLogin.Enabled = false;
115 121
 
116 122
             BtnDisConn.Enabled = true;
117 123
             BtnSendData.Enabled = true;
124
+
125
+            water2ToolStripMenuItem.Enabled = false;
126
+            dtuToolStripMenuItem.Enabled = false;
127
+
118 128
         }
119 129
 
120 130
 
121 131
         private void ConnectionInActive()
122 132
         {
123
-            TbHost.Enabled = true;
124
-            TbPort.Enabled = true;
125
-            TbDeviceId.Enabled = true;
126
-            TbCCID.Enabled = true;
133
+            TbHost.ReadOnly = false;
134
+            TbPort.ReadOnly = false;
135
+            TbDeviceId.ReadOnly = false;
136
+            TbCCID.ReadOnly = false;
127 137
 
128 138
             BtnConnection.Enabled = true;
129 139
             BtnLogin.Enabled = true;
130 140
 
131 141
             BtnDisConn.Enabled = false;
132 142
             BtnSendData.Enabled = false;
143
+
144
+
145
+
146
+            water2ToolStripMenuItem.Enabled = true;
147
+            dtuToolStripMenuItem.Enabled = true;
133 148
         }
134 149
 
135 150
         private void BeforeConnection()
@@ -156,23 +171,32 @@ namespace DotNettyFrom
156 171
                                     "/s";
157 172
         }
158 173
 
159
-        #region Component Event
160 174
 
161
-        private void BtnConnection_Click(object sender, EventArgs e)
175
+        private void ChangeWater2()
162 176
         {
163
-            /* var producer = Task.Factory.StartNew(() =>
164
-             {
165
-                 for (int count = 0; count < 1000; count++)
166
-                 {
177
+            this.Text = "模拟器-Water2";
178
+            dtuToolStripMenuItem.Checked = false;
179
+            water2ToolStripMenuItem.Checked = true;
180
+            CmdGenetor.Genetor = null;
181
+            CmdGenetor.Genetor = new Water2CmdGenetor();
182
+
183
+            ConfigChange.ChangeDevice(SystemConfig.Water2);
184
+        }
167 185
 
186
+        private void ChangeDtu()
187
+        {
188
+            this.Text = "模拟器-DTU";
189
+            water2ToolStripMenuItem.Checked = false;
190
+            dtuToolStripMenuItem.Checked = true;
191
+            CmdGenetor.Genetor = null;
192
+            CmdGenetor.Genetor = new DtuCmdGenetor();
193
+            ConfigChange.ChangeDevice(SystemConfig.Dtu);
194
+        }
168 195
 
169
-                 }
170
-                 //                blockingCollection.CompleteAdding();
171
-             });*/
172
-            /*_nettyClient = new NettyClient();
173
-            t = new Thread(() => { _nettyClient.StartNetty("127.0.0.1", 4001); });
174
-            t.Start();*/
196
+        #region Component Event
175 197
 
198
+        private void BtnConnection_Click(object sender, EventArgs e)
199
+        {
176 200
             BeforeConnection();
177 201
 
178 202
             CmdGenetor.Genetor.DeviceId = TbDeviceId.Text.Trim();
@@ -230,20 +254,15 @@ namespace DotNettyFrom
230 254
 
231 255
         private void dtuToolStripMenuItem_Click(object sender, EventArgs e)
232 256
         {
233
-            this.Text = "模拟器-DTU";
234
-            water2ToolStripMenuItem.Checked = false;
235
-            CmdGenetor.Genetor = null;
236
-            CmdGenetor.Genetor = new DtuCmdGenetor();
257
+            ChangeDtu();
237 258
         }
238 259
 
239 260
         private void water2ToolStripMenuItem_Click(object sender, EventArgs e)
240 261
         {
241
-            this.Text = "模拟器-Water2";
242
-            dtuToolStripMenuItem.Checked = false;
243
-            CmdGenetor.Genetor = null;
244
-            CmdGenetor.Genetor = new Water2CmdGenetor();
262
+            ChangeWater2();
245 263
         }
246 264
 
265
+
247 266
         private void BtnClearAll_Click(object sender, EventArgs e) => LBLogShow.Items.Clear();
248 267
 
249 268
         private void BtnCmdManager_Click(object sender, EventArgs e)
@@ -260,6 +279,12 @@ namespace DotNettyFrom
260 279
             hd.ShowDialog();
261 280
         }
262 281
 
282
+        private void HalfPkgToolStripMenuItem_Click_1(object sender, EventArgs e)
283
+        {
284
+            TcpPkgConfigDialog tcpDialog = new TcpPkgConfigDialog();
285
+            tcpDialog.ShowDialog();
286
+        }
287
+
263 288
         private void RT_HI_DeviceId_Click(object sender, EventArgs e)
264 289
         {
265 290
             HistoryDialog hd = new HistoryDialog(SystemConfig.AddrHisType);
@@ -281,14 +306,14 @@ namespace DotNettyFrom
281 306
             hd.ShowDialog();
282 307
         }
283 308
 
284
-        private void Hd_HistoryHandler(string type, string result)
309
+        private void TSMI_ClearAll_Click(object sender, EventArgs e)
285 310
         {
311
+            BtnClearAll_Click(null, null);
286 312
         }
287 313
 
288
-        private void HalfPkgToolStripMenuItem_Click(object sender, EventArgs e)
314
+
315
+        private void Hd_HistoryHandler(string type, string result)
289 316
         {
290
-            TcpPkgConfigDialog tcpDialog = new TcpPkgConfigDialog();
291
-            tcpDialog.ShowDialog();
292 317
         }
293 318
 
294 319
         #endregion
@@ -390,5 +415,10 @@ namespace DotNettyFrom
390 415
         private void LB_Context_ClearAll_Click(object sender, EventArgs e) => LBLogShow.Items.Clear();
391 416
 
392 417
         #endregion
418
+
419
+        private void LogHbtoolStripMenuItem_Click(object sender, EventArgs e)
420
+        {
421
+            SystemConfig.IsLogHeartBeatInfo = LogHbtoolStripMenuItem.Checked;
422
+        }
393 423
     }
394 424
 }

+ 21 - 2
DotNettyFrom/common/UIInfoModel..cs Ver fichero

@@ -16,6 +16,9 @@ namespace DotNettyFrom.common
16 16
 
17 17
         public string cmd = "";
18 18
 
19
+        public int cmdId = int.MinValue;
20
+
21
+
19 22
         //1 发送的. 0:接收的, -1.日常信息
20 23
         public int SendType = SystemConfig.RecType;
21 24
 
@@ -24,6 +27,7 @@ namespace DotNettyFrom.common
24 27
         {
25 28
             this.info = info;
26 29
             this.cmd = cmd;
30
+            cmdId = CalcCmdId(cmd);
27 31
         }
28 32
 
29 33
 
@@ -47,6 +51,7 @@ namespace DotNettyFrom.common
47 51
         public UIInfoModel setCmd(string cmd)
48 52
         {
49 53
             this.cmd = cmd;
54
+            cmdId = CalcCmdId(cmd);
50 55
             return this;
51 56
         }
52 57
 
@@ -70,8 +75,9 @@ namespace DotNettyFrom.common
70 75
             {
71 76
                 try
72 77
                 {
73
-                    string cmdId = cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
74
-                    res += ". cmdId=" + cmdId;
78
+                    string cmdIdString = cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
79
+                    res += ". cmdId=" + cmdIdString;
80
+                    cmdId = CalcCmdId(cmd);
75 81
                 }
76 82
                 catch (Exception)
77 83
                 {
@@ -80,5 +86,18 @@ namespace DotNettyFrom.common
80 86
             }
81 87
             return res + ".";
82 88
         }
89
+
90
+        public int CalcCmdId(string cmd)
91
+        {
92
+            try
93
+            {
94
+                string cmdId = cmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
95
+                return int.Parse(cmdId);
96
+            }
97
+            catch (Exception)
98
+            {
99
+            }
100
+            return int.MinValue;
101
+        }
83 102
     }
84 103
 }

+ 63 - 0
DotNettyFrom/config/ConfigChange.cs Ver fichero

@@ -0,0 +1,63 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace DotNettyFrom.config
8
+{
9
+    public class ConfigChange
10
+    {
11
+        public static void ChangeDevice(int type)
12
+        {
13
+            switch (type)
14
+            {
15
+                case SystemConfig.Dtu:
16
+                    changeDTU();
17
+                    break;
18
+                case SystemConfig.Water2:
19
+                    changeWater2();
20
+                    break;
21
+                default:
22
+                    break;
23
+            }
24
+        }
25
+
26
+        private static void changeWater2()
27
+        {
28
+            SystemConfig.CurrentType = SystemConfig.Water2;
29
+
30
+            SystemConfig.FunctionCodeStartPos = Water2Config.FunctionCodeStartPos;
31
+            SystemConfig.FunctionCodeLength = Water2Config.FunctionCodeLength;
32
+
33
+            SystemConfig.HeartbeatDownCmdCode = Water2Config.HeartbeatDownCmdCode;
34
+
35
+            SystemConfig.LengthFieldOffset = Water2Config.LengthFieldOffset;
36
+            SystemConfig.LengthFieldLength = Water2Config.LengthFieldLength;
37
+            SystemConfig.LengthAdjustment = Water2Config.LengthAdjustment;
38
+            SystemConfig.InitialBytesToStrip = Water2Config.InitialBytesToStrip;
39
+
40
+            SystemConfig.MeasurePointLen = Water2Config.MeasurePointLen;
41
+            SystemConfig.MessageFlowLen = Water2Config.MessageFlowLen;
42
+      
43
+    }
44
+
45
+        private static void changeDTU()
46
+        {
47
+            SystemConfig.CurrentType = SystemConfig.Dtu;
48
+
49
+            SystemConfig.FunctionCodeStartPos = DtuConfig.FunctionCodeStartPos;
50
+            SystemConfig.FunctionCodeLength = DtuConfig.FunctionCodeLength;
51
+
52
+            SystemConfig.HeartbeatDownCmdCode = DtuConfig.HeartbeatDownCmdCode;
53
+
54
+            SystemConfig.LengthFieldOffset = DtuConfig.LengthFieldOffset;
55
+            SystemConfig.LengthFieldLength = DtuConfig.LengthFieldLength;
56
+            SystemConfig.LengthAdjustment = DtuConfig.LengthAdjustment;
57
+            SystemConfig.InitialBytesToStrip = DtuConfig.InitialBytesToStrip;
58
+
59
+            SystemConfig.MeasurePointLen = DtuConfig.MeasurePointLen;
60
+            SystemConfig.MessageFlowLen = DtuConfig.MessageFlowLen;
61
+        }
62
+    }
63
+}

+ 15 - 0
DotNettyFrom/config/DBConfig.cs Ver fichero

@@ -16,8 +16,23 @@ namespace DotNettyFrom.config
16 16
 
17 17
         //历史表
18 18
         public const string IpHis = "ip_his";
19
+
19 20
         public const string SendHis = "send_his";
20 21
         public const string CcidHis = "ccid_his";
21 22
         public const string AddrHis = "addr_his";
23
+
24
+
25
+        public static string GetTableName()
26
+        {
27
+            if (SystemConfig.CurrentType == SystemConfig.Dtu)
28
+            {
29
+                return "dtu";
30
+            }
31
+            else if (SystemConfig.CurrentType == SystemConfig.Water2)
32
+            {
33
+                return "water2";
34
+            }
35
+            return "dtu";
36
+        }
22 37
     }
23 38
 }

+ 28 - 0
DotNettyFrom/config/DtuConfig.cs Ver fichero

@@ -0,0 +1,28 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace DotNettyFrom.config
8
+{
9
+    public class DtuConfig
10
+    {
11
+        //功能码的位置,长度
12
+        public static int FunctionCodeStartPos = 18;
13
+        public static int FunctionCodeLength = 2;
14
+
15
+
16
+        //心跳指令的功能码,用来判定是否是心跳
17
+        public static int HeartbeatDownCmdCode = 4;
18
+
19
+
20
+        public static int LengthFieldOffset = 10;
21
+        public static int LengthFieldLength = 2;
22
+        public static int LengthAdjustment = 1;
23
+        public static int InitialBytesToStrip = 0;
24
+
25
+        public static int MeasurePointLen = 1;
26
+        public static int MessageFlowLen = 2;
27
+    }
28
+}

+ 27 - 3
DotNettyFrom/config/SystemConfig.cs Ver fichero

@@ -8,33 +8,57 @@ namespace DotNettyFrom.config
8 8
 {
9 9
     public class SystemConfig
10 10
     {
11
+        public const int Dtu = 1;
12
+        public const int Water2 = 2;
13
+
14
+        //当前是哪一个设备
15
+        public static int CurrentType;
16
+
17
+        //是否打印心跳指令
18
+        public static bool IsLogHeartBeatInfo = false;
19
+
20
+        //心跳指令的功能码,用来判定是否是心跳
21
+        public static int HeartbeatDownCmdCode = 4;
22
+
23
+        //功能码的位置,长度
11 24
         public static int FunctionCodeStartPos = 18;
12
-        public static int FunctionCodeLength = 2;
13 25
 
26
+        public static int FunctionCodeLength = 2;
14 27
 
28
+        //定时发送心中
15 29
         public static bool OpenHeartBeat = true;
16 30
 
31
+        //心跳时间
17 32
         public static int ReaderIdleTimeSeconds = 5;
33
+
18 34
         public static int WriterIdleTimeSeconds = 5;
19 35
         public static int AllIdleTimeSeconds = 25;
20 36
 
21 37
 
38
+        //测量点&消息流水
39
+        public static int MeasurePointLen = 1;
40
+        public static int MessageFlowLen = 2;
41
+
42
+
43
+
44
+        //粘包-半包问题
22 45
         public static int LengthFieldOffset = 10;
23 46
         public static int LengthFieldLength = 2;
24 47
         public static int LengthAdjustment = 1;
25 48
         public static int InitialBytesToStrip = 0;
26 49
 
50
+        //ListBox最多显示条数
27 51
         public static int LBLogShowClearCount = 1000;
28 52
 
53
+        //----------------------------------------------------------------
29 54
 
30 55
         //1 发送的. 0:接收的, -1.Debug.日常信息
31 56
         public static int SendType = 1;
32
-
33 57
         public static int RecType = 0;
34 58
         public static int DebugType = -1;
35 59
         public static int ReplyType = 2;
36 60
 
37
-
61
+        //数据库对应
38 62
         public const int IpHisType = 1;
39 63
         public const int AddrHisType = 2;
40 64
         public const int SendHisType = 3;

+ 28 - 0
DotNettyFrom/config/Water2Config.cs Ver fichero

@@ -0,0 +1,28 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace DotNettyFrom.config
8
+{
9
+    public class Water2Config
10
+    {
11
+        //功能码的位置,长度
12
+        public static int FunctionCodeStartPos = 18;
13
+        public static int FunctionCodeLength = 2;
14
+
15
+        //心跳指令的功能码,用来判定是否是心跳
16
+        public static int HeartbeatDownCmdCode = 3;
17
+
18
+        public static int LengthFieldOffset = 10;
19
+        public static int LengthFieldLength = 1;
20
+        public static int LengthAdjustment = 2;
21
+        public static int InitialBytesToStrip = 0;
22
+
23
+
24
+        public static int MeasurePointLen = 0;
25
+        public static int MessageFlowLen = 2;
26
+
27
+    }
28
+}

+ 72 - 53
DotNettyFrom/db/DBHelper.cs Ver fichero

@@ -23,10 +23,17 @@ namespace DotNettyFrom.db
23 23
         private OleDbConnection _DbConn = null;
24 24
 
25 25
 
26
-        private DbHelper()
26
+        private DbHelper(string dbPath)
27 27
         {
28 28
             _idInfo = new Dictionary<string, string>();
29
-            _DbConn = new OleDbConnection(DBConfig.ConnStr + Application.StartupPath + @"\" + DBConfig.DbFileName);
29
+            if (dbPath.Equals(""))
30
+            {
31
+                _DbConn = new OleDbConnection(DBConfig.ConnStr + Application.StartupPath + @"\" + DBConfig.DbFileName);
32
+            }
33
+            else
34
+            {
35
+                _DbConn = new OleDbConnection(DBConfig.ConnStr + dbPath);
36
+            }
30 37
             _DbConn.Open();
31 38
         }
32 39
 
@@ -36,13 +43,13 @@ namespace DotNettyFrom.db
36 43
         }
37 44
 
38 45
 
39
-        public static void Init()
46
+        public static void Init(string dbPath = "")
40 47
         {
41 48
             lock (locker)
42 49
             {
43 50
                 if (Instance == null)
44 51
                 {
45
-                    Instance = new DbHelper();
52
+                    Instance = new DbHelper(dbPath);
46 53
                 }
47 54
             }
48 55
         }
@@ -60,20 +67,25 @@ namespace DotNettyFrom.db
60 67
         //reset user value
61 68
         public int ResetUserData()
62 69
         {
63
-            string sql = "update fw set user_value=default_value";
70
+            string table = DBConfig.GetTableName();
71
+            string sql = "update " + table + " set user_value=default_value";
64 72
             using (OleDbCommand inst = new OleDbCommand(sql, _DbConn))
65 73
             {
66 74
                 return inst.ExecuteNonQuery();
67 75
             }
68 76
         }
69 77
 
70
-        //Insert
78
+        //Insert CMD
71 79
         public int InsertCmd(WvBean wb)
72 80
         {
73 81
             if (wb == null)
82
+            {
74 83
                 return -1;
84
+            }
85
+            string table = DBConfig.GetTableName();
75 86
             string sql =
76
-                "INSERT INTO fw(my_index,MY_ID,idInfo,len,mode,desp,default_value,user_value,remark) VALUES(";
87
+                "INSERT INTO " + table +
88
+                "(my_index,MY_ID,idInfo,len,mode,desp,default_value,user_value,remark,protocol_no) VALUES(";
77 89
             sql += wb.index + ",";
78 90
             sql += "'" + wb.myId + "',";
79 91
             sql += "'" + wb.idInfo + "',";
@@ -82,7 +94,8 @@ namespace DotNettyFrom.db
82 94
             sql += "'" + wb.desp + "',";
83 95
             sql += "'" + wb.defalutValue + "',";
84 96
             sql += "'" + wb.userValue + "',";
85
-            sql += "'" + wb.remark + "')";
97
+            sql += "'" + wb.remark + "',";
98
+            sql += wb.protocolNo + ")";
86 99
             using (OleDbCommand inst = new OleDbCommand(sql, _DbConn))
87 100
             {
88 101
                 return inst.ExecuteNonQuery();
@@ -121,22 +134,30 @@ namespace DotNettyFrom.db
121 134
         //Delete
122 135
         public int DeleteCmdById(int id)
123 136
         {
124
-            string sql = "delete from fw where ID=" + id;
137
+            string table = DBConfig.GetTableName();
138
+            string sql = "delete from " + table + " where ID=" + id;
125 139
             using (OleDbCommand inst = new OleDbCommand(sql, _DbConn))
126 140
             {
127 141
                 return inst.ExecuteNonQuery();
128 142
             }
129 143
         }
130 144
 
131
-        public int DeleteAllFwData()
145
+        public int DeleteAllData()
132 146
         {
133
-            string sql = @"delete from fw";
147
+            string table = DBConfig.GetTableName();
148
+            string sql = @"delete from " + table;
134 149
             using (OleDbCommand inst = new OleDbCommand(sql, _DbConn))
135 150
             {
136 151
                 return inst.ExecuteNonQuery();
137 152
             }
138 153
         }
139 154
 
155
+        /// <summary>
156
+        /// 删除历史记录
157
+        /// </summary>
158
+        /// <param name="_type"></param>
159
+        /// <param name="id"></param>
160
+        /// <returns></returns>
140 161
         public int DeleteHistoryById(int _type, int id)
141 162
         {
142 163
             string tableName;
@@ -164,6 +185,11 @@ namespace DotNettyFrom.db
164 185
             }
165 186
         }
166 187
 
188
+        /// <summary>
189
+        /// 删除所有历史记录
190
+        /// </summary>
191
+        /// <param name="_type"></param>
192
+        /// <returns></returns>
167 193
         public int DeleteAllHistory(int _type)
168 194
         {
169 195
             string tableName;
@@ -194,7 +220,10 @@ namespace DotNettyFrom.db
194 220
         //Update
195 221
         public int UpdateCmd(WvBean wb)
196 222
         {
197
-            string updateSQL = "update fw set my_index=" + wb.index + ",MY_ID=\"" + wb.myId + "\",idInfo=\"" +
223
+            string table = DBConfig.GetTableName();
224
+
225
+            string updateSQL = "update " + table + " set my_index=" + wb.index + ",MY_ID=\"" + wb.myId +
226
+                               "\",idInfo=\"" +
198 227
                                wb.idInfo +
199 228
                                "\",len=\"" + wb.len +
200 229
                                "\",mode=\"" +
@@ -209,10 +238,15 @@ namespace DotNettyFrom.db
209 238
         }
210 239
 
211 240
         //Select
212
-        public DataTable SelectCmds(string sql = @"select * from fw")
241
+        public DataTable SelectCmds(string sql = null)
213 242
         {
243
+            if (sql == null)
244
+            {
245
+                string table = DBConfig.GetTableName();
246
+                sql = @"select * from " + table;
247
+            }
248
+
214 249
             DataTable dataTable = new DataTable();
215
-//            string sql = @"select * from fw";
216 250
 
217 251
             using (OleDbCommand sqlcmd = new OleDbCommand(sql, _DbConn))
218 252
             {
@@ -228,61 +262,40 @@ namespace DotNettyFrom.db
228 262
                         var userValue = CheckUtil.StringIsEmpty(reader.GetString(8));
229 263
                         if (!_idInfo.ContainsKey(myId))
230 264
                             _idInfo.Add(myId, userValue);
231
-
232
-                        /*WvBean wb = new WvBean();
233
-                        int id = 0;
234
-                        int index = 0;
235
-                        var myId = "";
236
-                        var idInfo = "";
237
-                        var len = "";
238
-                        var mode = "";
239
-                        var desp = "";
240
-                        var defalutValue = "";
241
-                        var userValue = "";
242
-                        var remark = "";
243
-
244
-                        id = reader.GetInt32(0);
245
-                        index = reader.GetInt32(1);
246
-                        myId = reader.GetString(2);
247
-                        idInfo = CheckUtil.StringIsEmpty(reader.GetString(3));
248
-                        len = CheckUtil.StringIsEmpty(reader.GetString(4));
249
-                        mode = CheckUtil.StringIsEmpty(reader.GetString(5));
250
-                        desp = CheckUtil.StringIsEmpty(reader.GetString(6));
251
-                        defalutValue = CheckUtil.StringIsEmpty(reader.GetString(7));
252
-                        userValue = CheckUtil.StringIsEmpty(reader.GetString(8));
253
-                        remark = CheckUtil.StringIsEmpty(reader.GetString(9));
254
-
255
-                        wb.id = id;
256
-                        wb.index = index;
257
-                        wb.myId = myId;
258
-                        wb.idInfo = idInfo;
259
-                        wb.len = len;
260
-                        wb.mode = mode;
261
-                        wb.desp = desp;
262
-                        wb.defalutValue = defalutValue;
263
-                        wb.userValue = userValue;
264
-                        wb.remark = remark;
265
-
266
-                        if (!_idInfo.ContainsKey(myId))
267
-                            _idInfo.Add(myId, userValue);*/
268 265
                     }
269 266
                 }
270 267
             }
271 268
             return dataTable;
272 269
         }
273 270
 
271
+        public WvBean SelectOneCmdByIndex(int index)
272
+        {
273
+            string table = DBConfig.GetTableName();
274
+            string sql = @"select * from " + table + " where my_index=" + index;
275
+            return SelectOneCmd(sql);
276
+        }
277
+
274 278
         public WvBean SelectOneCmdById(int _id)
275 279
         {
276
-            WvBean wb = new WvBean();
277
-            string sql = @"select * from fw where id=" + _id;
280
+            string table = DBConfig.GetTableName();
281
+            string sql = @"select * from " + table + " where id=" + _id;
282
+            return SelectOneCmd(sql);
283
+        }
284
+
285
+        private WvBean SelectOneCmd(string sql)
286
+        {
287
+            WvBean wb = null;
278 288
             using (OleDbCommand sqlcmd = new OleDbCommand(sql, _DbConn))
279 289
             {
280 290
                 OleDbDataAdapter adapter = new OleDbDataAdapter(sqlcmd);
281 291
 
292
+                #region 读数据
293
+
282 294
                 using (OleDbDataReader reader = sqlcmd.ExecuteReader())
283 295
                 {
284 296
                     while (reader.Read()) //这个read调用很重要!不写的话运行时将提示找不到数据  
285 297
                     {
298
+                        wb = new WvBean();
286 299
                         int id = 0;
287 300
                         int index = 0;
288 301
                         var myId = "";
@@ -293,6 +306,7 @@ namespace DotNettyFrom.db
293 306
                         var defalutValue = "";
294 307
                         var userValue = "";
295 308
                         var remark = "";
309
+                        var protocolNo = 0;
296 310
 
297 311
                         id = reader.GetInt32(0);
298 312
                         index = reader.GetInt32(1);
@@ -304,6 +318,7 @@ namespace DotNettyFrom.db
304 318
                         defalutValue = CheckUtil.StringIsEmpty(reader.GetString(7));
305 319
                         userValue = CheckUtil.StringIsEmpty(reader.GetString(8));
306 320
                         remark = CheckUtil.StringIsEmpty(reader.GetString(9));
321
+                        protocolNo = reader.GetInt32(10);
307 322
 
308 323
                         wb.id = id;
309 324
                         wb.index = index;
@@ -315,14 +330,18 @@ namespace DotNettyFrom.db
315 330
                         wb.defalutValue = defalutValue;
316 331
                         wb.userValue = userValue;
317 332
                         wb.remark = remark;
333
+                        wb.protocolNo = protocolNo;
318 334
 
319 335
                         break;
320 336
                     }
321 337
                 }
338
+
339
+                #endregion
322 340
             }
323 341
             return wb;
324 342
         }
325 343
 
344
+
326 345
         public DataTable SelectHistory(string sql)
327 346
         {
328 347
             DataTable dataTable = new DataTable();

+ 50 - 0
DotNettyFrom/dialog/FrameConfigDialog.Designer.cs Ver fichero

@@ -0,0 +1,50 @@
1
+namespace DotNettyFrom.dialog
2
+{
3
+    partial class FrameConfigDialog
4
+    {
5
+        /// <summary>
6
+        /// Required designer variable.
7
+        /// </summary>
8
+        private System.ComponentModel.IContainer components = null;
9
+
10
+        /// <summary>
11
+        /// Clean up any resources being used.
12
+        /// </summary>
13
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
14
+        protected override void Dispose(bool disposing)
15
+        {
16
+            if (disposing && (components != null))
17
+            {
18
+                components.Dispose();
19
+            }
20
+            base.Dispose(disposing);
21
+        }
22
+
23
+        #region Windows Form Designer generated code
24
+
25
+        /// <summary>
26
+        /// Required method for Designer support - do not modify
27
+        /// the contents of this method with the code editor.
28
+        /// </summary>
29
+        private void InitializeComponent()
30
+        {
31
+            this.SuspendLayout();
32
+            // 
33
+            // FrameConfigDialog
34
+            // 
35
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
36
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37
+            this.ClientSize = new System.Drawing.Size(613, 536);
38
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
39
+            this.MaximizeBox = false;
40
+            this.MinimizeBox = false;
41
+            this.Name = "FrameConfigDialog";
42
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
43
+            this.Text = "FrameConfigDialog";
44
+            this.ResumeLayout(false);
45
+
46
+        }
47
+
48
+        #endregion
49
+    }
50
+}

+ 20 - 0
DotNettyFrom/dialog/FrameConfigDialog.cs Ver fichero

@@ -0,0 +1,20 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.ComponentModel;
4
+using System.Data;
5
+using System.Drawing;
6
+using System.Linq;
7
+using System.Text;
8
+using System.Threading.Tasks;
9
+using System.Windows.Forms;
10
+
11
+namespace DotNettyFrom.dialog
12
+{
13
+    public partial class FrameConfigDialog : Form
14
+    {
15
+        public FrameConfigDialog()
16
+        {
17
+            InitializeComponent();
18
+        }
19
+    }
20
+}

+ 120 - 0
DotNettyFrom/dialog/FrameConfigDialog.resx Ver fichero

@@ -0,0 +1,120 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<root>
3
+  <!-- 
4
+    Microsoft ResX Schema 
5
+    
6
+    Version 2.0
7
+    
8
+    The primary goals of this format is to allow a simple XML format 
9
+    that is mostly human readable. The generation and parsing of the 
10
+    various data types are done through the TypeConverter classes 
11
+    associated with the data types.
12
+    
13
+    Example:
14
+    
15
+    ... ado.net/XML headers & schema ...
16
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
17
+    <resheader name="version">2.0</resheader>
18
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
24
+    </data>
25
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27
+        <comment>This is a comment</comment>
28
+    </data>
29
+                
30
+    There are any number of "resheader" rows that contain simple 
31
+    name/value pairs.
32
+    
33
+    Each data row contains a name, and value. The row also contains a 
34
+    type or mimetype. Type corresponds to a .NET class that support 
35
+    text/value conversion through the TypeConverter architecture. 
36
+    Classes that don't support this are serialized and stored with the 
37
+    mimetype set.
38
+    
39
+    The mimetype is used for serialized objects, and tells the 
40
+    ResXResourceReader how to depersist the object. This is currently not 
41
+    extensible. For a given mimetype the value must be set accordingly:
42
+    
43
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
44
+    that the ResXResourceWriter will generate, however the reader can 
45
+    read any of the formats listed below.
46
+    
47
+    mimetype: application/x-microsoft.net.object.binary.base64
48
+    value   : The object must be serialized with 
49
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50
+            : and then encoded with base64 encoding.
51
+    
52
+    mimetype: application/x-microsoft.net.object.soap.base64
53
+    value   : The object must be serialized with 
54
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55
+            : and then encoded with base64 encoding.
56
+
57
+    mimetype: application/x-microsoft.net.object.bytearray.base64
58
+    value   : The object must be serialized into a byte array 
59
+            : using a System.ComponentModel.TypeConverter
60
+            : and then encoded with base64 encoding.
61
+    -->
62
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64
+    <xsd:element name="root" msdata:IsDataSet="true">
65
+      <xsd:complexType>
66
+        <xsd:choice maxOccurs="unbounded">
67
+          <xsd:element name="metadata">
68
+            <xsd:complexType>
69
+              <xsd:sequence>
70
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
71
+              </xsd:sequence>
72
+              <xsd:attribute name="name" use="required" type="xsd:string" />
73
+              <xsd:attribute name="type" type="xsd:string" />
74
+              <xsd:attribute name="mimetype" type="xsd:string" />
75
+              <xsd:attribute ref="xml:space" />
76
+            </xsd:complexType>
77
+          </xsd:element>
78
+          <xsd:element name="assembly">
79
+            <xsd:complexType>
80
+              <xsd:attribute name="alias" type="xsd:string" />
81
+              <xsd:attribute name="name" type="xsd:string" />
82
+            </xsd:complexType>
83
+          </xsd:element>
84
+          <xsd:element name="data">
85
+            <xsd:complexType>
86
+              <xsd:sequence>
87
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89
+              </xsd:sequence>
90
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93
+              <xsd:attribute ref="xml:space" />
94
+            </xsd:complexType>
95
+          </xsd:element>
96
+          <xsd:element name="resheader">
97
+            <xsd:complexType>
98
+              <xsd:sequence>
99
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100
+              </xsd:sequence>
101
+              <xsd:attribute name="name" type="xsd:string" use="required" />
102
+            </xsd:complexType>
103
+          </xsd:element>
104
+        </xsd:choice>
105
+      </xsd:complexType>
106
+    </xsd:element>
107
+  </xsd:schema>
108
+  <resheader name="resmimetype">
109
+    <value>text/microsoft-resx</value>
110
+  </resheader>
111
+  <resheader name="version">
112
+    <value>2.0</value>
113
+  </resheader>
114
+  <resheader name="reader">
115
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116
+  </resheader>
117
+  <resheader name="writer">
118
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119
+  </resheader>
120
+</root>

+ 26 - 0
DotNettyFrom/dialog/TcpPkgConfigDialog.Designer.cs Ver fichero

@@ -39,6 +39,8 @@
39 39
             this.textBox1 = new System.Windows.Forms.TextBox();
40 40
             this.InitialBytesToStrip = new System.Windows.Forms.NumericUpDown();
41 41
             this.label4 = new System.Windows.Forms.Label();
42
+            this.buttonDtu = new System.Windows.Forms.Button();
43
+            this.buttonWater2 = new System.Windows.Forms.Button();
42 44
             ((System.ComponentModel.ISupportInitialize)(this.LengthFieldOffset)).BeginInit();
43 45
             ((System.ComponentModel.ISupportInitialize)(this.LengthFieldLength)).BeginInit();
44 46
             ((System.ComponentModel.ISupportInitialize)(this.LengthAdjustment)).BeginInit();
@@ -139,12 +141,34 @@
139 141
             this.label4.TabIndex = 5;
140 142
             this.label4.Text = "InitialBytesToStrip";
141 143
             // 
144
+            // buttonDtu
145
+            // 
146
+            this.buttonDtu.Location = new System.Drawing.Point(123, 47);
147
+            this.buttonDtu.Name = "buttonDtu";
148
+            this.buttonDtu.Size = new System.Drawing.Size(75, 23);
149
+            this.buttonDtu.TabIndex = 7;
150
+            this.buttonDtu.Text = "DTU";
151
+            this.buttonDtu.UseVisualStyleBackColor = true;
152
+            this.buttonDtu.Click += new System.EventHandler(this.buttonDtu_Click);
153
+            // 
154
+            // buttonWater2
155
+            // 
156
+            this.buttonWater2.Location = new System.Drawing.Point(210, 47);
157
+            this.buttonWater2.Name = "buttonWater2";
158
+            this.buttonWater2.Size = new System.Drawing.Size(75, 23);
159
+            this.buttonWater2.TabIndex = 7;
160
+            this.buttonWater2.Text = "水";
161
+            this.buttonWater2.UseVisualStyleBackColor = true;
162
+            this.buttonWater2.Click += new System.EventHandler(this.buttonWater2_Click);
163
+            // 
142 164
             // TcpPkgConfigDialog
143 165
             // 
144 166
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
145 167
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
146 168
             this.CancelButton = this.buttonCancle;
147 169
             this.ClientSize = new System.Drawing.Size(445, 518);
170
+            this.Controls.Add(this.buttonWater2);
171
+            this.Controls.Add(this.buttonDtu);
148 172
             this.Controls.Add(this.InitialBytesToStrip);
149 173
             this.Controls.Add(this.label4);
150 174
             this.Controls.Add(this.textBox1);
@@ -189,5 +213,7 @@
189 213
         private System.Windows.Forms.TextBox textBox1;
190 214
         private System.Windows.Forms.NumericUpDown InitialBytesToStrip;
191 215
         private System.Windows.Forms.Label label4;
216
+        private System.Windows.Forms.Button buttonDtu;
217
+        private System.Windows.Forms.Button buttonWater2;
192 218
     }
193 219
 }

+ 16 - 0
DotNettyFrom/dialog/TcpPkgConfigDialog.cs Ver fichero

@@ -35,5 +35,21 @@ namespace DotNettyFrom.dialog
35 35
 
36 36
             this.Close();
37 37
         }
38
+
39
+        private void buttonWater2_Click(object sender, EventArgs e)
40
+        {
41
+            LengthFieldOffset.Value = 10;
42
+            LengthFieldLength.Value = 1;
43
+            LengthAdjustment.Value = 2;
44
+            InitialBytesToStrip.Value = 0;
45
+        }
46
+
47
+        private void buttonDtu_Click(object sender, EventArgs e)
48
+        {
49
+            LengthFieldOffset.Value = 10;
50
+            LengthFieldLength.Value = 2;
51
+            LengthAdjustment.Value = 1;
52
+            InitialBytesToStrip.Value = 0;
53
+        }
38 54
     }
39 55
 }

+ 34 - 5
DotNettyFrom/form/ItemEditorForm.Designer.cs Ver fichero

@@ -59,6 +59,8 @@
59 59
             this.label3 = new System.Windows.Forms.Label();
60 60
             this.CBLenUnFix = new System.Windows.Forms.CheckBox();
61 61
             this.CBUnCheckUD = new System.Windows.Forms.CheckBox();
62
+            this.CbProtocolNo = new System.Windows.Forms.ComboBox();
63
+            this.label12 = new System.Windows.Forms.Label();
62 64
             this.SuspendLayout();
63 65
             // 
64 66
             // label1
@@ -81,7 +83,7 @@
81 83
             // label2
82 84
             // 
83 85
             this.label2.AutoSize = true;
84
-            this.label2.Location = new System.Drawing.Point(207, 32);
86
+            this.label2.Location = new System.Drawing.Point(303, 32);
85 87
             this.label2.Name = "label2";
86 88
             this.label2.Size = new System.Drawing.Size(46, 17);
87 89
             this.label2.TabIndex = 2;
@@ -89,7 +91,7 @@
89 91
             // 
90 92
             // TbItemId
91 93
             // 
92
-            this.TbItemId.Location = new System.Drawing.Point(276, 29);
94
+            this.TbItemId.Location = new System.Drawing.Point(355, 29);
93 95
             this.TbItemId.Name = "TbItemId";
94 96
             this.TbItemId.Size = new System.Drawing.Size(121, 23);
95 97
             this.TbItemId.TabIndex = 3;
@@ -97,7 +99,7 @@
97 99
             // 
98 100
             // TbitemId2
99 101
             // 
100
-            this.TbitemId2.Location = new System.Drawing.Point(501, 29);
102
+            this.TbitemId2.Location = new System.Drawing.Point(544, 29);
101 103
             this.TbitemId2.Name = "TbitemId2";
102 104
             this.TbitemId2.ReadOnly = true;
103 105
             this.TbitemId2.Size = new System.Drawing.Size(121, 23);
@@ -303,7 +305,7 @@
303 305
             this.CBInputType.Items.AddRange(new object[] {
304 306
             "10进制",
305 307
             "16进制"});
306
-            this.CBInputType.Location = new System.Drawing.Point(50, 29);
308
+            this.CBInputType.Location = new System.Drawing.Point(176, 29);
307 309
             this.CBInputType.Name = "CBInputType";
308 310
             this.CBInputType.Size = new System.Drawing.Size(121, 25);
309 311
             this.CBInputType.TabIndex = 26;
@@ -312,7 +314,7 @@
312 314
             // label3
313 315
             // 
314 316
             this.label3.AutoSize = true;
315
-            this.label3.Location = new System.Drawing.Point(419, 32);
317
+            this.label3.Location = new System.Drawing.Point(482, 32);
316 318
             this.label3.Name = "label3";
317 319
             this.label3.Size = new System.Drawing.Size(56, 17);
318 320
             this.label3.TabIndex = 4;
@@ -342,12 +344,37 @@
342 344
             this.CBUnCheckUD.Text = "是否检查长度与默认值";
343 345
             this.CBUnCheckUD.UseVisualStyleBackColor = true;
344 346
             // 
347
+            // CbProtocolNo
348
+            // 
349
+            this.CbProtocolNo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
350
+            this.CbProtocolNo.Enabled = false;
351
+            this.CbProtocolNo.FormattingEnabled = true;
352
+            this.CbProtocolNo.Items.AddRange(new object[] {
353
+            "Dtu",
354
+            "Water2"});
355
+            this.CbProtocolNo.Location = new System.Drawing.Point(47, 29);
356
+            this.CbProtocolNo.Name = "CbProtocolNo";
357
+            this.CbProtocolNo.Size = new System.Drawing.Size(121, 25);
358
+            this.CbProtocolNo.TabIndex = 29;
359
+            // 
360
+            // label12
361
+            // 
362
+            this.label12.AutoSize = true;
363
+            this.label12.ForeColor = System.Drawing.Color.DarkRed;
364
+            this.label12.Location = new System.Drawing.Point(12, 397);
365
+            this.label12.Name = "label12";
366
+            this.label12.Size = new System.Drawing.Size(295, 17);
367
+            this.label12.TabIndex = 30;
368
+            this.label12.Text = "如果是水协议,写操作时,备注必须要写读的my_index值";
369
+            // 
345 370
             // ItemEditorForm
346 371
             // 
347 372
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
348 373
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
349 374
             this.CancelButton = this.BtnCancle;
350 375
             this.ClientSize = new System.Drawing.Size(677, 432);
376
+            this.Controls.Add(this.label12);
377
+            this.Controls.Add(this.CbProtocolNo);
351 378
             this.Controls.Add(this.CBUnCheckUD);
352 379
             this.Controls.Add(this.CBLenUnFix);
353 380
             this.Controls.Add(this.CBInputType);
@@ -428,5 +455,7 @@
428 455
         private System.Windows.Forms.Label label3;
429 456
         private System.Windows.Forms.CheckBox CBLenUnFix;
430 457
         private System.Windows.Forms.CheckBox CBUnCheckUD;
458
+        private System.Windows.Forms.ComboBox CbProtocolNo;
459
+        private System.Windows.Forms.Label label12;
431 460
     }
432 461
 }

+ 23 - 4
DotNettyFrom/form/ItemEditorForm.cs Ver fichero

@@ -7,6 +7,7 @@ using System.Linq;
7 7
 using System.Text;
8 8
 using System.Threading.Tasks;
9 9
 using System.Windows.Forms;
10
+using DotNettyFrom.config;
10 11
 using DotNettyFrom.db;
11 12
 using DotNettyFrom.model;
12 13
 using DotNettyFrom.util;
@@ -21,6 +22,8 @@ namespace DotNettyFrom.form
21 22
         private string _id;
22 23
         private bool _isAdd = true; //true-add
23 24
 
25
+        private int len = 4;
26
+
24 27
         public ItemEditorForm(string id = null)
25 28
         {
26 29
             this._id = id;
@@ -30,6 +33,17 @@ namespace DotNettyFrom.form
30 33
         private void ItemEditorForm_Load(object sender, EventArgs e)
31 34
         {
32 35
             CBInputType.SelectedIndex = 0;
36
+            CbProtocolNo.SelectedIndex = SystemConfig.CurrentType - 1;
37
+
38
+
39
+            if (SystemConfig.CurrentType == SystemConfig.Dtu)
40
+            {
41
+                len = 4;
42
+            }
43
+            else if (SystemConfig.CurrentType == SystemConfig.Water2)
44
+            {
45
+                len = 2;
46
+            }
33 47
 
34 48
             if (_id != null)
35 49
             {
@@ -48,12 +62,18 @@ namespace DotNettyFrom.form
48 62
 
49 63
         private void UpdateOption(int id)
50 64
         {
51
-         
52 65
             BtnOp.Text = "修改";
53 66
             WvBean wb = DbHelper.GetInstance().SelectOneCmdById(id);
67
+            if (wb == null)
68
+            {
69
+                MessageBox.Show("出错,数据库找不到.id = " + id);
70
+                this.Close();
71
+            }
54 72
             this.Text = "修改ID - " + wb.id;
55 73
             _isAdd = false;
56 74
 
75
+            CbProtocolNo.SelectedIndex = wb.protocolNo - 1;
76
+
57 77
             TbItemId.Enabled = false;
58 78
             CBInputType.Enabled = false;
59 79
 
@@ -87,7 +107,6 @@ namespace DotNettyFrom.form
87 107
 
88 108
         private void CBInputType_SelectedIndexChanged(object sender, EventArgs e)
89 109
         {
90
-            Console.WriteLine(CBInputType.SelectedIndex);
91 110
         }
92 111
 
93 112
         private void TbItemId_TextChanged(object sender, EventArgs e)
@@ -98,7 +117,6 @@ namespace DotNettyFrom.form
98 117
                 TbitemId2.Text = "";
99 118
                 return;
100 119
             }
101
-
102 120
             if (CBInputType.SelectedIndex == 0)
103 121
             {
104 122
                 //10 ->16
@@ -106,7 +124,7 @@ namespace DotNettyFrom.form
106 124
                 try
107 125
                 {
108 126
                     int _id = int.Parse(text);
109
-                    TbitemId2.Text = CmdUtil.FrontWithZero(CmdUtil.Dec2Hex(_id), 4);
127
+                    TbitemId2.Text = CmdUtil.FrontWithZero(CmdUtil.Dec2Hex(_id), len);
110 128
                     RtbInfo.Text = "";
111 129
                 }
112 130
                 catch (Exception esException)
@@ -245,6 +263,7 @@ namespace DotNettyFrom.form
245 263
             wb.defalutValue = defalutValueString;
246 264
             wb.userValue = userValueString;
247 265
             wb.remark = TbRemark.Text.Trim();
266
+            wb.protocolNo = CbProtocolNo.SelectedIndex + 1;
248 267
 
249 268
             #endregion
250 269
 

+ 3 - 2
DotNettyFrom/form/ItemManagerForm.Designer.cs Ver fichero

@@ -58,7 +58,7 @@
58 58
             this.dataGridViewItem.ReadOnly = true;
59 59
             this.dataGridViewItem.RowTemplate.Height = 23;
60 60
             this.dataGridViewItem.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
61
-            this.dataGridViewItem.Size = new System.Drawing.Size(1130, 554);
61
+            this.dataGridViewItem.Size = new System.Drawing.Size(1211, 554);
62 62
             this.dataGridViewItem.TabIndex = 0;
63 63
             this.dataGridViewItem.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewItem_CellMouseClick);
64 64
             this.dataGridViewItem.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewItem_CellMouseDoubleClick);
@@ -139,6 +139,7 @@
139 139
             // 
140 140
             // BtnClose
141 141
             // 
142
+            this.BtnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
142 143
             this.BtnClose.Location = new System.Drawing.Point(562, 35);
143 144
             this.BtnClose.Name = "BtnClose";
144 145
             this.BtnClose.Size = new System.Drawing.Size(75, 23);
@@ -187,7 +188,7 @@
187 188
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
188 189
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
189 190
             this.CancelButton = this.BtnClose;
190
-            this.ClientSize = new System.Drawing.Size(1158, 729);
191
+            this.ClientSize = new System.Drawing.Size(1239, 729);
191 192
             this.Controls.Add(this.RtbLogInfo);
192 193
             this.Controls.Add(this.TBInputFind);
193 194
             this.Controls.Add(this.label1);

+ 1 - 1
DotNettyFrom/form/ItemManagerForm.cs Ver fichero

@@ -143,7 +143,7 @@ namespace DotNettyFrom.form
143 143
             if (dialogResult == DialogResult.OK)
144 144
             {
145 145
                 //
146
-                DbHelper.GetInstance().DeleteAllFwData();
146
+                DbHelper.GetInstance().DeleteAllData();
147 147
                 ReLoadDatatable();
148 148
             }
149 149
         }

+ 18 - 0
DotNettyFrom/generatecmd/CmdGenetor.cs Ver fichero

@@ -4,6 +4,7 @@ using System.Linq;
4 4
 using System.Text;
5 5
 using System.Threading.Tasks;
6 6
 using DotNetty.Handlers.Timeout;
7
+using DotNettyFrom.config;
7 8
 using DotNettyFrom.util;
8 9
 
9 10
 namespace DotNettyFrom.generatecmd
@@ -16,5 +17,22 @@ namespace DotNettyFrom.generatecmd
16 17
         public abstract string GetLoginCmd(string ccid);
17 18
 
18 19
         public abstract string GetHeartbeat();
20
+
21
+        public abstract string GetReplyCmd(string receiveCmd);
22
+
23
+
24
+        public int GetCmdId(string receiveCmd)
25
+        {
26
+            try
27
+            {
28
+                string cmdId = receiveCmd.Substring(SystemConfig.FunctionCodeStartPos, SystemConfig.FunctionCodeLength);
29
+                return Utils.hexToTen(cmdId);
30
+            }
31
+            catch (Exception)
32
+            {
33
+            }
34
+            return int.MinValue;
35
+        }
36
+
19 37
     }
20 38
 }

+ 6 - 1
DotNettyFrom/generatecmd/DtuCmdGenetor.cs Ver fichero

@@ -22,7 +22,12 @@ namespace DotNettyFrom.generatecmd
22 22
             //7e7e7e00000000000184000085
23 23
             string cmd = DeviceId + "840000";
24 24
             cmd = "7e7e7e" + CmdUtil.CalcCrcCode(cmd);
25
-            return cmd;
25
+            return cmd.ToUpper();
26
+        }
27
+
28
+        public override string GetReplyCmd(string receiveCmd)
29
+        {
30
+            throw new NotImplementedException();
26 31
         }
27 32
     }
28 33
 }

+ 91 - 1
DotNettyFrom/generatecmd/Water2CmdGenetor.cs Ver fichero

@@ -3,6 +3,9 @@ using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Text;
5 5
 using System.Threading.Tasks;
6
+using DotNettyFrom.config;
7
+using DotNettyFrom.db;
8
+using DotNettyFrom.model;
6 9
 using DotNettyFrom.util;
7 10
 
8 11
 namespace DotNettyFrom.generatecmd
@@ -18,7 +21,94 @@ namespace DotNettyFrom.generatecmd
18 21
         public override string GetHeartbeat()
19 22
         {
20 23
             string cmd = DeviceId + "03020001";
21
-            return "7e7e7e" + CmdUtil.CalcCrc16Code(cmd);
24
+            return "7e7e7e" + CmdUtil.CalcCrc16Code(cmd).ToUpper();
25
+        }
26
+
27
+        public override string GetReplyCmd(string receiveCmd)
28
+        {
29
+            int cmdId = GetCmdId(receiveCmd);
30
+
31
+
32
+            if (cmdId == int.MinValue)
33
+            {
34
+                return null;
35
+            }
36
+
37
+            WvBean wb = DbHelper.GetInstance().SelectOneCmdByIndex(cmdId);
38
+
39
+            if (wb == null)
40
+            {
41
+                return null;
42
+            }
43
+            int pos = SystemConfig.FunctionCodeStartPos + SystemConfig.FunctionCodeLength;
44
+
45
+            //前面的
46
+            string resp = receiveCmd.Substring(0, pos);
47
+            //消息长度
48
+            string msgLen = receiveCmd.Substring(pos, SystemConfig.LengthFieldLength * 2);
49
+            pos += SystemConfig.LengthFieldLength * 2;
50
+            //测量点&消息流水
51
+
52
+            int MeasureFlow = (SystemConfig.MeasurePointLen + SystemConfig.MessageFlowLen);
53
+            string msgFlow =
54
+                receiveCmd.Substring(pos, MeasureFlow * 2);
55
+
56
+            pos += MeasureFlow * 2;
57
+
58
+            Console.WriteLine(resp);
59
+            Console.WriteLine("长度:" + msgLen);
60
+            Console.WriteLine("消息流水:" + msgFlow);
61
+            string bodyFrame = "";
62
+
63
+            if (!wb.remark.Trim().Equals(""))
64
+            {
65
+                //写
66
+                try
67
+                {
68
+                    int updateId = int.Parse(wb.remark.Trim());
69
+                    int msgLenTen = Utils.hexToTen(msgLen) - MeasureFlow;
70
+
71
+                    string content = receiveCmd.Substring(pos, msgLenTen * 2);
72
+
73
+
74
+                    Console.WriteLine("updateId:" + updateId + ";;" + msgLenTen);
75
+                    Console.WriteLine("Conte=" + content);
76
+                    WvBean updateBean = DbHelper.GetInstance().SelectOneCmdByIndex(updateId);
77
+                    if (updateBean != null)
78
+                    {
79
+                        updateBean.userValue = content;
80
+                        int result = DbHelper.GetInstance().UpdateCmd(updateBean);
81
+                        if (result > 0)
82
+                        {
83
+                            bodyFrame = "03" + msgFlow + "00";
84
+                        }
85
+                        else
86
+                        {
87
+                            bodyFrame = "03" + msgFlow + "01";
88
+                        }
89
+                    }
90
+                    
91
+                }
92
+                catch (Exception exception)
93
+                {
94
+                    bodyFrame = "03" + msgFlow + "01";
95
+                    Console.WriteLine(exception.Message);
96
+                    Console.WriteLine(exception);
97
+                }
98
+            }
99
+            else
100
+            {
101
+                //读
102
+                Console.WriteLine(wb.userValue);
103
+            }
104
+
105
+
106
+            return null;
107
+        }
108
+
109
+        private string GetFrontFrame(string cmd)
110
+        {
111
+            return cmd.Substring(0, SystemConfig.FunctionCodeLength + SystemConfig.FunctionCodeStartPos);
22 112
         }
23 113
     }
24 114
 }

+ 14 - 4
DotNettyFrom/model/WvBean.cs Ver fichero

@@ -18,13 +18,23 @@ namespace DotNettyFrom.model
18 18
         public string remark = "";
19 19
         public string defalutValue = "";
20 20
         public string userValue = "";
21
+        public int protocolNo;
21 22
 
22 23
         public override string ToString()
23 24
         {
24
-            return "{\"index\":\"" + index + "\",\"myId\":\"" + myId + "\",\"idInfo\":\"" + idInfo + "\",\"len\":\"" +
25
-                   len + "\","
26
-                   + "\"mode\":\"" + mode + "\",\"desp\":\"" + desp + "\",\"remark\":\""
27
-                   + "\"}";
25
+            return "IssuedCmdDataTest{" +
26
+                   "id=" + id +
27
+                   ", index=" + index +
28
+                   ", myId='" + myId + '\'' +
29
+                   ", idInfo='" + idInfo + '\'' +
30
+                   ", len='" + len + '\'' +
31
+                   ", mode='" + mode + '\'' +
32
+                   ", desp='" + desp + '\'' +
33
+                   ", remark='" + remark + '\'' +
34
+                   ", defalutValue='" + defalutValue + '\'' +
35
+                   ", userValue='" + userValue + '\'' +
36
+                   ", protocolNo=" + protocolNo +
37
+                   '}';
28 38
         }
29 39
     }
30 40
 

+ 19 - 3
DotNettyFrom/netty/NettyClient.cs Ver fichero

@@ -45,11 +45,11 @@ namespace DotNettyFrom.netty
45 45
                 .Handler(new ActionChannelInitializer<ISocketChannel>(channel =>
46 46
                 {
47 47
                     IChannelPipeline pipeline = channel.Pipeline;
48
-                    /*pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue,
48
+                    pipeline.AddLast(new LengthFieldBasedFrameDecoder(ushort.MaxValue,
49 49
                         SystemConfig.LengthFieldOffset,
50 50
                         SystemConfig.LengthFieldLength,
51 51
                         SystemConfig.LengthAdjustment,
52
-                        SystemConfig.InitialBytesToStrip));*/
52
+                        SystemConfig.InitialBytesToStrip));
53 53
                     pipeline.AddLast(new IdleStateHandler(SystemConfig.ReaderIdleTimeSeconds,
54 54
                         SystemConfig.WriterIdleTimeSeconds,
55 55
                         SystemConfig.AllIdleTimeSeconds));
@@ -125,6 +125,18 @@ namespace DotNettyFrom.netty
125 125
                 {
126 126
                     string recCmd = AryUtil.ByteBuffer2Hex(buffer);
127 127
                     DataModel.ReceCollection.Add(new UIInfoModel("收到", recCmd));
128
+                    Console.WriteLine("收到:" + recCmd);
129
+
130
+                    string cmd = CmdGenetor.Genetor?.GetReplyCmd(recCmd);
131
+                    if (cmd != null)
132
+                    {
133
+                        IByteBuffer replyBuffer = AryUtil.Hex2IByteBuffer(cmd);
134
+                        context.WriteAndFlushAsync(replyBuffer);
135
+                    }
136
+                    else
137
+                    {
138
+                        Console.WriteLine("reply is null");
139
+                    }
128 140
                 }
129 141
                 else
130 142
                 {
@@ -147,7 +159,11 @@ namespace DotNettyFrom.netty
147 159
                     {
148 160
                         string hb = CmdGenetor.Genetor.GetHeartbeat();
149 161
                         context.Channel.WriteAndFlushAsync(AryUtil.Hex2IByteBuffer(hb));
150
-                        DataModel.ReceCollection.Add(new UIInfoModel("发送", hb).setSendType(SystemConfig.SendType));
162
+                        Console.WriteLine("发心跳:" + hb + ".log=" + SystemConfig.IsLogHeartBeatInfo);
163
+                        if (SystemConfig.IsLogHeartBeatInfo)
164
+                        {
165
+                            DataModel.ReceCollection.Add(new UIInfoModel("发送", hb).setSendType(SystemConfig.SendType));
166
+                        }
151 167
                     }
152 168
                     else
153 169
                     {

+ 1 - 0
DotNettyFrom/packages.config Ver fichero

@@ -11,6 +11,7 @@
11 11
   <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
12 12
   <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" />
13 13
   <package id="NETStandard.Library" version="1.6.1" targetFramework="net461" />
14
+  <package id="NUnit" version="3.8.1" targetFramework="net461" />
14 15
   <package id="System.AppContext" version="4.3.0" targetFramework="net461" />
15 16
   <package id="System.Collections" version="4.3.0" targetFramework="net461" />
16 17
   <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" />

+ 2 - 0
DotNettyFromTests/DotNettyFromTests.csproj Ver fichero

@@ -61,7 +61,9 @@
61 61
   <ItemGroup>
62 62
     <Compile Include="common\UIInfoModelTests.cs" />
63 63
     <Compile Include="generatecmd\CmdGenetorTests.cs" />
64
+    <Compile Include="generatecmd\Water2CmdGenetorTests.cs" />
64 65
     <Compile Include="Properties\AssemblyInfo.cs" />
66
+    <Compile Include="UnitTest1.cs" />
65 67
     <Compile Include="util\CmdUtilTests.cs" />
66 68
   </ItemGroup>
67 69
   <ItemGroup>

+ 15 - 0
DotNettyFromTests/UnitTest1.cs Ver fichero

@@ -0,0 +1,15 @@
1
+using System;
2
+using Microsoft.VisualStudio.TestTools.UnitTesting;
3
+
4
+namespace DotNettyFromTests
5
+{
6
+    [TestClass()]
7
+    public class UnitTest1
8
+    {
9
+        [TestMethod()]
10
+        public void TestMethod1()
11
+        {
12
+            Console.WriteLine("--------------------");
13
+        }
14
+    }
15
+}

+ 3 - 3
DotNettyFromTests/generatecmd/CmdGenetorTests.cs Ver fichero

@@ -21,9 +21,9 @@ namespace DotNettyFrom.generatecmd.Tests
21 21
         [TestMethod()]
22 22
         public void GetHeartbeatTest()
23 23
         {
24
-            CmdGenetor c = CmdGenetor.GetInstance().SetDeviceId("000000000002");
25
-            string cmd = c.GetLoginCmd("3839383630324731313931353530333339393137");
26
-            Console.WriteLine(cmd);
24
+            
25
+
26
+
27 27
         }
28 28
     }
29 29
 }

+ 28 - 0
DotNettyFromTests/generatecmd/Water2CmdGenetorTests.cs Ver fichero

@@ -0,0 +1,28 @@
1
+using System;
2
+using DotNettyFrom.config;
3
+using DotNettyFrom.db;
4
+using DotNettyFrom.generatecmd;
5
+using Microsoft.VisualStudio.TestTools.UnitTesting;
6
+
7
+namespace DotNettyFromTests.generatecmd
8
+{
9
+    [TestClass()]
10
+    public class Water2CmdGenetorTests
11
+    {
12
+        [TestMethod]
13
+        public void GetReplyCmdTest()
14
+        {
15
+
16
+            Console.WriteLine("----------------");
17
+
18
+            DbHelper.Init(@"D:\CSharp\DotNettyFrom\DotNettyFrom\bin\Debug\DotNettyFrom.accdb");
19
+            ConfigChange.ChangeDevice(SystemConfig.Water2);
20
+            
21
+
22
+            Water2CmdGenetor genetor = new Water2CmdGenetor();
23
+
24
+            genetor.GetReplyCmd("7e7e7e83a41e31f1f70f06018503e800645569");
25
+
26
+        }
27
+    }
28
+}