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 || 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 || 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) //??Ϊ?¼ӵ?????? ʹ??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
|
if (cmdlist[i].func == 16)
|
763
|
{
|
764
|
if (cmdlist[i].r_type == 1)
|
765
|
{
|
766
|
Operate_16(cmdlist[i].address, 1, (uint16)ycVal, cmdlist[i].func);
|
767
|
}
|
768
|
else
|
769
|
{
|
770
|
Operate_16(cmdlist[i].address, 1, (sint16)ycVal, cmdlist[i].func);
|
771
|
}
|
772
|
}
|
773
|
else {
|
774
|
if (cmdlist[i].func == 6)
|
775
|
len = OperateRegister(/*6*/cmdlist[i].func, cmdlist[i].address, (uint16)ycVal);
|
776
|
}
|
777
|
}
|
778
|
else continue;
|
779
|
//WillSendType = 6;
|
780
|
|
781
|
b_ret = TRUE;
|
782
|
}
|
783
|
break;
|
784
|
}
|
785
|
}
|
786
|
}
|
787
|
PrintLog(LOG_WARNING, "<<<<< YK no=%d val=%d", ykno, cmdinfo->ctlVal);
|
788
|
}
|
789
|
break;
|
790
|
|
791
|
case DC_K_CTL_DODEL://????
|
792
|
break;
|
793
|
}
|
794
|
}
|
795
|
break;
|
796
|
|
797
|
case DC_K_CMD_AOOPER:
|
798
|
{
|
799
|
S_AO_CTL* aoinfo;
|
800
|
aoinfo = (S_AO_CTL*)(&rawcmd.data);
|
801
|
switch (aoinfo->funcCode)
|
802
|
{
|
803
|
case DC_K_CTL_AOSEL://ѡ??
|
804
|
//ֱ?ӷ?У
|
805
|
rawcmd.type = DC_K_CMDRET_AOOPER;
|
806
|
rawcmd.len = sizeof(aoinfo);
|
807
|
rawcmd.src = m_cmdaddr;
|
808
|
aoinfo->retCode = 1;
|
809
|
pCmdMem->RptAResult(rtuno, rawcmd);
|
810
|
break;
|
811
|
|
812
|
case DC_K_CTL_AOEXE://ִ??
|
813
|
{
|
814
|
sint32 ytvalue = (sint32)(aoinfo->ptVal);
|
815
|
uint16 ptno = aoinfo->ptAddr;
|
816
|
for (int i = 0; i < cmdlength; i++)
|
817
|
{
|
818
|
if (cmdlist[i].m_type == 1)
|
819
|
continue;
|
820
|
if (cmdlist[i].pointnum == ptno)
|
821
|
{
|
822
|
if (cmdlist[i].func == 16)
|
823
|
{
|
824
|
if (cmdlist[i].r_type == 1)
|
825
|
{
|
826
|
Operate_16(cmdlist[i].address, 1, (uint16)ytvalue, cmdlist[i].func);
|
827
|
}
|
828
|
else
|
829
|
{
|
830
|
Operate_16(cmdlist[i].address, 1, (sint16)ytvalue, cmdlist[i].func);
|
831
|
}
|
832
|
b_ret = TRUE;
|
833
|
break;
|
834
|
}
|
835
|
if (cmdlist[i].func == 6)
|
836
|
{
|
837
|
if (ptno >= 1)
|
838
|
{
|
839
|
if (cmdlist[i].va == 1) //???????ΪDO
|
840
|
{
|
841
|
continue;
|
842
|
float32 yctmp = 0;
|
843
|
uint16 ytVal = 1 << cmdlist[i].start;
|
844
|
PRawCtrl->GetAYc(rtuno, cmdlist[i].pointnum, &yctmp);
|
845
|
uint16 ycVal = (uint16)yctmp;
|
846
|
uint16 ykvalue;
|
847
|
if (ytvalue == 0)
|
848
|
{//??բ
|
849
|
ycVal = ycVal & (~ytVal);
|
850
|
}
|
851
|
if (ytvalue == 1)
|
852
|
{//??բ
|
853
|
ycVal = ycVal | (ytVal);
|
854
|
}
|
855
|
len = OperateRegister(6, cmdlist[i].address, (uint16)ycVal);
|
856
|
}
|
857
|
else
|
858
|
{
|
859
|
if (cmdlist[i].r_type == 1)
|
860
|
{
|
861
|
len = OperateRegister(6, cmdlist[i].address, (uint16)ytvalue);
|
862
|
}
|
863
|
else if (cmdlist[i].r_type == 2)
|
864
|
{
|
865
|
len = OperateRegister(6, cmdlist[i].address, (sint16)ytvalue);
|
866
|
}
|
867
|
}
|
868
|
//WillSendType = 6;
|
869
|
|
870
|
b_ret = TRUE;
|
871
|
}
|
872
|
break;
|
873
|
}
|
874
|
}
|
875
|
}
|
876
|
//<wyf>
|
877
|
PrintLog(LOG_WARNING, "<<<<<< YT no=%d val=%d", ptno, ytvalue);
|
878
|
}
|
879
|
break;
|
880
|
|
881
|
case DC_K_CTL_AODEL://????
|
882
|
break;
|
883
|
|
884
|
default:
|
885
|
break;
|
886
|
}
|
887
|
}
|
888
|
break;
|
889
|
|
890
|
default: //?????????·????????
|
891
|
break;
|
892
|
}
|
893
|
|
894
|
pCmdMem->DelACmd(rtuno);
|
895
|
return b_ret;
|
896
|
}
|
897
|
|
898
|
|
899
|
|
900
|
sint32 CModbusTcpc::CheckFrameHeader(uint8* buff, sint32 len) //??Ϣ?ż???
|
901
|
{
|
902
|
if (len < 7)
|
903
|
return 0;
|
904
|
|
905
|
if (buff[0] != cnt_sequence / 256 || buff[1] != cnt_sequence % 256)
|
906
|
return -1;
|
907
|
|
908
|
sint32 rtuno = pLink->GetRtuNo();
|
909
|
uint8 rtuaddr = pRtu->GetRtuAddr(rtuno);
|
910
|
|
911
|
if (buff[2] != 0 || buff[3] != 0 || buff[6] != rtuaddr)
|
912
|
return -2;
|
913
|
|
914
|
return 1;
|
915
|
}
|
916
|
|
917
|
uint8 CModbusTcpc::ErrorHandle(uint8 errfunc)
|
918
|
{
|
919
|
uint8 retFunc = errfunc & 0x7f;
|
920
|
if (retFunc != WillSendType) //???????
|
921
|
return 0;
|
922
|
|
923
|
duquIndex = 0;
|
924
|
visitednum = 0;
|
925
|
GetWillSendType();
|
926
|
|
927
|
|
928
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
929
|
pLink->SetCommStatus(CMST_NORMAL);
|
930
|
PrintLog(LOG_ERROR, "------- ???????¶?ȡ!");
|
931
|
|
932
|
|
933
|
|
934
|
return 1;
|
935
|
}
|
936
|
|
937
|
|
938
|
|
939
|
uint8 CModbusTcpc::OperateRegister(uint8 FuncNo, uint16 Address, sint16 Value) //??????1??2??3??4??5??6?????
|
940
|
{
|
941
|
uint8 txbuff[256];
|
942
|
sint32 rtuno = pLink->GetRtuNo();
|
943
|
uint8 rtuadd = pRtu->GetRtuAddr(rtuno);
|
944
|
uint8 len = 0;
|
945
|
if (cnt_sequence >= 65535)
|
946
|
cnt_sequence = 0;
|
947
|
else
|
948
|
cnt_sequence++;
|
949
|
//7bytes Head
|
950
|
txbuff[len++] = cnt_sequence / 0x100;//H Transaction Identifier
|
951
|
txbuff[len++] = cnt_sequence % 0x100;//L
|
952
|
txbuff[len++] = 0;//Protocol Identifier "0 = MODBUS protocol"
|
953
|
txbuff[len++] = 0;
|
954
|
txbuff[len++] = 0;//len_H
|
955
|
txbuff[len++] = 6;//len_L
|
956
|
txbuff[len++] = rtuadd;//Unit Identifier
|
957
|
|
958
|
txbuff[len++] = FuncNo;
|
959
|
txbuff[len++] = Address / 0x100;//??
|
960
|
txbuff[len++] = Address % 0x100;//??
|
961
|
txbuff[len++] = Value / 0x100;//??
|
962
|
txbuff[len++] = Value % 0x100;//??
|
963
|
|
964
|
// pLink->RegisterFrmCode(RAW_CODEDIR_DOWN,(char *)txbuff,len);
|
965
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
966
|
pTxBuf->Write(txbuff, len);
|
967
|
pLink->SetCommStatus(CMST_RX_CNT);
|
968
|
m_LastSendTime = GetNowMilliSecond();
|
969
|
|
970
|
PrintLog(LOG_INFORMATION, ">>>>>> SendType = %d ,start=%d ,num=%d", WillSendType, Address, Value);
|
971
|
|
972
|
return len;
|
973
|
}
|
974
|
|
975
|
|
976
|
|
977
|
uint8 CModbusTcpc::OperateRegister(uint8 FuncNo, uint16 Address, uint16 Value)
|
978
|
{
|
979
|
uint8 txbuff[256];
|
980
|
sint32 rtuno = pLink->GetRtuNo();
|
981
|
uint8 rtuadd = pRtu->GetRtuAddr(rtuno);
|
982
|
uint8 len = 0;
|
983
|
if (cnt_sequence >= 65535)
|
984
|
cnt_sequence = 0;
|
985
|
else
|
986
|
cnt_sequence++;
|
987
|
//7bytes Head
|
988
|
txbuff[len++] = cnt_sequence / 0x100;//H Transaction Identifier
|
989
|
txbuff[len++] = cnt_sequence % 0x100;//L
|
990
|
txbuff[len++] = 0;//Protocol Identifier "0 = MODBUS protocol"
|
991
|
txbuff[len++] = 0;
|
992
|
txbuff[len++] = 0;//len_H
|
993
|
txbuff[len++] = 6;//len_L
|
994
|
txbuff[len++] = rtuadd;//Unit Identifier
|
995
|
|
996
|
txbuff[len++] = FuncNo;
|
997
|
txbuff[len++] = Address / 0x100;//??
|
998
|
txbuff[len++] = Address % 0x100;//??
|
999
|
txbuff[len++] = Value / 0x100;//??
|
1000
|
txbuff[len++] = Value % 0x100;//??
|
1001
|
|
1002
|
// pLink->RegisterFrmCode(RAW_CODEDIR_DOWN,(char *)txbuff,len);
|
1003
|
pLink->RegisterFrm(FRAME_TX_SUC);
|
1004
|
pTxBuf->Write(txbuff, len);
|
1005
|
pLink->SetCommStatus(CMST_RX_CNT);
|
1006
|
m_LastSendTime = GetNowMilliSecond();
|
1007
|
|
1008
|
PrintLog(LOG_INFORMATION, ">>>>>> SendType = %d ,start=%d ,num=%d", WillSendType, Address, Value);
|
1009
|
|
1010
|
return len;
|
1011
|
}
|
1012
|
|
1013
|
|
1014
|
|
1015
|
|
1016
|
int CModbusTcpc::ComparePoint(uint16 YxYcId, uint8& value) //?Ա?????Ӧ?????ݴ??? 01??02 ???????DI?????? bit
|
1017
|
{
|
1018
|
if (WillSendType == 1 || WillSendType == 2) {
|
1019
|
if (maplist[mapIndex].address == YxYcId) //Ϊ?˼???ѭ?? ?????ж? ??ͬ??ȥ???????
|
1020
|
{
|
1021
|
int fbit = 0;
|
1022
|
if (maplist[mapIndex].end == 0) //endΪ0˵??Ϊһλ ȡһ???ֽ????ݵĵ?0λ????????????һλ
|
1023
|
{
|
1024
|
maplist[mapIndex].data.datauint16 = value & 1;
|
1025
|
maplist[mapIndex].visited = 1;
|
1026
|
mapIndex++;
|
1027
|
mapnum++;
|
1028
|
value >>= 1;
|
1029
|
return 0;
|
1030
|
}
|
1031
|
else //end??Ϊ0 ȡһ???ֽ?endλ??????һλ
|
1032
|
{
|
1033
|
for (int i = 0; i <= maplist[mapIndex].end; i++) {
|
1034
|
fbit += pow(2, i);
|
1035
|
}
|
1036
|
maplist[mapIndex].data.datauint16 = value & fbit;
|
1037
|
maplist[mapIndex].visited = 1;
|
1038
|
mapIndex++;
|
1039
|
mapnum++;
|
1040
|
value >>= 1;
|
1041
|
return 0;
|
1042
|
}
|
1043
|
}
|
1044
|
if (maplist[mapIndex].address > YxYcId) //??????end??Ϊ0????? ʹ?õ?ַ???ڵ?ǰYxYcId ????1λֱ?????
|
1045
|
{
|
1046
|
value >>= 1;
|
1047
|
return -1;
|
1048
|
}
|
1049
|
for (int i = 0; i < maplength; i++) //????????жϵ?ַ????Ⱦͱ?????һ??
|
1050
|
{
|
1051
|
if (maplist[i].visited == 1)
|
1052
|
continue;
|
1053
|
if (maplist[i].address == YxYcId) {
|
1054
|
int fbit = 0;
|
1055
|
if (maplist[i].end == 0) {
|
1056
|
maplist[i].data.datauint16 = value & 1;
|
1057
|
maplist[i].visited = 1;
|
1058
|
mapIndex = i + 1;
|
1059
|
mapnum++;
|
1060
|
value >>= 1;
|
1061
|
return 0;
|
1062
|
}
|
1063
|
else {
|
1064
|
for (int i = 0; i <= maplist[i].end; i++) {
|
1065
|
fbit += pow(2, i);
|
1066
|
}
|
1067
|
maplist[i].data.datauint16 = value & fbit;
|
1068
|
maplist[i].visited = 1;
|
1069
|
mapIndex = i + 1;
|
1070
|
mapnum++;
|
1071
|
value >>= 1;
|
1072
|
return 0;
|
1073
|
}
|
1074
|
}
|
1075
|
}
|
1076
|
return -1;
|
1077
|
value >>= 1;
|
1078
|
}
|
1079
|
return -2;
|
1080
|
}
|
1081
|
|
1082
|
|
1083
|
|
1084
|
int CModbusTcpc::ComparePoint_reg(uint16 YxYcId, uint8* buf, int i) //?Ա?????Ӧ?????ݴ???03??04???? ??????ͬ???͵?DI??AI??PI??VA????
|
1085
|
{
|
1086
|
if (WillSendType == 3 || WillSendType == 4)
|
1087
|
{
|
1088
|
if (maplist[mapIndex].address == YxYcId) //???ж? Ϊ?˼???ѭ??
|
1089
|
{
|
1090
|
if (maplist[mapIndex].m_type == 0) //VA???ݣ?ֱ?Ӽ??????? ռһ???Ĵ??? ???ֽ? 16λ
|
1091
|
{
|
1092
|
maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]; //??8λ????????8λ+??8λ
|
1093
|
maplist[mapIndex].visited = 1; //??ȡ??־??Ϊ1
|
1094
|
mapIndex++;
|
1095
|
mapnum++;
|
1096
|
return 0;
|
1097
|
}
|
1098
|
|
1099
|
|
1100
|
if (maplist[mapIndex].start == 0 && maplist[mapIndex].end == 15) //??1???Ĵ??????
|
1101
|
{
|
1102
|
if (maplist[mapIndex].m_type == 3) //AI???? 16λ??ǰ
|
1103
|
{
|
1104
|
if (maplist[mapIndex].r_type == 1) //uint??????
|
1105
|
maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]; //??8λ????????8λ+??8λ
|
1106
|
else //int??????
|
1107
|
maplist[mapIndex].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1108
|
maplist[mapIndex].visited = 1;
|
1109
|
mapIndex++;
|
1110
|
mapnum++;
|
1111
|
return 0;
|
1112
|
}
|
1113
|
if (maplist[mapIndex].m_type == 4) //AI???? 16λrvǰ rv??ǰ?????Ĵ????ڲ??ֽ?ǰ?ͺ??
|
1114
|
{
|
1115
|
if (maplist[mapIndex].r_type == 1)
|
1116
|
maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]; //??8λ????????8λ+??8λ
|
1117
|
else
|
1118
|
maplist[mapIndex].data.datasint16 = (sint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];
|
1119
|
maplist[mapIndex].visited = 1;
|
1120
|
mapIndex++;
|
1121
|
mapnum++;
|
1122
|
return 0;
|
1123
|
}
|
1124
|
if (maplist[mapIndex].m_type == 9) //PI???? ע????PI????ֻ??int16??int32??uint16??uint32??float??5??????
|
1125
|
{
|
1126
|
if (maplist[mapIndex].r_type == 1)
|
1127
|
maplist[mapIndex].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1128
|
else
|
1129
|
maplist[mapIndex].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1130
|
maplist[mapIndex].visited = 1;
|
1131
|
mapIndex++;
|
1132
|
mapnum++;
|
1133
|
return 0;
|
1134
|
}
|
1135
|
|
1136
|
}
|
1137
|
|
1138
|
|
1139
|
if (maplist[mapIndex].start > 0 || maplist[mapIndex].end < 15) //???ݲ???һ?????Ĵ????????
|
1140
|
{
|
1141
|
int fbit = 0;
|
1142
|
if (maplist[mapIndex].m_type == 3 || maplist[mapIndex].m_type == 1) //??Ϊrv???
|
1143
|
{
|
1144
|
for (int i = maplist[mapIndex].start; i <= maplist[mapIndex].end; i++) //??fbitΪ?ӿ?ʼ??????λΪ1
|
1145
|
{
|
1146
|
fbit += pow(2, i); //pow????Ϊ??2??i?η?
|
1147
|
}
|
1148
|
if (maplist[mapIndex].r_type == 1){
|
1149
|
maplist[mapIndex].data.datauint16 = (uint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit; //ȡ??ʼ??????λ???ݣ?????λ??Ϊ0
|
1150
|
maplist[mapIndex].data.datauint16 >>= maplist[mapIndex].start; //???ƿ?ʼλ???ݼ????Ҳ???????Ϊ0??????ȥ??
|
1151
|
}
|
1152
|
else{
|
1153
|
maplist[mapIndex].data.datasint16 = (sint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1154
|
maplist[mapIndex].data.datasint16 >>= maplist[mapIndex].start;
|
1155
|
}
|
1156
|
maplist[mapIndex].visited = 1;
|
1157
|
mapIndex++;
|
1158
|
mapnum++;
|
1159
|
return 1;
|
1160
|
}
|
1161
|
if (maplist[mapIndex].m_type == 4 || maplist[mapIndex].m_type == 2) //rv??? ????Ϊ?ߵ??ֽڵ????Ƽ???
|
1162
|
{
|
1163
|
for (int i = maplist[mapIndex].start; i <= maplist[mapIndex].end; i++) {
|
1164
|
fbit += pow(2, i);
|
1165
|
}
|
1166
|
if (maplist[mapIndex].r_type == 1){
|
1167
|
maplist[mapIndex].data.datauint16 = (uint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1168
|
maplist[mapIndex].data.datauint16 >>= maplist[mapIndex].start;
|
1169
|
}
|
1170
|
else{
|
1171
|
maplist[mapIndex].data.datasint16 = (sint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1172
|
maplist[mapIndex].data.datasint16 >>= maplist[mapIndex].start;
|
1173
|
}
|
1174
|
maplist[mapIndex].visited = 1;
|
1175
|
mapIndex++;
|
1176
|
mapnum++;
|
1177
|
return 1;
|
1178
|
}
|
1179
|
}
|
1180
|
|
1181
|
|
1182
|
|
1183
|
if (maplist[mapIndex].end > 15) //?õ??????Ĵ????????
|
1184
|
{
|
1185
|
int fbit = 0;
|
1186
|
if (maplist[mapIndex].m_type == 5) //32λ??ǰ AI??
|
1187
|
{
|
1188
|
if (maplist[mapIndex].r_type == 3) //float??
|
1189
|
{
|
1190
|
FCHAR4 value;
|
1191
|
value.val2.b4 = buf[3 + 2 * i + 2];
|
1192
|
value.val2.b3 = buf[3 + 2 * i + 1 + 2];
|
1193
|
value.val2.b2 = buf[3 + 2 * i];
|
1194
|
value.val2.b1 = buf[3 + 2 * i + 1];
|
1195
|
|
1196
|
maplist[mapIndex].data.datafloat = value.val1;
|
1197
|
|
1198
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
|
1199
|
maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
|
1200
|
maplist[mapIndex].visited = 1;
|
1201
|
mapIndex = mapIndex + 1;
|
1202
|
mapnum++;
|
1203
|
return 1;
|
1204
|
}
|
1205
|
if (maplist[mapIndex].r_type == 4) //int32 ??
|
1206
|
{
|
1207
|
if (maplist[mapIndex].start > 0) //??ʼλ??Ϊ0 ǰ?Ĵ??????????
|
1208
|
{
|
1209
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1210
|
fbit += pow(2, i);
|
1211
|
}
|
1212
|
maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit; //????ͼĴ???????Ӧֵ
|
1213
|
maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start; //???ƿ?ʼλ ȥ???Ҳ?????????0
|
1214
|
fbit = 0;
|
1215
|
}
|
1216
|
else{
|
1217
|
maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]); //ǰ?Ĵ??????????
|
1218
|
}
|
1219
|
if (maplist[mapIndex].end < 31) //??Ĵ??????Ĵ??????????
|
1220
|
{
|
1221
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1222
|
fbit += pow(2, i);
|
1223
|
}
|
1224
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit; //?????Ĵ?????Ӧ??ֵ??ȡ????Ӧλ???? ??????0
|
1225
|
fbit = 0;
|
1226
|
maplist[mapIndex].data.datasint32 = (sint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datasint32; //ǰ??Ĵ??????ݺϲ? ????Ϊ?Ĵ??????ƵͼĴ???ֵ??λ??????ͼĴ???ֵ???
|
1227
|
}
|
1228
|
else{
|
1229
|
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λ????ǰ?Ĵ???ֵ???
|
1230
|
}
|
1231
|
maplist[mapIndex].visited = 1;
|
1232
|
mapIndex = mapIndex + 1;
|
1233
|
mapnum++;
|
1234
|
return 1;
|
1235
|
}
|
1236
|
if (maplist[mapIndex].r_type == 5) //uint32 ??
|
1237
|
{
|
1238
|
if (maplist[mapIndex].start > 0){
|
1239
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1240
|
fbit += pow(2, i);
|
1241
|
}
|
1242
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1243
|
maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
|
1244
|
fbit = 0;
|
1245
|
}
|
1246
|
else{
|
1247
|
maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1248
|
}
|
1249
|
if (maplist[mapIndex].end < 31){
|
1250
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1251
|
fbit += pow(2, i);
|
1252
|
}
|
1253
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1254
|
fbit = 0;
|
1255
|
maplist[mapIndex].data.datauint32 = (uint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datauint32;
|
1256
|
}
|
1257
|
else{
|
1258
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datauint32;
|
1259
|
}
|
1260
|
maplist[mapIndex].visited = 1;
|
1261
|
mapIndex = mapIndex + 1;
|
1262
|
mapnum++;
|
1263
|
return 1;
|
1264
|
}
|
1265
|
}
|
1266
|
|
1267
|
if (maplist[mapIndex].m_type == 6) //32λAI?? ӵ??swǰ sw??ǰ????ǰ?Ĵ???Ϊ??λ????Ĵ???Ϊ??λ;
|
1268
|
{
|
1269
|
if (maplist[mapIndex].r_type == 3){
|
1270
|
FCHAR4 value;
|
1271
|
value.val2.b4 = buf[3 + 2 * i];
|
1272
|
value.val2.b3 = buf[3 + 2 * i + 1];
|
1273
|
value.val2.b2 = buf[3 + 2 * i + 2];
|
1274
|
value.val2.b1 = buf[3 + 2 * i + 1 + 2];
|
1275
|
|
1276
|
maplist[mapIndex].data.datafloat = value.val1;
|
1277
|
|
1278
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
|
1279
|
maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]);*/
|
1280
|
maplist[mapIndex].visited = 1;
|
1281
|
mapIndex = mapIndex + 1;
|
1282
|
mapnum++;
|
1283
|
return 1;
|
1284
|
}
|
1285
|
if (maplist[mapIndex].r_type == 4){
|
1286
|
if (maplist[mapIndex].start > 0){
|
1287
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1288
|
fbit += pow(2, i);
|
1289
|
}
|
1290
|
maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1291
|
maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;
|
1292
|
fbit = 0;
|
1293
|
}
|
1294
|
else{
|
1295
|
maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1296
|
}
|
1297
|
if (maplist[mapIndex].end < 31){
|
1298
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1299
|
fbit += pow(2, i);
|
1300
|
}
|
1301
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1302
|
fbit = 0;
|
1303
|
maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 << (maplist[mapIndex].end - 15) | temp; //??Ҫ????Ϊǰ?Ĵ???ֵ???ƺ?Ĵ???ֵλ???????Ĵ???ֵ???
|
1304
|
}
|
1305
|
else{
|
1306
|
maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
|
1307
|
}
|
1308
|
maplist[mapIndex].visited = 1;
|
1309
|
mapIndex = mapIndex + 1;
|
1310
|
mapnum++;
|
1311
|
return 1;
|
1312
|
}
|
1313
|
if (maplist[mapIndex].r_type == 5){
|
1314
|
if (maplist[mapIndex].start > 0){
|
1315
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1316
|
fbit += pow(2, i);
|
1317
|
}
|
1318
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1319
|
maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
|
1320
|
fbit = 0;
|
1321
|
}
|
1322
|
else{
|
1323
|
maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1324
|
}
|
1325
|
if (maplist[mapIndex].end < 31){
|
1326
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1327
|
fbit += pow(2, i);
|
1328
|
}
|
1329
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1330
|
fbit = 0;
|
1331
|
maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 << (maplist[mapIndex].end - 15) | temp;
|
1332
|
}
|
1333
|
else{
|
1334
|
maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
|
1335
|
}
|
1336
|
maplist[mapIndex].visited = 1;
|
1337
|
mapIndex = mapIndex + 1;
|
1338
|
mapnum++;
|
1339
|
return 1;
|
1340
|
}
|
1341
|
}
|
1342
|
|
1343
|
|
1344
|
if (maplist[mapIndex].m_type == 7) //32λAI?? ӵ??rvǰ rv??ǰ?????Ĵ????ڲ??ֽ?ǰ?ͺ??
|
1345
|
{
|
1346
|
if (maplist[mapIndex].r_type == 3){
|
1347
|
FCHAR4 value;
|
1348
|
value.val2.b4 = buf[3 + 2 * i + 1 + 2];
|
1349
|
value.val2.b3 = buf[3 + 2 * i + 2];
|
1350
|
value.val2.b2 = buf[3 + 2 * i + 1];
|
1351
|
value.val2.b1 = buf[3 + 2 * i];
|
1352
|
|
1353
|
maplist[mapIndex].data.datafloat = value.val1;
|
1354
|
|
1355
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
|
1356
|
maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
|
1357
|
maplist[mapIndex].visited = 1;
|
1358
|
mapIndex = mapIndex + 1;
|
1359
|
mapnum++;
|
1360
|
return 1;
|
1361
|
}
|
1362
|
if (maplist[mapIndex].r_type == 4){
|
1363
|
if (maplist[mapIndex].start > 0){
|
1364
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1365
|
fbit += pow(2, i);
|
1366
|
}
|
1367
|
maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1368
|
maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;
|
1369
|
fbit = 0;
|
1370
|
}
|
1371
|
else{
|
1372
|
maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1373
|
}
|
1374
|
if (maplist[mapIndex].end < 31){
|
1375
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1376
|
fbit += pow(2, i);
|
1377
|
}
|
1378
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1379
|
fbit = 0;
|
1380
|
maplist[mapIndex].data.datasint32 = (sint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datasint32;
|
1381
|
}
|
1382
|
else{
|
1383
|
maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) *pow(2, 16) + maplist[mapIndex].data.datasint32;
|
1384
|
}
|
1385
|
maplist[mapIndex].visited = 1;
|
1386
|
mapIndex = mapIndex + 1;
|
1387
|
mapnum++;
|
1388
|
return 1;
|
1389
|
}
|
1390
|
if (maplist[mapIndex].r_type == 5){
|
1391
|
if (maplist[mapIndex].start > 0){
|
1392
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1393
|
fbit += pow(2, i);
|
1394
|
}
|
1395
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1396
|
maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
|
1397
|
fbit = 0;
|
1398
|
}
|
1399
|
else{
|
1400
|
maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1401
|
}
|
1402
|
if (maplist[mapIndex].end < 31){
|
1403
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1404
|
fbit += pow(2, i);
|
1405
|
}
|
1406
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1407
|
fbit = 0;
|
1408
|
maplist[mapIndex].data.datauint32 = (uint32)temp << (16 - maplist[mapIndex].start) | maplist[mapIndex].data.datauint32;
|
1409
|
}
|
1410
|
else{
|
1411
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) *pow(2, 16) + maplist[mapIndex].data.datauint32;
|
1412
|
}
|
1413
|
maplist[mapIndex].visited = 1;
|
1414
|
mapIndex = mapIndex + 1;
|
1415
|
mapnum++;
|
1416
|
return 1;
|
1417
|
}
|
1418
|
}
|
1419
|
|
1420
|
|
1421
|
|
1422
|
|
1423
|
|
1424
|
if (maplist[mapIndex].m_type == 8) //32λAI?? ͬʱӵ??sw??rvǰ
|
1425
|
{
|
1426
|
if (maplist[mapIndex].r_type == 3){
|
1427
|
FCHAR4 value;
|
1428
|
value.val2.b4 = buf[3 + 2 * i + 1];
|
1429
|
value.val2.b3 = buf[3 + 2 * i];
|
1430
|
value.val2.b2 = buf[3 + 2 * i + 1 + 2];
|
1431
|
value.val2.b1 = buf[3 + 2 * i + 2];
|
1432
|
|
1433
|
maplist[mapIndex].data.datafloat = value.val1;
|
1434
|
|
1435
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
|
1436
|
maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]);*/
|
1437
|
maplist[mapIndex].visited = 1;
|
1438
|
mapIndex = mapIndex + 1;
|
1439
|
mapnum++;
|
1440
|
return 1;
|
1441
|
}
|
1442
|
if (maplist[mapIndex].r_type == 4)
|
1443
|
{
|
1444
|
if (maplist[mapIndex].start > 0){
|
1445
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1446
|
fbit += pow(2, i);
|
1447
|
}
|
1448
|
maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1449
|
maplist[mapIndex].data.datasint32 >>= maplist[mapIndex].start;
|
1450
|
fbit = 0;
|
1451
|
}
|
1452
|
else{
|
1453
|
maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1454
|
}
|
1455
|
if (maplist[mapIndex].end < 31)
|
1456
|
{
|
1457
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1458
|
fbit += pow(2, i);
|
1459
|
}
|
1460
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1461
|
fbit = 0;
|
1462
|
maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 << (maplist[mapIndex].end - 15) | temp;
|
1463
|
}
|
1464
|
else{
|
1465
|
maplist[mapIndex].data.datasint32 = (sint32)maplist[mapIndex].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
|
1466
|
}
|
1467
|
maplist[mapIndex].visited = 1;
|
1468
|
mapIndex = mapIndex + 1;
|
1469
|
mapnum++;
|
1470
|
return 1;
|
1471
|
}
|
1472
|
if (maplist[mapIndex].r_type == 5){
|
1473
|
if (maplist[mapIndex].start > 0){
|
1474
|
for (int i = maplist[mapIndex].start; i < 16; i++) {
|
1475
|
fbit += pow(2, i);
|
1476
|
}
|
1477
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1478
|
maplist[mapIndex].data.datauint32 >>= maplist[mapIndex].start;
|
1479
|
fbit = 0;
|
1480
|
}
|
1481
|
else{
|
1482
|
maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1483
|
}
|
1484
|
if (maplist[mapIndex].end < 31){
|
1485
|
for (int i = 0; i <= maplist[mapIndex].end - 16; i++) {
|
1486
|
fbit += pow(2, i);
|
1487
|
}
|
1488
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1489
|
fbit = 0;
|
1490
|
maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 << (maplist[mapIndex].end - 15) | temp;
|
1491
|
}
|
1492
|
else{
|
1493
|
maplist[mapIndex].data.datauint32 = (uint32)maplist[mapIndex].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
|
1494
|
}
|
1495
|
maplist[mapIndex].visited = 1;
|
1496
|
mapIndex = mapIndex + 1;
|
1497
|
mapnum++;
|
1498
|
return 1;
|
1499
|
}
|
1500
|
}
|
1501
|
|
1502
|
|
1503
|
if (maplist[mapIndex].m_type == 9) //32λPI??
|
1504
|
{
|
1505
|
if (maplist[mapIndex].r_type == 3)
|
1506
|
{
|
1507
|
maplist[mapIndex].data.datafloat = (float)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1508
|
maplist[mapIndex].data.datafloat = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;
|
1509
|
maplist[mapIndex].visited = 1;
|
1510
|
mapIndex = mapIndex + 1;
|
1511
|
mapnum++;
|
1512
|
return 0;
|
1513
|
}
|
1514
|
|
1515
|
if (maplist[mapIndex].r_type == 4)
|
1516
|
{
|
1517
|
maplist[mapIndex].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1518
|
maplist[mapIndex].data.datasint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datasint32;
|
1519
|
maplist[mapIndex].visited = 1;
|
1520
|
mapIndex = mapIndex + 1;
|
1521
|
mapnum++;
|
1522
|
return 0;
|
1523
|
}
|
1524
|
|
1525
|
if (maplist[mapIndex].r_type == 5)
|
1526
|
{
|
1527
|
maplist[mapIndex].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1528
|
maplist[mapIndex].data.datauint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datauint32;
|
1529
|
maplist[mapIndex].visited = 1;
|
1530
|
mapIndex = mapIndex + 1;
|
1531
|
mapnum++;
|
1532
|
return 0;
|
1533
|
}
|
1534
|
}
|
1535
|
}
|
1536
|
}
|
1537
|
|
1538
|
|
1539
|
if (maplist[mapIndex].address > YxYcId) //??Ϊ?жϼ???ѭ?? ??Ϊѭ????ʵ?? ??????ͬ
|
1540
|
{
|
1541
|
return -1;
|
1542
|
}
|
1543
|
for (int j = 0; j < maplength; j++) {
|
1544
|
if (maplist[j].visited == 1)
|
1545
|
continue;
|
1546
|
if (maplist[j].address == YxYcId) {
|
1547
|
if (maplist[j].m_type == 0){
|
1548
|
maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1549
|
maplist[j].visited = 1;
|
1550
|
mapIndex = j + 1;
|
1551
|
mapnum++;
|
1552
|
return 0;
|
1553
|
}
|
1554
|
|
1555
|
|
1556
|
if (maplist[j].start == 0 && maplist[j].end == 15)
|
1557
|
{
|
1558
|
if (maplist[j].m_type == 3){
|
1559
|
if (maplist[j].r_type == 1)
|
1560
|
maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1561
|
else
|
1562
|
maplist[j].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1563
|
maplist[j].visited = 1;
|
1564
|
mapIndex = j + 1;
|
1565
|
mapnum++;
|
1566
|
return 0;
|
1567
|
}
|
1568
|
if (maplist[j].m_type == 4){
|
1569
|
if (maplist[j].r_type == 1)
|
1570
|
maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];
|
1571
|
else
|
1572
|
maplist[j].data.datasint16 = (sint16)256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i];
|
1573
|
maplist[j].visited = 1;
|
1574
|
mapIndex = j + 1;
|
1575
|
mapnum++;
|
1576
|
return 0;
|
1577
|
}
|
1578
|
if (maplist[j].m_type == 9)
|
1579
|
{
|
1580
|
if (maplist[j].r_type == 1)
|
1581
|
maplist[j].data.datauint16 = (uint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1582
|
else
|
1583
|
maplist[j].data.datasint16 = (sint16)256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1];
|
1584
|
maplist[j].visited = 1;
|
1585
|
mapIndex = j + 1;
|
1586
|
mapnum++;
|
1587
|
return 0;
|
1588
|
}
|
1589
|
|
1590
|
}
|
1591
|
|
1592
|
|
1593
|
if (maplist[j].start > 0 || maplist[j].end < 15) {
|
1594
|
int fbit = 0;
|
1595
|
if (maplist[j].m_type == 3 || maplist[j].m_type == 1){
|
1596
|
for (int i = maplist[j].start; i <= maplist[j].end; i++) {
|
1597
|
fbit += pow(2, i);
|
1598
|
}
|
1599
|
if (maplist[j].r_type == 1){
|
1600
|
maplist[j].data.datauint16 = (uint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1601
|
maplist[j].data.datauint16 >>= maplist[j].start;
|
1602
|
}
|
1603
|
else{
|
1604
|
maplist[j].data.datasint16 = (sint16)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1605
|
maplist[j].data.datasint16 >>= maplist[j].start;
|
1606
|
}
|
1607
|
maplist[j].visited = 1;
|
1608
|
mapIndex = j + 1;
|
1609
|
mapnum++;
|
1610
|
return 1;
|
1611
|
}
|
1612
|
if (maplist[j].m_type == 4 || maplist[j].m_type == 2){
|
1613
|
for (int i = maplist[j].start; i <= maplist[j].end; i++) {
|
1614
|
fbit += pow(2, i);
|
1615
|
}
|
1616
|
if (maplist[j].r_type == 1){
|
1617
|
maplist[j].data.datauint16 = (uint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1618
|
maplist[j].data.datauint16 >>= maplist[j].start;
|
1619
|
}
|
1620
|
else{
|
1621
|
maplist[j].data.datasint16 = (sint16)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1622
|
maplist[j].data.datasint16 >>= maplist[j].start;
|
1623
|
}
|
1624
|
maplist[j].visited = 1;
|
1625
|
mapIndex = j + 1;
|
1626
|
mapnum++;
|
1627
|
return 1;
|
1628
|
}
|
1629
|
}
|
1630
|
|
1631
|
|
1632
|
|
1633
|
if (maplist[j].end > 15) {
|
1634
|
int fbit = 0;
|
1635
|
if (maplist[j].m_type == 5){
|
1636
|
if (maplist[j].r_type == 3){
|
1637
|
FCHAR4 value;
|
1638
|
value.val2.b4 = buf[3 + 2 * i + 2];
|
1639
|
value.val2.b3 = buf[3 + 2 * i + 1 + 2];
|
1640
|
value.val2.b2 = buf[3 + 2 * i];
|
1641
|
value.val2.b1 = buf[3 + 2 * i + 1];
|
1642
|
|
1643
|
maplist[mapIndex].data.datafloat = value.val1;
|
1644
|
|
1645
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
|
1646
|
maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
|
1647
|
maplist[j].visited = 1;
|
1648
|
mapIndex = j + 1;
|
1649
|
mapnum++;
|
1650
|
return 1;
|
1651
|
}
|
1652
|
if (maplist[j].r_type == 4){
|
1653
|
if (maplist[j].start > 0){
|
1654
|
for (int i = maplist[j].start; i < 16; i++) {
|
1655
|
fbit += pow(2, i);
|
1656
|
}
|
1657
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1658
|
maplist[j].data.datasint32 >>= maplist[j].start;
|
1659
|
fbit = 0;
|
1660
|
}
|
1661
|
else{
|
1662
|
maplist[j].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1663
|
}
|
1664
|
if (maplist[j].end < 31){
|
1665
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1666
|
fbit += pow(2, i);
|
1667
|
}
|
1668
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1669
|
fbit = 0;
|
1670
|
maplist[j].data.datasint32 = (sint32)temp << (16 - maplist[j].start) | maplist[j].data.datasint32;
|
1671
|
}
|
1672
|
else{
|
1673
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datasint32;
|
1674
|
}
|
1675
|
maplist[j].visited = 1;
|
1676
|
mapIndex = j + 1;
|
1677
|
mapnum++;
|
1678
|
return 1;
|
1679
|
}
|
1680
|
if (maplist[j].r_type == 5){
|
1681
|
if (maplist[j].start > 0){
|
1682
|
for (int i = maplist[j].start; i < 16; i++) {
|
1683
|
fbit += pow(2, i);
|
1684
|
}
|
1685
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1686
|
maplist[j].data.datauint32 >>= maplist[j].start;
|
1687
|
fbit = 0;
|
1688
|
}
|
1689
|
else{
|
1690
|
maplist[j].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1691
|
}
|
1692
|
if (maplist[j].end < 31){
|
1693
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1694
|
fbit += pow(2, i);
|
1695
|
}
|
1696
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1697
|
fbit = 0;
|
1698
|
maplist[j].data.datauint32 = (uint32)temp << (16 - maplist[j].start) | maplist[j].data.datauint32;
|
1699
|
}
|
1700
|
else{
|
1701
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datauint32;
|
1702
|
}
|
1703
|
maplist[j].visited = 1;
|
1704
|
mapIndex = j + 1;
|
1705
|
mapnum++;
|
1706
|
return 1;
|
1707
|
}
|
1708
|
}
|
1709
|
|
1710
|
|
1711
|
|
1712
|
|
1713
|
|
1714
|
if (maplist[j].m_type == 6){
|
1715
|
if (maplist[j].r_type == 3){
|
1716
|
FCHAR4 value;
|
1717
|
value.val2.b4 = buf[3 + 2 * i];
|
1718
|
value.val2.b3 = buf[3 + 2 * i + 1];
|
1719
|
value.val2.b2 = buf[3 + 2 * i + 2];
|
1720
|
value.val2.b1 = buf[3 + 2 * i + 1 + 2];
|
1721
|
|
1722
|
maplist[mapIndex].data.datafloat = value.val1;
|
1723
|
|
1724
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i] + buf[3 + 2 * i + 1]);
|
1725
|
maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2] + buf[3 + 2 * i + 1 + 2]);*/
|
1726
|
maplist[j].visited = 1;
|
1727
|
mapIndex = j + 1;
|
1728
|
mapnum++;
|
1729
|
return 1;
|
1730
|
}
|
1731
|
if (maplist[j].r_type == 4){
|
1732
|
if (maplist[j].start > 0){
|
1733
|
for (int i = maplist[j].start; i < 16; i++) {
|
1734
|
fbit += pow(2, i);
|
1735
|
}
|
1736
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1737
|
maplist[j].data.datasint32 >>= maplist[j].start;
|
1738
|
fbit = 0;
|
1739
|
}
|
1740
|
else{
|
1741
|
maplist[j].data.datasint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1742
|
}
|
1743
|
if (maplist[j].end < 31){
|
1744
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1745
|
fbit += pow(2, i);
|
1746
|
}
|
1747
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1748
|
fbit = 0;
|
1749
|
maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 << (maplist[j].end - 15) | temp;
|
1750
|
}
|
1751
|
else{
|
1752
|
maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
|
1753
|
}
|
1754
|
maplist[j].visited = 1;
|
1755
|
mapIndex = j + 1;
|
1756
|
mapnum++;
|
1757
|
return 1;
|
1758
|
}
|
1759
|
if (maplist[j].r_type == 5){
|
1760
|
if (maplist[j].start > 0){
|
1761
|
for (int i = maplist[j].start; i < 16; i++) {
|
1762
|
fbit += pow(2, i);
|
1763
|
}
|
1764
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]) & fbit;
|
1765
|
maplist[j].data.datauint32 >>= maplist[j].start;
|
1766
|
fbit = 0;
|
1767
|
}
|
1768
|
else{
|
1769
|
maplist[j].data.datauint32 = (256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1770
|
}
|
1771
|
if (maplist[j].end < 31){
|
1772
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1773
|
fbit += pow(2, i);
|
1774
|
}
|
1775
|
uint16 temp = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) & fbit;
|
1776
|
fbit = 0;
|
1777
|
maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 << (maplist[j].end - 15) | temp;
|
1778
|
}
|
1779
|
else{
|
1780
|
maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]);
|
1781
|
}
|
1782
|
maplist[j].visited = 1;
|
1783
|
mapIndex = j + 1;
|
1784
|
mapnum++;
|
1785
|
return 1;
|
1786
|
}
|
1787
|
}
|
1788
|
|
1789
|
|
1790
|
|
1791
|
|
1792
|
|
1793
|
if (maplist[j].m_type == 7){
|
1794
|
if (maplist[j].r_type == 3){
|
1795
|
FCHAR4 value;
|
1796
|
value.val2.b4 = buf[3 + 2 * i + 1 + 2];
|
1797
|
value.val2.b3 = buf[3 + 2 * i + 2];
|
1798
|
value.val2.b2 = buf[3 + 2 * i + 1];
|
1799
|
value.val2.b1 = buf[3 + 2 * i];
|
1800
|
|
1801
|
maplist[mapIndex].data.datafloat = value.val1;
|
1802
|
|
1803
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
|
1804
|
maplist[mapIndex].data.datafloat = (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]) *pow(2, 16) + maplist[mapIndex].data.datafloat;*/
|
1805
|
maplist[j].visited = 1;
|
1806
|
mapIndex = j + 1;
|
1807
|
mapnum++;
|
1808
|
return 1;
|
1809
|
}
|
1810
|
if (maplist[j].r_type == 4){
|
1811
|
if (maplist[j].start > 0){
|
1812
|
for (int i = maplist[j].start; i < 16; i++) {
|
1813
|
fbit += pow(2, i);
|
1814
|
}
|
1815
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1816
|
maplist[j].data.datasint32 >>= maplist[j].start;
|
1817
|
fbit = 0;
|
1818
|
}
|
1819
|
else{
|
1820
|
maplist[j].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1821
|
}
|
1822
|
if (maplist[j].end < 31){
|
1823
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1824
|
fbit += pow(2, i);
|
1825
|
}
|
1826
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1827
|
fbit = 0;
|
1828
|
maplist[j].data.datasint32 = (sint32)temp << (16 - maplist[j].start) | maplist[j].data.datasint32;
|
1829
|
}
|
1830
|
else{
|
1831
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) *pow(2, 16) + maplist[j].data.datasint32;
|
1832
|
}
|
1833
|
maplist[j].visited = 1;
|
1834
|
mapIndex = j + 1;
|
1835
|
mapnum++;
|
1836
|
return 1;
|
1837
|
}
|
1838
|
if (maplist[j].r_type == 5){
|
1839
|
if (maplist[j].start > 0){
|
1840
|
for (int i = maplist[j].start; i < 16; i++) {
|
1841
|
fbit += pow(2, i);
|
1842
|
}
|
1843
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1844
|
maplist[j].data.datauint32 >>= maplist[j].start;
|
1845
|
fbit = 0;
|
1846
|
}
|
1847
|
else{
|
1848
|
maplist[j].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1849
|
}
|
1850
|
if (maplist[j].end < 31){
|
1851
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1852
|
fbit += pow(2, i);
|
1853
|
}
|
1854
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1855
|
fbit = 0;
|
1856
|
maplist[j].data.datauint32 = (uint32)temp << (16 - maplist[j].start) | maplist[j].data.datauint32;
|
1857
|
}
|
1858
|
else{
|
1859
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) *pow(2, 16) + maplist[j].data.datauint32;
|
1860
|
}
|
1861
|
maplist[j].visited = 1;
|
1862
|
mapIndex = j + 1;
|
1863
|
mapnum++;
|
1864
|
return 1;
|
1865
|
}
|
1866
|
}
|
1867
|
|
1868
|
|
1869
|
|
1870
|
|
1871
|
|
1872
|
if (maplist[j].m_type == 8){
|
1873
|
if (maplist[j].r_type == 3){
|
1874
|
FCHAR4 value;
|
1875
|
value.val2.b4 = buf[3 + 2 * i + 1];
|
1876
|
value.val2.b3 = buf[3 + 2 * i];
|
1877
|
value.val2.b2 = buf[3 + 2 * i + 1 + 2];
|
1878
|
value.val2.b1 = buf[3 + 2 * i + 2];
|
1879
|
|
1880
|
maplist[mapIndex].data.datafloat = value.val1;
|
1881
|
|
1882
|
/*maplist[mapIndex].data.datafloat = (float)(256 * buf[3 + 2 * i + 1] + buf[3 + 2 * i]);
|
1883
|
maplist[mapIndex].data.datafloat = maplist[mapIndex].data.datafloat *pow(2, 16) + (256 * buf[3 + 2 * i + 2 + 1] + buf[3 + 2 * i + 2]);*/
|
1884
|
maplist[j].visited = 1;
|
1885
|
mapIndex = j + 1;
|
1886
|
mapnum++;
|
1887
|
return 1;
|
1888
|
}
|
1889
|
if (maplist[j].r_type == 4){
|
1890
|
if (maplist[j].start > 0){
|
1891
|
for (int i = maplist[j].start; i < 16; i++) {
|
1892
|
fbit += pow(2, i);
|
1893
|
}
|
1894
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1895
|
maplist[j].data.datasint32 >>= maplist[j].start;
|
1896
|
fbit = 0;
|
1897
|
}
|
1898
|
else{
|
1899
|
maplist[j].data.datasint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1900
|
}
|
1901
|
if (maplist[j].end < 31){
|
1902
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1903
|
fbit += pow(2, i);
|
1904
|
}
|
1905
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1906
|
fbit = 0;
|
1907
|
maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 << (maplist[j].end - 15) | temp;
|
1908
|
}
|
1909
|
else{
|
1910
|
maplist[j].data.datasint32 = (sint32)maplist[j].data.datasint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
|
1911
|
}
|
1912
|
maplist[j].visited = 1;
|
1913
|
mapIndex = j + 1;
|
1914
|
mapnum++;
|
1915
|
return 1;
|
1916
|
}
|
1917
|
if (maplist[j].r_type == 5){
|
1918
|
if (maplist[j].start > 0){
|
1919
|
for (int i = maplist[j].start; i < 16; i++) {
|
1920
|
fbit += pow(2, i);
|
1921
|
}
|
1922
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]) & fbit;
|
1923
|
maplist[j].data.datauint32 >>= maplist[j].start;
|
1924
|
fbit = 0;
|
1925
|
}
|
1926
|
else{
|
1927
|
maplist[j].data.datauint32 = (256 * buf[9 + 2 * i + 1] + buf[9 + 2 * i]);
|
1928
|
}
|
1929
|
if (maplist[j].end < 31){
|
1930
|
for (int i = 0; i <= maplist[j].end - 16; i++) {
|
1931
|
fbit += pow(2, i);
|
1932
|
}
|
1933
|
uint16 temp = (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]) & fbit;
|
1934
|
fbit = 0;
|
1935
|
maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 << (maplist[j].end - 15) | temp;
|
1936
|
}
|
1937
|
else{
|
1938
|
maplist[j].data.datauint32 = (uint32)maplist[j].data.datauint32 *pow(2, 16) + (256 * buf[9 + 2 * i + 2 + 1] + buf[9 + 2 * i + 2]);
|
1939
|
}
|
1940
|
maplist[j].visited = 1;
|
1941
|
mapIndex = j + 1;
|
1942
|
mapnum++;
|
1943
|
return 1;
|
1944
|
}
|
1945
|
}
|
1946
|
|
1947
|
|
1948
|
if (maplist[j].m_type == 9)
|
1949
|
{
|
1950
|
if (maplist[j].r_type == 3){
|
1951
|
maplist[j].data.datafloat = (float)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1952
|
maplist[j].data.datafloat = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datafloat;
|
1953
|
maplist[j].visited = 1;
|
1954
|
mapIndex = j + 1;
|
1955
|
mapnum++;
|
1956
|
return 0;
|
1957
|
}
|
1958
|
if (maplist[j].r_type == 4){
|
1959
|
maplist[j].data.datasint32 = (sint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1960
|
maplist[j].data.datasint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datasint32;
|
1961
|
maplist[j].visited = 1;
|
1962
|
mapIndex = j + 1;
|
1963
|
mapnum++;
|
1964
|
return 0;
|
1965
|
}
|
1966
|
if (maplist[j].r_type == 5){
|
1967
|
maplist[j].data.datauint32 = (uint32)(256 * buf[9 + 2 * i] + buf[9 + 2 * i + 1]);
|
1968
|
maplist[j].data.datauint32 = (256 * buf[9 + 2 * i + 2] + buf[9 + 2 * i + 1 + 2]) *pow(2, 16) + maplist[j].data.datauint32;
|
1969
|
maplist[j].visited = 1;
|
1970
|
mapIndex = j + 1;
|
1971
|
mapnum++;
|
1972
|
return 0;
|
1973
|
}
|
1974
|
}
|
1975
|
}
|
1976
|
}
|
1977
|
}
|
1978
|
return -1;
|
1979
|
}
|
1980
|
return -2;
|
1981
|
}
|
1982
|
|
1983
|
sint64 CModbusTcpc::GetNowMilliSecond() //??ȡ??ǰ????ʱ??
|
1984
|
{
|
1985
|
CSeTime SE_T;
|
1986
|
TCriterionTime tmptime;//sint32
|
1987
|
unsigned short millsecond;
|
1988
|
SE_T.GetNow(&tmptime, &millsecond);
|
1989
|
sint64 nowmilltime = (sint64)tmptime * 1000 + millsecond;
|
1990
|
return nowmilltime;
|
1991
|
}
|
1992
|
|
1993
|
|
1994
|
|
1995
|
|
1996
|
sint32 CModbusTcpc::RxProc() {
|
1997
|
if (err)
|
1998
|
return -1;
|
1999
|
|
2000
|
//PrintLog(LOG_INFORMATION, "------- ????RxProc");
|
2001
|
sint32 rtuno = pLink->GetRtuNo();
|
2002
|
|
2003
|
uint8 buf[1024];
|
2004
|
int datalen = 0, datanum = 0;
|
2005
|
int i, j;
|
2006
|
sint32 buflen = pRxBuf->GetReadableSize();
|
2007
|
sint64 nowtime = GetNowMilliSecond();
|
2008
|
|
2009
|
if (mapnum >= maplength)
|
2010
|
{
|
2011
|
mapnum = 0;
|
2012
|
return 0;
|
2013
|
}
|
2014
|
|
2015
|
E_RAW_ComStat commstatus = pLink->GetCommStatus();
|
2016
|
if (commstatus == CMST_RX_CNT && (nowtime - m_LastSendTime) >= m_RcvTimeOuts * 1000)
|
2017
|
{
|
2018
|
//??ʱ???ط???ֱ????????һ???ն?
|
2019
|
pRxBuf->Move(buflen);
|
2020
|
pLink->RegisterFrm(FRAME_RX_TIMEOUT);
|
2021
|
pLink->SetCommStatus(CMST_TX_CNT);
|
2022
|
PrintLog(LOG_VIOLATION, " ???ݳ?ʱ,%d\n", nowtime - m_LastSendTime);
|
2023
|
return -1;
|
2024
|
}
|
2025
|
if (buflen < 7) //?????ݻ????ݲ??????ı???·ͨѶ״̬???????ȴ?
|
2026
|
return -1;
|
2027
|
datalen = pRxBuf->Read(buf, 7, DEF_BUFF_NOMOVE); //??ǰ7λ????ͷ
|
2028
|
|
2029
|
int ret = CheckFrameHeader(buf, 7);
|
2030
|
if (ret<0)
|
2031
|
{
|
2032
|
pRxBuf->Move(buflen);
|
2033
|
pLink->RegisterFrm(FRAME_RX_MISSTEP);
|
2034
|
PrintLog(LOG_VIOLATION, "ModbusHead??һ??\n");
|
2035
|
|
2036
|
return -1;
|
2037
|
}
|
2038
|
else if (ret == 0)
|
2039
|
return 0;
|
2040
|
|
2041
|
uint16 d_len = buf[4] * 256 + buf[5] + 6; //???㱨?????峤??
|
2042
|
if (buflen < d_len)
|
2043
|
return -1;
|
2044
|
datalen = pRxBuf->Read(buf, d_len, DEF_BUFF_MOVE);
|
2045
|
|
2046
|
// PrintLog(LOG_INFORMATION,"<<<<< ReceiveType=%d, numbyte=%d",buf[7],buf[8]);
|
2047
|
|
2048
|
if (buf[7] & 0x80){
|
2049
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2050
|
pLink->SetCommStatus(CMST_NORMAL);
|
2051
|
return -1;//ErrorHandle(buf[7]);
|
2052
|
}
|
2053
|
uint16 YxYcId = 0;
|
2054
|
|
2055
|
|
2056
|
switch (buf[7]) //???????ж?
|
2057
|
{
|
2058
|
case 1:
|
2059
|
if (WillSendType == 1)
|
2060
|
{
|
2061
|
//????ң??
|
2062
|
for (i = 0; i < buf[8]; i++)
|
2063
|
{
|
2064
|
uint8 value = buf[9 + i];
|
2065
|
for (j = 0; j < 8; j++)
|
2066
|
{
|
2067
|
|
2068
|
YxYcId = 8 * i + j + IndexDI;
|
2069
|
if (YxYcId >= (IndexDI + numDI))
|
2070
|
break;
|
2071
|
int ret = ComparePoint(YxYcId, value);
|
2072
|
if (ret == 0) {
|
2073
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2074
|
}
|
2075
|
}
|
2076
|
}
|
2077
|
PrintLog(LOG_INFORMATION, "---- Receive Yx data ");
|
2078
|
|
2079
|
if (buf[8] * 8 < numDI) {
|
2080
|
IndexDI += buf[8] * 8;
|
2081
|
visitednum += buf[8] * 8;
|
2082
|
}
|
2083
|
else {
|
2084
|
IndexDI += numDI;
|
2085
|
visitednum += numDI;
|
2086
|
}
|
2087
|
|
2088
|
|
2089
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2090
|
pLink->SetCommStatus(CMST_NORMAL);
|
2091
|
|
2092
|
return 1;
|
2093
|
}
|
2094
|
break;
|
2095
|
case 2:
|
2096
|
if (WillSendType == 2)
|
2097
|
{
|
2098
|
//????ң??
|
2099
|
for (i = 0; i < buf[8]; i++)
|
2100
|
{
|
2101
|
uint8 value = buf[9 + i];
|
2102
|
for (j = 0; j < 8; j++)
|
2103
|
{
|
2104
|
|
2105
|
YxYcId = 8 * i + j + IndexDI;
|
2106
|
if (YxYcId >= (IndexDI + numDI))
|
2107
|
break;
|
2108
|
int ret = ComparePoint(YxYcId, value);
|
2109
|
if (ret == 0) {
|
2110
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2111
|
}
|
2112
|
}
|
2113
|
}
|
2114
|
PrintLog(LOG_INFORMATION, "---- Receive Yx data ");
|
2115
|
|
2116
|
if (buf[8] * 8 < numDI) {
|
2117
|
IndexDI += buf[8] * 8;
|
2118
|
visitednum += buf[8] * 8;
|
2119
|
}
|
2120
|
else {
|
2121
|
IndexDI += numDI;
|
2122
|
visitednum += numDI;
|
2123
|
}
|
2124
|
|
2125
|
|
2126
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2127
|
pLink->SetCommStatus(CMST_NORMAL);
|
2128
|
|
2129
|
return 1;
|
2130
|
}
|
2131
|
break;
|
2132
|
case 3:
|
2133
|
//????ң??
|
2134
|
if (WillSendType == 3)
|
2135
|
{
|
2136
|
for (i = 0; i < buf[8] / 2; i++)
|
2137
|
{
|
2138
|
YxYcId = i + IndexAI;
|
2139
|
if (YxYcId >= (IndexAI + numAI))
|
2140
|
break;
|
2141
|
int ret = ComparePoint_reg(YxYcId, buf, i);
|
2142
|
if (ret == 0) {
|
2143
|
if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
|
2144
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2145
|
}
|
2146
|
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) {
|
2147
|
switch (maplist[mapIndex - 1].r_type){
|
2148
|
case 1:
|
2149
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2150
|
break;
|
2151
|
case 2:
|
2152
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2153
|
break;
|
2154
|
case 3:
|
2155
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2156
|
break;
|
2157
|
case 4:
|
2158
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2159
|
break;
|
2160
|
case 5:
|
2161
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2162
|
break;
|
2163
|
}
|
2164
|
}
|
2165
|
if (maplist[mapIndex - 1].m_type == 9) {
|
2166
|
switch (maplist[mapIndex - 1].r_type){
|
2167
|
case 1:
|
2168
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2169
|
break;
|
2170
|
case 2:
|
2171
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2172
|
break;
|
2173
|
case 3:
|
2174
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2175
|
break;
|
2176
|
case 4:
|
2177
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2178
|
break;
|
2179
|
case 5:
|
2180
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2181
|
break;
|
2182
|
}
|
2183
|
}
|
2184
|
if (maplist[mapIndex - 1].m_type == 0)
|
2185
|
{
|
2186
|
uint16 data = 1;
|
2187
|
if (maplist[mapIndex - 1].data.datauint16 == 0)
|
2188
|
{
|
2189
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2190
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2191
|
}
|
2192
|
|
2193
|
else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1)
|
2194
|
{
|
2195
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2196
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2197
|
PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2198
|
}
|
2199
|
|
2200
|
else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0)
|
2201
|
{
|
2202
|
uint16 data = 1;
|
2203
|
data <<= maplist[mapIndex - 1].data.datauint16 - 1;
|
2204
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
|
2205
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
|
2206
|
data >>= 1;
|
2207
|
}
|
2208
|
}
|
2209
|
}
|
2210
|
}
|
2211
|
while (ret == 1) {
|
2212
|
if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
|
2213
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2214
|
}
|
2215
|
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) {
|
2216
|
switch (maplist[mapIndex - 1].r_type){
|
2217
|
case 1:
|
2218
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2219
|
break;
|
2220
|
case 2:
|
2221
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2222
|
break;
|
2223
|
case 3:
|
2224
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2225
|
break;
|
2226
|
case 4:
|
2227
|
//float32 a; //????ʧ???????
|
2228
|
//a = maplist[mapIndex - 1].data.datasint32;
|
2229
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2230
|
break;
|
2231
|
case 5:
|
2232
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2233
|
break;
|
2234
|
}
|
2235
|
}
|
2236
|
if (maplist[mapIndex - 1].m_type == 9) {
|
2237
|
switch (maplist[mapIndex - 1].r_type){
|
2238
|
case 1:
|
2239
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2240
|
break;
|
2241
|
case 2:
|
2242
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2243
|
break;
|
2244
|
case 3:
|
2245
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2246
|
break;
|
2247
|
case 4:
|
2248
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2249
|
break;
|
2250
|
case 5:
|
2251
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2252
|
break;
|
2253
|
}
|
2254
|
}
|
2255
|
if (maplist[mapIndex - 1].m_type == 0) {
|
2256
|
uint16 data = 1;
|
2257
|
|
2258
|
if (maplist[mapIndex - 1].data.datauint16 == 0){
|
2259
|
for (int index = 0; index <= maplist[mapIndex - 1].end + 1; index++)
|
2260
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2261
|
}
|
2262
|
else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1){
|
2263
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2264
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2265
|
PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2266
|
}
|
2267
|
else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0){
|
2268
|
uint16 data = 1;
|
2269
|
data <<= maplist[mapIndex - 1].data.datauint16 - 1;
|
2270
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
|
2271
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
|
2272
|
data >>= 1;
|
2273
|
}
|
2274
|
}
|
2275
|
}
|
2276
|
ret = ComparePoint_reg(YxYcId, buf, i);
|
2277
|
}
|
2278
|
}
|
2279
|
|
2280
|
PrintLog(LOG_INFORMATION, ">>>> Receive Yc data ");
|
2281
|
if (buf[8] / 2 < numAI) {
|
2282
|
IndexAI += buf[8] / 2;
|
2283
|
visitednum += buf[8] / 2;
|
2284
|
}
|
2285
|
else {
|
2286
|
IndexAI += numAI;
|
2287
|
visitednum += numAI;
|
2288
|
}
|
2289
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2290
|
pLink->SetCommStatus(CMST_NORMAL);
|
2291
|
|
2292
|
return 1;
|
2293
|
}
|
2294
|
break;
|
2295
|
case 4:
|
2296
|
//????ң??
|
2297
|
if (WillSendType == 4)
|
2298
|
{
|
2299
|
for (i = 0; i < buf[8] / 2; i++)
|
2300
|
{
|
2301
|
YxYcId = i + IndexAI;
|
2302
|
if (YxYcId >= (IndexAI + numAI))
|
2303
|
break;
|
2304
|
int ret = ComparePoint_reg(YxYcId, buf, i);
|
2305
|
if (ret == 0) {
|
2306
|
if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
|
2307
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2308
|
}
|
2309
|
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) {
|
2310
|
switch (maplist[mapIndex - 1].r_type){
|
2311
|
case 1:
|
2312
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2313
|
break;
|
2314
|
case 2:
|
2315
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2316
|
break;
|
2317
|
case 3:
|
2318
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2319
|
break;
|
2320
|
case 4:
|
2321
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2322
|
break;
|
2323
|
case 5:
|
2324
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2325
|
break;
|
2326
|
}
|
2327
|
}
|
2328
|
if (maplist[mapIndex - 1].m_type == 9) {
|
2329
|
switch (maplist[mapIndex - 1].r_type){
|
2330
|
case 1:
|
2331
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2332
|
break;
|
2333
|
case 2:
|
2334
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2335
|
break;
|
2336
|
case 3:
|
2337
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2338
|
break;
|
2339
|
case 4:
|
2340
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2341
|
break;
|
2342
|
case 5:
|
2343
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2344
|
break;
|
2345
|
}
|
2346
|
}
|
2347
|
if (maplist[mapIndex - 1].m_type == 0) {
|
2348
|
uint16 data = 1;
|
2349
|
|
2350
|
if (maplist[mapIndex - 1].data.datauint16 == 0){
|
2351
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2352
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2353
|
}
|
2354
|
else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1){
|
2355
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2356
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2357
|
PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2358
|
}
|
2359
|
else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0){
|
2360
|
uint16 data = 1;
|
2361
|
data <<= maplist[mapIndex - 1].data.datauint16 - 1;
|
2362
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
|
2363
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
|
2364
|
data >>= 1;
|
2365
|
}
|
2366
|
}
|
2367
|
}
|
2368
|
}
|
2369
|
while (ret == 1) {
|
2370
|
if (maplist[mapIndex - 1].m_type == 1 || maplist[mapIndex - 1].m_type == 2) {
|
2371
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2372
|
}
|
2373
|
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)
|
2374
|
{
|
2375
|
switch (maplist[mapIndex - 1].r_type)
|
2376
|
{
|
2377
|
case 1:
|
2378
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2379
|
break;
|
2380
|
case 2:
|
2381
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2382
|
break;
|
2383
|
case 3:
|
2384
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2385
|
break;
|
2386
|
case 4:
|
2387
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2388
|
break;
|
2389
|
case 5:
|
2390
|
PRawCtrl->PutAYc(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2391
|
break;
|
2392
|
}
|
2393
|
}
|
2394
|
if (maplist[mapIndex - 1].m_type == 9) {
|
2395
|
switch (maplist[mapIndex - 1].r_type){
|
2396
|
case 1:
|
2397
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2398
|
break;
|
2399
|
case 2:
|
2400
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint16);
|
2401
|
break;
|
2402
|
case 3:
|
2403
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datafloat);
|
2404
|
break;
|
2405
|
case 4:
|
2406
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datasint32);
|
2407
|
break;
|
2408
|
case 5:
|
2409
|
PRawCtrl->PutAKwh(rtuno, maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint32);
|
2410
|
break;
|
2411
|
}
|
2412
|
}
|
2413
|
if (maplist[mapIndex - 1].m_type == 0) {
|
2414
|
uint16 data = 1;
|
2415
|
|
2416
|
if (maplist[mapIndex - 1].data.datauint16 == 0){
|
2417
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2418
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2419
|
}
|
2420
|
else if (maplist[mapIndex - 1].data.datauint16 > maplist[mapIndex - 1].end + 1){
|
2421
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++)
|
2422
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, 0);
|
2423
|
PrintLog(LOG_ERROR, "VA data error ?ɼ???ţ?%d?????ݣ?%d", maplist[mapIndex - 1].pointnum, maplist[mapIndex - 1].data.datauint16);
|
2424
|
}
|
2425
|
else if (maplist[mapIndex - 1].data.datauint16 <= maplist[mapIndex - 1].end + 1 && maplist[mapIndex - 1].data.datauint16 > 0){
|
2426
|
uint16 data = 1;
|
2427
|
data <<= maplist[mapIndex - 1].data.datauint16 - 1;
|
2428
|
for (int index = 0; index <= maplist[mapIndex - 1].end; index++){
|
2429
|
PRawCtrl->PutAYx(rtuno, maplist[mapIndex - 1].pointnum + index, data & 1);
|
2430
|
data >>= 1;
|
2431
|
}
|
2432
|
}
|
2433
|
}
|
2434
|
ret = ComparePoint_reg(YxYcId, buf, i);
|
2435
|
}
|
2436
|
}
|
2437
|
|
2438
|
PrintLog(LOG_INFORMATION, ">>>> Receive Yc data ");
|
2439
|
if (buf[8] / 2 < numAI) {
|
2440
|
IndexAI += buf[8] / 2;
|
2441
|
visitednum += buf[8] / 2;
|
2442
|
}
|
2443
|
else {
|
2444
|
IndexAI += numAI;
|
2445
|
visitednum += numAI;
|
2446
|
}
|
2447
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2448
|
pLink->SetCommStatus(CMST_NORMAL);
|
2449
|
|
2450
|
return 1;
|
2451
|
}
|
2452
|
break;
|
2453
|
case 5:
|
2454
|
//ң?ط???
|
2455
|
// if(WillSendType == 5)
|
2456
|
{
|
2457
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2458
|
pLink->SetCommStatus(CMST_NORMAL);
|
2459
|
return 1;
|
2460
|
}
|
2461
|
break;
|
2462
|
case 6:
|
2463
|
//ң??????
|
2464
|
// if(WillSendType == 6)
|
2465
|
{
|
2466
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2467
|
pLink->SetCommStatus(CMST_NORMAL);
|
2468
|
return 1;
|
2469
|
}
|
2470
|
case 15:
|
2471
|
//ң?ط???
|
2472
|
// if(WillSendType == 6)
|
2473
|
{
|
2474
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2475
|
pLink->SetCommStatus(CMST_NORMAL);
|
2476
|
return 1;
|
2477
|
}
|
2478
|
case 16:
|
2479
|
//ң??????
|
2480
|
// if(WillSendType == 6)
|
2481
|
{
|
2482
|
pLink->RegisterFrm(FRAME_RX_SUC);
|
2483
|
pLink->SetCommStatus(CMST_NORMAL);
|
2484
|
return 1;
|
2485
|
}
|
2486
|
break;
|
2487
|
default:
|
2488
|
return 0;
|
2489
|
break;
|
2490
|
}
|
2491
|
return 1;
|
2492
|
}
|
2493
|
|
2494
|
|
2495
|
sint32 CModbusTcpc::TxProc()
|
2496
|
{
|
2497
|
if (err)
|
2498
|
return -1;
|
2499
|
|
2500
|
if (readcfgflag == 0)
|
2501
|
{
|
2502
|
sint64 nowtime = GetNowMilliSecond();
|
2503
|
if (nowtime - sleepstarttime > sleeptime * 1000)
|
2504
|
{
|
2505
|
sint64 cfgstart = 0;
|
2506
|
sint64 cfgend = 0;
|
2507
|
cfgstart = GetNowMilliSecond();
|
2508
|
|
2509
|
ReadCfg();
|
2510
|
|
2511
|
cfgend = GetNowMilliSecond();
|
2512
|
sint64 pasttime = 0;
|
2513
|
pasttime = cfgend - cfgstart;
|
2514
|
PrintLog(1, "?????ļ???ȡʱ?? %d ????", pasttime);
|
2515
|
|
2516
|
readcfgflag = 1;
|
2517
|
}
|
2518
|
else
|
2519
|
{
|
2520
|
return 0;
|
2521
|
}
|
2522
|
}
|
2523
|
|
2524
|
//PrintLog(LOG_INFORMATION, "------- ????TxProc");
|
2525
|
E_RAW_ComStat commstatus = pLink->GetCommStatus();
|
2526
|
|
2527
|
if (commstatus != CMST_TX_CNT && commstatus != CMST_NORMAL)
|
2528
|
return 0;
|
2529
|
|
2530
|
uint16 rxbuflen = 0;
|
2531
|
rxbuflen = pRxBuf->GetReadableSize();
|
2532
|
if (rxbuflen > 0)
|
2533
|
{
|
2534
|
PrintLog(LOG_ERROR, "------- ???? %d????????!", rxbuflen);
|
2535
|
pRxBuf->Move(rxbuflen);
|
2536
|
}
|
2537
|
|
2538
|
if (Policy && ProcCmd())
|
2539
|
{
|
2540
|
pLink->SetCommStatus(CMST_RX_CNT);
|
2541
|
return 1; //?????ⲿ?·?????
|
2542
|
}
|
2543
|
|
2544
|
|
2545
|
//<wyf>temp
|
2546
|
// if(( nowtime - m_LastSendTime)<1)
|
2547
|
// return 0;
|
2548
|
|
2549
|
uint8 len = 0;
|
2550
|
|
2551
|
sint64 nowtime = GetNowMilliSecond();
|
2552
|
if (duqu[duquIndex][4] > 0 && ((uint64)(nowtime - m_LastSendTime) < (uint64)duqu[duquIndex][4]))
|
2553
|
{
|
2554
|
PrintLog(LOG_ERROR, "δ?ﵽ???ʱ??,?????ϴη???%d????,%d", nowtime - m_LastSendTime, (uint64)duqu[duquIndex][4]);
|
2555
|
return -1;
|
2556
|
}
|
2557
|
|
2558
|
if (visitednum >= duqu[duquIndex][1])
|
2559
|
{
|
2560
|
GetWillSendType();
|
2561
|
}
|
2562
|
|
2563
|
switch (WillSendType)
|
2564
|
{
|
2565
|
case 1://read DIO R/W
|
2566
|
if ((scopeDI - IndexDI) > MAX_BYTE_NUM * 8)
|
2567
|
numDI = MAX_BYTE_NUM * 8;
|
2568
|
else
|
2569
|
numDI = scopeDI - IndexDI;
|
2570
|
if (numDI > 0)
|
2571
|
len = OperateRegister(WillSendType, IndexDI, numDI);
|
2572
|
break;
|
2573
|
|
2574
|
case 2://read DIO R/W
|
2575
|
if ((scopeDI - IndexDI) > MAX_BYTE_NUM * 8)
|
2576
|
numDI = MAX_BYTE_NUM * 8;
|
2577
|
else
|
2578
|
numDI = scopeDI - IndexDI;
|
2579
|
if (numDI > 0)
|
2580
|
len = OperateRegister(WillSendType, IndexDI, numDI);
|
2581
|
break;
|
2582
|
|
2583
|
case 3://read AIO R/W
|
2584
|
if ((scopeAI - IndexAI) > MAX_BYTE_NUM / 2)
|
2585
|
numAI = MAX_BYTE_NUM / 2;
|
2586
|
else
|
2587
|
numAI = scopeAI - IndexAI;
|
2588
|
if (numAI > 0)
|
2589
|
len = OperateRegister(WillSendType, IndexAI, numAI);
|
2590
|
break;
|
2591
|
|
2592
|
case 4://read AIO R/W
|
2593
|
if ((scopeAI - IndexAI) > MAX_BYTE_NUM / 2)
|
2594
|
numAI = MAX_BYTE_NUM / 2;
|
2595
|
else
|
2596
|
numAI = scopeAI - IndexAI;
|
2597
|
if (numAI > 0)
|
2598
|
len = OperateRegister(WillSendType, IndexAI, numAI);
|
2599
|
break;
|
2600
|
|
2601
|
default:
|
2602
|
break;
|
2603
|
}
|
2604
|
|
2605
|
if (len > 0)
|
2606
|
pLink->SetCommStatus(CMST_RX_CNT);
|
2607
|
|
2608
|
return len;
|
2609
|
}
|
2610
|
|
2611
|
|
2612
|
|
2613
|
|
2614
|
//??Լ????????
|
2615
|
#ifdef __unix
|
2616
|
extern "C" CProtocol * CreateProtocol(char* defpara)
|
2617
|
#else
|
2618
|
extern "C" __declspec(dllexport) CProtocol * CreateProtocol(char* defpara)
|
2619
|
#endif
|
2620
|
{
|
2621
|
CProtocol* pEpv = new CModbusTcpc;
|
2622
|
return pEpv;
|
2623
|
}
|
2624
|
|