Project

General

Profile

Feature #3003 » DHacs.cpp

yan hong, 05/29/2023 10:39 AM

 
1
#ifdef WIN32
2
#include "stdafx.h"
3
#endif
4
#include "DHacs.h"
5
#include "se_btl.h"
6
#include "se_log.h"
7
#include <fstream>
8
#include <string>
9
#ifdef WIN32
10
#include <direct.h>
11
#include <io.h>
12
#else
13
#include <sys/stat.h>
14
#include <sys/io.h>
15
#include <stdio.h>
16
#include <unistd.h>
17
#include <sys/types.h>
18
#endif
19

    
20
#ifdef _DEBUG
21
#undef THIS_FILE
22
static char THIS_FILE[] = __FILE__;
23
#define new DEBUG_NEW
24
#endif
25
//ALARM_ACCESS_CTL_EVENT_INFO
26

    
27

    
28

    
29
void CALLBACK DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser) {
30
	DHacs* dh = (DHacs*)dwUser;
31
	dh->PrintLog(LOG_ERROR, "?豸????");
32
	dh->Register_Frm();
33
}
34

    
35

    
36
BOOL CALLBACK afMassCallBack(LONG lCommand, LLONG lLinID, char *pBuf, DWORD dwBufLen, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser) {
37
	
38
	
39
	if (lCommand == DH_ALARM_ACCESS_CTL_STATUS) {
40
		ALARM_ACCESS_CTL_STATUS_INFO* pstAccessInfo = (ALARM_ACCESS_CTL_STATUS_INFO*)pBuf;
41
		DHacs* dh = (DHacs*)dwUser;
42
		uint16 RtuNo = dh->Get_rtuno();
43
		NET_TIME stutime;
44
		stutime = pstAccessInfo->stuTime;
45
		S_RAWSOE soe;
46
		soe.Source = DC_K_RTUSOE;
47
		soe.Year = stutime.dwYear;
48
		soe.Month = stutime.dwMonth;
49
		soe.Day = stutime.dwDay;
50
		soe.Hour = stutime.dwHour;
51
		soe.Minute = stutime.dwMinute;
52
		soe.Second = stutime.dwSecond;
53
		soe.Ms = 0;				//
54
		soe.Rtuno = RtuNo;
55
		soe.Val = 1;
56
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_UNKNOWN) {
57
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 11;		//1??δ֪ 2?????? 3?????? 4???쳣 5?????? 6?????? 7?????? 8??????
58
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:δ֪", 1 + pstAccessInfo->nDoor);
59
		}
60
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_OPEN) {
61
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 12;
62
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:????", 1 + pstAccessInfo->nDoor);
63
		}
64
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_CLOSE) {
65
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 13;
66
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:????", 1 + pstAccessInfo->nDoor);
67
		}
68
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_ABNORMAL) {
69
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 14;
70
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:?쳣", 1 + pstAccessInfo->nDoor);
71
		}
72
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_FAKELOCKED) {
73
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 15;
74
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:????", 1 + pstAccessInfo->nDoor);
75
		}
76
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_CLOSEALWAYS) {
77
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 16;
78
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:????", 1 + pstAccessInfo->nDoor);
79
		}
80
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_OPENALWAYS) {
81
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 17;
82
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:????", 1 + pstAccessInfo->nDoor);
83
		}
84
		if (pstAccessInfo->emStatus == NET_ACCESS_CTL_STATUS_TYPE_NORMAL) {
85
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 18;
86
			dh->PrintLog(LOG_INFORMATION, "[?Ž?״̬?¼?] ??%d ״̬??Ϊ:????", 1 + pstAccessInfo->nDoor);
87
		}
88
		dh->PutSoe(soe);
89
	}
90
	
91

    
92

    
93
	if (lCommand == DH_ALARM_ACCESS_CTL_EVENT) {
94
		ALARM_ACCESS_CTL_EVENT_INFO* pstAccessInfo = (ALARM_ACCESS_CTL_EVENT_INFO*)pBuf;
95
		DHacs* dh = (DHacs*)dwUser;
96
		uint16 RtuNo = dh->Get_rtuno();
97
		NET_TIME stutime;
98
		stutime = pstAccessInfo->stuTime;
99
		S_RAWSOE soe;
100
		soe.Source = DC_K_RTUSOE;
101
		soe.Year = stutime.dwYear;
102
		soe.Month = stutime.dwMonth;
103
		soe.Day = stutime.dwDay;
104
		soe.Hour = stutime.dwHour;
105
		soe.Minute = stutime.dwMinute;
106
		soe.Second = stutime.dwSecond;
107
		soe.Ms = 0;				//
108
		soe.Rtuno = RtuNo;
109
		soe.Val = 1;
110
		//101:???뿪?? 102??ˢ?????? 103??Զ?̿??? 104????????ť???? 105????Ϣ????
111
		if (pstAccessInfo->emOpenMethod == NET_ACCESS_DOOROPEN_METHOD_PWD_ONLY) {		// ???뿪??
112
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 21;
113
			dh->PrintLog(LOG_INFORMATION, "[?Ž??¼?] ??%d ??????ʽ:???뿪??", 1 + pstAccessInfo->nDoor);
114
		}
115
		if (pstAccessInfo->emOpenMethod == NET_ACCESS_DOOROPEN_METHOD_CARD) {			// ˢ??????
116
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 22;
117
			dh->PrintLog(LOG_INFORMATION, "[?Ž??¼?] ??%d ??????ʽ:ˢ??????", 1 + pstAccessInfo->nDoor);
118
		}
119
		if (pstAccessInfo->emOpenMethod == NET_ACCESS_DOOROPEN_METHOD_REMOTE) {			//Զ?̿???
120
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 23;
121
			dh->PrintLog(LOG_INFORMATION, "[?Ž??¼?] ??%d ??????ʽ:Զ?̿???", 1 + pstAccessInfo->nDoor);
122
		}
123
		if (pstAccessInfo->emOpenMethod == NET_ACCESS_DOOROPEN_METHOD_BUTTON) {			//??????ť???п???
124
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 24;
125
			dh->PrintLog(LOG_INFORMATION, "[?Ž??¼?] ??%d ??????ʽ:??????ť???п???", 1 + pstAccessInfo->nDoor);
126
		}
127
		if (pstAccessInfo->emOpenMethod == NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT) {	//??Ϣ????
128
			soe.Yxno = (pstAccessInfo->nDoor) * 30 + 25;
129
			dh->PrintLog(LOG_INFORMATION, "[?Ž??¼?] ??%d ??????ʽ:??Ϣ????", 1 + pstAccessInfo->nDoor);
130
		}
131
		dh->PutSoe(soe);
132
	}
133
	return true;
134
}
135

    
136

    
137
UINT rxprocess(LPVOID rxptr) {
138
	DHacs* rtxpPara = NULL;
139
	rtxpPara = (DHacs*)rxptr;
140

    
141
//	CLIENT_SetDVRMessCallBack(afMassCallBack, 0);
142
	rtxpPara->SetCallBack();
143

    
144

    
145
	rtxpPara->GetGroups();
146

    
147
	bool listenflag = true;
148
	bool islisten = false;
149
	while (rtxpPara->rxflag) {
150
		for (int i = 0; i < rtxpPara->nchannelnum; i++) {
151
			if (listenflag) {
152
				if (CLIENT_StartListenEx(rtxpPara->ILoginHandle)) {
153
					islisten = true;
154
					rtxpPara->PrintLog(LOG_INFORMATION, "???ı??????óɹ???");
155
				} else {
156
					islisten = false;
157
					rtxpPara->PrintLog(LOG_ERROR, "???ı???????ʧ?ܣ?");
158
				}
159
				listenflag = false;
160
			}
161
			int sd = rtxpPara->SelectDoor(i, rtxpPara->ILoginHandle);
162
			if (sd == 0) {
163
				if (islisten) {
164
					CLIENT_StopListen(rtxpPara->ILoginHandle);
165
				}
166
				CLIENT_Logout(rtxpPara->ILoginHandle);
167
				int login = 0;
168
				while (!login) {
169
					login = rtxpPara->LoginDev();
170
					if (login) {
171
						listenflag = true;
172
					}
173
				}
174
			}
175
		}
176
		SeSleep(5000);
177
	}
178
	return 0;
179
}
180

    
181
UINT txprocess(LPVOID txptr) {
182
	DHacs* rtxpPara = NULL;
183
	rtxpPara = (DHacs*)txptr;
184
	sint32 rtuno = rtxpPara->Get_rtuno();
185
	while (rtxpPara->txflag) {
186
		S_RAWCMD rawcmd;
187
		while (rtxpPara->Get_CmdNum()>0) {
188
			if (rtxpPara->Get_ACmd(rtuno, &rawcmd) == 0)
189
				break;
190
			rtxpPara->PrintLog(LOG_INFORMATION, "?յ?%d???ն? ????:%d ", rtuno, rawcmd.type);
191
			uint8 len = 0;
192
			ST_TRACK_ADDR 	m_cmdaddr;     //?????ⲿ???ͨ???˱????????ⲿ?????ַ??Ϣ
193
			m_cmdaddr = rawcmd.src;
194
			switch (rawcmd.type) {
195
			case DC_K_CMD_DOOPER:{	//ң?أ??ؿ?????
196
									 S_DO_CTL *cmdinfo;
197
									 cmdinfo = (S_DO_CTL *)(&rawcmd.data);
198
									 uint16 ykno = (uint16)cmdinfo->ptAddr;//ң?غ?
199
									 switch (cmdinfo->funcCode) {
200
									 case DC_K_CTL_DOSEL:	//ѡ??
201
										 //ֱ?ӷ?У
202
										 rawcmd.type = DC_K_CMDRET_DOOPER;
203
										 rawcmd.len = sizeof(cmdinfo);
204
										 rawcmd.src = m_cmdaddr;
205
										 cmdinfo->retCode = 1;
206
										 rtxpPara->Rpt_AResult(rtuno, rawcmd);
207
										 break;
208

    
209
									 case DC_K_CTL_DOEXE:	//ִ??
210
										 uint16 ykvalue;
211
										 ykvalue = cmdinfo->ctlVal;
212
										 if ((ykno - (ykno / 30) * 30) == 5) {//Զ?̿?/????
213
											 //?ؿ?
214
											 if (ykvalue == 1) {
215
												 rtxpPara->OpenDoor(ykno / 30, rtxpPara->ILoginHandle);
216
											 }
217
											 //?ع?
218
											 if (ykvalue == 0) {
219
												 rtxpPara->CloseDoor(ykno / 30, rtxpPara->ILoginHandle);
220
											 }
221
										 }
222

    
223
										 if ((ykno - (ykno / 30) * 30) == 6) {//?س???
224
											 if (ykvalue == 1) {
225
												 rtxpPara->SetDoorNorOpen(ykno / 30, rtxpPara->ILoginHandle);
226
											 }
227
										 }
228

    
229
										 if ((ykno - (ykno / 30) * 30) == 7) {//?س???
230
											 if (ykvalue == 1) {
231
												 rtxpPara->SetDoorNorClose(ykno / 30, rtxpPara->ILoginHandle);
232
											 }
233
										 }
234

    
235
										 if ((ykno - (ykno / 30) * 30) == 6) {//?ָ?????
236
											 if (ykvalue == 1) {
237
												 rtxpPara->SetDoorNorNormal(ykno / 30, rtxpPara->ILoginHandle);
238
											 }
239
										 }
240

    
241
										 break;
242
									 case DC_K_CTL_DODEL://????
243
										 break;
244
									 }
245
			}
246
				break;
247
			default:
248
				break;
249
			}
250
			rtxpPara->Del_ACmd(rtuno);
251
		}
252

    
253
		SeSleep(500);
254
	}
255

    
256
	return 0;
257
}
258

    
259

    
260

    
261
DHacs::~DHacs() {}
262

    
263
//DHacs::DHacs() {}
264

    
265

    
266
void DHacs::Init(S_PROTOCOLCFG * pcfg) {
267
	PRawCtrl = pcfg->PRawCtrl;
268
	pCmdMem = pcfg->pCmdMem;
269
	pRtu = pcfg->pRtu;
270
	pLink = pcfg->pLink;
271

    
272
	
273

    
274
	memset(ip, 0, 64);
275
	memset(username, 0, 64);
276
	memset(password, 0, 64);
277
	ILoginHandle = 0;
278
	nchannelnum = 0;
279
	//	listen = 0;
280
	//	listenstate = false;
281

    
282
	sdkflag = true;
283
	rxflag = true;
284
	txflag = true;
285

    
286
	ReadIni();
287

    
288
	while (sdkflag) {
289
		bool sdk;
290
		sdk = CLIENT_Init(DisConnectFunc, (LDWORD)this);
291
		if (sdk) {
292
			PrintLog(LOG_INFORMATION, "SDK??ʼ????ɣ?");
293
			//			CLIENT_SetDVRMessCallBack(afMassCallBack, 0);
294
			int login = 0;
295
			while (!login) {
296
				login = LoginDev();
297
			}
298
			sdkflag = false;
299
		} else { PrintLog(LOG_ERROR, "SDK??ʼ??ʧ?ܣ?"); }
300
	}
301

    
302

    
303

    
304
	if (rxflag) {
305
		sint32 rxthread = SE_CreateThread((PTHREAD_FUNC_DEF)rxprocess, this, 100);
306
	}
307
	PrintLog(LOG_INFORMATION, "????rx?߳? !");
308

    
309
	if (txflag) {
310
		sint32 txthread = SE_CreateThread((PTHREAD_FUNC_DEF)txprocess, this, 100);
311
	}
312
	PrintLog(LOG_INFORMATION, "????tx?߳? !");
313

    
314
	/*
315
	S_RAWSOEEX soe;
316
	soe.Source = DC_K_RTUSOE;
317
	soe.Val=1;
318
	soe.Yxno = 1;
319
	PRawCtrl->PutASoeEx(soe);
320
	*/
321

    
322
}
323

    
324
/*
325
char * szOut11 = new char[1024 * 32];
326
CFG_ACCESS_EVENT_INFO stOut21 = { sizeof(stOut21) };
327
stOut21.emState = ACCESS_STATE_OPENALWAYS;
328
BOOL bRet2 = CLIENT_PacketData(CFG_CMD_ACCESS_EVENT, (char *)&stOut21,
329
sizeof(CFG_ACCESS_EVENT_INFO), szOut11, 1024 * 32);
330
if (bRet2) {
331
BOOL bRet3 = CLIENT_SetNewDevConfig(ILoginHandle, CFG_CMD_ACCESS_EVENT, 1, szOut11, 1024 * 32, NULL, NULL, 3000);
332
if (bRet3) {
333
int q = 1;
334
}
335
}
336

    
337

    
338

    
339
char * szOut1 = new char[1024 * 32];
340
CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
341
int nError = 0;
342
BOOL bRet = CLIENT_GetNewDevConfig(ILoginHandle, CFG_CMD_ACCESS_EVENT, 1, szOut1, 1024 * 32, &nError, 3000);
343
if (bRet) {
344
BOOL bRet1 = CLIENT_ParseData(CFG_CMD_ACCESS_EVENT, szOut1, &stOut2,
345
sizeof(CFG_ACCESS_EVENT_INFO), NULL);
346
if (bRet1) {
347
printf("??״̬??%d\n", stOut2.emState);
348
printf("????ʱ????%d\n", stOut2.nUnlockHoldInterval);
349
printf("???ų?ʱʱ????%d\n", stOut2.nCloseTimeout);
350
printf("????ģʽ??%d\n", stOut2.emDoorOpenMethod);
351
printf("в?ȣ?%d\n", stOut2.bDuressAlarmEnable);
352
}
353
}
354

    
355
*/
356
/*
357
char * szOut1 = new char[1024 * 32];
358
CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
359
int nError = 0;
360
BOOL bRet = CLIENT_GetNewDevConfig(ILoginHandle, CFG_CMD_ACCESS_EVENT, 1, szOut1, 1024 * 32, &nError, 3000);
361
if (bRet) {
362
BOOL bRet1 = CLIENT_ParseData(CFG_CMD_ACCESS_EVENT, szOut1, &stOut2,
363
sizeof(CFG_ACCESS_EVENT_INFO), NULL);
364
if (bRet1) {
365

    
366
}
367
}
368
*/
369
/*
370
char * szOut = new char[1024 * 32];
371
CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
372
stOut2.emState = ACCESS_STATE_NORMAL;
373
BOOL bRet2 = CLIENT_PacketData(CFG_CMD_ACCESS_EVENT, (char *)&stOut2,
374
sizeof(CFG_ACCESS_EVENT_INFO), szOut, 1024 * 32);
375
if (bRet2) {
376
BOOL bRet3 = CLIENT_SetNewDevConfig(ILoginHandle, CFG_CMD_ACCESS_EVENT, 0, szOut,
377
1024 * 32, NULL, NULL, 3000);
378
if (bRet3) {
379

    
380
}
381
}
382
*/
383

    
384

    
385
//???????ļ?
386
void DHacs::ReadIni() {
387
#ifdef WIN32
388
	char* home = getenv("SEROOT");
389
#else
390
	char* home = getenv("SEROOT");
391
#endif
392
	if (home == NULL) {
393
		PrintLog(LOG_ERROR, "????????δ????");
394
		return;
395
	}
396
	char filename[256] = { 0 };
397
	sint32 rtuno = pLink->GetRtuNo();
398
//	memset(logName, 0, 256);
399
#if defined(__unix)
400
	sprintf(filename, "%s%s%d%s", home, "/cfg/dhACSRTU", rtuno, ".ini");
401

    
402
#else
403
	sprintf(filename, "%s%s%d%s", home, "\\cfg\\dhACSRTU", rtuno, ".ini");
404

    
405
#endif
406
	CReadConf readconf;
407

    
408
	readconf.ReadString("ACSCFG", "IP", ip, filename, "");
409
	port = readconf.ReadLong("ACSCFG", "PORT", filename, "0");
410
	readconf.ReadString("ACSCFG", "UserName", username, filename, "");
411
	readconf.ReadString("ACSCFG", "PassWord", password, filename, "");
412
//	nchannelnum = readconf.ReadLong("ACSCFG", "DoorNum", filename, "0");
413
	//	listen = readconf.ReadLong("ACSCFG", "Listen", filename, "0");
414

    
415
}
416

    
417
//??Լ???պ???
418
sint32 DHacs::RxProc() {
419
	return 1;
420
}
421

    
422
sint32 DHacs::TxProc() {
423
	return 1;
424
}
425

    
426

    
427

    
428

    
429
sint32 DHacs::Get_rtuno() {
430
	return pLink->GetRtuNo();
431
}
432

    
433
sint32 DHacs::Get_CmdNum() {
434
	sint32 rtuno = pLink->GetRtuNo();
435
	return (pCmdMem->GetCmdNum(rtuno));
436
}
437

    
438
sint32 DHacs::Get_ACmd(sint32 rtuno, S_RAWCMD* cmd) {
439
	return pCmdMem->GetACmd(rtuno, cmd);
440
}
441

    
442
sint32 DHacs::Del_ACmd(sint32 rtuno) {
443
	return pCmdMem->DelACmd(rtuno);
444
}
445

    
446
void DHacs::PutSoe(S_RAWSOE tsoeex) {
447
	return PRawCtrl->PutASoe(tsoeex);
448
}
449

    
450
void DHacs::Register_Frm(){
451
	pLink->RegisterFrm(FRAME_RX_TIMEOUT);
452
}
453

    
454
sint32 DHacs::Rpt_AResult(sint32 rtuno, S_RAWCMD cmd) {
455
	return pCmdMem->RptAResult(rtuno, cmd);
456
}
457

    
458

    
459
void DHacs::SetCallBack() {
460
	CLIENT_SetDVRMessCallBack(afMassCallBack, (LDWORD)this);
461
}
462

    
463
BOOL DHacs::GetGroups() {
464
	char szBuf[1024] = { 0 };
465
	int nError = 0;
466
	BOOL bRet = CLIENT_QueryNewSystemInfo(ILoginHandle, CFG_CAP_CMD_ACCESSCONTROLMANAGER, -1,
467
		szBuf, sizeof(szBuf), &nError, 3000);
468
	if (bRet) {
469
		CFG_CAP_ACCESSCONTROL stuCap = { 0 };
470
		DWORD dwRet = 0;
471
		bRet = CLIENT_ParseData(CFG_CAP_CMD_ACCESSCONTROLMANAGER, szBuf, &stuCap,
472
			sizeof(stuCap), &dwRet);
473
		if (bRet && dwRet == sizeof(CFG_CAP_ACCESSCONTROL)) {
474
			nchannelnum = stuCap.nAccessControlGroups;
475
			return true;
476
		} else {
477
			return false;
478
		}
479
	}
480
}
481

    
482
int DHacs::LoginDev() {
483
	sint32 rtuno = Get_rtuno();
484
	NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY stuIn = { sizeof(stuIn) };
485
	strncpy(stuIn.szIP, ip, 63);
486
	stuIn.nPort = port;
487
	strncpy(stuIn.szUserName, username, 63);
488
	strncpy(stuIn.szPassword, password, 63);
489
	stuIn.emSpecCap = EM_LOGIN_SPEC_CAP_TCP;
490
	stuIn.pCapParam = NULL;
491
	NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY stuOut = { sizeof(stuOut) };
492
	ILoginHandle = CLIENT_LoginWithHighLevelSecurity(&stuIn, &stuOut);
493
	if (ILoginHandle != 0) {
494
		PrintLog(LOG_INFORMATION, "?豸??¼?ɹ???");
495
		PRawCtrl->PutAYx(rtuno, 0, 1);
496
		return 1;
497
	} else {
498
		switch (stuOut.nError) {
499
		case 1:
500
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[1]:???벻??ȷ????");
501
			break;
502
		case 2:
503
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[2]:?û????????ڣ???");
504
			break;
505
		case 3:
506
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[3]:??¼??ʱ????");
507
			break;
508
		case 4:
509
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[4]:?˺??ѵ?¼????");
510
			break;
511
		case 5:
512
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[5]:?˺??ѱ?????????");
513
			break;
514
		case 6:
515
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[6]:?˺ű???Ϊ??????????");
516
			break;
517
		case 7:
518
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[7]:??Դ???㣬?豸ϵͳæ????");
519
			break;
520
		case 8:
521
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[8]:??????ʧ?ܣ???");
522
			break;
523
		case 9:
524
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[9]:??????ʧ?ܣ???");
525
			break;
526
		case 10:
527
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[10]:????????û???????????");
528
			break;
529
		case 11:
530
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[11]:ȱ?? avnetsdk ?? avnetsdk ???????⣡??");
531
			break;
532
		case 12:
533
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[12]:?豸δ???? U ?̻? U ????Ϣ???󣡣?");
534
			break;
535
		case 13:
536
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[13]:?ͻ??? IP ??ַû?е?¼Ȩ?ޣ???");
537
			break;
538
		case 18:
539
			PrintLog(LOG_ERROR, "?豸??¼ʧ?ܣ???????[18]:?豸δ??ʼ?????޷???½????");
540
			break;
541
		default:
542
			break;
543
		}
544
		PRawCtrl->PutAYx(rtuno, 0, 0);
545
		ReadIni();
546
		SeSleep(1000);
547
		return 0;
548
	}
549
}
550

    
551
int DHacs::SelectDoor(int channel, LLONG iloginhandle) {
552
	sint32 rtuno = Get_rtuno();
553
	int nRet = 0;
554
	NET_DOOR_STATUS_INFO stuInfo = { sizeof(stuInfo) };
555
	stuInfo.nChannel = channel;
556
	BOOL bReturn = CLIENT_QueryDevState(iloginhandle, DH_DEVSTATE_DOOR_STATE, (char *)&stuInfo, sizeof(stuInfo), &nRet, 5000);
557
	if (bReturn) {
558

    
559
//		PRawCtrl->PutAYx(rtuno, 0, 1);
560
		PrintLog(LOG_INFORMATION, "??ѯ?豸??%d?Ŵ?״̬?ɹ???????", channel + 1);
561
		switch (stuInfo.emStateType) {
562
		case EM_NET_DOOR_STATUS_CLOSE:
563
			PrintLog(LOG_INFORMATION, "??ǰ??%d?Ŵ?״̬???ر?", channel + 1);
564
			PRawCtrl->PutAYx(rtuno, 30 * channel + 1, 1);
565
			PRawCtrl->PutAYx(rtuno, 30 * channel + 2, 0);
566
			PRawCtrl->PutAYx(rtuno, 30 * channel + 3, 0);
567
			PRawCtrl->PutAYx(rtuno, 30 * channel + 4, 0);
568
			break;
569
		case EM_NET_DOOR_STATUS_OPEN:
570
			PrintLog(LOG_INFORMATION, "??ǰ??%d?Ŵ?״̬????", channel + 1);
571
			PRawCtrl->PutAYx(rtuno, 30 * channel + 1, 0);
572
			PRawCtrl->PutAYx(rtuno, 30 * channel + 2, 1);
573
			PRawCtrl->PutAYx(rtuno, 30 * channel + 3, 0);
574
			PRawCtrl->PutAYx(rtuno, 30 * channel + 4, 0);
575
			break;
576
		case EM_NET_DOOR_STATUS_UNKNOWN:
577
			PrintLog(LOG_INFORMATION, "??ǰ??%d?Ŵ?״̬??δ֪", channel + 1);
578
			PRawCtrl->PutAYx(rtuno, 30 * channel + 1, 0);
579
			PRawCtrl->PutAYx(rtuno, 30 * channel + 2, 0);
580
			PRawCtrl->PutAYx(rtuno, 30 * channel + 3, 1);
581
			PRawCtrl->PutAYx(rtuno, 30 * channel + 4, 0);
582
			break;
583
		case EM_NET_DOOR_STATUS_BREAK:
584
			PrintLog(LOG_INFORMATION, "??ǰ??%d?Ŵ?״̬???쳣??", channel + 1);
585
			PRawCtrl->PutAYx(rtuno, 30 * channel + 1, 0);
586
			PRawCtrl->PutAYx(rtuno, 30 * channel + 2, 0);
587
			PRawCtrl->PutAYx(rtuno, 30 * channel + 3, 0);
588
			PRawCtrl->PutAYx(rtuno, 30 * channel + 4, 1);
589
			break;
590
		default:
591
			break;
592
		}
593
		return 1;
594
	} else {
595
		PRawCtrl->PutAYx(rtuno, 30 * channel + 1, 0);
596
		PRawCtrl->PutAYx(rtuno, 30 * channel + 2, 0);
597
		PRawCtrl->PutAYx(rtuno, 30 * channel + 3, 0);
598
		PRawCtrl->PutAYx(rtuno, 30 * channel + 4, 0);
599
		PrintLog(LOG_ERROR, "??ѯ?豸??%d?Ŵ?״̬ʧ?ܣ???????:%d", channel + 1, CLIENT_GetLastError()&(0x7fffffff));
600
		return 0;
601
	}
602

    
603
}
604

    
605

    
606
//??ѯ??ģʽ    ??ͨ??1???????أ?2??????????3????ʧ?ܣ?0??
607
int DHacs::SelectDoorState(int channel, LLONG iloginhandle) {
608
	char * szOut1 = new char[1024 * 32];
609
	CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
610
	int nError = 0;
611
	BOOL bRet = CLIENT_GetNewDevConfig(iloginhandle, CFG_CMD_ACCESS_EVENT, channel, szOut1, 1024 * 32, &nError, 3000);
612
	if (bRet) {
613
		BOOL bRet1 = CLIENT_ParseData(CFG_CMD_ACCESS_EVENT, szOut1, &stOut2, sizeof(CFG_ACCESS_EVENT_INFO), NULL);
614
		if (bRet1) {
615
			if (stOut2.emState == ACCESS_STATE_NORMAL) {
616
				PrintLog(LOG_INFORMATION, "??ǰ??%d??ģʽΪ????ͨ", channel + 1);
617
				return 1;
618
			}
619
			if (stOut2.emState == ACCESS_STATE_CLOSEALWAYS) {
620
				PrintLog(LOG_INFORMATION, "??ǰ??%d??ģʽΪ??????", channel + 1);
621
				return 2;
622
			}
623
			if (stOut2.emState == ACCESS_STATE_OPENALWAYS) {
624
				PrintLog(LOG_INFORMATION, "??ǰ??%d??ģʽΪ??????", channel + 1);
625
				return 3;
626
			}
627
		}
628
	} else {
629
		switch (nError) {
630
		case 1:
631
			PrintLog(LOG_ERROR, "??ѯ?豸??%d??ģʽʧ?ܣ???????[1]:ʧ??", channel + 1);
632
		case 2:
633
			PrintLog(LOG_ERROR, "??ѯ?豸??%d??ģʽʧ?ܣ???????[2]:???ݲ??Ϸ?", channel + 1);
634
		case 3:
635
			PrintLog(LOG_ERROR, "??ѯ?豸??%d??ģʽʧ?ܣ???????[3]:??ʱ?޷?????", channel + 1);
636
		case 4:
637
			PrintLog(LOG_ERROR, "??ѯ?豸??%d??ģʽʧ?ܣ???????[4]:û??Ȩ??", channel + 1);
638
		default:
639
			break;
640
		}
641
		return 0;
642
	}
643
}
644

    
645
//?̿?
646
int DHacs::OpenDoor(int channel, LLONG iloginhandle) {
647

    
648
	NET_CTRL_ACCESS_OPEN stOpen = { sizeof(stOpen) };
649
	stOpen.nChannelID = channel;
650
	bool bRet;
651
	bRet = CLIENT_ControlDeviceEx(iloginhandle, DH_CTRL_ACCESS_OPEN, &stOpen, NULL, 3000);
652
	if (bRet) {
653
		PrintLog(LOG_INFORMATION, "??%d?̿????Ƴɹ???????", channel + 1);
654
		return 1;
655
	} else {
656
		PrintLog(LOG_INFORMATION, "??%d?̿?????ʧ?ܣ?????", channel + 1);
657
		return 0;
658
	}
659

    
660
}
661

    
662

    
663
//?̹?
664
int DHacs::CloseDoor(int channel, LLONG iloginhandle) {
665
	NET_CTRL_ACCESS_CLOSE stClose = { sizeof(stClose) };
666
	stClose.nChannelID = channel;
667
	bool bRet;
668
	bRet = CLIENT_ControlDeviceEx(iloginhandle, DH_CTRL_ACCESS_CLOSE, &stClose, NULL, 3000);
669
	if (bRet) {
670
		PrintLog(LOG_INFORMATION, "??%d?̹ؿ??Ƴɹ???????", channel + 1);
671
		return 1;
672
	} else {
673
		PrintLog(LOG_INFORMATION, "??%d?̹ؿ???ʧ?ܣ?????", channel + 1);
674
		return 0;
675
	}
676
}
677

    
678
//????
679
int DHacs::SetDoorNorOpen(int channel, LLONG iloginhandle) {
680
	char * szOut1 = new char[1024 * 32];
681
	int nError = 0;
682
	CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
683
	stOut2.emState = ACCESS_STATE_OPENALWAYS;
684
	BOOL bRet2 = CLIENT_PacketData(CFG_CMD_ACCESS_EVENT, (char *)&stOut2, sizeof(CFG_ACCESS_EVENT_INFO), szOut1, 1024 * 32);
685
	if (bRet2) {
686
		BOOL bRet3 = CLIENT_SetNewDevConfig(iloginhandle, CFG_CMD_ACCESS_EVENT, channel, szOut1, 1024 * 32, &nError, NULL, 3000);
687
		if (bRet3) {
688
			PrintLog(LOG_INFORMATION, "??????%d?????ɹ???", channel + 1);
689
			return 1;
690
		} else {
691
			switch (nError) {
692
			case 1:
693
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[1]:ʧ??", channel + 1);
694
			case 2:
695
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[2]:???ݲ??Ϸ?", channel + 1);
696
			case 3:
697
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[3]:??ʱ?޷?????", channel + 1);
698
			case 4:
699
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[4]:û??Ȩ??", channel + 1);
700
			default:
701
				break;
702
			}
703
			return 0;
704
		}
705
	}
706
}
707

    
708
//????
709
int DHacs::SetDoorNorClose(int channel, LLONG iloginhandle) {
710
	char * szOut1 = new char[1024 * 32];
711
	int nError = 0;
712
	CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
713
	stOut2.emState = ACCESS_STATE_CLOSEALWAYS;
714
	BOOL bRet2 = CLIENT_PacketData(CFG_CMD_ACCESS_EVENT, (char *)&stOut2, sizeof(CFG_ACCESS_EVENT_INFO), szOut1, 1024 * 32);
715
	if (bRet2) {
716
		BOOL bRet3 = CLIENT_SetNewDevConfig(iloginhandle, CFG_CMD_ACCESS_EVENT, channel, szOut1, 1024 * 32, &nError, NULL, 3000);
717
		if (bRet3) {
718
			PrintLog(LOG_INFORMATION, "??????%d???سɹ???", channel + 1);
719
			return 1;
720
		} else {
721
			switch (nError) {
722
			case 1:
723
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[1]:ʧ??", channel + 1);
724
			case 2:
725
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[2]:???ݲ??Ϸ?", channel + 1);
726
			case 3:
727
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[3]:??ʱ?޷?????", channel + 1);
728
			case 4:
729
				PrintLog(LOG_ERROR, "??????%d????ʧ?ܣ???????[4]:û??Ȩ??", channel + 1);
730
			default:
731
				break;
732
			}
733
			return 0;
734
		}
735
	}
736
}
737

    
738
//??ͨ(?ָ?????)
739
int DHacs::SetDoorNorNormal(int channel, LLONG iloginhandle) {
740
	char * szOut1 = new char[1024 * 32];
741
	int nError = 0;
742
	CFG_ACCESS_EVENT_INFO stOut2 = { sizeof(stOut2) };
743
	stOut2.emState = ACCESS_STATE_NORMAL;
744
	BOOL bRet2 = CLIENT_PacketData(CFG_CMD_ACCESS_EVENT, (char *)&stOut2, sizeof(CFG_ACCESS_EVENT_INFO), szOut1, 1024 * 32);
745
	if (bRet2) {
746
		BOOL bRet3 = CLIENT_SetNewDevConfig(iloginhandle, CFG_CMD_ACCESS_EVENT, channel, szOut1, 1024 * 32, &nError, NULL, 3000);
747
		if (bRet3) {
748
			PrintLog(LOG_INFORMATION, "??????%dģʽ??ͨ?ɹ???", channel + 1);
749
			return 1;
750
		} else {
751
			switch (nError) {
752
			case 1:
753
				PrintLog(LOG_ERROR, "??????%dģʽ??ͨʧ?ܣ???????[1]:ʧ??", channel + 1);
754
			case 2:
755
				PrintLog(LOG_ERROR, "??????%dģʽ??ͨʧ?ܣ???????[2]:???ݲ??Ϸ?", channel + 1);
756
			case 3:
757
				PrintLog(LOG_ERROR, "??????%dģʽ??ͨʧ?ܣ???????[3]:??ʱ?޷?????", channel + 1);
758
			case 4:
759
				PrintLog(LOG_ERROR, "??????%dģʽ??ͨʧ?ܣ???????[4]:û??Ȩ??", channel + 1);
760
			default:
761
				break;
762
			}
763
			return 0;
764
		}
765
	}
766
}
767

    
768

    
769
//??Լ???󴴽?????
770
#ifdef __unix
771
extern "C" CProtocol * CreateProtocol(char* defpara)
772
#else
773
extern "C" __declspec(dllexport)  CProtocol * CreateProtocol(char* defpara)
774
#endif
775
{
776
	CProtocol* pEpv = new DHacs;
777
	return pEpv;
778
}
779

    
(1-1/3)