Procházet zdrojové kódy

Half Package Problem.

张泳健 před 7 roky
rodič
revize
7fd5990360

+ 11 - 0
DotNettyFrom/DotNettyFrom.csproj Zobrazit soubor

@@ -144,6 +144,13 @@
144 144
     <Compile Include="dialog\HistoryDialog.Designer.cs">
145 145
       <DependentUpon>HistoryDialog.cs</DependentUpon>
146 146
     </Compile>
147
+    <Compile Include="dialog\TcpPkgConfigDialog.cs">
148
+      <SubType>Form</SubType>
149
+    </Compile>
150
+    <Compile Include="dialog\TcpPkgConfigDialog.Designer.cs">
151
+      <DependentUpon>TcpPkgConfigDialog.cs</DependentUpon>
152
+    </Compile>
153
+    <Compile Include="generatecmd\DtuCmdGenetor.cs" />
147 154
     <Compile Include="excel\ExcelHelper.cs" />
148 155
     <Compile Include="form\ItemEditorForm.cs">
149 156
       <SubType>Form</SubType>
@@ -158,6 +165,7 @@
158 165
       <DependentUpon>ItemManagerForm.cs</DependentUpon>
159 166
     </Compile>
160 167
     <Compile Include="generatecmd\CmdGenetor.cs" />
168
+    <Compile Include="generatecmd\Water2CmdGenetor.cs" />
161 169
     <Compile Include="MainForm.cs">
162 170
       <SubType>Form</SubType>
163 171
     </Compile>
@@ -178,6 +186,9 @@
178 186
     <EmbeddedResource Include="dialog\HistoryDialog.resx">
179 187
       <DependentUpon>HistoryDialog.cs</DependentUpon>
180 188
     </EmbeddedResource>
189
+    <EmbeddedResource Include="dialog\TcpPkgConfigDialog.resx">
190
+      <DependentUpon>TcpPkgConfigDialog.cs</DependentUpon>
191
+    </EmbeddedResource>
181 192
     <EmbeddedResource Include="form\ItemEditorForm.resx">
182 193
       <DependentUpon>ItemEditorForm.cs</DependentUpon>
183 194
     </EmbeddedResource>

+ 62 - 8
DotNettyFrom/MainForm.Designer.cs Zobrazit soubor

@@ -46,7 +46,10 @@
46 46
             this.BtnSendData = new System.Windows.Forms.Button();
47 47
             this.menuStrip1 = new System.Windows.Forms.MenuStrip();
48 48
             this.文件FToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
49
+            this.dtuToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
50
+            this.water2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
49 51
             this.时间TToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
52
+            this.RT_HB_Enable = new System.Windows.Forms.ToolStripMenuItem();
50 53
             this.RT_HB_Time = new System.Windows.Forms.ToolStripMenuItem();
51 54
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
52 55
             this.历史HToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -70,6 +73,8 @@
70 73
             this.TbDeviceId = new System.Windows.Forms.TextBox();
71 74
             this.label2 = new System.Windows.Forms.Label();
72 75
             this.label1 = new System.Windows.Forms.Label();
76
+            this.配置CToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
77
+            this.HalfPkgToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
73 78
             this.ListBoxLogContextMenu.SuspendLayout();
74 79
             this.menuStrip1.SuspendLayout();
75 80
             this.statusStrip1.SuspendLayout();
@@ -222,7 +227,8 @@
222 227
             this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
223 228
             this.文件FToolStripMenuItem,
224 229
             this.时间TToolStripMenuItem,
225
-            this.历史HToolStripMenuItem});
230
+            this.历史HToolStripMenuItem,
231
+            this.配置CToolStripMenuItem});
226 232
             this.menuStrip1.Location = new System.Drawing.Point(0, 0);
227 233
             this.menuStrip1.Name = "menuStrip1";
228 234
             this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
@@ -232,30 +238,58 @@
232 238
             // 
233 239
             // 文件FToolStripMenuItem
234 240
             // 
241
+            this.文件FToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
242
+            this.dtuToolStripMenuItem,
243
+            this.water2ToolStripMenuItem});
235 244
             this.文件FToolStripMenuItem.Name = "文件FToolStripMenuItem";
236 245
             this.文件FToolStripMenuItem.Size = new System.Drawing.Size(58, 21);
237 246
             this.文件FToolStripMenuItem.Text = "文件(&F)";
238 247
             // 
248
+            // dtuToolStripMenuItem
249
+            // 
250
+            this.dtuToolStripMenuItem.Name = "dtuToolStripMenuItem";
251
+            this.dtuToolStripMenuItem.Size = new System.Drawing.Size(115, 22);
252
+            this.dtuToolStripMenuItem.Text = "dtu";
253
+            this.dtuToolStripMenuItem.Click += new System.EventHandler(this.dtuToolStripMenuItem_Click);
254
+            // 
255
+            // water2ToolStripMenuItem
256
+            // 
257
+            this.water2ToolStripMenuItem.Name = "water2ToolStripMenuItem";
258
+            this.water2ToolStripMenuItem.Size = new System.Drawing.Size(115, 22);
259
+            this.water2ToolStripMenuItem.Text = "water2";
260
+            this.water2ToolStripMenuItem.Click += new System.EventHandler(this.water2ToolStripMenuItem_Click);
261
+            // 
239 262
             // 时间TToolStripMenuItem
240 263
             // 
241 264
             this.时间TToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
265
+            this.RT_HB_Enable,
242 266
             this.RT_HB_Time,
243 267
             this.toolStripSeparator1});
244 268
             this.时间TToolStripMenuItem.Name = "时间TToolStripMenuItem";
245 269
             this.时间TToolStripMenuItem.Size = new System.Drawing.Size(59, 21);
246 270
             this.时间TToolStripMenuItem.Text = "时间(&T)";
247 271
             // 
272
+            // RT_HB_Enable
273
+            // 
274
+            this.RT_HB_Enable.Checked = true;
275
+            this.RT_HB_Enable.CheckOnClick = true;
276
+            this.RT_HB_Enable.CheckState = System.Windows.Forms.CheckState.Checked;
277
+            this.RT_HB_Enable.Name = "RT_HB_Enable";
278
+            this.RT_HB_Enable.Size = new System.Drawing.Size(152, 22);
279
+            this.RT_HB_Enable.Text = "启用心跳";
280
+            this.RT_HB_Enable.Click += new System.EventHandler(this.RT_HB_Enable_Click);
281
+            // 
248 282
             // RT_HB_Time
249 283
             // 
250 284
             this.RT_HB_Time.Name = "RT_HB_Time";
251
-            this.RT_HB_Time.Size = new System.Drawing.Size(141, 22);
285
+            this.RT_HB_Time.Size = new System.Drawing.Size(152, 22);
252 286
             this.RT_HB_Time.Text = "心跳超时(&H)";
253 287
             this.RT_HB_Time.Click += new System.EventHandler(this.RT_HB_Time_Click);
254 288
             // 
255 289
             // toolStripSeparator1
256 290
             // 
257 291
             this.toolStripSeparator1.Name = "toolStripSeparator1";
258
-            this.toolStripSeparator1.Size = new System.Drawing.Size(138, 6);
292
+            this.toolStripSeparator1.Size = new System.Drawing.Size(149, 6);
259 293
             // 
260 294
             // 历史HToolStripMenuItem
261 295
             // 
@@ -272,33 +306,33 @@
272 306
             // RT_HI_Host
273 307
             // 
274 308
             this.RT_HI_Host.Name = "RT_HI_Host";
275
-            this.RT_HI_Host.Size = new System.Drawing.Size(152, 22);
309
+            this.RT_HI_Host.Size = new System.Drawing.Size(124, 22);
276 310
             this.RT_HI_Host.Text = "Host";
277 311
             this.RT_HI_Host.Click += new System.EventHandler(this.RT_HI_Host_Click);
278 312
             // 
279 313
             // RT_HI_DeviceId
280 314
             // 
281 315
             this.RT_HI_DeviceId.Name = "RT_HI_DeviceId";
282
-            this.RT_HI_DeviceId.Size = new System.Drawing.Size(152, 22);
316
+            this.RT_HI_DeviceId.Size = new System.Drawing.Size(124, 22);
283 317
             this.RT_HI_DeviceId.Text = "地址";
284 318
             this.RT_HI_DeviceId.Click += new System.EventHandler(this.RT_HI_DeviceId_Click);
285 319
             // 
286 320
             // RT_HI_CCID
287 321
             // 
288 322
             this.RT_HI_CCID.Name = "RT_HI_CCID";
289
-            this.RT_HI_CCID.Size = new System.Drawing.Size(152, 22);
323
+            this.RT_HI_CCID.Size = new System.Drawing.Size(124, 22);
290 324
             this.RT_HI_CCID.Text = "CCID";
291 325
             this.RT_HI_CCID.Click += new System.EventHandler(this.RT_HI_CCID_Click);
292 326
             // 
293 327
             // toolStripSeparator2
294 328
             // 
295 329
             this.toolStripSeparator2.Name = "toolStripSeparator2";
296
-            this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6);
330
+            this.toolStripSeparator2.Size = new System.Drawing.Size(121, 6);
297 331
             // 
298 332
             // RT_HI_SendData
299 333
             // 
300 334
             this.RT_HI_SendData.Name = "RT_HI_SendData";
301
-            this.RT_HI_SendData.Size = new System.Drawing.Size(152, 22);
335
+            this.RT_HI_SendData.Size = new System.Drawing.Size(124, 22);
302 336
             this.RT_HI_SendData.Text = "发送数据";
303 337
             this.RT_HI_SendData.Click += new System.EventHandler(this.RT_HI_SendData_Click);
304 338
             // 
@@ -462,6 +496,21 @@
462 496
             this.label1.TabIndex = 2;
463 497
             this.label1.Text = "Host";
464 498
             // 
499
+            // 配置CToolStripMenuItem
500
+            // 
501
+            this.配置CToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
502
+            this.HalfPkgToolStripMenuItem});
503
+            this.配置CToolStripMenuItem.Name = "配置CToolStripMenuItem";
504
+            this.配置CToolStripMenuItem.Size = new System.Drawing.Size(60, 21);
505
+            this.配置CToolStripMenuItem.Text = "配置(&C)";
506
+            // 
507
+            // HalfPkgToolStripMenuItem
508
+            // 
509
+            this.HalfPkgToolStripMenuItem.Name = "HalfPkgToolStripMenuItem";
510
+            this.HalfPkgToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
511
+            this.HalfPkgToolStripMenuItem.Text = "半包-粘包";
512
+            this.HalfPkgToolStripMenuItem.Click += new System.EventHandler(this.HalfPkgToolStripMenuItem_Click);
513
+            // 
465 514
             // MainForm
466 515
             // 
467 516
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F);
@@ -534,6 +583,11 @@
534 583
         private System.Windows.Forms.ToolStripMenuItem LB_Context_ClearAll;
535 584
         private System.Windows.Forms.ToolStripMenuItem LB_Context_CpLine;
536 585
         private System.Windows.Forms.Button BtnClearAll;
586
+        private System.Windows.Forms.ToolStripMenuItem RT_HB_Enable;
587
+        private System.Windows.Forms.ToolStripMenuItem dtuToolStripMenuItem;
588
+        private System.Windows.Forms.ToolStripMenuItem water2ToolStripMenuItem;
589
+        private System.Windows.Forms.ToolStripMenuItem 配置CToolStripMenuItem;
590
+        private System.Windows.Forms.ToolStripMenuItem HalfPkgToolStripMenuItem;
537 591
     }
538 592
 }
539 593
 

+ 33 - 2
DotNettyFrom/MainForm.cs Zobrazit soubor

@@ -130,6 +130,15 @@ namespace DotNettyFrom
130 130
             StatusItemHbTime.Text = "R:" + SystemConfig.ReaderIdleTimeSeconds + "/s,W:" +
131 131
                                     SystemConfig.WriterIdleTimeSeconds + "/s,A:" + SystemConfig.AllIdleTimeSeconds +
132 132
                                     "/s";
133
+            CmdGenetor.Genetor = new DtuCmdGenetor();
134
+            if ("".Equals(TbDeviceId.Text.Trim()))
135
+            {
136
+                CmdGenetor.Genetor.DeviceId = "000000000001";
137
+            }
138
+            else
139
+            {
140
+                CmdGenetor.Genetor.DeviceId = TbDeviceId.Text.Trim();
141
+            }
133 142
         }
134 143
 
135 144
         #region Component Event
@@ -151,6 +160,7 @@ namespace DotNettyFrom
151 160
 
152 161
             BeforeConnection();
153 162
 
163
+            CmdGenetor.Genetor.DeviceId = TbDeviceId.Text.Trim();
154 164
             Task startNew = Task.Factory.StartNew(() =>
155 165
             {
156 166
                 _nettyClient = new NettyClient();
@@ -164,8 +174,8 @@ namespace DotNettyFrom
164 174
 
165 175
             Task startNew = Task.Factory.StartNew(() =>
166 176
             {
167
-                string loginCmd = CmdGenetor.GetInstance().SetDeviceId(TbDeviceId.Text.Trim())
168
-                    .GetLoginCmd(TbCCID.Text.Trim());
177
+                CmdGenetor.Genetor.DeviceId = TbDeviceId.Text.Trim();
178
+                string loginCmd = CmdGenetor.Genetor.GetLoginCmd(TbCCID.Text.Trim());
169 179
                 _nettyClient = new NettyClient();
170 180
                 _nettyClient.StartNetty(host, port, loginCmd);
171 181
             });
@@ -190,6 +200,11 @@ namespace DotNettyFrom
190 200
             hbt.ShowDialog();
191 201
         }
192 202
 
203
+        private void RT_HB_Enable_Click(object sender, EventArgs e)
204
+        {
205
+            SystemConfig.OpenHeartBeat = RT_HB_Enable.Checked;
206
+        }
207
+
193 208
         private void TbPort_KeyPress(object sender, KeyPressEventArgs e)
194 209
         {
195 210
             if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
@@ -198,6 +213,16 @@ namespace DotNettyFrom
198 213
             }
199 214
         }
200 215
 
216
+        private void dtuToolStripMenuItem_Click(object sender, EventArgs e)
217
+        {
218
+            CmdGenetor.Genetor = new DtuCmdGenetor();
219
+        }
220
+
221
+        private void water2ToolStripMenuItem_Click(object sender, EventArgs e)
222
+        {
223
+            CmdGenetor.Genetor = new Water2CmdGenetor();
224
+        }
225
+
201 226
         private void BtnClearAll_Click(object sender, EventArgs e) => LBLogShow.Items.Clear();
202 227
 
203 228
         private void BtnCmdManager_Click(object sender, EventArgs e)
@@ -239,6 +264,12 @@ namespace DotNettyFrom
239 264
         {
240 265
         }
241 266
 
267
+        private void HalfPkgToolStripMenuItem_Click(object sender, EventArgs e)
268
+        {
269
+            TcpPkgConfigDialog tcpDialog = new TcpPkgConfigDialog();
270
+            tcpDialog.ShowDialog();
271
+        }
272
+
242 273
         #endregion
243 274
 
244 275
         #region ListBox

+ 4 - 1
DotNettyFrom/config/SystemConfig.cs Zobrazit soubor

@@ -11,6 +11,9 @@ namespace DotNettyFrom.config
11 11
         public static int FunctionCodeStartPos = 18;
12 12
         public static int FunctionCodeLength = 2;
13 13
 
14
+
15
+        public static bool OpenHeartBeat = true;
16
+
14 17
         public static int ReaderIdleTimeSeconds = 5;
15 18
         public static int WriterIdleTimeSeconds = 5;
16 19
         public static int AllIdleTimeSeconds = 25;
@@ -26,6 +29,7 @@ namespace DotNettyFrom.config
26 29
 
27 30
         //1 发送的. 0:接收的, -1.Debug.日常信息
28 31
         public static int SendType = 1;
32
+
29 33
         public static int RecType = 0;
30 34
         public static int DebugType = -1;
31 35
         public static int ReplyType = 2;
@@ -35,6 +39,5 @@ namespace DotNettyFrom.config
35 39
         public const int AddrHisType = 2;
36 40
         public const int SendHisType = 3;
37 41
         public const int CcidHisType = 4;
38
-
39 42
     }
40 43
 }

+ 193 - 0
DotNettyFrom/dialog/TcpPkgConfigDialog.Designer.cs Zobrazit soubor

@@ -0,0 +1,193 @@
1
+namespace DotNettyFrom.dialog
2
+{
3
+    partial class TcpPkgConfigDialog
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.label1 = new System.Windows.Forms.Label();
32
+            this.label2 = new System.Windows.Forms.Label();
33
+            this.label3 = new System.Windows.Forms.Label();
34
+            this.LengthFieldOffset = new System.Windows.Forms.NumericUpDown();
35
+            this.LengthFieldLength = new System.Windows.Forms.NumericUpDown();
36
+            this.LengthAdjustment = new System.Windows.Forms.NumericUpDown();
37
+            this.buttonCancle = new System.Windows.Forms.Button();
38
+            this.buttonOk = new System.Windows.Forms.Button();
39
+            this.textBox1 = new System.Windows.Forms.TextBox();
40
+            this.InitialBytesToStrip = new System.Windows.Forms.NumericUpDown();
41
+            this.label4 = new System.Windows.Forms.Label();
42
+            ((System.ComponentModel.ISupportInitialize)(this.LengthFieldOffset)).BeginInit();
43
+            ((System.ComponentModel.ISupportInitialize)(this.LengthFieldLength)).BeginInit();
44
+            ((System.ComponentModel.ISupportInitialize)(this.LengthAdjustment)).BeginInit();
45
+            ((System.ComponentModel.ISupportInitialize)(this.InitialBytesToStrip)).BeginInit();
46
+            this.SuspendLayout();
47
+            // 
48
+            // label1
49
+            // 
50
+            this.label1.AutoSize = true;
51
+            this.label1.Location = new System.Drawing.Point(89, 124);
52
+            this.label1.Name = "label1";
53
+            this.label1.Size = new System.Drawing.Size(109, 17);
54
+            this.label1.TabIndex = 0;
55
+            this.label1.Text = "LengthFieldOffset";
56
+            // 
57
+            // label2
58
+            // 
59
+            this.label2.AutoSize = true;
60
+            this.label2.Location = new System.Drawing.Point(89, 188);
61
+            this.label2.Name = "label2";
62
+            this.label2.Size = new System.Drawing.Size(117, 17);
63
+            this.label2.TabIndex = 1;
64
+            this.label2.Text = "LengthFieldLength ";
65
+            // 
66
+            // label3
67
+            // 
68
+            this.label3.AutoSize = true;
69
+            this.label3.Location = new System.Drawing.Point(89, 241);
70
+            this.label3.Name = "label3";
71
+            this.label3.Size = new System.Drawing.Size(112, 17);
72
+            this.label3.TabIndex = 1;
73
+            this.label3.Text = "LengthAdjustment";
74
+            // 
75
+            // LengthFieldOffset
76
+            // 
77
+            this.LengthFieldOffset.Location = new System.Drawing.Point(210, 124);
78
+            this.LengthFieldOffset.Name = "LengthFieldOffset";
79
+            this.LengthFieldOffset.Size = new System.Drawing.Size(120, 23);
80
+            this.LengthFieldOffset.TabIndex = 2;
81
+            // 
82
+            // LengthFieldLength
83
+            // 
84
+            this.LengthFieldLength.Location = new System.Drawing.Point(210, 186);
85
+            this.LengthFieldLength.Name = "LengthFieldLength";
86
+            this.LengthFieldLength.Size = new System.Drawing.Size(120, 23);
87
+            this.LengthFieldLength.TabIndex = 2;
88
+            // 
89
+            // LengthAdjustment
90
+            // 
91
+            this.LengthAdjustment.Location = new System.Drawing.Point(210, 235);
92
+            this.LengthAdjustment.Name = "LengthAdjustment";
93
+            this.LengthAdjustment.Size = new System.Drawing.Size(120, 23);
94
+            this.LengthAdjustment.TabIndex = 2;
95
+            // 
96
+            // buttonCancle
97
+            // 
98
+            this.buttonCancle.DialogResult = System.Windows.Forms.DialogResult.Cancel;
99
+            this.buttonCancle.Location = new System.Drawing.Point(92, 345);
100
+            this.buttonCancle.Name = "buttonCancle";
101
+            this.buttonCancle.Size = new System.Drawing.Size(75, 23);
102
+            this.buttonCancle.TabIndex = 3;
103
+            this.buttonCancle.Text = "取消";
104
+            this.buttonCancle.UseVisualStyleBackColor = true;
105
+            // 
106
+            // buttonOk
107
+            // 
108
+            this.buttonOk.Location = new System.Drawing.Point(255, 345);
109
+            this.buttonOk.Name = "buttonOk";
110
+            this.buttonOk.Size = new System.Drawing.Size(75, 23);
111
+            this.buttonOk.TabIndex = 3;
112
+            this.buttonOk.Text = "确定";
113
+            this.buttonOk.UseVisualStyleBackColor = true;
114
+            this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click);
115
+            // 
116
+            // textBox1
117
+            // 
118
+            this.textBox1.Location = new System.Drawing.Point(80, 419);
119
+            this.textBox1.Name = "textBox1";
120
+            this.textBox1.ReadOnly = true;
121
+            this.textBox1.Size = new System.Drawing.Size(264, 23);
122
+            this.textBox1.TabIndex = 4;
123
+            this.textBox1.Text = "下次连接生效";
124
+            this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
125
+            // 
126
+            // InitialBytesToStrip
127
+            // 
128
+            this.InitialBytesToStrip.Location = new System.Drawing.Point(210, 296);
129
+            this.InitialBytesToStrip.Name = "InitialBytesToStrip";
130
+            this.InitialBytesToStrip.Size = new System.Drawing.Size(120, 23);
131
+            this.InitialBytesToStrip.TabIndex = 6;
132
+            // 
133
+            // label4
134
+            // 
135
+            this.label4.AutoSize = true;
136
+            this.label4.Location = new System.Drawing.Point(89, 302);
137
+            this.label4.Name = "label4";
138
+            this.label4.Size = new System.Drawing.Size(112, 17);
139
+            this.label4.TabIndex = 5;
140
+            this.label4.Text = "InitialBytesToStrip";
141
+            // 
142
+            // TcpPkgConfigDialog
143
+            // 
144
+            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
145
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
146
+            this.CancelButton = this.buttonCancle;
147
+            this.ClientSize = new System.Drawing.Size(445, 518);
148
+            this.Controls.Add(this.InitialBytesToStrip);
149
+            this.Controls.Add(this.label4);
150
+            this.Controls.Add(this.textBox1);
151
+            this.Controls.Add(this.buttonOk);
152
+            this.Controls.Add(this.buttonCancle);
153
+            this.Controls.Add(this.LengthAdjustment);
154
+            this.Controls.Add(this.LengthFieldLength);
155
+            this.Controls.Add(this.LengthFieldOffset);
156
+            this.Controls.Add(this.label3);
157
+            this.Controls.Add(this.label2);
158
+            this.Controls.Add(this.label1);
159
+            this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
160
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
161
+            this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
162
+            this.MaximizeBox = false;
163
+            this.MinimizeBox = false;
164
+            this.Name = "TcpPkgConfigDialog";
165
+            this.ShowIcon = false;
166
+            this.ShowInTaskbar = false;
167
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
168
+            this.Text = "半包-粘包";
169
+            this.Load += new System.EventHandler(this.TcpPkgConfigDialog_Load);
170
+            ((System.ComponentModel.ISupportInitialize)(this.LengthFieldOffset)).EndInit();
171
+            ((System.ComponentModel.ISupportInitialize)(this.LengthFieldLength)).EndInit();
172
+            ((System.ComponentModel.ISupportInitialize)(this.LengthAdjustment)).EndInit();
173
+            ((System.ComponentModel.ISupportInitialize)(this.InitialBytesToStrip)).EndInit();
174
+            this.ResumeLayout(false);
175
+            this.PerformLayout();
176
+
177
+        }
178
+
179
+        #endregion
180
+
181
+        private System.Windows.Forms.Label label1;
182
+        private System.Windows.Forms.Label label2;
183
+        private System.Windows.Forms.Label label3;
184
+        private System.Windows.Forms.NumericUpDown LengthFieldOffset;
185
+        private System.Windows.Forms.NumericUpDown LengthFieldLength;
186
+        private System.Windows.Forms.NumericUpDown LengthAdjustment;
187
+        private System.Windows.Forms.Button buttonCancle;
188
+        private System.Windows.Forms.Button buttonOk;
189
+        private System.Windows.Forms.TextBox textBox1;
190
+        private System.Windows.Forms.NumericUpDown InitialBytesToStrip;
191
+        private System.Windows.Forms.Label label4;
192
+    }
193
+}

+ 39 - 0
DotNettyFrom/dialog/TcpPkgConfigDialog.cs Zobrazit soubor

@@ -0,0 +1,39 @@
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
+using DotNettyFrom.config;
11
+
12
+namespace DotNettyFrom.dialog
13
+{
14
+    public partial class TcpPkgConfigDialog : Form
15
+    {
16
+        public TcpPkgConfigDialog()
17
+        {
18
+            InitializeComponent();
19
+        }
20
+
21
+        private void TcpPkgConfigDialog_Load(object sender, EventArgs e)
22
+        {
23
+            LengthFieldOffset.Value = SystemConfig.LengthFieldOffset;
24
+            LengthFieldLength.Value = SystemConfig.LengthFieldLength;
25
+            LengthAdjustment.Value = SystemConfig.LengthAdjustment;
26
+            InitialBytesToStrip.Value = SystemConfig.InitialBytesToStrip;
27
+        }
28
+
29
+        private void buttonOk_Click(object sender, EventArgs e)
30
+        {
31
+            SystemConfig.LengthFieldOffset = (int) LengthFieldOffset.Value;
32
+            SystemConfig.LengthFieldLength = (int) LengthFieldLength.Value;
33
+            SystemConfig.LengthAdjustment = (int) LengthAdjustment.Value;
34
+            SystemConfig.InitialBytesToStrip = (int) InitialBytesToStrip.Value;
35
+
36
+            this.Close();
37
+        }
38
+    }
39
+}

+ 120 - 0
DotNettyFrom/dialog/TcpPkgConfigDialog.resx Zobrazit soubor

@@ -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>

+ 5 - 33
DotNettyFrom/generatecmd/CmdGenetor.cs Zobrazit soubor

@@ -8,41 +8,13 @@ using DotNettyFrom.util;
8 8
 
9 9
 namespace DotNettyFrom.generatecmd
10 10
 {
11
-    public class CmdGenetor
11
+    public abstract class CmdGenetor
12 12
     {
13
-        public static CmdGenetor Instance = new CmdGenetor();
14
-        public string DeviceId { get; set; }
13
+        public string DeviceId;
14
+        public static CmdGenetor Genetor { get; set; }
15 15
 
16
+        public abstract string GetLoginCmd(string ccid);
16 17
 
17
-        public static CmdGenetor GetInstance()
18
-        {
19
-            return Instance;
20
-        }
21
-
22
-        public CmdGenetor SetDeviceId(string deviceId)
23
-        {
24
-            this.DeviceId = deviceId;
25
-            return this;
26
-        }
27
-
28
-        private CmdGenetor()
29
-        {
30
-        }
31
-
32
-
33
-        public string GetLoginCmd(string ccid)
34
-        {
35
-            string cmd = DeviceId + "820014" + ccid;
36
-            cmd = "7e7e7e" + CmdUtil.CalcCrcCode(cmd);
37
-            return cmd;
38
-        }
39
-
40
-        public string GetHeartbeat()
41
-        {
42
-            //7e7e7e00000000000184000085
43
-            string cmd = DeviceId + "840000";
44
-            cmd = "7e7e7e" + CmdUtil.CalcCrcCode(cmd);
45
-            return cmd;
46
-        }
18
+        public abstract string GetHeartbeat();
47 19
     }
48 20
 }

+ 28 - 0
DotNettyFrom/generatecmd/DtuCmdGenetor.cs Zobrazit soubor

@@ -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
+using DotNettyFrom.generatecmd;
7
+using DotNettyFrom.util;
8
+
9
+namespace DotNettyFrom.generatecmd
10
+{
11
+    public class DtuCmdGenetor : CmdGenetor
12
+    {
13
+        public override string GetLoginCmd( string ccid)
14
+        {
15
+            string cmd = DeviceId + "820014" + ccid;
16
+            cmd = "7e7e7e" + CmdUtil.CalcCrcCode(cmd);
17
+            return cmd;
18
+        }
19
+
20
+        public override string GetHeartbeat()
21
+        {
22
+            //7e7e7e00000000000184000085
23
+            string cmd = DeviceId + "840000";
24
+            cmd = "7e7e7e" + CmdUtil.CalcCrcCode(cmd);
25
+            return cmd;
26
+        }
27
+    }
28
+}

+ 21 - 0
DotNettyFrom/generatecmd/Water2CmdGenetor.cs Zobrazit soubor

@@ -0,0 +1,21 @@
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.generatecmd
8
+{
9
+    public class Water2CmdGenetor : CmdGenetor
10
+    {
11
+        public override string GetLoginCmd( string ccid)
12
+        {
13
+            throw new NotImplementedException();
14
+        }
15
+
16
+        public override string GetHeartbeat()
17
+        {
18
+            throw new NotImplementedException();
19
+        }
20
+    }
21
+}

+ 17 - 13
DotNettyFrom/netty/NettyClient.cs Zobrazit soubor

@@ -76,6 +76,7 @@ namespace DotNettyFrom.netty
76 76
             if (NettyClientHandler.Context.Channel.Active)
77 77
             {
78 78
                 IByteBuffer msg = AryUtil.Hex2IByteBuffer(hex);
79
+                Console.WriteLine(hex);
79 80
                 NettyClientHandler.Context.WriteAndFlushAsync(msg);
80 81
                 DataModel.ReceCollection.Add(new UIInfoModel("发送", hex).setSendType(SystemConfig.SendType));
81 82
             }
@@ -134,20 +135,23 @@ namespace DotNettyFrom.netty
134 135
 
135 136
             public override void UserEventTriggered(IChannelHandlerContext context, object evt)
136 137
             {
137
-                IdleStateEvent state = (IdleStateEvent) evt;
138
-
139
-
140
-                if (state == IdleStateEvent.ReaderIdleStateEvent)
141
-                {
142
-                }
143
-                else if (state == IdleStateEvent.WriterIdleStateEvent)
144
-                {
145
-                    string hb = CmdGenetor.GetInstance().GetHeartbeat();
146
-                    context.Channel.WriteAndFlushAsync(AryUtil.Hex2IByteBuffer(hb));
147
-                    DataModel.ReceCollection.Add(new UIInfoModel("发送", hb).setSendType(SystemConfig.SendType));
148
-                }
149
-                else
138
+                if (SystemConfig.OpenHeartBeat)
150 139
                 {
140
+                    IdleStateEvent state = (IdleStateEvent) evt;
141
+
142
+
143
+                    if (state == IdleStateEvent.ReaderIdleStateEvent)
144
+                    {
145
+                    }
146
+                    else if (state == IdleStateEvent.WriterIdleStateEvent)
147
+                    {
148
+                        string hb = CmdGenetor.Genetor.GetHeartbeat();
149
+                        context.Channel.WriteAndFlushAsync(AryUtil.Hex2IByteBuffer(hb));
150
+                        DataModel.ReceCollection.Add(new UIInfoModel("发送", hb).setSendType(SystemConfig.SendType));
151
+                    }
152
+                    else
153
+                    {
154
+                    }
151 155
                 }
152 156
             }
153 157