@@ -0,0 +1,2695 @@
+package com.easternedgerobotics.rov.io;%0A%0Aimport com.easternedgerobotics.rov.event.EventPublisher;%0Aimport com.easternedgerobotics.rov.value.ThrusterValue;%0A%0Aimport java.io.IOException;%0Aimport java.nio.ByteBuffer;%0A%0Apublic class Thruster %7B%0A%0A    private static final int BYTE_SIZE = 8;%0A%0A    private static final byte WRITE_ADDRESS = 0x00;%0A%0A    private static final byte READ_ADDRESS = 0x02;%0A%0A    private static final int READ_BUFFER_SIZE = 9;%0A%0A    private static final int VOLTAGE_INDEX = 0;%0A%0A    private static final int CURRENT_INDEX = 2;%0A%0A    private static final float CURRENT_SCALAR = 5.0f * 6.45f / 65536.0f;%0A%0A    private static final int TEMPERATURE_INDEX = 6;%0A%0A    private static final float TEMPERATURE_OFFSET = 32767;%0A%0A    private static final float TEMPERATURE_SCALAR =  5.0f * 14.706f / 65535.0f;%0A%0A    private final byte%5B%5D zeroBuffer = new byte%5B%5D %7B0x00, 0x00%7D;%0A%0A    private Device device;%0A%0A    private ThrusterValue thrusterValue;%0A%0A    private EventPublisher eventPublisher;%0A%0A    public Thruster(final EventPublisher event, final ThrusterValue thruster, final Device dev) %7B%0A%0A        device = dev;%0A%0A        eventPublisher = event;%0A%0A        thrusterValue = thruster;%0A%0A        eventPublisher.valuesOfType(ThrusterValue.class).subscribe(t -%3E %7B%0A            if (thrusterValue.getName().equals(t.getName())) %7B%0A                thrusterValue = t;%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public final void write() throws IOException %7B%0A        final short speed = (short) (thrusterValue.getSpeed() * Short.MAX_VALUE);%0A        final byte%5B%5D writeBuffer = ByteBuffer.allocate(2).putShort(speed).array();%0A        device.write(WRITE_ADDRESS, zeroBuffer);%0A        device.write(WRITE_ADDRESS, writeBuffer);%0A    %7D%0A%0A    public final void writeZero() throws IOException %7B%0A        device.write(WRITE_ADDRESS, zeroBuffer);%0A    %7D%0A%0A    public final void read() throws IOException %7B%0A        final byte%5B%5D readBuffer = device.read(READ_ADDRESS, READ_BUFFER_SIZE);%0A%0A        final float voltage = parseShort(readBuffer, VOLTAGE_INDEX);%0A        final float current = parseShort(readBuffer, CURRENT_INDEX) * CURRENT_SCALAR;%0A        final float temperature = (parseShort(readBuffer, TEMPERATURE_INDEX) - TEMPERATURE_OFFSET) * TEMPERATURE_SCALAR;%0A%0A        eventPublisher.emit(ThrusterValue.create(%0A            thrusterValue.getName(),%0A            thrusterValue.getSpeed(),%0A            voltage,%0A            current,%0A            temperature%0A        ));%0A    %7D%0A%0A    // reads a short from two consecutive bytes.%0A    // MSB located at offset.%0A    // LSB located at offset + 1.%0A    private short parseShort(final byte%5B%5D bytes, final int offset) %7B%0A        return (short) (((bytes%5Boffset%5D) %3C%3C BYTE_SIZE) %7C bytes%5Boffset + 1%5D);%0A    %7D%0A%7D%0A

Send speed commands and read status of a thruster