对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
写在前面
对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
海康设备 通过 SDK 查看修改网络摄像头配置 有个简单需求,需要通过程序远程修改 海康网络摄像头配置,可以在指定的时间间隔的情况下抓图,通过 FTP 传到指定服务器,需要修改的网络摄像头配置项:
FTP 配置 NET_DVR_SET_FTPCFG_V40
,NET_DVR_GET_FTPCFG_V40
抓图配置 NET_DVR_GET_JPEG_CAPTURE_CFG
,NET_DVR_SET_JPEG_CAPTURE_CFG
(图片大小等,时间间隔)
抓图计划配置 NET_DVR_GET_SCHED_CAPTURECFG
,NET_DVR_SET_SCHED_CAPTURECFG
(每天什么时候抓图)
项目目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X:. ├─main │ ├─java │ │ └─com │ │ └─xtj │ │ └─hikvisionsdkintegration │ │ ├─config │ │ ├─controller │ │ ├─dto │ │ ├─sdklib │ │ ├─service │ │ ├─task │ │ └─util │ └─resources
项目地址: https://github.com/LIRUILONGS/Hikvision-sdk-Integration
调用方式通过接口调用,支持 Get,Post
方式
get 方式
1 2 3 http://127.0.0.1:8099/config/state/192.168.1.143 http://127.0.0.1:8099/config/ftp?ips=192.168.1.143,192.168.1.141,192.168.1.142 http://127.0.0.1:8099/config/ftp/status?ips=192.168.1.143,192.168.1.141,192.168.1.142
post 方式
1 2 3 4 5 6 7 curl --location --request POST 'http://127.0.0.1:8099/config/ftp' \ --header 'Content-Type: application/json' \ --data-raw ' [ "192.168.1.143", "192.168.1.141", "192.168.1.142" ]'
1 2 3 4 5 6 7 8 9 curl --location --request POST 'http://127.0.0.1:8099/config/ftp/status' \ --header 'Content-Type: application/json' \ --data-raw ' [ "192.168.1.143", "192.168.1.141", "192.168.1.142" ] '
提供了 swagger UI ,接口文档,可以直接调用
配置说明 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 server: port: 8099 logging: level: org: springframework.web: info CAMERA: username: "admin" password: "hik12345" FTP: username: "face" password: "face" serverIP: "110.110.110.110" serverPort: 21 enableAnony: 0 custdir: "face" snapshot: dwPicInterval: 4000
部署 当前 SDK , window
下需要把SDK 包和 当前项目 jar 包放到同一级目录, Linux
需放到 /usr/lib/
下面
1 java -jar hikvision-sdk-integration-0.0.1-SNAPSHOT.jar
Docker 方式 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ┌──[root@vms81.liruilongs.github.io]-[~/ftpconfig] └─$ ls Dockerfile hikvision-sdk-integration-0.0.1-SNAPSHOT.jar sdk sdk.tar ┌──[root@vms81.liruilongs.github.io]-[~/ftpconfig] └─$ cat Dockerfile FROM openjdk:8u102-jdk COPY ./hikvision-sdk-integration-0.0.1-SNAPSHOT.jar / ADD ./sdk.tar /usr/lib/ CMD ["java" , "-jar" ,"hikvision-sdk-integration-0.0.1-SNAPSHOT.jar" ] ┌──[root@vms81.liruilongs.github.io]-[~/ftpconfig] └─$
仓库地址: https://hub.docker.com/r/liruilong/hikvision-sdk-config-ftp
1 docker pull liruilong/hikvision-sdk-config-ftp
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 ┌──[root@vms81.liruilongs.github.io]-[~/ftpconfig] └─$ docker run --rm -it -p 8099:8099 hikvision-sdk-config-ftp:latest . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | ' _ | '_| | ' _ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.3) 2023-10-12 17:20:41.184 INFO 1 --- [ main] c.x.h.HikvisionSdkIntegrationApplication : Starting HikvisionSdkIntegrationApplication v0.0.1-SNAPSHOT using Java 1.8.0_102 on bbb649e2e354 with PID 1 (/hikvision-sdk-integration-0.0.1-SNAPSHOT.jar started by root in /) 2023-10-12 17:20:41.186 INFO 1 --- [ main] c.x.h.HikvisionSdkIntegrationApplication : No active profile set, falling back to default profiles: default 2023-10-12 17:20:42.650 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8099 (http) 2023-10-12 17:20:42.669 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2023-10-12 17:20:42.669 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.50] 2023-10-12 17:20:42.764 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext ............. loop[2] find 2 mac and 0 ip 2023-10-12 17:20:44.151 INFO 1 --- [pool-1-thread-1] c.x.h.task.InitSdkTask : ============== InitSDK init success ==================== 2023-10-12 17:21:02.986 INFO 1 --- [nio-8099-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ' dispatcherServlet' 2023-10-12 17:21:02.986 INFO 1 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ' dispatcherServlet' 2023-10-12 17:21:02.988 INFO 1 --- [nio-8099-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms 2023-10-12 17:21:03.243 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : userId=0 2023-10-12 17:21:03.286 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : 获取参数成功 2023-10-12 17:21:03.287 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : =========================== 设备信息 ============================ 2023-10-12 17:21:03.287 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : 设备名称:IP CAMERA 设备序列号:DS-IPC-B12HV2-IA20210812AACHG51171281 2023-10-12 17:21:03.287 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : 设备型号名称:DS-IPC-B12HV2-IA 设备 型号:31 2023-10-12 17:21:03.287 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : 模拟通道个数:1 2023-10-12 17:21:03.289 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : 软件版本号:[firstVersion:5, secondVersion:5, lowVersion:34] 2023-10-12 17:21:03.289 INFO 1 --- [nio-8099-exec-1] c.x.h.controller.ConfigController : 软件生成日期:Build:2021.7.14
海康 SDK 使用 开发手册,动态库下载:
https://open.hikvision.com/download/5cda567cf47ae80dd41a54b3?type=10&id=5cda5902f47ae80dd41a54b7
确定需要调用的动态库功能
通过开发手册
查看对应的宏定义,结构体
定义宏变量,结构体转化
编写需要的功能业务,可以参考官方的 Demo
以 FTP 配置为 Demo:
宏变量
1 2 public static final int NET_DVR_GET_FTPCFG_V40 = 6162 ; public static final int NET_DVR_SET_FTPCFG_V40 = 6163 ;
结构体转化
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 public static class NET_DVR_STRUCTHEAD extends Structure { public short wLength; public byte byVersion ; public byte byRes; } public static class NET_DVR_PICTURE_NAME_EX extends Structure { public byte [] byItemOrder = new byte [PICNAME_MAXITEM]; public byte byDelimiter; public byte [] byPicNamePrefix = new byte [PICNAME_PREFIX]; } public static class STRUCT_SELF_DOMAIN extends Structure { public byte [] szDomain = new byte [64 ]; public byte [] byRes1 = new byte [80 ]; } public static class STRUCT_SELF_IP extends Structure { public NET_DVR_IPADDR struIp = new NET_DVR_IPADDR(); } public static class UNION_SELF_FTPSEVER extends Union { public STRUCT_SELF_DOMAIN struDomain = new STRUCT_SELF_DOMAIN(); public STRUCT_SELF_IP struAddrIP = new STRUCT_SELF_IP(); } public static class NET_DVR_FTPCFG_V40 extends Structure { public NET_DVR_STRUCTHEAD struStruceHead = new NET_DVR_STRUCTHEAD(); public byte byEnableFTP; public byte byProtocolType; public short wFTPPort; public UNION_SELF_FTPSEVER unionServer = new UNION_SELF_FTPSEVER(); public byte [] szUserName = new byte [32 ]; public byte [] szPassWORD = new byte [16 ]; public byte [] szTopCustomDir = new byte [64 ]; public byte [] szSubCustomDir = new byte [64 ]; public byte byDirLevel; public byte byTopDirMode; public byte bySubDirMode; public byte byType; public byte byEnableAnony; public byte byAddresType; public byte byFTPPicType; public byte byPicArchivingInterval; public NET_DVR_PICTURE_NAME_EX struPicNameRule = new NET_DVR_PICTURE_NAME_EX(); public byte byPicNameRuleType; public byte [] byRes = new byte [203 ]; } public static class NET_DVR_FTP_TYPE extends Structure { public byte byType; public byte [] byRes = new byte [3 ]; }
编写功能业务
博文部分内容参考 © 文中涉及参考链接内容版权归原作者所有,如有侵权请告知,这是一个开源项目,如果你认可它,不要吝啬星星哦 :)
https://github.com/LIRUILONGS/Hikvision-sdk-Integration
https://open.hikvision.com/download/5cda567cf47ae80dd41a54b3?type=10&id=5cda5902f47ae80dd41a54b7
https://gitee.com/naylor_personal/ramble-spring-boot/tree/master/hikvision-sdk-integration
© 2018-2023 liruilonger@gmail.com , All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)