跳转至

接收设备注册连接

需要先在设备配置好主动上报相关参数

接口概览

接口名称 功能描述
NET_SDK_AddRegisterDeviceInfo 添加主动注册设备的信息
NET_SDK_SetRegisterPort 设备接收 DVR 主动注册的本地平台端口号
NET_SDK_SetRegisterCallback 注册回调函数
NET_SDK_SetUnRegisterCallback 注销回调函数

流程说明

---
title: 接收设备注册连接
---
flowchart TD
    A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    B(添加上报设备的信息<br><strong>NET_SDK_AddRegisterDeviceInfo</strong>)
    C(在设备Web页面配置好上报参数)
    D(设置监听上报的端口<br><strong>NET_SDK_SetRegisterPort</strong>)
    E(设置设备上报成功回调函数<br><strong>NET_SDK_SetRegisterCallback</strong>)
    F(设置设备断开上报回调函数<br><strong>NET_SDK_SetUnRegisterCallback</strong>)
    G(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)
    style C fill:#e7b13387
    A --> B --> C --> D --> E --> F --> G
接收设备注册链接流程web端设置
接收设备注册链接流程web端设置

示例代码

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

using namespace std;
int m_userid1 = -1;

void CALLBACK AcceptRegisterProc1(LONG lUserID, LONG lRegisterID, LPNET_SDK_DEVICEINFO pDeviceInfo, void *pUser)
{
    m_userid1 = lUserID;
    cout << "lUserID: " << lUserID << endl;
    cout << "lRegisterID: " << lRegisterID << endl;
    cout << "deviceName: " << pDeviceInfo->deviceName << endl;
}

void my_LIVE_DATA_CALLBACK1(POINTERHANDLE lLiveHandle, NET_SDK_FRAME_INFO frameInfo, BYTE *pBuffer, void *pUser)
{
    cout << "deviceID: " << frameInfo.deviceID << endl;
    cout << "channel: " << frameInfo.channel << endl;
    cout << "length: " << frameInfo.length << endl;
}

void RegisterDevice()
{
    // init sdk
    NET_SDK_Init();
    NET_SDK_SetConnectTime(5000, 1);
    NET_SDK_SetReconnect();

    // Register the device.
    REG_LOGIN_INFO regInfo;
    regInfo.deviceId = 95272; // The reporting ID should be consistent with the device's registration.
    strcpy_s(regInfo.m_szUserName, "admin");
    strcpy_s(regInfo.m_szPasswd, "123456");

    NET_SDK_AddRegisterDeviceInfo(&regInfo, 1);

    // Initiate a report
    bool isOk = NET_SDK_SetRegisterPort(2009);
    cout << "NET_SDK_SetRegisterPort: " << isOk << endl;
    isOk = NET_SDK_SetRegisterCallback(AcceptRegisterProc1, NULL);
    cout << "NET_SDK_SetRegisterCallback: " << isOk << endl;

    while (true)
    {
        if (m_userid1 != -1)
        {
            cout << "login success!" << endl;
            break;
        }

        Sleep(1000);
        cout << "wait for login..." << endl;
    }

    // Open live display
    NET_SDK_CLIENTINFO lpClientInfo = {0};
    lpClientInfo.hPlayWnd = GetConsoleWindow();
    lpClientInfo.lChannel = 0;
    lpClientInfo.streamType = NET_SDK_MAIN_STREAM;
    lpClientInfo.bNoDecode = 0;
    LONG lhandle = NET_SDK_LivePlay(m_userid1, &lpClientInfo, NULL, NULL);
    if (lhandle == -1)
    {
        DWORD err1 = NET_SDK_GetLastError();
        cout << "Failed to preview!error code: " << err1 << endl;
        return;
    }
    else
    {
        NET_SDK_SetLiveDataCallBack(lhandle, my_LIVE_DATA_CALLBACK1, NULL);
    }
    cout << "Preview successful!" << endl;
    // Waiting for live display
    Sleep(100000);

    // Login
    NET_SDK_Logout(m_userid1);
    NET_SDK_Cleanup();
}

相关说明

错误码