球机登陆失败重新登陆

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;
private static int MAX_RECONNET_TIME = 100000;
static HikExceptionCallBack hikExceptionCallBack = new HikExceptionCallBack();
/**
@ -40,10 +42,10 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
log.error("hik callback config error");
}
//设置登录超时时间和尝试次数,可选
int waitTime = 5000; //登录请求响应超时时间设置为5S
int tryTimes = 1000; //登录时尝试建立链接1
hcNetsdk.NET_DVR_SetConnectTime(waitTime, tryTimes);
hcNetsdk.NET_DVR_SetReconnect(500,Boolean.TRUE);
int waitTime = 1000; //登录请求响应超时时间设置
int tryTimes = 1000; //登录时尝试建立链接
Boolean ok1 = hcNetsdk.NET_DVR_SetConnectTime(waitTime, tryTimes);
Boolean ok2 = hcNetsdk.NET_DVR_SetReconnect(500,Boolean.TRUE);
return true;
}
@ -75,18 +77,28 @@ public class HikLoginModuleImpl implements CameraControlLoginModule {
m_strLoginInfo.wPort = (short) m_nPort;
m_strLoginInfo.bUseAsynLogin = false; //是否异步登录0- 否1- 是
m_strLoginInfo.bUseAsynLogin = true; //是否异步登录0- 否1- 是
m_strLoginInfo.write();
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);
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());
return null;
}else {
try {
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");
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.NET_IN_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 static NetSDKLib netsdk = NetSDKLib.NETSDK_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();
@ -105,7 +109,16 @@ public class JoywareLoginModuleImpl implements CameraControlLoginModule {
pstOutParam.stuDeviceInfo=m_stDeviceInfo;
//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);
//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;
}

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

@ -44,19 +44,6 @@ public class StockService {
}catch (Exception e){
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