use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project BowlerStudio by CommonWealthRobotics.
the class TestServer method main.
public static void main(String[] args) throws Exception {
class SampleBowlerServer extends BowlerAbstractServer {
BowlerAbstractDeviceServerNamespace ns = new BowlerAbstractDeviceServerNamespace(getMacAddress(), "test.thingy.*;0.3;;") {
};
public SampleBowlerServer() {
super(new MACAddress());
ns.addRpc(new RpcEncapsulation(ns.getNamespaceIndex(), ns.getNamespace(), "test", BowlerMethod.GET, new BowlerDataType[] { BowlerDataType.I32, BowlerDataType.I32, // send 3
BowlerDataType.I32 }, // integers
BowlerMethod.POST, new BowlerDataType[] { BowlerDataType.I32, BowlerDataType.I32, // get 3 integers back
BowlerDataType.I32 }, new IBowlerCommandProcessor() {
public Object[] process(Object[] data) {
for (int i = 0; i < data.length; i++) {
System.out.println("Server Got # " + data[i]);
}
return new Object[] { 37, 42, 999999 };
}
}));
addBowlerDeviceServerNamespace(ns);
Log.info("Starting UDP");
try {
startNetworkServer(1865);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// starts the UDP server
// this also starts tcp server on port+1, in this case 1866
}
}
class SampleBowlerClient extends BowlerAbstractDevice {
public void runCommand() {
Object[] args = send("test.thingy.*;0.3;;", BowlerMethod.GET, "test", // send some numbers
new Object[] { 36, 83, 13 });
for (int i = 0; i < args.length; i++) {
System.out.println("Client Received # " + args[i]);
}
}
@Override
public void onAsyncResponse(BowlerDatagram data) {
}
// no async in this demo
}
SampleBowlerClient client = new SampleBowlerClient();
// client.setConnection(new UDPBowlerConnection(InetAddress.getByName("127.0.0.1"), 1865));
// Alternately you can use the tcp connection
client.setConnection(new BowlerTCPClient("127.0.0.1", 1866));
DeviceManager.addConnection(client, "sampleClient");
// runs our test command from client to server and
client.runCommand();
// back
}
use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project bowler-script-kernel by CommonWealthRobotics.
the class FileWatchDeviceWrapper method watch.
public static FileChangeWatcher watch(BowlerAbstractDevice device, File code, IFileChangeListener cadWatcher) {
try {
FileChangeWatcher watcher = FileChangeWatcher.watch(code);
watcher.addIFileChangeListener(cadWatcher);
device.addConnectionEventListener(new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice arg0) {
// TODO Auto-generated method stub
watcher.removeIFileChangeListener(cadWatcher);
}
@Override
public void onConnect(BowlerAbstractDevice arg0) {
// TODO Auto-generated method stub
}
});
return watcher;
} catch (IOException e) {
// TODO Auto-generated catch block
// BowlerStudioController.highlightException(code, e);
}
return null;
}
use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project bowler-script-kernel by CommonWealthRobotics.
the class GroovyHelper method inline.
private Object inline(Object code, ArrayList<Object> args) throws Exception {
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(new ImportCustomizer().addStarImports(ScriptingEngine.getImports()).addStaticStars("com.neuronrobotics.sdk.util.ThreadUtil", "eu.mihosoft.vrl.v3d.Transform", "com.neuronrobotics.bowlerstudio.vitamins.Vitamins"));
Binding binding = new Binding();
for (String pm : DeviceManager.listConnectedDevice()) {
BowlerAbstractDevice bad = DeviceManager.getSpecificDevice(null, pm);
try {
// groovy needs the objects cas to thier actual type befor
// passing into the scipt
binding.setVariable(bad.getScriptingName(), Class.forName(bad.getClass().getName()).cast(bad));
} catch (Throwable e) {
// throw e;
}
// System.err.println("Device " + bad.getScriptingName() + " is "
// + bad);
}
binding.setVariable("args", args);
GroovyShell shell = new GroovyShell(GroovyHelper.class.getClassLoader(), binding, cc);
// System.out.println(code + "\n\nStart\n\n");
Script script;
if (String.class.isInstance(code)) {
script = shell.parse((String) code);
} else if (File.class.isInstance(code)) {
script = shell.parse((File) code);
} else {
return null;
}
return script.run();
}
use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project bowler-script-kernel by CommonWealthRobotics.
the class JythonHelper method inlineScriptRun.
@Override
public Object inlineScriptRun(String code, ArrayList<Object> args) {
Properties props = new Properties();
PythonInterpreter.initialize(System.getProperties(), props, new String[] { "" });
if (interp == null) {
interp = new PythonInterpreter();
interp.exec("import sys");
}
for (String pm : DeviceManager.listConnectedDevice(null)) {
BowlerAbstractDevice bad = DeviceManager.getSpecificDevice(null, pm);
// passing into the scipt
try {
interp.set(bad.getScriptingName(), Class.forName(bad.getClass().getName()).cast(bad));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.err.println("Device " + bad.getScriptingName() + " is " + bad);
}
interp.set("args", args);
interp.exec(code);
ArrayList<Object> results = new ArrayList<>();
PyObject localVariables = interp.getLocals();
try {
results.add(interp.get("csg", CSG.class));
} catch (Exception e) {
e.printStackTrace();
}
try {
results.add(interp.get("tab", Tab.class));
} catch (Exception e) {
e.printStackTrace();
}
try {
results.add(interp.get("device", BowlerAbstractDevice.class));
} catch (Exception e) {
e.printStackTrace();
}
Log.debug("Jython return = " + results);
return results;
}
use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project bowler-script-kernel by CommonWealthRobotics.
the class MobileBaseCadManager method get.
public static MobileBaseCadManager get(MobileBase device) {
if (cadmap.get(device) == null) {
IMobileBaseUIlocal ui2 = new IMobileBaseUIlocal();
device.addConnectionEventListener(new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
ui2.list.clear();
}
@Override
public void onConnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
}
});
return get(device, ui2);
}
return cadmap.get(device);
}
Aggregations