Browse Source

youhua

master
4670101279 2 years ago
parent
commit
f50379f22e
  1. 2
      ruoyi-admin/src/main/resources/application.yml
  2. 6
      ruoyi-api/src/main/java/com/ruoyi/api/service/impl/DapingServiceImpl.java
  3. 110
      ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/ApiController.java
  4. 34
      ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraController.java
  5. 14
      ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RtspScreenshotTask.java
  6. 4
      ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraServiceImpl.java
  7. 79
      ruoyi-code/src/main/java/utils/Base64Utils.java
  8. 12
      ruoyi-code/src/main/java/utils/CameraUtil.java
  9. 3
      ruoyi-code/src/main/java/utils/RtspConvert.java
  10. 293
      ruoyi-code/src/main/java/utils/run_device_cfg.java
  11. 2
      sh/closeFFmpeg.sh

2
ruoyi-admin/src/main/resources/application.yml

@ -130,7 +130,7 @@ xss:
urlPatterns: /system/*,/monitor/*,/tool/* urlPatterns: /system/*,/monitor/*,/tool/*
#服务器ip #服务器ip
localip: 192.168.1.7 localip: 172.16.46.58
#公网ip,用于判断视频播放 #公网ip,用于判断视频播放
serverip: 121.40.203.197 serverip: 121.40.203.197
#接入方式 0-主动注册 1-网络 #接入方式 0-主动注册 1-网络

6
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/DapingServiceImpl.java

@ -18,7 +18,11 @@ public class DapingServiceImpl extends ServiceImpl<DapingMapper, WaterPhotoInfo>
*/ */
@Override @Override
public List<WaterPhotoInfo> getStationInfo() { public List<WaterPhotoInfo> getStationInfo() {
return baseMapper.selectStationInfo(); List<WaterPhotoInfo> list = baseMapper.selectStationInfo();
for (WaterPhotoInfo waterPhotoInfo : list) {
waterPhotoInfo.setImgName(waterPhotoInfo.getImgName().replace("\\","/"));
}
return list;
} }
/** /**

110
ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/ApiController.java

@ -1,30 +1,32 @@
package com.ruoyi.code.camera.controller; package com.ruoyi.code.camera.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.code.camera.domain.Camera; import com.ruoyi.code.camera.domain.Camera;
import com.ruoyi.code.camera.domain.CameraNetFtp; import com.ruoyi.code.camera.domain.CameraNetFtp;
import com.ruoyi.code.camera.domain.LogInfo; import com.ruoyi.code.camera.domain.LogInfo;
import com.ruoyi.code.camera.service.ICameraNetFtpService; import com.ruoyi.code.camera.service.ICameraNetFtpService;
import com.ruoyi.code.camera.service.ICameraService; import com.ruoyi.code.camera.service.ICameraService;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.R; import com.ruoyi.common.core.page.R;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.sun.jna.NativeLong; import com.sun.jna.NativeLong;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import sdk.java.lib.netmanager.NetEnums; import sdk.java.lib.netmanager.NetEnums;
import sdk.java.lib.netmanager.NetStructs; import sdk.java.lib.netmanager.NetStructs;
import utils.Base64Utils;
import utils.CameraUtil; import utils.CameraUtil;
import utils.RegisterUtil;
import utils.run_device_cfg; import utils.run_device_cfg;
import utils.run_device_log_search; import utils.run_device_log_search;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
/** /**
@ -220,4 +222,100 @@ public class ApiController extends BaseController
cameraService.pullRtspPhoto(); cameraService.pullRtspPhoto();
return R.ok(); return R.ok();
} }
private final SimpleDateFormat sdf_pic = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
private final SimpleDateFormat sdf_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final SimpleDateFormat sdf_date = new SimpleDateFormat("yyyy-MM-dd");
@RequestMapping("/getPicJson")
public R getPicJson(@RequestParam Map<String, Object> params) throws Exception {
System.out.println("===================================");
if(params.containsKey("json")){
String serialNo = (String) params.get("SerialNo");
String json = (String) params.get("json");
String picture = (String) params.get("picture");
System.out.println("图片进来了");
System.out.println("serialNo="+serialNo);
JSONObject object = JSON.parseObject(json);
String timestamp_str = object.getJSONArray("Events").getJSONObject(0).getString("Timestamp");
long times = Long.parseLong(timestamp_str);
Date date = new Date(times * 1000);
String pic_date = sdf_date.format(date);
//图片名称 new_2022_10_13_13_15_00_序列号.jpg
String pic_name = "new_"+getPicName(date)+"_"+serialNo+".jpg";
//保存路径
String path = RuoYiConfig.getProfile() + File.separator+"upload"+File.separator+"myftp"+File.separator+ serialNo + File.separator + pic_date + File.separator;
File file = new File(path);
//判断是否需要创建文件夹
if (!file.exists()) {
file.mkdirs();
}
boolean r = Base64Utils.GenerateImage(picture,path+pic_name);
System.out.println("图片保存结果为"+r);
}
return R.ok();
}
public String getPicName(Date date) throws ParseException {
List<String> arr = Arrays.asList("4","9");
String datetime_str = sdf_time.format(date);
String newDatetimeStr = datetime_str.substring(0,16)+":00";
Date newDate = DateUtils.parseDate(newDatetimeStr,"yyyy-MM-dd HH:mm:ss");
//m 分的末位
String m = newDatetimeStr.substring(15,16);
if(arr.contains(m)){
return sdf_pic.format(DateUtils.addMinutes(newDate,1));
}
return sdf_pic.format(newDate);
}
@RequestMapping("/addHttpCfg")
public R addHttpCfg(Long id){
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong loginID = new NativeLong(Long.parseLong(camera.getLoginId()));
cfg.addHttpCfg(loginID,"121.40.203.197");
return R.ok();
}
@RequestMapping("/getHttpCfg")
public R getHttpCfg(Long id){
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong loginID = new NativeLong(Long.parseLong(camera.getLoginId()));
cfg.getHttpCfg(loginID);
return R.ok();
}
@RequestMapping("/setHttpReverseRegister")
public R setHttpReverseRegister(Long id){
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong loginID = new NativeLong(Long.parseLong(camera.getLoginId()));
cfg.initHttpReverseRegister(loginID);
return R.ok();
}
@RequestMapping("/getHttpReverseRegister")
public R getHttpReverseRegister(Long id){
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong loginID = new NativeLong(Long.parseLong(camera.getLoginId()));
Map<String, Object> map = cfg.getHttpReverseRegister(loginID);
return R.ok().put("data",map);
}
@RequestMapping("/clearHttpReverseRegister")
public R clearHttpReverseRegister(Long id){
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong loginID = new NativeLong(Long.parseLong(camera.getLoginId()));
Map<String, Object> map = cfg.clearHttpReverseRegister(loginID);
return R.ok().put("data",map);
}
} }

34
ruoyi-code/src/main/java/com/ruoyi/code/camera/controller/CameraController.java

@ -269,9 +269,9 @@ public class CameraController extends BaseController
return R.ok(); return R.ok();
} }
@RequestMapping("/resetPullRtsp") @RequestMapping("/retartPullM3u8")
public R resetPullRtsp(){ public R retartPullM3u8(){
List<Camera> list = cameraService.list(new QueryWrapper<Camera>().eq("status","0").isNotNull("login_id").ne("login","")); List<Camera> list = cameraService.list(new QueryWrapper<Camera>().eq("access_type","1").eq("status","1"));
if(list.isEmpty()){ if(list.isEmpty()){
return R.error("设备未在线"); return R.error("设备未在线");
} }
@ -280,13 +280,37 @@ public class CameraController extends BaseController
for (Camera camera : list) { for (Camera camera : list) {
try { try {
String m3u8 = convert.rtsp2Hls(camera.getIp(), camera.getUsername(), camera.getPassword()); String m3u8 = convert.rtsp2Hls(camera.getIp(), camera.getUsername(), camera.getPassword());
System.out.println("拉流成功,地址:" + m3u8); System.out.println(camera.getIp() +" m3u8 = " + m3u8);
Thread.sleep(2000); Thread.sleep(2000);
} catch (Exception e) { } catch (Exception e) {
logger.error(camera.getIp() + "拉流失败");
logger.error(e.getMessage()); logger.error(e.getMessage());
return R.error("重启失败");
} }
} }
return R.ok(); return R.ok();
} }
@RequestMapping("/getHttpReverseRegister/{id}")
public R getHttpReverseRegister(@PathVariable("id") Long id){
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong loginID = new NativeLong(Long.parseLong(camera.getLoginId()));
Map<String,Object> map = cfg.getHttpReverseRegister(loginID);
return R.ok().put("data",map);
}
@RequestMapping("/setHttpReverseRegister")
public R setHttpReverseRegister(@RequestBody Map<String,Object> params){
Integer id = (Integer) params.get("id");
int bEnable = Integer.parseInt((String) params.get("bEnable"));
String heartUrl = (String) params.get("heartUrl");
String pushPicUrl = (String) params.get("pushPicUrl");
int heartbeatInterval = (Integer) params.get("heartbeatInterval");
Camera camera = cameraService.getById(id);
run_device_cfg cfg = new run_device_cfg();
NativeLong nativeID = new NativeLong(Long.parseLong(camera.getLoginId()));
return cfg.setHttpReverseRegister(nativeID, bEnable, heartUrl, pushPicUrl, heartbeatInterval);
}
} }

14
ruoyi-code/src/main/java/com/ruoyi/code/camera/scheduled/RtspScreenshotTask.java

@ -3,20 +3,34 @@ package com.ruoyi.code.camera.scheduled;
import com.ruoyi.code.camera.service.ICameraService; import com.ruoyi.code.camera.service.ICameraService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component @Component
@Configuration @Configuration
@EnableScheduling @EnableScheduling
public class RtspScreenshotTask { public class RtspScreenshotTask {
private static String accessmode = "";
@Autowired
private Environment env;
@PostConstruct
public void config() {
accessmode = env.getProperty("accessmode");
}
@Autowired @Autowired
private ICameraService cameraService; private ICameraService cameraService;
@Scheduled(cron = "0 0/5 * * * ?") @Scheduled(cron = "0 0/5 * * * ?")
public void rtspScreenshot(){ public void rtspScreenshot(){
if("1".equals(accessmode)){
cameraService.pullRtspPhoto(); cameraService.pullRtspPhoto();
} }
} }
}

4
ruoyi-code/src/main/java/com/ruoyi/code/camera/service/impl/CameraServiceImpl.java

@ -158,7 +158,7 @@ public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> impleme
@Override @Override
public void pullRtspPhoto(){ public void pullRtspPhoto(){
String path = RuoYiConfig.getProfile() + File.separator; String path = RuoYiConfig.getProfile() + File.separator+"upload"+File.separator+"myftp"+File.separator;
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + File.separator; String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + File.separator;
String currentTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) + ".jpg"; String currentTime = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) + ".jpg";
List<Camera> list = list(new QueryWrapper<Camera>().eq("access_type","1")); List<Camera> list = list(new QueryWrapper<Camera>().eq("access_type","1"));
@ -173,7 +173,7 @@ public class CameraServiceImpl extends ServiceImpl<CameraMapper, Camera> impleme
if (!file.exists()) { if (!file.exists()) {
file.mkdirs(); file.mkdirs();
} }
String ffmpeg = "ffmpeg -i rtsp://"+camera.getUsername()+":"+camera.getPassword()+"@"+camera.getIp()+cameraBrand.getRtsp()+" -y -f image2 -t 0.001 "+fileName+currentTime+""; String ffmpeg = "ffmpeg -i rtsp://"+camera.getUsername()+":"+camera.getPassword()+"@"+camera.getIp()+cameraBrand.getRtsp()+" -y -f image2 -t 0.02 "+fileName+ camera.getDevsn() + "_"+currentTime+"";
System.out.println("ffmpeg="+ffmpeg); System.out.println("ffmpeg="+ffmpeg);
RuntimeUtil.execForStr(ffmpeg); RuntimeUtil.execForStr(ffmpeg);

79
ruoyi-code/src/main/java/utils/Base64Utils.java

@ -0,0 +1,79 @@
package utils;
import org.apache.commons.codec.binary.Base64;
import java.io.*;
public class Base64Utils {
/**
* 图片转化成base64字符串
*
* @param imgPath
* @return
*/
public static String GetImageStr(String imgPath) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
String imgFile = imgPath;// 待处理的图片
InputStream in = null;
byte[] data = null;
String encode = null; // 返回Base64编码过的字节数组字符串
// 对字节数组Base64编码
Base64 encoder = new Base64();
try {
// 读取图片字节数组
in = new FileInputStream(imgFile);
data = new byte[in.available()];
in.read(data);
encode = encoder.encodeToString(data);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return encode;
}
/**
* base64字符串转化成图片
*
* @param imgData 图片编码
* @param imgFilePath 存放到本地路径
* @return
* @throws IOException
*/
@SuppressWarnings("finally")
public static boolean GenerateImage(String imgData, String imgFilePath) throws IOException { // 对字节数组字符串进行Base64解码并生成图片
if (imgData == null) // 图像数据为空
return false;
Base64 decoder = new Base64();
OutputStream out = null;
try {
out = new FileOutputStream(imgFilePath);
// Base64解码
byte[] b = decoder.decode(imgData);
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {// 调整异常数据
b[i] += 256;
}
}
out.write(b);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
out.flush();
out.close();
return true;
}
}
}

12
ruoyi-code/src/main/java/utils/CameraUtil.java

@ -15,7 +15,7 @@ public class CameraUtil {
NetLib.instance.Net_Init(null, null); NetLib.instance.Net_Init(null, null);
String strIp="192.168.1.64"; String strIp="192.168.1.40";
int nPort= 27778; int nPort= 27778;
String strUsername="admin"; String strUsername="admin";
String strPassword="admin123"; String strPassword="admin123";
@ -26,13 +26,19 @@ public class CameraUtil {
System.out.println("loginID = "+loginID); System.out.println("loginID = "+loginID);
run_device_cfg cfg = new run_device_cfg(); run_device_cfg cfg = new run_device_cfg();
Map<String, Object> ligntCfg = cfg.getLigntCfg(loginID); Map<String, Object> map = cfg.getAutoRegister(loginID);
System.out.println(JSON.toJSON(ligntCfg).toString()); // System.out.println(JSON.toJSON(map));
// cfg.setAutoRegister(loginID,1,"121.40.203.197",8020);
// System.out.println("----------------------------------");
// cfg.getAutoRegister(loginID);
System.out.println("=================================="); System.out.println("==================================");
//设置参数 //设置参数
// cfg.setLightCfg(loginID, NetEnums.EM_DEV_SUP_LIGHT_MODE.EM_DEV_SUP_LIGHT_MODE_FORCE_AUTO,30,60,"13:50:00","14:00:00"); // cfg.setLightCfg(loginID, NetEnums.EM_DEV_SUP_LIGHT_MODE.EM_DEV_SUP_LIGHT_MODE_FORCE_AUTO,30,60,"13:50:00","14:00:00");
// System.out.println("=================================="); // System.out.println("==================================");
// cfg.getLigntCfg(loginID); // cfg.getLigntCfg(loginID);
} }
/** /**

3
ruoyi-code/src/main/java/utils/RtspConvert.java

@ -63,6 +63,7 @@ public class RtspConvert {
/** /**
* 转换rtsp并获取hls文件路径 * 转换rtsp并获取hls文件路径
* 视频地址 http.../control-api/upload/hls/{ip}/live.m3u8
*/ */
public String rtsp2Hls(String ip, String userName, String pwd) { public String rtsp2Hls(String ip, String userName, String pwd) {
System.out.println(JSON.toJSON(coverMap)); System.out.println(JSON.toJSON(coverMap));
@ -74,7 +75,7 @@ public class RtspConvert {
} }
} }
String rtspUrl = "rtsp://" + userName + ":" + pwd + "@" + ip + ":554/stream/realtime?channel=1&streamtype=0"; String rtspUrl = "rtsp://" + userName + ":" + pwd + "@" + ip + ":554/stream/realtime?channel=1&streamtype=0";
String m3u8File = RuoYiConfig.getProfile() + File.separator + "hls" String m3u8File = RuoYiConfig.getProfile() + File.separator+"upload" + File.separator + "hls"
// String m3u8File = "D:" + File.separator + "ruoyi" + File.separator + "uploadPath" + File.separator + "hls" // String m3u8File = "D:" + File.separator + "ruoyi" + File.separator + "uploadPath" + File.separator + "hls"
+ File.separator + ip.replaceAll("\\.", "_") + File.separator + "live.m3u8"; + File.separator + ip.replaceAll("\\.", "_") + File.separator + "live.m3u8";
startTransform(ip, rtspUrl, m3u8File, userName, pwd); startTransform(ip, rtspUrl, m3u8File, userName, pwd);

293
ruoyi-code/src/main/java/utils/run_device_cfg.java

@ -601,8 +601,15 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
}else if(EM_DEVICE_CFG_TYPE.DEVICE_CFG_SOC_CONSTANT_LAMP == command) }else if(EM_DEVICE_CFG_TYPE.DEVICE_CFG_SOC_CONSTANT_LAMP == command)
{ {
stu = new NetStructs.STU_CFG_SOC_CONSTANT_LAMP_PARAM(); stu = new NetStructs.STU_CFG_SOC_CONSTANT_LAMP_PARAM();
}else if(EM_DEVICE_CFG_TYPE.DEVICE_CFG_HTTP_REVERSE_REGISTER == command)
{
stu = new NetStructs.STU_CFG_HTTP_REGISTER_PARAM();
}else if(EM_DEVICE_CFG_TYPE.DEVICE_CFG_AUTO_REGISTER == command)
{
stu = new NetStructs.STU_CFG_AUTO_REGISTER_PARAM();
} }
return stu; return stu;
} }
@ -3770,6 +3777,70 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
return ftpCfg; return ftpCfg;
} }
public void getHttpCfg(NativeLong loginID){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_NET_STORAGE_TRANS;
STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans = getStuCfgNetStorageTrans(loginID,nCommand);
System.out.println("======================");
System.out.println("count="+stuCfgNetStorageTrans.uItemCount);
for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++)
{
STU_CFG_NET_STORAGE_TRANS_ITEM stuItem = stuCfgNetStorageTrans.stuItemArray[i];
String ftpValue = DataUtils.sdk_data_byteArrayToString(stuItem.szProtocol, GlobalTool.getEncodeType());
System.out.println("-----------------------");
System.out.println("name="+ftpValue);
System.out.println("bOfflineEnable="+stuItem.bOfflineEnable);
System.out.println("address="+DataUtils.sdk_data_byteArrayToString(stuItem.szAddress, GlobalTool.getEncodeType()));
}
}
public void addHttpCfg(NativeLong loginID,String szAddress){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_NET_STORAGE_TRANS;
STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans = getStuCfgNetStorageTrans(loginID,nCommand);
System.out.println("========== addHttpCfg ============");
System.out.println(JSON.toJSON(stuCfgNetStorageTrans));
System.out.println("======================");
boolean flag = false;
for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++)
{
STU_CFG_NET_STORAGE_TRANS_ITEM stuItem = stuCfgNetStorageTrans.stuItemArray[i];
String ftpValue = DataUtils.sdk_data_byteArrayToString(stuItem.szProtocol, GlobalTool.getEncodeType());
if("HttpClient".equalsIgnoreCase(ftpValue)){
flag = true;
stuCfgNetStorageTrans.stuItemArray[i].szAddress = DataUtils.sdk_data_stringToByteArray(szAddress, GlobalTool.getEncodeType());
stuCfgNetStorageTrans.stuItemArray[i].bOfflineEnable = 1;
}
}
if(!flag){
STU_CFG_NET_STORAGE_TRANS_ITEM httpCfg = new STU_CFG_NET_STORAGE_TRANS_ITEM();
httpCfg.szProtocol = DataUtils.sdk_data_stringToByteArray("HttpClient", GlobalTool.getEncodeType());
httpCfg.szAddress = DataUtils.sdk_data_stringToByteArray(szAddress, GlobalTool.getEncodeType());
httpCfg.bOfflineEnable = 1;
stuCfgNetStorageTrans.uItemCount = stuCfgNetStorageTrans.uItemCount + 1;
stuCfgNetStorageTrans.stuItemArray[stuCfgNetStorageTrans.uItemCount] = httpCfg;
}
IntByReference inBufferSize = new IntByReference(0);
inBufferSize.setValue(stuCfgNetStorageTrans.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
DataUtils.sdk_data_structureToPtr(stuCfgNetStorageTrans, ptrInBuffer, 0);
boolean bResult2 = NetLib.instance.Net_SetDeviceCfg(
loginID,
nCommand,
0,
ptrInBuffer,
inBufferSize.getValue(),
6000);
if(!bResult2)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_setAutoRegister fail, command = %d, errorCode = %d", nCommand, error);
System.out.println("修改失败");
System.out.println(strError);
}
System.out.println("执行结束");
}
//获取自动重启配置 //获取自动重启配置
public STU_CFG_AUTO_MAINTAIN getAutoCfg(NativeLong loginID ,int nCommand){ public STU_CFG_AUTO_MAINTAIN getAutoCfg(NativeLong loginID ,int nCommand){
@ -3846,4 +3917,226 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
System.out.println(stuCfgAutoMaintain); System.out.println(stuCfgAutoMaintain);
return R.ok(); return R.ok();
} }
public Map<String, Object> getHttpReverseRegister(NativeLong loginID){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_HTTP_REVERSE_REGISTER;
NetStructs.STU_CFG_HTTP_REGISTER_PARAM cfg = getCfgHttpReverseRegister(loginID,nCommand);
System.out.println(JSON.toJSON(cfg));
// 0:禁用,1:启用
int bEnable = cfg.bEnable;
//心跳地址
String heartUrl = DataUtils.sdk_data_byteArrayToString(cfg.szMessageURL, GlobalTool.getEncodeType());
//推图地址
String pushPicUrl = DataUtils.sdk_data_byteArrayToString(cfg.szPushPictureURL, GlobalTool.getEncodeType());
//心跳间隔,单位秒
int heartbeatInterval = cfg.nHeartbeatInterval;
Map<String, Object> map = new HashMap<>();
map.put("bEnable",bEnable);
map.put("heartUrl",heartUrl);
map.put("pushPicUrl",pushPicUrl);
map.put("heartbeatInterval",heartbeatInterval);
return map;
}
public R setHttpReverseRegister(NativeLong loginID,int bEnable,String heartUrl,String pushPicUrl,int heartbeatInterval){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_HTTP_REVERSE_REGISTER;
NetStructs.STU_CFG_HTTP_REGISTER_PARAM cfg = getCfgHttpReverseRegister(loginID,nCommand);
cfg.bEnable = bEnable;
cfg.szMessageURL = DataUtils.sdk_data_stringToByteArray(heartUrl, GlobalTool.getEncodeType());;
cfg.szPushPictureURL = DataUtils.sdk_data_stringToByteArray(pushPicUrl, GlobalTool.getEncodeType());;
cfg.nHeartbeatInterval = heartbeatInterval;
IntByReference inBufferSize = new IntByReference(0);
inBufferSize.setValue(cfg.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
DataUtils.sdk_data_structureToPtr(cfg, ptrInBuffer, 0);
boolean bResult2 = NetLib.instance.Net_SetDeviceCfg(
loginID,
nCommand,
0,
ptrInBuffer,
inBufferSize.getValue(),
6000);
if(!bResult2)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_setHttpReverseRegister fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return R.error(500,strError);
}
return R.ok();
}
public R initHttpReverseRegister(NativeLong loginID){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_HTTP_REVERSE_REGISTER;
NetStructs.STU_CFG_HTTP_REGISTER_PARAM cfg = getCfgHttpReverseRegister(loginID,nCommand);
cfg.bEnable = 1;
cfg.szMessageURL = DataUtils.sdk_data_stringToByteArray("http://121.40.203.197/control-api/api/camera/heart", GlobalTool.getEncodeType());;
cfg.szPushPictureURL = DataUtils.sdk_data_stringToByteArray("http://121.40.203.197/control-api/api/getPicJson", GlobalTool.getEncodeType());;
cfg.nHeartbeatInterval = 50;
IntByReference inBufferSize = new IntByReference(0);
inBufferSize.setValue(cfg.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
DataUtils.sdk_data_structureToPtr(cfg, ptrInBuffer, 0);
boolean bResult2 = NetLib.instance.Net_SetDeviceCfg(
loginID,
nCommand,
0,
ptrInBuffer,
inBufferSize.getValue(),
6000);
if(!bResult2)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_setHttpReverseRegister fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return R.error(500,strError);
}
return R.ok();
}
public R clearHttpReverseRegister(NativeLong loginID){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_HTTP_REVERSE_REGISTER;
NetStructs.STU_CFG_HTTP_REGISTER_PARAM cfg = getCfgHttpReverseRegister(loginID,nCommand);
cfg.bEnable = 1;
cfg.szMessageURL = new byte[256];;
cfg.szPushPictureURL = new byte[256];
cfg.nHeartbeatInterval = 50;
IntByReference inBufferSize = new IntByReference(0);
inBufferSize.setValue(cfg.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
DataUtils.sdk_data_structureToPtr(cfg, ptrInBuffer, 0);
boolean bResult2 = NetLib.instance.Net_SetDeviceCfg(
loginID,
nCommand,
0,
ptrInBuffer,
inBufferSize.getValue(),
6000);
if(!bResult2)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_setHttpReverseRegister fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return R.error(500,strError);
}
return R.ok();
}
public NetStructs.STU_CFG_HTTP_REGISTER_PARAM getCfgHttpReverseRegister(NativeLong loginID, int nCommand){
IntByReference outBufferSize = new IntByReference(0);
IntByReference nReturnSize = new IntByReference(0);
Pointer ptrOutBuffer = initStuData(nCommand, outBufferSize);
boolean bResult = NetLib.instance.Net_GetDeviceCfg(
loginID,
nCommand,
0,
ptrOutBuffer,
outBufferSize.getValue(),
nReturnSize,
6000);
if(!bResult)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_HttpReverseRegisterCfg fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return null;
}
NetStructs.STU_CFG_HTTP_REGISTER_PARAM cfg = new NetStructs.STU_CFG_HTTP_REGISTER_PARAM();
DataUtils.sdk_data_ptrToStructure(ptrOutBuffer, cfg);
return cfg;
}
public Map<String, Object> getAutoRegister(NativeLong loginID){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_AUTO_REGISTER;
STU_CFG_AUTO_REGISTER_PARAM cfg = getAutoRegister(loginID,nCommand);
System.out.println(JSON.toJSON(cfg));
// 0:禁用,1:启用
// int bEnable = cfg.bEnable;
// //服务器地址
// String serverAddress = DataUtils.sdk_data_byteArrayToString(cfg.szServerAddress, GlobalTool.getEncodeType());
// //端口号
// int port = cfg.nPort;
// Map<String, Object> map = new HashMap<>();
// map.put("bEnable",bEnable);
// map.put("serverAddress",serverAddress);
// map.put("port",port);
// return map;
return null;
}
public R setAutoRegister(NativeLong loginID,int bEnable,String serverAddress,int port){
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_AUTO_REGISTER;
NetStructs.STU_CFG_AUTO_REGISTER_PARAM cfg = getAutoRegister(loginID,nCommand);
cfg.bEnable = bEnable;
cfg.szServerAddress = DataUtils.sdk_data_stringToByteArray(serverAddress, GlobalTool.getEncodeType());;
cfg.nPort = port;
IntByReference inBufferSize = new IntByReference(0);
inBufferSize.setValue(cfg.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
DataUtils.sdk_data_structureToPtr(cfg, ptrInBuffer, 0);
boolean bResult2 = NetLib.instance.Net_SetDeviceCfg(
loginID,
nCommand,
0,
ptrInBuffer,
inBufferSize.getValue(),
6000);
if(!bResult2)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_setAutoRegister fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return R.error(500,strError);
}
return R.ok();
}
public STU_CFG_AUTO_REGISTER_PARAM getAutoRegister(NativeLong loginID, int nCommand){
IntByReference outBufferSize = new IntByReference(0);
IntByReference nReturnSize = new IntByReference(0);
Pointer ptrOutBuffer = initStuData(nCommand, outBufferSize);
boolean bResult = NetLib.instance.Net_GetDeviceCfg(
loginID,
nCommand,
0,
ptrOutBuffer,
outBufferSize.getValue(),
nReturnSize,
6000);
if(!bResult)
{
int error = NetLib.instance.Net_LastError();
String strError = String.format("Net_AutoRegisterCfg fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return null;
}
STU_CFG_AUTO_REGISTER_PARAM cfg = new STU_CFG_AUTO_REGISTER_PARAM();
DataUtils.sdk_data_ptrToStructure(ptrOutBuffer, cfg);
return cfg;
}
} }

2
sh/closeFFmpeg.sh

@ -0,0 +1,2 @@
#!/bin/sh
ps -ef | grep ffmpeg | grep -v grep | awk {'print $2'} | xargs kill -9
Loading…
Cancel
Save