跳转至

智能报警

报警订阅流程:是指 SDK 主动连接设备,并向设备订阅报警,设备发生报警立即发送给 SDK。

接口概览

接口名称 功能描述
NET_SDK_GetIVMRuleConfig 获取设备的智能配置信息(仅支持 IPC)
NET_SDK_SetIVMRuleConfig 设置设备的智能配置信息(仅支持 IPC)
NET_SDK_SmartSubscrib 订阅报警
NET_SDK_UnSmartSubscrib 取消订阅报警
NET_SDK_SetSubscribCallBack 设置注册报警回调函数

流程说明

---
title: 智能报警流程
---

flowchart TD
    A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)
    subgraph 订阅/取消订阅
    direction LR
        C(订阅报警<br><strong>NET_SDK_SmartSubscribe</strong>)
        D(取消订阅报警<br><strong>NET_SDK_UnsmartSubscribe</strong>)
        C --> D
    end
    E(注册报警回调函数<br><strong>NET_SDK_SetSubscribeCallBack</strong>)
    F(注销设备<br><strong>NET_SDK_Logout</strong>)
    G(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)

    A --> B --> E --> 订阅/取消订阅  --> F --> G
  • 初始化接口 NET_SDK_Init 在程序开始时调用,一个程序只需要调用一次。

  • 用户注册即登录设备,调用 NET_SDK_Login  接口,每一台设备只需要登录一次。

  • 设置报警回调函数 NET_SDK_SetSubscribCallBack

  • 设置订阅类型订阅报警 NET_SDK_SmartSubscrib  虚线框部分是实现报警信息上传的必要条件,主要是进行报警布防配置,如果报警布防已经配置完成,那么虚线框部分可以省略。

  • 配置相关参数和联动方式之后,设备将按照配置的规则自动检测,SDK 可以通过报警布防方式获取设备上传的识别结果。不同的设备配置接口可能不同。

  • 退出程序时调用 NET_SDK_Logout  注销设备。

  • 调用 NET_SDK_Cleanup  释放 SDK 所有资源。

示例代码

 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
/* Subscrib and Unsubscrib */
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>
using namespace std;

/*
    Alarm subscription process
*/
/*
    Subscribe and unsubscribe
*/
char m_serverAddressPassLine[256];
void SmartSubscribAndUnSubscribPassline()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;

    // init sdk
    NET_SDK_Init();

    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return;
    }

    BOOL bret;

    NET_DVR_SUBSCRIBE_REPLY sSmartSubscrib;
    // Subscribe the passline alarm event, the information of the event will be put into &sSmartSubscrib
    bret = NET_SDK_SmartSubscrib(userid, NET_IPC_SMART_PASSLINE, 0, &sSmartSubscrib);
    if (!bret)
    {
        cout << " NET_SDK_SmartSubscrib  error" << endl;
    }
    else
    {
        cout << " NET_SDK_SmartSubscrib  success" << endl;
        // Copy the subscription server address information to the variable m_serverAddressPassLine
        memcpy(m_serverAddressPassLine, sSmartSubscrib.serverAddress, sizeof(sSmartSubscrib.serverAddress));
    }

    int dwResult = 0;
    // Unsubscribe passline statistics event
    bret = NET_SDK_UnSmartSubscrib(userid, NET_IPC_SMART_PASSLINE, 0, m_serverAddressPassLine, &dwResult);
    if (!bret)
    {

        cout << " NET_SDK_UnSmartSubscrib  error" << endl;
    }
    else
    {
        cout << " NET_SDK_UnSmartSubscrib  success" << endl;
    }

    // logout
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
}
  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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

/* Register Alarm Callback Functions */
void CALLBACK SubscribCallBack(LONG lUserID, DWORD dwCommand, char *pBuf, DWORD dwBufLen, void *pUser)
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return;
    }

    // dwCommand Different values represent different types of intelligent alarm information, and pBuf is the structure that the alarm content needs to be transformed into
    switch (dwCommand)
    {
    case NET_SDK_SMART_EVENT_TYPE_VFD:
    {
        break; // face detection event,here the specific business processing is omitted
    }

    // video issue detection event,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_AVD:
    {
        break;
    }
    // face comparison event,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_FACE_MATCH:
    {
        break;
    }

    case NET_SDK_SMART_EVENT_TYPE_FACE_MATCH_FOR_IPC:
    {
        // when dwCommand is NET_SDK_SMART_EVENT_TYPE_FACE_MATCH_FOR_IPC ,pBuf structure like this:
        /*  ----------------------
        |   NET_SDK_IVE_BASE_INFO   |
        -------------------------
        |   NET_SDK_IVE_PICTURE_INFO    |
        -------------------------
        |   Picture data(live time)     |
        -------------------------
        |   NET_SDK_IVE_PICTURE_INFO    |
        -------------------------
        |   picture data (album)        |
        -------------------------*/
        NET_SDK_IVE_BASE_INFO *baseInfo = (NET_SDK_IVE_BASE_INFO *)pBuf;
        NET_SDK_IVE_PICTURE_INFO *pictureInfo = (NET_SDK_IVE_PICTURE_INFO *)(pBuf + sizeof(NET_SDK_IVE_BASE_INFO));
        TRACE("iHeight=%d, iWidth=%d, iPicSize=%d, iPicFormat=%d, \n", pictureInfo->iHeight, pictureInfo->iWidth, pictureInfo->iPicSize, pictureInfo->iPicFormat);

        if (dwBufLen >= (sizeof(NET_SDK_IVE_BASE_INFO) + sizeof(NET_SDK_IVE_PICTURE_INFO) + pictureInfo->iPicSize))
        {
            if (pictureInfo->iPicSize > 0)
            {
                /*FILE* backfp = fopen("./testback.jpg", "wb");
                if (backfp)
                {
                    int fret = fwrite(pBuf + (sizeof(NET_SDK_IVE_BASE_INFO) + sizeof(NET_SDK_IVE_PICTURE_INFO)), pictureInfo->iPicSize, 1, backfp);
                    fclose(backfp);
                }*/
            }
        }
    }
    break;
    // cross boundary detection and regional intrusion detection for IPC ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_PEA_FOR_IPC:
    {
        break;
    }
    // cross boundary detection and regional intrusion detection, with target capture related information ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_PEA_TARGET:
    {
        break;
    }
    // object Abandoned/Missing event ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_OSC:
    {
        break;
    }
    // people counting event,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_CPC:
    {
        break;
    }
    // crowdy density event  ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_CDD:
    {
        break;
    }
    // people intrusion event ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_IPD:
    {
        break;
    }
    // target tracking trajectory  event ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_TRAJECT:
    {
        break;
    }
    // license plate for ipc  event ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_VEHICLE:
    {
        break;
    }
    // passline event ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_PASSLINE:
    {
        break;
    }
    // traffic event ,here the specific business processing is omitted
    case NET_SDK_SMART_EVENT_TYPE_TRAFFIC:
    {
    }

        // logout
        NET_SDK_Logout(userid);
        NET_SDK_Cleanup();
    }
}
void SubscribProcess()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.138";
    DWORD device_port = 9008;
    // init sdk
    NET_SDK_Init();
    // device login
    NET_SDK_DEVICEINFO device_info;
    memset(&device_info, 0, sizeof(NET_SDK_DEVICEINFO));
    int userid = NET_SDK_Login(device_ip.GetBuffer(), device_port, username.GetBuffer(), password.GetBuffer(), &device_info);

    if (userid > 0)
    {
        cout << "Login successful: " << userid << endl;
    }
    else
    {
        cout << "Login failed: " << userid << endl;
        return;
    }
    // subscrib callback function
    bool isOk = NET_SDK_SetSubscribCallBack(SubscribCallBack, NULL);

    if (isOk)
    {
        cout << "Set callback successfully" << endl;
    }
    else
    {
        cout << "Set callback failed" << endl;
    }
    // logout
    NET_SDK_Logout(userid);

    NET_SDK_Cleanup();
}
错误码