Browse Source

数据转换

hanqingsong 3 months ago
parent
commit
cb0face385

+ 2 - 2
src/main/java/com/unis/common/HCNetSDK.java

@@ -7,6 +7,7 @@ import com.sun.jna.ptr.ByteByReference;
7 7
 import com.sun.jna.ptr.IntByReference;
8 8
 import com.sun.jna.ptr.ShortByReference;
9 9
 import com.sun.jna.win32.StdCallLibrary;
10
+import lombok.Data;
10 11
 import org.apache.tomcat.jni.Library;
11 12
 
12 13
 import java.util.Arrays;
@@ -3931,6 +3932,7 @@ DVR实现巡航数据结构
3931 3932
     }
3932 3933
 
3933 3934
     //报警设备信息
3935
+    @Data
3934 3936
     public static class NET_DVR_ALARMER extends Structure {
3935 3937
         public byte byUserIDValid;                 /* userid是否有效 0-无效,1-有效 */
3936 3938
         public byte bySerialValid;                 /* 序列号是否有效 0-无效,1-有效 */
@@ -3950,8 +3952,6 @@ DVR实现巡航数据结构
3950 3952
         public byte[] sSocketIP = new byte[128];    			/* 报警主动上传时的socket IP地址 */
3951 3953
         public byte byIpProtocol;                  /* Ip协议 0-IPV4, 1-IPV6 */
3952 3954
         public byte[] byRes2 = new byte[11];
3953
-
3954
-
3955 3955
     }
3956 3956
 
3957 3957
     //硬解码显示区域参数(子结构)

+ 35 - 0
src/main/java/com/unis/common/NetDVRAlarmerConvert.java

@@ -0,0 +1,35 @@
1
+package com.unis.common;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * @author qingsong.han
7
+ * @description:
8
+ * @create 2024-07-31 16:49
9
+ */
10
+@Data
11
+public class NetDVRAlarmerConvert {
12
+
13
+    private Boolean autoRead;
14
+    private Boolean autoWrite;
15
+    private Byte byDeviceIPValid;
16
+    private Byte byDeviceNameValid;
17
+    private Byte byIpProtocol;
18
+    private Byte byLinkPortValid;
19
+    private String byMacAddr;
20
+    private Byte byMacAddrValid;
21
+    private String byRes2;
22
+    private Byte bySerialValid;
23
+    private Byte bySocketIPValid;
24
+    private Byte byUserIDValid;
25
+    private Byte byVersionValid;
26
+    private Byte dwDeviceVersion;
27
+    private String lUserID;
28
+    private Object pointer;
29
+    private String sDeviceIP;
30
+    private String sDeviceName;
31
+    private String sSerialNumber;
32
+    private String sSocketIP;
33
+    private Short wLinkPort;
34
+
35
+}

+ 1 - 0
src/main/java/com/unis/config/AddressModel.java

@@ -28,4 +28,5 @@ public class AddressModel {
28 28
     // 设备登录密码
29 29
     @Value("${exceptionAlarm.password}")
30 30
     private String password;
31
+
31 32
 }

+ 30 - 2
src/main/java/com/unis/face/FMSGCallBack_V31.java

@@ -5,7 +5,10 @@ import com.sun.jna.Pointer;
5 5
 import com.unis.common.HCNetSDK;
6 6
 /*import com.unissoft.pushMsg.AlarmDSService;
7 7
 import com.unissoft.pushMsg.AlarmDSServiceImpl;*/
8
+import com.unis.common.NetDVRAlarmerConvert;
9
+import com.unis.utils.BinaryConversionUtil;
8 10
 import lombok.extern.slf4j.Slf4j;
11
+import org.springframework.beans.BeanUtils;
9 12
 
10 13
 import java.io.FileOutputStream;
11 14
 import java.io.IOException;
@@ -29,10 +32,34 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
29 32
 
30 33
     public void AlarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
31 34
         log.info("报警事件发生,进入回调");
32
-        log.info(
35
+        log.info("lCommand: {}", lCommand);
36
+        log.info("pAlarmer: {}", JSON.toJSONString(pAlarmer));
37
+        log.info("pAlarmInfo: {}", JSON.toJSONString(pAlarmInfo));
38
+        log.info("dwBufLen: {}", dwBufLen);
39
+        log.info("pUser: {}", JSON.toJSONString(pUser));
40
+        /*log.info(
33 41
                 "lCommand {} -> pAlarmer {} -> pAlarmInfo {} -> dwBufLen {} -> pUser {}",
34 42
                 lCommand, JSON.toJSONString(pAlarmer), JSON.toJSONString(pAlarmInfo),dwBufLen,JSON.toJSONString(pUser)
35
-        );
43
+        );*/
44
+        // bye封装对象转换
45
+        NetDVRAlarmerConvert convert = new NetDVRAlarmerConvert();
46
+        BeanUtils.copyProperties(pAlarmer, convert);
47
+
48
+        // byMacAddr
49
+        convert.setByMacAddr(new String(pAlarmer.getByMacAddr()));
50
+        // byRes2
51
+        convert.setByRes2(new String(pAlarmer.getByRes2()));
52
+        // sDeviceIP
53
+        convert.setSDeviceIP(new String(pAlarmer.getSDeviceIP()));
54
+        // sDeviceName
55
+        convert.setSDeviceName(new String(pAlarmer.getSDeviceName()));
56
+        // sSerialNumber
57
+        convert.setSSerialNumber(new String(pAlarmer.getSSerialNumber()));
58
+        // sSocketIP
59
+        convert.setSSocketIP(new String(pAlarmer.getSSocketIP()));
60
+        log.info("convert: {}", convert);
61
+
62
+
36 63
         /*String hexString = Integer.toHexString(lCommand);
37 64
         log.info("报警类型 hexString {}", hexString);*/
38 65
         switch (lCommand) {
@@ -173,6 +200,7 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
173 200
             default:
174 201
                 // TODO 单报警设备 目前不需要 sAlarmType alarmNow
175 202
                 log.info("alarm type in the FMSGCallBack_V31 ->int: {}", lCommand);
203
+                log.info("alarm type in the FMSGCallBack_V31 ->HEX: {}", BinaryConversionUtil.toHex(lCommand));
176 204
 //                alarmDSService.pushLCommand(lCommand);
177 205
                 break;
178 206
         }

+ 14 - 0
src/main/java/com/unis/utils/BinaryConversionUtil.java

@@ -0,0 +1,14 @@
1
+package com.unis.utils;
2
+
3
+/**
4
+ * @author qingsong.han
5
+ * @description:
6
+ * @create 2024-07-31 17:41
7
+ */
8
+public class BinaryConversionUtil {
9
+
10
+    public static String toHex(int decimal) {
11
+        return String.format("%s%s", "0x", Integer.toHexString(decimal));
12
+    }
13
+
14
+}