Search in sources :

Example 1 with ByteList

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);
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) DyIO(com.neuronrobotics.sdk.dyio.DyIO) SPIChannel(com.neuronrobotics.sdk.dyio.peripherals.SPIChannel)

Example 2 with ByteList

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);
}
Also used : UARTChannel(com.neuronrobotics.sdk.dyio.peripherals.UARTChannel) ByteList(com.neuronrobotics.sdk.common.ByteList) DyIO(com.neuronrobotics.sdk.dyio.DyIO) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with ByteList

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;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) PIDChannel(com.neuronrobotics.sdk.pid.PIDChannel) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ControlAllPIDCommand(com.neuronrobotics.sdk.commands.bcs.pid.ControlAllPIDCommand)

Example 4 with ByteList

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");
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) Test(org.junit.Test)

Example 5 with ByteList

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