球机登陆失败重新登陆

merge-requests/5/merge
yiming 4 years ago
parent eee6f62a79
commit 36981ba1a5

@ -16,6 +16,8 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
public static HCNetSDK hcNetsdk = HCNetSDK.INSTANCE; public static HCNetSDK hcNetsdk = HCNetSDK.INSTANCE;
private static int MAX_RECONNET_TIME = 100000;
static HikExceptionCallBack hikExceptionCallBack = new HikExceptionCallBack(); static HikExceptionCallBack hikExceptionCallBack = new HikExceptionCallBack();
/** /**
@ -40,10 +42,10 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
log.error("hik callback config error"); log.error("hik callback config error");
} }
//设置登录超时时间和尝试次数,可选 //设置登录超时时间和尝试次数,可选
int waitTime = 5000; //登录请求响应超时时间设置为5S int waitTime = 1000; //登录请求响应超时时间设置
int tryTimes = 1000; //登录时尝试建立链接1 int tryTimes = 1000; //登录时尝试建立链接
hcNetsdk.NET_DVR_SetConnectTime(waitTime, tryTimes); Boolean ok1 = hcNetsdk.NET_DVR_SetConnectTime(waitTime, tryTimes);
hcNetsdk.NET_DVR_SetReconnect(500,Boolean.TRUE); Boolean ok2 = hcNetsdk.NET_DVR_SetReconnect(500,Boolean.TRUE);
return true; return true;
} }
@ -75,18 +77,28 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
m_strLoginInfo.wPort = (short) m_nPort; m_strLoginInfo.wPort = (short) m_nPort;
m_strLoginInfo.bUseAsynLogin = false; //是否异步登录0- 否1- 是 m_strLoginInfo.bUseAsynLogin = true; //是否异步登录0- 否1- 是
m_strLoginInfo.write(); m_strLoginInfo.write();
HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo30 = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//设备信息 HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo30 = new HCNetSDK.NET_DVR_DEVICEINFO_V30();//设备信息
int m_lUserID = hcNetsdk.NET_DVR_Login_V30(m_strIp,(short) m_nPort,m_strUser,m_strPassword,m_strDeviceInfo30); int m_lUserID = hcNetsdk.NET_DVR_Login_V30(m_strIp,(short) m_nPort,m_strUser,m_strPassword,m_strDeviceInfo30);
if(m_lUserID < 0){ int tryTimes = 0;
while(m_lUserID < 0 && tryTimes < MAX_RECONNET_TIME){
log.error("hik login error,ip:{},port:{},errorCode:{}",m_strIp,m_nPort,hcNetsdk.NET_DVR_GetLastError()); log.error("hik login error,ip:{},port:{},errorCode:{}",m_strIp,m_nPort,hcNetsdk.NET_DVR_GetLastError());
return null; try {
}else { Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
m_lUserID = hcNetsdk.NET_DVR_Login_V30(m_strIp,(short) m_nPort,m_strUser,m_strPassword,m_strDeviceInfo30);
tryTimes ++;
}
if(m_lUserID >= 0){
log.info("hik login success"); log.info("hik login success");
return new NetSDKLib.LLong(m_lUserID);
}else {
return null;
} }
return new NetSDKLib.LLong(m_lUserID);
} }
} }

@ -6,16 +6,20 @@ import com.zhehekeji.web.lib.CameraControlLoginModule;
import com.zhehekeji.web.lib.joyware.NetSDKLib.LLong; import com.zhehekeji.web.lib.joyware.NetSDKLib.LLong;
import com.zhehekeji.web.lib.joyware.NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY; import com.zhehekeji.web.lib.joyware.NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY;
import com.zhehekeji.web.lib.joyware.NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY; import com.zhehekeji.web.lib.joyware.NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY;
import lombok.extern.slf4j.Slf4j;
/** /**
* *
* *
*/ */
@Slf4j
public class JoywareLoginModuleImpl implements CameraControlLoginModule { public class JoywareLoginModuleImpl implements CameraControlLoginModule {
public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE; public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
public static NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE; public static NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE;
private static int MAX_RECONNET_TIME = 100000;
// 设备信息 // 设备信息
public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
@ -105,7 +109,16 @@ public class JoywareLoginModuleImpl implements CameraControlLoginModule {
pstOutParam.stuDeviceInfo=m_stDeviceInfo; pstOutParam.stuDeviceInfo=m_stDeviceInfo;
//m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, m_stDeviceInfo, nError); //m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, m_stDeviceInfo, nError);
LLong m_hLoginHandle=netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam); LLong m_hLoginHandle=netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam);
//attachPTZStatusProc(); int tryTimes = 0;
while (m_hLoginHandle.longValue()==0 && tryTimes <= MAX_RECONNET_TIME){
log.error("joyware login error,ip:{},port:{},errorCode:{}",m_strIp,m_nPort,netsdk.CLIENT_GetLastError());
m_hLoginHandle=netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam);
tryTimes ++;
}
if(m_hLoginHandle.longValue()==0){
return null;
}
log.info("hik login success");
return m_hLoginHandle; return m_hLoginHandle;
} }

@ -80,9 +80,10 @@ public class InitService implements ApplicationRunner {
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
//球机登录 //球机登录
List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0)); List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0));
loginThread loginThread = new loginThread(cameras); cameras.forEach(camera -> {
LoginThread loginThread = new LoginThread(camera);
loginThread.start(); loginThread.start();
});
//plc连接 //plc连接
if(configProperties.getServerMode() == 0){ if(configProperties.getServerMode() == 0){
log.info("PLC TCP MODE"); log.info("PLC TCP MODE");
@ -115,20 +116,17 @@ public class InitService implements ApplicationRunner {
TaskDelayExecutor.runMp4DownloadExecutor(); TaskDelayExecutor.runMp4DownloadExecutor();
} }
class loginThread extends Thread{ class LoginThread extends Thread{
List<Camera> cameras; Camera camera;
public loginThread(List<Camera> cameras){
this.cameras = cameras;
public LoginThread(Camera camera){
this.camera = camera;
} }
@Override @Override
public void run() { public void run() {
cameras.forEach(camera -> {
cameraService.cameraLogin(camera); cameraService.cameraLogin(camera);
});
} }
} }

@ -44,19 +44,6 @@ public class StockService {
}catch (Exception e){ }catch (Exception e){
Assert.isTrue(false,"导入出错"); Assert.isTrue(false,"导入出错");
} }
//
// Thread thread = new Thread(
// new Runnable() {
// @Override
// public void run() {
// try {
// } catch (IOException e) {
// log.error("库存导入error:{}", e);
// }
// }
// }
// );
// thread.start();
} }
/** /**

Loading…
Cancel
Save