Initial Commit

main
Matthew 2 years ago
parent 0f9bf421d5
commit 9594523a2d

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="Dahua-x64" default="default" basedir=".">
<description>Builds, tests, and runs the project Dahua-x64.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="Dahua-x64-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

@ -0,0 +1,4 @@
#Mon, 03 Jul 2023 11:20:10 +0800
/home/htdev/newcac/sourceproj/Dahua=

32
dist/README.TXT vendored

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "Dahua-x64.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

@ -0,0 +1,8 @@
build.xml.data.CRC32=a6c0abce
build.xml.script.CRC32=576cfaf9
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=a6c0abce
nbproject/build-impl.xml.script.CRC32=a5911d2b
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

@ -0,0 +1,6 @@
compile.on.save=true
do.depend=false
do.jar=true
javac.debug=true
javadoc.preview=true
user.properties.file=/home/htdev/.netbeans/8.2/build.properties

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
</open-files>
</project-private>

@ -0,0 +1,81 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=Dahua-x64
application.vendor=LENOVO
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# build.classes.dir \u4e2d\u5e94\u4ece\u5206\u53d1 jar \u4e2d\u6392\u9664\u7684\u6587\u4ef6
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/Dahua-x64.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.examples.jar=examples.jar
file.reference.jna.jar=jna.jar
includes=**
jar.compress=true
javac.classpath=\
${file.reference.examples.jar}:\
${libs.MySQLDriver.classpath}:\
${file.reference.jna.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=dahua.Hot
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=-Xss1024k
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Dahua-x64</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

@ -0,0 +1,88 @@
package dahua;
import dahua.NetSDKLib;
import dahua.NetSDKLib.LLong;
import dahua.ToolKits;
import com.sun.jna.ptr.IntByReference;
/**
* \if ENGLISH_LANG
* Capture Picture Interface
* contains:localremotetimer and stop capture picture
* \else
*
* :
* \endif
*/
public class CapturePictureModule {
/**
* \if ENGLISH_LANG
* Remote Capture Picture
* \else
*
* \endif
*/
public static boolean remoteCapturePicture(int chn) {
return snapPicture(chn, 0, 0);
}
/**
* \if ENGLISH_LANG
* Timer Capture Picture
* \else
*
* \endif
*/
public static boolean timerCapturePicture(int chn) {
return snapPicture(chn, 1, 2);
}
/**
* \if ENGLISH_LANG
* Stop Timer Capture Picture
* \else
*
* \endif
*/
public static boolean stopCapturePicture(int chn) {
return snapPicture(chn, -1, 0);
}
/**
* \if ENGLISH_LANG
* Capture Picture (except local capture picture, others all call this interface)
* \else
* (, )
* \endif
*/
private static boolean snapPicture(int chn, int mode, int interval) {
// send caputre picture command to device
NetSDKLib.SNAP_PARAMS stuSnapParams = new NetSDKLib.SNAP_PARAMS();
stuSnapParams.Channel = chn; // channel
stuSnapParams.mode = mode; // capture picture mode
stuSnapParams.Quality = 3; // picture quality
stuSnapParams.InterSnap = interval; // timer capture picture time interval
stuSnapParams.CmdSerial = 0; // request serial
IntByReference reserved = new IntByReference(0);
if (!INetSDK.netsdk.CLIENT_SnapPictureEx(INetSDK.m_hLoginHandle, stuSnapParams, reserved)) {
System.err.printf("CLIENT_SnapPictureEx Failed!" + INetSDK.netsdk.CLIENT_GetLastError());
return false;
} else {
System.out.println("CLIENT_SnapPictureEx success");
}
return true;
}
/**
* \if ENGLISH_LANG
* Set Capture Picture Callback
* \else
*
* \endif
*/
public static void setSnapRevCallBack(NetSDKLib.fSnapRev cbSnapReceive){
INetSDK.netsdk.CLIENT_SetSnapRevCallBack(cbSnapReceive, null);
}
}

@ -0,0 +1,192 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dahua;
import java.io.BufferedReader;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author LENOVO
*/
public class DBHelper {
private static String DRIVER="";
//private static final String URL="jdbc:mysql://192.168.1.188/dss";
private static String URL="";
private static String USER="";
private static String PASSWORD="";
public void GetText(String path){
if(DRIVER!=""){
return;
}
// 1.定义目标文件
File srcFile = new File(path);
// 2.创建一个流,指向目标文件
BufferedReader is = null;
try {
is = new BufferedReader(new FileReader(srcFile));
int i= 0;
String s = null;
while ((s = is.readLine()) != null) {// 使用readLine方法一次读一行
if(i==0){
DRIVER = s;
}
if(i==1){
URL = s;
}
if(i==2){
USER = s;
}
if(i==3){
PASSWORD = s;
}
i++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭io流
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*
* @return
*/
public Connection getConnection(){
// GetText("D://shjdconfig.txt");
GetText("/home/shjdconfig.txt");
Connection conn=null;
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
conn=DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
/**
*
* @param rs
* @param pstmt
* @param conn
*/
public void closeAll(ResultSet rs,PreparedStatement pstmt,Connection conn){
try {
if(rs!=null){
rs.close();
}
if(pstmt!=null){
pstmt.close();
}
if(conn!=null){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @param sql
* @return true or false
*/
public int excuteUpdate(String sql){
int res=0;//受影响的行数
Connection conn=null;
PreparedStatement pstmt = null;
ResultSet rs=null;
try {
conn=getConnection();
pstmt=conn.prepareStatement(sql);//装载sql语句
res=pstmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
closeAll(rs, pstmt, conn);
}
return res;
}
/**
* 使
* @param sql
* @param params
* @param cls
* @return
*/
public <T> List<T> executeQuery(String sql,List<Object> params,Class<T> cls) throws Exception{
Connection conn=null;
PreparedStatement pstmt = null;
ResultSet rs=null;
List<T> data=new ArrayList<T>();
try {
conn=getConnection();
pstmt=conn.prepareStatement(sql);//装载sql语句
if(params!=null){
//加入有?占位符,在执行之前把?占位符替换掉
for(int i=0;i<params.size();i++){
pstmt.setObject(i+1, params.get(i));
}
}
rs=pstmt.executeQuery();
//把查询出来的记录封装成对应的实体类对象
ResultSetMetaData rsd=rs.getMetaData();//获得列对象,通过此对象可以得到表的结构,包括,列名,列的个数,列的数据类型
while(rs.next()){
T m=cls.newInstance();
for(int i=0;i<rsd.getColumnCount();i++){
String col_name=rsd.getColumnName(i+1);//获得列名
Object value=rs.getObject(col_name);//获得列所对应的值
Field field=cls.getDeclaredField(col_name);
field.setAccessible(true);//给私有属性设置可访问权
field.set(m, value);//给对象的私有属性赋值
}
data.add(m);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
closeAll(rs, pstmt, conn);
}
return data;
}
}

@ -0,0 +1,576 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JFrame" name="jFrame1">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Container class="javax.swing.JFrame" name="jFrame2">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Component class="javax.swing.ButtonGroup" name="TypeGroup">
</Component>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="ClientDemo"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="&#x5b8b;&#x4f53;" size="10" style="0"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPaneHorizontal" alignment="0" pref="16050" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPaneHorizontal" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPaneHorizontal">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder/>
</Border>
</Property>
<Property name="dividerLocation" type="int" value="155"/>
<Property name="dividerSize" type="int" value="2"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanelUserInfo">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder>
<Color PropertyName="highlight" blue="ff" green="ff" red="cc" type="rgb"/>
</EtchetBorder>
</Border>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 878]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="left"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabelIPAddress1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
<Component id="jTextFieldPwd" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jButtonRealPlay" min="-2" pref="87" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jButtonLogin" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabelPortNumber1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
<Component id="jTextFieldPortNumber" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPaneTree" alignment="0" max="32767" attributes="1"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabelPortNumber4" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
<Component id="nPresetIdTxt" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="10" pref="10" max="-2" attributes="0"/>
<Component id="jLabelPortNumber2" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jLabelPortNumber3" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="26" pref="26" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="nRuleId" max="32767" attributes="0"/>
<Component id="nMeterType1" max="32767" attributes="0"/>
</Group>
</Group>
<Component id="jButton2" alignment="0" min="-2" pref="87" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="10" pref="10" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabelIPAddress" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabelPortNumber" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jTextFieldIPAddress" max="32767" attributes="0"/>
<Component id="jTextFieldUser" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="20" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabelIPAddress" min="-2" max="-2" attributes="0"/>
<Component id="jTextFieldIPAddress" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabelPortNumber" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jTextFieldUser" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabelIPAddress1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jTextFieldPwd" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabelPortNumber1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jTextFieldPortNumber" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jButtonLogin" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jButtonRealPlay" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="nPresetIdTxt" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabelPortNumber4" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabelPortNumber3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="nMeterType1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="nRuleId" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabelPortNumber2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="32" max="-2" attributes="0"/>
<Component id="jScrollPaneTree" min="-2" pref="167" max="-2" attributes="0"/>
<EmptySpace pref="349" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="jButtonRealPlay">
<Properties>
<Property name="text" type="java.lang.String" value="&#x9884;&#x89c8;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonRealPlayActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButtonLogin">
<Properties>
<Property name="text" type="java.lang.String" value="&#x9000;&#x51fa;&#x9884;&#x89c8;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonLoginActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabelIPAddress">
<Properties>
<Property name="text" type="java.lang.String" value="IP&#x5730;&#x5740;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldUser">
<Properties>
<Property name="text" type="java.lang.String" value="admin"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldIPAddress">
<Properties>
<Property name="text" type="java.lang.String" value="192.168.1.108"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabelPortNumber">
<Properties>
<Property name="text" type="java.lang.String" value="&#x7528;&#x6237;&#x540d;&#xff1a;"/>
</Properties>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPaneTree">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTree" name="jTreeDevice">
<Properties>
<Property name="model" type="javax.swing.tree.TreeModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="this.initialTreeModel()" type="code"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="jButton2">
<Properties>
<Property name="text" type="java.lang.String" value="&#x83b7;&#x53d6;&#x6e29;&#x5ea6;"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldPortNumber">
<Properties>
<Property name="text" type="java.lang.String" value="37777"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabelPortNumber1">
<Properties>
<Property name="text" type="java.lang.String" value="&#x7aef;&#x53e3;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabelIPAddress1">
<Properties>
<Property name="text" type="java.lang.String" value="&#x5bc6;&#x7801;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldPwd">
<Properties>
<Property name="text" type="java.lang.String" value="admin12345"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextFieldPwdActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabelPortNumber2">
<Properties>
<Property name="text" type="java.lang.String" value="&#x89c4;&#x5219;&#x7f16;&#x53f7;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="nRuleId">
<Properties>
<Property name="text" type="java.lang.String" value="0"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabelPortNumber3">
<Properties>
<Property name="text" type="java.lang.String" value="&#x6d4b;&#x6e29;&#x9879;&#x7c7b;&#x578b;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabelPortNumber4">
<Properties>
<Property name="text" type="java.lang.String" value="&#x9884;&#x7f6e;&#x70b9;&#x7f16;&#x53f7;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="nPresetIdTxt">
<Properties>
<Property name="text" type="java.lang.String" value="0"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="nMeterType1">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="1">
<StringItem index="0" value="&#x8bf7;&#x9009;&#x62e9;&#x7c7b;&#x578b;"/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JSplitPane" name="jSplitPaneVertical">
<Properties>
<Property name="dividerLocation" type="int" value="579"/>
<Property name="dividerSize" type="int" value="2"/>
<Property name="orientation" type="int" value="0"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanelRealplayArea">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder>
<Color PropertyName="color" blue="66" green="ff" red="99" type="rgb"/>
</LineBorder>
</Border>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
<Component id="Realplay" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="15366" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
<Component id="Realplay" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="49" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="java.awt.Panel" name="Realplay">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[500, 500]"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RealplayMousePressed"/>
</Events>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="500" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="500" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="jLabel1"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
</Component>
<Container class="java.awt.Panel" name="panel1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel8" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="fTemperStdTxt" min="-2" pref="118" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="fTemperMidTxt" min="-2" pref="118" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="fTemperMinTxt" min="-2" pref="118" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="fTemperMaxTxt" min="-2" pref="118" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="fTemperAverTxt" min="-2" pref="118" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="nTemperUnitTxt" min="-2" pref="118" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="15659" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="59" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="nTemperUnitTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fTemperAverTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel7" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fTemperMaxTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fTemperMinTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fTemperMidTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="fTemperStdTxt" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="52" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" value="&#x6d4b;&#x6e29;&#x5355;&#x4f4d;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="nTemperUnitTxt">
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" value="&#x5e73;&#x5747;&#x6e29;&#x5ea6;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="fTemperAverTxt">
</Component>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="text" type="java.lang.String" value="&#x4e2d;&#x95f4;&#x503c;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="fTemperMidTxt">
</Component>
<Component class="javax.swing.JTextField" name="fTemperMinTxt">
</Component>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" value="&#x6700;&#x5c0f;&#x6e29;&#x5ea6;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel7">
<Properties>
<Property name="text" type="java.lang.String" value="&#x6700;&#x9ad8;&#x6e29;&#x5ea6;&#xff1a;"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="fTemperMaxTxt">
</Component>
<Component class="javax.swing.JTextField" name="fTemperStdTxt">
</Component>
<Component class="javax.swing.JLabel" name="jLabel8">
<Properties>
<Property name="text" type="java.lang.String" value="&#x6807;&#x51c6;&#x65b9;&#x5dee;&#x503c;&#xff1a;"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,660 @@
package dahua;
import java.awt.Panel;
import java.io.File;
import dahua.ToolKits;
import dahua.NetSDKLib;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.examples.win32.W32API;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
import javax.swing.SwingUtilities;
public class INetSDK {
static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE;
private static NetSDKLib playsdk = NetSDKLib.CONFIG_dhplay;
// 设备信息
public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex();
// 登陆句柄
public static NativeLong m_hLoginHandle = new NativeLong(0);
// 预览句柄
public static NativeLong m_hPlayHandle = new NativeLong(0);
// 智能订阅句柄
public static NativeLong m_hAttachHandle = new NativeLong(0);
// 下载句柄
public static NativeLong m_hDownLoadHandle = new NativeLong(0);
private static boolean bInit = false;
private static boolean bLogopen = false;
/**
* \if ENGLISH_LANG
* Init
* \else
*
* \endif
*/
public static boolean init(NetSDKLib.fDisConnect disConnect, NetSDKLib.fHaveReConnect haveReConnect) {
bInit = netsdk.CLIENT_Init(disConnect, new NativeLong(0));
if(!bInit) {
System.out.println("Initialize SDK failed");
return false;
}
//打开日志,可选
NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO();
File path = new File("./sdklog/");
if (!path.exists()) {
path.mkdir();
}
String logPath = path.getAbsoluteFile().getParent() + "\\sdklog\\" + ToolKits.getDate() + ".log";
setLog.nPrintStrategy = 0;
setLog.bSetFilePath = 1;
System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length);
System.out.println(logPath);
setLog.bSetPrintStrategy = 1;
setLog.nPrintStrategy = 0;
bLogopen = netsdk.CLIENT_LogOpen(setLog);
if(!bLogopen ) {
System.err.println("Failed to open NetSDK log");
}
// 设置断线重连回调接口设置过断线重连成功回调函数后当设备出现断线情况SDK内部会自动进行重连操作
// 此操作为可选操作,但建议用户进行设置
netsdk.CLIENT_SetAutoReconnect(haveReConnect, new NativeLong(0));
//设置登录超时时间和尝试次数,可选
int waitTime = 5000; //登录请求响应超时时间设置为5S
int tryTimes = 1; //登录时尝试建立链接1次
netsdk.CLIENT_SetConnectTime(waitTime, tryTimes);
// 设置更多网络参数NET_PARAM的nWaittimenConnectTryNum成员与CLIENT_SetConnectTime
// 接口设置的登录设备超时时间和尝试次数意义相同,可选
NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM();
netParam.nConnectTime = 10000; //登录时尝试建立链接的超时时间
netsdk.CLIENT_SetNetworkParam(netParam);
return true;
}
/**
* \if ENGLISH_LANG
* CleanUp
* \else
*
* \endif
*/
public static void cleanup() {
if(bLogopen) {
netsdk.CLIENT_LogClose();
}
if(bInit) {
netsdk.CLIENT_Cleanup();
}
}
/**
* \if ENGLISH_LANG
* Login Device
* \else
*
* \endif
*/
public static boolean login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) {
IntByReference nError = new IntByReference(0);
m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, m_stDeviceInfo, nError);
if(m_hLoginHandle.longValue() == 0) {
System.err.printf("Login Device[%s] Port[%d]Failed. Last Error[0x%x]\n", m_strIp, m_nPort, netsdk.CLIENT_GetLastError());
} else {
System.out.println("Login Success [ " + m_strIp + " ]");
}
return m_hLoginHandle.longValue() == 0? false:true;
}
/**
* \if ENGLISH_LANG
* Logout Device
* \else
*
* \endif
*/
public static boolean logout() {
if(m_hLoginHandle.longValue() == 0) {
return false;
}
boolean bRet = netsdk.CLIENT_Logout(m_hLoginHandle);
if(bRet) {
m_hLoginHandle.setValue(0);
}
return bRet;
}
/**
*
*/
public static String getErrorCode() {
return Res.string().getErrorCode(netsdk.CLIENT_GetLastError());
}
/**
*
*/
public static boolean ptzControlnPresetId(int nChannelID, int lParam1, int lParam2, int lParam3, int dwStop, Pointer param4) {
return netsdk.CLIENT_DHPTZControlEx2(m_hLoginHandle, nChannelID, NetSDKLib.NET_PTZ_ControlType.NET_PTZ_POINT_MOVE_CONTROL,lParam1,lParam2,lParam3,dwStop,param4);
}
/**
* \if ENGLISH_LANG
* Start RealPlay
* \else
*
* \endif
*/
public static fRealDataCallBackEx fReal = new fRealDataCallBackEx();
public static W32API.HWND hwnd ;//窗体句柄
public static boolean startRealPlay(int channel, int stream, Panel realPlayWindow) {
hwnd =new W32API.HWND( Native.getComponentPointer(realPlayWindow));
boolean bOpenRet = playsdk.PLAY_OpenStream(new NativeLong(0),null,0,1024*500);
if(bOpenRet){
// 开始播放
boolean bPlayRet = playsdk.PLAY_Play(new NativeLong(0),hwnd);
if(bPlayRet){
m_hPlayHandle = netsdk.CLIENT_RealPlayEx(m_hLoginHandle, channel, null, stream);
//m_hPlayHandle = netsdk.CLIENT_RealPlayEx(m_hLoginHandle, channel, Native.getComponentPointer(realPlayWindow), stream);
}
boolean real = netsdk.CLIENT_SetRealDataCallBackEx(m_hPlayHandle,fReal,m_hLoginHandle,0x1f);
}
if(m_hPlayHandle.longValue() == 0) {
System.err.println("开始实时监视失败,错误码" + String.format("[0x%x]", netsdk.CLIENT_GetLastError()));
} else {
//boolean real = netsdk.CLIENT_SetRealDataCallBackEx(m_hPlayHandle,fReal,m_hLoginHandle,0x1f);
System.out.println("Success to start realplay");
}
return m_hPlayHandle.longValue() == 0? false:true;
}
//摄像头回调: 通过 startRealPlay
public static class fRealDataCallBackEx implements NetSDKLib.fRealDataCallBackEx {
public void invoke(NativeLong lRealHandle, int dwDataType, Pointer pBuffer, int dwBufSize, int param, NativeLong dwUser) {
boolean bInput=false;
if(0 != lRealHandle.intValue())
{
switch(dwDataType) {
case 0:
//原始音视频混合数据
bInput = playsdk.PLAY_InputData(new NativeLong(0),pBuffer,dwBufSize);
if (!bInput)
{
System.out.println("error");
}
break;
case 1:
//标准视频数据
break;
case 2:
//yuv 数据
break;
case 3:
//pcm 音频数据
break;
case 4:
//原始音频数据
break;
default:
break;
}
}
}
}
/**
* \if ENGLISH_LANG
* Start CLIENT_QueryDevInfo
* \else
*
* \endif
*/
//Pointer a = new Pointer(MemoryBlockFactory.createMemoryBlock(4 * 10));
public static boolean CLIENT_QueryDevInfo(int nQueryType, Pointer pInBuf, Pointer pOutBuf, Pointer pReservedL, int nWaitTime) {
//m_hLoginHandle.setValue(123);
boolean Isdate = netsdk.CLIENT_QueryDevInfo(m_hLoginHandle, nQueryType,pInBuf, pOutBuf,null,3000);
if(!Isdate) {
System.err.println("查看失败,错误码:" + String.format("[0x%x]", netsdk.CLIENT_GetLastError()));
} else {
System.out.println("Success Look");
}
return Isdate;
}
/**
* \if ENGLISH_LANG
* Start RealPlay
* \else
*
* \endif
*/
public static void stopRealPlay() {
if(m_hPlayHandle.longValue() == 0) {
return;
}
boolean bRet = netsdk.CLIENT_StopRealPlayEx(m_hPlayHandle);
if(bRet) {
m_hPlayHandle.setValue(0);
}
}
public static void SetSnapRevCallBack(NetSDKLib.fSnapRev m_SnapReceiveCB){
//设置抓图回调函数, 图片主要在m_SnapReceiveCB中返回
netsdk.CLIENT_SetSnapRevCallBack(m_SnapReceiveCB, new NativeLong(0));
}
/**
*
*/
public static boolean snapPicture(int chn) {
// 发送抓图命令给前端设备,抓图的信息
NetSDKLib.SNAP_PARAMS stuSnapParams = new NetSDKLib.SNAP_PARAMS() ;
stuSnapParams.Channel = chn; //抓图通道
stuSnapParams.mode = 0; //表示请求一帧
stuSnapParams.Quality = 3;
stuSnapParams.InterSnap = 5;
stuSnapParams.CmdSerial = 0; // 请求序列号,有效值范围 0~65535超过范围会被截断为
IntByReference reserved = new IntByReference(0);
if (!netsdk.CLIENT_SnapPictureEx(m_hLoginHandle, stuSnapParams, reserved)) {
System.err.printf("CLIENT_SnapPictureEx Failed!Last Error[%x]\n", netsdk.CLIENT_GetLastError());
return false;
} else {
System.out.println("CLIENT_SnapPictureEx success");
}
return true;
}
/********************************************************************************
* *
********************************************************************************/
/**
*
*/
public static boolean ptzControlUpStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_UP_CONTROL,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlUpEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_UP_CONTROL,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlDownStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_DOWN_CONTROL,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlDownEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_DOWN_CONTROL,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlLeftStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,NetSDKLib.NET_PTZ_ControlType.NET_PTZ_LEFT_CONTROL,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlLeftEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_LEFT_CONTROL,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlRightStart(int nChannelID, int lParam1,int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_RIGHT_CONTROL,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlRightEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_RIGHT_CONTROL,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlLeftUpStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTTOP,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlLeftUpEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTTOP,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlRightUpStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTTOP,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlRightUpEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTTOP,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlLeftDownStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTDOWN,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlLeftDownEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_LEFTDOWN,
0, 0, 0, 1);
}
/**
*
*/
public static boolean ptzControlRightDownStart(int nChannelID, int lParam1, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTDOWN,
lParam1, lParam2, 0, 0);
}
public static boolean ptzControlRightDownEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_EXTPTZ_ControlType.NET_EXTPTZ_RIGHTDOWN,
0, 0, 0, 1);
}
/**
* +
*/
public static boolean ptzControlZoomAddStart(int nChannelID, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_ADD_CONTROL,
0, lParam2, 0, 0);
}
public static boolean ptzControlZoomAddEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_ADD_CONTROL,
0, 0, 0, 1);
}
/**
* -
*/
public static boolean ptzControlZoomDecStart(int nChannelID, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_DEC_CONTROL,
0, lParam2, 0, 0);
}
public static boolean ptzControlZoomDecEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_ZOOM_DEC_CONTROL,
0, 0, 0, 1);
}
/**
* +
*/
public static boolean ptzControlFocusAddStart(int nChannelID, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_ADD_CONTROL,
0, lParam2, 0, 0);
}
public static boolean ptzControlFocusAddEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_ADD_CONTROL,
0, 0, 0, 1);
}
/**
* -
*/
public static boolean ptzControlFocusDecStart(int nChannelID, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_DEC_CONTROL,
0, lParam2, 0, 0);
}
public static boolean ptzControlFocusDecEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_FOCUS_DEC_CONTROL,
0, 0, 0, 1);
}
/**
* +
*/
public static boolean ptzControlIrisAddStart(int nChannelID, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_ADD_CONTROL,
0, lParam2, 0, 0);
}
public static boolean ptzControlIrisAddEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_ADD_CONTROL,
0, 0, 0, 1);
}
/**
* -
*/
public static boolean ptzControlIrisDecStart(int nChannelID, int lParam2) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_DEC_CONTROL,
0, lParam2, 0, 0);
}
public static boolean ptzControlIrisDecEnd(int nChannelID) {
return netsdk.CLIENT_DHPTZControlEx(m_hLoginHandle, nChannelID,
NetSDKLib.NET_PTZ_ControlType.NET_PTZ_APERTURE_DEC_CONTROL,
0, 0, 0, 1);
}
/********************************************************************************
* *
********************************************************************************/
/**
*
*/
public static void Old_OpenStrobe(int bTriggerBtnClick) {
if (m_hLoginHandle.longValue() != 0) {
System.out.println("Trigger Button Action");
NetSDKLib.ALARMCTRL_PARAM param = new NetSDKLib.ALARMCTRL_PARAM();
param.nAction = bTriggerBtnClick;; // 1触发报警0停止报警. 按钮按下
if (netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_TRIGGER_ALARM_OUT, param.getPointer(), null, 3000)) {
System.out.println("控制成功");
}else {
System.err.printf("Failed to Open 0x%x", netsdk.CLIENT_GetLastError());
}
}
}
/**
*
*/
public static boolean New_OpenStrobe() {
NetSDKLib.NET_CTRL_OPEN_STROBE openStrobe = new NetSDKLib.NET_CTRL_OPEN_STROBE();
openStrobe.nChannelId = 0;
String plate = new String("浙A888888");
System.arraycopy(plate.getBytes(), 0, openStrobe.szPlateNumber, 0, plate.getBytes().length);
openStrobe.write();
if (netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_OPEN_STROBE, openStrobe.getPointer(), null, 3000)) {
System.out.println("Open Success!");
} else {
System.err.printf("Failed to Open 0x%x\n", netsdk.CLIENT_GetLastError());
return false;
}
openStrobe.read();
return true;
}
/**
*
*/
public static void New_CloseStrobe() {
NetSDKLib.NET_CTRL_CLOSE_STROBE closeStrobe = new NetSDKLib.NET_CTRL_CLOSE_STROBE();
closeStrobe.nChannelId = 0;
closeStrobe.write();
if (netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_CTRL_CLOSE_STROBE, closeStrobe.getPointer(), null, 3000)) {
System.out.println("Close Success!");
} else {
System.err.printf("Failed to Close 0x%x\n", netsdk.CLIENT_GetLastError());
}
closeStrobe.read();
}
/**
*
*/
public static boolean manualSnapPicture(int chn) {
NetSDKLib.MANUAL_SNAP_PARAMETER snapParam = new NetSDKLib.MANUAL_SNAP_PARAMETER();
snapParam.nChannel = chn;
String sequence = "11111"; // 抓图序列号,必须用数组拷贝
System.arraycopy(sequence.getBytes(), 0, snapParam.bySequence, 0, sequence.getBytes().length);
snapParam.write();
boolean bRet = netsdk.CLIENT_ControlDeviceEx(m_hLoginHandle, NetSDKLib.CtrlType.CTRLTYPE_MANUAL_SNAP, snapParam.getPointer(), null, 5000);
if (!bRet) {
System.err.println("Failed to manual snap, last error " + String.format("[0x%x]", netsdk.CLIENT_GetLastError()));
return false;
} else {
System.out.println("Seccessed to manual snap");
}
snapParam.read();
return true;
}
/**
*
* @return
*/
public static boolean attachIVSEvent(int ChannelId, NetSDKLib.fAnalyzerDataCallBack m_AnalyzerDataCB) {
/**
*
* m_stDeviceInfo.byChanNum
* 0.
*/
int bNeedPicture = 1; // 是否需要图片
m_hAttachHandle = netsdk.CLIENT_RealLoadPictureEx(m_hLoginHandle, ChannelId, NetSDKLib.EVENT_IVS_ALL,
bNeedPicture , m_AnalyzerDataCB , null , null);
if( m_hAttachHandle.longValue() != 0 ) {
System.out.println("CLIENT_RealLoadPictureEx Success ChannelId : \n" + ChannelId);
} else {
System.err.printf("CLIENT_RealLoadPictureEx Failed!LastError = %x\n", netsdk.CLIENT_GetLastError() );
return false;
}
return true;
}
/**
*
*/
public static void detachIVSEvent() {
if (0 != m_hAttachHandle.longValue()) {
netsdk.CLIENT_StopLoadPic(m_hAttachHandle);
System.out.println("Stop detach IVS event");
m_hAttachHandle.setValue(0);
}
}
// 查找录像文件
public static boolean queryRecordFile(int nChannelId,
NetSDKLib.NET_TIME stTimeStart,
NetSDKLib.NET_TIME stTimeEnd,
NetSDKLib.NET_RECORDFILE_INFO[] stFileInfo,
IntByReference nFindCount) {
// RecordFileType 录像类型 0:所有录像 1:外部报警 2:动态监测报警 3:所有报警 4:卡号查询 5:组合条件查询 6:录像位置与偏移量长度 8:按卡号查询图片(目前仅HB-U和NVS特殊型号的设备支持) 9:查询图片(目前仅HB-U和NVS特殊型号的设备支持) 10:按字段查询 15:返回网络数据结构(金桥网吧) 16:查询所有透明串数据录像文件
int nRecordFileType = 0;
boolean bRet = netsdk.CLIENT_QueryRecordFile(m_hLoginHandle, nChannelId, nRecordFileType, stTimeStart, stTimeEnd, null, stFileInfo, stFileInfo.length * stFileInfo[0].size(), nFindCount, 5000, false);
if(bRet) {
System.out.println("QueryRecordFile Succeed! \n" + "查询到的视频个数:" + nFindCount.getValue());
} else {
System.err.println("QueryRecordFile Failed!" + netsdk.CLIENT_GetLastError());
return false;
}
return true;
}
public static void setStreamType(int m_streamType) {
// 设置回放时的码流类型
IntByReference steamType = new IntByReference(m_streamType);// 0-主辅码流,1-主码流,2-辅码流
int emType = NetSDKLib.EM_USEDEV_MODE.NET_RECORD_STREAM_TYPE;
boolean bret = netsdk.CLIENT_SetDeviceMode(m_hLoginHandle, emType, steamType.getPointer());
if (!bret) {
System.err.printf("Set Stream Type Failed, Get last error [0x%x]\n", netsdk.CLIENT_GetLastError());
} else {
System.out.println("Set Stream Type Succeed!");
}
}
public static NativeLong downloadRecordFile(int nChannelId,
int nRecordFileType,
NetSDKLib.NET_TIME stTimeStart,
NetSDKLib.NET_TIME stTimeEnd,
String SavedFileName,
NetSDKLib.fTimeDownLoadPosCallBack cbTimeDownLoadPos) {
m_hDownLoadHandle = netsdk.CLIENT_DownloadByTimeEx(m_hLoginHandle, nChannelId, nRecordFileType,
stTimeStart, stTimeEnd, SavedFileName,
cbTimeDownLoadPos, null, null, null, null);
if(m_hDownLoadHandle.longValue() != 0) {
System.out.println("Downloading RecordFile!");
} else {
System.err.println("Download RecordFile Failed!" + netsdk.CLIENT_GetLastError());
}
return m_hDownLoadHandle;
}
public static void stopDownLoadRecordFile(NativeLong m_hDownLoadHandle) {
if (m_hDownLoadHandle.longValue() == 0) {
return;
}
netsdk.CLIENT_StopDownload(m_hDownLoadHandle);
}
}

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

@ -0,0 +1,45 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dahua;
/**
*
* @author LENOVO
*/
public class Login extends javax.swing.JPanel {
/**
* Creates new form Login
*/
public Login() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

@ -0,0 +1,124 @@
package dahua;
import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
/** Provides a temporary allocation of an immutable C string
* (<code>const char*</code> or <code>const wchar_t*</code>) for use when
* converting a Java String into a native memory function argument.
*
* @author Todd Fast, todd.fast@sun.com
* @author twall@users.sf.net
*/
public class NativeString implements CharSequence, Comparable<Object> {
private Pointer pointer;
private boolean wide;
/** Create a native string (NUL-terminated array of <code>char</code>).<p>
* If the system property <code>jna.encoding</code> is set, its value will
* be used to encode the native string. If not set or if the encoding
* is unavailable, the default platform encoding will be used.
*/
public NativeString(String string) {
this(string, false);
}
/** Create a native string as a NUL-terminated array of <code>wchar_t</code>
* (if <code>wide</code> is true) or <code>char</code>.<p>
* If the system property <code>jna.encoding</code> is set, its value will
* be used to encode the native <code>char</code>string.
* If not set or if the encoding is unavailable, the default platform
* encoding will be used.
*
* @param string value to write to native memory
* @param wide whether to store the String as <code>wchar_t</code>
*/
public NativeString(String string, boolean wide) {
if (string == null) {
throw new NullPointerException("String must not be null");
}
// Allocate the memory to hold the string. Note, we have to
// make this 1 element longer in order to accommodate the terminating
// NUL (which is generated in Pointer.setString()).
this.wide = wide;
if (wide) {
int len = (string.length() + 1 ) * Native.WCHAR_SIZE;
pointer = new Memory(len);
pointer.setString(0, string, true);
}
else {
byte[] data = getBytes(string);
pointer = new Memory(data.length + 1);
pointer.write(0, data, 0, data.length);
pointer.setByte(data.length, (byte)0);
}
}
static byte[] getBytes(String s) {
try {
return getBytes(s, System.getProperty("jna.encoding"));
}
catch (UnsupportedEncodingException e) {
return s.getBytes();
}
}
/** Return a byte array corresponding to the given String, using the given
encoding.
*/
static byte[] getBytes(String s, String encoding) throws UnsupportedEncodingException {
if (encoding != null) {
return s.getBytes(encoding);
}
return s.getBytes();
}
public int hashCode() {
return toString().hashCode();
}
public boolean equals(Object other) {
if (other instanceof CharSequence) {
return compareTo(other) == 0;
}
return false;
}
public String toString() {
String s = wide ? "const wchar_t*" : "const char*";
s += "(" + pointer.getString(0, wide) + ")";
return s;
}
public Pointer getPointer() {
return pointer;
}
public char charAt(int index) {
return toString().charAt(index);
}
public int length() {
return toString().length();
}
public CharSequence subSequence(int start, int end) {
return CharBuffer.wrap(toString()).subSequence(start, end);
}
public int compareTo(Object other) {
if (other == null)
return 1;
return toString().compareTo(other.toString());
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,725 @@
package dahua;
import java.util.Locale;
import java.util.ResourceBundle;
import dahua.NetSDKLib;
public final class Res {
private ResourceBundle bundle;
private Res() {
switchLanguage(LanguageType.Chinese);
}
private static class StringBundleHolder {
private static Res instance = new Res();
}
public static Res string() {
return StringBundleHolder.instance;
}
public static enum LanguageType {
English,
Chinese
}
public ResourceBundle getBundle() {
return bundle;
}
/**
* \if ENGLISH_LANG
* Switch between Chinese and English
* \else
*
* \endif
*/
public void switchLanguage(LanguageType type) {
switch(type) {
case Chinese:
bundle = ResourceBundle.getBundle("res", new Locale("zh", "CN"));
break;
case English:
bundle = ResourceBundle.getBundle("res", new Locale("en", "US"));
break;
default:
break;
}
}
public String getSwitchLanguage() {
return bundle.getString("SWITCH_LANGUAGE");
}
public String getRealplay() {
return bundle.getString("REALPLAY");
}
public String getDownloadRecord() {
return bundle.getString("DOWNLOAD_RECORD");
}
public String getITSEvent() {
return bundle.getString("ITS_EVENT");
}
public String getOnline() {
return bundle.getString("ONLINE");
}
public String getDisConnectReconnecting() {
return bundle.getString("DISCONNECT_RECONNECTING");
}
public String getDisconnectLoginAgain() {
return bundle.getString("DISCONNECT_LOGIN_AGAIN");
}
public String getPromptMessage() {
return bundle.getString("PROMPT_MESSAGE");
}
public String getErrorMessage() {
return bundle.getString("ERROR_MESSAGE");
}
public String getReconnectSucceed() {
return bundle.getString("RECONNECT_SUCCEED");
}
public String getSucceed() {
return bundle.getString("SUCCEED");
}
public String getFailed() {
return bundle.getString("Failed");
}
public String getYear() {
return bundle.getString("YEAR");
}
public String getMonth() {
return bundle.getString("MONTH");
}
public String getDay() {
return bundle.getString("DAY");
}
public String getHour() {
return bundle.getString("HOUR");
}
public String getMinute() {
return bundle.getString("MINUTE");
}
public String getSecond() {
return bundle.getString("SECOND");
}
public String getSunday() {
return bundle.getString("SUNDAY");
}
public String getMonday() {
return bundle.getString("MONDAY");
}
public String getTuesday() {
return bundle.getString("TUESDAY");
}
public String getWednesday() {
return bundle.getString("WEDNESDAY");
}
public String getThursday() {
return bundle.getString("THURSDAY");
}
public String getFriday() {
return bundle.getString("FRIDAY");
}
public String getSaturday() {
return bundle.getString("SATURDAY");
}
public String[] getWeek() {
String[] weekdays = {getSunday(),
getMonday(),
getTuesday(),
getWednesday(),
getThursday(),
getFriday(),
getSaturday()
};
return weekdays;
}
public String getConfirm() {
return bundle.getString("CONFIRM");
}
public String getCancel() {
return bundle.getString("CANCEL");
}
public String getDateChooser() {
return bundle.getString("DATE_CHOOSER");
}
public String getFunctionList() {
return bundle.getString("FUNCTIONLIST");
}
/**
*
*/
public String getErrorCode(int err) {
String msg = "";
switch(err) {
case NetSDKLib.NET_INVALID_HANDLE:
msg = bundle.getString("NET_INVALID_HANDLE");
break;
case NetSDKLib.NET_USER_FLASEPWD_TRYTIME:
msg = bundle.getString("NET_USER_FLASEPWD_TRYTIME");
break;
case NetSDKLib.NET_LOGIN_ERROR_PASSWORD:
msg = bundle.getString("NET_LOGIN_ERROR_PASSWORD");
break;
case NetSDKLib.NET_LOGIN_ERROR_USER:
msg = bundle.getString("NET_LOGIN_ERROR_USER");
break;
case NetSDKLib.NET_LOGIN_ERROR_TIMEOUT:
msg = bundle.getString("NET_LOGIN_ERROR_TIMEOUT");
break;
case NetSDKLib.NET_LOGIN_ERROR_RELOGGIN:
msg = bundle.getString("NET_LOGIN_ERROR_RELOGGIN");
break;
case NetSDKLib.NET_LOGIN_ERROR_LOCKED:
msg = bundle.getString("NET_LOGIN_ERROR_LOCKED");
break;
case NetSDKLib.NET_LOGIN_ERROR_BLACKLIST:
msg = bundle.getString("NET_LOGIN_ERROR_BLACKLIST");
break;
case NetSDKLib.NET_LOGIN_ERROR_BUSY:
msg = bundle.getString("NET_LOGIN_ERROR_BUSY");
break;
case NetSDKLib.NET_LOGIN_ERROR_CONNECT:
msg = bundle.getString("NET_LOGIN_ERROR_CONNECT");
break;
case NetSDKLib.NET_LOGIN_ERROR_NETWORK:
msg = bundle.getString("NET_LOGIN_ERROR_NETWORK");
break;
case NetSDKLib.NET_NO_RECORD_FOUND:
msg = bundle.getString("NET_NO_RECORD_FOUND");
break;
case NetSDKLib.NET_OPEN_FILE_ERROR:
msg = bundle.getString("NET_OPEN_FILE_ERROR");
break;
case NetSDKLib.NET_ERROR:
msg = bundle.getString("NET_ERROR");
break;
case NetSDKLib.NET_RETURN_DATA_ERROR:
msg = bundle.getString("NET_RETURN_DATA_ERROR");
break;
case NetSDKLib.NET_LOGIN_ERROR_USER_OR_PASSOWRD:
msg = bundle.getString("NET_LOGIN_ERROR_USER_OR_PASSOWRD");
break;
default:
msg = bundle.getString("NET_ERROR");
break;
}
return msg;
}
public String getLogin() {
return bundle.getString("LOGIN");
}
public String getLogout() {
return bundle.getString("LOGOUT");
}
public String getDeviceIp() {
return bundle.getString("DEVICE_IP");
}
public String getPort() {
return bundle.getString("DEVICE_PORT");
}
public String getUserName() {
return bundle.getString("USERNAME");
}
public String getPassword() {
return bundle.getString("PASSWORD");
}
public String getLoginFailed() {
return bundle.getString("LOGIN_FAILED");
}
public String getInputDeviceIP() {
return bundle.getString("PLEASE_INPUT_DEVICE_IP");
}
public String getInputDevicePort() {
return bundle.getString("PLEASE_INPUT_DEVICE_PORT");
}
public String getInputUsername() {
return bundle.getString("PLEASE_INPUT_DEVICE_USERNAME");
}
public String getInputPassword() {
return bundle.getString("PLEASE_INPUT_DEVICE_PASSWORD");
}
public String getStartRealPlay() {
return bundle.getString("START_REALPLAY");
}
public String getStopRealPlay() {
return bundle.getString("STOP_REALPLAY");
}
public String getChannel() {
return bundle.getString("CHANNEL");
}
public String getStreamType() {
return bundle.getString("STREAM_TYPE");
}
public String getMasterAndSub() {
return bundle.getString("MASTER_AND_SUB_STREAM");
}
public String getMasterStream() {
return bundle.getString("MASTER_STREAM");
}
public String getSubStream() {
return bundle.getString("SUB_STREAM");
}
public String getSnap() {
return bundle.getString("SNAP");
}
public String getSnapPicture() {
return bundle.getString("SNAP_PICTURE");
}
public String getPTZControl() {
return bundle.getString("PTZ_CONTROL");
}
public String getLeftUp() {
return bundle.getString("LEFT_UP");
}
public String getUp() {
return bundle.getString("UP");
}
public String getRightUp() {
return bundle.getString("RIGHT_UP");
}
public String getLeft() {
return bundle.getString("LEFT");
}
public String getRight() {
return bundle.getString("RIGHT");
}
public String getLeftDown() {
return bundle.getString("LEFT_DOWN");
}
public String getDown() {
return bundle.getString("DOWN");
}
public String getRightDown() {
return bundle.getString("RIGHT_DOWN");
}
public String getSpeed() {
return bundle.getString("SPEED");
}
public String getZoomAdd() {
return bundle.getString("ZOOM_ADD");
}
public String getZoomDec() {
return bundle.getString("ZOOM_DEC");
}
public String getFocusAdd() {
return bundle.getString("FOCUS_ADD");
}
public String getFocusDec() {
return bundle.getString("FOCUS_DEC");
}
public String getIrisAdd() {
return bundle.getString("IRIS_ADD");
}
public String getIrisDec() {
return bundle.getString("IRIS_DEC");
}
public String getIndex() {
return bundle.getString("INDEX");
}
public String getEventPicture() {
return bundle.getString("EVENT_PICTURE");
}
public String getPlatePicture() {
return bundle.getString("PLATE_PICTURE");
}
public String getEventName() {
return bundle.getString("EVENT_NAME");
}
public String getLicensePlate() {
return bundle.getString("LICENSE_PLATE");
}
public String getEventTime() {
return bundle.getString("EVENT_TIME");
}
public String getPlateType() {
return bundle.getString("PLATE_TYPE");
}
public String getPlateColor() {
return bundle.getString("PLATE_COLOR");
}
public String getVehicleColor() {
return bundle.getString("VEHICLE_COLOR");
}
public String getVehicleType() {
return bundle.getString("VEHICLE_TYPE");
}
public String getVehicleSize() {
return bundle.getString("VEHICLE_SIZE");
}
public String getFileCount() {
return bundle.getString("FILE_COUNT");
}
public String getFileIndex() {
return bundle.getString("FILE_INDEX");
}
public String getGroupId() {
return bundle.getString("GROUP_ID");
}
public String getIllegalPlace() {
return bundle.getString("ILLEGAL_PLACE");
}
public String getLaneNumber() {
return bundle.getString("LANE_NUMBER");
}
public String getEventInfo() {
return bundle.getString("EVENT_INFO");
}
public String getNoPlate() {
return bundle.getString("NO_PLATENUMBER");
}
public String[] getTrafficTableName() {
String[] name = {getIndex(),
getEventName(),
getLicensePlate(),
getEventTime(),
getPlateType(),
getPlateColor(),
getVehicleColor(),
getVehicleType(),
getVehicleSize(),
getFileCount(),
getFileIndex(),
getGroupId(),
getIllegalPlace(),
getLaneNumber()};
return name;
}
public String getOperate() {
return bundle.getString("OPERATE");
}
public String getAttach() {
return bundle.getString("ATTACH");
}
public String getDetach() {
return bundle.getString("DETACH");
}
public String getOpenStrobe() {
return bundle.getString("OPEN_STROBE");
}
public String getCloseStrobe() {
return bundle.getString("CLOSE_STROBE");
}
public String getOpenStrobeFailed() {
return bundle.getString("OPEN_STROBE_FAILED");
}
public String getManualCapture() {
return bundle.getString("MANUAL_CAPTURE");
}
public String getManualCaptureSucceed() {
return bundle.getString("MANUALSNAP_SUCCEED");
}
public String getManualCaptureFailed() {
return bundle.getString("MANUALSNAP_FAILED");
}
/*
*
*/
public String getTrafficSize(int nVehicleSize) {
String vehicleClass = "";
for(int i = 0; i < 5; i++) {
if( ((byte)nVehicleSize & (1 << i)) > 0 ) {
switch (i) {
case 0:
vehicleClass = bundle.getString("LIGHT_DUTY");
break;
case 1:
vehicleClass = bundle.getString("MEDIUM");
break;
case 2:
vehicleClass = bundle.getString("OVER_SIZE");
break;
case 3:
vehicleClass = bundle.getString("MINI_SIZE");
break;
case 4:
vehicleClass = bundle.getString("LARGE_SIZE");
break;
default:
break;
}
}
}
return vehicleClass;
}
/*
*
*/
public String getEventName(int type) {
String name = "";
switch (type) {
case NetSDKLib.EVENT_IVS_TRAFFICJUNCTION: ///< 交通路口事件
name = bundle.getString("EVENT_IVS_TRAFFICJUNCTION");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_RUNREDLIGHT: ///< 闯红灯事件
name = bundle.getString("EVENT_IVS_TRAFFIC_RUNREDLIGHT");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_OVERLINE: ///< 压车道线事件
name = bundle.getString("EVENT_IVS_TRAFFIC_OVERLINE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_RETROGRADE: ///< 逆行事件
name = bundle.getString("EVENT_IVS_TRAFFIC_RETROGRADE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_TURNLEFT: ///< 违章左转
name = bundle.getString("EVENT_IVS_TRAFFIC_TURNLEFT");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_TURNRIGHT: ///< 违章右转
name = bundle.getString("EVENT_IVS_TRAFFIC_TURNRIGHT");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_UTURN: ///< 违章掉头
name = bundle.getString("EVENT_IVS_TRAFFIC_UTURN");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_OVERSPEED: ///< 超速
name = bundle.getString("EVENT_IVS_TRAFFIC_OVERSPEED");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_UNDERSPEED: ///< 低速
name = bundle.getString("EVENT_IVS_TRAFFIC_UNDERSPEED");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_PARKING: ///< 违章停车
name = bundle.getString("EVENT_IVS_TRAFFIC_PARKING");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_WRONGROUTE: ///< 不按车道行驶
name = bundle.getString("EVENT_IVS_TRAFFIC_WRONGROUTE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_CROSSLANE: ///< 违章变道
name = bundle.getString("EVENT_IVS_TRAFFIC_CROSSLANE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_OVERYELLOWLINE: ///< 压黄线
name = bundle.getString("EVENT_IVS_TRAFFIC_OVERYELLOWLINE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_YELLOWPLATEINLANE: ///< 黄牌车占道事件
name = bundle.getString("EVENT_IVS_TRAFFIC_YELLOWPLATEINLANE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_PEDESTRAINPRIORITY: ///< 斑马线行人优先事件
name = bundle.getString("EVENT_IVS_TRAFFIC_PEDESTRAINPRIORITY");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_MANUALSNAP: ///< 交通手动抓拍事件
name = bundle.getString("EVENT_IVS_TRAFFIC_MANUALSNAP");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_VEHICLEINROUTE: ///< 有车占道事件
name = bundle.getString("EVENT_IVS_TRAFFIC_VEHICLEINROUTE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_VEHICLEINBUSROUTE: ///< 占用公交车道事件
name = bundle.getString("EVENT_IVS_TRAFFIC_VEHICLEINBUSROUTE");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_BACKING: ///< 违章倒车事件
name = bundle.getString("EVENT_IVS_TRAFFIC_BACKING");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_PARKINGSPACEPARKING: ///< 车位有车事件
name = bundle.getString("EVENT_IVS_TRAFFIC_PARKINGSPACEPARKING");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_PARKINGSPACENOPARKING: ///< 车位无车事件
name = bundle.getString("EVENT_IVS_TRAFFIC_PARKINGSPACENOPARKING");
break;
case NetSDKLib.EVENT_IVS_TRAFFIC_WITHOUT_SAFEBELT: ///< 交通未系安全带事件
name = bundle.getString("EVENT_IVS_TRAFFIC_WITHOUT_SAFEBELT");
break;
default:
break;
}
return name;
}
public String getRecordType() {
return bundle.getString("RECORD_TYPE");
}
public String getStartTime() {
return bundle.getString("START_TIME");
}
public String getEndTime() {
return bundle.getString("END_TIME");
}
public String[] getDownloadTableName() {
String[] name = {getIndex(),
getChannel(),
getRecordType(),
getStartTime(),
getEndTime()};
return name;
}
public String getDownloadByFile() {
return bundle.getString("DOWNLOAD_RECORD_BYFILE");
}
public String getQuery() {
return bundle.getString("QUERY");
}
public String getDownload() {
return bundle.getString("DOWNLOAD");
}
public String getStopDownload() {
return bundle.getString("STOP_DOWNLOAD");
}
public String getDownloadByTime() {
return bundle.getString("DOWNLOAD_RECORD_BYTIME");
}
public String getSelectTimeAgain() {
return bundle.getString("PLEASE_SELECT_TIME_AGAIN");
}
public String getSelectRowWithData() {
return bundle.getString("PLEASE_FIRST_SELECT_ROW_WITH_DATA");
}
public String getQueryRecord() {
return bundle.getString("PLEASE_FIRST_QUERY_RECORD");
}
public String getDownloadCompleted() {
return bundle.getString("DOWNLOAD_COMPLETED");
}
/**
*
*/
public String getRecordTypeStr(int nRecordFileType) {
String recordTypeStr = "";
switch(nRecordFileType) {
case 0:
recordTypeStr = bundle.getString("GENERAL_RECORD");
break;
case 1:
recordTypeStr = bundle.getString("ALARM_RECORD");
break;
case 2:
recordTypeStr = bundle.getString("MOTION_DETECTION");
break;
case 3:
recordTypeStr = bundle.getString("CARD_NUMBER_RECORD");
break;
default:
break;
}
return recordTypeStr;
}
public int getRecordTypeInt(String recordFileStr) {
int recordType = -1;
if(recordFileStr.equals(bundle.getString("GENERAL_RECORD"))) {
recordType = 0;
} else if(recordFileStr.equals(bundle.getString("ALARM_RECORD"))) {
recordType = 1;
} else if(recordFileStr.equals(bundle.getString("MOTION_DETECTION"))) {
recordType = 2;
} else if(recordFileStr.equals(bundle.getString("CARD_NUMBER_RECORD"))) {
recordType = 3;
}
return recordType;
}
}

@ -0,0 +1,76 @@
package dahua;
import java.io.File;
import dahua.ToolKits;
public class SavePath {
private SavePath() {}
private static class SavePathHolder {
private static SavePath instance = new SavePath();
}
public static SavePath getSavePath() {
return SavePathHolder.instance;
}
String s_captureSavePath = "./Capture/" + ToolKits.getDate() + "/"; // 抓拍图片保存路径
String s_imageSavePath = "./Image/" + ToolKits.getDate() + "/"; // 图片保存路径
String s_recordFileSavePath = "./RecordFile/" + ToolKits.getDate() + "/"; // 录像保存路径
/*
*
*/
public String getSaveSnapPath() {
File path1 = new File("./Capture/");
if (!path1.exists()) {
path1.mkdir();
}
File path2 = new File(s_captureSavePath);
if (!path2.exists()) {
path2.mkdir();
}
String strFileName = s_captureSavePath + ToolKits.getDate() + ".jpg";
return strFileName;
}
/*
*
*/
public String getSaveTrafficImagePath() {
File path1 = new File("./Image/");
if (!path1.exists()) {
path1.mkdir();
}
File path = new File(s_imageSavePath);
if (!path.exists()) {
path.mkdir();
}
return s_imageSavePath;
}
/*
*
*/
public String getSaveRecordFilePath() {
File path1 = new File("./RecordFile/");
if (!path1.exists()) {
path1.mkdir();
}
File path2 = new File(s_recordFileSavePath);
if (!path2.exists()) {
path2.mkdir();
}
String SavedFileName = s_recordFileSavePath + ToolKits.getDate() + ".dav"; // 默认保存路径
return SavedFileName;
}
}

@ -0,0 +1,194 @@
package dahua;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
public class ToolKits {
/***************************************************************************************************
* *
***************************************************************************************************/
public static void GetPointerData(Pointer pNativeData, Structure pJavaStu) {
GetPointerDataToStruct(pNativeData, 0, pJavaStu);
}
public static void GetPointerDataToStruct(Pointer pNativeData, long OffsetOfpNativeData, Structure pJavaStu) {
pJavaStu.write();
Pointer pJavaMem = pJavaStu.getPointer();
pJavaMem.write(0, pNativeData.getByteArray(OffsetOfpNativeData, pJavaStu.size()), 0, pJavaStu.size());
pJavaStu.read();
}
public static void GetPointerDataToStructArr(Pointer pNativeData, Structure[] pJavaStuArr) {
long offset = 0;
for (int i = 0; i < pJavaStuArr.length; ++i) {
GetPointerDataToStruct(pNativeData, offset, pJavaStuArr[i]);
offset += pJavaStuArr[i].size();
}
}
/**
*
*
* @param pNativeData
* @param pJavaStuArr
*/
public static void SetStructArrToPointerData(Structure[] pJavaStuArr, Pointer pNativeData) {
long offset = 0;
for (int i = 0; i < pJavaStuArr.length; ++i) {
SetStructDataToPointer(pJavaStuArr[i], pNativeData, offset);
offset += pJavaStuArr[i].size();
}
}
public static void SetStructDataToPointer(Structure pJavaStu, Pointer pNativeData, long OffsetOfpNativeData) {
pJavaStu.write();
Pointer pJavaMem = pJavaStu.getPointer();
pNativeData.write(OffsetOfpNativeData, pJavaMem.getByteArray(0, pJavaStu.size()), 0, pJavaStu.size());
}
public static void savePicture(byte[] pBuf, String sDstFile) {
try {
FileOutputStream fos = new FileOutputStream(sDstFile);
fos.write(pBuf);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void savePicture(byte[] pBuf, int dwBufOffset, int dwBufSize, String sDstFile) {
try {
FileOutputStream fos = new FileOutputStream(sDstFile);
fos.write(pBuf, dwBufOffset, dwBufSize);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void savePicture(Pointer pBuf, int dwBufSize, String sDstFile) {
try {
FileOutputStream fos = new FileOutputStream(sDstFile);
fos.write(pBuf.getByteArray(0, dwBufSize), 0, dwBufSize);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void savePicture(Pointer pBuf, int dwBufOffset, int dwBufSize, String sDstFile) {
try {
FileOutputStream fos = new FileOutputStream(sDstFile);
fos.write(pBuf.getByteArray(dwBufOffset, dwBufSize), 0, dwBufSize);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// 将Pointer值转为byte[]
public static String GetPointerDataToByteArr(Pointer pointer) {
String str = "";
if (pointer == null) {
return str;
}
int length = 0;
byte[] bufferPlace = new byte[1];
for (int i = 0; i < 2048; i++) {
pointer.read(i, bufferPlace, 0, 1);
if (bufferPlace[0] == '\0') {
length = i;
break;
}
}
if (length > 0) {
byte[] buffer = new byte[length];
pointer.read(0, buffer, 0, length);
try {
str = new String(buffer, "GBK").trim();
} catch (UnsupportedEncodingException e) {
return str;
}
}
return str;
}
// 获取当前时间
public static String getDate() {
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = simpleDate.format(new java.util.Date()).replace(" ", "_").replace(":", "-");
return date;
}
// 限制JTextField 长度,以及内容
public static void limitTextFieldLength(final JTextField jTextField, final int size) {
jTextField.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
String number = "0123456789" + (char) 8;
if (number.indexOf(e.getKeyChar()) < 0 || jTextField.getText().trim().length() >= size) {
e.consume();
return;
}
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
});
}
// 获取当前窗口
public static JFrame getFrame(ActionEvent e) {
JButton btn = (JButton) e.getSource();
JFrame frame = (JFrame) btn.getRootPane().getParent();
return frame;
}
// 获取操作平台信息
public static String getLoadLibrary(String library) {
String path = "";
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
path = "./libs/";
} else if (os.toLowerCase().startsWith("linux")) {
path = "";
}
return (path + library);
}
public static String getOsName() {
String osName = "";
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) {
osName = "win";
} else if (os.toLowerCase().startsWith("linux")) {
osName = "linux";
}
return osName;
}
}

@ -0,0 +1,32 @@
package dahua;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import com.sun.jna.Platform;
public class Utils {
public Utils() {
}
// 读取当前目录下的路径配置文件
public static String readConfigProperties(String key) {
Properties properties = new Properties();
String rootPath = System.getProperty("user.dir").replace("\\", "/"); // 获取当前目录
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(rootPath + "/config.properties");
properties.load(inputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
return properties.getProperty(key);
}
}
Loading…
Cancel
Save