Search in sources :

Example 1 with BowlerAbstractDevice

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
}
Also used : IBowlerCommandProcessor(com.neuronrobotics.sdk.common.device.server.IBowlerCommandProcessor) BowlerAbstractDeviceServerNamespace(com.neuronrobotics.sdk.common.device.server.BowlerAbstractDeviceServerNamespace) IOException(java.io.IOException) BowlerDataType(com.neuronrobotics.sdk.common.BowlerDataType) BowlerTCPClient(com.neuronrobotics.sdk.network.BowlerTCPClient) BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) MACAddress(com.neuronrobotics.sdk.common.MACAddress) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) BowlerAbstractServer(com.neuronrobotics.sdk.common.device.server.BowlerAbstractServer) RpcEncapsulation(com.neuronrobotics.sdk.common.RpcEncapsulation)

Example 2 with BowlerAbstractDevice

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;
}
Also used : BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) IDeviceConnectionEventListener(com.neuronrobotics.sdk.common.IDeviceConnectionEventListener) IOException(java.io.IOException)

Example 3 with BowlerAbstractDevice

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();
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) File(java.io.File) GroovyShell(groovy.lang.GroovyShell)

Example 4 with BowlerAbstractDevice

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;
}
Also used : PythonInterpreter(org.python.util.PythonInterpreter) BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) Tab(javafx.scene.control.Tab) CSG(eu.mihosoft.vrl.v3d.CSG) ArrayList(java.util.ArrayList) PyObject(org.python.core.PyObject) Properties(java.util.Properties) PyObject(org.python.core.PyObject) IOException(java.io.IOException)

Example 5 with BowlerAbstractDevice

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);
}
Also used : BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) IDeviceConnectionEventListener(com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)

Aggregations

BowlerAbstractDevice (com.neuronrobotics.sdk.common.BowlerAbstractDevice)8 IDeviceConnectionEventListener (com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)4 IOException (java.io.IOException)4 CSG (eu.mihosoft.vrl.v3d.CSG)3 ArrayList (java.util.ArrayList)3 Tab (javafx.scene.control.Tab)2 LocalFileScriptTab (com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab)1 DHLink (com.neuronrobotics.sdk.addons.kinematics.DHLink)1 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)1 MobileBase (com.neuronrobotics.sdk.addons.kinematics.MobileBase)1 BowlerDataType (com.neuronrobotics.sdk.common.BowlerDataType)1 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)1 DMDevice (com.neuronrobotics.sdk.common.DMDevice)1 MACAddress (com.neuronrobotics.sdk.common.MACAddress)1 RpcEncapsulation (com.neuronrobotics.sdk.common.RpcEncapsulation)1 BowlerAbstractDeviceServerNamespace (com.neuronrobotics.sdk.common.device.server.BowlerAbstractDeviceServerNamespace)1 BowlerAbstractServer (com.neuronrobotics.sdk.common.device.server.BowlerAbstractServer)1 IBowlerCommandProcessor (com.neuronrobotics.sdk.common.device.server.IBowlerCommandProcessor)1 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)1 IDigitalInputListener (com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener)1