From 4283a2ebc4ec1bf062cc5e8e08aabe0f47c5fe9b Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Tue, 1 Sep 2015 13:19:01 +0100 Subject: [PATCH] Replace tabs with spaces --- .../com/github/boukefalos/ibuddy/Loader.java | 76 ++--- .../com/github/boukefalos/ibuddy/Server.java | 124 ++++---- .../ibuddy/exception/iBuddyException.java | 2 +- .../com/github/boukefalos/ibuddy/iBuddy.java | 34 +-- .../ibuddy/implementation/Local.java | 164 +++++------ .../ibuddy/implementation/Remote.java | 266 +++++++++--------- src/main/java/org/jraf/jlibibuddy/IBuddy.java | 6 +- src/test/java/test/TestOriginal.java | 40 +-- src/test/java/test/TestTcpCommunication.java | 52 ++-- src/test/java/test/TestUdpCommunication.java | 52 ++-- 10 files changed, 408 insertions(+), 408 deletions(-) diff --git a/src/main/java/com/github/boukefalos/ibuddy/Loader.java b/src/main/java/com/github/boukefalos/ibuddy/Loader.java index 1ad2814..5c50c00 100644 --- a/src/main/java/com/github/boukefalos/ibuddy/Loader.java +++ b/src/main/java/com/github/boukefalos/ibuddy/Loader.java @@ -11,51 +11,51 @@ import com.github.boukefalos.ibuddy.implementation.Remote; public class Loader extends AbstractLoader { protected static final String PROPERTIES_FILE = "ibuddy.properties"; - public Loader(Properties properties) throws LoaderException { - super(); + public Loader(Properties properties) throws LoaderException { + super(); - /* Add implementation */ - switch (properties.getProperty("implementation")) { - case "local": - pico.addComponent(Local.class); - break; - case "remote": - pico.addComponent(Remote.class); + /* Add implementation */ + switch (properties.getProperty("implementation")) { + case "local": + pico.addComponent(Local.class); + break; + case "remote": + pico.addComponent(Remote.class); - /* Add sender implementation */ - try { - String protocol = properties.getOrDefault("protocol", "tcp").toString(); - String implementation = properties.getOrDefault("tcp.implementation", "socket").toString(); - String host = properties.getProperty("remote.host"); - int port = Integer.valueOf(properties.getProperty("remote.port")); - addClientSender(protocol, implementation, host, port); - } catch (NumberFormatException e) { - throw new LoaderException("Failed to parse remote.port"); - } - break; - } + /* Add sender implementation */ + try { + String protocol = properties.getOrDefault("protocol", "tcp").toString(); + String implementation = properties.getOrDefault("tcp.implementation", "socket").toString(); + String host = properties.getProperty("remote.host"); + int port = Integer.valueOf(properties.getProperty("remote.port")); + addClientSender(protocol, implementation, host, port); + } catch (NumberFormatException e) { + throw new LoaderException("Failed to parse remote.port"); + } + break; + } - /* Add server */ - if (properties.getProperty("server") != null) { - pico.addComponent(Server.class); + /* Add server */ + if (properties.getProperty("server") != null) { + pico.addComponent(Server.class); - /* Add server forwarder implementation */ - try { - String protocol = properties.getOrDefault("server.protocol", "tcp").toString(); - String implementation = properties.getOrDefault("tcp.implementation", "socket").toString(); - int port = Integer.valueOf(properties.getProperty("server.port")); - addServerForwarder(protocol, implementation, port); - } catch (NumberFormatException e) { - throw new LoaderException("Failed to parse server.port"); - } - } - } + /* Add server forwarder implementation */ + try { + String protocol = properties.getOrDefault("server.protocol", "tcp").toString(); + String implementation = properties.getOrDefault("tcp.implementation", "socket").toString(); + int port = Integer.valueOf(properties.getProperty("server.port")); + addServerForwarder(protocol, implementation, port); + } catch (NumberFormatException e) { + throw new LoaderException("Failed to parse server.port"); + } + } + } - public iBuddy getiBuddy() { - return pico.getComponent(iBuddy.class); + public iBuddy getiBuddy() { + return pico.getComponent(iBuddy.class); } public Server getServer() { - return pico.getComponent(Server.class); + return pico.getComponent(Server.class); } } diff --git a/src/main/java/com/github/boukefalos/ibuddy/Server.java b/src/main/java/com/github/boukefalos/ibuddy/Server.java index 83ea4df..afa45c6 100644 --- a/src/main/java/com/github/boukefalos/ibuddy/Server.java +++ b/src/main/java/com/github/boukefalos/ibuddy/Server.java @@ -16,68 +16,68 @@ import base.Forwarder; import base.server.receiver.AbstractReceiver; public class Server extends AbstractReceiver { - protected iBuddy iBuddy; + protected iBuddy iBuddy; - public Server(iBuddy iBuddy, Forwarder forwarder) { - super(forwarder); - this.iBuddy = iBuddy; - } + public Server(iBuddy iBuddy, Forwarder forwarder) { + super(forwarder); + this.iBuddy = iBuddy; + } - public void receive(byte[] buffer) { - ByteArrayInputStream input = new ByteArrayInputStream(buffer); - logger.debug("Received input"); - try { - Command command = Command.parseDelimitedFrom(input); - logger.debug("Command type = " + command.getType().name()); - switch (command.getType()) { - case HEAD: - Head head = command.getHead(); - Color color = head.getColor(); - if (head.getSingle()) { - boolean state = head.getState().equals(State.ON); - switch (color) { - case RED: - iBuddy.setHeadRed(state); - case GREEN: - iBuddy.setHeadGreen(state); - case BLUE: - iBuddy.setHeadBlue(state); - default: - break; - } - } else { - iBuddy.setHead(color); - } - break; - case WINGS: - iBuddy.setWings(command.getWings().getDirection()); - break; - case ROTATE: - iBuddy.setRotate(command.getRotate().getDirection()); - break; - case HEART: - iBuddy.setHeart(command.getHeart().getState().equals(State.ON)); - break; - case BLINK: - Blink blink = command.getBlink(); - iBuddy.blink(blink.getColor(), blink.getOnTime(), blink.getOffTime(), blink.getTimes()); - break; - case NUDGE: - Nudge nudge = command.getNudge(); - iBuddy.nudge(nudge.getDelay(), nudge.getTimes()); - break; - case FLAP: - Flap flap = command.getFlap(); - iBuddy.flap(flap.getDelay(), flap.getTimes()); - break; - default: - iBuddy.off(); - } - } catch (IOException e) { - logger.error("Failed to parse input"); - return; - } catch (IBuddyException e) { - logger.error("Failed to send command to iBuddy", e); - } - } + public void receive(byte[] buffer) { + ByteArrayInputStream input = new ByteArrayInputStream(buffer); + logger.debug("Received input"); + try { + Command command = Command.parseDelimitedFrom(input); + logger.debug("Command type = " + command.getType().name()); + switch (command.getType()) { + case HEAD: + Head head = command.getHead(); + Color color = head.getColor(); + if (head.getSingle()) { + boolean state = head.getState().equals(State.ON); + switch (color) { + case RED: + iBuddy.setHeadRed(state); + case GREEN: + iBuddy.setHeadGreen(state); + case BLUE: + iBuddy.setHeadBlue(state); + default: + break; + } + } else { + iBuddy.setHead(color); + } + break; + case WINGS: + iBuddy.setWings(command.getWings().getDirection()); + break; + case ROTATE: + iBuddy.setRotate(command.getRotate().getDirection()); + break; + case HEART: + iBuddy.setHeart(command.getHeart().getState().equals(State.ON)); + break; + case BLINK: + Blink blink = command.getBlink(); + iBuddy.blink(blink.getColor(), blink.getOnTime(), blink.getOffTime(), blink.getTimes()); + break; + case NUDGE: + Nudge nudge = command.getNudge(); + iBuddy.nudge(nudge.getDelay(), nudge.getTimes()); + break; + case FLAP: + Flap flap = command.getFlap(); + iBuddy.flap(flap.getDelay(), flap.getTimes()); + break; + default: + iBuddy.off(); + } + } catch (IOException e) { + logger.error("Failed to parse input"); + return; + } catch (IBuddyException e) { + logger.error("Failed to send command to iBuddy", e); + } + } } diff --git a/src/main/java/com/github/boukefalos/ibuddy/exception/iBuddyException.java b/src/main/java/com/github/boukefalos/ibuddy/exception/iBuddyException.java index 9814a41..33d731a 100644 --- a/src/main/java/com/github/boukefalos/ibuddy/exception/iBuddyException.java +++ b/src/main/java/com/github/boukefalos/ibuddy/exception/iBuddyException.java @@ -1,6 +1,6 @@ package com.github.boukefalos.ibuddy.exception; public class iBuddyException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; } diff --git a/src/main/java/com/github/boukefalos/ibuddy/iBuddy.java b/src/main/java/com/github/boukefalos/ibuddy/iBuddy.java index 7552907..e46c42e 100644 --- a/src/main/java/com/github/boukefalos/ibuddy/iBuddy.java +++ b/src/main/java/com/github/boukefalos/ibuddy/iBuddy.java @@ -7,21 +7,21 @@ import proto.Ibuddy.Direction; import base.Control; public interface iBuddy extends Control { - public void setHeart(boolean on) throws IBuddyException; - public void setHeadRed(boolean on) throws IBuddyException; - public void setHeadBlue(boolean on) throws IBuddyException; - public void setHeadGreen(boolean on) throws IBuddyException; - public void setHead(Color color) throws IBuddyException; - public void setWingsUp() throws IBuddyException; - public void setWingsDown() throws IBuddyException; - public void setWingsCenter() throws IBuddyException; - public void setWings(Direction direction) throws IBuddyException; - public void setRotateLeft() throws IBuddyException; - public void setRotateRight() throws IBuddyException; - public void setRotateCenter() throws IBuddyException; - public void setRotate(Direction direction) throws IBuddyException; - public void off() throws IBuddyException; - public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException; - public void nudge(int delay, int times) throws IBuddyException; - public void flap(int delay, int times) throws IBuddyException; + public void setHeart(boolean on) throws IBuddyException; + public void setHeadRed(boolean on) throws IBuddyException; + public void setHeadBlue(boolean on) throws IBuddyException; + public void setHeadGreen(boolean on) throws IBuddyException; + public void setHead(Color color) throws IBuddyException; + public void setWingsUp() throws IBuddyException; + public void setWingsDown() throws IBuddyException; + public void setWingsCenter() throws IBuddyException; + public void setWings(Direction direction) throws IBuddyException; + public void setRotateLeft() throws IBuddyException; + public void setRotateRight() throws IBuddyException; + public void setRotateCenter() throws IBuddyException; + public void setRotate(Direction direction) throws IBuddyException; + public void off() throws IBuddyException; + public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException; + public void nudge(int delay, int times) throws IBuddyException; + public void flap(int delay, int times) throws IBuddyException; } diff --git a/src/main/java/com/github/boukefalos/ibuddy/implementation/Local.java b/src/main/java/com/github/boukefalos/ibuddy/implementation/Local.java index c081ff0..21c6f28 100644 --- a/src/main/java/com/github/boukefalos/ibuddy/implementation/Local.java +++ b/src/main/java/com/github/boukefalos/ibuddy/implementation/Local.java @@ -10,107 +10,107 @@ import proto.Ibuddy.Direction; import com.github.boukefalos.ibuddy.iBuddy; public class Local implements iBuddy { - IBuddy IBuddy; + IBuddy IBuddy; - @SuppressWarnings("static-access") - public Local() { - IBuddy = IBuddy.getIBuddy(); - } + @SuppressWarnings("static-access") + public Local() { + IBuddy = IBuddy.getIBuddy(); + } - public void start() {} - public void stop() {} - public void exit() {} + public void start() {} + public void stop() {} + public void exit() {} - public void setHeadRed(boolean on) throws IBuddyException { - IBuddy.sendHeadRed(on); - } + public void setHeadRed(boolean on) throws IBuddyException { + IBuddy.sendHeadRed(on); + } - public void setHeadBlue(boolean on) throws IBuddyException { - IBuddy.sendHeadBlue(on); - } + public void setHeadBlue(boolean on) throws IBuddyException { + IBuddy.sendHeadBlue(on); + } - public void setHeadGreen(boolean on) throws IBuddyException { - IBuddy.sendHeadGreen(on); - } + public void setHeadGreen(boolean on) throws IBuddyException { + IBuddy.sendHeadGreen(on); + } - public void setHeart(boolean on) throws IBuddyException { - IBuddy.sendHeart(on); - } + public void setHeart(boolean on) throws IBuddyException { + IBuddy.sendHeart(on); + } - public void setHead(Color color) throws IBuddyException { - IBuddy.sendHeadColor(mapColor(color)); - } + public void setHead(Color color) throws IBuddyException { + IBuddy.sendHeadColor(mapColor(color)); + } - public void setWingsUp() throws IBuddyException { - IBuddy.sendWings(false, true); - } + public void setWingsUp() throws IBuddyException { + IBuddy.sendWings(false, true); + } - public void setWingsDown() throws IBuddyException { - IBuddy.sendWings(true, false); - } + public void setWingsDown() throws IBuddyException { + IBuddy.sendWings(true, false); + } - public void setWingsCenter() throws IBuddyException { - IBuddy.sendWings(false, false); - } + public void setWingsCenter() throws IBuddyException { + IBuddy.sendWings(false, false); + } - public void setWings(Direction direction) throws IBuddyException { - switch (direction) { - case UP: - setWingsUp(); - break; - case DOWN: - setWingsDown(); - break; - default: - setWingsCenter(); - break; - } - } + public void setWings(Direction direction) throws IBuddyException { + switch (direction) { + case UP: + setWingsUp(); + break; + case DOWN: + setWingsDown(); + break; + default: + setWingsCenter(); + break; + } + } - public void setRotateLeft() throws IBuddyException { - IBuddy.sendRotate(false, true); - } + public void setRotateLeft() throws IBuddyException { + IBuddy.sendRotate(false, true); + } - public void setRotateRight() throws IBuddyException { - IBuddy.sendRotate(true, false); - } + public void setRotateRight() throws IBuddyException { + IBuddy.sendRotate(true, false); + } - public void setRotateCenter() throws IBuddyException { - IBuddy.sendRotate(false, false); - } + public void setRotateCenter() throws IBuddyException { + IBuddy.sendRotate(false, false); + } - public void setRotate(Direction direction) throws IBuddyException { - switch (direction) { - case LEFT: - setRotateLeft(); - break; - case RIGHT: - setRotateRight(); - default: - setRotateCenter(); - } - } + public void setRotate(Direction direction) throws IBuddyException { + switch (direction) { + case LEFT: + setRotateLeft(); + break; + case RIGHT: + setRotateRight(); + default: + setRotateCenter(); + } + } - public void off() throws IBuddyException { - IBuddy.sendAllOff(); - } + public void off() throws IBuddyException { + IBuddy.sendAllOff(); + } - public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException { - IBuddyUtils.blink(IBuddy, mapColor(color), onTime, offTime, times); - } + public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException { + IBuddyUtils.blink(IBuddy, mapColor(color), onTime, offTime, times); + } - public void nudge(int delay, int times) throws IBuddyException { - IBuddyUtils.nudge(IBuddy, delay, times); - } + public void nudge(int delay, int times) throws IBuddyException { + IBuddyUtils.nudge(IBuddy, delay, times); + } - public void flap(int delay, int times) throws IBuddyException { - IBuddyUtils.flap(IBuddy, delay, times); - } + public void flap(int delay, int times) throws IBuddyException { + IBuddyUtils.flap(IBuddy, delay, times); + } - protected org.jraf.jlibibuddy.IBuddy.Color mapColor(Color color) { - return color.equals(Color.NONE) - ? org.jraf.jlibibuddy.IBuddy.Color.OFF - : org.jraf.jlibibuddy.IBuddy.Color.valueOf(color.name()); - } + protected org.jraf.jlibibuddy.IBuddy.Color mapColor(Color color) { + return color.equals(Color.NONE) + ? org.jraf.jlibibuddy.IBuddy.Color.OFF + : org.jraf.jlibibuddy.IBuddy.Color.valueOf(color.name()); + } } diff --git a/src/main/java/com/github/boukefalos/ibuddy/implementation/Remote.java b/src/main/java/com/github/boukefalos/ibuddy/implementation/Remote.java index 7114070..5184ef9 100644 --- a/src/main/java/com/github/boukefalos/ibuddy/implementation/Remote.java +++ b/src/main/java/com/github/boukefalos/ibuddy/implementation/Remote.java @@ -25,162 +25,162 @@ import base.Sender; import com.github.boukefalos.ibuddy.iBuddy; public class Remote implements iBuddy, Control { - protected final static int BUFFER_SIZE = 1024; - protected Logger logger = LoggerFactory.getLogger(getClass()); + protected final static int BUFFER_SIZE = 1024; + protected Logger logger = LoggerFactory.getLogger(getClass()); - protected Sender sender; + protected Sender sender; - public Remote(Sender sender) { - this.sender = sender; - } + public Remote(Sender sender) { + this.sender = sender; + } - public void start() { - sender.start(); - } + public void start() { + sender.start(); + } - public void stop() { - sender.stop(); - } + public void stop() { + sender.stop(); + } - public void exit() { - sender.exit(); - } + public void exit() { + sender.exit(); + } - public void setHeart(boolean on) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.HEART) - .setHeart(Heart.newBuilder() - .setState(mapState(on))).build()); - } + public void setHeart(boolean on) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.HEART) + .setHeart(Heart.newBuilder() + .setState(mapState(on))).build()); + } - public void setHeadRed(boolean on) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.HEAD) - .setHead(Head.newBuilder() - .setState(mapState(on)) - .setSingle(true) - .setColor(Color.RED)).build()); - } + public void setHeadRed(boolean on) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.HEAD) + .setHead(Head.newBuilder() + .setState(mapState(on)) + .setSingle(true) + .setColor(Color.RED)).build()); + } - public void setHeadBlue(boolean on) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.HEAD) - .setHead(Head.newBuilder() - .setState(mapState(on)) - .setSingle(true) - .setColor(Color.BLUE)).build()); - } + public void setHeadBlue(boolean on) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.HEAD) + .setHead(Head.newBuilder() + .setState(mapState(on)) + .setSingle(true) + .setColor(Color.BLUE)).build()); + } - public void setHeadGreen(boolean on) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.HEAD) - .setHead(Head.newBuilder() - .setState(mapState(on)) - .setSingle(true) - .setColor(Color.GREEN)).build()); - } + public void setHeadGreen(boolean on) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.HEAD) + .setHead(Head.newBuilder() + .setState(mapState(on)) + .setSingle(true) + .setColor(Color.GREEN)).build()); + } - public void setHead(Color color) throws IBuddyException { - State state = mapState(!color.equals(Color.NONE)); - send( - Command.newBuilder() - .setType(Type.HEAD) - .setHead(Head.newBuilder() - .setState(state) - .setSingle(false) - .setColor(color)).build()); - } + public void setHead(Color color) throws IBuddyException { + State state = mapState(!color.equals(Color.NONE)); + send( + Command.newBuilder() + .setType(Type.HEAD) + .setHead(Head.newBuilder() + .setState(state) + .setSingle(false) + .setColor(color)).build()); + } - public void setWingsUp() throws IBuddyException { - setWings(Direction.UP); - } + public void setWingsUp() throws IBuddyException { + setWings(Direction.UP); + } - public void setWingsDown() throws IBuddyException { - setWings(Direction.DOWN); - } + public void setWingsDown() throws IBuddyException { + setWings(Direction.DOWN); + } - public void setWingsCenter() throws IBuddyException { - setWings(Direction.CENTER); - } + public void setWingsCenter() throws IBuddyException { + setWings(Direction.CENTER); + } - public void setWings(Direction direction) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.WINGS) - .setWings(Wings.newBuilder() - .setDirection(direction)).build()); - } + public void setWings(Direction direction) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.WINGS) + .setWings(Wings.newBuilder() + .setDirection(direction)).build()); + } - public void setRotateLeft() throws IBuddyException { - setRotate(Direction.LEFT); - } + public void setRotateLeft() throws IBuddyException { + setRotate(Direction.LEFT); + } - public void setRotateRight() throws IBuddyException { - setRotate(Direction.RIGHT); - } + public void setRotateRight() throws IBuddyException { + setRotate(Direction.RIGHT); + } - public void setRotateCenter() throws IBuddyException { - setRotate(Direction.CENTER); - } + public void setRotateCenter() throws IBuddyException { + setRotate(Direction.CENTER); + } - public void setRotate(Direction direction) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.ROTATE) - .setRotate(Rotate.newBuilder() - .setDirection(direction)).build()); - } + public void setRotate(Direction direction) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.ROTATE) + .setRotate(Rotate.newBuilder() + .setDirection(direction)).build()); + } - public void off() throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.STATE).build()); - } + public void off() throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.STATE).build()); + } - public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.BLINK) - .setBlink(Blink.newBuilder() - .setOnTime(onTime) - .setOffTime(offTime) - .setTimes(times)).build()); - } + public void blink(Color color, int onTime, int offTime, int times) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.BLINK) + .setBlink(Blink.newBuilder() + .setOnTime(onTime) + .setOffTime(offTime) + .setTimes(times)).build()); + } - public void nudge(int delay, int times) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.NUDGE) - .setNudge(Nudge.newBuilder() - .setDelay(delay) - .setTimes(times)).build()); - } + public void nudge(int delay, int times) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.NUDGE) + .setNudge(Nudge.newBuilder() + .setDelay(delay) + .setTimes(times)).build()); + } - public void flap(int delay, int times) throws IBuddyException { - send( - Command.newBuilder() - .setType(Type.FLAP) - .setFlap(Flap.newBuilder() - .setDelay(delay) - .setTimes(times)).build()); - } + public void flap(int delay, int times) throws IBuddyException { + send( + Command.newBuilder() + .setType(Type.FLAP) + .setFlap(Flap.newBuilder() + .setDelay(delay) + .setTimes(times)).build()); + } - protected static State mapState(boolean on) { - return on ? State.ON : State.OFF; - } + protected static State mapState(boolean on) { + return on ? State.ON : State.OFF; + } - protected void send(Command command) { - ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); - try { - command.writeDelimitedTo(output); - sender.send(output.toByteArray()); - } catch (IOException e) { - logger.error("Failed to send command"); - } - } + protected void send(Command command) { + ByteArrayOutputStream output = new ByteArrayOutputStream(BUFFER_SIZE); + try { + command.writeDelimitedTo(output); + sender.send(output.toByteArray()); + } catch (IOException e) { + logger.error("Failed to send command"); + } + } } diff --git a/src/main/java/org/jraf/jlibibuddy/IBuddy.java b/src/main/java/org/jraf/jlibibuddy/IBuddy.java index adf6427..18c77ce 100644 --- a/src/main/java/org/jraf/jlibibuddy/IBuddy.java +++ b/src/main/java/org/jraf/jlibibuddy/IBuddy.java @@ -205,18 +205,18 @@ public class IBuddy { * @param command the command byte. */ private synchronized void sendMessage(byte command) throws IBuddyException { - open(); + open(); try { device.controlMsg(USB.REQ_TYPE_TYPE_CLASS | USB.REQ_TYPE_RECIP_INTERFACE, USB.REQ_SET_CONFIGURATION, 0x02, 0x01, INIT, INIT.length, 100, true); } catch (USBException e) { - close(); + close(); throw new IBuddyException("Could not send message to i-Buddy", e); } byte[] commandMessage = getCommandMessage(command); try { device.controlMsg(USB.REQ_TYPE_TYPE_CLASS | USB.REQ_TYPE_RECIP_INTERFACE, USB.REQ_SET_CONFIGURATION, 0x02, 0x01, commandMessage, commandMessage.length, 100, true); } catch (USBException e) { - close(); + close(); throw new IBuddyException("Could not send message to i-Buddy", e); } close(); diff --git a/src/test/java/test/TestOriginal.java b/src/test/java/test/TestOriginal.java index 7115931..66966b5 100644 --- a/src/test/java/test/TestOriginal.java +++ b/src/test/java/test/TestOriginal.java @@ -5,26 +5,26 @@ import org.jraf.jlibibuddy.IBuddyException; import org.jraf.jlibibuddy.IBuddyUtils; public class TestOriginal { - public static void main(String[] args) { - IBuddy iBuddy = IBuddy.getIBuddy(); + public static void main(String[] args) { + IBuddy iBuddy = IBuddy.getIBuddy(); try { - while (true) { - iBuddy.sendAllOff(); - for (Color color : IBuddy.Color.values()) { - iBuddy.sendHeart(false); - iBuddy.sendHeadColor(color); - Thread.sleep(100); - iBuddy.sendHeart(true); - Thread.sleep(500); - } - iBuddy.sendAllOff(); - Thread.sleep(2000); + while (true) { + iBuddy.sendAllOff(); + for (Color color : IBuddy.Color.values()) { + iBuddy.sendHeart(false); + iBuddy.sendHeadColor(color); + Thread.sleep(100); + iBuddy.sendHeart(true); + Thread.sleep(500); + } + iBuddy.sendAllOff(); + Thread.sleep(2000); IBuddyUtils.flap(iBuddy, 400, 6); - } - } catch (IBuddyException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + } + } catch (IBuddyException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/test/java/test/TestTcpCommunication.java b/src/test/java/test/TestTcpCommunication.java index 791cb6e..1f22b02 100644 --- a/src/test/java/test/TestTcpCommunication.java +++ b/src/test/java/test/TestTcpCommunication.java @@ -9,36 +9,36 @@ import com.github.boukefalos.ibuddy.Server; import com.github.boukefalos.ibuddy.iBuddy; public class TestTcpCommunication { - public static void main(String[] args) { - try { - Properties localProperties = new Properties(); - localProperties.setProperty("implementation", "local"); - localProperties.setProperty("server", "true"); - localProperties.setProperty("server.port", "8883"); - localProperties.setProperty("server.protocol", "tcp"); - localProperties.setProperty("tcp.implementation", "socket"); + public static void main(String[] args) { + try { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "tcp"); + localProperties.setProperty("tcp.implementation", "socket"); - Properties remoteProperties = new Properties(); - remoteProperties.setProperty("implementation", "remote"); - remoteProperties.setProperty("protocol", "tcp"); - remoteProperties.setProperty("remote.host", "localhost"); - remoteProperties.setProperty("remote.port", "8883"); + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "tcp"); + remoteProperties.setProperty("remote.host", "localhost"); + remoteProperties.setProperty("remote.port", "8883"); - Loader localLoader = new Loader(localProperties); - Loader remoteLoader = new Loader(remoteProperties); + Loader localLoader = new Loader(localProperties); + Loader remoteLoader = new Loader(remoteProperties); - Server server = localLoader.getServer(); - iBuddy iBuddy = remoteLoader.getiBuddy(); + Server server = localLoader.getServer(); + iBuddy iBuddy = remoteLoader.getiBuddy(); - server.start(); - iBuddy.start(); + server.start(); + iBuddy.start(); - iBuddy.setHead(Color.GREEN); + iBuddy.setHead(Color.GREEN); - server.exit(); - iBuddy.exit(); - } catch (Exception e) { - e.printStackTrace(); - } - } + server.exit(); + iBuddy.exit(); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/test/java/test/TestUdpCommunication.java b/src/test/java/test/TestUdpCommunication.java index 8014ebf..e5da74b 100644 --- a/src/test/java/test/TestUdpCommunication.java +++ b/src/test/java/test/TestUdpCommunication.java @@ -9,36 +9,36 @@ import com.github.boukefalos.ibuddy.Server; import com.github.boukefalos.ibuddy.iBuddy; public class TestUdpCommunication { - public static void main(String[] args) { - try { - Properties localProperties = new Properties(); - localProperties.setProperty("implementation", "local"); - localProperties.setProperty("protocol", "udp"); - localProperties.setProperty("server", "true"); - localProperties.setProperty("server.port", "8883"); - localProperties.setProperty("server.protocol", "udp"); + public static void main(String[] args) { + try { + Properties localProperties = new Properties(); + localProperties.setProperty("implementation", "local"); + localProperties.setProperty("protocol", "udp"); + localProperties.setProperty("server", "true"); + localProperties.setProperty("server.port", "8883"); + localProperties.setProperty("server.protocol", "udp"); - Properties remoteProperties = new Properties(); - remoteProperties.setProperty("implementation", "remote"); - remoteProperties.setProperty("protocol", "udp"); - remoteProperties.setProperty("remote.host", "255.255.255.255"); - remoteProperties.setProperty("remote.port", "8883"); + Properties remoteProperties = new Properties(); + remoteProperties.setProperty("implementation", "remote"); + remoteProperties.setProperty("protocol", "udp"); + remoteProperties.setProperty("remote.host", "255.255.255.255"); + remoteProperties.setProperty("remote.port", "8883"); - Loader localLoader = new Loader(localProperties); - Loader remoteLoader = new Loader(remoteProperties); + Loader localLoader = new Loader(localProperties); + Loader remoteLoader = new Loader(remoteProperties); - iBuddy iBuddy = remoteLoader.getiBuddy(); - Server server = localLoader.getServer(); + iBuddy iBuddy = remoteLoader.getiBuddy(); + Server server = localLoader.getServer(); - iBuddy.start(); - server.start(); + iBuddy.start(); + server.start(); - iBuddy.setHead(Color.WHITE); + iBuddy.setHead(Color.WHITE); - server.exit(); - iBuddy.exit(); - } catch (Exception e) { - e.printStackTrace(); - } - } + server.exit(); + iBuddy.exit(); + } catch (Exception e) { + e.printStackTrace(); + } + } }