houzhongjian
2024-10-30 a28ca3f36d0ace05966a8c0fac1e4b5fe921f882
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package com.netsdk.demo.module;
 
import java.io.IOException;
 
import com.netsdk.lib.ImageAlgLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.NetSDKLib.*;
 
 
public class ThermalCameraModule {
    
    static ImageAlgLib imageAlgApi = ImageAlgLib.IMAGEALG_INSTANCE;
    
    public static class ThermalCameraStatus {
        public boolean bSearching = false;                               // 是否正在查找
        public int     nFinderHanle;                                  // 取到的查询句柄
        public int     nTotalCount;                                   // 符合此次查询条件的结果总条数
        public LLong hRadiometryHandle = new LLong(0); // 订阅句柄
    }
    
    private static ThermalCameraStatus status = new ThermalCameraStatus();
    
    /**
     * 订阅温度分布数据(热图)
     */
    public static boolean radiometryAttach(int nChannel, fRadiometryAttachCB cbNotify) {
        /*
         * 入参
         */
        NET_IN_RADIOMETRY_ATTACH stIn = new NET_IN_RADIOMETRY_ATTACH();
        stIn.nChannel = nChannel;  // 通道号
        stIn.cbNotify = cbNotify;  // 回调函数
        
        /*
         * 出参
         */
        NET_OUT_RADIOMETRY_ATTACH stOut = new NET_OUT_RADIOMETRY_ATTACH();
        status.hRadiometryHandle = LoginModule.netsdk.CLIENT_RadiometryAttach(LoginModule.m_hLoginHandle, stIn, stOut, 3000);
        
        if(status.hRadiometryHandle.longValue() == 0) {
            System.err.printf("RadiometryAttach Failed!" + ToolKits.getErrorCodePrint());
        }
        
        return status.hRadiometryHandle.longValue() != 0;
    }
    
    /**
     * 获取查询总个数
     */
    public static boolean isAttaching() {
        return status.hRadiometryHandle.longValue() != 0;
    }
    
    /**
     * 开始获取热图数据
     */
    public static int radiometryFetch(int nChannel) {
        
        int nStatus = -1;
        
        /*
         * 入参
         */
        NET_IN_RADIOMETRY_FETCH stIn = new NET_IN_RADIOMETRY_FETCH();
        stIn.nChannel = nChannel;  // 通道号
        
        /*
         * 出参
         */
        NET_OUT_RADIOMETRY_FETCH stOut = new NET_OUT_RADIOMETRY_FETCH();
        
        if(!LoginModule.netsdk.CLIENT_RadiometryFetch(LoginModule.m_hLoginHandle, stIn, stOut, 3000)) {
            System.err.printf("RadiometryFetch Failed!" + ToolKits.getErrorCodePrint());
        } else {
            nStatus = stOut.nStatus;
        }
        
        return nStatus;
    }
    
    /**
     * 处理回调数据(热图)
     * @throws IOException 
     */
    public static boolean saveData(NET_RADIOMETRY_DATA radiometryData) throws IOException {
        
        if (radiometryData == null) {
            return false;
        }
        
        int nWidth = radiometryData.stMetaData.nWidth;
        int nHeight = radiometryData.stMetaData.nHeight;
        
        short[] pGrayImg = new short[nWidth * nHeight];
        float[] pTempForPixels = new float[nWidth * nHeight];
        
        if(LoginModule.netsdk.CLIENT_RadiometryDataParse(radiometryData, pGrayImg, pTempForPixels)) {
            byte[] pYData = new byte[nWidth*nHeight*2];
            imageAlgApi.drcTable(pGrayImg, (short)nWidth, (short)nHeight, 0, pYData, null);
            ToolKits.savePicture(pYData, "./GrayscaleMap.yuv");
        } else {
            System.err.println("saveData failed!" + ToolKits.getErrorCodePrint());
            return false;
        }
        
        return true;
    }
    
    /**
     * 取消订阅温度分布数据
     */
    public static void radiometryDetach() {
        if(status.hRadiometryHandle.longValue() != 0) {
            LoginModule.netsdk.CLIENT_RadiometryDetach(status.hRadiometryHandle);
            status.hRadiometryHandle.setValue(0);
        }
    }
    
    /**
     * 查询测温点
     */
    public static NET_RADIOMETRYINFO queryPointTemper(int nChannel, short x, short y) {
        int nQueryType = NetSDKLib.NET_QUERY_DEV_RADIOMETRY_POINT_TEMPER;
 
        // 入参
        NET_IN_RADIOMETRY_GETPOINTTEMPER stIn = new NET_IN_RADIOMETRY_GETPOINTTEMPER();
        stIn.nChannel = nChannel;
        stIn.stCoordinate.nx = x;
        stIn.stCoordinate.ny = y;
        
        // 出参
        NET_OUT_RADIOMETRY_GETPOINTTEMPER stOut = new NET_OUT_RADIOMETRY_GETPOINTTEMPER();
    
        stIn.write();
        stOut.write();
        boolean bRet = LoginModule.netsdk.CLIENT_QueryDevInfo(LoginModule.m_hLoginHandle, nQueryType, stIn.getPointer(), stOut.getPointer(), null, 3000);
        if(!bRet) {
            System.err.printf("QueryPointTemper Failed!" + ToolKits.getErrorCodePrint());
            return null;
        }
        
        stOut.read();
        return stOut.stPointTempInfo;
    }
    
    /**
     * 查询测温项
     */
    public static NET_RADIOMETRYINFO queryItemTemper(int nChannel, int nPresetId, int nRuleId, int nMeterType) {
        int nQueryType = NetSDKLib.NET_QUERY_DEV_RADIOMETRY_TEMPER;
        
        // 入参
        NET_IN_RADIOMETRY_GETTEMPER stIn = new NET_IN_RADIOMETRY_GETTEMPER();
        stIn.stCondition.nPresetId = nPresetId;
        stIn.stCondition.nRuleId = nRuleId;
        stIn.stCondition.nMeterType = nMeterType;     // eg: NET_RADIOMETRY_METERTYPE.NET_RADIOMETRY_METERTYPE_AREA;
        stIn.stCondition.nChannel = nChannel;
 
        // 出参
        NET_OUT_RADIOMETRY_GETTEMPER stOut = new NET_OUT_RADIOMETRY_GETTEMPER();
    
        stIn.write();
        stOut.write();
        boolean bRet = LoginModule.netsdk.CLIENT_QueryDevInfo(LoginModule.m_hLoginHandle, nQueryType, stIn.getPointer(), stOut.getPointer(), null, 3000);
        if(!bRet) {
            System.err.printf("QueryPointTemper Failed!" + ToolKits.getErrorCodePrint());
            return null;
        }
        
        stOut.read();
        return stOut.stTempInfo;
    }
    
    /**
     * 开始查询信息
     */
    public static boolean startFind(NET_IN_RADIOMETRY_STARTFIND stuIn) {
        if(status.bSearching) {
            stopFind();
        }
        
        /*
         * 出参
         */
        NET_OUT_RADIOMETRY_STARTFIND stuOut = new NET_OUT_RADIOMETRY_STARTFIND();
        stuIn.write();
        stuOut.write();
        status.bSearching = LoginModule.netsdk.CLIENT_StartFind(LoginModule.m_hLoginHandle, 
                NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000);
        if (status.bSearching) {
            stuOut.read();
            status.nFinderHanle = stuOut.nFinderHanle;
            status.nTotalCount = stuOut.nTotalCount;
        }else {
            System.err.printf("startFind Failed!" + ToolKits.getErrorCodePrint());
        }
        
        return status.bSearching;
    }
    
    /**
     * 获取查询总个数
     */
    public static int getTotalCount() {
        return status.nTotalCount;
    }
    
    /**
     * 查询信息
     */
    public static NET_OUT_RADIOMETRY_DOFIND doFind(int nOffset, int nCount) {
        if(!status.bSearching) {
            System.err.printf("DoFind Failed! [need startFind]");
            return null;
        }
        
        /*
         * 入参
         */
        NET_IN_RADIOMETRY_DOFIND stuIn = new NET_IN_RADIOMETRY_DOFIND();
        stuIn.nFinderHanle = status.nFinderHanle;
        stuIn.nBeginNumber = nOffset;
        stuIn.nCount = nCount;
        
        /*
         * 出参
         */
        NET_OUT_RADIOMETRY_DOFIND stuOut = new NET_OUT_RADIOMETRY_DOFIND();
        
        stuIn.write();
        stuOut.write();
        if (!LoginModule.netsdk.CLIENT_DoFind(LoginModule.m_hLoginHandle,
                NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000)) {
            System.err.printf("DoFind Failed!" + ToolKits.getErrorCodePrint());
            return null;
        }
        
        stuOut.read();
        return stuOut;
    }
    
    /**
     * 停止查询信息
     */
    public static void stopFind() {
        if(!status.bSearching) {
            return;
        }
        
        /*
         * 入参
         */
        NET_IN_RADIOMETRY_STOPFIND stuIn = new NET_IN_RADIOMETRY_STOPFIND();
        stuIn.nFinderHanle = status.nFinderHanle;
        
        /*
         * 出参
         */
        NET_OUT_RADIOMETRY_STOPFIND stuOut = new NET_OUT_RADIOMETRY_STOPFIND();
        
        stuIn.write();
        stuOut.write();
        LoginModule.netsdk.CLIENT_StopFind(LoginModule.m_hLoginHandle, 
                NET_FIND.NET_FIND_RADIOMETRY, stuIn.getPointer(), stuOut.getPointer(), 5000);
        
        status.bSearching = false;
        status.nFinderHanle = 0;
//        status.nTotalCount = 0;
        
        return;
    }
}