Search in sources :

Example 1 with BowlerDatagram

use of com.neuronrobotics.sdk.common.BowlerDatagram 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 BowlerDatagram

use of com.neuronrobotics.sdk.common.BowlerDatagram in project BowlerStudio by CommonWealthRobotics.

the class RpcCommandPanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent arg0) {
    Object[] values = new Object[tx.size()];
    for (int i = 0; i < values.length; i++) {
        if (rpc.getDownstreamArguments()[i] == BowlerDataType.ASCII)
            values[i] = tx.get(i).getText();
        else
            values[i] = Integer.parseInt(tx.get(i).getText());
    }
    BowlerDatagram bd = device.send(rpc.getCommand(values));
    rxRpc.setText(bd.getRPC());
    Object[] up = rpc.parseResponse(bd);
    for (int i = 0; i < up.length; i++) {
        if (up[i] != null)
            rx.get(i).setText(up[i].toString());
        else {
            rx.get(i).setText("Null");
        }
    }
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram)

Example 3 with BowlerDatagram

use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.

the class LegacyPidNamespaceImp method getPIDConfiguration.

@Override
public /* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPIDConfiguration
	 */
PIDConfiguration getPIDConfiguration(int group) {
    BowlerDatagram conf = getDevice().send(new ConfigurePIDCommand((char) group));
    PIDConfiguration back = new PIDConfiguration(conf);
    return back;
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) PIDConfiguration(com.neuronrobotics.sdk.pid.PIDConfiguration) ConfigurePIDCommand(com.neuronrobotics.sdk.commands.bcs.pid.ConfigurePIDCommand)

Example 4 with BowlerDatagram

use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.

the class LegacyPidNamespaceImp method ResetPIDChannel.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#ResetPIDChannel
	 */
@Override
public boolean ResetPIDChannel(int group, int valueToSetCurrentTo) {
    BowlerDatagram rst = getDevice().send(new ResetPIDCommand((char) group, valueToSetCurrentTo));
    if (rst == null)
        return false;
    int val = GetPIDPosition(group);
    firePIDResetEvent(group, val);
    return true;
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ResetPIDCommand(com.neuronrobotics.sdk.commands.bcs.pid.ResetPIDCommand)

Example 5 with BowlerDatagram

use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.

the class LegacyPidNamespaceImp method GetAllPIDPosition.

@Override
public int[] GetAllPIDPosition() {
    Log.debug("Getting All PID Positions");
    BowlerDatagram b = getDevice().send(new ControlAllPIDCommand());
    ByteList data = b.getData();
    int[] back = new int[data.size() / 4];
    for (int i = 0; i < back.length; i++) {
        int start = i * 4;
        byte[] tmp = data.getBytes(start, 4);
        back[i] = ByteList.convertToInt(tmp, true);
    }
    if (back.length != getNumberOfChannels()) {
        lastPacketTime = new long[back.length];
        for (int i = 0; i < back.length; i++) {
            PIDChannel c = new PIDChannel(this, i);
            c.setCachedTargetValue(back[i]);
            getChannels().add(c);
        }
    }
    return back;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ControlAllPIDCommand(com.neuronrobotics.sdk.commands.bcs.pid.ControlAllPIDCommand)

Aggregations

BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)31 ByteList (com.neuronrobotics.sdk.common.ByteList)9 MACAddress (com.neuronrobotics.sdk.common.MACAddress)5 IOException (java.io.IOException)5 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)4 ArrayList (java.util.ArrayList)4 PingCommand (com.neuronrobotics.sdk.commands.bcs.core.PingCommand)3 GetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand)2 GetValueCommand (com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand)2 InvalidConnectionException (com.neuronrobotics.sdk.common.InvalidConnectionException)2 RpcEncapsulation (com.neuronrobotics.sdk.common.RpcEncapsulation)2 PIDCommandException (com.neuronrobotics.sdk.pid.PIDCommandException)2 SocketException (java.net.SocketException)2 Test (org.junit.Test)2 GetChannelModeListCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeListCommand)1 GetDyIOChannelCountCommand (com.neuronrobotics.sdk.commands.bcs.io.GetDyIOChannelCountCommand)1 SetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.setmode.SetChannelModeCommand)1 ConfigurePIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.ConfigurePIDCommand)1 ControlAllPIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.ControlAllPIDCommand)1 ConfigureDynamicPIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.DyPID.ConfigureDynamicPIDCommand)1