fuliqi
2024-08-29 4163c93761115c7524ef74a557a1f5e01eafb429
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
package com.ycl.api.YS.config.motion;
 
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.lib.NetDEVSDKLib.*;
 
import javax.swing.*;
import java.awt.event.ItemEvent;
 
/**
 *
 * @introduction Motion Area
 * @description Support IPC
 */
public class MotionArea {
 
    /**
     *
     * @introduction Get motion area
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void getMotionArea() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
 
        NETDEV_MOTION_DETECTION_AREA_TYPE_S stMotionAreaType = new NETDEV_MOTION_DETECTION_AREA_TYPE_S();
        stMotionAreaType.write();
        IntByReference dwBytesReturned = new IntByReference();
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_MOTION_DETECTION_AREA_TYPE, stMotionAreaType.getPointer(), 132, dwBytesReturned );
        if(bRet != true) {
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        stMotionAreaType.read();
        System.out.println(stMotionAreaType.udwAreaType);
        NetDemo.jComboBoxAreaType.setSelectedIndex(stMotionAreaType.udwAreaType);
        //视频通道运动检测区域类型为矩形区域
        if(stMotionAreaType.udwAreaType == 0){
            setMacroElement(false);
            setRectangleElement(true);
            NETDEV_MOTION_DETECTION_AREA_RECTANGLE_INFO_LIST_S RectangleArea = new NETDEV_MOTION_DETECTION_AREA_RECTANGLE_INFO_LIST_S();
            RectangleArea.write();
            dwBytesReturned = new IntByReference();
            bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_MOTION_DETECTION_AREA_RECTANGLE_INFO_LIST, RectangleArea.getPointer(), 1444, dwBytesReturned );
            if(bRet != true) {
                System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
                }
            RectangleArea.read();
            System.out.println(RectangleArea.udwNum);
            NetDemo.textFieldConfigChannelMotionRectangleAreaNum.setText(String.valueOf(RectangleArea.udwNum));
            }else if(stMotionAreaType.udwAreaType == 1){
                setMacroElement(true);
                setRectangleElement(false);
         //视频通道运动检测区域类型为宏块区域
            NETDEV_MOTION_DETECTION_AREA_GRID_INFO_S GridArea = new NETDEV_MOTION_DETECTION_AREA_GRID_INFO_S();
            GridArea.write();
            dwBytesReturned = new IntByReference();
            bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_MOTION_DETECTION_AREA_GRID_INFO, GridArea.getPointer(), 1444, dwBytesReturned );
            if(bRet != true) {
                System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            GridArea.read();
        }
    }
 
    /**
     *
     * @introduction Set motion area
     * @description Calling the interface of NETDEV_SetDevConfig
     *
     */
    public static void setMotionAera() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
 
        NETDEV_MOTION_DETECTION_AREA_TYPE_S stMotionAreaType = new NETDEV_MOTION_DETECTION_AREA_TYPE_S();
        stMotionAreaType.udwAreaType = NetDemo.jComboBoxAreaType.getSelectedIndex();
        stMotionAreaType.write();
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_SET_MOTION_DETECTION_AREA_TYPE, stMotionAreaType.getPointer(), 132);
        if(bRet != true) {
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        JOptionPane.showMessageDialog(null, "Set Success.");
    }
 
    /**
     *
     * @introduction Modify rectangle area
     * @description
     *
     */
    public static void modifyReactangleArea() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
        MotionDetectionAreaWindow mda=new MotionDetectionAreaWindow(NETDEV_MOTION_DETECTION_AREA_TYPE_E.NETDEV_MOTION_DETECTION_AREA_TYPE_RECTANGLE,NetDemo.lpUserID,NetDemo.ChannelID);
        mda.setVisible(true);
    }
 
    /**
     *
     * @introduction Modify macro area
     * @description
     *
     */
    public static void modifyMacroArea() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
        MotionDetectionAreaWindow mdaw=new MotionDetectionAreaWindow(NETDEV_MOTION_DETECTION_AREA_TYPE_E.NETDEV_MOTION_DETECTION_AREA_TYPE_MB, NetDemo.lpUserID, NetDemo.ChannelID);
        mdaw.setVisible(true);
 
    }
 
    /**
     *
     * @introduction Change motion area type
     * @description
     *
     */
    public static void changeAreaType(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            NETDEV_MOTION_DETECTION_AREA_TYPE_S stMotionAreaType = new NETDEV_MOTION_DETECTION_AREA_TYPE_S();
            stMotionAreaType.udwAreaType = NetDemo.jComboBoxAreaType.getSelectedIndex();
            if(stMotionAreaType.udwAreaType == 0){
                setMacroElement(false);
                setRectangleElement(true);
            }else if(stMotionAreaType.udwAreaType == 1){
                setMacroElement(true);
                setRectangleElement(false);
                }
            }
        }
 
    public static void setRectangleElement(boolean aFlag){
        NetDemo.lblAreaRectangle.setVisible(aFlag);
        NetDemo.textFieldConfigChannelMotionRectangleAreaNum.setVisible(aFlag);
        NetDemo.jButtonModifyRectangleArea.setVisible(aFlag);
    }
 
    public static void setMacroElement(boolean aFlag){
        NetDemo.lblAreaGridInfo.setVisible(aFlag);
        NetDemo.jButtonModifyMacroArea.setVisible(aFlag);
    }
 
}