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
package com.ycl.api.YS.ptz.basicptz;
 
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.ptz.ptzextend.Preset;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_PTZ_ALLPRESETS_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_PTZ_PRESETCMD_E;
 
import javax.swing.*;
import java.util.Vector;
 
/**
 * 
 * @description Preset operation includes acquiring preset, turning to preset,setting preset and deleting preset
 *
 */
public class PresetPTZ {
    /**
     * @introduction Get PTZ preset location
     */
    public static void getPTZPreset() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first.error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        NetDemo.PTZBasePresetModel.setRowCount(0);
        /* Create PTZ preset structure */
        NETDEV_PTZ_ALLPRESETS_S stPtzPresets = new NETDEV_PTZ_ALLPRESETS_S();
        /* Get PTZ preset location list */
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetPTZPresetList(NetDemo.lpUserID, NetDemo.ChannelID, stPtzPresets);
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Get data failed,maybe not support,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_GetPTZPresetList failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else
        {
            for(int i = 0; i < stPtzPresets.dwSize; i++)
            {
                Vector<String> vector = new Vector<String>();
                vector.add(String.valueOf(stPtzPresets.astPreset[i].dwPresetID));
                vector.add(Common.byteArrayToString(stPtzPresets.astPreset[i].szPresetName));
                NetDemo.PTZBasePresetModel.insertRow(i,vector);
            }
        }
    }
    
    /**
     * @introduction Go to preset location 
     */
    public static void gotoPTZPreset() {
        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;
        }
 
        if(0 == NetDemo.PTZBasePresetModel.getRowCount()  || NetDemo.jTablePTZBasePreset.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find Preset or seletc Preset first.");
            return;
        }
        else 
        {
            String strPresetID = (String) NetDemo.jTablePTZBasePreset.getValueAt(NetDemo.jTablePTZBasePreset.getSelectedRow(), 0);
            if(strPresetID==null||strPresetID.equals("")) 
            {
                JOptionPane.showMessageDialog(null, "PresetID is null");
                return;
            }
            int PresetID=0;
            try {
                PresetID=Integer.parseInt(strPresetID);
            }catch(Exception m) {
                JOptionPane.showMessageDialog(null, "PresetID is error");
                return;
            }
            
            String strPresetNameString = "";
            /* PTZ preset operation(Do not need to start preview) */
            boolean bRet = NetDemo.netdevsdk.NETDEV_PTZPreset_Other(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_PTZ_PRESETCMD_E.NETDEV_PTZ_GOTO_PRESET, strPresetNameString,PresetID);
            if(bRet != true)
            {
                JOptionPane.showMessageDialog(null, " failed,maybe not support,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_PTZPreset_Other failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
        }
        
    }
    
    /**
     * @introduction Set preset location 
     * @description  It is mainly initialized by the constructor of the Preset class.
     */
    public static void addPTZPreset() {
        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;
        }
 
        Preset p = new Preset();
        p.setVisible(true);
    }
 
    /**
     * @introduction Delete preset location 
     * @description
     */
    public static void deletePTZPreset() {
        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;
        }
 
        if(0 == NetDemo.PTZBasePresetModel.getRowCount()  || NetDemo.jTablePTZBasePreset.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find Preset or seletc Preset first.");
            return;
        }
        else 
        {
            String strPresetID = (String) NetDemo.jTablePTZBasePreset.getValueAt(NetDemo.jTablePTZBasePreset.getSelectedRow(), 0);
            int PresetID=0;
            try {
                PresetID=Integer.parseInt(strPresetID);
            }catch(Exception m) {
                JOptionPane.showMessageDialog(null, "PresetID is error");
                return;
            }
 
            String strPresetNameString = "";
            boolean bRet = NetDemo.netdevsdk.NETDEV_PTZPreset_Other(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_PTZ_PRESETCMD_E.NETDEV_PTZ_CLE_PRESET, strPresetNameString, PresetID);
            if(bRet != true)
            {
                JOptionPane.showMessageDialog(null, " Failed,maybe not support,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_PTZPreset_Other failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            NetDemo.jButtonGetBasePTZPreset.doClick();
        }
 
    }
}