Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ademco_hb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
ademco_hb
Commits
89fdc440
Commit
89fdc440
authored
Jul 08, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update pack2
parent
21e2ec9d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
dllmain.cpp
examples/javademo/cpp/dllmain.cpp
+2
-1
SimpleServerThread.java
examples/javademo/jni/SimpleServerThread.java
+32
-0
No files found.
examples/javademo/cpp/dllmain.cpp
View file @
89fdc440
...
...
@@ -88,7 +88,8 @@ JNIEXPORT jstring JNICALL Java_javademo_jni_AdemcoHbLibrary_pack2
nullptr
,
static_cast
<
size_t
>
(
ademco_id
),
static_cast
<
unsigned
char
>
(
gg
),
static_cast
<
ademco
::
ADEMCO_EVENT
>
(
ademco_event
),
static_cast
<
size_t
>
(
zone
),
xdata_
);
if
(
res
>
0
)
{
buff
[
res
]
=
0
;
auto
ascii
=
ademco
::
detail
::
toString
(
buff
,
res
,
ademco
::
detail
::
ToStringOption
::
ALL_CHAR_AS_HEX
,
false
,
false
);
memcpy
(
buff
,
ascii
.
data
(),
ascii
.
size
());
return
env
->
NewStringUTF
(
buff
);
}
return
0
;
...
...
examples/javademo/jni/SimpleServerThread.java
View file @
89fdc440
...
...
@@ -7,12 +7,32 @@ import java.util.regex.*;
public
class
SimpleServerThread
extends
Thread
{
private
Socket
socket
;
private
AdemcoHbLibrary
lib
;
private
long
lastTimeStatusChange
=
0
;
public
SimpleServerThread
(
Socket
socket
,
AdemcoHbLibrary
lib
)
{
this
.
socket
=
socket
;
this
.
lib
=
lib
;
}
/**
* 16进制表示的字符串转换为字节数组
*
* @param s 16进制表示的字符串
* @return byte[] 字节数组
*/
public
static
byte
[]
hexStringToByteArray
(
String
s
)
{
int
len
=
s
.
length
();
byte
[]
b
=
new
byte
[
len
/
2
];
for
(
int
i
=
0
;
i
<
len
;
i
+=
2
)
{
// 两位一组,表示一个字节,把这样表示的16进制字符串,还原成一个字节
b
[
i
/
2
]
=
(
byte
)
((
Character
.
digit
(
s
.
charAt
(
i
),
16
)
<<
4
)
+
Character
.
digit
(
s
.
charAt
(
i
+
1
),
16
));
}
return
b
;
}
public
void
run
()
{
try
{
InputStream
input
=
socket
.
getInputStream
();
...
...
@@ -74,6 +94,18 @@ public class SimpleServerThread extends Thread {
System
.
out
.
println
(
"Found ademco_event: "
+
ademco_event
);
System
.
out
.
println
(
"Found gg: "
+
gg
);
System
.
out
.
println
(
"Found zone: "
+
zone
);
if
(
ademco_event
==
3400
||
ademco_event
==
1400
){
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
lastTimeStatusChange
>
5000
){
lastTimeStatusChange
=
now
;
String
cmd
=
lib
.
pack2
(
seq
+
1
,
ademco_id16
,
ademco_event
==
3400
?
1400
:
3400
,
gg
,
zone
,
"123456"
);
System
.
out
.
println
(
"sending command:"
+
cmd
);
byte
[]
data
=
hexStringToByteArray
(
cmd
);
output
.
write
(
data
);
output
.
flush
();
}
}
}
else
{
System
.
out
.
println
(
"r2 NO MATCH"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment