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
/*
 * Copyright(C) 2010,Hikvision Digital Technology Co., Ltd 
 * 
 * File   name£ºAlarm.cpp
 * Discription£º
 * Version    £º1.0
 * Author     £ºpanyd
 * Create Date£º2010_3_25
 * Modification History£º
 */
 
#include <stdio.h>
#include <string.h>
#include "public.h"
#include "Alarm.h"
 
#ifdef _WIN32
#elif defined(__linux__) || defined(__APPLE__)
#include   <unistd.h> 
#endif
 
 
void CALLBACK MessageCallback(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser)
{
    int i;
    NET_DVR_ALARMINFO_V30 struAlarmInfo;
    memcpy(&struAlarmInfo, pAlarmInfo, sizeof(NET_DVR_ALARMINFO_V30));
    //printf("lCommand is %d, alarm type is %d\n", lCommand, struAlarmInfo.dwAlarmType);
    switch(lCommand) 
    {       
    case COMM_ALARM_V30:
        {
            switch (struAlarmInfo.dwAlarmType)
            {
            case 3: //ÒÆ¶¯Õì²â±¨¾¯
                for (i=0; i<16; i++)   //#define MAX_CHANNUM   16  //×î´óͨµÀÊý
                {
                    if (struAlarmInfo.byChannel[i] == 1)
                    {
                        printf("Motion detection %d\n", i+1);
                    }
                }       
                break;
            default:
                break;
            }
        }
        break;
    default:
        break;
    }
}
 
 
//Alarm Test
int Demo_Alarm()
{
//     if (Demo_AlarmListen() == HPR_ERROR)
//     {
//         return HPR_ERROR;
//     }
 
    if (Demo_AlarmFortify() == HPR_ERROR)
    {
        return HPR_ERROR;
    }
 
    return HPR_OK;
}
 
//Alarm listen
int Demo_AlarmListen()
{
    int iRet;
    
    //Init
    iRet = NET_DVR_Init();
    if (iRet == FALSE)
    {
        printf("   pyd---Alarm. NET_DVR_Init fail!\n");
        return HPR_ERROR;
    }
 
    //close
    iRet = NET_DVR_StopListen();
    if (iRet == FALSE)
    {
        printf("   pyd---Alarm. NET_DVR_StopListen fail!%d\n", NET_DVR_GetLastError());
        return HPR_ERROR;
    }
 
    //clean up
    NET_DVR_Cleanup();
 
    return HPR_ERROR;
}
 
// Fortify ²¼·À
int Demo_AlarmFortify()
{
    LONG lUserID;
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30("172.9.6.20", 8000, "admin", "12345", &struDeviceInfo);
    if (lUserID < 0)
    {
        printf("Login error, %d\n", NET_DVR_GetLastError());
        NET_DVR_Cleanup(); 
        return HPR_ERROR;
    }
 
    //ÉèÖñ¨¾¯»Øµ÷º¯Êý
    NET_DVR_SetDVRMessageCallBack_V30(MessageCallback, NULL);
 
    //ÆôÓò¼·À
    LONG lHandle;
    lHandle = NET_DVR_SetupAlarmChan_V30(lUserID);
    if (lHandle < 0)
    {
        printf("NET_DVR_SetupAlarmChan_V30 error, %d\n", NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup(); 
        return HPR_ERROR;
    }
 
#ifdef _WIN32
    Sleep(5000);  //millisecond
#elif  defined(__linux__) || defined(__APPLE__)
    sleep(500);   //second
#endif
 
    //³·Ïú²¼·ÀÉÏ´«Í¨µÀ
    if (!NET_DVR_CloseAlarmChan_V30(lHandle))
    {
        printf("NET_DVR_CloseAlarmChan_V30 error, %d\n", NET_DVR_GetLastError());
        NET_DVR_Logout(lUserID);
        NET_DVR_Cleanup(); 
        return HPR_ERROR;
    }
 
    //×¢ÏúÓû§
    NET_DVR_Logout(lUserID);
    //ÊÍ·ÅSDK×ÊÔ´
    NET_DVR_Cleanup();
    return HPR_OK;
}