Search in sources :

Example 11 with BowlerDatagram

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

the class DyIOChannel method resync.

/**
 * Live query the device for its mode and cache it.
 *
 * @param all - should all channels be refreshed.
 */
public void resync(boolean all) {
    if (all) {
        getDevice().resync();
        return;
    }
    BowlerDatagram bd = getDevice().send(new GetChannelModeCommand(number));
    // System.out.println(bd);
    fireModeChangeEvent(DyIOChannelMode.get(bd.getData().getByte(1)));
    throw new RuntimeException();
}
Also used : GetChannelModeCommand(com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram)

Example 12 with BowlerDatagram

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

the class DyIOChannel method getValue.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.dyio.IDyIOChannel#getValue()
	 */
public int getValue() {
    int val = 0;
    if (getDevice().isLegacyParser()) {
        BowlerDatagram response = null;
        try {
            response = getDevice().send(new GetValueCommand(number));
        } catch (InvalidResponseException e) {
            response = getDevice().send(new GetValueCommand(number));
        }
        ByteList bl = response.getData();
        Byte b = bl.pop();
        if (b == null || b.intValue() != number) {
            Log.error("Failed to get value " + response);
            return 0;
        }
        val = new DyIOChannelEvent(this, bl).getValue();
        setCachedValue(val);
        setPreviousValue(val);
    } else {
        // Object [] args =getDevice().send("bcs.io.*;0.3;;",
        // BowlerMethod.GET,
        // "gchv",
        // new Object[]{number});
        // val=(Integer)args[1];
        // Log.debug("Got Value: "+val);
        // For the new API the channel values should come in through the asynchronous path.
        val = getPreviousValue();
    }
    return val;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) GetValueCommand(com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Example 13 with BowlerDatagram

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

the class BowlerAbstractDeviceServer method sendAsync.

/**
 * Send a sendable to the getConnection().
 *
 * @param sendable the sendable without expecting a response
 * @throws IOException
 */
public void sendAsync(BowlerAbstractCommand command, int rpcIndexID) throws IOException {
    command.setNamespaceIndex(rpcIndexID);
    BowlerDatagram bd = BowlerDatagramFactory.build(getAddress(), command);
    // Log.debug("ASYN>>\n"+bd.toString());
    getConnection().sendAsync(bd);
    getConnection().getDataOuts().flush();
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram)

Example 14 with BowlerDatagram

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

the class NRBootLoader method reset.

public void reset() {
    // We expect this to fail the connection.
    // No response is expected
    // Disconnect afterwards
    BowlerDatagram bd = BowlerDatagramFactory.build(getAddress(), new ResetChipCommand());
    try {
        getConnection().sendAsync(bd);
        getConnection().getDataOuts().flush();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    disconnect();
}
Also used : ResetChipCommand(com.neuronrobotics.sdk.commands.neuronrobotics.bootloader.ResetChipCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) IOException(java.io.IOException)

Example 15 with BowlerDatagram

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

the class NRBootLoader method getBootloaderID.

public String getBootloaderID() {
    BowlerDatagram back = send(new BootloaderIDCommand());
    if (back == null)
        return null;
    String s = new String();
    for (Byte b : back.getData()) {
        s += (char) b.byteValue();
    }
    return s;
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) BootloaderIDCommand(com.neuronrobotics.sdk.commands.neuronrobotics.bootloader.BootloaderIDCommand)

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