modified dmx addressing in devices
This commit is contained in:
parent
99ae75b88f
commit
2043cf7fee
|
@ -2,17 +2,11 @@ package de.ctdo.bunti.dmx;
|
||||||
|
|
||||||
public final class DMX {
|
public final class DMX {
|
||||||
|
|
||||||
public static final int DMX_CHANNELS_MAX = 511;
|
public static final int DMX_CHANNEL_INDEX_MAX = 512;
|
||||||
public static final int DMX_CHANNELS_MIN = 0;
|
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_MAX = 255;
|
||||||
public static final int DMX_CHANNEL_VALUE_MIN = 0;
|
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() {
|
private DMX() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +14,7 @@ public final class DMX {
|
||||||
/**
|
/**
|
||||||
* Checks the DMX Value boundaries
|
* Checks the DMX Value boundaries
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value the DMX channel value to sanitize
|
||||||
* @return A valid DMX512 channel value
|
* @return A valid DMX512 channel value
|
||||||
*/
|
*/
|
||||||
public static int sanitizeDMXValue(int value) {
|
public static int sanitizeDMXValue(int value) {
|
||||||
|
@ -40,7 +34,7 @@ public final class DMX {
|
||||||
* @return True if channel is valid. Otherwise false.
|
* @return True if channel is valid. Otherwise false.
|
||||||
*/
|
*/
|
||||||
public static boolean checkChannelBoundaries(int channel) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.util.Map;
|
||||||
@Component
|
@Component
|
||||||
|
|
||||||
public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChangedEvent> {
|
public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChangedEvent> {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class);
|
||||||
private String artNetDeviceAddress;
|
private String artNetDeviceAddress;
|
||||||
|
|
||||||
private final Map<Integer, Integer> dmxMap = Collections.synchronizedMap(new HashMap<Integer, Integer>());
|
private final Map<Integer, Integer> dmxMap = Collections.synchronizedMap(new HashMap<Integer, Integer>());
|
||||||
|
@ -35,7 +35,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void initDMXData() {
|
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);
|
dmxMap.put(i, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
|
|
||||||
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
|
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
|
||||||
super(deviceId, name);
|
super(deviceId, name);
|
||||||
this.startAddress = startAddress;
|
setStartAddress(startAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getLastSendOut() {
|
public final long getLastSendOut() {
|
||||||
|
@ -30,8 +30,13 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
return startAddress;
|
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;
|
this.startAddress = startAddress;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,11 +78,11 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
|
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
|
||||||
|
|
||||||
for (DMXChannel channel : dmxChannels.getAllChannels()) {
|
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());
|
map.put(index, channel.getValue());
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package de.ctdo.bunti.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.DMX;
|
|
||||||
import de.ctdo.bunti.dmx.DMXChannel;
|
import de.ctdo.bunti.dmx.DMXChannel;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -47,6 +46,16 @@ public class BuntiDMXDeviceTest {
|
||||||
assertEquals(333, dut.getStartAddress());
|
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
|
@Test
|
||||||
public void testSetValuesFromOptions() throws Exception {
|
public void testSetValuesFromOptions() throws Exception {
|
||||||
|
@ -86,7 +95,7 @@ public class BuntiDMXDeviceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetChannelValueWrong() throws Exception {
|
public void testGetChannelValueWrong() throws Exception {
|
||||||
assertEquals(dut.getChannelValueByName("nonexistent"),0 );
|
assertEquals(dut.getChannelValueByName("nonexistent"), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -117,12 +126,19 @@ public class BuntiDMXDeviceTest {
|
||||||
|
|
||||||
Map<Integer,Integer> channelData = dut.getChannelData();
|
Map<Integer,Integer> channelData = dut.getChannelData();
|
||||||
|
|
||||||
assertEquals(new Integer(222), channelData.get(STARTADDRESS + 0 + DMX.DMX_STARTADDRESS_OFFSET));
|
assertEquals(new Integer(222), channelData.get(STARTADDRESS));
|
||||||
assertEquals(new Integer(66), channelData.get(STARTADDRESS + 1 + DMX.DMX_STARTADDRESS_OFFSET));
|
assertEquals(new Integer(66), channelData.get(STARTADDRESS + 1));
|
||||||
assertEquals(new Integer(77), channelData.get(STARTADDRESS + 2 + DMX.DMX_STARTADDRESS_OFFSET));
|
assertEquals(new Integer(77), channelData.get(STARTADDRESS + 2));
|
||||||
assertEquals(new Integer(99), channelData.get(STARTADDRESS + 3 + DMX.DMX_STARTADDRESS_OFFSET));
|
assertEquals(new Integer(99), channelData.get(STARTADDRESS + 3));
|
||||||
assertEquals(new Integer(111), channelData.get(STARTADDRESS + 4 + DMX.DMX_STARTADDRESS_OFFSET));
|
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
|
@Test
|
||||||
public void testAddChannel() throws Exception {
|
public void testAddChannel() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue