package utils; import com.alibaba.fastjson.JSON; import com.ruoyi.common.utils.DateUtils; import com.sun.jna.NativeLong; import com.sun.jna.ptr.IntByReference; import sdk.java.lib.netmanager.NetLib; import sdk.java.lib.netmanager.NetStructs; import java.util.Date; import java.util.Map; public class CameraUtil { public static void main(String[] args) { NetLib.instance.Net_Init(null, null); String strIp="192.168.1.40"; int nPort= 27778; String strUsername="admin"; String strPassword="admin123"; String strDevSN="8R23R300003"; IntByReference nError = new IntByReference(0); NativeLong loginID = NetLib.instance.Net_LoginDevice(strIp, nPort, strUsername, strPassword, null, nError); System.out.println("loginID = "+loginID); run_device_cfg cfg = new run_device_cfg(); Map map = cfg.getAutoRegister(loginID); // System.out.println(JSON.toJSON(map)); // cfg.setAutoRegister(loginID,1,"121.40.203.197",8020); // System.out.println("----------------------------------"); // cfg.getAutoRegister(loginID); 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"); // System.out.println("=================================="); // cfg.getLigntCfg(loginID); } /** * 重启设备 */ public static boolean deal(NativeLong loginID){ boolean res = NetLib.instance.Net_RebootDevice(loginID); int error = NetLib.instance.Net_LastError(); System.out.println("reboot errorCode = "+ error); return res; } /** * 获取4G信号强度 */ public static int get4gRssiLevel(NativeLong loginID){ NetStructs.STU_GET_4G_RSSI_IN_PARAM.ByReference pstInParam = new NetStructs.STU_GET_4G_RSSI_IN_PARAM.ByReference(); NetStructs.STU_GET_4G_RSSI_OUT_PARAM.ByReference pstOutParam = new NetStructs.STU_GET_4G_RSSI_OUT_PARAM.ByReference(); boolean res = NetLib.instance.Net_GetDevice4GRSSI(loginID,pstInParam, pstOutParam,6000); int level = 0; if(res){ // System.out.println(JSON.toJSONString(pstOutParam)); // System.out.println("4G信号强度:"+pstOutParam.nRssiLevel); level = pstOutParam.nRssiLevel; } return level; } private static void sleep(int nTime) { try { Thread.sleep(nTime * 1000); } catch (InterruptedException e) { e.printStackTrace(); } } /** * 设置当前时间 * @param loginID */ public static void setNowTime(NativeLong loginID){ NetStructs.STU_TIME.ByReference stuTimeRef = new NetStructs.STU_TIME.ByReference(); boolean bGet = NetLib.instance.Net_GetDeviceTime(loginID, stuTimeRef, 6000); System.out.printf("Get time = %b, time = %04d-%02d-%02d %02d:%02d:%02d\n", bGet, stuTimeRef.nYear, stuTimeRef.nMonth, stuTimeRef.nDay, stuTimeRef.nHour, stuTimeRef.nMinute, stuTimeRef.nSecond); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } String time = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",new Date()); // 修改时间 stuTimeRef.nYear = Integer.parseInt(time.substring(0,4)); stuTimeRef.nMonth = Integer.parseInt(time.substring(5,7)); stuTimeRef.nDay = Integer.parseInt(time.substring(8,10)); stuTimeRef.nHour = Integer.parseInt(time.substring(11,13)); stuTimeRef.nMinute = Integer.parseInt(time.substring(14,16)); stuTimeRef.nSecond = Integer.parseInt(time.substring(17,19)); System.out.println("Set time, time"+ stuTimeRef.nYear+"-"+ stuTimeRef.nMonth+"-"+ stuTimeRef.nDay+" "+ stuTimeRef.nHour+":"+ stuTimeRef.nMinute+":"+stuTimeRef.nSecond); NetLib.instance.Net_SetDeviceTime(loginID, stuTimeRef, 2000); // 再获取时间 bGet = NetLib.instance.Net_GetDeviceTime(loginID, stuTimeRef, 2000); System.out.println("Get time = %b, time =" + stuTimeRef.nYear+"-"+ stuTimeRef.nMonth+"-"+ stuTimeRef.nDay+" "+ stuTimeRef.nHour+":"+ stuTimeRef.nMinute+":"+stuTimeRef.nSecond); } }