Project

General

Profile

Feature #3175 » modbus_tcpex.cpp

yufeng wu, 10/27/2023 11:48 AM

 
1
#include "modbus_tcpc_ex.h"
2
#include "se_btl.h"
3
#include "se_log.h"
4
#include <sstream>
5
#include <vector>
6
#include <fstream>
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include<math.h>
10
#include <time.h>
11
#include "stdtostring.h"
12

    
13
#ifdef _DEBUG
14
#undef THIS_FILE
15
static char THIS_FILE[] = __FILE__;
16
#define new DEBUG_NEW
17
#endif
18

    
19

    
20

    
21
using namespace std;
22

    
23
CModbusTcpc::~CModbusTcpc() {
24

    
25
}
26

    
27
CModbusTcpc::CModbusTcpc() {
28

    
29
}
30

    
31
void CModbusTcpc::Init(S_PROTOCOLCFG* pcfg) {
32
	PRawCtrl = pcfg->PRawCtrl;
33
	pRxBuf = pcfg->pRxBuf;
34
	pTxBuf = pcfg->pTxBuf;
35
	pCmdMem = pcfg->pCmdMem;
36
	pRtu = pcfg->pRtu;
37
	pLink = pcfg->pLink;
38
	pTable = pcfg->pTable;
39
	pZfDataCtrl = pcfg->pZfDataCtrl;
40
	//pHis		=	pcfg->pHis;
41

    
42
	mapnum = 0;
43
	mapIndex = 0;
44
	Policy = 0;
45
	WillSendType = 0;
46
	cnt_sequence = 0;
47
	m_LastSendTime = 0;
48
	m_RcvTimeOuts = pLink->GetRxTimeouts();
49
	if (m_RcvTimeOuts <= 0)	m_RcvTimeOuts = 10;
50

    
51
	//em_daq.exe?????????? ??ʱ????,???????ñ???ȡ???????ͺ? ljk20221026	
52
	sleeptime = pLink->GetAllDataScanInterval();
53
	readcfgflag = 0;
54
	
55
	sint32 rtuno = pLink->GetRtuNo();
56
	//	m_SyncTime = pRtu->GetSyncTimeInt(rtuno)*60;
57
	m_SyncTime = pRtu->GetSyncTimeInt(rtuno);
58
	duquIndex = 0;
59
	visitednum = 0;
60
	cmdlength = 0;
61
	err = false;
62

    
63
	sleepstarttime = GetNowMilliSecond();
64
	PrintLog(1, "??Լ??ʼ????ɣ?");
65
}
66

    
67
void CModbusTcpc::ReadCfg()
68
{
69
	char* pathvar;
70
	pathvar = getenv(SE_EMS_RUN_DIR);
71
	if (pathvar == NULL){
72
		PrintLog(LOG_ERROR, "δ?ҵ?????????");
73
		err = true;
74
		return;
75
	}
76

    
77
	std::string route;
78
	route.append(pathvar);
79
	std::string str = to_string(pLink->GetRtuNo());
80
	route.append("/cfg/modbus_tcpex_rtu");
81
	route.append(str);
82
	route.append(".csv");
83

    
84
	std::string AI = "AI";
85
	std::string DI = "DI";
86
	std::string m_PI = "PI";
87
	std::string AO = "AO";
88
	std::string DO = "DO";
89
	std::string VA = "VA";
90

    
91
	std::string int32 = "int32";
92
	std::string int16 = "int16";
93
	std::string float32 = "float";
94
	std::string uint32 = "uint32";
95
	std::string uint16 = "uint16";
96
	std::string rv_int16 = "rv_int16";
97
	std::string rv_float = "rv_float";
98
	std::string rv_uint16 = "rv_uint16";
99
	std::string sw_int32 = "sw_int32";
100
	std::string sw_uint32 = "sw_uint32";
101
	std::string sw_float = "sw_float";
102
	std::string rv_int32 = "rv_int32";
103
	std::string rv_uint32 = "rv_uint32";
104
	std::string rv_sw_int32 = "sw_rv_int32";
105
	std::string rv_sw_uint32 = "sw_rv_uint32";
106
	std::string rv_sw_float = "sw_rv_float";
107
	std::string rv_bit = "rv_bit";
108
	std::string bit = "bit";
109

    
110
	duqulength = 0;
111
	maplength = 0;
112
	cmdlength = 0;
113

    
114
	ifstream inf;
115
	inf.open(route.c_str(), ios::in);
116
	if (!inf.is_open()){
117
		PrintLog(LOG_ERROR, "δ?ɹ????????ļ?");
118
		err = true;
119
		return;
120
	}
121

    
122

    
123
	std::string lineStr;
124
	vector<vector<std::string> > strArray;   //???????ļ??????άstrArray
125
	while (getline(inf, lineStr)) {
126
		stringstream ss(lineStr);
127
		std::string str;
128
		vector<std::string> lineArray;
129
		while (getline(ss, str, ',')) {
130
			lineArray.push_back(str);
131
		}
132
		strArray.push_back(lineArray);
133
	}
134
	maplist = new map[strArray.size()];     //?????????ļ???????????ΪDI??AI??PI??VA???? ?ṹ???????ݰ???????ַ???ɼ???š????͡?ֵ???͡????ݽṹ?塢??ʼλ?á?????λ?á??Ƿ???ʹ???־??
135
	cmdlist = new cmd[strArray.size()];     //?????????ļ???????????ΪDO??AO???? ?ṹ???????ݰ???????ַ???ɼ???š????͡?ֵ???͡???š??????롢??ʼλ?á?????λ?á???????Ϊ16??6??????ΪDO?ı?־??
136
	duqu = new sint32 *[strArray.size()];   //?????????ļ???ÿ???һ?? ע??ÿ???һ???й??ܺź?ʱ????  ????????Ϊ????ַ???Ĵ???????????Ҫ???㣩????š??????롢ʱ??????
137
	int i;
138
	for (i = 0; i < strArray.size(); i++)
139
		duqu[i] = new sint32[5];
140

    
141

    
142
	duqu[duqulength][0] = atoi(strArray[1][0].c_str()) - 1;
143
	duqu[duqulength][1] = 1;
144
	duqu[duqulength][2] = atoi(strArray[1][6].c_str());
145
	duqu[duqulength][3] = atoi(strArray[1][7].c_str());
146
	duqu[duqulength][4] = atoi(strArray[1][8].c_str());
147

    
148
	maplist[maplength].address = atoi(strArray[1][0].c_str()) - 1;
149
	if (strArray[1][4].c_str() == DI) {
150
		maplist[maplength].r_type = 1;
151
		if (strArray[1][5].c_str() == bit){
152
			maplist[maplength].m_type = 1;
153
		}
154
		if (strArray[1][5].c_str() == rv_bit){
155
			maplist[maplength].m_type = 2;
156
		}
157
	}
158
	if (strArray[1][4].c_str() == AI){
159
		if (strArray[1][5].c_str() == int16){
160
			maplist[maplength].r_type = 2;
161
			maplist[maplength].m_type = 3;
162
		}
163
		if (strArray[1][5].c_str() == uint16){
164
			maplist[maplength].r_type = 1;
165
			maplist[maplength].m_type = 3;
166
		}
167
		if (strArray[1][5].c_str() == rv_int16){
168
			maplist[maplength].r_type = 2;
169
			maplist[maplength].m_type = 4;
170
		}
171
		if (strArray[1][5].c_str() == rv_uint16){
172
			maplist[maplength].r_type = 1;
173
			maplist[maplength].m_type = 4;
174
		}
175
		if (strArray[1][5].c_str() == int32){
176
			maplist[maplength].r_type = 4;
177
			maplist[maplength].m_type = 5;
178
		}
179
		if (strArray[1][5].c_str() == uint32){
180
			maplist[maplength].r_type = 5;
181
			maplist[maplength].m_type = 5;
182
		}
183
		if (strArray[1][5].c_str() == sw_int32){
184
			maplist[maplength].r_type = 4;
185
			maplist[maplength].m_type = 6;
186
		}
187
		if (strArray[1][5].c_str() == sw_uint32){
188
			maplist[maplength].r_type = 5;
189
			maplist[maplength].m_type = 6;
190
		}
191
		if (strArray[1][5].c_str() == rv_int32){
192
			maplist[maplength].r_type = 4;
193
			maplist[maplength].m_type = 7;
194
		}
195
		if (strArray[1][5].c_str() == rv_uint32){
196
			maplist[maplength].r_type = 5;
197
			maplist[maplength].m_type = 7;
198
		}
199
		if (strArray[1][5].c_str() == rv_sw_int32){
200
			maplist[maplength].r_type = 4;
201
			maplist[maplength].m_type = 8;
202
		}
203
		if (strArray[1][5].c_str() == rv_sw_uint32){
204
			maplist[maplength].r_type = 5;
205
			maplist[maplength].m_type = 8;
206
		}
207
		if (strArray[1][5].c_str() == float32){
208
			maplist[maplength].r_type = 3;
209
			maplist[maplength].m_type = 5;
210
		}
211
		if (strArray[1][5].c_str() == sw_float){
212
			maplist[maplength].r_type = 3;
213
			maplist[maplength].m_type = 6;
214
		}
215
		if (strArray[1][5].c_str() == rv_float){
216
			maplist[maplength].r_type = 3;
217
			maplist[maplength].m_type = 7;
218
		}
219
		if (strArray[1][5].c_str() == rv_sw_float){
220
			maplist[maplength].r_type = 3;
221
			maplist[maplength].m_type = 8;
222
		}
223
	}
224
	if (strArray[1][4].c_str() == m_PI) {
225
		maplist[maplength].m_type = 9;
226
		if (strArray[1][5].c_str() == uint16)
227
			maplist[maplength].r_type = 1;
228
		if (strArray[1][5].c_str() == int16)
229
			maplist[maplength].r_type = 2;
230
		if (strArray[1][5].c_str() == float32)
231
			maplist[maplength].r_type = 3;
232
		if (strArray[1][5].c_str() == int32)
233
			maplist[maplength].r_type = 4;
234
		if (strArray[1][5].c_str() == uint32)
235
			maplist[maplength].r_type = 5;
236
	}
237
	if (strArray[1][4].c_str() == VA) {
238
		maplist[maplength].m_type = 0;
239
		maplist[maplength].r_type = 1;
240
	}
241
	maplist[maplength].pointnum = atoi(strArray[1][1].c_str());
242
	maplist[maplength].start = atoi(strArray[1][2].c_str());
243
	maplist[maplength].end = atoi(strArray[1][3].c_str());
244
	maplength++;
245
	for (i = 2; i < strArray.size(); i++) {
246
		if (i >= strArray.size() || i < 0) {
247
			break;
248
		}
249
		if (strArray[i][4].c_str() == AO || strArray[i][4].c_str() == DO)
250
		{
251
			if (cmdlength != 0 && atoi(strArray[i][6].c_str()) == cmdlist[cmdlength - 1].group)
252
			{
253
				cmdlist[cmdlength].address = atoi(strArray[i][0].c_str()) - 1;
254
				cmdlist[cmdlength].group = atoi(strArray[i][6].c_str());
255
				cmdlist[cmdlength].pointnum = atoi(strArray[i][1].c_str());
256
				cmdlist[cmdlength].m_type = cmdlist[cmdlength - 1].m_type;
257
				cmdlist[cmdlength].func = cmdlist[cmdlength - 1].func;
258
				if (strArray[i][5].c_str() == int16){
259
					cmdlist[cmdlength].r_type = 2;
260
				}
261
				if (strArray[i][5].c_str() == uint16){
262
					cmdlist[cmdlength].r_type = 1;
263
				}
264
				if (strArray[i][5].c_str() == bit){
265
					cmdlist[cmdlength].r_type = 3;
266
				}
267
				if ((cmdlist[cmdlength].func == 6 || cmdlist[cmdlength].func == 16) && strArray[i][4].c_str() == DO){
268
					cmdlist[cmdlength].va = 1;
269
					cmdlist[cmdlength].start = atoi(strArray[i][2].c_str());
270
					cmdlist[cmdlength].end = atoi(strArray[i][3].c_str());
271
				}
272
			}
273
			else {
274
				cmdlist[cmdlength].address = atoi(strArray[i][0].c_str()) - 1;
275
				cmdlist[cmdlength].group = atoi(strArray[i][6].c_str());
276
				cmdlist[cmdlength].func = atoi(strArray[i][7].c_str());
277
				cmdlist[cmdlength].pointnum = atoi(strArray[i][1].c_str());
278
				if (atoi(strArray[i][7].c_str()) == 5 || atoi(strArray[i][7].c_str()) == 15) {
279
					cmdlist[cmdlength].m_type = 1;
280
				}
281
				else if (atoi(strArray[i][7].c_str()) == 6 || atoi(strArray[i][7].c_str()) == 16) {
282
					cmdlist[cmdlength].m_type = 2;
283
				}
284
				if (strArray[i][5].c_str() == bit){
285
					cmdlist[cmdlength].r_type = 3;
286
				}
287
				if (strArray[i][5].c_str() == int16){
288
					cmdlist[cmdlength].r_type = 2;
289
				}
290
				if (strArray[i][5].c_str() == uint16){
291
					cmdlist[cmdlength].r_type = 1;
292
				}
293
				if ((cmdlist[cmdlength].func == 6 || cmdlist[cmdlength].func == 16) && strArray[i][4].c_str() == DO){
294
					cmdlist[cmdlength].va = 1;
295
					cmdlist[cmdlength].start = atoi(strArray[i][2].c_str());
296
					cmdlist[cmdlength].end = atoi(strArray[i][3].c_str());
297
				}
298
			}
299

    
300
			cmdlength++;
301
			continue;
302
		}
303

    
304
		maplist[maplength].address = atoi(strArray[i][0].c_str()) - 1;
305
		if (strArray[i][4].c_str() == DI) {
306
			maplist[maplength].r_type = 1;
307
			if (strArray[i][5].c_str() == bit){
308
				maplist[maplength].m_type = 1;
309
			}
310
			if (strArray[i][5].c_str() == rv_bit){
311
				maplist[maplength].m_type = 2;
312
			}
313
		}
314
		if (strArray[i][4].c_str() == AI){
315
			if (strArray[i][5].c_str() == int16){
316
				maplist[maplength].r_type = 2;
317
				maplist[maplength].m_type = 3;
318
			}
319
			if (strArray[i][5].c_str() == uint16){
320
				maplist[maplength].r_type = 1;
321
				maplist[maplength].m_type = 3;
322
			}
323
			if (strArray[i][5].c_str() == rv_int16){
324
				maplist[maplength].r_type = 2;
325
				maplist[maplength].m_type = 4;
326
			}
327
			if (strArray[i][5].c_str() == rv_uint16){
328
				maplist[maplength].r_type = 1;
329
				maplist[maplength].m_type = 4;
330
			}
331
			if (strArray[i][5].c_str() == int32){
332
				maplist[maplength].r_type = 4;
333
				maplist[maplength].m_type = 5;
334
			}
335
			if (strArray[i][5].c_str() == uint32){
336
				maplist[maplength].r_type = 5;
337
				maplist[maplength].m_type = 5;
338
			}
339
			if (strArray[i][5].c_str() == sw_int32){
340
				maplist[maplength].r_type = 4;
341
				maplist[maplength].m_type = 6;
342
			}
343
			if (strArray[i][5].c_str() == sw_uint32){
344
				maplist[maplength].r_type = 5;
345
				maplist[maplength].m_type = 6;
346
			}
347
			if (strArray[i][5].c_str() == rv_int32){
348
				maplist[maplength].r_type = 4;
349
				maplist[maplength].m_type = 7;
350
			}
351
			if (strArray[i][5].c_str() == rv_uint32){
352
				maplist[maplength].r_type = 5;
353
				maplist[maplength].m_type = 7;
354
			}
355
			if (strArray[i][5].c_str() == rv_sw_int32){
356
				maplist[maplength].r_type = 4;
357
				maplist[maplength].m_type = 8;
358
			}
359
			if (strArray[i][5].c_str() == rv_sw_uint32){
360
				maplist[maplength].r_type = 5;
361
				maplist[maplength].m_type = 8;
362
			}
363
			if (strArray[i][5].c_str() == float32){
364
				maplist[maplength].r_type = 3;
365
				maplist[maplength].m_type = 5;
366
			}
367
			if (strArray[i][5].c_str() == sw_float){
368
				maplist[maplength].r_type = 3;
369
				maplist[maplength].m_type = 6;
370
			}
371
			if (strArray[i][5].c_str() == rv_float){
372
				maplist[maplength].r_type = 3;
373
				maplist[maplength].m_type = 7;
374
			}
375
			if (strArray[i][5].c_str() == rv_sw_float){
376
				maplist[maplength].r_type = 3;
377
				maplist[maplength].m_type = 8;
378
			}
379
		}
380
		if (strArray[i][4].c_str() == m_PI) {
381
			maplist[maplength].m_type = 9;
382
			if (strArray[i][5].c_str() == uint16)
383
				maplist[maplength].r_type = 1;
384
			if (strArray[i][5].c_str() == int16)
385
				maplist[maplength].r_type = 2;
386
			if (strArray[i][5].c_str() == float32)
387
				maplist[maplength].r_type = 3;
388
			if (strArray[i][5].c_str() == int32)
389
				maplist[maplength].r_type = 4;
390
			if (strArray[i][5].c_str() == uint32)
391
				maplist[maplength].r_type = 5;
392
		}
393
		if (strArray[i][4].c_str() == VA) {
394
			maplist[maplength].m_type = 0;
395
			maplist[maplength].r_type = 1;
396
		}
397
		maplist[maplength].pointnum = atoi(strArray[i][1].c_str());
398
		maplist[maplength].start = atoi(strArray[i][2].c_str());
399
		maplist[maplength].end = atoi(strArray[i][3].c_str());
400
		if (atoi(strArray[i][6].c_str()) != duqu[duqulength][2]) {
401
			duqulength++;
402
			duqu[duqulength][0] = atoi(strArray[i][0].c_str()) - 1;
403
			duqu[duqulength][1] = 1;
404
			duqu[duqulength][2] = atoi(strArray[i][6].c_str());
405
			duqu[duqulength][3] = atoi(strArray[i][7].c_str());
406
			duqu[duqulength][4] = atoi(strArray[i][8].c_str());
407
			if (i < strArray.size() - 1) {
408
				if (atoi(strArray[i + 1][6].c_str()) != duqu[duqulength][2] && maplist[maplength].end > 15 && (duqu[duqulength][3] == 3 || duqu[duqulength][3] == 4)) {
409
					duqu[duqulength][1] += maplist[maplength].end / 16;
410
				}
411
				if (atoi(strArray[i + 1][6].c_str()) != duqu[duqulength][2] && maplist[maplength].end > 0 && (duqu[duqulength][3] == 1 || duqu[duqulength][3] == 2)) {
412
					duqu[duqulength][1] += maplist[maplength].end;
413
				}
414
			}
415
			else {
416
				if (maplist[maplength].end > 15 && duqu[duqulength][3] == 3) {
417
					duqu[duqulength][1] += maplist[maplength].end / 16;
418
				}
419
				if (maplist[maplength].end > 0 && duqu[duqulength][3] == 1) {
420
					duqu[duqulength][1] += maplist[maplength].end;
421
				}
422
			}
423
		}
424
		else {
425
			duqu[duqulength][1] += atoi(strArray[i][0].c_str()) - atoi(strArray[i - 1][0].c_str());
426
			if (i < strArray.size() - 1) {
427
				if (atoi(strArray[i + 1][6].c_str()) != duqu[duqulength][2] && maplist[maplength].end > 15 && (duqu[duqulength][3] == 3 || duqu[duqulength][3] == 4)) {
428
					duqu[duqulength][1] += maplist[maplength].end / 16;
429
				}
430
				if (atoi(strArray[i + 1][6].c_str()) != duqu[duqulength][2] && maplist[maplength].end > 0 && (duqu[duqulength][3] == 1 || duqu[duqulength][3] == 2)) {
431
					duqu[duqulength][1] += maplist[maplength].end;
432
				}
433
			}
434
			else {
435
				if (maplist[maplength].end > 15 && (duqu[duqulength][3] == 3 || duqu[duqulength][3] == 4)) {
436
					duqu[duqulength][1] += maplist[maplength].end / 16;
437
				}
438
				if (maplist[maplength].end > 0 && (duqu[duqulength][3] == 1 || duqu[duqulength][3] == 2)) {
439
					duqu[duqulength][1] += maplist[maplength].end;
440
				}
441
			}
442
		}
443
		maplength++;
444
	}
445
	GetWillSendType();
446
}
447

    
448

    
449

    
450
void CModbusTcpc::GetWillSendType()   //???????????ж?
451
{
452

    
453
	if (visitednum >= duqu[duquIndex][1])  //??ȡ??λ?ô??ڵ?????ļĴ??????? ??¼??????Ƿ????
454
	{
455
		duquIndex++;
456
		if (duquIndex > duqulength) {
457
			duquIndex = 0;
458
			visitednum = 0;
459
			IndexDI = 0;
460
			IndexAI = 0;
461
			for (int i = 0; i < maplength; i++) {
462
				maplist[i].visited = 0;
463
			}
464
			mapnum = 0;
465
			mapIndex = 0;
466
			Policy = 1;
467
		}
468
		visitednum = 0;
469
		m_SyncTime = duqu[duquIndex][4];        //ʱ????
470
		if (duqu[duquIndex][3] == 1) 
471
		{
472
			IndexDI = duqu[duquIndex][0];      //??ǰ??ȡ????DI??λ????Ϊÿ?鿪ʼʱ?ĵ?ַ
473
			scopeDI = duqu[duquIndex][1] + duqu[duquIndex][0];  //ÿһ?ζ?ȡ???? ??ʼ??ַ+ÿ??Ĵ???????
474
			WillSendType = 1;
475
		}
476
		if (duqu[duquIndex][3] == 2) {
477
			IndexDI = duqu[duquIndex][0];
478
			scopeDI = duqu[duquIndex][1] + duqu[duquIndex][0];
479
			WillSendType = 2;
480
		}
481
		if (duqu[duquIndex][3] == 3) {
482
			IndexAI = duqu[duquIndex][0];
483
			scopeAI = duqu[duquIndex][1] + duqu[duquIndex][0];
484
			WillSendType = 3;
485
		}
486
		if (duqu[duquIndex][3] == 4) {
487
			IndexAI = duqu[duquIndex][0];
488
			scopeAI = duqu[duquIndex][1] + duqu[duquIndex][0];
489
			WillSendType = 4;
490
		}
491
	}
492
	else {
493
		visitednum = 0;
494
		m_SyncTime = duqu[duquIndex][4];
495
		if (duqu[duquIndex][3] == 1) {
496
			IndexDI = duqu[duquIndex][0];
497
			scopeDI = duqu[duquIndex][1] + duqu[duquIndex][0];
498
			WillSendType = 1;
499
		}
500
		if (duqu[duquIndex][3] == 2) {
501
			IndexDI = duqu[duquIndex][0];
502
			scopeDI = duqu[duquIndex][1] + duqu[duquIndex][0];
503
			WillSendType = 2;
504
		}
505
		if (duqu[duquIndex][3] == 3) {
506
			IndexAI = duqu[duquIndex][0];
507
			scopeAI = duqu[duquIndex][1] + duqu[duquIndex][0];
508
			WillSendType = 3;
509
		}
510
		if (duqu[duquIndex][3] == 4) {
511
			IndexAI = duqu[duquIndex][0];
512
			scopeAI = duqu[duquIndex][1] + duqu[duquIndex][0];
513
			WillSendType = 4;
514
		}
515
	}
516

    
517
}
518

    
519

    
520
uint8	CModbusTcpc::Operate_16(uint16 Address, uint16 num, uint16 pValue, uint8 func)
521
{
522
	if (num > 125)//??????0ֵ || pValue == NULL)
523
	{
524
		PrintLog(LOG_ERROR, ">>>>>> Wrong Func_16 parameter");
525
		return 0;
526
	}
527
	uint8 txbuff[256];
528
	sint32 rtuno = pLink->GetRtuNo();
529
	uint8 rtuadd = pRtu->GetRtuAddr(rtuno);
530
	uint8 len = 0;
531

    
532
	if (cnt_sequence >= 65535)
533
		cnt_sequence = 0;
534
	else
535
		cnt_sequence++;
536

    
537
	txbuff[len++] = cnt_sequence / 0x100;//H Transaction Identifier
538
	txbuff[len++] = cnt_sequence % 0x100;//L
539
	txbuff[len++] = 0;//Protocol Identifier "0 = MODBUS protocol"
540
	txbuff[len++] = 0;
541
	txbuff[len++] = 0;//len_H
542
	
543
	if (func == 15) 
544
	{
545
		txbuff[len++] = num + 7;//len_L
546
		txbuff[len++] = rtuadd;//Unit Identifier
547
		txbuff[len++] = 0x0F;
548
		txbuff[len++] = Address / 0x100;//??
549
		txbuff[len++] = Address % 0x100;//??
550
		txbuff[len++] = num / 0x100;
551
		txbuff[len++] = num % 0x100;
552
		txbuff[len++] = num;                     //????Լֻʹ??15??16????????ǿ??һλ??Ȧ?ͼĴ???????????05,06???? ????ʡ????ѭ?? ??Ȧ???ֽ?????ת??
553
		//uint8 i = 0;
554
		//for (i = 0; i < num; i++)
555
		//{
556
		txbuff[len++] = pValue;
557
		//}
558
	}
559

    
560
	if (func == 16) 
561
	{
562
		txbuff[len++] = num * 2 + 7;//len_L
563
		txbuff[len++] = rtuadd;//Unit Identifier
564
		txbuff[len++] = 0x10;
565
		txbuff[len++] = Address / 0x100;//??
566
		txbuff[len++] = Address % 0x100;//??
567
		txbuff[len++] = num / 0x100;
568
		txbuff[len++] = num % 0x100;
569
		txbuff[len++] = num * 2;
570
		//uint8 i = 0;
571
		//for (i = 0; i < num; i++)
572
		//{
573
		txbuff[len++] = pValue / 0x100;//??
574
		txbuff[len++] = pValue % 0x100;//??
575
		//}
576
	}
577

    
578
	//	pLink->RegisterFrmCode(RAW_CODEDIR_DOWN,(char *)txbuff,len);
579
	pLink->RegisterFrm(FRAME_TX_SUC);
580
	pTxBuf->Write(txbuff, len);
581
	pLink->SetCommStatus(CMST_RX_CNT);
582
	m_LastSendTime = GetNowMilliSecond();
583

    
584
	PrintLog(LOG_INFORMATION, ">>>>>> SendType = 16 ,start=%d ,num=%d", Address, num);
585

    
586
	return len;
587
}
588

    
589

    
590

    
591
uint8	CModbusTcpc::Operate_16(uint16 Address, uint16 num, sint16 pValue, uint8 func)
592
{
593
	if (num > 125 )//??????0ֵ|| pValue == NULL)
594
	{
595
		PrintLog(LOG_ERROR, ">>>>>> Wrong Func_16 parameter");
596
		return 0;
597
	}
598
	uint8 txbuff[256];
599
	sint32 rtuno = pLink->GetRtuNo();
600
	uint8 rtuadd = pRtu->GetRtuAddr(rtuno);
601
	uint8 len = 0;
602
	if (cnt_sequence >= 65535)
603
		cnt_sequence = 0;
604
	else
605
		cnt_sequence++;
606

    
607
	txbuff[len++] = cnt_sequence / 0x100;//H Transaction Identifier
608
	txbuff[len++] = cnt_sequence % 0x100;//L
609
	txbuff[len++] = 0;//Protocol Identifier "0 = MODBUS protocol"
610
	txbuff[len++] = 0;
611
	txbuff[len++] = 0;//len_H
612

    
613
	if (func == 15) 
614
	{
615
		txbuff[len++] = num + 7;//len_L
616
		txbuff[len++] = rtuadd;//Unit Identifier
617
		txbuff[len++] = 0x0F;
618
		txbuff[len++] = Address / 0x100;//??
619
		txbuff[len++] = Address % 0x100;//??
620
		txbuff[len++] = num / 0x100;
621
		txbuff[len++] = num % 0x100;
622
		txbuff[len++] = num;
623
		//uint8 i = 0;
624
		//for (i = 0; i < num; i++)
625
		//{
626
		txbuff[len++] = pValue;
627
		//}
628
	}
629

    
630
	if (func == 16) 
631
	{
632
		txbuff[len++] = num * 2 + 7;//len_L
633
		txbuff[len++] = rtuadd;//Unit Identifier
634
		txbuff[len++] = 0x10;
635
		txbuff[len++] = Address / 0x100;//??
636
		txbuff[len++] = Address % 0x100;//??
637
		txbuff[len++] = num / 0x100;
638
		txbuff[len++] = num % 0x100;
639
		txbuff[len++] = num * 2;
640
		//uint8 i = 0;
641
		//for (i = 0; i < num; i++)
642
		//{
643
		txbuff[len++] = pValue / 0x100;//??
644
		txbuff[len++] = pValue % 0x100;//??
645
		//}
646
	}
647

    
648
	//	pLink->RegisterFrmCode(RAW_CODEDIR_DOWN,(char *)txbuff,len);
649
	pLink->RegisterFrm(FRAME_TX_SUC);
650
	pTxBuf->Write(txbuff, len);
651
	pLink->SetCommStatus(CMST_RX_CNT);
652
	m_LastSendTime = GetNowMilliSecond();
653

    
654
	PrintLog(LOG_INFORMATION, ">>>>>> SendType = 16 ,start=%d ,num=%d", Address, num);
655

    
656
	return len;
657
}
658

    
659

    
660

    
661
uint8 CModbusTcpc::ProcCmd()    //?¿? ???DO??AOʹ??05,06,15,16???? ʹ??cmdlist?ṹ??
662
{
663
	uint8 b_ret = FALSE;
664
	sint32 rtuno = pLink->GetRtuNo();
665
	uint8 rtuaddr = pRtu->GetRtuAddr(rtuno);
666

    
667
	if (pCmdMem->GetCmdNum(rtuno) <= 0)
668
		return FALSE;
669

    
670
	S_RAWCMD rawcmd;
671
	if (pCmdMem->GetACmd(rtuno, &rawcmd) == 0)
672
		return FALSE;
673

    
674
	PrintLog(LOG_INFORMATION, "?յ?%d???ն? rtuaddr:%d ????:%d", rtuno, rtuaddr, rawcmd.type);
675

    
676
	uint8 len = 0;
677
	m_cmdaddr = rawcmd.src;
678
	switch (rawcmd.type)
679
	{
680
		case DC_K_CMD_DOOPER: //ң??
681
		{
682
			S_DO_CTL* cmdinfo;
683
			cmdinfo = (S_DO_CTL*)(&rawcmd.data);
684
			uint16 ykno = (uint16)cmdinfo->ptAddr;//ң?غ?
685
			switch (cmdinfo->funcCode)
686
			{
687
				case DC_K_CTL_DOSEL://ѡ??
688
					//ֱ?ӷ?У
689
					rawcmd.type = DC_K_CMDRET_DOOPER;
690
					rawcmd.len = sizeof(cmdinfo);
691
					rawcmd.src = m_cmdaddr;
692
					cmdinfo->retCode = 1;
693

    
694
					pCmdMem->RptAResult(rtuno, rawcmd);
695
					break;
696

    
697
				case DC_K_CTL_DOEXE://ִ??
698
				{
699
					PrintLog(LOG_INFORMATION, "ִ??");
700
					for (int i = 0; i < cmdlength; i++) 
701
					{
702
						if (cmdlist[i].pointnum == ykno) 
703
						{
704
							//PrintLog(LOG_INFORMATION, "%d?ŵ? ??ַ:%d ???ܺţ?%d", cmdlist[i].pointnum, cmdlist[i].address, cmdlist[i].func);
705
							if (cmdlist[i].func == 15) 
706
							{
707
								Operate_16(cmdlist[i].address, 1, (uint16)cmdinfo->ctlVal, cmdlist[i].func);
708
								b_ret = TRUE;
709
								break;
710
							}
711
							if (cmdlist[i].func == 5) 
712
							{
713
								uint16 ykvalue;
714
								if (cmdinfo->ctlVal == 0) 
715
								{//??բ
716
									ykvalue = 0x0000;
717
								}
718
								else 
719
								{//if(cmdinfo->ctlVal==1){//??բ
720
									ykvalue = 0xff00;
721
								}
722

    
723
								if (ykno >= 1)
724
								{
725
									//WillSendType = 5;
726
									len = OperateRegister(5, cmdlist[i].address, ykvalue);
727
									b_ret = TRUE;
728
								}
729
								break;
730
							}
731
							if (cmdlist[i].func == 6||cmdlist[i].func == 16)   //֧??DOתAO16????Ϊ?¼ӵ????⹦?? ʹ??06???????һ???Ĵ?????ijһλDO?? ???Ƶ??ѱ???ȡΪuint ??AI?㣨?????ļ??????ã?
732
							{
733
								PrintLog(LOG_INFORMATION, "֡????%d?ŵ? ??ַ:%d ???ܺţ?%d", cmdlist[i].pointnum, cmdlist[i].address, cmdlist[i].func);
734
								PrintLog(LOG_INFORMATION, "ykno=%d va=%d ", ykno, cmdlist[i].va);
735

    
736
								if (ykno >= 1)
737
								{
738
									if (cmdlist[i].va == 1)    //va=1 ->??????Ϊ6??16????????ΪDO
739
									{
740
										uint16 yctmp = 0;
741
										uint16	ytVal = 1 << cmdlist[i].start;
742
										for (int index = maplength-1; index >= 0; index--)
743
										{
744
											if (maplist[index].address == cmdlist[i].address)
745
											{
746
												yctmp = maplist[index].data.datauint16;     //?ѱ???ȡΪAI?? ?????˼Ĵ?????ֵ uint16
747
												break;
748
											}
749
										}
750
										uint16	ycVal = (uint16)yctmp;
751

    
752
										uint16 ykvalue = cmdinfo->ctlVal;
753
										if (ykvalue == 0)
754
										{//??բ
755
											ycVal = ycVal & (~ytVal);    //ָ??λ??ǿ??Ϊ0
756
										}
757
										if (ykvalue == 1)
758
										{//??բ
759
											ycVal = ycVal | (ytVal);    //ָ??λ??ǿ??Ϊ1
760
										}
761
										PrintLog(LOG_INFORMATION, "????֡??%d?ŵ? ??ַ:%d ???ܺţ?%d?????ݣ?%d", cmdlist[i].pointnum, cmdlist[i].address, cmdlist[i].func, ycVal);
762
										//len = OperateRegister(6, cmdlist[i].address, (uint16)ycVal);
763
										if (cmdlist[i].func == 16) 
764
										{
765
											if (cmdlist[i].r_type == 1)
766
											{
767
												Operate_16(cmdlist[i].address, 1, (uint16)ycVal, cmdlist[i].func);
768
											}
769
											else
770
											{
771
												Operate_16(cmdlist[i].address, 1, (sint16)ycVal, cmdlist[i].func);
772
											}
773
										}
774
										else {
775
											if (cmdlist[i].func == 6) 
776
													len = OperateRegister(/*6*/cmdlist[i].func, cmdlist[i].address, (uint16)ycVal);
777
										}
778

    
779
									}
780
									else continue;
781
									//WillSendType = 6;
782

    
783
									b_ret = TRUE;
784
								}
785
								break;
786
							}
787
						}
788
					}
789
					PrintLog(LOG_WARNING, "<<<<< YK no=%d   val=%d", ykno, cmdinfo->ctlVal);
790
				}
791
				break;
792

    
793
				case DC_K_CTL_DODEL://????
794
				break;
795
			}
796
		}
797
		break;
798

    
799
		case DC_K_CMD_AOOPER:
800
		{
801
			S_AO_CTL* aoinfo;
802
			aoinfo = (S_AO_CTL*)(&rawcmd.data);
803
			switch (aoinfo->funcCode)
804
			{
805
				case DC_K_CTL_AOSEL://ѡ??
806
					//ֱ?ӷ?У
807
					rawcmd.type = DC_K_CMDRET_AOOPER;
808
					rawcmd.len = sizeof(aoinfo);
809
					rawcmd.src = m_cmdaddr;
810
					aoinfo->retCode = 1;
811
					pCmdMem->RptAResult(rtuno, rawcmd);
812
					break;
813

    
814
				case DC_K_CTL_AOEXE://ִ??
815
				{
816
					sint32 ytvalue = (sint32)(aoinfo->ptVal);
817
					uint16 ptno = aoinfo->ptAddr;
818
					for (int i = 0; i < cmdlength; i++) 
819
					{
820
						if (cmdlist[i].m_type == 1)
821
							continue;
822
						if (cmdlist[i].pointnum == ptno) 
823
						{
824
							if (cmdlist[i].func == 16) 
825
							{
826
								if (cmdlist[i].r_type == 1)
827
								{
828
									Operate_16(cmdlist[i].address, 1, (uint16)ytvalue, cmdlist[i].func);
829
								}
830
								else
831
								{
832
									Operate_16(cmdlist[i].address, 1, (sint16)ytvalue, cmdlist[i].func);
833
								}
834
								b_ret = TRUE;
835
								break;
836
							}
837
							if (cmdlist[i].func == 6) 
838
							{
839
								if (ptno >= 1)
840
								{
841
									if (cmdlist[i].va == 1)   //???????ΪDO
842
									{
843
										continue;
844
										float32 yctmp = 0;
845
										uint16	ytVal = 1 << cmdlist[i].start;
846
										PRawCtrl->GetAYc(rtuno, cmdlist[i].pointnum, &yctmp);
847
										uint16	ycVal = (uint16)yctmp;
848
										uint16 ykvalue;
849
										if (ytvalue == 0)
850
										{//??բ
851
											ycVal = ycVal & (~ytVal);
852
										}
853
										if (ytvalue == 1)
854
										{//??բ
855
											ycVal = ycVal | (ytVal);
856
										}
857
										len = OperateRegister(6, cmdlist[i].address, (uint16)ycVal);
858
									}
859
									else
860
									{
861
										if (cmdlist[i].r_type == 1)
862
										{
863
											len = OperateRegister(6, cmdlist[i].address, (uint16)ytvalue);
864
										}
865
										else if (cmdlist[i].r_type == 2)
866
										{
867
											len = OperateRegister(6, cmdlist[i].address, (sint16)ytvalue);
868
										}
869
									}
870
									//WillSendType = 6;
871

    
872
									b_ret = TRUE;
873
								}
874
								break;
875
							}
876
						}
877
					}
878
					//<wyf>
879
					PrintLog(LOG_WARNING, "<<<<<< YT no=%d   val=%d", ptno, ytvalue);
880
				}
881
				break;
882

    
883
				case DC_K_CTL_AODEL://????
884
				break;
885

    
886
				default:
887
				break;
888
			}
889
		}
890
		break;
891

    
892
		default: //?????????·????????		
893
		break;
894
	}
895

    
896
	pCmdMem->DelACmd(rtuno);
897
	return b_ret;
898
}
899

    
900

    
901

    
902
sint32	CModbusTcpc::CheckFrameHeader(uint8* buff, sint32 len)  //??Ϣ?ż???
903
{
904
	if (len < 7)
905
		return 0;
906

    
907
	if (buff[0] != cnt_sequence / 256 || buff[1] != cnt_sequence % 256)
908
		return -1;
909

    
910
	sint32 rtuno = pLink->GetRtuNo();
911
	uint8 rtuaddr = pRtu->GetRtuAddr(rtuno);
912

    
913
	if (buff[2] != 0 || buff[3] != 0 || buff[6] != rtuaddr)
914
		return -2;
915

    
916
	return 1;
917
}
918

    
919
uint8	CModbusTcpc::ErrorHandle(uint8 errfunc)
920
{
921
	uint8  retFunc = errfunc & 0x7f;
922
	if (retFunc != WillSendType)	//???????
923
		return 0;
924

    
925
	duquIndex = 0;
926
	visitednum = 0;
927
	GetWillSendType();
928

    
929

    
930
	pLink->RegisterFrm(FRAME_RX_SUC);
931
	pLink->SetCommStatus(CMST_NORMAL);
932
	PrintLog(LOG_ERROR, "------- ???????¶?ȡ!");
933

    
934

    
935

    
936
	return 1;
937
}
938

    
939

    
940

    
941
uint8 CModbusTcpc::OperateRegister(uint8 FuncNo, uint16 Address, sint16 Value)  //??????1??2??3??4??5??6?????
942
{
943
	uint8 txbuff[256];
944
	sint32 rtuno = pLink->GetRtuNo();
945
	uint8 rtuadd = pRtu->GetRtuAddr(rtuno);
946
	uint8 len = 0;
947
	if (cnt_sequence >= 65535)
948
		cnt_sequence = 0;
949
	else
950
		cnt_sequence++;
951
	//7bytes Head
952
	txbuff[len++] = cnt_sequence / 0x100;//H Transaction Identifier
953
	txbuff[len++] = cnt_sequence % 0x100;//L
954
	txbuff[len++] = 0;//Protocol Identifier "0 = MODBUS protocol"
955
	txbuff[len++] = 0;
956
	txbuff[len++] = 0;//len_H
957
	txbuff[len++] = 6;//len_L
958
	txbuff[len++] = rtuadd;//Unit Identifier
959

    
960
	txbuff[len++] = FuncNo;
961
	txbuff[len++] = Address / 0x100;//??
962
	txbuff[len++] = Address % 0x100;//??
963
	txbuff[len++] = Value / 0x100;//??
964
	txbuff[len++] = Value % 0x100;//??
965

    
966
	//	pLink->RegisterFrmCode(RAW_CODEDIR_DOWN,(char *)txbuff,len);
967
	pLink->RegisterFrm(FRAME_TX_SUC);
968
	pTxBuf->Write(txbuff, len);
969
	pLink->SetCommStatus(CMST_RX_CNT);
970
	m_LastSendTime = GetNowMilliSecond();
971

    
972
	PrintLog(LOG_INFORMATION, ">>>>>> SendType = %d ,start=%d ,num=%d", WillSendType, Address, Value);
973

    
974
	return len;
975
}
976

    
977

    
978

    
979
uint8 CModbusTcpc::OperateRegister(uint8 FuncNo, uint16 Address, uint16 Value)
980
{
981
	uint8 txbuff[256];
982
	sint32 rtuno = pLink->GetRtuNo();
983
	uint8 rtuadd = pRtu->GetRtuAddr(rtuno);
984
	uint8 len = 0;
985
	if (cnt_sequence >= 65535)
986
		cnt_sequence = 0;
987
	else
988
		cnt_sequence++;
989
	//7bytes Head
990
	txbuff[len++] = cnt_sequence / 0x100;//H Transaction Identifier
991
	txbuff[len++] = cnt_sequence % 0x100;//L
992
	txbuff[len++] = 0;//Protocol Identifier "0 = MODBUS protocol"
993
	txbuff[len++] = 0;
994
	txbuff[len++] = 0;//len_H
995
	txbuff[len++] = 6;//len_L
996
	txbuff[len++] = rtuadd;//Unit Identifier
997

    
998
	txbuff[len++] = FuncNo;
999
	txbuff[len++] = Address / 0x100;//??
1000
	txbuff[len++] = Address % 0x100;//??
1001
	txbuff[len++] = Value / 0x100;//??
1002
	txbuff[len++] = Value % 0x100;//??
1003

    
1004
	//	pLink->RegisterFrmCode(RAW_CODEDIR_DOWN,(char *)txbuff,len);
1005
	pLink->RegisterFrm(FRAME_TX_SUC);
1006
	pTxBuf->Write(txbuff, len);
1007
	pLink->SetCommStatus(CMST_RX_CNT);
1008
	m_LastSendTime = GetNowMilliSecond();
1009

    
1010
	PrintLog(LOG_INFORMATION, ">>>>>> SendType = %d ,start=%d ,num=%d", WillSendType, Address, Value);
1011

    
1012
	return len;
1013
}
1014

    
1015

    
1016

    
1017

    
1018
int CModbusTcpc::ComparePoint(uint16 YxYcId, uint8& value)  //?Ա?????Ӧ?????ݴ??? 01??02 ???????DI?????? bit
1019
{
1020
	if (WillSendType == 1 || WillSendType == 2) {
1021
		if (maplist[mapIndex].address == YxYcId)    //Ϊ?˼???ѭ?? ?????ж? ??ͬ??ȥ???????
1022
		{
1023
			int fbit = 0;
1024
			if (maplist[mapIndex].end == 0)        //endΪ0˵??Ϊһλ ȡһ???ֽ????ݵĵ?0λ????????????һλ
1025
			{
1026
				maplist[mapIndex].data.datauint16 = value & 1;
1027
				maplist[mapIndex].visited = 1;
1028
				mapIndex++;
1029
				mapnum++;
1030
				value >>= 1;
1031
				return 0;
1032
			}
1033
			else             //end??Ϊ0 ȡһ???ֽ?endλ??????һλ
1034
			{
1035
				for (int i = 0; i <= maplist[mapIndex].end; i++) {
1036
					fbit += pow(2, i);
1037
				}
1038
				maplist[mapIndex].data.datauint16 = value & fbit;
1039
				maplist[mapIndex].visited = 1;
1040
				mapIndex++;
1041
				mapnum++;
1042
				value >>= 1;
1043
				return 0;
1044
			}
1045
		}
1046
		if (maplist[mapIndex].address > YxYcId)   //??????end??Ϊ0????? ʹ?õ?ַ???ڵ?ǰYxYcId ????1λֱ?????
1047
		{
1048
			value >>= 1;
1049
			return -1;
1050
		}
1051
		for (int i = 0; i < maplength; i++)   //????????жϵ?ַ????Ⱦͱ?????һ??
1052
		{
1053
			if (maplist[i].visited == 1)
1054
				continue;
1055
			if (maplist[i].address == YxYcId) {
1056
				int fbit = 0;
1057
				if (maplist[i].end == 0) {
1058
					maplist[i].data.datauint16 = value & 1;
1059
					maplist[i].visited = 1;
1060
					mapIndex = i + 1;
1061
					mapnum++;
1062
					value >>= 1;
1063
					return 0;
1064
				}
1065
				else {
1066
					for (int i = 0; i <= maplist[i].end; i++) {
1067
						fbit += pow(2, i);
1068
					}
1069
					maplist[i].data.datauint16 = value & fbit;
1070
					maplist[i].visited = 1;
1071
					mapIndex = i + 1;
1072
					mapnum++;
1073
					value >>= 1;
1074
					return 0;
1075
				}
1076
			}
1077
		}
1078
		return -1;
1079
		value >>= 1;
1080
	}
1081
	return -2;
1082
}
1083

    
1084

    
1085

    
1086
int	CModbusTcpc::ComparePoint_reg(uint16 YxYcId, uint8* buf, int i)  //?Ա?????Ӧ?????ݴ???03??04???? ??????ͬ???͵?DI??AI??PI??VA????
1087
{
1088
	if (WillSendType == 3 || WillSendType == 4) 
1089
	{
1090
		if (maplist[mapIndex].address == YxYcId)  //???ж? Ϊ?˼???ѭ??
1091
		{
1092
			if (maplist[mapIndex].m_type == 0)    //VA???ݣ?ֱ?Ӽ??????? ռһ???Ĵ??? ???ֽ? 16λ
1093
			{
1094
				maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];   //??8λ????????8λ+??8λ
1095
				maplist[mapIndex].visited = 1;    //??ȡ??־??Ϊ1
1096
				mapIndex++;
1097
				mapnum++;
1098
				return 0;
1099
			}
1100

    
1101

    
1102
			if (maplist[mapIndex].start == 0 && maplist[mapIndex].end == 15)    //??1???Ĵ??????
1103
			{
1104
				if (maplist[mapIndex].m_type == 3)    //AI???? 16λ??ǰ׺
1105
				{
1106
					if (maplist[mapIndex].r_type == 1)   //uint??????
1107
						maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];  //??8λ????????8λ+??8λ
1108
					else        //int??????
1109
						maplist[mapIndex].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1110
					maplist[mapIndex].visited = 1;
1111
					mapIndex++;
1112
					mapnum++;
1113
					return 0;
1114
				}
1115
				if (maplist[mapIndex].m_type == 4)   //AI???? 16λrvǰ׺  rv??ǰ׺?????Ĵ????ڲ??ֽ?ǰ?ͺ??
1116
				{
1117
					if (maplist[mapIndex].r_type == 1)
1118
						maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];    //??8λ????????8λ+??8λ
1119
					else
1120
						maplist[mapIndex].data.datasint16 = (sint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];
1121
					maplist[mapIndex].visited = 1;
1122
					mapIndex++;
1123
					mapnum++;
1124
					return 0;
1125
				}
1126
				if (maplist[mapIndex].m_type == 9)    //PI???? ע????PI????ֻ??int16??int32??uint16??uint32??float??5??????
1127
				{
1128
					if (maplist[mapIndex].r_type == 1)
1129
						maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1130
					else
1131
						maplist[mapIndex].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1132
					maplist[mapIndex].visited = 1;
1133
					mapIndex++;
1134
					mapnum++;
1135
					return 0;
1136
				}
1137

    
1138
			}
1139

    
1140

    
1141
			if (maplist[mapIndex].start > 0 || maplist[mapIndex].end < 15)   //???ݲ???һ?????Ĵ????????
1142
			{
1143
				int fbit = 0;
1144
				if (maplist[mapIndex].m_type == 3 || maplist[mapIndex].m_type == 1)  //??Ϊrv???
1145
				{
1146
					for (int i = maplist[mapIndex].start; i <= maplist[mapIndex].end; i++)  //??fbitΪ?ӿ?ʼ??????λΪ1
1147
					{
1148
						fbit += pow(2, i);  //pow????Ϊ??2??i?η?
1149
					}
1150
					if (maplist[mapIndex].r_type == 1){
1151
						maplist[mapIndex].data.datauint16 = (uint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;  //ȡ??ʼ??????λ???ݣ?????λ??Ϊ0
1152
						maplist[mapIndex].data.datauint16 >>= maplist[mapIndex].start;  //???ƿ?ʼλ???ݼ????Ҳ???????Ϊ0??????ȥ??
1153
					}
1154
					else{
1155
						maplist[mapIndex].data.datasint16 = (sint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1156
						maplist[mapIndex].data.datasint16 >>= maplist[mapIndex].start;
1157
					}
1158
					maplist[mapIndex].visited = 1;
1159
					mapIndex++;
1160
					mapnum++;
1161
					return 1;
1162
				}
1163
				if (maplist[mapIndex].m_type == 4 || maplist[mapIndex].m_type == 2)  //rv??? ????Ϊ?ߵ??ֽڵ????Ƽ???
1164
				{
1165
					for (int i = maplist[mapIndex].start; i <= maplist[mapIndex].end; i++) {
1166
						fbit += pow(2, i);
1167
					}
1168
					if (maplist[mapIndex].r_type == 1){
1169
						maplist[mapIndex].data.datauint16 = (uint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1170
						maplist[mapIndex].data.datauint16 >>= maplist[mapIndex].start;
1171
					}
1172
					else{
1173
						maplist[mapIndex].data.datasint16 = (sint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1174
						maplist[mapIndex].data.datasint16 >>= maplist[mapIndex].start;
1175
					}
1176
					maplist[mapIndex].visited = 1;
1177
					mapIndex++;
1178
					mapnum++;
1179
					return 1;
1180
				}
1181
			}
1182

    
1183

    
1184

    
1185
			if (maplist[mapIndex].end > 15)  //?õ??????Ĵ????????
1186
			{
1187
				int fbit = 0;
1188
				if (maplist[mapIndex].m_type == 5)   //32λ??ǰ׺ AI??
1189
				{
1190
					if (maplist[mapIndex].r_type == 3)  //float??
1191
					{
1192
						FCHAR4 value;
1193
						value.val2.b4 = buf[3 + 2 * i + 2];
1194
						value.val2.b3 = buf[3 + 2 * i + 1 + 2];
1195
						value.val2.b2 = buf[3 + 2 * i];
1196
						value.val2.b1 = buf[3 + 2 * i + 1];
1197

    
1198
						maplist[mapIndex].data.datafloat = value.val1;
1199

    
1200
						/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
1201
						maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
1202
						maplist[mapIndex].visited = 1;
1203
						mapIndex = mapIndex + 1;
1204
						mapnum++;
1205
						return 1;
1206
					}
1207
					if (maplist[mapIndex].r_type == 4)   //int32 ??
1208
					{
1209
						if (maplist[mapIndex].start > 0)   //??ʼλ??Ϊ0 ǰ?Ĵ??????????
1210
						{
1211
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1212
								fbit += pow(2, i);
1213
							}
1214
							maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;   //????ͼĴ???????Ӧֵ
1215
							maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;  //???ƿ?ʼλ ȥ???Ҳ?????????0
1216
							fbit = 0;
1217
						}
1218
						else{
1219
							maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);   //ǰ?Ĵ??????????
1220
						}
1221
						if (maplist[mapIndex].end < 31)   //??Ĵ??????߼Ĵ??????????
1222
						{
1223
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1224
								fbit += pow(2, i);
1225
							}
1226
							uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;   //?????Ĵ?????Ӧ??ֵ??ȡ????Ӧλ???? ??????0
1227
							fbit = 0;
1228
							maplist[mapIndex].data.datasint32 = (sint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datasint32;  //ǰ??Ĵ??????ݺϲ? ????Ϊ?߼Ĵ??????ƵͼĴ???ֵ??λ??????ͼĴ???ֵ???
1229
						}
1230
						else{
1231
							maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2])  *pow(2, 16) + maplist[mapIndex].data.datasint32;  //??Ĵ?????????? ֱ?Ӽ???????16λ????ǰ?Ĵ???ֵ???
1232
						}
1233
						maplist[mapIndex].visited = 1;
1234
						mapIndex = mapIndex + 1;
1235
						mapnum++;
1236
						return 1;
1237
					}
1238
					if (maplist[mapIndex].r_type == 5)   //uint32 ??
1239
					{
1240
						if (maplist[mapIndex].start > 0){
1241
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1242
								fbit += pow(2, i);
1243
							}
1244
							maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1245
							maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
1246
							fbit = 0;
1247
						}
1248
						else{
1249
							maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1250
						}
1251
						if (maplist[mapIndex].end < 31){
1252
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1253
								fbit += pow(2, i);
1254
							}
1255
							uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1256
							fbit = 0;
1257
							maplist[mapIndex].data.datauint32 = (uint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datauint32;
1258
						}
1259
						else{
1260
							maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2])  *pow(2, 16) + maplist[mapIndex].data.datauint32;
1261
						}
1262
						maplist[mapIndex].visited = 1;
1263
						mapIndex = mapIndex + 1;
1264
						mapnum++;
1265
						return 1;
1266
					}
1267
				}
1268

    
1269
				if (maplist[mapIndex].m_type == 6)  //32λAI?? ӵ??swǰ׺  sw??ǰ׺????ǰ?Ĵ???Ϊ??λ????Ĵ???Ϊ??λ;
1270
				{
1271
					if (maplist[mapIndex].r_type == 3){
1272
						FCHAR4 value;
1273
						value.val2.b4 = buf[3 + 2 * i];
1274
						value.val2.b3 = buf[3 + 2 * i + 1];
1275
						value.val2.b2 = buf[3 + 2 * i + 2];
1276
						value.val2.b1 = buf[3 + 2 * i + 1 + 2];
1277

    
1278
						maplist[mapIndex].data.datafloat = value.val1;
1279

    
1280
						/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
1281
						maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]);*/
1282
						maplist[mapIndex].visited = 1;
1283
						mapIndex = mapIndex + 1;
1284
						mapnum++;
1285
						return 1;
1286
					}
1287
					if (maplist[mapIndex].r_type == 4){
1288
						if (maplist[mapIndex].start > 0){
1289
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1290
								fbit += pow(2, i);
1291
							}
1292
							maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1293
							maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;
1294
							fbit = 0;
1295
						}
1296
						else{
1297
							maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1298
						}
1299
						if (maplist[mapIndex].end < 31){
1300
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1301
								fbit += pow(2, i);
1302
							}
1303
							uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1304
							fbit = 0;
1305
							maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 << (maplist[mapIndex].end - 15) | temp;   //??Ҫ????Ϊǰ?Ĵ???ֵ???ƺ?Ĵ???ֵλ???????Ĵ???ֵ???
1306
						}
1307
						else{
1308
							maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
1309
						}
1310
						maplist[mapIndex].visited = 1;
1311
						mapIndex = mapIndex + 1;
1312
						mapnum++;
1313
						return 1;
1314
					}
1315
					if (maplist[mapIndex].r_type == 5){
1316
						if (maplist[mapIndex].start > 0){
1317
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1318
								fbit += pow(2, i);
1319
							}
1320
							maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1321
							maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
1322
							fbit = 0;
1323
						}
1324
						else{
1325
							maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1326
						}
1327
						if (maplist[mapIndex].end < 31){
1328
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1329
								fbit += pow(2, i);
1330
							}
1331
							uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1332
							fbit = 0;
1333
							maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 << (maplist[mapIndex].end - 15) | temp;
1334
						}
1335
						else{
1336
							maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
1337
						}
1338
						maplist[mapIndex].visited = 1;
1339
						mapIndex = mapIndex + 1;
1340
						mapnum++;
1341
						return 1;
1342
					}
1343
				}
1344

    
1345

    
1346
				if (maplist[mapIndex].m_type == 7)      //32λAI?? ӵ??rvǰ׺  rv??ǰ׺?????Ĵ????ڲ??ֽ?ǰ?ͺ??
1347
				{
1348
					if (maplist[mapIndex].r_type == 3){
1349
						FCHAR4 value;
1350
						value.val2.b4 = buf[3 + 2 * i + 1 + 2];
1351
						value.val2.b3 = buf[3 + 2 * i + 2];
1352
						value.val2.b2 = buf[3 + 2 * i + 1];
1353
						value.val2.b1 = buf[3 + 2 * i];
1354

    
1355
						maplist[mapIndex].data.datafloat = value.val1;
1356

    
1357
						/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
1358
						maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
1359
						maplist[mapIndex].visited = 1;
1360
						mapIndex = mapIndex + 1;
1361
						mapnum++;
1362
						return 1;
1363
					}
1364
					if (maplist[mapIndex].r_type == 4){
1365
						if (maplist[mapIndex].start > 0){
1366
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1367
								fbit += pow(2, i);
1368
							}
1369
							maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1370
							maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;
1371
							fbit = 0;
1372
						}
1373
						else{
1374
							maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1375
						}
1376
						if (maplist[mapIndex].end < 31){
1377
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1378
								fbit += pow(2, i);
1379
							}
1380
							uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1381
							fbit = 0;
1382
							maplist[mapIndex].data.datasint32 = (sint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datasint32;
1383
						}
1384
						else{
1385
							maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2])  *pow(2, 16) + maplist[mapIndex].data.datasint32;
1386
						}
1387
						maplist[mapIndex].visited = 1;
1388
						mapIndex = mapIndex + 1;
1389
						mapnum++;
1390
						return 1;
1391
					}
1392
					if (maplist[mapIndex].r_type == 5){
1393
						if (maplist[mapIndex].start > 0){
1394
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1395
								fbit += pow(2, i);
1396
							}
1397
							maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1398
							maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
1399
							fbit = 0;
1400
						}
1401
						else{
1402
							maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1403
						}
1404
						if (maplist[mapIndex].end < 31){
1405
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1406
								fbit += pow(2, i);
1407
							}
1408
							uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1409
							fbit = 0;
1410
							maplist[mapIndex].data.datauint32 = (uint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datauint32;
1411
						}
1412
						else{
1413
							maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2])  *pow(2, 16) + maplist[mapIndex].data.datauint32;
1414
						}
1415
						maplist[mapIndex].visited = 1;
1416
						mapIndex = mapIndex + 1;
1417
						mapnum++;
1418
						return 1;
1419
					}
1420
				}
1421

    
1422

    
1423

    
1424

    
1425

    
1426
				if (maplist[mapIndex].m_type == 8)   //32λAI?? ͬʱӵ??sw??rvǰ׺
1427
				{
1428
					if (maplist[mapIndex].r_type == 3){
1429
						FCHAR4 value;
1430
						value.val2.b4 = buf[3 + 2 * i + 1];
1431
						value.val2.b3 = buf[3 + 2 * i];
1432
						value.val2.b2 = buf[3 + 2 * i + 1 + 2];
1433
						value.val2.b1 = buf[3 + 2 * i + 2];
1434

    
1435
						maplist[mapIndex].data.datafloat = value.val1;
1436

    
1437
						/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
1438
						maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]);*/
1439
						maplist[mapIndex].visited = 1;
1440
						mapIndex = mapIndex + 1;
1441
						mapnum++;
1442
						return 1;
1443
					}
1444
					if (maplist[mapIndex].r_type == 4)
1445
					{
1446
						if (maplist[mapIndex].start > 0){
1447
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1448
								fbit += pow(2, i);
1449
							}
1450
							maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1451
							maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;
1452
							fbit = 0;
1453
						}
1454
						else{
1455
							maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1456
						}
1457
						if (maplist[mapIndex].end < 31)
1458
						{
1459
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1460
								fbit += pow(2, i);
1461
							}
1462
							uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1463
							fbit = 0;
1464
							maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 << (maplist[mapIndex].end - 15) | temp;
1465
						}
1466
						else{
1467
							maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
1468
						}
1469
						maplist[mapIndex].visited = 1;
1470
						mapIndex = mapIndex + 1;
1471
						mapnum++;
1472
						return 1;
1473
					}
1474
					if (maplist[mapIndex].r_type == 5){
1475
						if (maplist[mapIndex].start > 0){
1476
							for (int i = maplist[mapIndex].start; i < 16; i++) {
1477
								fbit += pow(2, i);
1478
							}
1479
							maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1480
							maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
1481
							fbit = 0;
1482
						}
1483
						else{
1484
							maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1485
						}
1486
						if (maplist[mapIndex].end < 31){
1487
							for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
1488
								fbit += pow(2, i);
1489
							}
1490
							uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1491
							fbit = 0;
1492
							maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 << (maplist[mapIndex].end - 15) | temp;
1493
						}
1494
						else{
1495
							maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
1496
						}
1497
						maplist[mapIndex].visited = 1;
1498
						mapIndex = mapIndex + 1;
1499
						mapnum++;
1500
						return 1;
1501
					}
1502
				}
1503

    
1504

    
1505
				if (maplist[mapIndex].m_type == 9)   //32λPI??
1506
				{
1507
					if (maplist[mapIndex].r_type == 3)
1508
					{
1509
						maplist[mapIndex].data.datafloat = (float)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1510
						maplist[mapIndex].data.datafloat = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;
1511
						maplist[mapIndex].visited = 1;
1512
						mapIndex = mapIndex + 1;
1513
						mapnum++;
1514
						return 0;
1515
					}
1516

    
1517
					if (maplist[mapIndex].r_type == 4)
1518
					{
1519
						maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1520
						maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datasint32;
1521
						maplist[mapIndex].visited = 1;
1522
						mapIndex = mapIndex + 1;
1523
						mapnum++;
1524
						return 0;
1525
					}
1526

    
1527
					if (maplist[mapIndex].r_type == 5)
1528
					{
1529
						maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1530
						maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datauint32;
1531
						maplist[mapIndex].visited = 1;
1532
						mapIndex = mapIndex + 1;
1533
						mapnum++;
1534
						return 0;
1535
					}
1536
				}
1537
			}
1538
		}
1539
	
1540
		
1541
		if (maplist[mapIndex].address > YxYcId)     //??Ϊ?жϼ???ѭ?? ??Ϊѭ????ʵ?? ??????ͬ
1542
		{
1543
			return -1;
1544
		}
1545
		for (int j = 0; j < maplength; j++) {
1546
			if (maplist[j].visited == 1)
1547
				continue;
1548
			if (maplist[j].address == YxYcId) {
1549
				if (maplist[j].m_type == 0){
1550
					maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1551
					maplist[j].visited = 1;
1552
					mapIndex = j + 1;
1553
					mapnum++;
1554
					return 0;
1555
				}
1556

    
1557

    
1558
				if (maplist[j].start == 0 && maplist[j].end == 15) 
1559
				{
1560
					if (maplist[j].m_type == 3){
1561
						if (maplist[j].r_type == 1)
1562
							maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1563
						else
1564
							maplist[j].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1565
						maplist[j].visited = 1;
1566
						mapIndex = j + 1;
1567
						mapnum++;
1568
						return 0;
1569
					}
1570
					if (maplist[j].m_type == 4){
1571
						if (maplist[j].r_type == 1)
1572
							maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];
1573
						else
1574
							maplist[j].data.datasint16 = (sint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];
1575
						maplist[j].visited = 1;
1576
						mapIndex = j + 1;
1577
						mapnum++;
1578
						return 0;
1579
					}
1580
					if (maplist[j].m_type == 9)
1581
					{
1582
						if (maplist[j].r_type == 1)
1583
							maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1584
						else
1585
							maplist[j].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
1586
						maplist[j].visited = 1;
1587
						mapIndex = j + 1;
1588
						mapnum++;
1589
						return 0;
1590
					}
1591

    
1592
				}
1593

    
1594

    
1595
				if (maplist[j].start > 0 || maplist[j].end < 15) {
1596
					int fbit = 0;
1597
					if (maplist[j].m_type == 3 || maplist[j].m_type == 1){
1598
						for (int i = maplist[j].start; i <= maplist[j].end; i++) {
1599
							fbit += pow(2, i);
1600
						}
1601
						if (maplist[j].r_type == 1){
1602
							maplist[j].data.datauint16 = (uint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1603
							maplist[j].data.datauint16 >>= maplist[j].start;
1604
						}
1605
						else{
1606
							maplist[j].data.datasint16 = (sint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1607
							maplist[j].data.datasint16 >>= maplist[j].start;
1608
						}
1609
						maplist[j].visited = 1;
1610
						mapIndex = j + 1;
1611
						mapnum++;
1612
						return 1;
1613
					}
1614
					if (maplist[j].m_type == 4 || maplist[j].m_type == 2){
1615
						for (int i = maplist[j].start; i <= maplist[j].end; i++) {
1616
							fbit += pow(2, i);
1617
						}
1618
						if (maplist[j].r_type == 1){
1619
							maplist[j].data.datauint16 = (uint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1620
							maplist[j].data.datauint16 >>= maplist[j].start;
1621
						}
1622
						else{
1623
							maplist[j].data.datasint16 = (sint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1624
							maplist[j].data.datasint16 >>= maplist[j].start;
1625
						}
1626
						maplist[j].visited = 1;
1627
						mapIndex = j + 1;
1628
						mapnum++;
1629
						return 1;
1630
					}
1631
				}
1632

    
1633

    
1634

    
1635
				if (maplist[j].end > 15) {
1636
					int fbit = 0;
1637
					if (maplist[j].m_type == 5){
1638
						if (maplist[j].r_type == 3){
1639
							FCHAR4 value;
1640
							value.val2.b4 = buf[3 + 2 * i + 2];
1641
							value.val2.b3 = buf[3 + 2 * i + 1 + 2];
1642
							value.val2.b2 = buf[3 + 2 * i];
1643
							value.val2.b1 = buf[3 + 2 * i + 1];
1644

    
1645
							maplist[mapIndex].data.datafloat = value.val1;
1646

    
1647
							/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
1648
							maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
1649
							maplist[j].visited = 1;
1650
							mapIndex = j + 1;
1651
							mapnum++;
1652
							return 1;
1653
						}
1654
						if (maplist[j].r_type == 4){
1655
							if (maplist[j].start > 0){
1656
								for (int i = maplist[j].start; i < 16; i++) {
1657
									fbit += pow(2, i);
1658
								}
1659
								maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1660
								maplist[j].data.datasint32 >>= maplist[j].start;
1661
								fbit = 0;
1662
							}
1663
							else{
1664
								maplist[j].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1665
							}
1666
							if (maplist[j].end < 31){
1667
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1668
									fbit += pow(2, i);
1669
								}
1670
								uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1671
								fbit = 0;
1672
								maplist[j].data.datasint32 = (sint32)temp << (16 - maplist[j].start) | maplist[j].data.datasint32;
1673
							}
1674
							else{
1675
								maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2])  *pow(2, 16) + maplist[j].data.datasint32;
1676
							}
1677
							maplist[j].visited = 1;
1678
							mapIndex = j + 1;
1679
							mapnum++;
1680
							return 1;
1681
						}
1682
						if (maplist[j].r_type == 5){
1683
							if (maplist[j].start > 0){
1684
								for (int i = maplist[j].start; i < 16; i++) {
1685
									fbit += pow(2, i);
1686
								}
1687
								maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1688
								maplist[j].data.datauint32 >>= maplist[j].start;
1689
								fbit = 0;
1690
							}
1691
							else{
1692
								maplist[j].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1693
							}
1694
							if (maplist[j].end < 31){
1695
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1696
									fbit += pow(2, i);
1697
								}
1698
								uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1699
								fbit = 0;
1700
								maplist[j].data.datauint32 = (uint32)temp << (16 - maplist[j].start) | maplist[j].data.datauint32;
1701
							}
1702
							else{
1703
								maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2])  *pow(2, 16) + maplist[j].data.datauint32;
1704
							}
1705
							maplist[j].visited = 1;
1706
							mapIndex = j + 1;
1707
							mapnum++;
1708
							return 1;
1709
						}
1710
					}
1711

    
1712

    
1713

    
1714

    
1715

    
1716
					if (maplist[j].m_type == 6){
1717
						if (maplist[j].r_type == 3){
1718
							FCHAR4 value;
1719
							value.val2.b4 = buf[3 + 2 * i];
1720
							value.val2.b3 = buf[3 + 2 * i + 1];
1721
							value.val2.b2 = buf[3 + 2 * i + 2];
1722
							value.val2.b1 = buf[3 + 2 * i + 1 + 2];
1723

    
1724
							maplist[mapIndex].data.datafloat = value.val1;
1725

    
1726
							/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
1727
							maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]);*/
1728
							maplist[j].visited = 1;
1729
							mapIndex = j + 1;
1730
							mapnum++;
1731
							return 1;
1732
						}
1733
						if (maplist[j].r_type == 4){
1734
							if (maplist[j].start > 0){
1735
								for (int i = maplist[j].start; i < 16; i++) {
1736
									fbit += pow(2, i);
1737
								}
1738
								maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1739
								maplist[j].data.datasint32 >>= maplist[j].start;
1740
								fbit = 0;
1741
							}
1742
							else{
1743
								maplist[j].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1744
							}
1745
							if (maplist[j].end < 31){
1746
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1747
									fbit += pow(2, i);
1748
								}
1749
								uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1750
								fbit = 0;
1751
								maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 << (maplist[j].end - 15) | temp;
1752
							}
1753
							else{
1754
								maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
1755
							}
1756
							maplist[j].visited = 1;
1757
							mapIndex = j + 1;
1758
							mapnum++;
1759
							return 1;
1760
						}
1761
						if (maplist[j].r_type == 5){
1762
							if (maplist[j].start > 0){
1763
								for (int i = maplist[j].start; i < 16; i++) {
1764
									fbit += pow(2, i);
1765
								}
1766
								maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
1767
								maplist[j].data.datauint32 >>= maplist[j].start;
1768
								fbit = 0;
1769
							}
1770
							else{
1771
								maplist[j].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1772
							}
1773
							if (maplist[j].end < 31){
1774
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1775
									fbit += pow(2, i);
1776
								}
1777
								uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
1778
								fbit = 0;
1779
								maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 << (maplist[j].end - 15) | temp;
1780
							}
1781
							else{
1782
								maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
1783
							}
1784
							maplist[j].visited = 1;
1785
							mapIndex = j + 1;
1786
							mapnum++;
1787
							return 1;
1788
						}
1789
					}
1790

    
1791

    
1792

    
1793

    
1794

    
1795
					if (maplist[j].m_type == 7){
1796
						if (maplist[j].r_type == 3){
1797
							FCHAR4 value;
1798
							value.val2.b4 = buf[3 + 2 * i + 1 + 2];
1799
							value.val2.b3 = buf[3 + 2 * i + 2];
1800
							value.val2.b2 = buf[3 + 2 * i + 1];
1801
							value.val2.b1 = buf[3 + 2 * i];
1802

    
1803
							maplist[mapIndex].data.datafloat = value.val1;
1804

    
1805
							/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
1806
							maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
1807
							maplist[j].visited = 1;
1808
							mapIndex = j + 1;
1809
							mapnum++;
1810
							return 1;
1811
						}
1812
						if (maplist[j].r_type == 4){
1813
							if (maplist[j].start > 0){
1814
								for (int i = maplist[j].start; i < 16; i++) {
1815
									fbit += pow(2, i);
1816
								}
1817
								maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1818
								maplist[j].data.datasint32 >>= maplist[j].start;
1819
								fbit = 0;
1820
							}
1821
							else{
1822
								maplist[j].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1823
							}
1824
							if (maplist[j].end < 31){
1825
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1826
									fbit += pow(2, i);
1827
								}
1828
								uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1829
								fbit = 0;
1830
								maplist[j].data.datasint32 = (sint32)temp << (16 - maplist[j].start) | maplist[j].data.datasint32;
1831
							}
1832
							else{
1833
								maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2])  *pow(2, 16) + maplist[j].data.datasint32;
1834
							}
1835
							maplist[j].visited = 1;
1836
							mapIndex = j + 1;
1837
							mapnum++;
1838
							return 1;
1839
						}
1840
						if (maplist[j].r_type == 5){
1841
							if (maplist[j].start > 0){
1842
								for (int i = maplist[j].start; i < 16; i++) {
1843
									fbit += pow(2, i);
1844
								}
1845
								maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1846
								maplist[j].data.datauint32 >>= maplist[j].start;
1847
								fbit = 0;
1848
							}
1849
							else{
1850
								maplist[j].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1851
							}
1852
							if (maplist[j].end < 31){
1853
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1854
									fbit += pow(2, i);
1855
								}
1856
								uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1857
								fbit = 0;
1858
								maplist[j].data.datauint32 = (uint32)temp << (16 - maplist[j].start) | maplist[j].data.datauint32;
1859
							}
1860
							else{
1861
								maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2])  *pow(2, 16) + maplist[j].data.datauint32;
1862
							}
1863
							maplist[j].visited = 1;
1864
							mapIndex = j + 1;
1865
							mapnum++;
1866
							return 1;
1867
						}
1868
					}
1869

    
1870

    
1871

    
1872

    
1873

    
1874
					if (maplist[j].m_type == 8){
1875
						if (maplist[j].r_type == 3){
1876
							FCHAR4 value;
1877
							value.val2.b4 = buf[3 + 2 * i + 1];
1878
							value.val2.b3 = buf[3 + 2 * i];
1879
							value.val2.b2 = buf[3 + 2 * i + 1 + 2];
1880
							value.val2.b1 = buf[3 + 2 * i + 2];
1881

    
1882
							maplist[mapIndex].data.datafloat = value.val1;
1883

    
1884
							/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
1885
							maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]);*/
1886
							maplist[j].visited = 1;
1887
							mapIndex = j + 1;
1888
							mapnum++;
1889
							return 1;
1890
						}
1891
						if (maplist[j].r_type == 4){
1892
							if (maplist[j].start > 0){
1893
								for (int i = maplist[j].start; i < 16; i++) {
1894
									fbit += pow(2, i);
1895
								}
1896
								maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1897
								maplist[j].data.datasint32 >>= maplist[j].start;
1898
								fbit = 0;
1899
							}
1900
							else{
1901
								maplist[j].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1902
							}
1903
							if (maplist[j].end < 31){
1904
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1905
									fbit += pow(2, i);
1906
								}
1907
								uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1908
								fbit = 0;
1909
								maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 << (maplist[j].end - 15) | temp;
1910
							}
1911
							else{
1912
								maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
1913
							}
1914
							maplist[j].visited = 1;
1915
							mapIndex = j + 1;
1916
							mapnum++;
1917
							return 1;
1918
						}
1919
						if (maplist[j].r_type == 5){
1920
							if (maplist[j].start > 0){
1921
								for (int i = maplist[j].start; i < 16; i++) {
1922
									fbit += pow(2, i);
1923
								}
1924
								maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
1925
								maplist[j].data.datauint32 >>= maplist[j].start;
1926
								fbit = 0;
1927
							}
1928
							else{
1929
								maplist[j].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
1930
							}
1931
							if (maplist[j].end < 31){
1932
								for (int i = 0; i <= maplist[j].end - 16; i++) {
1933
									fbit += pow(2, i);
1934
								}
1935
								uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
1936
								fbit = 0;
1937
								maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 << (maplist[j].end - 15) | temp;
1938
							}
1939
							else{
1940
								maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
1941
							}
1942
							maplist[j].visited = 1;
1943
							mapIndex = j + 1;
1944
							mapnum++;
1945
							return 1;
1946
						}
1947
					}
1948

    
1949

    
1950
					if (maplist[j].m_type == 9)
1951
					{
1952
						if (maplist[j].r_type == 3){
1953
							maplist[j].data.datafloat = (float)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1954
							maplist[j].data.datafloat = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datafloat;
1955
							maplist[j].visited = 1;
1956
							mapIndex = j + 1;
1957
							mapnum++;
1958
							return 0;
1959
						}
1960
						if (maplist[j].r_type == 4){
1961
							maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1962
							maplist[j].data.datasint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datasint32;
1963
							maplist[j].visited = 1;
1964
							mapIndex = j + 1;
1965
							mapnum++;
1966
							return 0;
1967
						}
1968
						if (maplist[j].r_type == 5){
1969
							maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
1970
							maplist[j].data.datauint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datauint32;
1971
							maplist[j].visited = 1;
1972
							mapIndex = j + 1;
1973
							mapnum++;
1974
							return 0;
1975
						}
1976
					}
1977
				}
1978
			}
1979
		}
1980
		return -1;
1981
	}
1982
	return -2;
1983
}
1984

    
1985
sint64  CModbusTcpc::GetNowMilliSecond()  //??ȡ??ǰ????ʱ??
1986
{
1987
	CSeTime     SE_T;
1988
	TCriterionTime tmptime;//sint32
1989
	unsigned short  millsecond;
1990
	SE_T.GetNow(&tmptime, &millsecond);
1991
	sint64 nowmilltime = (sint64)tmptime * 1000 + millsecond;
1992
	return nowmilltime;
1993
}
1994

    
1995

    
1996

    
1997

    
1998
sint32 CModbusTcpc::RxProc() {
1999
	if (err)
2000
		return -1;
2001

    
2002
	//PrintLog(LOG_INFORMATION, "------- ????RxProc");
2003
	sint32 rtuno = pLink->GetRtuNo();
2004

    
2005
	uint8 buf[1024];
2006
	int datalen = 0, datanum = 0;
2007
	int i, j;
2008
	sint32 buflen = pRxBuf->GetReadableSize();
2009
	sint64 nowtime = GetNowMilliSecond();
2010

    
2011
	if (mapnum >= maplength) 
2012
	{
2013
		mapnum = 0;
2014
		return 0;
2015
	}
2016

    
2017
	E_RAW_ComStat commstatus = pLink->GetCommStatus();
2018
	if (commstatus == CMST_RX_CNT && (nowtime - m_LastSendTime) >= m_RcvTimeOuts * 1000)
2019
	{
2020
		//??ʱ???ط???ֱ????????һ???ն?
2021
		pRxBuf->Move(buflen);
2022
		pLink->RegisterFrm(FRAME_RX_TIMEOUT);
2023
		pLink->SetCommStatus(CMST_TX_CNT);
2024
		PrintLog(LOG_VIOLATION, " ???ݳ?ʱ,%d\n", nowtime - m_LastSendTime);
2025
		return -1;
2026
	}
2027
	if (buflen < 7)		//?????ݻ????ݲ??????ı???·ͨѶ״̬???????ȴ?
2028
		return -1;
2029
	datalen = pRxBuf->Read(buf, 7, DEF_BUFF_NOMOVE);   //??ǰ7λ????ͷ
2030

    
2031
	int ret = CheckFrameHeader(buf, 7);
2032
	if (ret<0)
2033
	{
2034
		pRxBuf->Move(buflen);
2035
		pLink->RegisterFrm(FRAME_RX_MISSTEP);
2036
		PrintLog(LOG_VIOLATION, "ModbusHead??һ??\n");
2037

    
2038
		return -1;
2039
	}
2040
	else if (ret == 0)
2041
		return 0;
2042

    
2043
	uint16 d_len = buf[4] * 256 + buf[5] + 6;   //???㱨?????峤??
2044
	if (buflen < d_len)
2045
		return -1;
2046
	datalen = pRxBuf->Read(buf, d_len, DEF_BUFF_MOVE);
2047

    
2048
	//	PrintLog(LOG_INFORMATION,"<<<<< ReceiveType=%d, numbyte=%d",buf[7],buf[8]);
2049

    
2050
	if (buf[7] & 0x80){
2051
		pLink->RegisterFrm(FRAME_RX_SUC);
2052
		pLink->SetCommStatus(CMST_NORMAL);
2053
		return -1;//ErrorHandle(buf[7]);
2054
	}
2055

    
2056
	uint16 YxYcId = 0;
2057

    
2058
	
2059
	switch (buf[7])  //???????ж?
2060
	{
2061
	case 1:
2062
		if (WillSendType == 1)
2063
		{
2064
			//????ң??
2065
			for (i = 0; i < buf[8]; i++)
2066
			{
2067
				uint8 value = buf[9 + i];
2068
				for (j = 0; j < 8; j++)
2069
				{
2070

    
2071
					YxYcId = 8 * i + j + IndexDI;
2072
					if (YxYcId >= (IndexDI + numDI))
2073
						break;
2074
					int ret = ComparePoint(YxYcId, value);
2075
					if (ret == 0) {
2076
						PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2077
					}
2078
				}
2079
			}
2080
			PrintLog(LOG_INFORMATION, "---- Receive Yx data ");
2081

    
2082
			if (buf[8] * 8 < numDI) {
2083
				IndexDI += buf[8] * 8;
2084
				visitednum += buf[8] * 8;
2085
			}
2086
			else {
2087
				IndexDI += numDI;
2088
				visitednum += numDI;
2089
			}
2090

    
2091

    
2092
			pLink->RegisterFrm(FRAME_RX_SUC);
2093
			pLink->SetCommStatus(CMST_NORMAL);
2094

    
2095
			return 1;
2096
		}
2097
		break;
2098
	case 2:
2099
		if (WillSendType == 2)
2100
		{
2101
			//????ң??
2102
			for (i = 0; i < buf[8]; i++)
2103
			{
2104
				uint8 value = buf[9 + i];
2105
				for (j = 0; j < 8; j++)
2106
				{
2107

    
2108
					YxYcId = 8 * i + j + IndexDI;
2109
					if (YxYcId >= (IndexDI + numDI))
2110
						break;
2111
					int ret = ComparePoint(YxYcId, value);
2112
					if (ret == 0) {
2113
						PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2114
					}
2115
				}
2116
			}
2117
			PrintLog(LOG_INFORMATION, "---- Receive Yx data ");
2118

    
2119
			if (buf[8] * 8 < numDI) {
2120
				IndexDI += buf[8] * 8;
2121
				visitednum += buf[8] * 8;
2122
			}
2123
			else {
2124
				IndexDI += numDI;
2125
				visitednum += numDI;
2126
			}
2127

    
2128

    
2129
			pLink->RegisterFrm(FRAME_RX_SUC);
2130
			pLink->SetCommStatus(CMST_NORMAL);
2131

    
2132
			return 1;
2133
		}
2134
		break;
2135
	case 3:
2136
		//????ң??
2137
		if (WillSendType == 3)
2138
		{
2139
			for (i = 0; i < buf[8] / 2; i++)
2140
			{
2141
				YxYcId = i + IndexAI;
2142
				if (YxYcId >= (IndexAI + numAI))
2143
					break;
2144
				int ret = ComparePoint_reg(YxYcId, buf, i);
2145
				if (ret == 0) {
2146
					if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
2147
						PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2148
					}
2149
					if (maplist[mapIndex - 1].m_type == 3 || maplist[mapIndex - 1].m_type == 4 || maplist[mapIndex - 1].m_type == 5 || maplist[mapIndex - 1].m_type == 6 || maplist[mapIndex - 1].m_type == 7 || maplist[mapIndex - 1].m_type == 8) {
2150
						switch (maplist[mapIndex - 1].r_type){
2151
						case 1:
2152
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2153
							break;
2154
						case 2:
2155
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2156
							break;
2157
						case 3:
2158
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2159
							break;
2160
						case 4:
2161
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2162
							break;
2163
						case 5:
2164
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2165
							break;
2166
						}
2167
					}
2168
					if (maplist[mapIndex - 1].m_type == 9) {
2169
						switch (maplist[mapIndex - 1].r_type){
2170
						case 1:
2171
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2172
							break;
2173
						case 2:
2174
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2175
							break;
2176
						case 3:
2177
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2178
							break;
2179
						case 4:
2180
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2181
							break;
2182
						case 5:
2183
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2184
							break;
2185
						}
2186
					}
2187
					if (maplist[mapIndex - 1].m_type == 0) 
2188
					{
2189
						uint16 data = 1;
2190
						if (maplist[mapIndex - 1].data.datauint16 == 0)
2191
						{
2192
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2193
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2194
						}
2195

    
2196
						else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1)
2197
						{
2198
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2199
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2200
							PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2201
						}
2202

    
2203
						else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0)
2204
						{
2205
							uint16 data = 1;
2206
							data <<= maplist[mapIndex - 1].data.datauint16 - 1;
2207
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
2208
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
2209
								data >>= 1;
2210
							}
2211
						}
2212
					}
2213
				}
2214
				while (ret == 1) {
2215
					if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
2216
						PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2217
					}
2218
					if (maplist[mapIndex - 1].m_type == 3 || maplist[mapIndex - 1].m_type == 4 || maplist[mapIndex - 1].m_type == 5 || maplist[mapIndex - 1].m_type == 6 || maplist[mapIndex - 1].m_type == 7 || maplist[mapIndex - 1].m_type == 8) {
2219
						switch (maplist[mapIndex - 1].r_type){
2220
						case 1:
2221
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2222
							break;
2223
						case 2:
2224
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2225
							break;
2226
						case 3:
2227
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2228
							break;
2229
						case 4:
2230
							//float32 a;  //????ʧ???????
2231
							//a = maplist[mapIndex - 1].data.datasint32;
2232
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2233
							break;
2234
						case 5:
2235
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2236
							break;
2237
						}
2238
					}
2239
					if (maplist[mapIndex - 1].m_type == 9) {
2240
						switch (maplist[mapIndex - 1].r_type){
2241
						case 1:
2242
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2243
							break;
2244
						case 2:
2245
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2246
							break;
2247
						case 3:
2248
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2249
							break;
2250
						case 4:
2251
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2252
							break;
2253
						case 5:
2254
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2255
							break;
2256
						}
2257
					}
2258
					if (maplist[mapIndex - 1].m_type == 0) {
2259
							uint16 data = 1;
2260

    
2261
						if (maplist[mapIndex - 1].data.datauint16 == 0){
2262
							for (int index = 0; index <= maplist[mapIndex - 1].end + 1; index++)
2263
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2264
						}
2265
						else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1){
2266
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2267
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2268
							PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2269
						}
2270
						else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0){
2271
							uint16 data = 1;
2272
							data <<= maplist[mapIndex - 1].data.datauint16 - 1;
2273
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
2274
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
2275
								data >>= 1;
2276
							}
2277
						}
2278
					}
2279
					ret = ComparePoint_reg(YxYcId, buf, i);
2280
				}
2281
			}
2282

    
2283
			PrintLog(LOG_INFORMATION, ">>>> Receive Yc data ");
2284
			if (buf[8] / 2 < numAI) {
2285
				IndexAI += buf[8] / 2;
2286
				visitednum += buf[8] / 2;
2287
			}
2288
			else {
2289
				IndexAI += numAI;
2290
				visitednum += numAI;
2291
			}
2292
			pLink->RegisterFrm(FRAME_RX_SUC);
2293
			pLink->SetCommStatus(CMST_NORMAL);
2294

    
2295
			return 1;
2296
		}
2297
		break;
2298
	case 4:
2299
		//????ң??
2300
		if (WillSendType == 4)
2301
		{
2302
			for (i = 0; i < buf[8] / 2; i++)
2303
			{
2304
				YxYcId = i + IndexAI;
2305
				if (YxYcId >= (IndexAI + numAI))
2306
					break;
2307
				int ret = ComparePoint_reg(YxYcId, buf, i);
2308
				if (ret == 0) {
2309
					if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
2310
						PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2311
					}
2312
					if (maplist[mapIndex - 1].m_type == 3 || maplist[mapIndex - 1].m_type == 4 || maplist[mapIndex - 1].m_type == 5 || maplist[mapIndex - 1].m_type == 6 || maplist[mapIndex - 1].m_type == 7 || maplist[mapIndex - 1].m_type == 8) {
2313
						switch (maplist[mapIndex - 1].r_type){
2314
						case 1:
2315
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2316
							break;
2317
						case 2:
2318
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2319
							break;
2320
						case 3:
2321
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2322
							break;
2323
						case 4:
2324
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2325
							break;
2326
						case 5:
2327
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2328
							break;
2329
						}
2330
					}
2331
					if (maplist[mapIndex - 1].m_type == 9) {
2332
						switch (maplist[mapIndex - 1].r_type){
2333
						case 1:
2334
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2335
							break;
2336
						case 2:
2337
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2338
							break;
2339
						case 3:
2340
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2341
							break;
2342
						case 4:
2343
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2344
							break;
2345
						case 5:
2346
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2347
							break;
2348
						}
2349
					}
2350
					if (maplist[mapIndex - 1].m_type == 0) {
2351
							uint16 data = 1;
2352

    
2353
						if (maplist[mapIndex - 1].data.datauint16 == 0){
2354
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2355
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2356
						}
2357
						else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1){
2358
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2359
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2360
							PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2361
						}
2362
						else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0){
2363
							uint16 data = 1;
2364
							data <<= maplist[mapIndex - 1].data.datauint16 - 1;
2365
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
2366
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
2367
								data >>= 1;
2368
							}
2369
						}
2370
					}
2371
				}
2372
				while (ret == 1) {
2373
					if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
2374
						PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2375
					}
2376
					if (maplist[mapIndex - 1].m_type == 3 || maplist[mapIndex - 1].m_type == 4 || maplist[mapIndex - 1].m_type == 5 || maplist[mapIndex - 1].m_type == 6 || maplist[mapIndex - 1].m_type == 7 || maplist[mapIndex - 1].m_type == 8) 
2377
					{
2378
						switch (maplist[mapIndex - 1].r_type)
2379
						{
2380
						case 1:
2381
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2382
							break;
2383
						case 2:
2384
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2385
							break;
2386
						case 3:
2387
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2388
							break;
2389
						case 4:
2390
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2391
							break;
2392
						case 5:
2393
							PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2394
							break;
2395
						}
2396
					}
2397
					if (maplist[mapIndex - 1].m_type == 9) {
2398
						switch (maplist[mapIndex - 1].r_type){
2399
						case 1:
2400
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2401
							break;
2402
						case 2:
2403
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
2404
							break;
2405
						case 3:
2406
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
2407
							break;
2408
						case 4:
2409
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
2410
							break;
2411
						case 5:
2412
							PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
2413
							break;
2414
						}
2415
					}
2416
					if (maplist[mapIndex - 1].m_type == 0) {
2417
							uint16 data = 1;
2418

    
2419
						if (maplist[mapIndex - 1].data.datauint16 == 0){
2420
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2421
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2422
						}
2423
						else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1){
2424
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
2425
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
2426
							PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
2427
						}
2428
						else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0){
2429
							uint16 data = 1;
2430
							data <<= maplist[mapIndex - 1].data.datauint16 - 1;
2431
							for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
2432
								PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
2433
								data >>= 1;
2434
							}
2435
						}
2436
					}
2437
					ret = ComparePoint_reg(YxYcId, buf, i);
2438
				}
2439
			}
2440

    
2441
			PrintLog(LOG_INFORMATION, ">>>> Receive Yc data ");
2442
			if (buf[8] / 2 < numAI) {
2443
				IndexAI += buf[8] / 2;
2444
				visitednum += buf[8] / 2;
2445
			}
2446
			else {
2447
				IndexAI += numAI;
2448
				visitednum += numAI;
2449
			}
2450
			pLink->RegisterFrm(FRAME_RX_SUC);
2451
			pLink->SetCommStatus(CMST_NORMAL);
2452

    
2453
			return 1;
2454
		}
2455
		break;
2456
	case 5:
2457
		//ң?ط???
2458
		//			if(WillSendType == 5)
2459
	{
2460
			  pLink->RegisterFrm(FRAME_RX_SUC);
2461
			  pLink->SetCommStatus(CMST_NORMAL);
2462
			  return 1;
2463
	}
2464
		break;
2465
	case 6:
2466
		//ң??????
2467
		//			if(WillSendType == 6)
2468
	{
2469
			  pLink->RegisterFrm(FRAME_RX_SUC);
2470
			  pLink->SetCommStatus(CMST_NORMAL);
2471
			  return 1;
2472
	}
2473
	case 15:
2474
		//ң?ط???
2475
		//			if(WillSendType == 6)
2476
	{
2477
			   pLink->RegisterFrm(FRAME_RX_SUC);
2478
			   pLink->SetCommStatus(CMST_NORMAL);
2479
			   return 1;
2480
	}
2481
	case 16:
2482
		//ң??????
2483
		//			if(WillSendType == 6)
2484
	{
2485
			   pLink->RegisterFrm(FRAME_RX_SUC);
2486
			   pLink->SetCommStatus(CMST_NORMAL);
2487
			   return 1;
2488
	}
2489
		break;
2490
	default:
2491
		return 0;
2492
		break;
2493
	}
2494
	return 1;
2495
}
2496

    
2497

    
2498
sint32 CModbusTcpc::TxProc() 
2499
{
2500
	if (err)
2501
		return -1;
2502

    
2503
	if (readcfgflag == 0)
2504
	{
2505
		sint64	nowtime = GetNowMilliSecond();
2506
		if (nowtime - sleepstarttime > sleeptime * 1000)
2507
		{
2508
			sint64 cfgstart = 0;
2509
			sint64 cfgend = 0;
2510
			cfgstart = GetNowMilliSecond();
2511

    
2512
			ReadCfg();
2513

    
2514
			if (err)
2515
				return -1;
2516

    
2517
			cfgend = GetNowMilliSecond();
2518
			sint64 pasttime = 0;
2519
			pasttime = cfgend - cfgstart;
2520
			PrintLog(1, "?????ļ???ȡʱ?? %d ????", pasttime);
2521

    
2522
			readcfgflag = 1;
2523
		}
2524
		else
2525
		{
2526
			return 0;
2527
		}
2528
	}
2529

    
2530
	//PrintLog(LOG_INFORMATION, "------- ????TxProc");
2531
	E_RAW_ComStat commstatus = pLink->GetCommStatus();
2532

    
2533
	if (commstatus != CMST_TX_CNT && commstatus != CMST_NORMAL)
2534
		return 0;
2535

    
2536
	uint16 rxbuflen = 0;
2537
	rxbuflen = pRxBuf->GetReadableSize();
2538
	if (rxbuflen > 0)
2539
	{
2540
		PrintLog(LOG_ERROR, "------- ???? %d????????!", rxbuflen);
2541
		pRxBuf->Move(rxbuflen);
2542
	}
2543

    
2544
	if (Policy && ProcCmd())
2545
	{
2546
		pLink->SetCommStatus(CMST_RX_CNT);
2547
		return 1; //?????ⲿ?·?????
2548
	}
2549

    
2550

    
2551
	//<wyf>temp
2552
	//	if(( nowtime - m_LastSendTime)<1)
2553
	//		return 0;
2554

    
2555
	uint8 len = 0;
2556

    
2557
	sint64 nowtime = GetNowMilliSecond();
2558
	if (duqu[duquIndex][4] > 0 && ((uint64)(nowtime - m_LastSendTime) < (uint64)duqu[duquIndex][4])) 
2559
	{
2560
		PrintLog(LOG_ERROR, "δ?ﵽ???ʱ??,?????ϴη???%d????,%d", nowtime - m_LastSendTime, (uint64)duqu[duquIndex][4]);
2561
		return -1;
2562
	}
2563

    
2564
	if (visitednum >= duqu[duquIndex][1]) 
2565
	{
2566
		GetWillSendType();
2567
	}
2568

    
2569
	switch (WillSendType)
2570
	{
2571
		case 1://read DIO R/W
2572
			if ((scopeDI - IndexDI) > MAX_BYTE_NUM * 8)
2573
				numDI = MAX_BYTE_NUM * 8;
2574
			else
2575
				numDI = scopeDI - IndexDI;
2576
			if (numDI > 0)
2577
				len = OperateRegister(WillSendType, IndexDI, numDI);
2578
			break;
2579

    
2580
		case 2://read DIO R/W
2581
			if ((scopeDI - IndexDI) > MAX_BYTE_NUM * 8)
2582
				numDI = MAX_BYTE_NUM * 8;
2583
			else
2584
				numDI = scopeDI - IndexDI;
2585
			if (numDI > 0)
2586
				len = OperateRegister(WillSendType, IndexDI, numDI);
2587
			break;
2588

    
2589
		case 3://read AIO R/W
2590
			if ((scopeAI - IndexAI) > MAX_BYTE_NUM / 2)
2591
				numAI = MAX_BYTE_NUM / 2;
2592
			else
2593
				numAI = scopeAI - IndexAI;
2594
			if (numAI > 0)
2595
				len = OperateRegister(WillSendType, IndexAI, numAI);
2596
			break;
2597

    
2598
		case 4://read AIO R/W
2599
			if ((scopeAI - IndexAI) > MAX_BYTE_NUM / 2)
2600
				numAI = MAX_BYTE_NUM / 2;
2601
			else
2602
				numAI = scopeAI - IndexAI;
2603
			if (numAI > 0)
2604
				len = OperateRegister(WillSendType, IndexAI, numAI);
2605
			break;
2606

    
2607
			default:
2608
			break;
2609
	}
2610

    
2611
	if (len > 0)
2612
		pLink->SetCommStatus(CMST_RX_CNT);
2613

    
2614
	return len;
2615
}
2616

    
2617

    
2618

    
2619

    
2620
//??Լ???󴴽?????
2621
#ifdef __unix
2622
extern "C" CProtocol * CreateProtocol(char* defpara)
2623
#else
2624
extern "C" __declspec(dllexport)  CProtocol * CreateProtocol(char* defpara)
2625
#endif
2626
{
2627
	CProtocol* pEpv = new CModbusTcpc;
2628
	return pEpv;
2629
}
2630

    
(3-3/3)