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
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
//#include "Windows.h"
#include "HCNetSDK.h"
#include <time.h>
 
using namespace std;
#define XML_BUF 3*1024*1024
void CALLBACK g_ExceptionCallBack(DWORD dwType, LONG lUserID, LONG lHandle, void *pUser) {
    char tempbuf[256] = {0};
    switch(dwType) {
    case EXCEPTION_RECONNECT:
// 预览时重连
        printf("----------reconnect--------%d\n", time(NULL));
        break;
    default:
        break;
    }
}
int main() {
    DWORD dwRet;
    
    NET_DVR_Init();
    NET_DVR_SetConnectTime(2000, 1);
    NET_DVR_SetReconnect(10000, true);
    NET_DVR_SetExceptionCallBack_V30(0, NULL,g_ExceptionCallBack, NULL);
 
    LONG lUserID;
 
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30("192.168.1.101", 8000, "admin", "a1234567", &struDeviceInfo);
    if (lUserID < 0) {
        printf("NET_DVR_Login_V30 failed, err: %d\n", NET_DVR_GetLastError());
        NET_DVR_Cleanup();
        return -1;
    }
    
 
    //报警时间段
    NET_DVR_SCHEDTIME net_dvr_schedtime = {0};
    net_dvr_schedtime.byStartHour = 0;
    net_dvr_schedtime. byStartMin = 1;
    net_dvr_schedtime.byStopHour = 11;
    net_dvr_schedtime.byStopMin = 59;
    
    //报警设置信息
    NET_DVR_ALARMOUTCFG_V30 net_dvr_alarmoutcfg = {0};
    net_dvr_alarmoutcfg.dwSize = sizeof(net_dvr_alarmoutcfg);
    net_dvr_alarmoutcfg.sAlarmOutName = "ac";
    net_dvr_alarmoutcfg.dwAlarmOutDelay = 0;
    net_dvr_alarmoutcfg.struAlarmOutTime = &net_dvr_schedtime;
    net_dvr_alarmoutcfg.byRes[16] = 0;
    if(!NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_ALARMOUTCFG_V30,0,&net_dvr_alarmoutcfg,net_dvr_alarmoutcfg.dwSize)){
        printf("NET_DVR_SetDVRConfig failed, err: %d\n", NET_DVR_GetLastError());
    }
        
    //开启警报
    ;
    if(!NET_DVR_SetAlarmOut(lUserID,0xff00,1)){
        printf("NET_DVR_SetAlarmOut failed, err: %d\n", NET_DVR_GetLastError());
    }
    int i =5000;
    while(i>0){
        i--;
    }
    
    //解除警报
    NET_DVR_SetAlarmOut(lUserID,0xff00,0);
    //注销用户
    NET_DVR_Logout(lUserID);
    //释放SDK资源
    NET_DVR_Cleanup();
    return 0;
}