From 2043cf7fee1b42593dd09451ae155a20920976e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 7 Mar 2012 19:17:43 +0100 Subject: [PATCH] modified dmx addressing in devices --- src/main/java/de/ctdo/bunti/dmx/DMX.java | 14 +++------ .../java/de/ctdo/bunti/dmx/DMXMixerImpl.java | 4 +-- .../de/ctdo/bunti/model/BuntiDMXDevice.java | 15 ++++++---- .../ctdo/bunti/model/BuntiDMXDeviceTest.java | 30 ++++++++++++++----- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/ctdo/bunti/dmx/DMX.java b/src/main/java/de/ctdo/bunti/dmx/DMX.java index 5f72185..5f655b4 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMX.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMX.java @@ -2,17 +2,11 @@ package de.ctdo.bunti.dmx; public final class DMX { - public static final int DMX_CHANNELS_MAX = 511; - public static final int DMX_CHANNELS_MIN = 0; + public static final int DMX_CHANNEL_INDEX_MAX = 512; + public static final int DMX_CHANNEL_INDEX_MIN = 1; public static final int DMX_CHANNEL_VALUE_MAX = 255; public static final int DMX_CHANNEL_VALUE_MIN = 0; - /** - * Offset by which startaddress differs from DMX512 Data Array location - */ - public static final int DMX_STARTADDRESS_OFFSET = -1; - - private DMX() { } @@ -20,7 +14,7 @@ public final class DMX { /** * Checks the DMX Value boundaries * - * @param value + * @param value the DMX channel value to sanitize * @return A valid DMX512 channel value */ public static int sanitizeDMXValue(int value) { @@ -40,7 +34,7 @@ public final class DMX { * @return True if channel is valid. Otherwise false. */ public static boolean checkChannelBoundaries(int channel) { - return (channel >= DMX_CHANNELS_MIN && channel <= DMX_CHANNELS_MAX); + return (channel >= DMX_CHANNEL_INDEX_MIN && channel <= DMX_CHANNEL_INDEX_MAX); } diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java index 90029e3..8526a2a 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMXMixerImpl.java @@ -18,7 +18,7 @@ import java.util.Map; @Component public class DMXMixerImpl implements DMXMixer, ApplicationListener { - private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class); private String artNetDeviceAddress; private final Map dmxMap = Collections.synchronizedMap(new HashMap()); @@ -35,7 +35,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener DMX.DMX_CHANNEL_INDEX_MAX) { + return false; + } this.startAddress = startAddress; + return true; } /** @@ -73,11 +78,11 @@ public abstract class BuntiDMXDevice extends BuntiDevice { Map map = new HashMap(); for (DMXChannel channel : dmxChannels.getAllChannels()) { - int index = channel.getOffset() + startAddress + DMX.DMX_STARTADDRESS_OFFSET; + int index = channel.getOffset() + startAddress; - if (index >= DMX.DMX_CHANNELS_MIN && index <= DMX.DMX_CHANNELS_MAX) { +// if (index >= DMX.DMX_CHANNEL_INDEX_MIN && index <= DMX.DMX_CHANNEL_INDEX_MAX) { map.put(index, channel.getValue()); - } +// } } return map; diff --git a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java index 7906270..43fdcef 100644 --- a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java +++ b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java @@ -1,6 +1,5 @@ package de.ctdo.bunti.model; -import de.ctdo.bunti.dmx.DMX; import de.ctdo.bunti.dmx.DMXChannel; import org.junit.Before; import org.junit.Test; @@ -47,6 +46,16 @@ public class BuntiDMXDeviceTest { assertEquals(333, dut.getStartAddress()); } + @Test + public void testSetStartAddressWrong1() throws Exception { + assertFalse(dut.setStartAddress(0)); + } + + @Test + public void testSetStartAddressWrong2() throws Exception { + assertFalse(dut.setStartAddress(513)); + } + @Test public void testSetValuesFromOptions() throws Exception { @@ -86,7 +95,7 @@ public class BuntiDMXDeviceTest { @Test public void testGetChannelValueWrong() throws Exception { - assertEquals(dut.getChannelValueByName("nonexistent"),0 ); + assertEquals(dut.getChannelValueByName("nonexistent"), 0); } @Test @@ -117,12 +126,19 @@ public class BuntiDMXDeviceTest { Map channelData = dut.getChannelData(); - assertEquals(new Integer(222), channelData.get(STARTADDRESS + 0 + DMX.DMX_STARTADDRESS_OFFSET)); - assertEquals(new Integer(66), channelData.get(STARTADDRESS + 1 + DMX.DMX_STARTADDRESS_OFFSET)); - assertEquals(new Integer(77), channelData.get(STARTADDRESS + 2 + DMX.DMX_STARTADDRESS_OFFSET)); - assertEquals(new Integer(99), channelData.get(STARTADDRESS + 3 + DMX.DMX_STARTADDRESS_OFFSET)); - assertEquals(new Integer(111), channelData.get(STARTADDRESS + 4 + DMX.DMX_STARTADDRESS_OFFSET)); + assertEquals(new Integer(222), channelData.get(STARTADDRESS)); + assertEquals(new Integer(66), channelData.get(STARTADDRESS + 1)); + assertEquals(new Integer(77), channelData.get(STARTADDRESS + 2)); + assertEquals(new Integer(99), channelData.get(STARTADDRESS + 3)); + assertEquals(new Integer(111), channelData.get(STARTADDRESS + 4)); } + +// @Test +// public void testGetChannelDataIndex() throws Exception { +// dut = new Par56Spot(42, -10, "faultdevice"); +// dut.setChannelValueByName("red", 23); +// assertEquals(5, dut.getChannelData().size()); +// } @Test public void testAddChannel() throws Exception {