package com.ycl.api.YS.login; import com.sun.jna.Memory; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import com.ycl.api.YS.NetDemo; import com.ycl.api.YS.util.Common; import com.ycl.api.YS.util.Common.NETDEMO_DEVICE_INFO_S; import com.ycl.api.YS.util.Common.NETDEMO_DEV_LOGININFO_S; import com.ycl.api.YS.lib.NetDEVSDKLib; import com.ycl.api.YS.lib.NetDEVSDKLib.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.util.Timer; import java.util.TimerTask; import java.util.Vector; /** * * @introduction Log in and log out * @description Support IPC/NVR/VMS, and VMS only support private protocol */ public class Login { /** * * @introduction Log in * @description * */ public static void loginIn() { String strUserName = NetDemo.jTextFieldLoginUserName.getText(); String strPassword = NetDemo.jPasswordFieldLoginPassword.getText(); String strPort = NetDemo.jTextFieldLoginPort.getText(); NetDemo.strIPAddr = NetDemo.jTextFieldLoginIP.getText(); if(strUserName.isEmpty()){ JOptionPane.showMessageDialog(null, "Enter UserName first."); return; } if(NetDemo.strIPAddr.isEmpty()){ JOptionPane.showMessageDialog(null, "Enter IP first."); return; } if(strPort.isEmpty()){ JOptionPane.showMessageDialog(null, "Enter Port first."); return; } NetDEVSDKLib.NETDEV_DEVICE_LOGIN_INFO_S stDevLoginInfo = new NetDEVSDKLib.NETDEV_DEVICE_LOGIN_INFO_S(); NetDEVSDKLib.NETDEV_SELOG_INFO_S stSELogInfo = new NetDEVSDKLib.NETDEV_SELOG_INFO_S(); System.arraycopy(strUserName.getBytes(), 0, stDevLoginInfo.szUserName, 0, strUserName.getBytes().length); System.arraycopy(strPassword.getBytes(), 0, stDevLoginInfo.szPassword, 0, strPassword.getBytes().length); System.arraycopy(NetDemo.strIPAddr.getBytes(), 0, stDevLoginInfo.szIPAddr, 0, NetDemo.strIPAddr.getBytes().length); int getStrPort=0; try { getStrPort=Integer.parseInt(strPort); }catch(Exception m) { JOptionPane.showMessageDialog(null, "Port Conversion Exception"); NetDemo.jTextFieldLoginPort.setText(null); return; } if(getStrPort<1 || getStrPort>65535) { JOptionPane.showMessageDialog(null, "Port should between 1 and 65535"); NetDemo.jTextFieldLoginPort.setText(null); return; } stDevLoginInfo.dwPort = getStrPort; stDevLoginInfo.dwLoginProto = NetDemo.jComboBoxLoginProtocol.getSelectedIndex(); if((NetDemo.jComboBoxDeviceType.getSelectedIndex()==0)&&(NetDemo.jComboBoxLoginProtocol.getSelectedIndex()==1)) { JOptionPane.showMessageDialog(null, "Please right choose equipment corresponding protocol "); return; } if((NetDemo.jComboBoxDeviceType.getSelectedIndex()==1)&&(NetDemo.jComboBoxLoginProtocol.getSelectedIndex()==0)) { JOptionPane.showMessageDialog(null, "Please right choose equipment corresponding protocol "); return; } NetDemo.lpUserID = NetDemo.netdevsdk.NETDEV_Login_V30(stDevLoginInfo, stSELogInfo); if(null != NetDemo.lpUserID){ NetDemo.jComboBoxDeviceType.setEnabled(false); NetDemo.jComboBoxLoginProtocol.setEnabled(false); NetDemo.singleLoginThread.execute(new Runnable() { @Override public void run() { if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0){ int nMaxChlCount = 256; IntByReference dwChlCount = new IntByReference(nMaxChlCount); NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S[] stVideoChlList = (NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S[])new NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S().toArray(nMaxChlCount); boolean bRet = NetDemo.netdevsdk.NETDEV_QueryVideoChlDetailListEx(NetDemo.lpUserID, dwChlCount, stVideoChlList); NetDemo.DeviceTableModel.setRowCount(0); if(bRet) { for(int i=0; i vector = new Vector(); vector.add(String.valueOf(stVideoChlList[i].dwChannelID)); vector.add(Common.DevideStatusToString(stVideoChlList[i].enStatus)); vector.add(Common.utfToString(stVideoChlList[i].szChnName)); NetDemo.DeviceTableModel.insertRow(i,vector); } } NetDemo.netdevsdk.NETDEV_SetFaceSnapshotCallBack(NetDemo.lpUserID, NetDemo.cbFaceSnapshotCallBack, null); NetDemo.netdevsdk.NETDEV_SetCarPlateCallBack( NetDemo.lpUserID, NetDemo.cbCarPlateCallBack, null); NetDemo.netdevsdk.NETDEV_SetPassengerFlowStatisticCallBack( NetDemo.lpUserID, NetDemo.cbPassengerFlowStatisticCallBack, null); } else{ NetDemo.gastLoginDeviceInfo = new NETDEMO_DEV_LOGININFO_S(); NetDemo.gastLoginDeviceInfo.pHandle = NetDemo.lpUserID; int devIndex= 0; int dwDeviceType = NETDEV_DEVICE_MAIN_TYPE_E.NETDEV_DTYPE_MAIN_ENCODE; for(int i =0; i < 2; i++) { Pointer lpDevFindHandle = NetDemo.netdevsdk.NETDEV_FindDevList(NetDemo.lpUserID, dwDeviceType); if(lpDevFindHandle != null) { while(true) { NETDEV_DEV_BASIC_INFO_S stDevInfo = new NETDEV_DEV_BASIC_INFO_S(); stDevInfo.stDevAddr = new NETDEV_IPADDR_INFO_S(); stDevInfo.stDevUserInfo = new NETDEV_USER_SIMPLE_INFO_S(); if(true == NetDemo.netdevsdk.NETDEV_FindNextDevInfo(lpDevFindHandle, stDevInfo)) { NETDEMO_DEVICE_INFO_S stDemoDeviceInfo = new NETDEMO_DEVICE_INFO_S(); stDemoDeviceInfo.stDevBasicInfo = stDevInfo; stDemoDeviceInfo.dwDevIndex = devIndex; /*登录时获取以私有协议类型登录的并在线设备 */ if((stDemoDeviceInfo.stDevBasicInfo.dwImageProtocol == 1)&&stDemoDeviceInfo.stDevBasicInfo.dwDevStatus == 1) { Vector syncDevicevector = new Vector(); syncDevicevector.add(String.valueOf(stDemoDeviceInfo.stDevBasicInfo.dwDevID)); syncDevicevector.add(Common.byteArrayToString(stDemoDeviceInfo.stDevBasicInfo.stDevAddr.szIPAddr)); NetDemo.SyncDeviceModel.addRow(syncDevicevector); } NetDemo.gastLoginDeviceInfo.stDevLoginInfo.put(devIndex, stDemoDeviceInfo); NetDemo.gastLoginDeviceInfo.dwDevNum++; Pointer lpChnFindHandle = NetDemo.netdevsdk.NETDEV_FindDevChnList(NetDemo.gastLoginDeviceInfo.pHandle, stDevInfo.dwDevID, NETDEV_CHN_TYPE_E.NETDEV_CHN_TYPE_ENCODE); if(null != lpChnFindHandle) { while(true) { NETDEV_DEV_CHN_ENCODE_INFO_S stDevChnEncodeInfo = new NETDEV_DEV_CHN_ENCODE_INFO_S(); stDevChnEncodeInfo.write(); IntByReference dwBytesReturned = new IntByReference(0); if(true == NetDemo.netdevsdk.NETDEV_FindNextDevChn(lpChnFindHandle, stDevChnEncodeInfo.getPointer(),stDevChnEncodeInfo.size(), dwBytesReturned)) { stDevChnEncodeInfo.read(); //将指针内存中字段写入到结构体中 Vector vector = new Vector(); vector.add(String.valueOf(stDevChnEncodeInfo.stChnBaseInfo.dwChannelID)); vector.add(Common.CHNStatusToString(stDevChnEncodeInfo.stChnBaseInfo.dwChnStatus)); vector.add(Common.utfToString(stDevChnEncodeInfo.stChnBaseInfo.szChnName)); NetDemo.DeviceTableModel.addRow(vector); NetDemo.gastLoginDeviceInfo.stDevLoginInfo.get(devIndex).vecChanInfo.add(stDevChnEncodeInfo); NetDemo.gastLoginDeviceInfo.stDevLoginInfo.get(devIndex).dwChnNum++; } else { break; } } NetDemo.netdevsdk.NETDEV_FindCloseDevChn(lpChnFindHandle); } } else { break; } devIndex++; } NetDemo.netdevsdk.NETDEV_FindCloseDevInfo(lpDevFindHandle); } dwDeviceType = NETDEV_DEVICE_MAIN_TYPE_E.NETDEV_DTYPE_MAIN_BAYONET; } } } }); { NetDemo.jButtonLogIn.setEnabled(false); NetDemo.jButtonLogOut.setEnabled(true); NetDemo.jTextFieldConfigImageExposureSlowestShutter.setEnabled(false); if(NetDemo.jComboBoxDeviceType.getSelectedIndex()==0) { NetDemo.textFieldImageInfo2DNoiseReduce.setEnabled(true); NetDemo.textFieldImageInfo3DNoiseReduce.setEnabled(true); }else { NetDemo.textFieldImageInfo2DNoiseReduce.setEnabled(false); NetDemo.textFieldImageInfo3DNoiseReduce.setEnabled(false); } NetDemo.runflag=true; } } else { System.out.print("error code"+NetDemo.netdevsdk.NETDEV_GetLastError()); if(NetDemo.netdevsdk.NETDEV_GetLastError()==11201){ JOptionPane.showMessageDialog(null, "Login failed, Please check username and password"); }else { JOptionPane.showMessageDialog(null, "Login failed, Please check device information."); } } NetDemo.pstDeviceInfo = new NETDEV_DEVICE_BASE_INFO_S(); NetDemo.pstDeviceInfo.write(); boolean bRet = NetDemo.netdevsdk.NETDEV_GetDeviceBaseInfo(NetDemo.lpUserID,NetDemo.pstDeviceInfo); if(bRet != true){ System.out.println("NETDEV_GetDeviceBaseInfo failed:%d\n" + NetDemo.netdevsdk.NETDEV_GetLastError()); return; } NetDemo.pstDeviceInfo.read(); if((NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_VMS)&&(NetDemo.jComboBoxDeviceType.getSelectedIndex()==0)) { JOptionPane.showMessageDialog(null, "Please right choose equipment type "); NetDemo.jButtonLogOut.doClick(); return; } if((NetDemo.pstDeviceInfo.dwDeviceType != NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_VMS)&&(NetDemo.jComboBoxDeviceType.getSelectedIndex()==1)) { JOptionPane.showMessageDialog(null, "Please right choose equipment type "); NetDemo.jButtonLogOut.doClick(); return; } if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_HNVR || NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR || NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR_BACKUP ) { NetDemo.comboBoxFontMargin.setEnabled(false); NetDemo.comboBoxFontStyle.setEnabled(false); NetDemo.comboBoxFontStyleAlign.setEnabled(false); NetDemo.jComboBoxFontStyleAlign2.setEnabled(false); NetDemo.jComboBoxFontStyleAlign3.setEnabled(false); NetDemo.jComboBoxFontStyleAlign4.setEnabled(false); NetDemo.jComboBoxFontStyleAlign5.setEnabled(false); NetDemo.jComboBoxFontStyleAlign6.setEnabled(false); NetDemo.jComboBoxFontStyleAlign7.setEnabled(false); NetDemo.jComboBoxFontStyleAlign8.setEnabled(false); }else { NetDemo.comboBoxFontMargin.setEnabled(true); NetDemo.comboBoxFontStyle.setEnabled(true); NetDemo.comboBoxFontStyleAlign.setEnabled(true); NetDemo.jComboBoxFontStyleAlign2.setEnabled(true); NetDemo.jComboBoxFontStyleAlign3.setEnabled(true); NetDemo.jComboBoxFontStyleAlign4.setEnabled(true); NetDemo.jComboBoxFontStyleAlign5.setEnabled(true); NetDemo.jComboBoxFontStyleAlign6.setEnabled(true); NetDemo.jComboBoxFontStyleAlign7.setEnabled(true); NetDemo.jComboBoxFontStyleAlign8.setEnabled(true); } Pointer lpUserData=new Memory(128); boolean rbet=NetDemo.netdevsdk.NETDEV_SetExceptionCallBack(NetDemo.cbExceptionCallBack,lpUserData); if(!rbet) { System.out.println("NETDEV_SetExceptionCallBack failed:%d\n" + NetDemo.netdevsdk.NETDEV_GetLastError()); } } /** * * @introduction Log out * @description * */ public static void loginOut() { NetDemo.runflag=false; NetDemo.isTimer=false; if(null != NetDemo.lpTalkHandle){ NetDemo.netdevsdk.NETDEV_StopVoiceCom(NetDemo.lpTalkHandle); NetDemo.lpTalkHandle = null; } if(null != NetDemo.lpPlayHandle){ NetDemo.netdevsdk.NETDEV_StopRealPlay(NetDemo.lpPlayHandle); NetDemo.lpPlayHandle = null; } NetDemo.panelPlayLabel.repaint(); if(null != NetDemo.lpUserID){ NetDemo.netdevsdk.NETDEV_SetPassengerFlowStatisticCallBack(NetDemo.lpUserID, null, null); NetDemo.VCAPeopleCountingTableModel.setRowCount(0); NetDemo.netdevsdk.NETDEV_Logout(NetDemo.lpUserID); int numrow=NetDemo.VATable.getRowCount(); for(int i=0;i