zxl
1 天以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package com.ycl.api.YS.vca.vehicle;
 
import com.sun.jna.Pointer;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.vca.vehicle.VehicleMonitor.VEHICLE_MONITOR_OPERATE_WINDOW_EFFECT;
import com.ycl.api.YS.lib.NetDEVSDKLib.*;
 
import javax.swing.*;
import java.util.Vector;
 
/**
 * @description VCA/Vehicle Monitor includes add,delete,modify,find  the information of vehicle monitor
 * @introduction Only support VMS.
 */
public class VCAVehicleMonitor {
    /**
     * @introduction To add vehicle monitor information.
     * @description It is mainly realized by the constructor of VehicleMonitor.
     */
    public static void addVehicleMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_VMS ) 
        {
            VehicleMonitor vm=new VehicleMonitor(VEHICLE_MONITOR_OPERATE_WINDOW_EFFECT.VEHICLE_MONITOR_OPERATE_WINDOW_ADDVEHICLEMONITOR,NetDemo.jButtonVehicleLibFind,NetDemo.jButtonFindVehicleMonitor);
            vm.setVisible(true);
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "only support VMS");
            return;
        }
    }
    /**
     * @introduction To delete vehicle monitor information.
     * @description Calling the interface of NETDEV_DeleteVehicleMonitorInfo to realize.
     */
    public static void deleteVehicleMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        if(0 == NetDemo.jTableVehicleMonitor.getRowCount() || NetDemo.jTableVehicleMonitor.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor and select monitor first!");
            return;
        }
        String strVehicleMonitorName = (String) NetDemo.jTableVehicleMonitor.getValueAt(NetDemo.jTableVehicleMonitor.getSelectedRow(), 0);
        NETDEV_MONITION_INFO_S stVehicleMonitorInfo = NetDemo.mapVehicleMonitorMap.get(strVehicleMonitorName);
        NETDEV_BATCH_OPERATOR_LIST_S stResultList = new NETDEV_BATCH_OPERATOR_LIST_S();
        stResultList.udwNum = 1;
        NETDEV_BATCH_OPERATOR_INFO_S stBatchList = new NETDEV_BATCH_OPERATOR_INFO_S();
        stBatchList.udwID = stVehicleMonitorInfo.udwID;
        stBatchList.write();
        stResultList.pstBatchList = stBatchList.getPointer();
        boolean bRet = NetDemo.netdevsdk.NETDEV_DeleteVehicleMonitorInfo(NetDemo.lpUserID, stResultList);
        if(false == bRet)
        {
            JOptionPane.showMessageDialog(null, "Delete falied,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_DeleteVehicleMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "Delete success");
            NetDemo.jButtonFindVehicleMonitor.doClick();
        }
    
    }
    /**
     * @introduction To modify vehicle monitor information.
     * @description It is mainly realized by the constructor of VehicleMonitor.
     */
    public static void modifyVehicleMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(0 == NetDemo.jTableVehicleMonitor.getRowCount() || NetDemo.jTableVehicleMonitor.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor and select monitor first!");
            return;
        }
 
        VehicleMonitor vvm=new VehicleMonitor(VEHICLE_MONITOR_OPERATE_WINDOW_EFFECT.VEHICLE_MONITOR_OPERATE_WINDOW_MODIFYVEHICLEMONITOR,NetDemo.jButtonVehicleLibFind,NetDemo.jButtonFindVehicleMonitor);
        vvm.setVisible(true);
    }
    /** 
     * @introduction To find vehicle monitor information.
     * @description Calling the interface of NETDEV_FindVehicleMonitorList and NETDEV_FindCloseVehicleMonitorList to realize.
     */
    public static void findVehicleMonitor() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.mapVehicleMonitorMap.clear();
        NetDemo.VehicleMonitorTableModel.setRowCount(0);
        boolean bRet = false;
        NETDEV_MONITOR_QUERY_INFO_S stQueryInfo = new NETDEV_MONITOR_QUERY_INFO_S();
        stQueryInfo.udwLimit = 20;
        Pointer lpVehicleMonitorHandle = NetDemo.netdevsdk.NETDEV_FindVehicleMonitorList(NetDemo.lpUserID);
        if(lpVehicleMonitorHandle == null)
        {
            System.out.printf("NETDEV_FindVehicleMonitorList failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else
        {
            while(true)
            {
                NETDEV_MONITION_INFO_S stMonitorInfo = new NETDEV_MONITION_INFO_S();
                bRet = NetDemo.netdevsdk.NETDEV_FindNextVehicleMonitorInfo(lpVehicleMonitorHandle, stMonitorInfo);
                if(bRet != true)
                {
                    System.out.printf("NETDEV_FindNextVehicleMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                    break;
                }
                else
                {
                    //显示查询数据
                    Vector<String> VehicleMonitorVector = new Vector<String>();
                    VehicleMonitorVector.add(Common.byteArrayToString(stMonitorInfo.stMonitorRuleInfo.szName));
                    VehicleMonitorVector.add(Common.byteArrayToString(stMonitorInfo.stMonitorRuleInfo.szReason));
                    if(stMonitorInfo.stMonitorRuleInfo.udwMonitorType == 0)
                    {
                        VehicleMonitorVector.add("match");
                    }
                    else
                    {
                        VehicleMonitorVector.add("not match");
                    }
                    if(stMonitorInfo.stMonitorRuleInfo.bEnabled == 1)
                    {
                        VehicleMonitorVector.add("enable");
                    }
                    else
                    {
                        VehicleMonitorVector.add("disable");
                    }
                    NetDemo.VehicleMonitorTableModel.addRow(VehicleMonitorVector);
                    NetDemo.mapVehicleMonitorMap.put(Common.byteArrayToString(stMonitorInfo.stMonitorRuleInfo.szName), stMonitorInfo);
                }
            }
            bRet = NetDemo.netdevsdk.NETDEV_FindCloseVehicleMonitorList(lpVehicleMonitorHandle);
            if(bRet != true)
            {
                System.out.printf("NETDEV_FindCloseVehicleMonitorList failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
        }
    
    }
    /**
     * @introduction To enable vehicle monitor.
     * @description Calling the interface of NETDEV_GetVehicleMonitorInfo and NETDEV_SetVehicleMonitorInfo to realize.
     */
    public static void enableVehicleMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        if(0 == NetDemo.jTableVehicleMonitor.getRowCount() || NetDemo.jTableVehicleMonitor.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor and select a monitor first.");
            return;
        }
 
        String strVehiecleMonitorName = (String) NetDemo.jTableVehicleMonitor.getValueAt(NetDemo.jTableVehicleMonitor.getSelectedRow(), 0);
        NETDEV_MONITION_INFO_S stVehicleMonitorInfo = NetDemo.mapVehicleMonitorMap.get(strVehiecleMonitorName);
        NETDEV_MONITION_RULE_INFO_S stMonitorRuleInfo = new NETDEV_MONITION_RULE_INFO_S();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetVehicleMonitorInfo(NetDemo.lpUserID, stVehicleMonitorInfo.udwID, stMonitorRuleInfo);
        if(false == bRet)
        {
            System.out.printf("NETDEV_SetVehicleMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        stMonitorRuleInfo.bEnabled = 1;
        bRet = NetDemo.netdevsdk.NETDEV_SetVehicleMonitorInfo(NetDemo.lpUserID, stVehicleMonitorInfo.udwID, stMonitorRuleInfo);
        if(false == bRet)
        {
            System.out.printf("NETDEV_SetVehicleMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.jButtonFindVehicleMonitor.doClick();
    
    }
    /**
     * @introduction To disable vehicle monitor.
     * @description Calling the interface of NETDEV_GetVehicleMonitorInfo and NETDEV_SetVehicleMonitorInfo.
     */
    public static void disableVehicleMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        if(0 == NetDemo.jTableVehicleMonitor.getRowCount() || NetDemo.jTableVehicleMonitor.getSelectedRow() < 0){
            JOptionPane.showMessageDialog(null, "Please find monitor and select a monitor first.");
            return;
        }
 
        String strVehiecleMonitorName = (String) NetDemo.jTableVehicleMonitor.getValueAt(NetDemo.jTableVehicleMonitor.getSelectedRow(), 0);
        NETDEV_MONITION_INFO_S stVehicleMonitorInfo = NetDemo.mapVehicleMonitorMap.get(strVehiecleMonitorName);
 
        NETDEV_MONITION_RULE_INFO_S stMonitorRuleInfo = new NETDEV_MONITION_RULE_INFO_S();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetVehicleMonitorInfo(NetDemo.lpUserID, stVehicleMonitorInfo.udwID, stMonitorRuleInfo);
        if(false == bRet)
        {
            System.out.printf("NETDEV_SetVehicleMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
 
        stMonitorRuleInfo.bEnabled = 0;
 
 
        bRet = NetDemo.netdevsdk.NETDEV_SetVehicleMonitorInfo(NetDemo.lpUserID, stVehicleMonitorInfo.udwID, stMonitorRuleInfo);
        if(false == bRet)
        {
            System.out.printf("NETDEV_SetVehicleMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.jButtonFindVehicleMonitor.doClick();
    }
}