1
|
#pragma once
|
2
|
#include "AxiomAcs.h"
|
3
|
|
4
|
#include "iostream"
|
5
|
#include "fstream"
|
6
|
|
7
|
#ifdef WIN32
|
8
|
#include <direct.h>
|
9
|
#include <io.h>
|
10
|
#else
|
11
|
#include <sys/stat.h>
|
12
|
#include <sys/io.h>
|
13
|
#include <stdio.h>
|
14
|
#include <unistd.h>
|
15
|
#include <sys/types.h>
|
16
|
#endif
|
17
|
|
18
|
#ifndef WIN32
|
19
|
#include <iconv.h>
|
20
|
#endif
|
21
|
|
22
|
#define far
|
23
|
typedef void far *LPVOID;
|
24
|
|
25
|
|
26
|
int AxionAcs::GetNowSecond() {
|
27
|
CSeTime SE_T;
|
28
|
TCriterionTime tmptime;
|
29
|
SE_T.GetNow(&tmptime);
|
30
|
return (int)tmptime;
|
31
|
}
|
32
|
std::string convertTime(int timestamp) {
|
33
|
time_t tick = (time_t)(timestamp);//ת??ʱ??
|
34
|
struct tm tm;
|
35
|
char s[40];
|
36
|
tm = *localtime(&tick);
|
37
|
strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm);
|
38
|
std::string str(s);
|
39
|
return str;
|
40
|
}
|
41
|
|
42
|
unsigned long long GetTimeStamp() {
|
43
|
unsigned long long stampNow = 0;
|
44
|
time_t timer;
|
45
|
timer = time(NULL);
|
46
|
stampNow = timer;
|
47
|
|
48
|
return stampNow;
|
49
|
}
|
50
|
|
51
|
void Inver2byte(uint8* Src, int num) {
|
52
|
int t = 0;
|
53
|
for (int i = 0; i < num / 2; i++) {
|
54
|
t = Src[2 * i];
|
55
|
Src[2 * i] = Src[2 * i + 1];
|
56
|
Src[2 * i + 1] = t;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
|
61
|
unsigned int rxprocess(LPVOID rxptr) {
|
62
|
AxionAcs* rtxpPara = NULL;
|
63
|
|
64
|
rtxpPara = (AxionAcs*)rxptr;
|
65
|
sint32 rtuno = rtxpPara->Get_Rtuno();
|
66
|
|
67
|
bool doorflag = true;
|
68
|
while (doorflag) {
|
69
|
if (rtxpPara->GetDoors() == 1) { //??ȡ?????????ݳɹ?
|
70
|
doorflag = false;
|
71
|
}
|
72
|
if (doorflag) {
|
73
|
rtxpPara->PrintLog(LOG_ERROR, "??״̬ǰ????ʧ?ܣ??ȴ?2s");
|
74
|
SeSleep(2000);
|
75
|
}
|
76
|
}
|
77
|
while (rtxpPara->rxflag) {
|
78
|
for (int i = 0; i < rtxpPara->doorNum; i++) {
|
79
|
if (rtxpPara->httpflag_doors == false) {
|
80
|
rtxpPara->fclient_door.init_mg();
|
81
|
rtxpPara->httpflag_doors = true;
|
82
|
rtxpPara->httpflag1_doors = true;
|
83
|
rtxpPara->PrintLog(LOG_INFORMATION, "??ʼ????״̬???ӣ?");
|
84
|
}
|
85
|
rtxpPara->GetDoorState(i + 1);
|
86
|
}
|
87
|
|
88
|
SeSleep(500);
|
89
|
}
|
90
|
return 0;
|
91
|
}
|
92
|
|
93
|
unsigned int txprocess(LPVOID txptr) {
|
94
|
AxionAcs* rtxpPara = NULL;
|
95
|
|
96
|
rtxpPara = (AxionAcs*)txptr;
|
97
|
sint32 rtuno = rtxpPara->Get_Rtuno();
|
98
|
|
99
|
while (rtxpPara->txflag) {
|
100
|
S_RAWCMD rawcmd;
|
101
|
while (rtxpPara->Get_CmdNum() >0 ) {
|
102
|
if (rtxpPara->Get_ACmd(rtuno, &rawcmd) == 0) break;
|
103
|
rtxpPara->PrintLog(LOG_INFORMATION, "?յ?%d???ն? ????:%d ", rtuno, rawcmd.type);
|
104
|
|
105
|
uint8 len = 0;
|
106
|
ST_TRACK_ADDR m_cmdaddr; //?????ⲿ???ͨ???˱????????ⲿ?????ַ??Ϣ
|
107
|
m_cmdaddr = rawcmd.src;
|
108
|
switch (rawcmd.type) {
|
109
|
case DC_K_CMD_DOOPER:{ //ң?أ??ؿ?????
|
110
|
S_DO_CTL *cmdinfo;
|
111
|
cmdinfo = (S_DO_CTL *)(&rawcmd.data);
|
112
|
uint16 ykno = (uint16)cmdinfo->ptAddr;//ң?غ?
|
113
|
switch (cmdinfo->funcCode) {
|
114
|
case DC_K_CTL_DOSEL: //ѡ??
|
115
|
//ֱ?ӷ?У
|
116
|
rawcmd.type = DC_K_CMDRET_DOOPER;
|
117
|
rawcmd.len = sizeof(cmdinfo);
|
118
|
rawcmd.src = m_cmdaddr;
|
119
|
cmdinfo->retCode = 1;
|
120
|
rtxpPara->Rpt_AResult(rtuno, rawcmd);
|
121
|
break;
|
122
|
|
123
|
case DC_K_CTL_DOEXE: //ִ??
|
124
|
uint16 ykvalue;
|
125
|
ykvalue = cmdinfo->ctlVal;
|
126
|
|
127
|
if (ykno % 10 == 4){
|
128
|
if (ykvalue == 1) { //Զ?̿???
|
129
|
//????yknoΪ??
|
130
|
// rtxpPara->PrintLog(LOG_INFORMATION, "ɾ??һ???յ?%d???ն????? ", rtuno);
|
131
|
rtxpPara->SetDoorOpen(ykno / 10);
|
132
|
}
|
133
|
if (ykvalue == 0) { //Զ?̹???
|
134
|
//????yknoΪ?ر?
|
135
|
rtxpPara->SetDoorClose(ykno / 10);
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if ((ykno % 10 == 5) && (ykvalue == 1)){ //????
|
140
|
rtxpPara->SetDoorMode(ykno / 10, "4");
|
141
|
}
|
142
|
if ((ykno % 10 == 5) && (ykvalue == 0)){ //????
|
143
|
rtxpPara->SetDoorMode(ykno / 10, "5");
|
144
|
}
|
145
|
if ((ykno % 10 == 5) && (ykvalue == 2)){ //?Զ?
|
146
|
rtxpPara->SetDoorMode(ykno / 10, "0");
|
147
|
}
|
148
|
break;
|
149
|
case DC_K_CTL_DODEL://????
|
150
|
break;
|
151
|
}
|
152
|
|
153
|
}
|
154
|
break;
|
155
|
default:
|
156
|
break;
|
157
|
}
|
158
|
rtxpPara->Del_ACmd(rtuno);
|
159
|
rtxpPara->PrintLog(LOG_INFORMATION, "ɾ??һ???յ?%d???ն????? ", rtuno);
|
160
|
}
|
161
|
SeSleep(500);
|
162
|
}
|
163
|
|
164
|
return 0;
|
165
|
}
|
166
|
|
167
|
|
168
|
unsigned int xxprocess(LPVOID xxptr) {
|
169
|
AxionAcs* rtxpPara = NULL;
|
170
|
|
171
|
rtxpPara = (AxionAcs*)xxptr;
|
172
|
sint32 rtuno = rtxpPara->Get_Rtuno();
|
173
|
int eventNum = 0;
|
174
|
|
175
|
bool devicesflag = true;
|
176
|
while (devicesflag) {
|
177
|
if (rtxpPara->GetDevices() == 1) { //??ȡ?????Ž??豸???ݳɹ?
|
178
|
devicesflag = false;
|
179
|
}
|
180
|
if (devicesflag) {
|
181
|
rtxpPara->PrintLog(LOG_ERROR, "?¼?ǰ????ʧ?ܣ??ȴ?2s");
|
182
|
SeSleep(2000);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
while (rtxpPara->xxflag) {
|
187
|
if (rtxpPara->httpflag_devices == false) {
|
188
|
rtxpPara->fclient_device.init_mg();
|
189
|
rtxpPara->httpflag_devices = true;
|
190
|
rtxpPara->httpflag1_devices = true;
|
191
|
rtxpPara->PrintLog(LOG_INFORMATION, "??ʼ???¼????ӣ?");
|
192
|
}
|
193
|
eventNum = rtxpPara->GetSwipecard();
|
194
|
if (eventNum != 0) {
|
195
|
for (int i = 0; i < eventNum; i++) {
|
196
|
if ((rtxpPara->lastEventId) < (rtxpPara->eventid[rtxpPara->eventidex[i]])) {
|
197
|
rtxpPara->lastEventId = rtxpPara->eventid[rtxpPara->eventidex[i]];
|
198
|
string doorid = rtxpPara->GetDoorId(rtxpPara->eventidex[i]);
|
199
|
string cardId = rtxpPara->GetCardId(rtxpPara->eventidex[i]);
|
200
|
string eventtime = rtxpPara->GetEventTime(rtxpPara->eventidex[i]);
|
201
|
int reason = rtxpPara->GetaccessBlockedReason(rtxpPara->eventidex[i]);
|
202
|
int doorno;
|
203
|
for (int j = 0; j < rtxpPara->doorNum; j++) {
|
204
|
if (doorid == rtxpPara->Getmapdoor(j + 1)) {
|
205
|
doorno = j + 1;
|
206
|
}
|
207
|
}
|
208
|
if (reason == 0) {
|
209
|
rtxpPara->PrintLog(LOG_INFORMATION, "?Ž?ˢ??ʵʱ?¼???ˢ???ɹ?????[%d] ʱ??[%s] ????[%s]", doorno, eventtime.c_str(), cardId.c_str());
|
210
|
rtxpPara->PutSoe(rtuno, doorno * 10 + 2, eventtime, cardId);
|
211
|
} else {
|
212
|
rtxpPara->PrintLog(LOG_ERROR, "?Ž?ˢ??ʵʱ?¼???ˢ??ʧ?ܣ???[%d] ʱ??[%s] ????[%s] ??????[%d]", doorno, eventtime.c_str(), cardId.c_str(), reason);
|
213
|
rtxpPara->PutSoe(rtuno, doorno * 10 + 3, eventtime, cardId);
|
214
|
}
|
215
|
|
216
|
}
|
217
|
}
|
218
|
}
|
219
|
SeSleep(1000);
|
220
|
}
|
221
|
|
222
|
|
223
|
}
|
224
|
|
225
|
void AxionAcs::Init(S_PROTOCOLCFG* pcfg) {
|
226
|
PRawCtrl = pcfg->PRawCtrl;
|
227
|
pCmdMem = pcfg->pCmdMem;
|
228
|
pRtu = pcfg->pRtu;
|
229
|
pLink = pcfg->pLink;
|
230
|
|
231
|
|
232
|
deviceNum = 0;
|
233
|
doorNum = 0;
|
234
|
lastEventId = 0;
|
235
|
eventid[100] = { 0 };
|
236
|
eventidex[100] = { 0 };
|
237
|
username[128] = { 0 };
|
238
|
password[128] = { 0 };
|
239
|
rxflag = true;
|
240
|
txflag = true;
|
241
|
xxflag = true;
|
242
|
httpflag_doors = false;
|
243
|
httpflag_devices = false;
|
244
|
|
245
|
ReadIni();
|
246
|
|
247
|
PrintLog(LOG_INFORMATION, "????rx?߳?%s %s !",username,password);
|
248
|
if (rxflag) {
|
249
|
rxthread = SE_CreateThread((PTHREAD_FUNC_DEF)rxprocess, this, 100);
|
250
|
}
|
251
|
PrintLog(LOG_INFORMATION, "????rx?߳? !");
|
252
|
|
253
|
if (txflag) {
|
254
|
txthread = SE_CreateThread((PTHREAD_FUNC_DEF)txprocess, this, 100);
|
255
|
}
|
256
|
PrintLog(LOG_INFORMATION, "????tx?߳? !");
|
257
|
|
258
|
if (xxflag) {
|
259
|
xxthread = SE_CreateThread((PTHREAD_FUNC_DEF)xxprocess, this, 100);
|
260
|
}
|
261
|
PrintLog(LOG_INFORMATION, "????xx?߳? !");
|
262
|
|
263
|
/*
|
264
|
//????restful?????ܲ???????????Ϣ
|
265
|
strCallback.iotprotocols = this;
|
266
|
strCallback.rtuno = iotpLink->GetRtuNo();
|
267
|
restfulServer();
|
268
|
*/
|
269
|
|
270
|
}
|
271
|
|
272
|
|
273
|
|
274
|
|
275
|
|
276
|
|
277
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
278
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
279
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
280
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
281
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
282
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
283
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
284
|
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
285
|
|
286
|
sint32 AxionAcs::Get_Rtuno() {
|
287
|
return (pLink->GetRtuNo());
|
288
|
}
|
289
|
void AxionAcs::Put_AYx(uint16 Rtuno, uint16 YxNo, uint8 YxValue) {
|
290
|
PRawCtrl->PutAYx(Rtuno, YxNo, YxValue);
|
291
|
}
|
292
|
|
293
|
sint32 AxionAcs::Get_CmdNum() {
|
294
|
sint32 rtuno = pLink->GetRtuNo();
|
295
|
return (pCmdMem->GetCmdNum(rtuno));
|
296
|
}
|
297
|
|
298
|
sint32 AxionAcs::Get_ACmd(sint32 rtuno, S_RAWCMD* cmd) {
|
299
|
return pCmdMem->GetACmd(rtuno, cmd);
|
300
|
}
|
301
|
|
302
|
sint32 AxionAcs::Del_ACmd(sint32 rtuno) {
|
303
|
return pCmdMem->DelACmd(rtuno);
|
304
|
}
|
305
|
|
306
|
sint32 AxionAcs::Rpt_AResult(sint32 rtuno, S_RAWCMD cmd) {
|
307
|
return pCmdMem->RptAResult(rtuno, cmd);
|
308
|
}
|
309
|
|
310
|
/*
|
311
|
int AxionAcs::GetEventId(int i) {
|
312
|
return events[i].eventId;
|
313
|
}
|
314
|
*/
|
315
|
|
316
|
string AxionAcs::Getusername() {
|
317
|
return username;
|
318
|
}
|
319
|
|
320
|
string AxionAcs::Getpassword() {
|
321
|
return password;
|
322
|
}
|
323
|
|
324
|
|
325
|
string AxionAcs::GetDoorId(int i) {
|
326
|
return events[i].subDeviceId;
|
327
|
}
|
328
|
|
329
|
string AxionAcs::GetEventTime(int i) {
|
330
|
return events[i].eventTime;
|
331
|
}
|
332
|
|
333
|
string AxionAcs::GetCardId(int i) {
|
334
|
return events[i].cardNo;
|
335
|
}
|
336
|
|
337
|
int AxionAcs::GetaccessBlockedReason(int i) {
|
338
|
return events[i].accessBlockedReason;
|
339
|
}
|
340
|
|
341
|
string AxionAcs::Getmapdoor(int i) {
|
342
|
return map_door[i];
|
343
|
}
|
344
|
|
345
|
void AxionAcs::PutSoe(int rtuno, int yxno, string time, string cardId) {
|
346
|
char ti[50] = { 0 };
|
347
|
char id[50] = { 0 };
|
348
|
if (time.length() < 50) { strcpy(ti, time.c_str());
|
349
|
} else { PrintLog(LOG_ERROR, "??ȡʵʱ?¼????Ƿ???ʱ?䣡"); return; }
|
350
|
if (cardId.length() < 50) {strcpy(id, cardId.c_str());
|
351
|
} else { PrintLog(LOG_ERROR, "??ȡʵʱ?¼????Ƿ??Ŀ??ţ?"); return; }
|
352
|
sint8 year = (ti[0] - 48) * 1000 + (ti[1] - 48) * 100 + (ti[2] - 48) * 10 + (ti[3] - 48);
|
353
|
sint8 month = (ti[5] - 48) * 10 + (ti[6] - 48);
|
354
|
sint8 day = (ti[8] - 48) * 10 + (ti[9] - 48);
|
355
|
sint8 hour = (ti[11] - 48) * 10 + (ti[12] - 48);
|
356
|
sint8 minute = (ti[14] - 48) * 10 + (ti[15] - 48);
|
357
|
sint8 second = (ti[17] - 48) * 10 + (ti[18] - 48);
|
358
|
int length = strlen(id);
|
359
|
if (length>15) {
|
360
|
length = 15;
|
361
|
PrintLog(LOG_ERROR, "??ȡʵʱ?¼?????ȡ???Ŀ??Ź?????ֻȡǰ15????");
|
362
|
}
|
363
|
|
364
|
S_RAWSOEEX soe;
|
365
|
soe.Source = DC_K_RTUSOE;
|
366
|
soe.Year = year;
|
367
|
soe.Month = month;
|
368
|
soe.Day = day;
|
369
|
soe.Hour = hour;
|
370
|
soe.Minute = minute;
|
371
|
soe.Second = second;
|
372
|
soe.Ms = 0;
|
373
|
soe.Rtuno = rtuno;
|
374
|
soe.Yxno = yxno;
|
375
|
soe.Val = 1;
|
376
|
soe.Type = DC_SOEEX_ACSCARD;
|
377
|
for (int i = 0; i < length; i++) {
|
378
|
soe.Data[i] = id[i];
|
379
|
}
|
380
|
soe.Data[length] = 0;
|
381
|
PRawCtrl->PutASoeEx(soe);
|
382
|
}
|
383
|
|
384
|
//??ȡ????????????
|
385
|
int AxionAcs::Getareas() {
|
386
|
int status = 0;
|
387
|
sint32 rtuno = Get_Rtuno();
|
388
|
|
389
|
char tmp_header[128] = { 0 };
|
390
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
391
|
string start_header = tmp_header;
|
392
|
|
393
|
string urls = server_urls + "/api/v1/areas";
|
394
|
string body = "";
|
395
|
string callback;
|
396
|
|
397
|
status = Fclient::Sendreq(urls, start_header, body, callback, 1);
|
398
|
if (status != -1) {
|
399
|
Put_AYx(rtuno, 1, 1);
|
400
|
} else { Put_AYx(rtuno, 1, 0); return 0; }
|
401
|
|
402
|
if (callback.size() <= 0) {
|
403
|
PrintLog(LOG_ERROR, "??ȡ???????????ݷ??ؽ??Ϊ?գ?");
|
404
|
return 0;
|
405
|
}
|
406
|
|
407
|
Json::Reader reader(Json::Features::strictMode());
|
408
|
Json::Value parse_callback;
|
409
|
if (reader.parse(callback, parse_callback)) {
|
410
|
int status = parse_callback["status"].asInt();
|
411
|
string msg = parse_callback["msg"].asString();
|
412
|
if (status != 0) {
|
413
|
PrintLog(LOG_ERROR, "??ȡ????????????ʧ?ܣ? ??????[%d]: %s", status, msg.c_str());
|
414
|
return 0;
|
415
|
}
|
416
|
|
417
|
int size = 0;
|
418
|
if (parse_callback["data"].isArray()) {
|
419
|
size = parse_callback["data"].size();
|
420
|
} else { return 0; }
|
421
|
PrintLog(LOG_INFORMATION, "??ȡ????????ܸ???Ϊ??%d", size);
|
422
|
|
423
|
for (int i = 0; i < size; i++) {
|
424
|
int areaId = parse_callback["data"][i]["areaId"].asInt();
|
425
|
string areaName = parse_callback["data"][i]["areaName"].asString();
|
426
|
string areaCode = parse_callback["data"][i]["areaCode"].asString();
|
427
|
int parentId = parse_callback["data"][i]["parentId"].asInt();
|
428
|
|
429
|
area area_tmp;
|
430
|
area_tmp.areaId = areaId;
|
431
|
area_tmp.areaName = areaName;
|
432
|
area_tmp.areaCode = areaCode;
|
433
|
area_tmp.parentId = parentId;
|
434
|
areas.push_back(area_tmp);
|
435
|
}
|
436
|
}
|
437
|
return 1;
|
438
|
}
|
439
|
|
440
|
//??ȡ?????Ž??豸????
|
441
|
int AxionAcs::GetDevices() {
|
442
|
int status = 0;
|
443
|
sint32 rtuno = Get_Rtuno();
|
444
|
|
445
|
char tmp_header[128] = { 0 };
|
446
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
447
|
string start_header = tmp_header;
|
448
|
|
449
|
string urls = server_urls + "/api/v1/acs/devices";
|
450
|
string body = "";
|
451
|
string callback;
|
452
|
|
453
|
status = Fclient::Sendreq(urls, start_header, body, callback, 1);
|
454
|
// PrintLog(3, "?Ž??豸%d %d",status,callback.size());
|
455
|
if (status != -1) {
|
456
|
Put_AYx(rtuno, 1, 1);
|
457
|
// PrintLog(3, "111111??");
|
458
|
} else {
|
459
|
Put_AYx(rtuno, 1, 0);
|
460
|
// PrintLog(3, "000000??");
|
461
|
return 0;
|
462
|
}
|
463
|
|
464
|
if (callback.size() <= 0) {
|
465
|
PrintLog(LOG_ERROR, "??ȡ?????Ž??豸???ݷ??ؽ??Ϊ?գ?");
|
466
|
return 0;
|
467
|
}
|
468
|
|
469
|
Json::Reader reader(Json::Features::strictMode());
|
470
|
Json::Value parse_callback;
|
471
|
if (reader.parse(callback, parse_callback)) {
|
472
|
int status = parse_callback["status"].asInt();
|
473
|
string msg = parse_callback["msg"].asString();
|
474
|
if (status != 0) {
|
475
|
PrintLog(LOG_ERROR, "??ȡ?????Ž??豸????ʧ?ܣ? ??????[%d]: %s", status, msg.c_str());
|
476
|
return 0;
|
477
|
}
|
478
|
|
479
|
int size = 0;
|
480
|
if (parse_callback["data"].isArray()) {
|
481
|
size = parse_callback["data"].size();
|
482
|
deviceNum = size;
|
483
|
} else { return 0; }
|
484
|
PrintLog(LOG_INFORMATION, "??ȡ???Ž??豸???ܸ???Ϊ??%d", size);
|
485
|
|
486
|
for (int i = 0; i < size; i++) {
|
487
|
string deviceId = parse_callback["data"][i]["deviceId"].asString();
|
488
|
string deviceName = parse_callback["data"][i]["deviceName"].asString();
|
489
|
int areaId = parse_callback["data"][i]["areaId"].asInt();
|
490
|
string areaName = parse_callback["data"][i]["areaName"].asString();
|
491
|
string deviceSn = parse_callback["data"][i]["deviceSn"].asString();
|
492
|
string commAddr = parse_callback["data"][i]["commAddr"].asString();
|
493
|
int isOnline = parse_callback["data"][i]["isOnline"].asInt();
|
494
|
string commErrorMsg = parse_callback["data"][i]["commErrorMsg"].asString();
|
495
|
|
496
|
device device_tmp;
|
497
|
device_tmp.deviceNo = i + 1;
|
498
|
device_tmp.deviceId = deviceId;
|
499
|
device_tmp.deviceName = deviceName;
|
500
|
device_tmp.areaId = areaId;
|
501
|
device_tmp.areaName = areaName;
|
502
|
device_tmp.deviceSn = deviceSn;
|
503
|
device_tmp.commAddr = commAddr;
|
504
|
device_tmp.isOnline = isOnline;
|
505
|
device_tmp.commErrorMsg = commErrorMsg;
|
506
|
devices.push_back(device_tmp);
|
507
|
|
508
|
map_device[i + 1] = deviceId;
|
509
|
}
|
510
|
}
|
511
|
// PrintLog(3, "222222??");
|
512
|
return 1;
|
513
|
}
|
514
|
|
515
|
//??ȡ??????????
|
516
|
int AxionAcs::GetDoors() {
|
517
|
int status = 0;
|
518
|
sint32 rtuno = Get_Rtuno();
|
519
|
|
520
|
char tmp_header[128] = { 0 };
|
521
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
522
|
string start_header = tmp_header;
|
523
|
|
524
|
string urls = server_urls + "/api/v1/acs/device/doors";
|
525
|
string body = "";
|
526
|
string callback;
|
527
|
|
528
|
status = Fclient::Sendreq(urls, start_header, body, callback, 1);
|
529
|
// PrintLog(3, "??????%d %d", status, callback.size());
|
530
|
if (status != -1) {
|
531
|
Put_AYx(rtuno, 1, 1);
|
532
|
} else { Put_AYx(rtuno, 1, 0); return 0; }
|
533
|
|
534
|
|
535
|
/*
|
536
|
doorNum = 5;
|
537
|
map_door[1] = "fb6b37cf331f409d9b4e9c5161043707";
|
538
|
map_door[2] = "c034f795a2c0401584bc13c767d598b6";
|
539
|
map_door[3] = "80b3b27f29044b55b81b75cd8b3b10fc";
|
540
|
map_door[4] = "b15b2026ed104953be046f2b1924e0a9";
|
541
|
map_door[5] = "c733f78d42cb4f8d81174a3572d15957";
|
542
|
*/
|
543
|
|
544
|
if (callback.size() <= 0) {
|
545
|
PrintLog(LOG_ERROR, "??ȡ?????????ݷ??ؽ??Ϊ?գ?");
|
546
|
return 0;
|
547
|
}
|
548
|
|
549
|
Json::Reader reader(Json::Features::strictMode());
|
550
|
|
551
|
Json::Value parse_callback;
|
552
|
PrintLog(LOG_ERROR, "??????????");
|
553
|
if (reader.parse(callback, parse_callback)) {
|
554
|
|
555
|
int status = parse_callback["status"].asInt();
|
556
|
string msg = parse_callback["msg"].asString();
|
557
|
|
558
|
if (status != 0) {
|
559
|
PrintLog(LOG_ERROR, "??ȡ??????????ʧ?ܣ? ??????[%d]: %s", status, msg.c_str());
|
560
|
return 0;
|
561
|
}
|
562
|
|
563
|
int size = 0;
|
564
|
if (parse_callback["data"].isArray()) {
|
565
|
size = parse_callback["data"].size();
|
566
|
doorNum = size;
|
567
|
} else { return 0; }
|
568
|
PrintLog(LOG_INFORMATION, "??ȡ???ŵ??ܸ???Ϊ??%d", size);
|
569
|
|
570
|
std::string time;
|
571
|
time = convertTime(GetNowSecond());
|
572
|
std::ofstream outfile;
|
573
|
outfile.open(logName, std::ios_base::app);
|
574
|
outfile << "[" << time << "] " << std::endl;
|
575
|
for (int i = 0; i < size; i++) {
|
576
|
string doorId = parse_callback["data"][i]["doorId"].asString();
|
577
|
string doorName = parse_callback["data"][i]["doorName"].asString();
|
578
|
string doorAddr = parse_callback["data"][i]["doorAddr"].asString();
|
579
|
int areaId = parse_callback["data"][i]["areaId"].asInt();
|
580
|
string areaName = parse_callback["data"][i]["areaName"].asString();
|
581
|
string deviceId = parse_callback["data"][i]["deviceId"].asString();
|
582
|
string deviceName = parse_callback["data"][i]["deviceName"].asString();
|
583
|
|
584
|
door door_tmp;
|
585
|
door_tmp.doorNo = i + 1;
|
586
|
door_tmp.doorId = doorId;
|
587
|
door_tmp.doorName = doorName;
|
588
|
door_tmp.doorAddr = doorAddr;
|
589
|
door_tmp.areaId = areaId;
|
590
|
door_tmp.areaName = areaName;
|
591
|
door_tmp.deviceId = deviceId;
|
592
|
door_tmp.deviceName = deviceName;
|
593
|
doors.push_back(door_tmp);
|
594
|
|
595
|
map_door[i + 1] = doorId;
|
596
|
|
597
|
outfile << "[ door" << i + 1 << " ]" << std::endl;
|
598
|
outfile << " doorId?? " << doorId << std::endl;
|
599
|
outfile << " doorName?? " << doorName << std::endl;
|
600
|
outfile << " doorAddr?? " << doorAddr << std::endl;
|
601
|
outfile << " areaId?? " << areaId << std::endl;
|
602
|
outfile << " areaName?? " << areaName << std::endl;
|
603
|
outfile << " deviceId?? " << deviceId << std::endl;
|
604
|
outfile << " deviceName??" << deviceName << std::endl;
|
605
|
}
|
606
|
outfile.close();
|
607
|
}
|
608
|
|
609
|
return 1;
|
610
|
}
|
611
|
|
612
|
//??ȡ??doorNo???ŵ?״̬
|
613
|
int AxionAcs::GetDoorState(int doorNo) {
|
614
|
|
615
|
int status = 0;
|
616
|
sint32 rtuno = Get_Rtuno();
|
617
|
|
618
|
char tmp_header[128] = { 0 };
|
619
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
620
|
string start_header = tmp_header;
|
621
|
|
622
|
string urls = server_urls + "/api/v1/acs/device/door/state/"+map_door[doorNo];
|
623
|
string body = "";
|
624
|
// string callback;
|
625
|
|
626
|
string con_urls = "/api/v1/acs/device/door/state/" + map_door[doorNo];
|
627
|
// PrintLog(LOG_ERROR, "!!!!!%d %d ", httpflag1, con_urls.find("swipecard"));
|
628
|
// PrintLog(LOG_ERROR, "????????????%d??", httpflag1_doors);
|
629
|
// PrintLog(LOG_ERROR, "%d%s%s%s%s??", httpflag1, urls.c_str(), start_header.c_str(), con_urls.c_str(), urls_tmp);
|
630
|
// if (iii == 555) { PrintLog(LOG_INFORMATION, "ͣ???⣡"); sleep(1000000); }
|
631
|
status = fclient_door.SendreqLong(urls, start_header, body, 1, httpflag1_doors, con_urls, urls_ip);
|
632
|
// PrintLog(3, "??״̬%d %d %s", status, fclient.call_back.size(), fclient.call_back.c_str()); //---------
|
633
|
// SeSleep(100000);
|
634
|
// PrintLog(LOG_INFORMATION, "ͣ???⣡");
|
635
|
if (status != -1) {
|
636
|
Put_AYx(rtuno, 1, 1);
|
637
|
} else {
|
638
|
Put_AYx(rtuno, 1, 0);
|
639
|
fclient_door.free_mg();
|
640
|
httpflag_doors = false;
|
641
|
PrintLog(LOG_ERROR, "??״̬????ʧ?ܣ? ??[%d]ID:%s", doorNo, map_door[doorNo].c_str());
|
642
|
return 0;
|
643
|
}
|
644
|
|
645
|
|
646
|
|
647
|
if (fclient_door.call_back.size() <= 0) {
|
648
|
PrintLog(LOG_ERROR, "??ȡ??%d???ŵ?״̬???ݷ??ؽ??Ϊ?գ?",doorNo);
|
649
|
return 0;
|
650
|
}
|
651
|
|
652
|
Json::Reader reader(Json::Features::strictMode());
|
653
|
Json::Value parse_callback;
|
654
|
if (reader.parse(fclient_door.call_back, parse_callback)) {
|
655
|
int status = parse_callback["status"].asInt();
|
656
|
string msg = parse_callback["msg"].asString();
|
657
|
int isOnline = parse_callback["isOnLine"].asInt();
|
658
|
int isOpen = parse_callback["isOpen"].asInt();
|
659
|
if (status != 0) {
|
660
|
PrintLog(LOG_ERROR, "??ȡ??%d???ŵ?״̬????ʧ?ܣ? ??????[%d]: %s", doorNo, status, msg.c_str());
|
661
|
return 0;
|
662
|
}
|
663
|
if (isOnline==0) {
|
664
|
Put_AYx(rtuno, doorNo * 10, 0);
|
665
|
// PrintLog(LOG_ERROR, "??ǰ??%d???Ŵ???????״̬??", doorNo);
|
666
|
} else {
|
667
|
Put_AYx(rtuno, doorNo * 10, 1);
|
668
|
if (isOpen==1) {
|
669
|
Put_AYx(rtuno, doorNo * 10 + 1, 1);
|
670
|
// PrintLog(LOG_INFORMATION, "??ǰ??%d???ŵ?״̬Ϊ????", doorNo);
|
671
|
} else {
|
672
|
Put_AYx(rtuno, doorNo * 10 + 1, 0);
|
673
|
// PrintLog(LOG_INFORMATION, "??ǰ??%d???ŵ?״̬Ϊ???رգ?", doorNo);
|
674
|
}
|
675
|
}
|
676
|
}
|
677
|
return 1;
|
678
|
}
|
679
|
|
680
|
|
681
|
//???Ƶ?doorNO???ŵ?״̬Ϊ????
|
682
|
int AxionAcs::SetDoorOpen(int doorNo) {
|
683
|
int status = 0;
|
684
|
sint32 rtuno = Get_Rtuno();
|
685
|
|
686
|
char tmp_header[128] = { 0 };
|
687
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
688
|
string start_header = tmp_header;
|
689
|
|
690
|
string urls = server_urls + "/api/v1/acs/device/door/open/" + username + "/" + password + "/" + map_door[doorNo];
|
691
|
|
692
|
|
693
|
|
694
|
|
695
|
string body = "";
|
696
|
string callback;
|
697
|
|
698
|
status = Fclient::Sendreq(urls, start_header, body, callback, 1);
|
699
|
if (status != -1) {
|
700
|
Put_AYx(rtuno, 1, 1);
|
701
|
} else { Put_AYx(rtuno, 1, 0); return 0; }
|
702
|
|
703
|
if (callback.size() <= 0) {
|
704
|
PrintLog(LOG_ERROR, "???Ƶ?%d???Ŵ????ݷ??ؽ??Ϊ?գ?", doorNo);
|
705
|
return 0;
|
706
|
}
|
707
|
|
708
|
Json::Reader reader(Json::Features::strictMode());
|
709
|
Json::Value parse_callback;
|
710
|
if (reader.parse(callback, parse_callback)) {
|
711
|
int status = parse_callback["status"].asInt();
|
712
|
string msg = parse_callback["msg"].asString();
|
713
|
if (status!=0) {
|
714
|
Put_AYx(rtuno, 2, 0);
|
715
|
PrintLog(LOG_ERROR, "???Ƶ?%d???Ŵ?ʧ?ܣ? ??????[%d]: %s", doorNo, status, msg.c_str());
|
716
|
return 0;
|
717
|
} else {
|
718
|
Put_AYx(rtuno, 2, 1);
|
719
|
PrintLog(LOG_INFORMATION, "???Ƶ?%d???Ŵɹ???", doorNo);
|
720
|
}
|
721
|
}
|
722
|
return 1;
|
723
|
}
|
724
|
|
725
|
//???Ƶ?doorNO???ŵ?״̬Ϊ???ر?
|
726
|
int AxionAcs::SetDoorClose(int doorNo) {
|
727
|
int status = 0;
|
728
|
sint32 rtuno = Get_Rtuno();
|
729
|
|
730
|
char tmp_header[128] = { 0 };
|
731
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
732
|
string start_header = tmp_header;
|
733
|
|
734
|
string urls = server_urls + "/api/v1/acs/device/door/close/" + username + "/" + password + "/" + map_door[doorNo];
|
735
|
string body = "";
|
736
|
string callback;
|
737
|
|
738
|
status = Fclient::Sendreq(urls, start_header, body, callback, 1);
|
739
|
if (status != -1) {
|
740
|
Put_AYx(rtuno, 1, 1);
|
741
|
} else { Put_AYx(rtuno, 1, 0); return 0; }
|
742
|
|
743
|
if (callback.size() <= 0) {
|
744
|
PrintLog(LOG_ERROR, "???Ƶ?%d???Źرյ????ݷ??ؽ??Ϊ?գ?", doorNo);
|
745
|
return 0;
|
746
|
}
|
747
|
|
748
|
Json::Reader reader(Json::Features::strictMode());
|
749
|
Json::Value parse_callback;
|
750
|
if (reader.parse(callback, parse_callback)) {
|
751
|
int status = parse_callback["status"].asInt();
|
752
|
string msg = parse_callback["msg"].asString();
|
753
|
if (status != 0) {
|
754
|
Put_AYx(rtuno, 2, 0);
|
755
|
PrintLog(LOG_ERROR, "???Ƶ?%d???Źر?ʧ?ܣ? ??????[%d]: %s", doorNo, status, msg.c_str());
|
756
|
return 0;
|
757
|
} else {
|
758
|
Put_AYx(rtuno, 2, 1);
|
759
|
PrintLog(LOG_INFORMATION, "???Ƶ?%d???Źرճɹ???", doorNo);
|
760
|
}
|
761
|
}
|
762
|
return 1;
|
763
|
}
|
764
|
|
765
|
|
766
|
//???Ƶ?doorNO???ŵĹ???ģʽΪmode 0???Զ???1??ˢ????2????+???룬3?????????룬4????????5?????գ?6????????
|
767
|
int AxionAcs::SetDoorMode(int doorNo, string mode) {
|
768
|
int status = 0;
|
769
|
sint32 rtuno = Get_Rtuno();
|
770
|
|
771
|
char tmp_header[128] = { 0 };
|
772
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
773
|
string start_header = tmp_header;
|
774
|
|
775
|
string urls = server_urls + "/api/v1/acs/device/door/workmode/" + username + "/" + password + "/" + map_door[doorNo] + "/" + mode;
|
776
|
string body = "";
|
777
|
string callback;
|
778
|
|
779
|
status = Fclient::Sendreq(urls, start_header, body, callback, 1);
|
780
|
if (status != -1) {
|
781
|
Put_AYx(rtuno, 1, 1);
|
782
|
} else { Put_AYx(rtuno, 1, 0); return 0; }
|
783
|
|
784
|
if (callback.size() <= 0) {
|
785
|
PrintLog(LOG_ERROR, "???õ?%d???ŵĹ???ģʽΪ%s ???ؽ??Ϊ?գ?", doorNo, mode.c_str());
|
786
|
return 0;
|
787
|
}
|
788
|
|
789
|
Json::Reader reader(Json::Features::strictMode());
|
790
|
Json::Value parse_callback;
|
791
|
if (reader.parse(callback, parse_callback)) {
|
792
|
int status = parse_callback["status"].asInt();
|
793
|
string msg = parse_callback["msg"].asString();
|
794
|
if (status != 0) {
|
795
|
Put_AYx(rtuno, 2, 0);
|
796
|
PrintLog(LOG_ERROR, "???õ?%d???ŵĹ???ģʽΪ%s ʧ?ܣ? ??????[%d]: %s", doorNo, mode.c_str(), status, msg.c_str());
|
797
|
return 0;
|
798
|
} else {
|
799
|
Put_AYx(rtuno, 2, 1);
|
800
|
PrintLog(LOG_INFORMATION, "???õ?%d???ŵĹ???ģʽΪ%s ?ɹ???", doorNo, mode.c_str());
|
801
|
}
|
802
|
}
|
803
|
return 1;
|
804
|
}
|
805
|
|
806
|
|
807
|
//??ȡ?????豸??ʵʱˢ????¼
|
808
|
int AxionAcs::GetSwipecard() {
|
809
|
int status = 0;
|
810
|
int size = 0;
|
811
|
sint32 rtuno = Get_Rtuno();
|
812
|
|
813
|
char tmp_header[128] = { 0 };
|
814
|
sprintf(tmp_header, "Connection:keep-alive\r\n");
|
815
|
string start_header = tmp_header;
|
816
|
|
817
|
string urls = server_urls + "/api/v1/acs/device/eventcache/swipecard/";
|
818
|
for (int i = 0; i < deviceNum; i++) {
|
819
|
if (i==(deviceNum-1)) {
|
820
|
urls = urls + map_device[i + 1];
|
821
|
} else {
|
822
|
urls = urls + map_device[i + 1] + ",";
|
823
|
}
|
824
|
}
|
825
|
|
826
|
string body = "";
|
827
|
// string callback;
|
828
|
|
829
|
string con_urls = "/api/v1/acs/device/eventcache/swipecard/";
|
830
|
for (int i = 0; i < deviceNum; i++) {
|
831
|
if (i == (deviceNum - 1)) {
|
832
|
con_urls = con_urls + map_device[i + 1];
|
833
|
} else {
|
834
|
con_urls = con_urls + map_device[i + 1] + ",";
|
835
|
}
|
836
|
}
|
837
|
|
838
|
|
839
|
// PrintLog(LOG_ERROR, "!!!!!%d %d ", httpflag1_devices, con_urls.find("swipecard"));
|
840
|
// SeSleep(10000000);
|
841
|
|
842
|
// PrintLog(LOG_ERROR, "11111%s??", urls_ip.c_str());
|
843
|
status = fclient_device.SendreqLong(urls, start_header, body, 1, httpflag1_devices, con_urls, urls_ip);
|
844
|
// status = Fclient::Sendreq(urls, start_header, body, callback, 2);
|
845
|
|
846
|
// PrintLog(LOG_ERROR, "22222%s %d??", urls_ip.c_str(), status);
|
847
|
// SeSleep(10000000);
|
848
|
if (status != -1) {
|
849
|
Put_AYx(rtuno, 1, 1);
|
850
|
} else {
|
851
|
Put_AYx(rtuno, 1, 0);
|
852
|
fclient_device.free_mg();
|
853
|
httpflag_devices = false;
|
854
|
PrintLog(LOG_ERROR, "?¼?????ʧ?ܣ?");
|
855
|
return 0;
|
856
|
}
|
857
|
|
858
|
if (fclient_device.call_back.size() <= 0) {
|
859
|
PrintLog(LOG_ERROR, "??ȡʵʱˢ????¼???ؽ??Ϊ?գ?");
|
860
|
return 0;
|
861
|
}
|
862
|
|
863
|
Json::Reader reader(Json::Features::strictMode());
|
864
|
Json::Value parse_callback;
|
865
|
if (reader.parse(fclient_device.call_back, parse_callback)) {
|
866
|
int status = parse_callback["status"].asInt();
|
867
|
string msg = parse_callback["msg"].asString();
|
868
|
if (status != 0) {
|
869
|
PrintLog(LOG_ERROR, "??ȡʵʱˢ????¼ʧ?ܣ? ??????[%d]: %s", status, msg.c_str());
|
870
|
return 0;
|
871
|
}
|
872
|
|
873
|
if (parse_callback["data"].isArray()) {
|
874
|
size = parse_callback["data"].size();
|
875
|
} else { return 0; }
|
876
|
// PrintLog(LOG_INFORMATION, "??ǰ??ȡ??ʵʱˢ????¼????Ϊ??%d", size);
|
877
|
|
878
|
events.clear(); //??ȡʵʱˢ????¼֮ǰ?????events????
|
879
|
eventid[100] = { 0 }; //????ȡ????˳?????¼?ID
|
880
|
eventidex[100] = { 0 }; //???¼?ID?Ĵ?С??С??????eventid[]??????
|
881
|
for (int i = 0; i < size; i++) {
|
882
|
int eventId = parse_callback["data"][i]["eventId"].asInt(); //?¼?ID
|
883
|
string areaName = parse_callback["data"][i]["areaName"].asString(); //????????
|
884
|
string deviceName = parse_callback["data"][i]["deviceName"].asString(); //?Ž??豸????
|
885
|
string subDeviceId = parse_callback["data"][i]["subDeviceId"].asString(); //??ID
|
886
|
string subDeviceName = parse_callback["data"][i]["subDeviceName"].asString(); //??????
|
887
|
string eventTime = parse_callback["data"][i]["eventTime"].asString(); //?¼?ʱ??
|
888
|
string eventName = parse_callback["data"][i]["eventName"].asString(); //?¼?????
|
889
|
string cardNo = parse_callback["data"][i]["cardNo"].asString(); //????
|
890
|
string cardType = parse_callback["data"][i]["cardType"].asString(); //??Ƭ????
|
891
|
int accessBlockedReason = parse_callback["data"][i]["accessBlockedReason"].asInt(); //?ܾ?????
|
892
|
|
893
|
event event_tmp;
|
894
|
event_tmp.eventId = eventId;
|
895
|
event_tmp.areaName = areaName;
|
896
|
event_tmp.deviceName = deviceName;
|
897
|
event_tmp.subDeviceId = subDeviceId;
|
898
|
event_tmp.subDeviceName = subDeviceName;
|
899
|
event_tmp.eventTime = eventTime;
|
900
|
event_tmp.eventName = eventName;
|
901
|
event_tmp.cardNo = cardNo;
|
902
|
event_tmp.cardType = cardType;
|
903
|
event_tmp.accessBlockedReason = accessBlockedReason;
|
904
|
events.push_back(event_tmp);
|
905
|
eventid[i] = eventId;
|
906
|
}
|
907
|
for (int i = 0; i < size; i++) {
|
908
|
for (int j = 0; j < size; j++) {
|
909
|
if (eventid[i]>eventid[j]) {
|
910
|
eventidex[i]++;
|
911
|
}
|
912
|
}
|
913
|
}
|
914
|
}
|
915
|
return size;
|
916
|
}
|
917
|
|
918
|
|
919
|
|
920
|
|
921
|
|
922
|
//------------------------
|
923
|
void AxionAcs::ReadIni() {
|
924
|
char filename[512] = { 0 };
|
925
|
CReadConf readconf;
|
926
|
sint32 rtuno = pLink->GetRtuNo();
|
927
|
memset(logName, 0, 256);
|
928
|
|
929
|
char* pWorkPath = getenv("SEROOT");
|
930
|
if (pWorkPath != NULL) {
|
931
|
sprintf(filename, "%s%s%d%s", pWorkPath, "/cfg/AxiomAcsRTU", rtuno, ".ini");
|
932
|
sprintf(logName, "%s%s%d%s", pWorkPath, "/log/AxiomAcsRTU", rtuno, ".txt");
|
933
|
} else {
|
934
|
PrintLog(LOG_ERROR, "????????δ????");
|
935
|
return;
|
936
|
}
|
937
|
|
938
|
char urls_tmp[128] = { 0 };
|
939
|
string head_tmp = "http://";
|
940
|
readconf.ReadString("LoginInfo", "server_urls", urls_tmp, filename, "10.44.1.90:6500");
|
941
|
readconf.ReadString("LoginInfo", "username",username, filename, "admin");
|
942
|
readconf.ReadString("LoginInfo", "password",password, filename, "1");
|
943
|
server_urls = head_tmp + urls_tmp;
|
944
|
urls_ip = urls_tmp;
|
945
|
}
|
946
|
|
947
|
sint32 AxionAcs::TxProc() {
|
948
|
return 1;
|
949
|
}
|
950
|
|
951
|
sint32 AxionAcs::RxProc() {
|
952
|
return 1;
|
953
|
}
|
954
|
|
955
|
|
956
|
|
957
|
#if defined(WIN32)
|
958
|
extern "C" __declspec(dllexport)
|
959
|
#else
|
960
|
extern "C"
|
961
|
#endif
|
962
|
CProtocol *CreateProtocol(char *defpara) {
|
963
|
return (CProtocol*)(new AxionAcs());
|
964
|
}
|
965
|
|
966
|
/*
|
967
|
#ifdef __unix
|
968
|
extern "C" CProtocol* CreateProtocol(char *defpara)
|
969
|
#else
|
970
|
extern "C" __declspec(dllexport) CProtocol* CreateProtocol(char *defpara)
|
971
|
#endif
|
972
|
{
|
973
|
CProtocol *pEpv = new AxionAcs;
|
974
|
return pEpv;
|
975
|
}
|
976
|
*/
|