use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class SPITest method main.
public static void main(String[] args) throws InterruptedException {
DyIO dyio = new DyIO();
if (!ConnectionDialog.getBowlerDevice(dyio)) {
System.exit(0);
}
// Instantiate the SPI
SPIChannel spi = new SPIChannel(dyio);
ByteList dataStream = new ByteList(new byte[] { 33, 55, 66, 77, 88, 99 });
int slaveSelectChannelNumber = 3;
// Send data to the SPI channel using the given DYIO channel as the slave select.
byte[] back = spi.write(slaveSelectChannelNumber, dataStream.getBytes());
// Cleanup and exit
dyio.disconnect();
System.exit(0);
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class USARTTest method main.
public static void main(String[] args) throws InterruptedException {
DyIO dyio = new DyIO();
if (!ConnectionDialog.getBowlerDevice(dyio)) {
System.exit(0);
}
// Instantiate the UARTPassThroughChannel
UARTChannel uart = new UARTChannel(dyio);
// Configure the DyIO's output UART to use 115200 baud
uart.setUARTBaudrate(115200);
// Create a test string and send it to the serial port
String s = new String("abcdefghijklmnopqrstuvwxyz");
ByteList stream = new ByteList(s.getBytes());
try {
System.out.println("Sending: " + stream.asString());
uart.sendBytes(stream);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
Thread.sleep(1000);
// Wait for data to arrive
while (!uart.inStreamDataReady()) {
Thread.sleep(10);
}
// Print out the data we got back
try {
System.out.println("Got input: " + new ByteList(uart.getBytes()).asString());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
// Cleanup and exit
dyio.disconnect();
System.exit(0);
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class LegacyPidNamespaceImp method GetAllPIDPosition.
@Override
public int[] GetAllPIDPosition() {
Log.debug("Getting All PID Positions");
BowlerDatagram b = getDevice().send(new ControlAllPIDCommand());
ByteList data = b.getData();
int[] back = new int[data.size() / 4];
for (int i = 0; i < back.length; i++) {
int start = i * 4;
byte[] tmp = data.getBytes(start, 4);
back[i] = ByteList.convertToInt(tmp, true);
}
if (back.length != getNumberOfChannels()) {
lastPacketTime = new long[back.length];
for (int i = 0; i < back.length; i++) {
PIDChannel c = new PIDChannel(this, i);
c.setCachedTargetValue(back[i]);
getChannels().add(c);
}
}
return back;
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class ByteListTest method test.
@Test
public void test() {
Log.enableDebugPrint();
ByteList.setUseStaticBuffer(true);
ByteList tester = new ByteList();
assertTrue(tester != null);
tester.setStaticBufferSize(5);
byte[] testAray = new byte[(int) (tester.getStaticBufferSize() * 3)];
for (int i = 0; i < testAray.length; i++) {
testAray[i] = (byte) (Math.random() * 255);
}
for (int j = 0; j < 3; j++) {
for (int i = 0; i < testAray.length; i++) {
tester.add(testAray[i]);
}
System.out.println("Read test");
for (int i = 0; i < testAray.length; i++) {
assertTrue(tester.getByte(i) == testAray[i]);
}
System.out.println("Iterator test");
int k = 0;
for (Byte b : tester) {
// System.out.println("Expecting "+testAray[k]+" Got "+b );
assertTrue(b == testAray[k++]);
}
System.out.println("Pop test");
for (int i = 0; i < testAray.length; i++) {
assertTrue(tester.pop() == testAray[i]);
}
System.out.println("Looped through index " + j);
}
// fail("Not yet implemented");
}
use of com.neuronrobotics.sdk.common.ByteList in project java-bowler by NeuronRobotics.
the class PPMReaderChannel method onChannelEvent.
public void onChannelEvent(DyIOChannelEvent e) {
getValues();
if (crossLinks == null) {
crossLinks = new int[6];
ByteList data = new ByteList(e.getData().getBytes(6, 6));
for (int i = 0; i < crossLinks.length; i++) {
crossLinks[i] = data.getUnsigned(i);
}
}
for (int i = 0; i < values.length; i++) {
values[i] = e.getData().getUnsigned(i);
}
if (values != null) {
for (IPPMReaderListener l : listeners) {
l.onPPMPacket(values);
}
}
}
Aggregations