Search in sources :

Example 1 with GetAllChannelValuesCommand

use of com.neuronrobotics.sdk.commands.neuronrobotics.dyio.GetAllChannelValuesCommand 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)

Aggregations

GetAllChannelValuesCommand (com.neuronrobotics.sdk.commands.neuronrobotics.dyio.GetAllChannelValuesCommand)1 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)1 ByteList (com.neuronrobotics.sdk.common.ByteList)1