Project

General

Profile

Feature #2956 » cctvC3jt.cpp

yan hong, 04/19/2023 10:59 AM

 
1
// cctv_C301.cpp: implementation of the CcctvC3JT class.
2
//
3
//////////////////////////////////////////////////////////////////////
4

    
5
#include "cctvC3jt.h"
6

    
7
#ifdef _DEBUG
8
#undef THIS_FILE
9
static char THIS_FILE[]=__FILE__;
10
#define new DEBUG_NEW
11
#endif
12

    
13
//////////////////////////////////////////////////////////////////////
14
// Construction/Destruction
15
//////////////////////////////////////////////////////////////////////
16

    
17
//keycode:0-9
18
static int KeyCode[10]={75, 62, 63, 64, 66, 67, 68, 70, 71, 72}; 
19
//keycode:???? ???? ???? ???? ?Ŵ? ??С ???? Զ?? ??Ȧ?? ??Ȧ??
20
static int Operation[10]={96, 97, 98, 99, 86, 87, 88, 89, 90, 91};
21
CcctvC3JT::CcctvC3JT()
22
{
23

    
24
}
25

    
26
CcctvC3JT::~CcctvC3JT()
27
{
28

    
29
}
30

    
31
sint32 CcctvC3JT::TxProc()
32
{
33
	
34
	E_RAW_ComStat coms = pLink->GetCommStatus();
35
	if (coms == CMST_RX_CNT)
36
		return 0;
37
	if (ProcCmd())//?????ⲿ?·?????
38
		return 1;
39
	if(0<TxFlag){
40
		if (!m_bLogin){
41
			Login(name,pwd,ip,port);
42
//			pCmdMem->DelACmd(rtuno);
43
			return FALSE;}//δ??¼??????????
44
		TxBufwrite();
45
	}
46
	if ((GetNowSecond() - m_LastSendTime) > m_reloginTime){
47
		Login(name,pwd,ip,port);
48
	}
49
	if(!m_bLogin){
50
		if ((GetNowSecond() - m_LastSendTime) > m_RcvTimeOuts)
51
		Login(name,pwd,ip,port);
52
	}
53
	return 1;
54
}
55
void CcctvC3JT::TrimBlank(char *buf,int len)
56
{
57
	int i=0,j=0;
58
	for(i=0;i<len;i++){
59
		if(buf[i]!=' ' && buf[i]!='	') 
60
			buf[j++]=buf[i];
61
	}
62
	buf[j]='\0'; 
63
}
64
/*????cctv??б??4????????DEVC26??TOUR29??MAC30??PATTERN31??*/
65
sint32 CcctvC3JT::RxProc()
66
{
67
	sint32 rtuno			=	pLink->GetRtuNo();
68
	unsigned char rtuaddr	=	pRtu->GetRtuAddr(rtuno);
69

    
70
	uint8  buf[512];
71
	int datalen = 0 ,datanum =0;
72
	int buflen=pRxBuf->GetReadableSize();
73
	char tmp[512]="";
74
	int keylen=5;
75
	char *ctmp=NULL,cVal[16]="";
76
	if(buflen>512)buflen=512;
77
	int nowtime = GetNowSecond();
78
	E_RAW_ComStat coms = pLink->GetCommStatus();
79
	if ( coms == CMST_RX_CNT && (nowtime-m_LastSendTime) >= m_RcvTimeOuts)
80
	{
81
		//??ʱ???ط???ֱ????????һ???ն?
82
		pRxBuf->Move(buflen);
83
		pLink->RegisterFrm(FRAME_RX_TIMEOUT);
84
		pLink->SetCommStatus(CMST_TX_CNT);
85
		PrintLog(LOG_VIOLATION,
86
					"???ݳ?ʱ\n");
87
//		PRawCtrl->PutAYx(rtuno, 0, 0);
88
		return 1;
89
	}
90
	//??½???ؽ??2/100
91
	if (buflen<60)		//?????ݻ????ݲ??????ı???·ͨѶ״̬???????ȴ?
92
		return 1;
93
	datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE);
94
	keylen=5;
95
	ctmp=NULL;
96
	if(NULL==(ctmp=GetAkeyStart((CHAR*)buf,"/body",keylen)))
97
	{
98
		return 1;
99
	}
100
	while(datalen>=100 && !(buf[0]=='<' && buf[1]=='?' && buf[2]=='x' && buf[3]=='m' && buf[4]=='l')){
101
		pRxBuf->Move(1);
102
		datalen = pRxBuf->Read(buf,buflen,DEF_BUFF_NOMOVE);
103
	}
104

    
105
	memcpy(tmp,buf,buflen);
106
	TrimBlank(tmp,buflen);
107

    
108
	int tLog=0;
109
	keylen=5;
110
	ctmp=NULL;memset(cVal,0,16);
111
	if(NULL!=(ctmp=GetAkeyVal(tmp,"login",keylen)))
112
	{
113
		if(keylen>15) keylen=15;
114
		memcpy(cVal,ctmp,keylen);
115
		tLog=atoi(cVal);
116
		PrintLog(LOG_INFORMATION,"login=%s	", cVal);
117
	}
118
	keylen=5;
119
	ctmp=NULL;memset(cVal,0,16);
120
	if(NULL!=(ctmp=GetAkeyVal(tmp,"state",keylen)))
121
	{
122
		if(keylen>15) keylen=15;
123
		memcpy(cVal,ctmp,keylen);
124
		m_state=atoi(cVal);
125
		if(1==m_state && 1==tLog){
126
			PRawCtrl->PutAYx(rtuno,0,m_state&1);
127
			m_bLogin=TRUE;
128
		}
129
		else if(0==tLog)
130
		{m_bLogin=FALSE;PRawCtrl->PutAYx(rtuno,0,0);}
131
		PrintLog(LOG_INFORMATION,"state=%s	", cVal);
132
	}
133
	m_state=0;
134

    
135
	keylen=8;
136
	ctmp=NULL;memset(cVal,0,16);
137
	if(NULL!=(ctmp=GetAkeyVal(tmp,"infotype",keylen)))
138
	{
139
		if(keylen>15) keylen=15;
140
		memcpy(cVal,ctmp,keylen);
141
		m_infotype=atoi(cVal);
142
		PrintLog(LOG_INFORMATION,"infotype=%s	", cVal);
143
	}
144
	/*infotype=1??????2ƽ̨?ظ?*/
145
	/*keyvalue=0-9???֣?10????ֹͣ??11-18????????-????-????-????-???£?????0-8????20-21?䱶??С??22-23??Զ??24-25??Ȧ??С??
146
	26DEVC,27CAM,28MON,29TOUR,30MAC,31PATTERN,32AUTOPAN,33GOTO,34ENTER,35MULT,36WIN,37CAN-G,38MON-G,39GROUP,40SET,41PT,42LOCK,43SHIFT,44ESC
147
	45??ҳ??46??һҳ??47??һҳ??48??Ѳ??ʼ??49??Ѳֹͣ??50??Ѳ??ͣ*/
148
	/*platinfotype=1ѡ????Ϣ?ظ???2??Ѳ?ظ???3??̨??4??????5???ԣ?6״̬??Ϣ??Mon??Winͨ????Cam??	*/
149
	keylen=12;
150
	ctmp=NULL;memset(cVal,0,16);
151
	if(NULL!=(ctmp=GetAkeyVal(tmp,"platinfotype",keylen)))
152
	{
153
		if(keylen>15) keylen=15;
154
		memcpy(cVal,ctmp,keylen);
155
		m_platinfotype=atoi(cVal);
156
		PrintLog(LOG_INFORMATION,"platinfotype=%s	", cVal);
157
	}
158
	keylen=7;
159
	ctmp=NULL;memset(cVal,0,16);
160
	if(NULL!=(ctmp=GetAkeyVal(tmp,"message",keylen)))
161
	{	memset(m_msg,0,100);
162
		if(keylen>99) keylen=99;
163
		memcpy(m_msg,ctmp,keylen);
164
		PrintLog(LOG_INFORMATION,"message=%s	", m_msg);
165
	}
166
	keylen=3;
167
	ctmp=NULL;memset(cVal,0,16);
168
	if(NULL!=(ctmp=GetAkeyVal(tmp,"Mon",keylen)))
169
	{
170
		if(keylen>15) keylen=15;
171
		memcpy(cVal,ctmp,keylen);
172
		m_mon=atoi(cVal);
173
		PrintLog(LOG_INFORMATION,"Mon=%s	", cVal);
174
	}
175
	keylen=3;
176
	ctmp=NULL;memset(cVal,0,16);
177
	if(NULL!=(ctmp=GetAkeyVal(tmp,"Win",keylen)))
178
	{
179
		if(keylen>15) keylen=15;
180
		memcpy(cVal,ctmp,keylen);
181
		m_win=atoi(cVal);
182
		PrintLog(LOG_INFORMATION,"Win=%s	", cVal);
183
	}
184
	keylen=3;
185
	ctmp=NULL;memset(cVal,0,16);
186
	if(NULL!=(ctmp=GetAkeyVal(tmp,"Cam",keylen)))
187
	{
188
		if(keylen>15) keylen=15;
189
		memcpy(cVal,ctmp,keylen);
190
		m_cam=atoi(cVal);
191
		PrintLog(LOG_INFORMATION,"Cam=%s	", cVal);
192
	}
193

    
194
	keylen=5;
195
	ctmp=NULL;
196
	if(NULL!=(ctmp=GetAkeyStart((CHAR*)buf,"/body",keylen)))
197
	{
198
		pRxBuf->Move(ctmp-(CHAR*)buf+7+4);///r/d/r/d
199
		pLink->SetCommStatus(CMST_NORMAL);
200
		pLink->RegisterFrm(FRAME_RX_SUC);	
201
	}
202

    
203
	return 1;
204
}
205

    
206
void CcctvC3JT::Init(S_PROTOCOLCFG *pcfg)
207
{
208
	memset(mHead,0,40);
209
	strcat(mHead,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
210
	PRawCtrl	=	pcfg->PRawCtrl;
211
	pRxBuf		=	pcfg->pRxBuf;
212
	pTxBuf		=	pcfg->pTxBuf;
213
	pCmdMem		=	pcfg->pCmdMem;
214
	pRtu		=	pcfg->pRtu;
215
	pLink		=	pcfg->pLink;
216
	pTable		=	pcfg->pTable;
217
	pZfDataCtrl	=	pcfg->pZfDataCtrl;
218
//	pHis		=	pcfg->pHis;
219

    
220
	m_infotype=0;
221
	m_keyval=0;
222
	m_state=0;
223
	m_step=0;
224
	m_platinfotype=0;
225
	memset(m_msg,0,100);
226
	m_mon=0;
227
	m_win=0;
228
	m_cam=0;
229
	m_mult=0;
230
//	pRxBuf->Move(pRxBuf->GetReadableSize());
231
//	pTxBuf->Move(pTxBuf->GetReadableSize());
232
	m_reloginTime = pLink->GetAllDataScanInterval();
233
	m_RcvTimeOuts = pLink->GetRxTimeouts();
234
	m_ID = 1;
235
	m_bLogin = FALSE;
236
	m_bCmd = FALSE;
237
	m_LastSendTime=0;
238
	if(m_reloginTime <= 0)
239
		m_reloginTime = 60;
240
	if(m_RcvTimeOuts <= 0)
241
		m_RcvTimeOuts = 10;
242
//read cfg/cctv.ini
243
//char name[]="admin",pwd[]="admin",ip[]="192.168.1.108",port[]="9000";
244
	char filename[512];
245
	CReadConf readconf;
246
	char *pWorkPath;	
247
	pWorkPath=getenv("FEPROOT");
248
	if(pWorkPath!=NULL) 
249
		sprintf(filename,"%s%s",pWorkPath,"/cfg/cctv.ini");
250
	readconf.ReadString("LoginInfo","PlatIP",ip,filename,"127.0.0.1");
251
	readconf.ReadString("LoginInfo","PlatPort",port,filename,"502");
252
	readconf.ReadString("LoginInfo","UserName",name,filename,"admin");
253
	readconf.ReadString("LoginInfo","Password",pwd,filename,"admin");
254
	TxFlag=-1;
255
	TxIndex=0;
256
}
257

    
258
char* CcctvC3JT::GetAkeyStart(char * buf,char *key,int &len)
259
{
260
	int rlen=0;
261
	char key1[16]="<";
262
	memcpy(key1+1,key,len);key1[1+len]='>';key1[2+len]=0;
263
	
264
	char *str1=strstr(buf,key1);
265
	if(NULL != str1){
266
		return str1;
267
	}
268
	return NULL;
269
}
270

    
271
char* CcctvC3JT::GetAkeyVal(char * buf,char *key,int &len)
272
{	
273
	int rlen=0;
274
	char key1[16]="<";
275
	memcpy(key1+1,key,len);key1[1+len]='>';key1[2+len]=0;
276

    
277
	char key2[16]="</";
278
	memcpy(key2+2,key,len);key2[2+len]='>';key2[3+len]=0;
279
	char *str1=strstr(buf,key1);
280
	char *str2=strstr(buf,key2);
281
	if(NULL != str1 && NULL != str2){
282
		rlen=str2-str1-len-2;
283
		str1+=len+2;
284
		if(rlen>0)len=rlen;
285
		return str1;
286
	}
287
	return NULL;
288
}
289

    
290
	/*infotype=1??????2ƽ̨?ظ?*/
291
	/*keyvalue=0-9???֣?10????ֹͣ??11-18????????-????-????-????-???£?step????0-8????20-21?䱶??С??22-23??Զ??24-25??Ȧ??С??
292
	26DEVC,27CAM,28MON,29TOUR,30MAC,31PATTERN,32AUTOPAN,33GOTO,34ENTER,35MULT,36WIN,37CAN-G,38MON-G,39GROUP,40SET,41PT,42LOCK,43SHIFT,44ESC
293
	45??ҳ??46??һҳ??47??һҳ??48??Ѳ??ʼ??49??Ѳֹͣ??50??Ѳ??ͣ*/
294
	/*platinfotype=1ѡ????Ϣ?ظ???2??Ѳ?ظ???3??̨??4??????5???ԣ?6״̬??Ϣ??Mon??Winͨ????Cam??	*/
295
BOOL CcctvC3JT::ProcCmd()
296
{
297
	if(0<TxFlag)	return FALSE;
298
	int i=0;
299
	char n[2]="";
300
	sint32 rtuno			=	pLink->GetRtuNo();
301
	unsigned char rtuaddr	=	pRtu->GetRtuAddr(rtuno);
302
	
303
	S_RAWCMD rawcmd;
304

    
305
	while (pCmdMem->GetCmdNum(rtuno) > 0)
306
	{
307
		if (pCmdMem->GetACmd(rtuno, &rawcmd) == 0)
308
			break;
309
		if (rawcmd.type == DC_K_CMD_CCTVCTRL)
310
		{
311
			m_bCmd = TRUE;
312
			CSI_D_CCTV_CMD *CctvCmd;
313
			CctvCmd	=	(CSI_D_CCTV_CMD *)rawcmd.data;
314
			m_cmdAddr = rawcmd.src;
315
			
316
			int len = 0;
317

    
318
			uint8 nSpeed = CctvCmd->Val/0x100;
319
			uint8 nOper = CctvCmd->Val %0x100; 
320
			int nPtz=PTZConv(nOper);
321
if(nPtz>=11 && nPtz<=18)	nSpeed*=11;//???첽??*6/64????
322
if(nPtz>=22 && nPtz<=23)nPtz-=2;//?ñ䱶??20?滻????+22;?ñ䱶С21?滻????-23;//wyf 20190214
323
			char scangroup[16]="0";
324
			char sta[16]="",cam[16]="",mon[16]="",win[16]="",ptz[16]="",speed[16]="",cmdval[16]="";
325
			sprintf(cam,"%d",CctvCmd->Cam);/*sprintf(mon,"%d",CctvCmd->Mon);*/sprintf(mon,"%d",CctvCmd->decode);//Yansx 2019-02-28
326
			sprintf(cmdval,"%d",nOper);sprintf(sta,"%d",CctvCmd->Sta);sprintf(win,"%d",CctvCmd->Win);sprintf(ptz,"%d",nPtz);sprintf(speed,"%d",nSpeed);
327
			switch (CctvCmd->Func)
328
			{
329
			case 1://CCTV_FUNC_MON:	//????ͷѡ??=????+DEVC??26+????+MON28+????+CAM??27
330
				TxFlag=CctvCmd->Func;
331
				memset(&m_tBuf,0,sizeof(m_tBuf));
332
				PrintLog(LOG_INFORMATION,"??ʼ?л?Ŀ???????%d:,????????%d,?????????%d", CctvCmd->Mon,CctvCmd->Cam,CctvCmd->decode);	
333
/*				for(i=0;i<strlen(sta);i++){//??վ??//??????ְ???
334
					n[0]=sta[i];
335
					PressKey(n,"1","0");//????
336
					PressKey(n,"0","0");//????????
337
				}
338
				PressKey("26","1","0");
339
				PressKey("26","0","0");//DEVC26??վ??//????cctv?޴˹???
340
*/				for(i=0;i<strlen(mon);i++){
341
					n[0]=mon[i];
342
					PressKey(n,"1","0");m_tBuf.FrameNum++;//????
343
					PressKey(n,"0","0");m_tBuf.FrameNum++;//????????
344
				}
345
				PressKey("28","1","0");m_tBuf.FrameNum++;//MON??28DEV
346
				PressKey("28","0","0");m_tBuf.FrameNum++;//MON??28DEV
347
//				if(strlen(cam)<4){//L06???첹????4λ??????0105
348
				if(strlen(cam)<5){//L07???첹????4λ??????01005
349
					PressKey("0","1","0");m_tBuf.FrameNum++;//????
350
					PressKey("0","0","0");m_tBuf.FrameNum++;//????????
351
				}
352
				for(i=0;i<strlen(cam);i++){
353
					n[0]=cam[i];
354
					PressKey(n,"1","0");m_tBuf.FrameNum++;//????
355
					PressKey(n,"0","0");m_tBuf.FrameNum++;//????????
356
				}
357
				PressKey("27","1","0");m_tBuf.FrameNum++;//CAM??27DEV
358
				PressKey("27","0","0");m_tBuf.FrameNum++;//CAM??27DEV
359
//WYF 20190127 Add Mult 35 func
360
			if(m_mult!=CctvCmd->Mult){
361
				PrintLog(LOG_INFORMATION, "?л?Ϊ[%d X %d]????",CctvCmd->Mult+1,CctvCmd->Mult+1);
362
				PressKey("35","1","0");		m_tBuf.FrameNum++;
363
				PressKey("35","0","0");		m_tBuf.FrameNum++;
364
				m_mult=CctvCmd->Mult;
365
			}
366
//WYF 20190127 Add Mult 35 func
367
				TxIndex=0;
368
				TxBufwrite();
369
				break;
370
			case 4://CCTV_FUNC_VIEW:	
371
				TxFlag=CctvCmd->Func;
372
				memset(&m_tBuf,0,sizeof(m_tBuf));
373
				PrintLog(LOG_INFORMATION,"??ʼ????Ԥ??λ");		
374
				for(i=0;i<strlen(cmdval);i++){
375
					n[0]=cmdval[i];
376
					PressKey(n,"1","0");m_tBuf.FrameNum++;//??????????ְ???
377
					PressKey(n,"0","0");m_tBuf.FrameNum++;//????
378
				}
379
				PressKey("33","1","0");m_tBuf.FrameNum++;//GOTO???????33
380
				PressKey("33","0","0");m_tBuf.FrameNum++;//
381
//				PressKey("34","1","0");//ENTER?󻪲???34
382
//				PressKey("34","0","0");//
383
				TxIndex=0;
384
				TxBufwrite();
385
				break;
386
			case 14://CCTV_FUNC_VIEWSET://????579+??24?޴˹???
387
				TxFlag=CctvCmd->Func;
388
				memset(&m_tBuf,0,sizeof(m_tBuf));
389
				PrintLog(LOG_INFORMATION,"??ʼ????Ԥ??λ");
390
				for(i=0;i<strlen(cmdval);i++){
391
					n[0]=cmdval[i];
392
					PressKey(n,"1","0");m_tBuf.FrameNum++;//??????????ְ???
393
					PressKey(n,"0","0");m_tBuf.FrameNum++;//????
394
				}
395
				PressKey("40","1","0");	m_tBuf.FrameNum++;//SET
396
				PressKey("40","0","0");	m_tBuf.FrameNum++;//
397
				TxIndex=0;
398
				TxBufwrite();
399
				break;
400
			case 2://CCTV_FUNC_PTZ://??ÿһ???????ʱ???ȷ??ͷ???ֹͣ???ģ?֮?????????ͷ???ʼ???ģ?ֱ????????ɿ????ٴη??ͷ???ֹͣ????
401
				TxFlag=CctvCmd->Func;
402
				memset(&m_tBuf,0,sizeof(m_tBuf));
403
				PrintLog(LOG_INFORMATION,"??ʼPTZ????,????????%d,?ٶ?%d[??????%d:,????????%d,?????????%d]", nOper, nSpeed, CctvCmd->Mon,CctvCmd->Cam,CctvCmd->decode);			
404
//				PressKey("10","1","0");m_tBuf.FrameNum++;//ֹͣ????
405
//				PressKey("10","0","0");m_tBuf.FrameNum++;//ֹͣ????
406
				if(nPtz>=11 && nPtz<=18){
407
//					PressKey(ptz,"0","0");	m_tBuf.FrameNum++;//?ȷ?ֹͣ
408
					PressKey(ptz,"1",speed);m_tBuf.FrameNum++;
409
					PressKey(ptz,"0","0");m_tBuf.FrameNum++;//????????
410
//					PressKey("0","0","0");	m_tBuf.FrameNum++;//???մ󻪼???ʵ?ʱ???.txt??????Ƿ?Ҫ
411
//				PressKey("10","1","0");m_tBuf.FrameNum++;//ֹͣ????
412
//				PressKey("10","0","0");m_tBuf.FrameNum++;//ֹͣ????
413
				}
414
				if(nPtz>=20 && nPtz<=25){//?䱶??-С???۽???-Զ????Ȧ??-С					
415
					PressKey(ptz,"1","0");	m_tBuf.FrameNum++;
416
					PressKey(ptz,"0","0");	m_tBuf.FrameNum++;
417
				}
418
				TxIndex=0;
419
				TxBufwrite();
420
				break;
421
			case 3://CCTV_FUNC_SCAN:??Ѳ//50??ͣ??֧??
422
				TxFlag=CctvCmd->Func;
423
				memset(&m_tBuf,0,sizeof(m_tBuf));
424
				PrintLog(LOG_INFORMATION, "??Ѳֵ%d", CctvCmd->Val);
425
				if(0==nOper){
426
					PressKey("49",cmdval,"0");m_tBuf.FrameNum++;
427
				}
428
				else {
429
					for(i=0;i<strlen(cmdval);i++){
430
						n[0]=cmdval[i];
431
						PressKey(n,"1","0");	m_tBuf.FrameNum++;
432
						PressKey(n,"0","0");	m_tBuf.FrameNum++;
433
					}
434
					PressKey("48",cmdval,"0");	m_tBuf.FrameNum++;
435
				}
436
				TxIndex=0;
437
				TxBufwrite();
438
				break;
439
			case 11://CCTV_FUNC_URGEN://??Ϊ??Ѳ50??ͣ
440
				TxFlag=CctvCmd->Func;
441
				memset(&m_tBuf,0,sizeof(m_tBuf));
442
				PrintLog(LOG_INFORMATION, "??Ѳ??ͣ");
443
				PressKey("50",cmdval,"0");	m_tBuf.FrameNum++;//1-??ͣ??0-??ͣȡ??
444
				PressKey("10","1","0");		m_tBuf.FrameNum++;//ֹͣ????
445
				PressKey("10","0","0");		m_tBuf.FrameNum++;//ֹͣ????
446
				TxIndex=0;
447
				TxBufwrite();
448
				break;
449
			default:
450
				memset(&m_tBuf,0,sizeof(m_tBuf));
451
				TxFlag=-1;
452
				break;
453
			}
454

    
455
			pCmdMem->DelACmd(rtuno);
456
			return TRUE;
457
		}
458
		else//?????????·????????
459
			pCmdMem->DelACmd(rtuno);
460
		break;
461
	}	
462
	return FALSE;
463
}
464

    
465

    
466
int CcctvC3JT::GetNowSecond()
467
{
468
	CSeTime     SE_T;
469
	TCriterionTime tmptime;
470
	SE_T.GetNow(&tmptime);
471
	return (int)tmptime;
472
}
473

    
474
void CcctvC3JT::SetExtendedPara(uint16 no, sint32 val)
475
{
476
	if ( no == 1 )	
477
	{
478
		if (val == 1)
479
			m_ID = val + 59;
480
		else
481
			m_ID = 1;		
482
	}	
483
	else 
484
		m_ID = 1;		
485
}
486

    
487
//1:Challenge_request;2:Challenge_response;3:Auth_login_success;4;Auth_login_fail;5:Auth_login;6:Auth_logout
488
void CcctvC3JT::Login(char *name,char *pwd,char *ip,char *port)
489
{
490
	m_bLogin=FALSE;
491
	char	buf[256];
492
	int		p = 0;
493

    
494
	memcpy(buf+p,mHead,HEADLEN);p+=HEADLEN;
495
	buf[p++]='\r';buf[p++]='\n';
496
	strcpy(buf+p,"<body>");		p+=6;
497
	buf[p++]='\r';buf[p++]='\n';
498
	//body//////////////////////////////////////////////////////
499

    
500
	strcpy(buf+p,"<login>");		p+=7;
501
	buf[p]='1';						p+=1;//????
502
	strcpy(buf+p,"</login>");		p+=8;
503
	buf[p++]='\r';buf[p++]='\n';
504

    
505
	strcpy(buf+p,"<username>");		p+=10;
506
	strncpy(buf+p,name,strlen(name));	p+=strlen(name);//name
507
	strcpy(buf+p,"</username>");	p+=11;
508
	buf[p++]='\r';buf[p++]='\n';
509

    
510
	strcpy(buf+p,"<password>");		p+=10;
511
	strncpy(buf+p,pwd,strlen(pwd));		p+=strlen(pwd);//pwd
512
	strcpy(buf+p,"</password>");	p+=11;
513
	buf[p++]='\r';buf[p++]='\n';
514

    
515
	strcpy(buf+p,"<ip>");			p+=4;
516
	strncpy(buf+p,ip,strlen(ip));		p+=strlen(ip);//ip192.168.1.1
517
	strcpy(buf+p,"</ip>");			p+=5;
518
	buf[p++]='\r';buf[p++]='\n';
519

    
520
	strcpy(buf+p,"<port>");			p+=6;
521
	strncpy(buf+p,port,strlen(port));	p+=strlen(port);//port9000
522
	strcpy(buf+p,"</port>");		p+=7;
523
	buf[p++]='\r';buf[p++]='\n';
524

    
525
	//body//////////////////////////////////////////////////////
526
	strcpy(buf+p,"</body>");	p+=7;
527
	buf[p++]='\r';buf[p++]='\n';buf[p++]='\r';buf[p++]='\n';
528

    
529
	pTxBuf->Write((uint8 *)buf,p);
530
	pLink->SetCommStatus(CMST_RX_CNT);
531
	pLink->RegisterFrm(FRAME_TX_SUC);
532
	m_LastSendTime = GetNowSecond();
533
	PrintLog(LOG_INFORMATION,"???͵?¼????%d",p);
534

    
535
	return;
536
}
537

    
538
void CcctvC3JT::PressKey(char *keyval,char *state,char *step)
539
{
540

    
541
	char	buf[256];
542
	int		p = 0;
543
	
544
	memcpy(buf+p,mHead,HEADLEN);p+=HEADLEN;
545
	buf[p++]='\r';buf[p++]='\n';
546
	strcpy(buf+p,"<body>");		p+=6;
547
	buf[p++]='\r';buf[p++]='\n';
548
	//body//////////////////////////////////////////////////////
549
	strcpy(buf+p,"<infotype>");		p+=10;
550
	buf[p]='1';						p+=1;//????infotype=1
551
	strcpy(buf+p,"</infotype>");	p+=11;
552
	buf[p++]='\r';buf[p++]='\n';
553
	
554
	strcpy(buf+p,"<keyvalue>");		p+=10;
555
	strncpy(buf+p,keyval,strlen(keyval));	p+=strlen(keyval);//1???£?0????
556
	strcpy(buf+p,"</keyvalue>");	p+=11;
557
	buf[p++]='\r';buf[p++]='\n';
558

    
559
	strcpy(buf+p,"<state>");	p+=7;
560
	strncpy(buf+p,state,strlen(state));	p+=strlen(state);//??Ҫ??????̨??????????Ĭ??ʹ?ñ䲽??
561
	strcpy(buf+p,"</state>");	p+=8;
562
	buf[p++]='\r';buf[p++]='\n';
563
	
564
	strcpy(buf+p,"<step>");		p+=6;
565
	strncpy(buf+p,step,strlen(step));	p+=strlen(step);//??Ҫ??????̨??????????Ĭ??ʹ?ñ䲽??
566
	strcpy(buf+p,"</step>");	p+=7;
567
	buf[p++]='\r';buf[p++]='\n';
568

    
569
	//body//////////////////////////////////////////////////////
570
	strcpy(buf+p,"</body>");	p+=7;
571
	buf[p++]='\r';buf[p++]='\n';buf[p++]='\r';buf[p++]='\n';
572
	m_tBuf.Len[m_tBuf.FrameNum]=p;
573
	memcpy(m_tBuf.Buf[m_tBuf.FrameNum],buf,p);
574
//	pTxBuf->Write((uint8 *)buf,p);
575
//	pLink->SetCommStatus(CMST_NORMAL);
576
//	pLink->RegisterFrm(FRAME_TX_SUC);
577
//	m_LastSendTime = GetNowSecond();
578
//	PrintLog(LOG_INFORMATION,"????key=%s????state=%s,step=%s,time=%d",keyval,state,step,m_LastSendTime);
579
	
580
	return;
581
}
582

    
583
void CcctvC3JT::TxBufwrite()
584
{
585
	int now=GetNowSecond();
586
	if(TxIndex<m_tBuf.FrameNum){
587
		if(TxIndex==m_tBuf.FrameNum-1 && 2==TxFlag){
588
			if(now-m_LastSendTime>1){
589
				pTxBuf->Write((uint8 *)m_tBuf.Buf[TxIndex],m_tBuf.Len[TxIndex]);
590
				TxIndex++;
591
	pLink->SetCommStatus(CMST_NORMAL);
592
	pLink->RegisterFrm(FRAME_TX_SUC);
593
	m_LastSendTime = GetNowSecond();
594
			}
595
		}
596
		else{
597
			pTxBuf->Write((uint8 *)m_tBuf.Buf[TxIndex],m_tBuf.Len[TxIndex]);
598
			TxIndex++;
599
	pLink->SetCommStatus(CMST_NORMAL);
600
	pLink->RegisterFrm(FRAME_TX_SUC);
601
	m_LastSendTime = GetNowSecond();
602
		}
603
	}
604
	else{
605
		TxIndex=0;
606
		memset(&m_tBuf,0,sizeof(m_tBuf));
607
		TxFlag=-1;
608
	}
609
//	PrintLog(LOG_INFORMATION,"CCTV????????ʱ?䣺%d",m_LastSendTime);
610
	
611
	return;
612
}
613

    
614
void CcctvC3JT::Aim(uint8 oper,uint8 wall,uint8 task,uint8 mon,uint8 mult,uint8 win,uint8 cam)//,uint8 ptz,uint8 ptzpara)
615
{
616
	char	buf[256];
617
	int		p = 0;
618
	
619
	memcpy(buf+p,mHead,HEADLEN);p+=HEADLEN;
620
	buf[p++]='\r';buf[p++]='\n';buf[p++]='\r';buf[p++]='\n';
621
	strcpy(buf+p,"<body>");		p+=6;
622
	buf[p++]='\r';buf[p++]='\n';buf[p++]='\r';buf[p++]='\n';
623
	
624
	strcpy(buf+p,"<infotype>");		p+=10;
625
	buf[p]='2';						p+=1;//????
626
	strcpy(buf+p,"</infotype>");	p+=11;
627
	buf[p++]='\r';buf[p++]='\n';buf[p++]='\r';buf[p++]='\n';
628
	
629
//////////	
630
	strcpy(buf+p,"</body>");	p+=7;
631
	buf[p++]='\r';buf[p++]='\n';buf[p++]='\r';buf[p++]='\n';
632
	
633
	pTxBuf->Write((uint8 *)buf,p);
634
	pLink->SetCommStatus(CMST_NORMAL);
635
	m_LastSendTime = GetNowSecond();
636
	PrintLog(LOG_INFORMATION,"????????Ƶ????%d",p);
637
/*
638
	BYTE	buf[20];
639
	int		p = 0;
640
	buf[p] = 0x68;p++;
641
	buf[p] = 0xee;p++;
642
	buf[p] = 0x00;p++;
643
	buf[p] = 0x00;p++;
644
	buf[p] = 14;p++;
645
	buf[p] = 0x00;p++;//
646
	buf[p] = oper;p++;//????
647
	buf[p] = 0x00;p++;//
648
	buf[p] = wall;p++;//????ǽ
649
	buf[p] = task;p++;//????id
650
	buf[p] = mon;p++;//??(??????ͨ??)???
651
	buf[p] = mult;p++;//?ָ?????---
652
	buf[p] = win;p++;//???ڱ??
653
	buf[p] = cam;p++;//ͨ????ƵԴ
654
	buf[p] = 0x00;p++;//ptz
655
	buf[p] = 0x00;p++;//ptzpara
656
	buf[p] = 0x00;p++;//
657
	buf[p] = 0x00;p++;//rec
658
	buf[p] = 0x00;p++;//recpara
659
*/
660

    
661
	return;
662
}
663

    
664
//2bytes,11:????ǽ;12:????;21:ѡ??;22:?ָ??л?;23:ѡ????;24:?л???ƵԴ;31:??̨;41:¼??;51:ץ??
665
//1			2			3	  4	  5   6   7     8		9		10			11	12
666
//??ɫֵ ????????LoHi ????ǽ ???? ?? ?ָ? ?? ͨ????ƵԴ ??̨ ??̨????LoHi ¼?? ¼?????
667
int CcctvC3JT::PTZConv(uint8 ptz)
668
{
669
	int	tPtz=0;
670
	tPtz=ptz;
671
	switch(tPtz){
672
	case 0://ͣ
673
	case 1://????????
674
	case 2:
675
	case 3:
676
	case 4:
677
		tPtz+=10;
678
		break;
679
	case 11://???ϣ????£????ϣ?????
680
	case 12:
681
	case 13:
682
	case 14:
683
		tPtz+=4;
684
		break;
685
	case 5://?䱶??С????Ȧ??С
686
	case 6:
687
	case 9:
688
	case 10:
689
		tPtz+=15;
690
		break;
691
	case 8://????
692
		tPtz+=14;
693
		break;
694
	case 7://Զ??
695
		tPtz+=16;
696
		break;
697
	}	
698
	return tPtz;
699
}
700

    
701
//??Լ???󴴽?????
702
#ifdef __unix
703
extern "C" CProtocol* CreateProtocol(char *defpara)
704
#else
705
extern "C" __declspec(dllexport)  CProtocol* CreateProtocol(char *defpara)
706
#endif
707
{
708
	CProtocol *pEpv = new CcctvC3JT;
709
	return pEpv;
710
} 
(1-1/3)