2014-01-24 11:41:56 +01:00
|
|
|
package org.hwo.pulscounter;
|
|
|
|
|
2014-02-03 10:52:19 +01:00
|
|
|
import java.io.File;
|
2014-10-20 21:32:52 +02:00
|
|
|
import java.io.IOException;
|
2014-02-03 10:52:19 +01:00
|
|
|
import java.lang.reflect.Field;
|
2014-10-20 21:32:52 +02:00
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.prefs.Preferences;
|
2014-02-03 10:52:19 +01:00
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
import org.hwo.beacon.Beacon;
|
2014-02-03 10:52:19 +01:00
|
|
|
import org.hwo.os.OsDetect;
|
|
|
|
import org.hwo.os.OsDetect.OsType;
|
2014-10-20 21:32:52 +02:00
|
|
|
import org.hwo.rpc.json.RPCAdapter;
|
|
|
|
import org.hwo.rpc.simple.SimpleRPCServer;
|
2014-02-03 10:52:19 +01:00
|
|
|
|
2014-01-24 11:41:56 +01:00
|
|
|
public class PulsCounter {
|
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
static private Preferences prefs;
|
|
|
|
public static Preferences getPrefs() {
|
|
|
|
return prefs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static private IPulsCounter deviceConnection;
|
|
|
|
public static IPulsCounter getDeviceConnection() {
|
|
|
|
return deviceConnection;
|
|
|
|
}
|
|
|
|
public static void setDeviceConnection(IPulsCounter deviceConnection) {
|
|
|
|
PulsCounter.deviceConnection = deviceConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Beacon beacon;
|
|
|
|
public static Beacon getBeacon() {
|
|
|
|
return beacon;
|
|
|
|
}
|
|
|
|
|
|
|
|
static boolean serverMode;
|
|
|
|
|
2014-01-24 11:41:56 +01:00
|
|
|
|
|
|
|
public static void main(String args[])
|
|
|
|
{
|
2014-02-03 10:52:19 +01:00
|
|
|
File cwd = new File(".");
|
|
|
|
|
|
|
|
System.err.println("Starting on OS: " + System.getProperty("os.name"));
|
|
|
|
System.err.println("Current Directory: " + cwd.getAbsolutePath());
|
|
|
|
System.err.println("Library Path: " + System.getProperty("java.library.path"));
|
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
prefs = Preferences.userRoot();
|
|
|
|
|
2014-02-03 10:52:19 +01:00
|
|
|
if (OsDetect.getOperatingSystem() == OsType.LINUX)
|
|
|
|
{
|
|
|
|
System.err.println("Linux erkannt. Patche java.library.path");
|
|
|
|
System.setProperty("java.library.path",String.format(".:%s",System.getProperty("java.library.path")));
|
|
|
|
Field fieldSysPath;
|
|
|
|
try {
|
|
|
|
fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
|
|
|
|
fieldSysPath.setAccessible( true );
|
|
|
|
fieldSysPath.set( null, null );
|
|
|
|
} catch (SecurityException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
System.err.println("Library Path: " + System.getProperty("java.library.path"));
|
|
|
|
}
|
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
Iterator<String> options = Arrays.asList(args).iterator();
|
2014-01-24 11:41:56 +01:00
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
while (options.hasNext()) {
|
|
|
|
String no = options.next();
|
|
|
|
|
|
|
|
if (no.equals("-s")) {
|
|
|
|
serverMode = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceConnection = null;
|
2014-01-24 11:41:56 +01:00
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
beacon = new Beacon(44556);
|
|
|
|
beacon.getProperties().setProperty("rpc.simple.interfaces", "org.hwo.pulsecounter");
|
|
|
|
beacon.getProperties().setProperty("rpc.simple.port", "44352");
|
|
|
|
beacon.setServerOnly(serverMode);
|
|
|
|
beacon.start();
|
|
|
|
|
|
|
|
try {
|
|
|
|
NewPulsCounterDevice device = new NewPulsCounterDevice();
|
|
|
|
|
|
|
|
SimpleRPCServer rpcserver = new SimpleRPCServer(InetAddress.getByName("0.0.0.0"), 44352);
|
|
|
|
rpcserver.registerObject(IPulsCounter.class, device);
|
|
|
|
rpcserver.start();
|
|
|
|
|
|
|
|
} catch (UnknownHostException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2014-01-24 11:41:56 +01:00
|
|
|
|
2014-10-20 21:32:52 +02:00
|
|
|
if (!serverMode) {
|
|
|
|
PulsCounterWindow window = new PulsCounterWindow();
|
|
|
|
window.setVisible(true);
|
|
|
|
}
|
2014-01-24 11:41:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|