跳转至

远程设备维护

功能描述

远程设备维护模块包括获取设备工作状态、远程升级、日志查找、恢复设备默认参数和导入、导出配置文件等功能

接口概览

接口名称 描述
NET_SDK_Upgrade NVR 升级 tar 包
NET_SDK_UpgradeEx NVR 升级固件包
NET_SDK_UpgradeIPC IPC 升级
NET_SDK_GetUpgradeState 获取升级状态
NET_SDK_GetUpgradeProgress 获取升级进度
NET_SDK_CloseUpgradeHandle 关闭升级句柄
NET_SDK_FindDVRLog 查找日志
NET_SDK_FindNextLog 查找下一个日志
NET_SDK_FindLogClose 关闭日志查找
NET_SDK_RestoreConfig 恢复出厂设置
NET_SDK_GetConfigFile 导出配置文件
NET_SDK_SetConfigFile 导入配置文件

流程说明

---
title: 远程设备维护
---
flowchart TD
    A(设备SDK初始化<br><strong>NET_SDK_Init</strong>)
    B(用户注册设备<br><strong>NET_SDK_Login</strong>或<br><strong>NET_SDK_LoginEx</strong>)

    C("获取设备工作状态<br>...")
    D("设备远程升级<br><strong>NET_SDK_Upgrade</strong>")
    E("设备日志查找<br><strong>NET_SDK_FindDVRLog</strong>")
    F("恢复设备默认配置<br><strong>NET_SDK_RestoreConfig</strong>")
    G("导入配置文件<br><strong>NET_SDK_GetConfigFile</strong>")
    H("导出配置文件<br><strong>NET_SDK_SetConfigFile</strong>")
    style C fill:#e7b13387

    Y(注销设备<br><strong>NET_SDK_Logout</strong>)
    Z(释放SDK资源<br><strong>NET_SDK_Cleanup</strong>)


    A --> B
    Y --> Z
    B ---> C ---> Y
    B ---> D ---> Y
    B ---> E ---> Y
    B ---> F ---> Y
    B ---> G ---> Y
    B ---> H ---> Y

  • 获取设备工作状态:可以获取到设备当前的硬盘状态、通道状态、报警输入和输出口状态、本地显示状态和语音通道状态等信息,虚线框表示本版本对此功能暂时保留。

  • 远程升级:对设备进行升级,并且可以获取当前升级的进度和状态。

  • 日志查找:可以搜索到当前设备的日志信息,包括报警、异常、操作和带 S.M.A.R.T 信息的日志。

  • 恢复设备默认参数:调用接口 NET_SDK_RestoreConfig 能将设备的所有参数都恢复成默认值。

  • 导入、导出配置文件:将设备目前的所有配置信息导出保存或者将指定的配置信息导入到设备。

示例代码

 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>
using namespace std;
void RemoteUpgrade()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.177";
    DWORD device_port = 6036;

    // init sdk
    NET_SDK_Init();
    NET_SDK_SetConnectTime(6000, 1);
    NET_SDK_SetReconnect();

    // 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;
    }

    // nvr upgrade
    // NET_SDK_Upgrade   tar package
    // NET_SDK_UpgradeEx     firmware package

    CString filename = "D:\\N0N_UI1A_230522_148_59579.release.fls"; // firmware package path
    long lUpgradeHandle = NET_SDK_Upgrade(userid, filename.GetBuffer(0));
    if (lUpgradeHandle != -1)
    {
        cout << "Firmware package uploaded successfully." << endl;
        // check upgrade status
        while (true)
        {
            int nState = NET_SDK_GetUpgradeState(lUpgradeHandle);
            if (nState == 3)
            {
                cout << "Upgrade fail 3" << endl;
                break;
            }
            else if (nState == 4)
            {
                cout << "Upgrade fail 4" << endl;
                break;
            }
            else if (nState == 5)
            {
                cout << "Upgrade fail 5" << endl;
                break;
            }

            int nPos = NET_SDK_GetUpgradeProgress(lUpgradeHandle);
            if (nPos >= 100)
            {
                cout << "Upgrade successful." << endl;
                NET_SDK_CloseUpgradeHandle(lUpgradeHandle);
                break;
            }
            cout << "Upgrading: " << nState << "  " << nPos << "%" << endl;
            Sleep(500);
        }
    }
    else
    {
        cout << "firmware package upload failed: " << lUpgradeHandle << endl;
        DWORD LastError = NET_SDK_GetLastError();
        if (LastError == NET_SDK_BUSY)
        {
            cout << "device busy!" << endl;
        }
        else if (LastError == NET_SDK_FILE_NOT_MATCH_PRODUCT)
        {
            cout << "same version!" << endl;
        }
        else
        {
            cout << "Faild :" << LastError << 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

using namespace std;

CTime parseStrTimeToCTime1(string_view intime)
{
    tm tm = {};
    istringstream ss(intime.data());
    ss >> get_time(&tm, "%Y-%m-%d %H:%M:%S");
    time_t tt = mktime(&tm);
    CTime ctime(tt);

    return ctime;
}

void FindDVRLog()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.177";
    DWORD device_port = 6036;

    // 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;
    }

    // Search time period for alarm logs.
    CTime startTime = parseStrTimeToCTime1("2023-04-13 00:00:00");
    CTime endTime = parseStrTimeToCTime1("2023-04-13 23:59:59");

    DD_TIME start = {startTime.GetSecond(), startTime.GetMinute(), startTime.GetHour(), 0, startTime.GetDay(), startTime.GetMonth() - 1, startTime.GetYear() - 1900};
    DD_TIME end = {endTime.GetSecond(), endTime.GetMinute(), endTime.GetHour(), 0, endTime.GetDay(), endTime.GetMonth() - 1, endTime.GetYear() - 1900};

    // Start searching for alarm logs   LOG_ALARM_ALL
    int loghandle = NET_SDK_FindDVRLog(userid, LOG_ALARM_ALL, &start, &end);

    // Search for specific content
    NET_SDK_LOG log;
    long result = 0;
    while (true)
    {
        result = NET_SDK_FindNextLog(loghandle, &log);
        if (result == NET_SDK_NOMOREFILE)
        {
            break;
        }

        // You can process only the required minor types
        // if (log.dwMinorType == LOG_ALARM_INTELLIGENT) {
        //  cout << log.sContent << endl;
        //}

        cout << "Log main type: " << log.dwMajorType << " Log sub type: " << log.dwMinorType << " Log content: " << log.sContent << endl;
    }

    // Close the search
    NET_SDK_FindLogClose(loghandle);

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

void RestoreConfig()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.177";
    DWORD device_port = 6036;
    // 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;
    }

    // Restore to factory settings
    bool isOk = NET_SDK_RestoreConfig(userid);

    if (isOk)
    {
        cout << "Restore to factory settings successful" << endl;
    }
    else
    {
        cout << "Restore to factory settings failed" << 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

void GetConfigFile()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.177";
    DWORD device_port = 6036;
    // 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;
    }

    // Export configuration file
    CString fileName = "config.dat";
    bool isOk = NET_SDK_GetConfigFile(userid, fileName.GetBuffer());

    if (isOk)
    {
        cout << "Configuration file exported successfully" << endl;
    }
    else
    {
        cout << "Configuration file export failed" << 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
#include <iostream>
#include <string>
#include "stdafx.h"
#include "DVR_NET_SDK.h"
#include <iomanip>
#include <sstream>
#include <ctime>
#include <afx.h>

void SetConfigFile()
{
    // device info
    CString username = "admin";
    CString password = "123456";
    CString device_ip = "10.80.1.177";
    DWORD device_port = 6036;
    // 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;
    }

    // Import configuration file
    CString fileName = "ConfigurationBackupFile.txt";
    bool isOk = NET_SDK_SetConfigFile(userid, fileName.GetBuffer());

    if (isOk)
    {
        cout << "Configuration file imported successfully" << endl;
    }
    else
    {
        cout << "Configuration file import failed" << endl;
    }

    // logout
    NET_SDK_Logout(userid);
    NET_SDK_Cleanup();
}

相关说明

错误码