pans
2016-12-15 87e3ee273b2f84081ac45926be9d8e5be3166eaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/*
* Copyright(C) 2010,Hikvision Digital Technology Co., Ltd 
* File   name£ºConfigParams.cpp
* Discription£º
* Version    £º1.0
* Author     £ºpanyadong
* Create Date£º2010_3_29
* Modification History£º
*/
 
#include "ConfigParams.h"
#include <stdio.h>
#include <string.h>
#include "public.h"
 
 
#include <iostream>
using namespace std;
 
//#define DEMO_DVRCONFIG_IP "172.2.87.101"
#define DEMO_DVRCONFIG_IP "172.4.4.221"
 
/*******************************************************************
      Function:   Demo_ConfigParams
   Description:   Set params.
     Parameter:   (IN)   none  
        Return:   0--successful£¬-1--fail¡£   
**********************************************************************/
int Demo_ConfigParams(LONG lUserID)
{
    //Demo_CompressParams_V30(lUserID);
 
    //Demo_GetDeviceState(lUserID);
 
    //Demo_DiskRaidInfo(lUserID);
 
    //if (Demo_CompressParams_V30() == HPR_ERROR)
    //{
    //    return HPR_ERROR;
    //}
    //Demo_Synchronous_IPC(lUserID);
    //Demo_IPCPasswd(lUserID);
    //Demo_GetDeviceNetUsingInfo(lUserID);
    //Demo_SetIPCNet(lUserID);
 
    //picture
    //Demo_PictureParams(lUserID);
 
    //IPC configure v40
    Demo_IPParaCfg_v31(lUserID);
 
    //IPC configure v40
    //Demo_IPParaCfg_V40(lUserID);
 
    //channel record status
    //Demo_ChannelRecordStatus(lUserID);
 
    return HPR_OK;
}
 
//NET_DVR_GET_COMPRESSCFG
int Demo_CompressParams()
{
    NET_DVR_Init();
    long lUserID;
    //login
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30(DEMO_DVRCONFIG_IP, 8000, "admin", "12345", &struDeviceInfo);
    if (lUserID < 0)
    {
        printf("pyd1---Login error\n");
        return HPR_ERROR;
    }
 
    int iRet;
    //set params
    DWORD uiReturnLen;
    NET_DVR_COMPRESSIONCFG struParams = {0};
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_COMPRESSCFG, struDeviceInfo.byStartChan, \
        &struParams, sizeof(NET_DVR_COMPRESSIONCFG), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_COMPRESSCFG_V30 error.\n");
        NET_DVR_Logout_V30(lUserID);
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
    printf("pyd---size is %d\n", sizeof(NET_DVR_COMPRESSIONCFG_V30));
 
    //stop a minute.
    char cUserChoose;
    printf("pyd---press any key to set :");
    cin>>cUserChoose;
 
    //Set params.
    struParams.struRecordPara.dwVideoBitrate = 2;
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_COMPRESSCFG, struDeviceInfo.byStartChan, \
        &struParams, sizeof(NET_DVR_COMPRESSIONCFG));
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_SET_COMPRESSCFG_V30 error.\n");
        NET_DVR_Logout_V30(lUserID);
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
 
    printf("pyd---press any key to get :");
    cin>>cUserChoose;
    //Get params.
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_COMPRESSCFG, struDeviceInfo.byStartChan, \
        &struParams, sizeof(NET_DVR_COMPRESSIONCFG), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_COMPRESSCFG_V30 error.\n");
        NET_DVR_Logout_V30(lUserID);
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
    printf("pyd---press any key to stop:");
    cin>>cUserChoose;
 
    printf("pyd---%d\n", struParams.struRecordPara.dwVideoBitrate);
    NET_DVR_Logout_V30(lUserID);
    NET_DVR_Cleanup();
    return HPR_OK;
}
 
//NET_DVR_GET_COMPRESSCFG_V30
int Demo_CompressParams_V30(LONG lUserID)
{
    int iRet;
    //set params
    DWORD uiReturnLen;
    NET_DVR_COMPRESSIONCFG_V30 struParams = {0};
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_COMPRESSCFG_V30, 33, \
        &struParams, sizeof(NET_DVR_COMPRESSIONCFG_V30), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_COMPRESSCFG_V30 error.\n");
        NET_DVR_Logout_V30(lUserID);
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
    printf("pyd---size is %d\n", sizeof(NET_DVR_COMPRESSIONCFG_V30));
 
    //stop a minute.
    char cUserChoose;
    printf("pyd---press any key to set :");
    cin>>cUserChoose;
 
    //Set params.
    struParams.struNormHighRecordPara.dwVideoBitrate = 2;
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_COMPRESSCFG_V30, 33, \
        &struParams, sizeof(NET_DVR_COMPRESSIONCFG_V30));
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_SET_COMPRESSCFG_V30 error.\n");
        NET_DVR_Logout_V30(lUserID);
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
 
    printf("pyd---press any key to get :");
    cin>>cUserChoose;
    //Get params.
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_COMPRESSCFG_V30, 33, \
        &struParams, sizeof(NET_DVR_COMPRESSIONCFG_V30), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_COMPRESSCFG_V30 error.\n");
        NET_DVR_Logout_V30(lUserID);
        NET_DVR_Cleanup();
        return HPR_ERROR;
    }
    printf("pyd---press any key to stop:");
    cin>>cUserChoose;
 
    printf("pyd---%d\n", struParams.struNormHighRecordPara.dwVideoBitrate);
    NET_DVR_Logout_V30(lUserID);
    NET_DVR_Cleanup();
    return HPR_OK;
}
 
//NET_DVR_GET_DVR_SYNCHRONOUS_IPC
int Demo_Synchronous_IPC(LONG lUserID)
{
    int iRet = -1;
    DWORD uiReturnLen = 0;
    LONG lChannel = 0;
 
    NET_DVR_SYNCHRONOUS_IPC struParams = {0};
    struParams.dwSize = sizeof(struParams);
 
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_DVR_SYNCHRONOUS_IPC, lChannel, \
        &struParams, sizeof(NET_DVR_SYNCHRONOUS_IPC), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_DVR_SYNCHRONOUS_IPC error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    }
    //printf("pyd---size is %d\n", sizeof(NET_DVR_COMPRESSIONCFG_V30));
 
 
 
    struParams.byEnable = !struParams.byEnable;
    //Set params.
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DVR_SYNCHRONOUS_IPC, lChannel, \
        &struParams, sizeof(NET_DVR_SYNCHRONOUS_IPC));
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_SET_COMPRESSCFG_V30 error.%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    //Get params.
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_DVR_SYNCHRONOUS_IPC, lChannel, \
        &struParams, sizeof(NET_DVR_SYNCHRONOUS_IPC), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_DVR_SYNCHRONOUS_IPC error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    } 
 
    printf("pyd---byEnable:%d\n", struParams.byEnable);
 
    return HPR_OK;
}
 
/**  @fn  int Demo_IPCPasswd(LONG lUserID)
 *   @brief NET_DVR_SET_DVR_IPC_PASSWD
 *   @param (IN) LONG lUserID  
 *   @return 0--success£¬-1--fail.   
 */
int Demo_IPCPasswd(LONG lUserID)
{
    int iRet = -1;
    LONG lChannel = 33;
 
    NET_DVR_IPC_PASSWD struParams = {0};
    struParams.dwSize = sizeof(NET_DVR_IPC_PASSWD);
    strcpy(struParams.sOldPasswd, "12345");
    strcpy(struParams.sNewPasswd, "12345");
 
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DVR_IPC_PASSWD, lChannel, &struParams, sizeof(NET_DVR_IPC_PASSWD));
    if (!iRet)
    {
        printf("pyd---Set NET_DVR_SET_DVR_IPC_PASSWD error:%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
int Demo_GetDeviceNetUsingInfo(LONG lUserID)
{
    int iRet = -1;
    DWORD uiReturnLen = 0;
    LONG lChannel = 0;
 
    NET_DVR_DEVICE_NET_USING_INFO struParams = {0};
    struParams.dwSize = sizeof(NET_DVR_DEVICE_NET_USING_INFO);
 
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_DEVICE_NET_USING_INFO, lChannel, \
        &struParams, sizeof(NET_DVR_DEVICE_NET_USING_INFO), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---Get NET_DVR_DEVICE_NET_USING_INFO error:%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    printf("pyd---dwPreview:%d\n", struParams.dwPreview);
    printf("pyd---dwPlayback:%d\n", struParams.dwPlayback);
    printf("pyd---dwIPCModule:%d\n", struParams.dwIPCModule);
    printf("pyd---dwNetDiskRW:%d\n", struParams.dwNetDiskRW);
 
    return HPR_OK;
}
 
// NET_DVR_SET_DVR_IPC_NET
int Demo_SetIPCNet(LONG lUserID)
{
    int iRet = -1;
    LONG lChannel = 33;
 
    NET_DVR_IPC_NETCFG struParams = {0};
    struParams.dwSize = sizeof(NET_DVR_IPC_NETCFG);
    strcpy(struParams.struIP.sIpV4, "172.9.12.217");
    struParams.wPort = 8000;
 
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DVR_IPC_NET, lChannel, &struParams, sizeof(NET_DVR_IPC_NETCFG));
    if (!iRet)
    {
        printf("pyd---Set NET_DVR_SET_DVR_IPC_NET error:%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
// NET_DVR_GET_DISK_RAID_INFO  && NET_DVR_SET_DISK_RAID_ INFO
/**  @fn  int Demo_DiskRaidInfo(LONG lUserID)
 *   @brief 
 *   @param (IN) LONG lUserID  
 *   @return 0--success£¬-1--fail.   
 */
int Demo_DiskRaidInfo(LONG lUserID)
{
    int iRet = -1;
    DWORD uiReturnLen = 0;
    LONG lChannel = 0;
 
    NET_DVR_DISK_RAID_INFO struParams = {0};
    struParams.dwSize = sizeof(struParams);
 
    //get
    iRet = NET_DVR_GetDVRConfig(lUserID,  NET_DVR_GET_DISK_RAID_INFO, lChannel, \
        &struParams, sizeof(NET_DVR_DISK_RAID_INFO), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_DISK_RAID_INFO error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    struParams.byEnable = !struParams.byEnable;
    //Set
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DISK_RAID_INFO, lChannel, \
        &struParams, sizeof(NET_DVR_DISK_RAID_INFO));
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_SET_DISK_RAID_INFO error.%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    //Get
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_DISK_RAID_INFO, lChannel, \
        &struParams, sizeof(NET_DVR_DISK_RAID_INFO), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_DISK_RAID_INFO error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    } 
 
    printf("pyd---byEnable:%d\n", struParams.byEnable);
 
    return HPR_OK;
}
 
//IPC params v40
int Demo_IPParaCfg_V40(LONG lUserID)
{
    int iRet = -1;
    DWORD uiReturnLen = 0;
    LONG lChannel = 0;
 
    NET_DVR_IPPARACFG_V40 struParams = {0};
    struParams.dwSize = sizeof(struParams);
 
    //get
    iRet = NET_DVR_GetDVRConfig(lUserID,  NET_DVR_GET_IPPARACFG_V40, lChannel, \
        &struParams, sizeof(NET_DVR_IPPARACFG_V40), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_IPPARACFG_V40 error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    }
    //Set
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_IPPARACFG_V40, lChannel, \
        &struParams, sizeof(NET_DVR_IPPARACFG_V40));
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_SET_IPPARACFG_V40 error.%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    //Get
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_IPPARACFG_V40, lChannel, \
        &struParams, sizeof(NET_DVR_IPPARACFG_V40), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_IPPARACFG_V40 error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    } 
    printf("pyd---The Info of IP config:\n");
    PrintIPParaCfgInfo(&struParams);
 
    return HPR_OK;
}
 
int Demo_IPParaCfg_v31(LONG lUserID)
{
    int iRet = -1;
    DWORD uiReturnLen = 0;
    LONG lChannel = 0;
 
    NET_DVR_IPPARACFG_V31 struParams = {0};
    struParams.dwSize = sizeof(struParams);
 
    //get
    iRet = NET_DVR_GetDVRConfig(lUserID,  NET_DVR_GET_IPPARACFG_V31, lChannel, \
        &struParams, sizeof(NET_DVR_IPPARACFG_V31), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GetDVRConfig NET_DVR_GET_IPPARACFG_V31 error.%d\n",  NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
void PrintIPParaCfgInfo(NET_DVR_IPPARACFG_V40 *pIPCParamsInfo)
{
    printf("dwGroupNum:%d\n", pIPCParamsInfo->dwGroupNum);
    printf("dwAChanNum:%d\n", pIPCParamsInfo->dwAChanNum);
    printf("dwDChanNum:%d\n", pIPCParamsInfo->dwDChanNum);
    printf("dwStartDChan:%d\n", pIPCParamsInfo->dwStartDChan);
 
    //for (int i = 0; i <MAX_CHANNUM_V30; i++)
    int i =0;
    for (i = 0; i <1; i++)
    {
        printf("byAnalogChanEnable[%d]:%d", i, pIPCParamsInfo->byAnalogChanEnable[i]);
    }
 
    i = 0;
    if (pIPCParamsInfo->struStreamMode[i].byGetStreamType == 3)
    {
        printf("[%d]Enable:%d", i, pIPCParamsInfo->struStreamMode[i].uGetStream.struDDNSStream.byEnable);
        printf("[%d]IP:    %s", i, pIPCParamsInfo->struStreamMode[i].uGetStream.struDDNSStream.struStreamServer.sIpV4);
        printf("[%d]Port:  %d", i, pIPCParamsInfo->struStreamMode[i].uGetStream.struDDNSStream.wStreamServerPort);
    }
 
}
 
//NET_DVR_GET_PICCFG
int Demo_PictureParams(LONG lUserID)
{
    int iChannelNO = 1;
    int iRet;
 
    //1.Get picture params.
    DWORD uiReturnLen;
    NET_DVR_PICCFG_V30 struParams = {0};
    struParams.dwSize = sizeof(NET_DVR_PICCFG_V30);
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_PICCFG_V30, iChannelNO, &struParams, sizeof(NET_DVR_PICCFG_V30), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GET_PICCFG _V30 %d error.\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
    printf("pyd---Channel %d Name is %s.\n", iChannelNO, struParams.sChanName);
 
    //2.modify
    struParams.dwSize = sizeof(NET_DVR_PICCFG_V30);
    strcpy((char *)(struParams.sChanName), "²»ÊÇÂÒÂë");
 
    //3.set
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_PICCFG_V30, iChannelNO, &struParams, sizeof(NET_DVR_PICCFG_V30));
    if (!iRet)
    {
        printf("pyd---NET_DVR_SetDVRConfig NET_DVR_SET_PICCFG error, %d.\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    printf("pyd---Channel %d Name is %s.\n", iChannelNO, struParams.sChanName);
    return HPR_OK;
}
 
 
//channel record status
int Demo_ChannelRecordStatus(LONG lUserID)
{
    int iGroupNO = 0;
    int iRet = -1;
 
    //1.channel record status.
    DWORD uiReturnLen = 0;
    NET_DVR_CHAN_GROUP_RECORD_STATUS struParams = {0};
    struParams.dwSize = sizeof(NET_DVR_CHAN_GROUP_RECORD_STATUS);
 
    iRet = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_RECORD_CHANNEL_INFO, iGroupNO, &struParams, sizeof(NET_DVR_CHAN_GROUP_RECORD_STATUS), &uiReturnLen);
    if (!iRet)
    {
        printf("pyd---NET_DVR_GET_RECORD_CHANNEL_INFO %d error.\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    //2.set
    iRet = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_RECORD_CHANNEL_INFO, iGroupNO, &struParams, sizeof(NET_DVR_CHAN_GROUP_RECORD_STATUS));
    if (!iRet)
    {
        printf("pyd---NET_DVR_SET_RECORD_CHANNEL_INFO error, %d.\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
 
//Get device state
int Demo_GetDeviceState(LONG lUserID)
{
    NET_DVR_WORKSTATE_V30    struWorkState;
    if (NET_DVR_GetDVRWorkState_V30(lUserID, &struWorkState))
    {
        printf("pyd---NET_DVR_GetDVRWorkState_V30 success.\n");
    } 
    else
    {
        printf("pyd---NET_DVR_GetDVRWorkState_V30 error, %d.\n", NET_DVR_GetLastError());
    }
 
    return HPR_OK;
}