diff --git a/pom.xml b/pom.xml index c877eb5..a69d414 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,13 @@ 4.10 + + org.easymock + easymock + 3.0 + test + + org.eclipse.jetty jetty-server diff --git a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java index 33cf9c1..c702647 100644 --- a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java +++ b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java @@ -31,11 +31,11 @@ public class ByteUtils { this.data = data; } - public static final int byteToUint(byte b) { + public static int byteToUint(byte b) { return (b < 0 ? BYTE_OVERFLOW + b : b); } - public static final byte uintToByte(int i) { + public static byte uintToByte(int i) { return (byte)(i & BYTE_MAX); } diff --git a/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java b/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java index 759d475..511f57c 100644 --- a/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java +++ b/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java @@ -119,8 +119,8 @@ public class ArtDmxPacket extends ArtNetPacket { /** * Sets universe and subnet into data array. Needed because subnet and universe are both 4 bit and share one byte - * @param subnetID - * @param universeID + * @param subnetID The ArtNet Subnet ID from 0 to 3 + * @param universeID The ArtNet Universe ID from 0 to 3 */ private void setUniverse(int subnetID, int universeID) { getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE); diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java index 0241d5f..c316c81 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java @@ -45,6 +45,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener options); + } diff --git a/src/main/java/de/ctdo/bunti/model/Par56Spot.java b/src/main/java/de/ctdo/bunti/model/Par56Spot.java index d1d1f13..c59c0e2 100644 --- a/src/main/java/de/ctdo/bunti/model/Par56Spot.java +++ b/src/main/java/de/ctdo/bunti/model/Par56Spot.java @@ -21,45 +21,45 @@ public class Par56Spot extends BuntiDMXDevice { addChannel(new DMXChannel(offset, CHANNEL_SPEED)); } - public final void setColorRed(int value) { + public final void setRed(int value) { setChannelValueByName(CHANNEL_RED, value); } - public final void setColorGreen(int value) { + public final void setGreen(int value) { setChannelValueByName(CHANNEL_GREEN, value); } - public final void setColorBlue(int value) { + public final void setBlue(int value) { setChannelValueByName(CHANNEL_BLUE, value); } - public final int getColorRed() { + public final int getRed() { return getChannelValueByName(CHANNEL_RED); } - public final int getColorGreen() { + public final int getGreen() { return getChannelValueByName(CHANNEL_GREEN); } - public final int getColorBlue() { + public final int getBlue() { return getChannelValueByName(CHANNEL_BLUE); } @Override public final void switchOff() { setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN); - setColorRed(DMX.DMX_CHANNEL_VALUE_MIN); - setColorGreen(DMX.DMX_CHANNEL_VALUE_MIN); - setColorBlue(DMX.DMX_CHANNEL_VALUE_MIN); + setRed(DMX.DMX_CHANNEL_VALUE_MIN); + setGreen(DMX.DMX_CHANNEL_VALUE_MIN); + setBlue(DMX.DMX_CHANNEL_VALUE_MIN); setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN); } @Override public final void switchOn() { setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN); - setColorRed(DMX.DMX_CHANNEL_VALUE_MAX); - setColorGreen(DMX.DMX_CHANNEL_VALUE_MAX); - setColorBlue(DMX.DMX_CHANNEL_VALUE_MAX); + setRed(DMX.DMX_CHANNEL_VALUE_MAX); + setGreen(DMX.DMX_CHANNEL_VALUE_MAX); + setBlue(DMX.DMX_CHANNEL_VALUE_MAX); setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN); } @@ -71,11 +71,11 @@ public class Par56Spot extends BuntiDMXDevice { sb.append(", "); sb.append(getDeviceName()); sb.append(" ["); - sb.append(getColorRed()); + sb.append(getRed()); sb.append(","); - sb.append(getColorGreen()); + sb.append(getGreen()); sb.append(","); - sb.append(getColorBlue()); + sb.append(getBlue()); sb.append("]"); return sb.toString(); } diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java index e7a62c7..3cf790e 100644 --- a/src/main/java/de/ctdo/bunti/web/RestController.java +++ b/src/main/java/de/ctdo/bunti/web/RestController.java @@ -30,18 +30,6 @@ public class RestController { this.controller = controller; } - @RequestMapping(value = "/devices2", method = RequestMethod.GET) - public @ResponseBody DeviceUpdate testGet() { - DeviceUpdate update = new DeviceUpdate(); - update.setDeviceId(23); - Map options = new HashMap(); - options.put("red", 111); - options.put("green", 2); - options.put("blue", 33); - update.setOptions(options); - return update; - } - @RequestMapping(value = "/devices", method = RequestMethod.GET) public @ResponseBody Collection getAll() { LOGGER.info("handle GET /devices request"); @@ -54,37 +42,26 @@ public class RestController { return controller.getDeviceById(id); } - @RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT) - public String setDeviceById(@PathVariable("id") int id, @RequestBody Map update) { + @RequestMapping(value = "/devices/{id}", method = RequestMethod.POST) + public @ResponseBody BuntiDevice setDeviceById(@PathVariable("id") int id, @RequestBody DeviceUpdate update) { LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() ); - controller.updateDeviceData(id, update); - return "redirect:devices/" + id; + + controller.updateDeviceData(id, update.getOptions()); + return controller.getDeviceById(id); } - @RequestMapping(value = "/devices", method = RequestMethod.PUT) - public String setDevices(@RequestBody ArrayList updates) { + @RequestMapping(value = "/devices", method = RequestMethod.POST) + public String setDevices(@RequestBody DeviceUpdates updates) { LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() ); - for (DeviceUpdate update: updates) { + for (DeviceUpdate update: updates.getUpdates()) { LOGGER.info("Update deviceId=" + update.getDeviceId()); controller.updateDeviceData(update.getDeviceId(), update.getOptions()); } - return "redirect:devices"; - } - - @RequestMapping(value = "/devices2", method = RequestMethod.PUT) - public String setDevices2(@RequestBody DeviceUpdate update) { - LOGGER.info("handle PUT /devices" + " request update=" + update.toString() ); - - LOGGER.info("Update deviceId=" + update.getDeviceId()); - - controller.updateDeviceData(update.getDeviceId(), update.getOptions()); - - - return "redirect:devices"; + return "bla"; } } diff --git a/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java b/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java index f8abcd0..55a4b84 100644 --- a/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java +++ b/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdates.java @@ -1,10 +1,29 @@ package de.ctdo.bunti.webmodel; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; public class DeviceUpdates { + private long timeStamp = 0; + + private List updates = new ArrayList(); + public List getUpdates() { + return updates; + } + public void setUpdates(List updates) { + this.updates = updates; + } + + public long getTimeStamp() { + return timeStamp; + } + + public void setTimeStamp(long timeStamp) { + this.timeStamp = timeStamp; + } } diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index f299a85..d62be13 100644 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -12,7 +12,7 @@ - + diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index fcf046e..3347166 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -14,53 +14,74 @@

Bunti Steuerung

- +
+
+
+
+
-
-
-
-
-
+
- + \ No newline at end of file diff --git a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java index 5153f01..c3583f9 100644 --- a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java +++ b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java @@ -142,4 +142,15 @@ public class BuntiDMXDeviceTest { assertEquals(DEVICEID, dut.getDeviceId()); } + @Test + public void testGetPicture() throws Exception { + dut.setPicture("urltopicture"); + assertEquals("urltopicture", dut.getPicture()); + } + + @Test + public void testGetType() throws Exception { + assertEquals("Par56Spot", dut.getType()); + } + } diff --git a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java index 87aff24..fb1b664 100644 --- a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java +++ b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java @@ -15,55 +15,55 @@ public class Par56SpotTest { @Test public void testColorRed() throws Exception { - dut.setColorRed(0); - assertEquals(0,dut.getColorRed()); - dut.setColorRed(128); - assertEquals(128,dut.getColorRed()); - dut.setColorRed(255); - assertEquals(255,dut.getColorRed()); + dut.setRed(0); + assertEquals(0,dut.getRed()); + dut.setRed(128); + assertEquals(128,dut.getRed()); + dut.setRed(255); + assertEquals(255,dut.getRed()); } @Test public void testColorGreen() throws Exception { - dut.setColorGreen(0); - assertEquals(0,dut.getColorGreen()); - dut.setColorGreen(128); - assertEquals(128,dut.getColorGreen()); - dut.setColorGreen(255); - assertEquals(255,dut.getColorGreen()); + dut.setGreen(0); + assertEquals(0,dut.getGreen()); + dut.setGreen(128); + assertEquals(128,dut.getGreen()); + dut.setGreen(255); + assertEquals(255,dut.getGreen()); } @Test public void testColorBlue() throws Exception { - dut.setColorBlue(0); - assertEquals(0,dut.getColorBlue()); - dut.setColorBlue(128); - assertEquals(128,dut.getColorBlue()); - dut.setColorBlue(255); - assertEquals(255,dut.getColorBlue()); + dut.setBlue(0); + assertEquals(0,dut.getBlue()); + dut.setBlue(128); + assertEquals(128,dut.getBlue()); + dut.setBlue(255); + assertEquals(255,dut.getBlue()); } @Test public void testSwitchOff() throws Exception { dut.switchOff(); - assertEquals(0,dut.getColorRed()); - assertEquals(0,dut.getColorGreen()); - assertEquals(0,dut.getColorBlue()); + assertEquals(0,dut.getRed()); + assertEquals(0,dut.getGreen()); + assertEquals(0,dut.getBlue()); } @Test public void testSwitchOn() throws Exception { dut.switchOn(); - assertEquals(255,dut.getColorRed()); - assertEquals(255,dut.getColorGreen()); - assertEquals(255,dut.getColorBlue()); + assertEquals(255,dut.getRed()); + assertEquals(255,dut.getGreen()); + assertEquals(255,dut.getBlue()); } @Test public void testToString() throws Exception { - dut.setColorRed(123); - dut.setColorGreen(111); - dut.setColorBlue(42); + dut.setRed(123); + dut.setGreen(111); + dut.setBlue(42); assertEquals("Par56Spot 23, device [123,111,42]", dut.toString()); } }