1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
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
package com.netsdk.demo.customize.configuration;
 
import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.Utils;
import com.netsdk.lib.enumeration.EM_MAIN_PAGE_STATE;
import com.netsdk.lib.enumeration.NET_EM_CFG_OPERATE_TYPE;
import com.netsdk.lib.structure.NET_CFG_BSCCUSTOM;
import com.netsdk.module.ConfigModule;
 
import java.nio.charset.Charset;
 
/**
 * 楼宇门禁产品 配置
 *
 * @author 47040
 * @since Created in 2021/4/26 16:47
 */
public class BSCCustomConfig {
 
    // netsdk 接口
    private final NetSDKLib netSdkApi = NetSDKLib.NETSDK_INSTANCE;
 
    // 引入sdk初始化和登录模块
    private final ConfigInitAndLogon initModule = new ConfigInitAndLogon(netSdkApi);
 
    // 二次封装模块,包含一些设备配置的通用接口
    private final ConfigModule configModule = new ConfigModule(netSdkApi);
 
    // 多平台 编码
    private final Charset encode = Charset.forName(Utils.getPlatformEncode());
 
    // 登录句柄 存储时句柄时可以直接使用long 传入netsdk时需要包装为LLong类
    private long loginHandler;
 
    ////////////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////// BSC Custom 配置 获取/下发 ////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////
 
    /**
     * BSCCustom 配置获取
     */
    public void getBSCCustomConfig() {
        NET_CFG_BSCCUSTOM config = new NET_CFG_BSCCUSTOM();
        config = (NET_CFG_BSCCUSTOM)
                configModule.getConfig(
                        loginHandler,                                         // 登录句柄
                        NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_BSCCUSTOM,         // 枚举->门禁配置汇总
                        config,                                               // 配置结构体
                        -1,                                           // 通道号 无效 填-1
                        5000                                         // 超时时间(毫秒)
                );
        if (config == null) {
            System.err.println("获取门禁配置汇总失败:" + ToolKits.getErrorCode());
            return;
        }
 
        // 打印看下原先的配置
        StringBuilder info = new StringBuilder().append("---------- 用户门禁配置汇总信息 ----------").append("\n");
 
        int samePersonInterval = config.nSamePersonInterval; // 间隔时间
        String mainPicState = EM_MAIN_PAGE_STATE.getNoteByValue(config.emMainPageState); // 设备界面图片所表示的状态
 
        info.append(String.format("%s: ", "相同人员开门间隔时间(0指不限) 单位秒")).append(samePersonInterval).append("\n")
                .append(String.format("%s: ", "设备界面图片所表示的状态")).append(mainPicState);
        System.out.println(info.toString());
    }
 
    //
 
    /**
     * BSCCustom 配置下发
     */
    public void setBSCCustomConfig() {
 
        // 我们推荐修改配置的方式都是 获取->修改->下发 这样的流程
 
        //////////////////////////////////////// 获取配置 /////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////
 
        NET_CFG_BSCCUSTOM config = new NET_CFG_BSCCUSTOM();
        config = (NET_CFG_BSCCUSTOM)
                configModule.getConfig(
                        loginHandler,                                         // 登录句柄
                        NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_BSCCUSTOM,         // 枚举->门禁配置汇总
                        config,                                               // 配置结构体
                        -1,                                           // 通道号 无效 填-1
                        5000                                         // 超时时间(毫秒)
                );
        if (config == null) {
            System.err.println("获取门禁配置汇总失败:" + ToolKits.getErrorCode());
            return;
        }
        //////////////////////////////////////// 修改配置 /////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////
 
        config.nSamePersonInterval = 60;    // 修改间隔时间 以 60s为例
        // 设备界面图片所表示的状态 以紧急疏散为例
        config.emMainPageState = EM_MAIN_PAGE_STATE.EM_MAIN_PAGE_STATE_URGENTEVACUATE.getValue();
 
        //////////////////////////////////////// 下发配置 /////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////
 
        boolean ret = configModule.setConfig(
                loginHandler,                                         // 登录句柄
                NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_BSCCUSTOM,         // 枚举->门禁配置汇总
                config,                                               // 配置结构体
                -1,                                           // 通道号 无效 填-1
                5000                                         // 超时时间
        );
        if (!ret) {
            System.err.println("配置门禁配置汇总失败:" + ToolKits.getErrorCode());
            return;
        }
        System.out.println("配置门禁配置汇总发送成功");
    }
 
    ////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////// 简易控制台 ////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////
 
    // 初始化测试
    public void InitTest() {
        initModule.init(initModule.defaultDisconnectCB, initModule.defaultReconnectCB);                // 初始化SDK库
        loginHandler = initModule.loginWithHighSecurity(m_strIp, m_nPort, m_strUser, m_strPassword);   // 高安全登录
        if (loginHandler == 0) {
            System.err.println("登录失败, 请检查接口参数, See You..");
            initModule.cleanAndExit();
        }
    }
 
    // 加载测试内容
    public void RunTest() {
        CaseMenu menu = new CaseMenu();
        menu.addItem(new CaseMenu.Item(this, "获取 门禁配置 BSCCustomCfg", "getBSCCustomConfig"));
        menu.addItem(new CaseMenu.Item(this, "下发 门禁配置 BSCCustomCfg", "setBSCCustomConfig"));
        menu.run();
    }
 
    // 结束测试
    public void EndTest() {
        System.out.println("End Test");
        initModule.logout(loginHandler);   // 登出
        System.out.println("See You...");
        initModule.cleanAndExit();         // 清理资源并退出
    }
 
    //////////////////// 配置登陆地址,端口,用户名,密码 ///////////////////////
     private String m_strIp = "172.5.3.159";
    // private String m_strIp = "10.34.3.126";
    private int m_nPort = 37777;
    private String m_strUser = "admin";
    private String m_strPassword = "admin123";
    /////////////////////////////////////////////////////////////////////////
 
    public static void main(String[] args) {
        BSCCustomConfig demo = new BSCCustomConfig();
 
        if (args.length == 4) {
            demo.m_strIp = args[0];
            demo.m_nPort = Integer.parseInt(args[1]);
            demo.m_strUser = args[2];
            demo.m_strPassword = args[3];
        }
 
        demo.InitTest();
        demo.RunTest();
        demo.EndTest();
    }
 
}