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);
}
}
}
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 });
}
}
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));
}
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];
}
}
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);
}
Aggregations