fuliqi
2024-09-11 b14531e3b850fe6d2fa916ba7b88b3e2bd2ff30a
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package com.ycl.api.YS.config.video;
 
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_VIDEO_SNAPSHOT_S;
 
import javax.swing.*;
import java.util.InputMismatchException;
 
/**
 *
 * @introduction SnapShot configure
 * @description Support IPC
 */
public class SnapShot {
 
    /**
     *
     * @introduction Get snapshot configure information
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void getSnapShot() {
        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_VIDEO_SNAPSHOT_S snapshotInfo =new NETDEV_VIDEO_SNAPSHOT_S();
        IntByReference dwBytesReturned = new IntByReference();
        snapshotInfo.write();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID,
                NETDEV_CONFIG_COMMAND_E.NETDEV_GET_SNAPSHOT_CFG, snapshotInfo.getPointer(),snapshotInfo.size(),dwBytesReturned);
        if(bRet != true) {
            JOptionPane.showMessageDialog(null, "Get data failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
        }
        else {
            snapshotInfo.read();
            if(snapshotInfo.bIsEnabled==1) {
                NetDemo.chckbxEnableGetPicture.setSelected(true);
            }else {
                NetDemo.chckbxEnableGetPicture.setSelected(false);
            }
            NetDemo.textFieldSnapshotWidth.setText(String.valueOf(snapshotInfo.stResolution.dwWidth));
            NetDemo.textFieldSnapshotHeight.setText(String.valueOf(snapshotInfo.stResolution.dwHeight));
            NetDemo.textFieldPictureMaxSize.setText(String.valueOf(snapshotInfo.udwPictureMaxSize));
            NetDemo.textFieldSnapshotInterval.setText(String.valueOf(snapshotInfo.udwSnapshotInterval));
            NetDemo.textFieldSnapshotNum.setText(String.valueOf(snapshotInfo.udwSnapshotNum));
        }
    }
 
    /**
     *
     * @introduction Set snapshot configure information
     * @description Calling the interface of NETDEV_SetDevConfig
     *
     */
    public static void setSnapShot() {
        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_VIDEO_SNAPSHOT_S snapshotInfo =new NETDEV_VIDEO_SNAPSHOT_S();
        IntByReference dwBytesReturned = new IntByReference();
        snapshotInfo.write();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_SNAPSHOT_CFG, snapshotInfo.getPointer(),snapshotInfo.size(),dwBytesReturned);
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Get data failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else {
            snapshotInfo.read();
            if(NetDemo.chckbxEnableGetPicture.isSelected()) {
                snapshotInfo.bIsEnabled=1;
            }else {
                snapshotInfo.bIsEnabled=0;
            }
            String gettextFieldSnapshotWidth=NetDemo.textFieldSnapshotWidth.getText();
            int SnapshotWidth=0;
            if(gettextFieldSnapshotWidth==null||gettextFieldSnapshotWidth.equals("")) {
                JOptionPane.showMessageDialog(null, "Please input width");
                return;
            }
            try {
                SnapshotWidth=Integer.parseInt(gettextFieldSnapshotWidth);
            }catch(NumberFormatException |InputMismatchException e2) {
                JOptionPane.showMessageDialog(null, "Width is null or transformation Exception");
                NetDemo.textFieldSnapshotWidth.setText(null);
                System.out.println("Width is null or transformation Exception");
                return;
            }
            if(SnapshotWidth<0) {
                NetDemo.textFieldSnapshotWidth.setText(null);
                JOptionPane.showMessageDialog(null, "Width can not less than 0");
                return;
            }
 
            String gettextFieldSnapshotHeight=NetDemo.textFieldSnapshotHeight.getText();
            int shotHeight=0;
            if( gettextFieldSnapshotHeight==null||gettextFieldSnapshotHeight.equals("")) {
                JOptionPane.showMessageDialog(null, "Please input height");
                return;
            }
            try {
                shotHeight=Integer.parseInt(gettextFieldSnapshotHeight);
            }catch(NumberFormatException |InputMismatchException e2) {
                JOptionPane.showMessageDialog(null, "Height is null or transformation Exception");
                NetDemo.textFieldSnapshotHeight.setText(null);
                return;
            }
            if(shotHeight<0) {
                NetDemo.textFieldSnapshotHeight.setText(null);
                JOptionPane.showMessageDialog(null, "Height can not less than 0");
                return;
            }
 
            String gettextFieldPictureMaxSize=NetDemo.textFieldPictureMaxSize.getText();
            int PictureMaxSize=0;
            if(gettextFieldPictureMaxSize==null||gettextFieldPictureMaxSize.equals("")) {
                JOptionPane.showMessageDialog(null, "Please input MaxSize");
                return;
            }
            try {
                PictureMaxSize=Integer.parseInt(gettextFieldPictureMaxSize);
            }catch(NumberFormatException |InputMismatchException e2) {
                JOptionPane.showMessageDialog(null, "MaxSize is null or transformation Exception");
                NetDemo.textFieldPictureMaxSize.setText(null);
                return;
            }
            if(PictureMaxSize<0) {
                NetDemo.textFieldPictureMaxSize.setText(null);
                JOptionPane.showMessageDialog(null, "MaxSize can not less than 0");
                return;
            }
 
            String gettextFieldSnapshotInterval=NetDemo.textFieldSnapshotInterval.getText();
            int shotInterval=1;
            if(gettextFieldSnapshotInterval==null||gettextFieldSnapshotInterval.equals("")) {
                JOptionPane.showMessageDialog(null, "Please input Interval");
                return;
            }
            try {
                shotInterval=Integer.parseInt(gettextFieldSnapshotInterval);
            }catch(NumberFormatException |InputMismatchException e2) {
                JOptionPane.showMessageDialog(null, "Interval is null or transformation Exception");
                NetDemo.textFieldSnapshotInterval.setText(null);
                return;
            }
            if(shotInterval<1) {
                NetDemo.textFieldSnapshotInterval.setText(null);
                JOptionPane.showMessageDialog(null, "Interval can not less than 1");
                return;
            }
            if(shotInterval>60) {
                NetDemo.textFieldSnapshotInterval.setText(null);
                JOptionPane.showMessageDialog(null, "Interval can not more than sixty");
                return;
            }
 
            String gettextFieldSnapshotNum=NetDemo.textFieldSnapshotNum.getText();
            int shotNum=1;
            if(gettextFieldSnapshotNum==null||gettextFieldSnapshotNum.equals("")) {
                JOptionPane.showMessageDialog(null, "Please input num");
                return;
            }
            try {
                shotNum=Integer.parseInt(gettextFieldSnapshotNum);
            }catch(NumberFormatException |InputMismatchException e2) {
                JOptionPane.showMessageDialog(null, "Num is null or transformation Exception");
                NetDemo.textFieldSnapshotNum.setText(null);
                return;
            }
            if(shotNum<1||shotNum>3) {
                NetDemo.textFieldSnapshotNum.setText(null);
                JOptionPane.showMessageDialog(null, "Num should between 1 and 3");
                return;
            }
 
            snapshotInfo.udwPictureMaxSize=PictureMaxSize;
            snapshotInfo.stResolution.dwWidth=SnapshotWidth;
            snapshotInfo.stResolution.dwHeight=shotHeight;
            snapshotInfo.udwSnapshotNum=shotNum;
            snapshotInfo.udwSnapshotInterval=shotInterval;
            snapshotInfo.write();
 
            boolean bRet2 = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_SET_SNAPSHOT_CFG, snapshotInfo.getPointer(), snapshotInfo.size());
            if(!bRet2)
            {
                JOptionPane.showMessageDialog(null, "Set data failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                JOptionPane.showMessageDialog(null, "Set scuess");
                NetDemo.jButtonGetSnapshot.doClick();
            }
        }
    }
}