From 51d25be2fac930b44a13784c311e7603009d7f6d Mon Sep 17 00:00:00 2001
From: whycxzp <glperry@163.com>
Date: 星期六, 29 三月 2025 10:47:22 +0800
Subject: [PATCH] 更新hik温度读取

---
 src/main/java/com/whyc/listener/ApplicationListener.java            |  113 +++-----
 src/main/java/com/whyc/pojo/db_power_rt/BattStationTemp.java        |    6 
 src/main/java/com/whyc/util/HikTempUtil.java                        |  489 +++++++++++++++++++++++++++++++++++++
 src/main/java/com/whyc/schedule/BattStationTempScheduleService.java |   84 ++++++
 src/main/java/com/whyc/service/BattStationTempService.java          |   31 ++
 src/main/java/com/whyc/dto/IpInfo.java                              |   18 +
 src/main/java/com/whyc/schedule/VideoScheduleService.java           |    6 
 7 files changed, 671 insertions(+), 76 deletions(-)

diff --git a/src/main/java/com/whyc/dto/IpInfo.java b/src/main/java/com/whyc/dto/IpInfo.java
new file mode 100644
index 0000000..01720d9
--- /dev/null
+++ b/src/main/java/com/whyc/dto/IpInfo.java
@@ -0,0 +1,18 @@
+package com.whyc.dto;
+
+import lombok.Data;
+import lombok.ToString;
+
+@Data
+@ToString
+public class IpInfo {
+
+    private String ip;
+
+    private String cameraId;
+
+    public IpInfo(String ip, String cameraId) {
+        this.ip = ip;
+        this.cameraId = cameraId;
+    }
+}
diff --git a/src/main/java/com/whyc/listener/ApplicationListener.java b/src/main/java/com/whyc/listener/ApplicationListener.java
index b03f730..238db74 100644
--- a/src/main/java/com/whyc/listener/ApplicationListener.java
+++ b/src/main/java/com/whyc/listener/ApplicationListener.java
@@ -1,67 +1,46 @@
-//package com.whyc.listener;
-//
-//import com.whyc.constant.YamlProperties;
-//import com.whyc.dto.Response;
-//import com.whyc.service.VideoService;
-//import org.springframework.beans.factory.annotation.Autowired;
-//
-//import javax.servlet.ServletContext;
-//import javax.servlet.ServletContextEvent;
-//import javax.servlet.ServletContextListener;
-//import javax.servlet.annotation.WebListener;
-//import java.util.List;
-//
-//import static java.lang.Thread.sleep;
-//
-///**
-// * 搴旂敤鍚姩鏃跺垵濮嬪寲
-// * 搴旂敤鍏抽棴鏃堕攢姣�
-// */
-//@WebListener
-//public class ApplicationListener implements ServletContextListener {
-//
-//    @Autowired
-//    private VideoService videoService;
-//
-//    /**
-//     * 1.鍒濆鍖�,寮�鍚棰戞祦骞跺惎鍔ㄥ綍鍍忓瓨鍌�
-//     * @param servletContextEvent
-//     */
-//    @Override
-//    public void contextInitialized(ServletContextEvent servletContextEvent) {
-//        ServletContext application = servletContextEvent.getServletContext();
-//        //鑰冭檻鎰忓鎯呭喌:绐佺劧绋嬪簭姝绘満鎴栬�呯數鑴戞柇鐢甸噸鍚�,闇�瑕佸欢鏃跺惎鍔ㄥ綍鍍�,鍥犱负瑙嗛鎺ㄦ祦鏈嶅姟杩樻湭瀹屾垚.
-//        try {
-//            //寤舵椂20s
-//            sleep(20000);
-//        } catch (InterruptedException e) {
-//            throw new RuntimeException(e);
-//        }
-//
-//
-//        //1.褰曞儚瀛樺偍
-//        //鑾峰彇鎵�鏈夌殑娴乮d
-//        List<String> videoStreamIds = YamlProperties.videoStreamIds;
-//        //寮�鍚綍鍍忓瓨鍌�
-//        videoStreamIds.forEach(streamId -> {
-//            //娣诲姞娴�
-//            Response<String> response = videoService.addStreamProxy(streamId);
-//
-//            //鍒ゆ柇鏄惁鍦ㄥ綍鍍�,涓嶅湪鐨勮瘽,寮�鍚綍鍍�
-//
-//            Response response2 = videoService.startRecord(streamId);
-//            if(!(response2.getCode() ==1 && ((boolean) response2.getData()))){
-//                System.out.println("娴乮d涓�:"+streamId+"鐨勪俊鎭�:"+response2.getMsg());
-//            }else{
-//                System.out.println("娴乮d涓�:"+streamId+"鐨勪俊鎭�:"+response2.getData());
-//            }
-//        });
-//
-//    }
-//
-//    @Override
-//    public void contextDestroyed(ServletContextEvent servletContextEvent) {
-//        //鍏抽棴鎵�鏈夋祦
-//        //videoService.closeStreams();
-//    }
-//}
+package com.whyc.listener;
+
+import com.whyc.constant.YamlProperties;
+import com.whyc.dto.IpInfo;
+import com.whyc.dto.Response;
+import com.whyc.service.VideoService;
+import com.whyc.util.HikTempUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.annotation.WebListener;
+import java.util.LinkedList;
+import java.util.List;
+
+import static java.lang.Thread.sleep;
+
+/**
+ * 搴旂敤鍚姩鏃跺垵濮嬪寲
+ * 搴旂敤鍏抽棴鏃堕攢姣�
+ */
+@WebListener
+public class ApplicationListener implements ServletContextListener {
+
+    @Autowired
+    private VideoService videoService;
+
+    /**
+     * 1.鍒濆鍖�,寮�鍚棰戞祦骞跺惎鍔ㄥ綍鍍忓瓨鍌�
+     * @param servletContextEvent
+     */
+    @Override
+    public void contextInitialized(ServletContextEvent servletContextEvent) {
+        ServletContext application = servletContextEvent.getServletContext();
+        //鍒濆鍖杊ik sdk
+        HikTempUtil.init();
+
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent servletContextEvent) {
+        //鍏抽棴hik sdk
+        HikTempUtil.logoutAndCleanup(HikTempUtil.lUserIDs);
+    }
+}
diff --git a/src/main/java/com/whyc/pojo/db_power_rt/BattStationTemp.java b/src/main/java/com/whyc/pojo/db_power_rt/BattStationTemp.java
index e75bb23..2b981bf 100644
--- a/src/main/java/com/whyc/pojo/db_power_rt/BattStationTemp.java
+++ b/src/main/java/com/whyc/pojo/db_power_rt/BattStationTemp.java
@@ -37,13 +37,13 @@
     private Date recordTime;
 
     /**鏈�楂樻俯搴︾偣璺熺鏉¤建閬撶殑鏈�鐭窛绂荤殑鐐� x*y */
-    private String mtCrossMstPoint;
+    //private String mtCrossMstPoint;
 
     /**鏈�楂樻俯搴﹁窡纾佹潯鐨勬渶鐭窛绂�,鍨傜洿璺濈*/
-    private String mtCrossMstDistance;
+    //private String mtCrossMstDistance;
 
     /**鏈�楂樻俯搴﹀湪纾佹潯鐨勫乏杈�/鍙宠竟,鍊间负false鎴栬�卹ight*/
-    private String mtpMstDirection;
+    //private String mtpMstDirection;
 
     @TableField(exist = false)
     private List<Point> minTempPointList;
diff --git a/src/main/java/com/whyc/schedule/BattStationTempScheduleService.java b/src/main/java/com/whyc/schedule/BattStationTempScheduleService.java
new file mode 100644
index 0000000..35c90cf
--- /dev/null
+++ b/src/main/java/com/whyc/schedule/BattStationTempScheduleService.java
@@ -0,0 +1,84 @@
+package com.whyc.schedule;
+
+import com.whyc.constant.YamlProperties;
+import com.whyc.dto.*;
+import com.whyc.factory.ThreadPoolExecutorFactory;
+import com.whyc.pojo.db_power_rt.BattStationTemp;
+import com.whyc.service.BattStationTempService;
+import com.whyc.service.VideoService;
+import com.whyc.util.DateUtil;
+import com.whyc.util.FileUtil;
+import com.whyc.util.HikTempUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@EnableScheduling
+@Component
+@Slf4j
+public class BattStationTempScheduleService {
+
+    @Autowired
+    private BattStationTempService service;
+
+    /**
+     * 娓╁害瀹炴椂
+     * */
+    @Scheduled(fixedRate = 4000,initialDelay = 2000)
+    public void startRecordAndCheck(){
+        List<IpInfo> ipInfoList = HikTempUtil.ipInfoList;
+        for (int i = 0; i < ipInfoList.size(); i++) {
+            IpInfo ipInfo = ipInfoList.get(i);
+            ThreadPoolExecutorFactory.getPoolExecutor().execute(()-> {
+                String ip = ipInfo.getIp();
+                String cameraId = ipInfo.getCameraId();
+
+                Response response = HikTempUtil.getTempPoint(ip);
+                if ((Boolean) response.getData()){
+                    Map<String, Object> tempMap = (Map<String, Object>) response.getData2();
+                    int pixelX = (int) tempMap.get("pixelX");
+                    int pixelY = (int) tempMap.get("pixelY");
+                    TempPoint minTempPoint = (TempPoint) tempMap.get("minTempPoint");
+                    TempPoint maxTempPoint = (TempPoint) tempMap.get("maxTempPoint");
+
+                    BattStationTemp battStationTemp = new BattStationTemp();
+                    battStationTemp.setPixelX(pixelX);
+                    battStationTemp.setPixelY(pixelY);
+                    //鏈�澶ф俯搴︾偣浣�
+                    battStationTemp.setMaxTemp(maxTempPoint.getTemp());
+                    List<Point> maxTempPoints = maxTempPoint.getPoints();
+                    //瀵筽oints,閲岄潰鐨剎,y杩涜x*y鐨勫瓧绗︿覆杞崲,骞跺皢鎵�鏈夊厓绱犵敤閫楀彿闅斿紑
+                    List<String> maxPointsStr = maxTempPoints.stream().map(item -> item.getX() + "*" + item.getY()).collect(Collectors.toList());
+                    String maxPoints = String.join(",", maxPointsStr);
+                    battStationTemp.setMaxTempPoint(maxPoints);
+                    //鏈�灏忔俯搴︾偣浣�
+                    battStationTemp.setMinTemp(minTempPoint.getTemp());
+                    List<Point> minTempPoints = minTempPoint.getPoints();
+                    //瀵筽oints,閲岄潰鐨剎,y杩涜x*y鐨勫瓧绗︿覆杞崲,骞跺皢鎵�鏈夊厓绱犵敤閫楀彿闅斿紑
+                    List<String> minPointsStr = minTempPoints.stream().map(item -> item.getX() + "*" + item.getY()).collect(Collectors.toList());
+                    String minPoints = String.join(",", minPointsStr);
+                    battStationTemp.setMinTempPoint(minPoints);
+
+                    battStationTemp.setCameraId(cameraId);
+                    Date date = new Date();
+                    battStationTemp.setRecordTime(date);
+
+                    service.addOrUpdate(battStationTemp);
+
+                }else{
+                    String msg = response.getMsg();
+                    // TODO 鎶ラ敊鏃ュ織璁板綍
+                }
+            });
+        }
+
+    }
+
+
+}
diff --git a/src/main/java/com/whyc/schedule/VideoScheduleService.java b/src/main/java/com/whyc/schedule/VideoScheduleService.java
index 5fa060e..5f0b96a 100644
--- a/src/main/java/com/whyc/schedule/VideoScheduleService.java
+++ b/src/main/java/com/whyc/schedule/VideoScheduleService.java
@@ -72,9 +72,9 @@
     }
 
     /**
-     * 褰曞儚淇濇寔2澶�
+     * 褰曞儚淇濇寔7澶�
      */
-    @Scheduled(cron= "0 0 2 * * ?")
+    @Scheduled(cron= "0 0 7 * * ?")
     public void recordRecycle(){
         log.info("-----------鎵ц褰曞儚寰幆----------:"+ DateUtil.YYYY_MM_DD_HH_MM_SS.format(new Date()));
         //鏂囦欢澶硅矾寰� /battery_system/video_system/Debug/www/record/rtp/{streamId}/{day}}
@@ -87,7 +87,7 @@
             List<String> dirList2 = Arrays.asList(dirList);
 
             for (int i = 0; i < dirList2.size()-3; i++) {
-                //鎸夐『搴忓垹闄�,淇濈暀鏈�鍚�3涓猟ay鐨勮棰戝綍鍍忔枃浠跺す
+                //鎸夐『搴忓垹闄�,淇濈暀鏈�鍚�7涓猟ay鐨勮棰戝綍鍍忔枃浠跺す
                 String dirPath2Remove = dirPath + File.separator + dirList2.get(i);
                 File dir2Remove = new File(dirPath2Remove);
                 FileUtil.deleteFile(dir2Remove);
diff --git a/src/main/java/com/whyc/service/BattStationTempService.java b/src/main/java/com/whyc/service/BattStationTempService.java
index 0da95da..7b7af62 100644
--- a/src/main/java/com/whyc/service/BattStationTempService.java
+++ b/src/main/java/com/whyc/service/BattStationTempService.java
@@ -1,14 +1,19 @@
 package com.whyc.service;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.whyc.dto.Point;
 import com.whyc.dto.Response;
 import com.whyc.mapper.BattStationTempMapper;
 import com.whyc.pojo.db_power_rt.BattStationTemp;
 import com.whyc.util.ActionUtil;
+import com.whyc.util.PointUtil;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.LinkedList;
 import java.util.List;
 
 @Service
@@ -18,15 +23,23 @@
     private BattStationTempMapper mapper;
 
     public Response<List<BattStationTemp>> getList() {
-        List<BattStationTemp> list = mapper.selectList((Wrapper<BattStationTemp>) ActionUtil.objeNull);
+        QueryWrapper<BattStationTemp> query = Wrappers.query();
+        query.orderByAsc("camera_id");
+        List<BattStationTemp> list = mapper.selectList(query);
         //瀵规俯搴﹀潗鏍囪繘琛岃В鏋�,minTempPoint鏍煎紡涓�"1*2,2*3",鎶婇噷闈㈡墍鏈夌殑x*y鐐� 鎷嗚В鍒癙oint(x,y)鍒楄〃涓�
         list.stream().forEach(battStationTemp -> {
             String minTempPointStr = battStationTemp.getMinTempPoint();
+
+            List<Point> minTempPointList = battStationTemp.getMinTempPointList();
+            minTempPointList = new LinkedList<>();
+
+            List<Point> maxTempPointList = battStationTemp.getMaxTempPointList();
+            maxTempPointList =new LinkedList<>();
             if(minTempPointStr!=null&&!minTempPointStr.equals("")){
                 String[] split = minTempPointStr.split(",");
                 for (String s : split) {
                     String[] split1 = s.split("\\*");
-                    battStationTemp.getMinTempPointList().add(new Point(Integer.parseInt(split1[0]),Integer.parseInt(split1[1])));
+                    minTempPointList.add(new Point(Integer.parseInt(split1[0]),Integer.parseInt(split1[1])));
                 }
             }
             String maxTempPointStr = battStationTemp.getMaxTempPoint();
@@ -38,11 +51,23 @@
                     //瀵逛簬鏈�楂樻俯搴︾偣 p(a,b)
                     //TODO 宸茬煡鍧愭爣鐐逛袱鐐逛负p1(a1,b1)鍜宲2(a2,b2), 姹� maxTempPoint鐐逛笌p1p2缁勬垚鐨勭嚎鍨傜洿鐩镐氦鐨勭偣p3鐨勫潗鏍囪绠楁柟寮�
 
-                    battStationTemp.getMaxTempPointList().add(p);
+                    maxTempPointList.add(p);
                 }
             }
 
         });
         return new Response<List<BattStationTemp>>().set(1,list);
     }
+
+    public void addOrUpdate(BattStationTemp battStationTemp) {
+        QueryWrapper<BattStationTemp> query = Wrappers.query();
+        query.eq("camera_id",battStationTemp.getCameraId());
+        BattStationTemp tempInDB = mapper.selectOne(query);
+        if (tempInDB ==null) {
+            mapper.insert(battStationTemp);
+        }else{
+            battStationTemp.setId(tempInDB.getId());
+            mapper.updateById(battStationTemp);
+        }
+    }
 }
diff --git a/src/main/java/com/whyc/util/HikTempUtil.java b/src/main/java/com/whyc/util/HikTempUtil.java
new file mode 100644
index 0000000..c6d89d1
--- /dev/null
+++ b/src/main/java/com/whyc/util/HikTempUtil.java
@@ -0,0 +1,489 @@
+package com.whyc.util;
+
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+import com.whyc.dto.IpInfo;
+import com.whyc.dto.Point;
+import com.whyc.dto.Response;
+import com.whyc.dto.TempPoint;
+import com.whyc.hik.Commom.osSelect;
+import com.whyc.hik.NetSDKDemo.HCNetSDK;
+import org.springframework.stereotype.Service;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.*;
+
+@Service
+public class HikTempUtil {
+
+
+
+    static HCNetSDK hCNetSDK = null;
+    //static int lUserID = -1; //鐢ㄦ埛鍙ユ焺
+    public static List<Integer> lUserIDs = new LinkedList<>();
+    public static Map<String,Integer> ipLUserIdMap = new HashMap<>();
+    public static FExceptionCallBack_Imp fExceptionCallBack;
+    public static List<IpInfo> ipInfoList = new LinkedList<>();
+    static {
+        //TODO 鏆傛椂瀹氫箟,鍚庣画瑕佹敼鎴愬搴旂殑
+        ipInfoList.add(new IpInfo("192.168.10.11","1"));
+        ipInfoList.add(new IpInfo("192.168.10.12","2"));
+        ipInfoList.add(new IpInfo("192.168.10.13","3"));
+        ipInfoList.add(new IpInfo("192.168.10.14","4"));
+        ipInfoList.add(new IpInfo("192.168.10.15","5"));
+        ipInfoList.add(new IpInfo("192.168.10.16","6"));
+        ipInfoList.add(new IpInfo("192.168.10.17","7"));
+        ipInfoList.add(new IpInfo("192.168.10.18","8"));
+    }
+
+
+    public static Response getTempPoint(String ip){
+        Integer lUserID = ipLUserIdMap.get(ip);
+        //hCNetSDK.NET_DVR_STDXMLConfig(lUserID, "<?xml version=\"1.0\" encoding=\"GB2312\"?><GetDeviceInfo><dwSize>0</dwSize></GetDeviceInfo>", "GetDeviceInfo", 1000);
+
+        /*========== 绾㈠ 鎶撳浘娴嬫俯 Start==========*/
+        //鎶撶儹鍥�
+        HCNetSDK.NET_DVR_JPEGPICTURE_WITH_APPENDDATA m_strJpegWithAppendData = new HCNetSDK.NET_DVR_JPEGPICTURE_WITH_APPENDDATA();
+        m_strJpegWithAppendData.dwSize = m_strJpegWithAppendData.size();
+        HCNetSDK.BYTE_ARRAY ptrJpegByte = new HCNetSDK.BYTE_ARRAY(2*1024*1024);
+        HCNetSDK.BYTE_ARRAY ptrP2PDataByte  = new HCNetSDK.BYTE_ARRAY(2*1024*1024);
+        m_strJpegWithAppendData.pJpegPicBuff = ptrJpegByte.getPointer();
+        m_strJpegWithAppendData.pP2PDataBuff = ptrP2PDataByte.getPointer();
+        m_strJpegWithAppendData.dwJpegPicLen = 2*1024*1024;
+        m_strJpegWithAppendData.dwP2PDataLen = 2*1024*1024;
+        m_strJpegWithAppendData.write();
+        Map<String, Object> tempPointMap;
+        boolean resBoolean = hCNetSDK.NET_DVR_CaptureJPEGPicture_WithAppendData(lUserID, 2, m_strJpegWithAppendData);
+        if (resBoolean) {
+            System.out.println("鎶撳浘鎴愬姛");
+            //m_strJpegWithAppendData.read();
+            // 瀹氫箟鏂囦欢鍚�
+            String cFilename = "Jpegwithappend_"+ip+".data";
+            String cFilename2 = "Jpegwithappend_"+ip+".csv";
+
+            // 鍒涘缓鏂囦欢杈撳嚭娴�
+            try {
+                FileOutputStream fos = new FileOutputStream(cFilename);
+                // 灏嗘暟鎹啓鍏ユ枃浠�
+                //fos.write(m_strJpegWithAppendData.pP2PDataBuff, 0, m_strJpegWithAppendData.dwP2PDataLen);
+                Pointer pP2PDataBuff = m_strJpegWithAppendData.pP2PDataBuff;
+                fos.write(pP2PDataBuff.getByteArray(0, m_strJpegWithAppendData.dwP2PDataLen), 0, m_strJpegWithAppendData.dwP2PDataLen);
+
+                //鑾峰彇绾㈠缁撴灉骞惰В鏋�
+                tempPointMap = analyzeData(m_strJpegWithAppendData, cFilename, cFilename2);
+            }catch (Exception e){
+                return new Response().set(1,false,e.toString());
+            }
+        }else {
+            System.out.printf("鎶撶儹鍥惧け璐�:%s",hCNetSDK.NET_DVR_GetLastError());
+            return new Response().set(1,false,String.format("鎶撶儹鍥惧け璐�:%s",hCNetSDK.NET_DVR_GetLastError()));
+        }
+        /*========== 绾㈠ 鎶撳浘娴嬫俯 End==========*/
+        /*for (boolean exit = false; !exit; ) {
+            System.out.println("璇疯緭鍏ユ偍鎯宠鎵ц鐨刣emo瀹炰緥! 锛堥��鍑鸿杈撳叆yes锛�");
+            Scanner input = new Scanner(System.in);
+            String str = input.next();
+            // 杞崲涓烘爣鍑嗚緭鍏�
+            str = str.toLowerCase();
+            if (str.equals("yes")) {
+                // 閫�鍑虹▼搴�
+                exit = true;
+                break;
+            }
+            switch (str) {
+                case "1":
+                {
+                    System.out.println("\n[Module]鎵嬪姩鑾峰彇璁惧鍦ㄧ嚎鐘舵��");
+                    DevManager.getDeviceStatus(lUserID);
+                    break;
+                }
+                case "2":
+                {
+                    System.out.println("\n[Module]鑾峰彇璁惧宸ヤ綔鐘舵�佷唬鐮�");
+                    DevManager.getWorkS(lUserID);
+                    break;
+                }
+                case "3":
+                {
+                    System.out.println("\n[Module]鑾峰彇璁惧鍩烘湰淇℃伅");
+                    DevManager.getDeviceInfo(lUserID);
+                    break;
+                }
+
+                case "4":
+                {
+
+                    System.out.println("\n[Module]璁惧鎶撳浘浠g爜");
+                    ChannelParamCfg.CaptureJPEGPicture(lUserID);
+                    break;
+                }
+                case "5":
+                {
+                    //閫傜敤NVR绛夌‖鐩樺綍鍍忔満璁惧
+                    System.out.println("\n[Module]鏌ヨ璁惧閫氶亾鐘舵�佷唬鐮�");
+                    ChannelParamCfg.GetIPChannelInfo(lUserID);
+                    break;
+                }
+                case "6":
+                {
+                    //鑾峰彇鍜岃缃墠绔墿灞曞弬鏁�
+                    System.out.println("\n[Module]鑾峰彇鍜岃缃墠绔墿灞曞弬鏁�");
+                    ChannelParamCfg.GetCameraPara(lUserID);
+                    break;
+                }
+                case "7":
+                {
+                    //鑾峰彇鍜岃缃綉缁滃弬鏁�
+                    System.out.println("\n[Module]鑾峰彇鍜岃缃綉缁滃弬鏁�");
+                    ChannelParamCfg.GetNetCfg(lUserID);
+                    break;
+                }
+                case "8":
+                {
+                    //鑾峰彇鍜岃缃綍鍍忓弬鏁�
+                    System.out.println("\n[Module]鑾峰彇鍜岃缃綍鍍忓弬鏁�");
+                    ChannelParamCfg.GetRecordCfg(lUserID);
+                    break;
+                }
+                case "9":
+                {
+                    //鑾峰彇鍜岃缃浘鍍忓弬鏁�
+                    System.out.println("\n[Module]鑾峰彇鍜岃缃浘鍍忓弬鏁�");
+                    ChannelParamCfg.GetandSetPicCfg(lUserID);
+                    break;
+                }
+                case "10":
+                {
+                    //鑾峰彇鍜岃缃椂闂村弬鏁�
+                    System.out.println("\n[Module]鑾峰彇鍜岃缃椂闂村弬鏁�");
+                    SdkSysCfg.GetandSetDevTime(lUserID);
+                    break;
+                }
+                case "11":
+                {
+                    //鑾峰彇璁惧杞‖浠惰兘鍔涗俊鎭�
+                    System.out.println("\n[Module]鑾峰彇璁惧杞‖浠惰兘鍔�");
+                    DevManager.GetSofthardware_Ability(lUserID);
+                    break;
+                }
+                case "12":
+                {
+                    //鑾峰彇璁惧JPEG鎶撳浘鑳藉姏
+                    System.out.println("\n[Module]鑾峰彇璁惧JPEG鎶撳浘鑳藉姏");
+                    DevManager.GetJPEG_Cap_Ability(lUserID);
+                    break;
+                }
+                case "13":
+                {
+                    //鏃ュ織鏌ユ壘
+                    System.out.println("\n[Module]鏃ュ織鏌ユ壘");
+                    DevManager.FindLog(lUserID);
+                    break;
+                }
+                default:
+                {
+                    System.out.println("\n鏈煡鐨勬寚浠ゆ搷浣�!璇烽噸鏂拌緭鍏�!\n");
+                }
+            }
+        }*/
+
+        //logoutAndCleanup(lUserIDs);
+        return new Response().setII(1,true,tempPointMap,null);
+    }
+
+    public static void init(){
+        if (hCNetSDK == null) {
+            if (!createSDKInstance()) {
+                System.out.println("Load SDK fail");
+                //return new Response().set(1,false,"Load SDK fail");
+            }
+        }
+        //linux绯荤粺寤鸿璋冪敤浠ヤ笅鎺ュ彛鍔犺浇缁勪欢搴�
+        if (osSelect.isLinux()) {
+            HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
+            HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
+            //杩欓噷鏄簱鐨勭粷瀵硅矾寰勶紝璇锋牴鎹疄闄呮儏鍐典慨鏀癸紝娉ㄦ剰鏀硅矾寰勫繀椤绘湁璁块棶鏉冮檺
+            String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
+            String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
+            System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
+            ptrByteArray1.write();
+            hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_LIBEAY_PATH, ptrByteArray1.getPointer());
+            System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
+            ptrByteArray2.write();
+            hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SSLEAY_PATH, ptrByteArray2.getPointer());
+            String strPathCom = System.getProperty("user.dir") + "/lib/";
+            HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
+            System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
+            struComPath.write();
+            hCNetSDK.NET_DVR_SetSDKInitCfg(HCNetSDK.NET_SDK_INIT_CFG_SDK_PATH, struComPath.getPointer());
+        }
+        //SDK鍒濆鍖栵紝涓�涓▼搴忚繘绋嬪彧闇�瑕佽皟鐢ㄤ竴娆�
+        hCNetSDK.NET_DVR_Init();
+
+        if (fExceptionCallBack == null) {
+            fExceptionCallBack = new FExceptionCallBack_Imp();
+        }
+        Pointer pUser = null;
+        if (!hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, pUser)) {
+            //return new Response().set(1,false,"璁剧疆寮傚父娑堟伅鍥炶皟澶辫触");
+            System.out.println("璁剧疆寮傚父娑堟伅鍥炶皟澶辫触");
+        }
+        System.out.println("璁剧疆寮傚父娑堟伅鍥炶皟鎴愬姛");
+
+        //鍚敤SDK鍐欐棩蹇�
+        hCNetSDK.NET_DVR_SetLogToFile(3, "./sdkLog", false);
+        //鐧诲綍璁惧锛屾瘡涓�鍙拌澶囧彧闇�瑕佺櫥褰曚竴娆�
+        //lUserID = TestDemo.loginDevice("10.9.137.21", (short) 8000, "admin", "Cpfwb518+");
+        //int lUserID = HikTempUtil.loginDevice("192.168.10.16", (short) 8000, "admin", "fg001@hdw");
+        for (int i = 0; i < ipInfoList.size(); i++) {
+            String ip = ipInfoList.get(i).getIp();
+            int lUserID = HikTempUtil.loginDevice(ip, (short) 8000, "admin", "fg001@hdw");
+            lUserIDs.add(lUserID);
+            ipLUserIdMap.put(ip,lUserID);
+        }
+
+    }
+
+    public static void logoutAndCleanup(List<Integer> lUserIDs) {
+        for (int i = 0; i < lUserIDs.size(); i++) {
+            int lUserID = lUserIDs.get(i);
+            //绋嬪簭閫�鍑虹殑鏃跺�欒皟鐢ㄦ敞閿�鐧诲綍鎺ュ彛锛屾瘡涓�鍙拌澶囧垎鍒皟鐢ㄤ竴娆�
+            if (hCNetSDK.NET_DVR_Logout(lUserID)) {
+                System.out.println("娉ㄩ攢鎴愬姛");
+            }
+        }
+
+        //閲婃斁SDK璧勬簮锛岀▼搴忛��鍑烘椂璋冪敤锛屽彧闇�瑕佽皟鐢ㄤ竴娆�
+        hCNetSDK.NET_DVR_Cleanup();
+    }
+
+    static class FExceptionCallBack_Imp implements HCNetSDK.FExceptionCallBack {
+        public void invoke(int dwType, int lUserID, int lHandle, Pointer pUser) {
+            System.out.println("寮傚父浜嬩欢绫诲瀷:" + dwType);
+            return;
+        }
+    }
+
+    /**
+     * 鍔ㄦ�佸簱鍔犺浇
+     *
+     * @return
+     */
+    private static boolean createSDKInstance() {
+        if (hCNetSDK == null) {
+            synchronized (HCNetSDK.class) {
+                String strDllPath = "";
+                try {
+                    if (osSelect.isWindows()) {
+                        //win绯荤粺鍔犺浇SDK搴撹矾寰�
+                        strDllPath = System.getProperty("user.dir") + "\\src\\main\\resources\\lib\\Hik\\HCNetSDK.dll";
+                    }
+                    else if (osSelect.isLinux()) {
+                        //Linux绯荤粺鍔犺浇SDK搴撹矾寰�
+                        strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so";
+                    }
+                    hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);
+                } catch (Exception ex) {
+                    System.out.println("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    public static Map<String,Object> analyzeData(HCNetSDK.NET_DVR_JPEGPICTURE_WITH_APPENDDATA m_strJpegWithAppendData, String cFilename, String cFilename2) throws IOException {
+        Map<String,Object> tempMap = new LinkedHashMap<>();
+        // 鎵撳紑鏈湴淇濆瓨鐨勬枃浠�
+        String inputFilename = cFilename;
+        String outputFilename = cFilename2;
+
+        //int m_AnalysisHotPic_W = 384; // 鏍规嵁鎶撶儹鍥炬帴鍙h繑鍥炵殑鍥惧儚瀹絛wJpegPicWidth杩涜璧嬪��
+        //int m_AnalysisHotPic_H = 288; // 鏍规嵁鎶撶儹鍥炬帴鍙h繑鍥炵殑鍥惧儚楂榙wJpegPicHeight杩涜璧嬪��
+        int m_AnalysisHotPic_W = m_strJpegWithAppendData.dwJpegPicWidth; // 鏍规嵁鎶撶儹鍥炬帴鍙h繑鍥炵殑鍥惧儚瀹絛wJpegPicWidth杩涜璧嬪��
+        int m_AnalysisHotPic_H = m_strJpegWithAppendData.dwJpegPicHeight; // 鏍规嵁鎶撶儹鍥炬帴鍙h繑鍥炵殑鍥惧儚楂榙wJpegPicHeight杩涜璧嬪��
+        int bufSize = m_AnalysisHotPic_H * m_AnalysisHotPic_W * 4;
+
+        try (RandomAccessFile datafilefp = new RandomAccessFile(inputFilename, "r");
+             FileOutputStream fp = new FileOutputStream(outputFilename)) {
+
+            // 璇诲彇鏂囦欢閲岄潰鎵�鏈夋暟鎹�
+            byte[] pDataBuf = new byte[bufSize];
+            int bytesRead = datafilefp.read(pDataBuf);
+            if (bytesRead != bufSize) {
+                System.out.println("Failed to read the entire file");
+                return tempMap;
+            }
+
+            float minTemp = 10000.0f;
+            float maxTemp = -10000.0f;
+            //瀛樺偍鏋佸�兼俯搴︾殑鍧愭爣,濡傛灉鏄浉鍚岀殑鏋佸�兼俯搴�,灏变篃鍚屾娣诲姞鍧愭爣鐐�
+            TempPoint minTempPoint = new TempPoint();
+            TempPoint maxTempPoint = new TempPoint();
+
+            ByteBuffer buffer = ByteBuffer.wrap(pDataBuf);
+            buffer.order(ByteOrder.LITTLE_ENDIAN); // 鏍规嵁瀹為檯鎯呭喌璋冩暣瀛楄妭搴�
+
+            for (int iWriteHeight = 0; iWriteHeight < m_AnalysisHotPic_H; ++iWriteHeight) {
+                for (int iWriteWidth = 0; iWriteWidth < m_AnalysisHotPic_W; ++iWriteWidth) {
+                    float fTemp = buffer.getFloat();
+                    // 鍒ゆ柇fTemp鏄惁鏄竴涓甯稿�硷紝涓嶆槸鍒欒祴鍊兼渶澶ф垨鏈�灏忥紝闃叉璁惧宕╂簝
+                    fTemp = (9999 < fTemp) ? 9999 : ((-9999 > fTemp) ? -9999 : fTemp);
+                    //鍙繚鐣欎互涓哄皬鏁�
+                    fTemp = BigDecimal.valueOf(fTemp).setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
+
+                    //minTemp = (minTemp > fTemp) ? fTemp : minTemp;
+                    if(minTemp >= fTemp){
+                        minTemp = fTemp;
+                        //鏌ョ湅瀛樼殑鏈�浣庢俯搴︽槸涓嶆槸褰撳墠娓╁害,涓嶆槸鐨勮瘽,瑕佹竻绌烘渶浣庢俯搴ap,
+                        //鍚屾椂鎶婃渶鏂扮殑鏈�浣庢俯搴﹀拰鍧愭爣淇濆瓨
+                        Float minTempOld = minTempPoint.getTemp();
+                        if(minTempOld == null || minTempOld!=minTemp){ //棣栨璧嬪�� 鎴栬�� 闇�瑕侀噸缃渶浣庢俯搴�
+                            minTempPoint.setTemp(minTemp);
+                            List<Point> points = new ArrayList<>();
+                            Point point = new Point(iWriteWidth,iWriteHeight);
+                            points.add(point);
+                            minTempPoint.setPoints(points);
+                        }else { //瀛樺湪鏈�浣庢俯搴︾浉鍚岀殑鍙﹀涓�涓偣,淇濆瓨涓嬫潵杩涘叆鏈�浣庢俯搴﹀垪琛�
+                            List<Point> points = minTempPoint.getPoints();
+                            points.add(new Point(iWriteWidth,iWriteHeight));
+                        }
+                    }
+                    //maxTemp = (maxTemp < fTemp) ? fTemp : maxTemp;
+                    if(maxTemp <= fTemp){
+                        maxTemp = fTemp;
+                        //鏌ョ湅瀛樼殑鏈�楂樻俯搴︽槸涓嶆槸褰撳墠娓╁害,涓嶆槸鐨勮瘽,瑕佹竻绌烘渶楂樻俯搴ap,
+                        //鍚屾椂鎶婃渶鏂扮殑鏈�楂樻俯搴﹀拰鍧愭爣淇濆瓨
+                        Float maxTempOld = maxTempPoint.getTemp();
+                        if(maxTempOld == null || maxTempOld!=maxTemp){ //棣栨璧嬪�� 鎴栬�� 闇�瑕侀噸缃渶楂樻俯搴�
+                            maxTempPoint.setTemp(maxTemp);
+                            List<Point> points = new ArrayList<>();
+                            Point point = new Point(iWriteWidth,iWriteHeight);
+                            points.add(point);
+                            maxTempPoint.setPoints(points);
+                        }else { //瀛樺湪鏈�楂樻俯搴︾浉鍚岀殑鍙﹀涓�涓偣,淇濆瓨涓嬫潵杩涘叆鏈�楂樻俯搴﹀垪琛�
+                            List<Point> points = maxTempPoint.getPoints();
+                            points.add(new Point(iWriteWidth,iWriteHeight));
+                        }
+                    }
+
+                    String temp = String.format("%.2f,", fTemp);
+
+                    fp.write(temp.getBytes());
+                }
+
+                fp.write("\n".getBytes());
+            }
+
+            System.out.println("Min Temperature: " + minTempPoint);
+            System.out.println("Max Temperature: " + maxTempPoint);
+            tempMap.put("pixelX",m_strJpegWithAppendData.dwJpegPicWidth);
+            tempMap.put("pixelY",m_strJpegWithAppendData.dwJpegPicHeight);
+            tempMap.put("minTempPoint",minTempPoint);
+            tempMap.put("maxTempPoint",maxTempPoint);
+        }
+
+        return  tempMap;
+    }
+
+    /**
+     * 璁惧鐧诲綍V30
+     *
+     * @param ip   璁惧IP
+     * @param port SDK绔彛锛岄粯璁よ澶囩殑8000绔彛
+     * @param user 璁惧鐢ㄦ埛鍚�
+     * @param psw  璁惧瀵嗙爜
+     */
+    /*public static int login_V30(String ip, short port, String user, String psw) {
+        HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
+        int iUserID = hCNetSDK.NET_DVR_Login_V30(ip, port, user, psw, m_strDeviceInfo);
+        System.out.println("UserID:" + lUserID);
+        if ((iUserID == -1) || (iUserID == 0xFFFFFFFF)) {
+            System.out.println("鐧诲綍澶辫触锛岄敊璇爜涓�" + hCNetSDK.NET_DVR_GetLastError());
+            return iUserID;
+        } else {
+            System.out.println(ip + ":璁惧鐧诲綍鎴愬姛锛�");
+            return iUserID;
+        }
+    }*/
+
+    /**
+     * 鐧诲綍璁惧锛屾敮鎸� V40 鍜� V30 鐗堟湰锛屽姛鑳戒竴鑷淬��
+     *
+     * @param ip      璁惧IP鍦板潃
+     * @param port    SDK绔彛锛岄粯璁や负璁惧鐨�8000绔彛
+     * @param user    璁惧鐢ㄦ埛鍚�
+     * @param psw     璁惧瀵嗙爜
+     * @return 鐧诲綍鎴愬姛杩斿洖鐢ㄦ埛ID锛屽け璐ヨ繑鍥�-1
+     */
+    public static int loginDevice(String ip, short port, String user, String psw) {
+        // 鍒涘缓璁惧鐧诲綍淇℃伅鍜岃澶囦俊鎭璞�
+        HCNetSDK.NET_DVR_USER_LOGIN_INFO loginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();
+        HCNetSDK.NET_DVR_DEVICEINFO_V40 deviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
+
+        // 璁剧疆璁惧IP鍦板潃
+        byte[] deviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
+        byte[] ipBytes = ip.getBytes();
+        System.arraycopy(ipBytes, 0, deviceAddress, 0, Math.min(ipBytes.length, deviceAddress.length));
+        loginInfo.sDeviceAddress = deviceAddress;
+
+        // 璁剧疆鐢ㄦ埛鍚嶅拰瀵嗙爜
+        byte[] userName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
+        byte[] password = psw.getBytes();
+        System.arraycopy(user.getBytes(), 0, userName, 0, Math.min(user.length(), userName.length));
+        System.arraycopy(password, 0, loginInfo.sPassword, 0, Math.min(password.length, loginInfo.sPassword.length));
+        loginInfo.sUserName = userName;
+
+        // 璁剧疆绔彛鍜岀櫥褰曟ā寮�
+        loginInfo.wPort = port;
+        loginInfo.bUseAsynLogin = false; // 鍚屾鐧诲綍
+        loginInfo.byLoginMode = 0; // 浣跨敤SDK绉佹湁鍗忚
+
+        // 鎵ц鐧诲綍鎿嶄綔
+        int userID = hCNetSDK.NET_DVR_Login_V40(loginInfo, deviceInfo);
+        if (userID == -1) {
+            System.err.println("鐧诲綍澶辫触锛岄敊璇爜涓�: " + hCNetSDK.NET_DVR_GetLastError());
+        } else {
+            System.out.println(ip + " 璁惧鐧诲綍鎴愬姛锛�");
+            // 澶勭悊閫氶亾鍙烽�昏緫
+            int startDChan = deviceInfo.struDeviceV30.byStartDChan;
+            System.out.println("棰勮璧峰閫氶亾鍙�: " + startDChan);
+        }
+        return userID; // 杩斿洖鐧诲綍缁撴灉
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+

--
Gitblit v1.9.1