Search in sources :

Example 21 with ByteList

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

the class PPMReaderChannel method updateValues.

private void updateValues() {
    if (getChannel().getDevice().isLegacyParser()) {
        BowlerDatagram b = null;
        // System.out.println("Updating value map");
        try {
            b = getChannel().getDevice().send(new GetValueCommand(23));
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (b != null) {
            crossLinks = new int[6];
            values = new int[6];
            for (int i = 0; i < values.length; i++) {
                values[i] = b.getData().getUnsigned(1 + i);
            }
            for (int i = 0; i < crossLinks.length; i++) {
                crossLinks[i] = b.getData().getUnsigned(1 + 6 + i);
            }
        }
    } else {
        Object[] args = getChannel().getDevice().send("bcs.io.*;0.3;;", BowlerMethod.GET, "strm", new Object[] { 23 });
        crossLinks = new int[6];
        values = new int[6];
        ByteList data = (ByteList) args[1];
        Log.debug("PPM link data: " + data.size());
        for (int i = 0; i < values.length; i++) {
            values[i] = data.getUnsigned(i);
        }
        for (int i = 0; i < crossLinks.length; i++) {
            crossLinks[i] = data.getUnsigned(6 + i);
        }
    }
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) GetValueCommand(com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand)

Example 22 with ByteList

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

the class PPMReaderChannel method setCrossLink.

/**
 * This sets up the PPM cross link. For each PPM channel you can assign it one DyIO output channel as its direct
 * control. Indecies in the array corospond to the PPM channel, and values corospond to the DyIO output channel
 * @param links an array of channel numbers corosponding to the PPM channel to do a direct 1:1 mapping
 */
public void setCrossLink(int[] links) {
    if (links.length != 6)
        throw new IndexOutOfBoundsException("Array of cross links must be of legnth 6");
    if (crossLinks == null) {
        throw new RuntimeException("Must get cross link state before setting a new one");
    }
    // System.out.print("\nSetting cross link map: [");
    for (int i = 0; i < crossLinks.length; i++) {
        crossLinks[i] = links[i];
    // System.out.print(" "+crossLinks[i]);
    }
    // System.out.print("]");
    if (getChannel().getDevice().isLegacyParser()) {
        getChannel().getDevice().send(new SetChannelValueCommand(23, crossLinks, myMode));
    } else {
        ByteList data = new ByteList(crossLinks);
        getChannel().getDevice().send("bcs.io.*;0.3;;", BowlerMethod.POST, "strm", new Object[] { 23, data });
    }
}
Also used : SetChannelValueCommand(com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand) ByteList(com.neuronrobotics.sdk.common.ByteList)

Example 23 with ByteList

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

the class SPIChannel method sendSPIStream.

/**
 * THis method sends a byte array our the SPI peripheral. It uses another DyIO channel as its slave select pin.
 * @param ss the index of the DyIO channel to use as a slave select pin for the SPI
 * @param stream the Bytes to be sent out
 * @return true if success
 */
@Deprecated
private BowlerDatagram sendSPIStream(int ss, byte[] stream) {
    ByteList b = new ByteList();
    b.add(ss);
    b.add(stream);
    return dyio.send(new SetChannelValueCommand(0, b));
}
Also used : SetChannelValueCommand(com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand) ByteList(com.neuronrobotics.sdk.common.ByteList)

Example 24 with ByteList

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

the class SPIChannel method write.

/**
 * This performs a full read/write transaction. The data is sent down, and the corosponding data is read back in.
 * @param ss the index of the DyIO channel to use as a slave select pin for the SPI
 * @param stream the Bytes to be sent out
 * @return the data received
 */
public byte[] write(int ss, byte[] stream) {
    if (dyio.isLegacyParser()) {
        BowlerDatagram b = sendSPIStream(ss, stream);
        if (b == null)
            return new byte[0];
        return b.getData().getBytes(2);
    } else {
        ByteList data = new ByteList(stream);
        data.insert(0, (byte) ss);
        dyio.send("bcs.io.*;0.3;;", BowlerMethod.POST, "strm", new Object[] { 0, data });
        int timeout = 1000;
        rx = null;
        while (timeout-- > 0) {
            ThreadUtil.wait(1);
            if (rx != null) {
                return rx;
            }
        }
        return new byte[0];
    }
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram)

Example 25 with ByteList

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

the class CounterInputChannel method setValue.

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

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