Browse Source

摄像机配置

platform-api
4670101279 2 years ago
parent
commit
8fb6bcd7c5
  1. 29
      ruoyi-code/src/main/java/utils/CameraUtil.java
  2. 196
      ruoyi-code/src/main/java/utils/run_device_cfg.java

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

@ -12,34 +12,11 @@ import java.util.Date;
public class CameraUtil { public class CameraUtil {
public static void main(String[] args) { public static void main(String[] args) {
NetLib.instance.Net_Init(null, null); // NetLib.instance.Net_Init(null, null);
String strIp="36.134.51.220";
int nPort= 16754;
String strUsername="admin";
String strPassword="admin123";
String strDevSN="8R23R300003";
IntByReference nErr = new IntByReference(0); run_device_cfg cfg = new run_device_cfg();
cfg.startCfg();
// 此接口专为 主动注册登陆 接口,与 Net_LoginDevice 有区别
NativeLong lLoginID = NetLib.instance.Net_LoginDeviceSpec(
strIp,
nPort,
strUsername,
strPassword,
NetEnums.EM_LOGIN_PROTOCAL_TYPE.EM_LOGIN_PROTOCAL_TYPE_REG_SERVER,
strDevSN,
null,
nErr);
System.out.println(lLoginID);
//重启设备
// boolean bResult = NetLib.instance.Net_RebootDevice(loginID);
// System.out.println("Net_RebootDevice = " + bResult);
// boolean r2 = NetLib.instance.Net_LogoutDevice(loginID);
// System.out.println("r2 = " + r2);
// NetLib.instance.Net_Exit();
} }
public static boolean deal(NativeLong loginID){ public static boolean deal(NativeLong loginID){

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

@ -2637,25 +2637,23 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
int nNewValue = (stuCfgNetStorageTrans.stuItemArray[0].bOfflineEnable + 1) % 2; int nNewValue = (stuCfgNetStorageTrans.stuItemArray[0].bOfflineEnable + 1) % 2;
stuCfgNetStorageTrans.stuItemArray[0].bOfflineEnable = nNewValue; stuCfgNetStorageTrans.stuItemArray[0].bOfflineEnable = nNewValue;
/*
for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++)
{
String strProtocol = DataUtils.ry_data_byteArrayToString(stuCfgNetStorageTrans.stuItemArray[i].szProtocol, GlobalTool.getEncodeType());
if(0 == strProtocol.compareTo("Ftp"))
{
int nNewValue = (stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.bRealtimeEnable + 1) % 2;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.bRealtimeEnable = nNewValue;
}
}
*/
}
for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++) // if(0 < stuCfgNetStorageTrans.uItemCount)
{ // {
System.out.println(JSON.toJSON(stuCfgNetStorageTrans.stuItemArray[i]).toString()); // for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++)
String name = DataUtils.sdk_data_byteArrayToString(stuCfgNetStorageTrans.stuItemArray[i].szProtocol,GlobalTool.getEncodeType()); // {
System.out.println(name); // String name = DataUtils.sdk_data_byteArrayToString(stuCfgNetStorageTrans.stuItemArray[i].szProtocol,GlobalTool.getEncodeType());
// if("ftp".equalsIgnoreCase(name)){
// System.out.println(JSON.toJSON(stuCfgNetStorageTrans.stuItemArray[i]).toString());
// stuCfgNetStorageTrans.stuItemArray[i].szAddress = getNewArray(64,DataUtils.sdk_data_stringToByteArray("1.1.1.1",GlobalTool.getEncodeType()));
// stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.szUserName = getNewArray(64,DataUtils.sdk_data_stringToByteArray("test",GlobalTool.getEncodeType()));
// stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.szPassword = getNewArray(64,DataUtils.sdk_data_stringToByteArray("test123",GlobalTool.getEncodeType()));
// }
// }
//
// }
} }
/* /*
* *
* *
@ -2664,11 +2662,27 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
inBufferSize.setValue(stuCfgNetStorageTrans.size()); inBufferSize.setValue(stuCfgNetStorageTrans.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue()); Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
System.out.println("stuCfgNetStorageTrans");
System.out.println(JSON.toJSON(stuCfgNetStorageTrans).toString());
DataUtils.sdk_data_structureToPtr(stuCfgNetStorageTrans, ptrInBuffer, 0); DataUtils.sdk_data_structureToPtr(stuCfgNetStorageTrans, ptrInBuffer, 0);
return ptrInBuffer; return ptrInBuffer;
} }
private byte[] getNewArray(int length,byte[] newArr){
byte[] arr = new byte[length];
for (int i = 0; i < length; i++) {
if(newArr.length >= i+1){
arr[i] = newArr[i];
}else {
arr[i] = 0;
}
}
return arr;
}
private Pointer createStuCfgStorage(IntByReference inBufferSize) private Pointer createStuCfgStorage(IntByReference inBufferSize)
{ {
STU_CFG_STORAGE stuCfgStorage = (STU_CFG_STORAGE) m_curStuObj; STU_CFG_STORAGE stuCfgStorage = (STU_CFG_STORAGE) m_curStuObj;
@ -3328,6 +3342,8 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
if(null == ptrInBuffer) if(null == ptrInBuffer)
return false; return false;
System.out.println("ptrInBuffer="+JSON.toJSON(ptrInBuffer).toString());
System.out.println("inBufferSize="+ inBufferSize.getValue());
boolean bResult = NetLib.instance.Net_SetDeviceCfg( boolean bResult = NetLib.instance.Net_SetDeviceCfg(
m_loginID, m_loginID,
nCommand, nCommand,
@ -3473,4 +3489,150 @@ public class run_device_cfg implements ActionListener, ListSelectionListener {
} }
}); });
} }
//////////////////////////////////////////////////////////
public void startCfg(){
String strIp="192.168.1.64";
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);
//bRealtimeEnable为0时 bOfflineEnable只能为0
int bRealtimeEnable = 0;
int bOfflineEnable = 0;
String szAddress = "192.168.1.1";
int uFtpPort = 22;
String szUserName = "test";
String szPassword = "test123";
boolean result = setDeviceFtpCfg(loginID, bRealtimeEnable, bOfflineEnable, szAddress, uFtpPort, szUserName, szPassword);
System.out.println("result = " + result);
}
/**
*
* @param bRealtimeEnable 使能 0- 1-
* @param szAddress 服务地址
* @param bOfflineEnable 断网续传 0- 1-
* @param uFtpPort 端口
* @param szUserName 用户名
* @param szPassword 密码
* @return
*/
public boolean setDeviceFtpCfg(NativeLong loginID, int bRealtimeEnable,int bOfflineEnable,String szAddress,int uFtpPort,String szUserName,String szPassword){
//上传图片路径规则
String szPathRule = "/%n/%Y/%M/%D/%Y_%M_%D_%h_%m_%s.jpg";
byte[] szPathRuleBytes = getNewArray(160,DataUtils.sdk_data_stringToByteArray(szPathRule,GlobalTool.getEncodeType()));
//路径编码类型
int emPathEncodeType = 0;
byte[] szAddressBytes = getNewArray(64,DataUtils.sdk_data_stringToByteArray(szAddress,GlobalTool.getEncodeType()));
byte[] szUserNameBytes = getNewArray(64,DataUtils.sdk_data_stringToByteArray(szUserName,GlobalTool.getEncodeType()));
byte[] szPasswordBytes = getNewArray(64,DataUtils.sdk_data_stringToByteArray(szPassword,GlobalTool.getEncodeType()));
// 句柄 - 网络存储传输配置
int nCommand = EM_DEVICE_CFG_TYPE.DEVICE_CFG_NET_STORAGE_TRANS;
STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans = getStuCfgNetStorageTrans(loginID,nCommand);
IntByReference inBufferSize = new IntByReference(0);
Pointer ptrInBuffer = getDeviceCfgPointer(stuCfgNetStorageTrans,inBufferSize,bRealtimeEnable,bOfflineEnable,szAddressBytes,uFtpPort,szUserNameBytes,szPasswordBytes,szPathRuleBytes,emPathEncodeType);
if(null == ptrInBuffer)
return false;
System.out.println("ptrInBuffer="+JSON.toJSON(ptrInBuffer).toString());
System.out.println("inBufferSize="+ inBufferSize.getValue());
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_SetDeviceCfg fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return false;
}
System.out.println("33333333333333333333333333333333");
STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans2 = getStuCfgNetStorageTrans(loginID,nCommand);
System.out.println(JSON.toJSON(stuCfgNetStorageTrans2.stuItemArray[1]).toString());
return true;
}
public STU_CFG_NET_STORAGE_TRANS getStuCfgNetStorageTrans(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_GetDeviceCfg fail, command = %d, errorCode = %d", nCommand, error);
System.out.println(strError);
return null;
}
STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans = new STU_CFG_NET_STORAGE_TRANS();
DataUtils.sdk_data_ptrToStructure(ptrOutBuffer, stuCfgNetStorageTrans);
return stuCfgNetStorageTrans;
}
public Pointer getDeviceCfgPointer(STU_CFG_NET_STORAGE_TRANS stuCfgNetStorageTrans,IntByReference inBufferSize,int bRealtimeEnable,
int bOfflineEnable,byte[] szAddress,int uFtpPort,
byte[] szUserName,byte[] szPassword,byte[] szPathRule,int emPathEncodeType){
if(0 < stuCfgNetStorageTrans.uItemCount)
{
for(int i=0; i<stuCfgNetStorageTrans.uItemCount; i++)
{
String name = DataUtils.sdk_data_byteArrayToString(stuCfgNetStorageTrans.stuItemArray[i].szProtocol,GlobalTool.getEncodeType());
if("ftp".equalsIgnoreCase(name)){
System.out.println("111111111111111111");
System.out.println(JSON.toJSON(stuCfgNetStorageTrans.stuItemArray[i]).toString());
stuCfgNetStorageTrans.stuItemArray[i].szAddress = szAddress;
stuCfgNetStorageTrans.stuItemArray[i].bOfflineEnable = bOfflineEnable;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.szUserName = szUserName;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.szPassword = szPassword;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.uFtpPort = uFtpPort;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.bRealtimeEnable = bRealtimeEnable;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.szPathRule = szPathRule;
stuCfgNetStorageTrans.stuItemArray[i].stuFtpParams.emPathEncodeType = emPathEncodeType;
}
}
}
System.out.println("222222222222222222222222222");
System.out.println(JSON.toJSON(stuCfgNetStorageTrans.stuItemArray[1]).toString());
inBufferSize.setValue(stuCfgNetStorageTrans.size());
Pointer ptrInBuffer = DataUtils.sdk_data_createPtr(inBufferSize.getValue());
System.out.println("stuCfgNetStorageTrans");
System.out.println(JSON.toJSON(stuCfgNetStorageTrans).toString());
DataUtils.sdk_data_structureToPtr(stuCfgNetStorageTrans, ptrInBuffer, 0);
return ptrInBuffer;
}
} }

Loading…
Cancel
Save