Search in sources :

Example 6 with ByteList

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

the class CounterOutputChannel method setValue.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.dyio.peripherals.DyIOAbstractPeripheral#setValue(int)
	 */
public boolean setValue(int value) {
    Log.info("Setting counter set point");
    ByteList b = new ByteList();
    b.addAs32(value);
    return setValue(b);
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList)

Example 7 with ByteList

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

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

the class DyIO method powerEvent.

/**
 * Parses a datagram into the power event data
 * @param data
 */
private void powerEvent(BowlerDatagram data) {
    // Log.warning("POWER event "+data);
    if (data.getRPC().contains("_pwr")) {
        ByteList bl = data.getData();
        if (isLegacyParser() && bl.size() == 1) {
            enableBrownOut = bl.get(0) != 0;
        }
        if (bl.size() > 1) {
            batteryVoltage = ((double) (ByteList.convertToInt(bl.getBytes(2, 2), false))) / 1000.0;
            bankAState = DyIOPowerState.valueOf(bl.get(0), batteryVoltage);
            bankBState = DyIOPowerState.valueOf(bl.get(1), batteryVoltage);
            if (!isLegacyParser()) {
                enableBrownOut = bl.get(4) != 0;
            }
        }
        fireDyIOEvent(new DyIOPowerEvent(bankAState, bankBState, batteryVoltage));
        return;
    } else {
        Log.error("Wrong type for updating Power state " + data);
    }
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList)

Example 9 with ByteList

use of com.neuronrobotics.sdk.common.ByteList 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 10 with ByteList

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

Aggregations

ByteList (com.neuronrobotics.sdk.common.ByteList)25 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)9 IOException (java.io.IOException)5 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)3 GetValueCommand (com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand)2 SetChannelValueCommand (com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand)2 DyIO (com.neuronrobotics.sdk.dyio.DyIO)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 PingCommand (com.neuronrobotics.sdk.commands.bcs.core.PingCommand)1 GetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand)1 GetChannelModeListCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeListCommand)1 SetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.setmode.SetChannelModeCommand)1 ControlAllPIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.ControlAllPIDCommand)1 ProgramSectionCommand (com.neuronrobotics.sdk.commands.neuronrobotics.bootloader.ProgramSectionCommand)1 GetAllChannelValuesCommand (com.neuronrobotics.sdk.commands.neuronrobotics.dyio.GetAllChannelValuesCommand)1 InvalidConnectionException (com.neuronrobotics.sdk.common.InvalidConnectionException)1 MACAddress (com.neuronrobotics.sdk.common.MACAddress)1 SPIChannel (com.neuronrobotics.sdk.dyio.peripherals.SPIChannel)1 UARTChannel (com.neuronrobotics.sdk.dyio.peripherals.UARTChannel)1