Search in sources :

Example 6 with BowlerDatagram

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

the class BowlerUDPServer method loadPacketFromPhy.

@Override
public BowlerDatagram loadPacketFromPhy(ByteList bytesToPacketBuffer) throws NullPointerException, IOException {
    byte[] receiveData = new byte[4096];
    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    Log.info("Waiting for UDP packet");
    try {
        udpSock.receive(receivePacket);
    } catch (SocketException ex) {
        // disconnect called
        Log.warning("Receive bailed out because of close");
        return null;
    }
    IPAddressSet = (receivePacket.getAddress());
    destinationPort = receivePacket.getPort();
    Log.info("Got UDP packet from " + IPAddressSet + " : " + destinationPort);
    byte[] data = receivePacket.getData();
    for (int i = 0; i < receivePacket.getLength(); i++) {
        internalReceiveBuffer.add(data[i]);
    }
    BowlerDatagram bd = null;
    while (internalReceiveBuffer.size() > 0) {
        bytesToPacketBuffer.add(internalReceiveBuffer.pop());
        if (bd == null) {
            bd = BowlerDatagramFactory.build(bytesToPacketBuffer);
        }
    }
    return bd;
}
Also used : SocketException(java.net.SocketException) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) DatagramPacket(java.net.DatagramPacket)

Example 7 with BowlerDatagram

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

the class DyIO method getAvailibleChannelModes.

public ArrayList<DyIOChannelMode> getAvailibleChannelModes(int channel) {
    ArrayList<DyIOChannelMode> modes = new ArrayList<DyIOChannelMode>();
    ByteList m;
    if (isLegacyParser()) {
        BowlerDatagram dg = send(new GetChannelModeListCommand(channel));
        m = dg.getData();
        Log.error("Packet " + channel + "\r\n" + dg);
        Log.error("Data: " + channel + "\r\n" + m);
    } else {
        // int l = Log.getMinimumPrintLevel();
        // Log.enableInfoPrint();
        Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gcml", new Object[] { channel });
        m = (ByteList) args[0];
    // Log.setMinimumPrintLevel(l);
    }
    String modeString = " Availible modes on " + channel;
    for (int i = 0; i < m.size(); i++) {
        DyIOChannelMode tmpMode = DyIOChannelMode.get(m.getByte(i));
        modeString += "\r\n\t" + tmpMode.toString() + "\r\n\t";
        modes.add(tmpMode);
    }
    Log.info(modeString);
    return modes;
}
Also used : GetChannelModeListCommand(com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeListCommand) ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ArrayList(java.util.ArrayList)

Example 8 with BowlerDatagram

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

the class DyIO method getAllChannelValues.

/**
 * Gets the values of all channels as an array
 * @return the values of all non stream arrays.
 */
public int[] getAllChannelValues() {
    int[] back = new int[getInternalChannels().size()];
    if (isLegacyParser()) {
        BowlerDatagram gacv = send(new GetAllChannelValuesCommand());
        Log.info("GACV RX<<\n" + gacv);
        ByteList bl = gacv.getData();
        int i = 0;
        for (DyIOChannel c : getChannels()) {
            if (!c.isStreamChannel()) {
                ByteList val = new ByteList(bl.popList(4));
                DyIOChannelEvent ev = new DyIOChannelEvent(c, val);
                back[i++] = ev.getValue();
                if (!c.isStreamChannel()) {
                    c.fireChannelEvent(ev);
                }
            } else {
                back[i++] = 0;
            }
        }
    } else {
        // Log.enableInfoPrint();
        Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gacv", new Object[] {});
        Integer[] values = (Integer[]) args[0];
        for (int i = 0; i < getChannels().size(); i++) {
            DyIOChannel c = getChannels().get(i);
            if (!c.isStreamChannel()) {
                DyIOChannelEvent ev = new DyIOChannelEvent(c, values[i]);
                back[i] = values[i];
                if (!c.isStreamChannel()) {
                    c.fireChannelEvent(ev);
                }
            }
        }
    }
    return back;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) GetAllChannelValuesCommand(com.neuronrobotics.sdk.commands.neuronrobotics.dyio.GetAllChannelValuesCommand)

Example 9 with BowlerDatagram

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

the class DyIO method getBatteryVoltage.

/**
 * THis method will return the current voltage on the battery connected to the DyIO external power connector.
 * @param refresh true if you want to query the device, false to just get the cached value from the last async.
 * @return the voltage of the battery in Volts
 */
public double getBatteryVoltage(boolean refresh) {
    if (refresh) {
        BowlerDatagram data = send(new PowerCommand());
        powerEvent(data);
    }
    return batteryVoltage;
}
Also used : PowerCommand(com.neuronrobotics.sdk.commands.neuronrobotics.dyio.PowerCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram)

Example 10 with BowlerDatagram

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

the class DyIO method getDyIOChannelCount.

public Integer getDyIOChannelCount() {
    if (dyioChanCount == null) {
        if (isLegacyParser()) {
            try {
                BowlerDatagram dg = send(new GetDyIOChannelCountCommand());
                dyioChanCount = ByteList.convertToInt(dg.getData().getBytes(0, 4));
            } catch (InvalidResponseException ex) {
                ex.printStackTrace();
            }
        } else {
            Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gchc", new Object[] {});
            dyioChanCount = (Integer) args[0];
        }
    }
    return dyioChanCount;
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) GetDyIOChannelCountCommand(com.neuronrobotics.sdk.commands.bcs.io.GetDyIOChannelCountCommand) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

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