Commit 2f14cbdc authored by captainwong's avatar captainwong

save

parent ca3d73fc
...@@ -11,8 +11,14 @@ import java.util.*; ...@@ -11,8 +11,14 @@ import java.util.*;
import com.hb3344.ademco.*; import com.hb3344.ademco.*;
public class JavaDemo { public class JavaDemo {
static {
try {
System.loadLibrary("ademco");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
private Selector selector; private Selector selector;
private Map<SocketChannel, Client> clients; private Map<SocketChannel, Client> clients;
...@@ -72,64 +78,6 @@ public class JavaDemo { ...@@ -72,64 +78,6 @@ public class JavaDemo {
clients.get(channel).onMsg(data); clients.get(channel).onMsg(data);
} }
static {
try {
System.loadLibrary("ademco");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
public static String printable_bytes(byte[] b){
return printable_bytes(b, b.length);
}
public static String printable_bytes(byte[] b, int length){
String HEX_STRING = "0123456789ABCDEF";
String s = "";
for(int i = 0; i < length; i++){
byte c = b[i];
if(32 <= c && c <= 127){
s += (char)c;
}else{
s += "\\x" + HEX_STRING.charAt((b[i] >>> 4) & 0x0F);
s += HEX_STRING.charAt(b[i] & 0x0F);
}
}
return s;
}
public static String printable_bytes(char[] b){
String HEX_STRING = "0123456789ABCDEF";
String s = "";
for(int i = 0; i < b.length; i++){
int c = b[i] & 0xFF;
if(32 <= c && c <= 127){
s += (char)c;
}else{
s += "\\x" + HEX_STRING.charAt(c >>> 4);
s += HEX_STRING.charAt(c & 0x0F);
}
}
return s;
}
public static String printable_bytes(String b){
String HEX_STRING = "0123456789ABCDEF";
String s = "";
for(int i = 0; i < b.length(); i++){
char c = b.charAt(i);
if(32 <= c && c <= 127){
s += (char)c;
}else{
s += "\\x" + HEX_STRING.charAt(c >>> 4);
s += HEX_STRING.charAt(c & 0x0F);
}
}
return s;
}
public static void test_libademco(){ public static void test_libademco(){
// test parse // test parse
{ {
...@@ -202,8 +150,7 @@ public class JavaDemo { ...@@ -202,8 +150,7 @@ public class JavaDemo {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
JavaDemo.test_libademco(); JavaDemo.test_libademco();
int port = 12345; int port = 12345;
if (args.length > 0){ if (args.length > 0){
...@@ -348,6 +295,55 @@ public class JavaDemo { ...@@ -348,6 +295,55 @@ public class JavaDemo {
} }
} }
public static String printable_bytes(byte[] b){
return printable_bytes(b, b.length);
}
public static String printable_bytes(byte[] b, int length){
String HEX_STRING = "0123456789ABCDEF";
String s = "";
for(int i = 0; i < length; i++){
byte c = b[i];
if(32 <= c && c <= 127){
s += (char)c;
}else{
s += "\\x" + HEX_STRING.charAt((b[i] >>> 4) & 0x0F);
s += HEX_STRING.charAt(b[i] & 0x0F);
}
}
return s;
}
public static String printable_bytes(char[] b){
String HEX_STRING = "0123456789ABCDEF";
String s = "";
for(int i = 0; i < b.length; i++){
int c = b[i] & 0xFF;
if(32 <= c && c <= 127){
s += (char)c;
}else{
s += "\\x" + HEX_STRING.charAt(c >>> 4);
s += HEX_STRING.charAt(c & 0x0F);
}
}
return s;
}
public static String printable_bytes(String b){
String HEX_STRING = "0123456789ABCDEF";
String s = "";
for(int i = 0; i < b.length(); i++){
char c = b.charAt(i);
if(32 <= c && c <= 127){
s += (char)c;
}else{
s += "\\x" + HEX_STRING.charAt(c >>> 4);
s += HEX_STRING.charAt(c & 0x0F);
}
}
return s;
}
public static char[] append(char[]origin, char[] buf){ public static char[] append(char[]origin, char[] buf){
char[] dst = new char[origin.length + buf.length]; char[] dst = new char[origin.length + buf.length];
System.arraycopy(origin, 0, dst, 0, origin.length); System.arraycopy(origin, 0, dst, 0, origin.length);
...@@ -383,4 +379,4 @@ public class JavaDemo { ...@@ -383,4 +379,4 @@ public class JavaDemo {
} }
return b; return b;
} }
} }
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
mkdir com\hb3344\ademco
"C:\Users\Jack\Downloads\swigwin-3.0.12\swig.exe" -java -package com.hb3344.ademco -outdir com/hb3344/ademco -o ademco_java_wrap.c libademco.swig
cl -c ../ademco.c ademco_java_wrap.c -I"../" -I"%JAVA_HOME%include" -I"%JAVA_HOME%include/win32"
cl -LD ademco.obj ademco_java_wrap.obj -o ademco.dll
mkdir com\hb3344\ademco
"C:\Users\Jack\Downloads\swigwin-3.0.12\swig.exe" -java -package com.hb3344.ademco -outdir com/hb3344/ademco -o libademco_java_wrap.c libademco.swig
cl -c ../ademco.c libademco_java_wrap.c -I"../" -I"%JAVA_HOME%include" -I"%JAVA_HOME%include/win32"
cl -LD ademco.obj libademco_java_wrap.obj -o ademco.dll
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment