Skip to content

Intelligent Alarm

Alarm subscription process: It refers to the SDK actively connecting to the device and subscribing to the device for alarms. If the device experiences an alarm, it will be immediately sent to the SDK.

Interface Overview

interface Name Functional Description
NET_SDK_GetIVMRuleConfig Obtain intelligent configuration information for devices (only - supports IPC)
NET_SDK_SetIVMRuleConfig Set intelligent configuration information for devices (only - supports IPC)
NET_SDK_SmartSubscrib Subscribe alarms
NET_SDK_UnSmartSubscrib UnSubscribe alarms
NET_SDK_SetSubscribCallBack Set the registration alarm callback function

Process Description

---
title: Smart Alarm Process
---

flowchart TD
    A(Device SDK initialization <br><strong>NET_SDK_Init</strong>)
    B(User registers device <br><strong>NET_SDK_Login</strong> or <br><strong>NET_SDK_LoginEx</strong>)
    subgraph Subscribe/Unsubscribe
        direction LR
        C(Subscribe to alarm <br><strong>NET_SDK_SmartSubscribe</strong>)
        D(Unsubscribe to alarm <br><strong>NET_SDK_UnsmartSubscribe</strong>)
        C --> D
    end
    E(Register alarm callback function <br><strong>NET_SDK_SetSubscribeCallBack</strong>)
    F(Unregister device <br><strong>NET_SDK_Logout</strong>)
    G(Release SDK resources <br><strong>NET_SDK_Cleanup</strong>)

    A --> B --> E --> Subscribe/Unsubscribe --> F --> G
  • Initialization interface NET_SDK_Init Called at the beginning of a program, a program only needs to be called once.

  • Users register and login the device, calling NET_SDK_Login Interface,Each device only needs to be login once.

  • Set alarm callback function NET_SDK_SetSubscribCallBack.

  • Set subscription type to subscrib alarm NET_SDK_SmartSubscrib The dashed box section is a necessary condition for uploading alarm information, mainly for configuring alarm deployment. If the alarm deployment is already configured, the dashed box section can be omitted.

  • After configuring relevant parameters and linkage methods, the device will automatically detect according to the configured rules. The SDK can obtain the identification results uploaded by the device through alarm deployment. Different device configurations may have different interfaces.

  • Called when exiting the program NET_SDK_Logout Logout the device.

  • Call NET_SDK_Cleanup Release all SDK resources.

Sample Code

 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();
}
Error Code