modified dmx addressing in devices

This commit is contained in:
Lucas Pleß 2012-03-07 19:17:43 +01:00
parent 99ae75b88f
commit 2043cf7fee
4 changed files with 39 additions and 24 deletions

View File

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

View File

@ -35,7 +35,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
}
public final void initDMXData() {
for (int i = 0; i <= DMX.DMX_CHANNELS_MAX; i++) {
for (int i = 0; i <= DMX.DMX_CHANNEL_INDEX_MAX; i++) {
dmxMap.put(i, 0);
}
}

View File

@ -15,7 +15,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
super(deviceId, name);
this.startAddress = startAddress;
setStartAddress(startAddress);
}
public final long getLastSendOut() {
@ -30,8 +30,13 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
return startAddress;
}
public final void setStartAddress(int startAddress) {
public final boolean setStartAddress(int startAddress) {
if(startAddress < DMX.DMX_CHANNEL_INDEX_MIN ||
startAddress - 1 + dmxChannels.getCount() > DMX.DMX_CHANNEL_INDEX_MAX) {
return false;
}
this.startAddress = startAddress;
return true;
}
/**
@ -73,11 +78,11 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
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;

View File

@ -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,13 +126,20 @@ public class BuntiDMXDeviceTest {
Map<Integer,Integer> 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 {
dut.addChannel(new DMXChannel(5, "channel"));