Project

General

Profile

Feature #3000 » ZJ_cctv.cpp

yan hong, 05/24/2023 03:21 PM

 
1
#pragma once
2
#include "ZJ_cctv.h"
3
#include "ZJ_cctvClient.h"
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
unsigned long long GetTimeStamp()
26
{
27
	unsigned long long stampNow = 0;
28
	time_t timer;
29
	timer = time(NULL);
30
	stampNow = timer;
31

    
32
	return stampNow;
33
}
34

    
35
unsigned int rxprocess(LPVOID rxptr)
36
{
37
	ZJ_CCTV* rtxpPara = NULL;
38

    
39
	rtxpPara = (ZJ_CCTV*)rxptr;
40
	sint32 rtuno = rtxpPara->Get_rtuno();
41
	while (rtxpPara->rxflag)
42
	{
43
		//rtxpPara->getallResources();
44
		
45
//		rtxpPara->realplay("api/tvwall/1/device/1/floatwnd/16846849/subwnd/3","e3c1c32b86154dcea0e9fb2dc701a015");
46
//		rtxpPara->getToken();//wyf test 20230517
47
		SeSleep(10000);
48
	}
49

    
50
	return 0;
51
}
52

    
53
unsigned int txprocess(LPVOID txptr)
54
{
55
	ZJ_CCTV* rtxpPara = NULL;
56

    
57
	rtxpPara = (ZJ_CCTV*)txptr;
58
	sint32 rtuno = rtxpPara->Get_rtuno();
59

    
60
	while (rtxpPara->txflag)
61
	{
62
		S_RAWCMD rawcmd;
63

    
64
		while (rtxpPara->Get_CmdNum() > 0)
65
		{
66
			if (rtxpPara->Get_ACmd(rtuno, &rawcmd) == 0)
67
				break;
68

    
69
			rtxpPara->PrintLog(LOG_INFORMATION, "?յ?%d???ն? ????:%d ", rtuno, rawcmd.type);
70

    
71
			uint8 len = 0;
72
			ST_TRACK_ADDR 	m_cmdaddr;     //?????ⲿ???ͨ???˱????????ⲿ?????ַ??Ϣ
73
			m_cmdaddr = rawcmd.src;
74
			switch (rawcmd.type)
75
			{
76
				case DC_K_CMD_AOOPER:
77
				{
78
					S_AO_CTL* aoinfo;
79
					aoinfo = (S_AO_CTL*)(&rawcmd.data);
80
					int i;
81
					switch (aoinfo->funcCode)
82
					{
83
						case DC_K_CTL_AOSEL://ѡ??
84
							//ֱ?ӷ?У
85
							rawcmd.type = DC_K_CMDRET_AOOPER;
86
							rawcmd.len = sizeof(aoinfo);
87
							rawcmd.src = m_cmdaddr;
88
							aoinfo->retCode = 1;
89

    
90
							rtxpPara->Rpt_AResult(rtuno, rawcmd);
91
							break;
92

    
93
						case DC_K_CTL_AOEXE://ִ??
94
						{
95
							sint32 ytvalue = (sint32)(aoinfo->ptVal);
96
							uint16 ptno = aoinfo->ptAddr;
97

    
98
							rtxpPara->PrintLog(1, "<<<<<< YT no=%d   val=%d  ", ptno, ytvalue);
99

    
100
							int wid = ytvalue / 100;
101
							ytvalue = ytvalue - wid * 100;
102

    
103
							if (ptno >= 1 && ptno <= 4 &&rtxpPara->Cameramap.count(ytvalue)>0 && rtxpPara->Wndmap.count(ptno * 100)>0)
104
							{
105
								rtxpPara->getToken();
106
								rtxpPara->realplay(rtxpPara->Wndmap[ptno * 100], rtxpPara->Cameramap[ytvalue]);								
107
								rtxpPara->PrintLog(1, "??????????ͷ%d??%s ??Ƶ??ǽ??%d x100??%s", ytvalue,rtxpPara->Cameramap[ytvalue].c_str(),ptno,rtxpPara->Wndmap[ptno * 100].c_str());
108
							}
109
							else
110
							{
111
								rtxpPara->PrintLog(3, "δ?????¿?ֵ %d ??Ӧ?ļ?ص??? ???? ???ںţ??¿??ƴ???", ytvalue);
112
							}
113

    
114
						}
115
							break;
116

    
117
						case DC_K_CTL_AODEL://????
118
							break;
119

    
120
						default:
121
							break;
122
					}
123
				}
124
					break;
125

    
126
				default: //?????????·????????		
127
					break;
128
			}
129

    
130

    
131
			rtxpPara->Del_ACmd(rtuno);
132

    
133
		}
134

    
135
		SeSleep(500);
136

    
137
	}
138

    
139
	return 0;
140
}
141

    
142
sint32 ZJ_CCTV::Get_rtuno()
143
{
144
	return (pLink->GetRtuNo());
145
}
146

    
147
sint32 ZJ_CCTV::Get_CmdNum()
148
{
149
	sint32 rtuno = pLink->GetRtuNo();
150
	return (pCmdMem->GetCmdNum(rtuno));
151
}
152

    
153
sint32 ZJ_CCTV::Get_ACmd(sint32 rtuno, S_RAWCMD* cmd)
154
{
155
	return pCmdMem->GetACmd(rtuno, cmd);
156
}
157

    
158
sint32 ZJ_CCTV::Del_ACmd(sint32 rtuno)
159
{
160
	return pCmdMem->DelACmd(rtuno);
161
}
162

    
163
sint32 ZJ_CCTV::Rpt_AResult(sint32 rtuno, S_RAWCMD cmd)
164
{
165
	return pCmdMem->RptAResult(rtuno, cmd);
166
}
167

    
168
void ZJ_CCTV::Init(S_PROTOCOLCFG* pcfg)
169
{
170
	PRawCtrl = pcfg->PRawCtrl;
171
	pCmdMem = pcfg->pCmdMem;
172
	pRtu = pcfg->pRtu;
173
	pLink = pcfg->pLink;
174

    
175
	rxflag = true;
176
	txflag = true;
177

    
178
	ReadIni();
179

    
180
	if (rxflag)
181
	{
182
		sint32 rxthread = SE_CreateThread((PTHREAD_FUNC_DEF)rxprocess, this, 100);
183
	}
184
	PrintLog(LOG_INFORMATION, "????rx?߳? !");
185

    
186
	if (txflag)
187
	{
188
		sint32 txthread = SE_CreateThread((PTHREAD_FUNC_DEF)txprocess, this, 100);
189
	}
190
	PrintLog(LOG_INFORMATION, "????tx?߳? !");
191

    
192
}
193

    
194
int ZJ_CCTV::getallResources()
195
{
196
	int status = 0;
197
	sint32 rtuno = Get_rtuno();
198

    
199
	string url = logininfo.urlheader + "/artemis/api/tvms/v1/public/all";
200
	string header = "Content-Type:application/json\r\n";
201

    
202
	//header = header + logininfo.appkey + "\r\nx-ca-signature-headers:x-ca-key\r\nx-ca-signature:" + Signaturemap["getallResources"];
203

    
204
	string body;
205
	string callback;
206
	Json::Value bodysender;
207

    
208
	bodysender;
209

    
210
	Json::FastWriter bodywrite;
211
	body = bodywrite.write(bodysender);
212
	status = Fclient::Sendreq(url, header, body, callback, 1);
213

    
214
	if (callback.size() <= 0)
215
	{
216
		PrintLog(LOG_ERROR, "getallResources callback is NULL!   ");
217
		return 0;
218
	}
219
		
220
	Json::Reader reader(Json::Features::strictMode());
221
	Json::Value data;
222
	if (reader.parse(callback, data))
223
	{
224
		string state = data["code"].asString();
225
		if (!(state.compare("0")))
226
		{
227
			int size = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"].size();
228
			for (int i = 0; i < size; i++)
229
			{
230
				/*WndInfo wnd;
231
				wnd.wnd_uri = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["wnd_uri"].asString();
232
				wnd.status = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["status"].asInt();
233
				wnd.decode_channel = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["decode_channel"].asInt();
234
				int id = data["data"]["tvwall_list"][0]["dlp_list"][0]["floatwmd_list"][0]["wnd_list"][i]["wnd_id"].asInt();
235
				Wndmap[id] = wnd;*/
236
			}
237
		}
238
		else
239
		{
240
			PrintLog(LOG_ERROR, "??ȡ????ǽ??????Ϣ???ش????? :%s   ",state.c_str());
241
		}
242
	}
243
	
244
	return 1;
245
}
246

    
247
int ZJ_CCTV::getToken()
248
{//{"access_token":"CBI2JCUP8cZvQFwPZJZTEs0EZkC9ridr","expires_in":43199}
249
	int ret=-1;
250
	int status = 0;
251
	sint32 rtuno = Get_rtuno();
252
	m_seq=rand();
253
	string seq_tmp=to_string(m_seq);
254
//seq_tmp="192051860833485581719661";
255
	string url = logininfo.urlheader + "/artemis/oauth/token";
256
//	string header = "Content-Type:application/json\r\n";
257
	string header = "Content-Type: multipart/form-data; boundary=--------------------------"+seq_tmp+"\r\n";//492051860833485581719660\r\n";
258
//	header = header +"User-Agent: PostmanRuntime/7.28.4\r\nAccept: */*\r\n";
259
//	header = header +"Postman-Token: b90f3dd3-2c85-49f6-844e-e2f838f8d380\r\n";
260
//	header = header +"Accept-Encoding: gzip, deflate, br\r\n";
261

    
262
	string body="----------------------------" + seq_tmp + "\r\n";//492051860833485581719660\r\n";
263
body = body +"Content-Disposition: form-data; name=\"client_id\"\r\n\r\n"+logininfo.appkey;
264
body = body +"\r\n----------------------------" + seq_tmp + "\r\n";//492051860833485581719660\r\n";	
265
body = body +"Content-Disposition: form-data; name=\"client_secret\"\r\n\r\n"+logininfo.secret;
266
body = body +"\r\n----------------------------" + seq_tmp + "--\r\n";//492051860833485581719660--\r\n";	
267
	
268
	string callback;
269
	Json::Value bodysender;
270
//	bodysender["client_id"] = logininfo.appkey;
271
//	bodysender["client_secret"] = logininfo.secret;
272
//	Json::FastWriter bodywrite;
273
//	body = bodywrite.write(bodysender);
274

    
275
	status = Fclient::Sendreq(url, header, body, callback, 1);
276
//callback="{\"access_token\":\"CBI2JCUP8cZvQFwPZJZTEs0EZkC9ridr\",\"expires_in\":43199}";//wyf test
277
	if (callback.size() <= 0)
278
	{
279
		PrintLog(LOG_ERROR, "getToken callback is NULL!status=%d   ",status);
280
		return 0;
281
	}
282

    
283
	Json::Reader reader(Json::Features::strictMode());
284
	Json::Value data;
285
	if (reader.parse(callback, data))
286
	{
287
		m_token="";
288
		m_token = data["access_token"].asString();
289
		if (0!=m_token.compare(""))
290
		{
291
			ret=1;
292
			PrintLog(1, "access_token=%s  ",m_token.c_str());
293
		}
294
		else
295
		{
296
			ret=-1;
297
			PrintLog(LOG_ERROR, "access_token??ȡʧ??");
298
		}
299
	}
300
	
301

    
302
	return ret;
303
}
304

    
305
int ZJ_CCTV::realplay(string wnd,string camera)
306
{
307
	int status = 0;
308
	sint32 rtuno = Get_rtuno();
309

    
310
	string url = logininfo.urlheader + "/artemis/api/tvms/v1/public/tvwall/wnds/realplay/addition";
311
//	string header = "Content-Type:application/json\r\nx-ca-key:23013291\r\n";
312
	string header = "Content-Type:application/json\r\naccess_token:" + m_token + "\r\n";
313

    
314
	string body;
315
	string callback;
316
	Json::Value bodysender;
317

    
318
	bodysender["realplay_list"][0]["wnd_uri"] = wnd;
319
	bodysender["realplay_list"][0]["camera_indexcode"] = camera;
320
	bodysender["realplay_list"][0]["stream_type"] = 0;
321

    
322
	Json::FastWriter bodywrite;
323
	body = bodywrite.write(bodysender);
324

    
325
	status = Fclient::Sendreq(url, header, body, callback, 1);
326

    
327
	if (callback.size() <= 0)
328
	{
329
		PrintLog(LOG_ERROR, "realplay callback is NULL!   ");
330
		return 0;
331
	}
332

    
333
	Json::Reader reader(Json::Features::strictMode());
334
	Json::Value data;
335
	if (reader.parse(callback, data))
336
	{
337
		string state = data["code"].asString();
338
		if (!(state.compare("0")))
339
		{
340
			PrintLog(1, "????ǽ??ǽ?????ɹ???   ");
341
		}
342
		else
343
		{
344
			PrintLog(LOG_ERROR, "????ǽ??ǽ???ش????? :%d   ", state);
345
		}
346
	}
347
	
348

    
349
	return 1;
350
}
351

    
352
int ZJ_CCTV::ReadIni()
353
{
354
	char *home = getenv("SEROOT");
355
	if (NULL == home)
356
	{
357
		PrintLog(LOG_ERROR, "????????SEROOTδ????");
358
		return 0;
359
	}
360
	char filename[256] = { 0 };
361
#if defined(__unix)
362
	sprintf(filename, "%s%s", home, "/cfg/ZJ_CCTV.ini");
363
#else
364
	sprintf(filename, "%s%s", home, "\\cfg\\ZJ_CCTV.ini");
365
#endif
366

    
367
	CReadConf readconf;
368

    
369
	char http_tmp[128]={0};
370
	char appkey_tmp[128]={0};
371
	char secret_tmp[128]={0};
372
	char ip_tmp[128]={0};
373
	readconf.ReadString("LoginInfo", "http_type", http_tmp, filename, "http");
374
	string head_tmp = http_tmp;//"https://";
375

    
376
	readconf.ReadString("LoginInfo", "server_ip", ip_tmp, filename, "10.151.1.80:443");
377
	readconf.ReadString("LoginInfo", "appkey", appkey_tmp, filename, "23013291");
378
	readconf.ReadString("LoginInfo", "secret", secret_tmp, filename, "N63QsR6vnHHu73laueHH");
379
	logininfo.appkey = appkey_tmp;
380
	logininfo.secret = secret_tmp;
381
//	logininfo.urlheader = head_tmp + ip_tmp;
382
	logininfo.urlheader = head_tmp + "://" + ip_tmp;
383
	
384
	int wndnum = 0;
385
	wndnum = readconf.ReadLong("Wnd_uri", "winNum", filename, "0");
386
	int i;
387
	char sSection[20];
388
	char wnd_tmp[128];
389
	for (i = 0; i < wndnum; i++)
390
	{
391
		memset(sSection, 0, sizeof(char)* 10);
392
		sprintf(sSection, "win_%d", i + 1);
393
		readconf.ReadString("Wnd_uri", sSection, wnd_tmp, filename, "0");
394
		Wndmap[(i + 1) * 100] = wnd_tmp;
395
	}
396

    
397

    
398
	int cameranum = 0;
399
	cameranum = readconf.ReadLong("Camera", "cameraNum", filename, "0");
400
	char cam_tmp[128];
401
	for (i = 0; i < cameranum; i++)
402
	{
403
		memset(sSection, 0, sizeof(char)* 10);
404
		sprintf(sSection, "camera_%d", i + 1);
405
		readconf.ReadString("Camera", sSection, cam_tmp, filename, "0");
406
		Cameramap[i + 1] = cam_tmp;
407
	}
408

    
409
	return 1;
410
}
411

    
412
sint32 ZJ_CCTV::TxProc()
413
{
414
	return 1;
415
}
416

    
417
sint32 ZJ_CCTV::RxProc()
418
{
419
	return 1;
420
}
421

    
422

    
423

    
424
#if defined(WIN32)
425
extern "C" __declspec(dllexport)
426
#else 
427
extern "C"
428
#endif
429
CProtocol	*CreateProtocol(char *defpara)
430
{
431
	return (CProtocol*)(new ZJ_CCTV());
432
}
433

    
434
/*
435
#ifdef __unix
436
extern "C" CProtocol* CreateProtocol(char *defpara)
437
#else
438
extern "C" __declspec(dllexport)  CProtocol* CreateProtocol(char *defpara)
439
#endif
440
{
441
CProtocol *pEpv = new ZJ_CCTV;
442
return pEpv;
443
}
444
*/
(1-1/9)