跳转至

报警

此处报警方式为“布防”报警方式:是指 SDK 主动连接设备,并发起报警上传命令,设备发生报警立即发送给 SDK。

接口概览

接口名称 功能描述
NET_SDK_SetupAlarmChan 配置报警
NET_SDK_SetDVRMessageCallBack DVR 报警或状态回调
NET_SDK_CloseAlarmChan 关闭报警

流程说明

---
title: 报警模块流程
---
flowchart TD
    line1(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    line2(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)
    line3(配置报警条件和处理方式)
    line4(报警或状态回调<br><strong>NET_SDK_SetDVRMessageCallBack</strong>)
    line5(设置报警<br><strong>NET_SDK_SetupAlarmChan</strong>)
    line6(关闭报警<br><strong>NET_SDK_CloseAlarmChan</strong>)
    line7(注销设备<br><strong>NET_SDK_Logout</strong>)
    line8(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)
    line1 --> line2 --> line3 --> line4 -->line5 -->line6 -->line7 -->line8

示例代码

 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
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>
#include <iostream>

using namespace std;

void SubscribCallBack1(LONG lUserID, DWORD dwCommand, char *pBuf, DWORD dwBufLen, void *pUser)
{
    cout << "recive command: " << dwCommand << endl;
    // NET_SDK_SMART_EVENT_TYPE
    // According to different commands, do different processing
}

void DeviceAlarmProcess()
{
    // 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;
    }

    // Setup alarm
    LONG handle = NET_SDK_SetupAlarmChan(userid);

    if (handle > 0)
    {
        cout << "Setup alarm handle: " << handle << endl;
    }
    else
    {
        DWORD error_code = NET_SDK_GetLastError();
        cout << "Setup alarm fail: " << error_code << endl;
    }

    NET_SDK_SetSubscribCallBack(SubscribCallBack1, NULL);
    // wait for alarm
    Sleep(100000);
    // Close alarm
    NET_SDK_CloseAlarmChan(handle);
    // logout
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
}

相关说明

特殊颜色框部分是实现报警信息上传的必要条件,主要完成相关的报警条件和处理方法的配置,参数配置的接口为 NET_SDK_GetDVRConfigNET_SDK_SetDVRConfig ,信号量报警的配置结构体是 NET_SDK_ALARMINFO

这些参数如果已经配置完成,接下来就是设置布防 NET_SDK_SetupAlarmChan,然后调用报警回调函数 NET_SDK_SetDVRMessageCallBack

整个报警上传过程结束后还需要调用撤防接口等操作。

错误码