auf spring ApplicationListener umgebaut.
Die Mixer bekommen nun DeviceChangedEvents wenn sich ein Gerät updatet.
This commit is contained in:
parent
7d2ab0dd44
commit
d8817c2e46
|
@ -0,0 +1,34 @@
|
||||||
|
package de.ctdo.bunti;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.model.BuntiDevice;
|
||||||
|
|
||||||
|
public class DeviceChangedEvent extends ApplicationEvent {
|
||||||
|
private static final long serialVersionUID = 104525838879412827L;
|
||||||
|
private BuntiDevice device;
|
||||||
|
private Map<String, Object> options;
|
||||||
|
|
||||||
|
public DeviceChangedEvent(Object source, BuntiDevice device, Map<String, Object> options) {
|
||||||
|
super(source);
|
||||||
|
|
||||||
|
this.device = device;
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuntiDevice getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getOptions() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DeviceChangedEvent " + getDevice().getDeviceName();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
package de.ctdo.bunti;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import de.ctdo.bunti.model.BuntiDevice;
|
|
||||||
|
|
||||||
public interface Mixer {
|
|
||||||
|
|
||||||
public boolean setDevice(BuntiDevice device, Map<String, Object> options);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package de.ctdo.bunti.control;
|
|
||||||
|
|
||||||
public interface BroadcastListener {
|
|
||||||
void Broadcast(String message);
|
|
||||||
}
|
|
|
@ -5,49 +5,26 @@ import java.util.Map;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.context.ApplicationEventPublisherAware;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
|
import de.ctdo.bunti.DeviceChangedEvent;
|
||||||
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
||||||
import de.ctdo.bunti.devices.*;
|
|
||||||
import de.ctdo.bunti.dmx.*;
|
|
||||||
import de.ctdo.bunti.model.*;
|
import de.ctdo.bunti.model.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BuntiControllerImpl implements BuntiController {
|
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
||||||
Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
BuntiDevicesDAO devicesDAO;
|
private ApplicationEventPublisher applicationEventPublisher = null;
|
||||||
DMXMixer dmxMixer;
|
private BuntiDevicesDAO devicesDAO;
|
||||||
DeviceMixer deviceMixer;
|
|
||||||
|
|
||||||
// protected final List<BroadcastListener> listeners = new ArrayList<BroadcastListener>();
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setDmxMixer(DMXMixer dmxMixer) {
|
|
||||||
this.dmxMixer = dmxMixer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setDeviceMixer(DeviceMixer deviceMixer) {
|
|
||||||
this.deviceMixer = deviceMixer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
||||||
this.devicesDAO = devicesDAO;
|
this.devicesDAO = devicesDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void addListener(BroadcastListener l) {
|
|
||||||
// synchronized (listeners) {
|
|
||||||
// listeners.add(l);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// public void removeListener(BroadcastListener l) {
|
|
||||||
// synchronized (listeners) {
|
|
||||||
// listeners.remove(l);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void performJSONString(String json) {
|
public void performJSONString(String json) {
|
||||||
|
|
||||||
JSONObject jsonobj = JSONObject.fromObject(json);
|
JSONObject jsonobj = JSONObject.fromObject(json);
|
||||||
|
@ -71,13 +48,10 @@ public class BuntiControllerImpl implements BuntiController {
|
||||||
|
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
|
|
||||||
//TODO hier dann DeviceChangedEvent feuern
|
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
|
||||||
|
|
||||||
|
logger.debug("publishEvent in BuntiController");
|
||||||
|
|
||||||
if (device instanceof BuntiDMXDevice) {
|
|
||||||
dmxMixer.setDevice(device, options);
|
|
||||||
} else if (device instanceof BuntiSwitchingDevice) {
|
|
||||||
deviceMixer.setDevice(device, options);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +60,11 @@ public class BuntiControllerImpl implements BuntiController {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
|
||||||
|
this.applicationEventPublisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
// public void sendBroadcastMessage(String message) {
|
// public void sendBroadcastMessage(String message) {
|
||||||
// for (BroadcastListener l : listeners) {
|
// for (BroadcastListener l : listeners) {
|
||||||
// l.Broadcast(message);
|
// l.Broadcast(message);
|
||||||
|
|
|
@ -12,8 +12,8 @@ import de.ctdo.bunti.model.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||||
Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
||||||
|
|
||||||
public BuntiDevicesDAOImpl() {
|
public BuntiDevicesDAOImpl() {
|
||||||
addDummyDevices();
|
addDummyDevices();
|
||||||
|
@ -30,7 +30,7 @@ public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||||
devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
|
devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
|
||||||
|
|
||||||
devices.add(new Par56Spot(deviceID++, 508, "Par56 Lampe 5"));
|
devices.add(new Par56Spot(deviceID++, 508, "Par56 Lampe 5"));
|
||||||
|
logger.debug("added dummy devices in DAO");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||||
@Override
|
@Override
|
||||||
public BuntiDevice getDeviceById(int deviceId) {
|
public BuntiDevice getDeviceById(int deviceId) {
|
||||||
for (BuntiDevice dev : devices) {
|
for (BuntiDevice dev : devices) {
|
||||||
if(dev.getDeviceID() == deviceId) {
|
if(dev.getDeviceId() == deviceId) {
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package de.ctdo.bunti.devices;
|
package de.ctdo.bunti.devices;
|
||||||
|
|
||||||
|
|
||||||
import de.ctdo.bunti.Mixer;
|
import org.springframework.context.ApplicationListener;
|
||||||
|
|
||||||
public interface DeviceMixer extends Mixer {
|
import de.ctdo.bunti.DeviceChangedEvent;
|
||||||
|
|
||||||
|
public interface DeviceMixer extends ApplicationListener<DeviceChangedEvent> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,27 @@
|
||||||
package de.ctdo.bunti.devices;
|
package de.ctdo.bunti.devices;
|
||||||
|
|
||||||
import java.util.Map;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import de.ctdo.bunti.model.BuntiDMXDevice;
|
import de.ctdo.bunti.DeviceChangedEvent;
|
||||||
import de.ctdo.bunti.model.BuntiDevice;
|
import de.ctdo.bunti.model.BuntiSwitchingDevice;
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DeviceMixerImpl implements DeviceMixer {
|
public class DeviceMixerImpl implements DeviceMixer {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setDevice(BuntiDevice device, Map<String, Object> options) {
|
public void onApplicationEvent(DeviceChangedEvent arg0) {
|
||||||
|
|
||||||
|
if( arg0.getDevice() instanceof BuntiSwitchingDevice) {
|
||||||
|
|
||||||
|
BuntiSwitchingDevice switchDev = (BuntiSwitchingDevice)arg0.getDevice();
|
||||||
|
switchDev.setValuesFromOptions(arg0.getOptions());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
BuntiDMXDevice dmxDev = (BuntiDMXDevice)device;
|
|
||||||
return dmxDev.setValuesFromOptions(options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,27 @@ public class DMX {
|
||||||
public static int DMX_CHANNEL_VALUE_MAX = 255;
|
public static int DMX_CHANNEL_VALUE_MAX = 255;
|
||||||
public static int DMX_CHANNEL_VALUE_MIN = 0;
|
public static int DMX_CHANNEL_VALUE_MIN = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offset by which startaddress differs from DMX512 Data Array location
|
||||||
|
*/
|
||||||
|
public static int DMX_STARTADDRESS_OFFSET = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the DMX Value boundaries
|
||||||
|
* @param value
|
||||||
|
* @return A valid DMX512 channel value
|
||||||
|
*/
|
||||||
public static int sanitizeDMXValue(int value) {
|
public static int sanitizeDMXValue(int value) {
|
||||||
if(value < DMX_CHANNEL_VALUE_MIN) value = DMX_CHANNEL_VALUE_MIN;
|
if(value < DMX_CHANNEL_VALUE_MIN) value = DMX_CHANNEL_VALUE_MIN;
|
||||||
if(value > DMX_CHANNEL_VALUE_MAX) value = DMX_CHANNEL_VALUE_MAX;
|
if(value > DMX_CHANNEL_VALUE_MAX) value = DMX_CHANNEL_VALUE_MAX;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the DMX Channel boundaries
|
||||||
|
* @param channel The channel to check
|
||||||
|
* @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_CHANNELS_MIN && channel <= DMX_CHANNELS_MAX);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DMXChannel container
|
* DMXChannel container
|
||||||
*/
|
*/
|
||||||
|
@ -15,12 +13,6 @@ public class DMXChannels {
|
||||||
protected Map<Integer,DMXChannel> channelByNumber = new HashMap<Integer, DMXChannel>();
|
protected Map<Integer,DMXChannel> channelByNumber = new HashMap<Integer, DMXChannel>();
|
||||||
protected Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>();
|
protected Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new DMXChannel container
|
|
||||||
*/
|
|
||||||
public DMXChannels() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of channels
|
* Returns the number of channels
|
||||||
* @return number of channels
|
* @return number of channels
|
||||||
|
@ -41,14 +33,14 @@ public class DMXChannels {
|
||||||
return this.channelByName.get(name);
|
return this.channelByName.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Returns a channel by offset
|
// * Returns a channel by offset
|
||||||
* @param number number
|
// * @param number number
|
||||||
* @return channel or null if not found
|
// * @return channel or null if not found
|
||||||
*/
|
// */
|
||||||
public DMXChannel getChannelByNumber(int number) {
|
// public DMXChannel getChannelByNumber(int number) {
|
||||||
return this.channelByNumber.get(number);
|
// return this.channelByNumber.get(number);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a channel
|
* Adds a channel
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package de.ctdo.bunti.dmx;
|
|
||||||
|
|
||||||
public interface DMXDataChangedListener {
|
|
||||||
|
|
||||||
void DMXDataChanged(int[] dmx512data);
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,25 +7,27 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import de.ctdo.bunti.DeviceChangedEvent;
|
||||||
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
import de.ctdo.bunti.dao.BuntiDevicesDAO;
|
||||||
import de.ctdo.bunti.model.*;
|
import de.ctdo.bunti.model.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DMXMixerImpl implements DMXMixer {
|
public class DMXMixerImpl implements DMXMixer {
|
||||||
Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
final int TICKS_BETWEEN_DMX_SEND = 20;
|
private final int TICKS_BETWEEN_DMX_SEND = 20;
|
||||||
final String ARTNET_DEVICE_ADDRESS = "192.168.0.90";
|
// private final String ARTNET_DEVICE_ADDRESS = "192.168.0.90";
|
||||||
|
|
||||||
int[] dmx512databuffer = new int[DMX.DMX_CHANNELS_MAX+1];
|
private int[] dmx512databuffer = new int[DMX.DMX_CHANNELS_MAX+1];
|
||||||
|
|
||||||
static int sequenceID = 0;
|
// private int sequenceID = 0;
|
||||||
long ticksLastBufferFlush = 0;
|
private long ticksLastBufferFlush = 0;
|
||||||
BuntiDevicesDAO devicesDAO;
|
private BuntiDevicesDAO devicesDAO;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
|
||||||
this.devicesDAO = devicesDAO;
|
this.devicesDAO = devicesDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendOutDMXBuffer() {
|
private void sendOutDMXBuffer() {
|
||||||
|
|
||||||
|
@ -41,34 +43,49 @@ public class DMXMixerImpl implements DMXMixer {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(sb.toString());
|
// sequenceID++;
|
||||||
|
|
||||||
|
logger.debug(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void sendOutDMXBufferIfNeeded() {
|
public void sendOutDMXBufferIfNeeded() {
|
||||||
if(ticksLastBufferFlush + TICKS_BETWEEN_DMX_SEND < System.currentTimeMillis()) {
|
if(ticksLastBufferFlush + TICKS_BETWEEN_DMX_SEND < System.currentTimeMillis()) {
|
||||||
|
|
||||||
mergeDevicesIntoBuffer();
|
// mergeDevicesIntoBuffer();
|
||||||
sendOutDMXBuffer();
|
sendOutDMXBuffer();
|
||||||
ticksLastBufferFlush = System.currentTimeMillis();
|
ticksLastBufferFlush = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeDevicesIntoBuffer() {
|
private void updateDevice(BuntiDevice device, Map<String, Object> options) {
|
||||||
|
BuntiDMXDevice dmxDev = (BuntiDMXDevice)device;
|
||||||
for (BuntiDMXDevice buntiDMXDevice : devicesDAO.getAllDMXDevices()) {
|
boolean retval = dmxDev.setValuesFromOptions(options);
|
||||||
long lastchanged = buntiDMXDevice.getLastChanged();
|
|
||||||
long lastSend = buntiDMXDevice.getLastSendOut();
|
if( retval ) {
|
||||||
|
dmxDev.mergeDMXData(dmx512databuffer);
|
||||||
|
|
||||||
if(lastchanged >= lastSend ) {
|
sendOutDMXBufferIfNeeded();
|
||||||
buntiDMXDevice.mergeDMXData(dmx512databuffer);
|
} else {
|
||||||
logger.debug("merged " + buntiDMXDevice + " into dmx buffer");
|
logger.error("setValuesFromOptions failed");
|
||||||
buntiDMXDevice.setSendOutNow();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private void mergeDevicesIntoBuffer() {
|
||||||
|
//
|
||||||
|
// for (BuntiDMXDevice buntiDMXDevice : devicesDAO.getAllDMXDevices()) {
|
||||||
|
// long lastchanged = buntiDMXDevice.getLastChanged();
|
||||||
|
// long lastSend = buntiDMXDevice.getLastSendOut();
|
||||||
|
//
|
||||||
|
// if (lastchanged >= lastSend) {
|
||||||
|
// buntiDMXDevice.mergeDMXData(dmx512databuffer);
|
||||||
|
// logger.debug("merged " + buntiDMXDevice + " into dmx buffer");
|
||||||
|
// buntiDMXDevice.setSendOutNow();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// public void setDMX512Channel(int channel, int value) {
|
// public void setDMX512Channel(int channel, int value) {
|
||||||
// if(!DMX.checkChannelBoundaries(channel)) return;
|
// if(!DMX.checkChannelBoundaries(channel)) return;
|
||||||
|
@ -80,20 +97,16 @@ public class DMXMixerImpl implements DMXMixer {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setDevice(BuntiDevice device, Map<String, Object> options) {
|
public void onApplicationEvent(DeviceChangedEvent arg0) {
|
||||||
boolean retval = false;
|
|
||||||
|
|
||||||
if( device instanceof BuntiDMXDevice) {
|
if( arg0.getDevice() instanceof BuntiDMXDevice) {
|
||||||
|
|
||||||
BuntiDMXDevice dmxDev = (BuntiDMXDevice)device;
|
updateDevice(arg0.getDevice(), arg0.getOptions());
|
||||||
retval = dmxDev.setValuesFromOptions(options);
|
|
||||||
|
|
||||||
if( retval ) {
|
|
||||||
sendOutDMXBufferIfNeeded();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,21 @@
|
||||||
package de.ctdo.bunti.model;
|
package de.ctdo.bunti.model;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import de.ctdo.bunti.dmx.*;
|
import de.ctdo.bunti.dmx.*;
|
||||||
|
|
||||||
public abstract class BuntiDMXDevice extends BuntiDevice {
|
public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
Logger logger = LoggerFactory.getLogger(getClass());
|
protected int startAddress;
|
||||||
int startAddress;
|
private long lastSendOut;
|
||||||
long lastSendOut;
|
protected DMXChannels dmxChannels = new DMXChannels();
|
||||||
DMXChannels dmxChannels = new DMXChannels();
|
|
||||||
|
|
||||||
public int getStartAddress() {
|
public BuntiDMXDevice(int deviceId, int startAddress, String name) {
|
||||||
return startAddress+1;
|
this.startAddress = startAddress;
|
||||||
|
this.deviceName = name;
|
||||||
|
this.deviceId = deviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastSendOut() {
|
public long getLastSendOut() {
|
||||||
return lastSendOut;
|
return lastSendOut;
|
||||||
}
|
}
|
||||||
|
@ -25,26 +23,21 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
public void setSendOutNow() {
|
public void setSendOutNow() {
|
||||||
this.lastSendOut = System.currentTimeMillis();
|
this.lastSendOut = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStartAddress() {
|
||||||
|
return startAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the DMX Start Address (1 to 512)
|
|
||||||
* @param startAddress
|
|
||||||
*/
|
|
||||||
public void setStartAddress(int startAddress) {
|
public void setStartAddress(int startAddress) {
|
||||||
this.startAddress = startAddress-1;
|
this.startAddress = startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public void addChannel(DMXChannel channel) {
|
* Set channel value by given channel name.
|
||||||
//dmxChannels.add(channel);
|
* @param name The channel name to change the value.
|
||||||
dmxChannels.addChannel(channel);
|
* @param value The channel value to set.
|
||||||
}
|
*/
|
||||||
|
protected void setChannelValueByName(String name, int value) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void setChannelValueByName(String name, int value) {
|
|
||||||
DMXChannel dx = dmxChannels.getChannelByName(name);
|
DMXChannel dx = dmxChannels.getChannelByName(name);
|
||||||
if(dx != null) {
|
if(dx != null) {
|
||||||
dx.setValue(DMX.sanitizeDMXValue(value));
|
dx.setValue(DMX.sanitizeDMXValue(value));
|
||||||
|
@ -52,7 +45,12 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
lastChangedNow();
|
lastChangedNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChannelValueByName(String name) {
|
/**
|
||||||
|
* Returns the channel value identified by channel name.
|
||||||
|
* @param name The channel name to get the value from.
|
||||||
|
* @return The desired channel value.
|
||||||
|
*/
|
||||||
|
protected int getChannelValueByName(String name) {
|
||||||
DMXChannel dx = dmxChannels.getChannelByName(name);
|
DMXChannel dx = dmxChannels.getChannelByName(name);
|
||||||
if(dx != null) {
|
if(dx != null) {
|
||||||
return dx.getValue();
|
return dx.getValue();
|
||||||
|
@ -60,25 +58,21 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge the DMX values from this device into a global DMX512 Data Array
|
* Merge the DMX values from this device into a global DMX512 Data Array.
|
||||||
* @param dmxData
|
* @param dmxData DMX512 Data array to merge the local values into.
|
||||||
* @return
|
* @return True on success, false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean mergeDMXData(int[] dmxData) {
|
public boolean mergeDMXData(int[] dmxData) {
|
||||||
|
|
||||||
if(dmxData == null) {
|
if(dmxData == null || dmxData.length == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (DMXChannel channel : dmxChannels.getAllChannels()) {
|
for (DMXChannel channel : dmxChannels.getAllChannels()) {
|
||||||
int index = channel.getOffset() + startAddress;
|
int index = channel.getOffset() + (startAddress - DMX.DMX_STARTADDRESS_OFFSET);
|
||||||
|
|
||||||
if(index >= DMX.DMX_CHANNEL_VALUE_MIN && index <= DMX.DMX_CHANNELS_MAX){
|
if(index >= 0 && index < dmxData.length){
|
||||||
dmxData[index] = channel.getValue();
|
dmxData[index] = channel.getValue();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -88,17 +82,6 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void switchOff() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void switchOn() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setValuesFromOptions(Map<String, Object> options) {
|
public boolean setValuesFromOptions(Map<String, Object> options) {
|
||||||
|
|
||||||
|
@ -120,43 +103,8 @@ public abstract class BuntiDMXDevice extends BuntiDevice {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public void setChannelValueByOffset(int offsetChannel, int value) {
|
|
||||||
// DMXChannel dx = getDMXChannelByOffset(offsetChannel);
|
|
||||||
// if(dx != null) {
|
|
||||||
// dx.value = DMX.sanitizeDMXValue(value);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public void setChannelValueByAddress(int address, int value) {
|
|
||||||
// DMXChannel dx = getDMXChannelByAddress(address);
|
|
||||||
// if(dx != null) {
|
|
||||||
// dx.value = DMX.sanitizeDMXValue(value);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public int getChannelValueByOffset(int offsetChannel) {
|
|
||||||
// DMXChannel dx = getDMXChannelByOffset(offsetChannel)
|
|
||||||
// if(dx != null) {
|
|
||||||
// return dx.value;
|
|
||||||
// }
|
|
||||||
// return 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public int getChannelValueByAddress(int address) {
|
|
||||||
// DMXChannel dx = getDMXChannelByAddress(address);
|
|
||||||
// if(dx != null) {
|
|
||||||
// return dx.value;
|
|
||||||
// }
|
|
||||||
// return 0;
|
|
||||||
//}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "BuntiDMXDevice " + getDeviceID() + ", " + getDeviceName();
|
return "BuntiDMXDevice " + deviceId + ", " + deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,37 +3,45 @@ package de.ctdo.bunti.model;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class BuntiDevice {
|
public abstract class BuntiDevice {
|
||||||
|
protected int deviceId;
|
||||||
|
protected String deviceName;
|
||||||
|
private long lastChanged;
|
||||||
|
|
||||||
int deviceID;
|
public int getDeviceId() {
|
||||||
String deviceName;
|
return deviceId;
|
||||||
long lastChanged;
|
|
||||||
|
|
||||||
public int getDeviceID() {
|
|
||||||
return deviceID;
|
|
||||||
}
|
|
||||||
public void setDeviceID(int deviceID) {
|
|
||||||
this.deviceID = deviceID;
|
|
||||||
}
|
|
||||||
public String getDeviceName() {
|
|
||||||
return deviceName;
|
|
||||||
}
|
|
||||||
public void setDeviceName(String deviceName) {
|
|
||||||
this.deviceName = deviceName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastChanged() {
|
public long getLastChanged() {
|
||||||
return lastChanged;
|
return lastChanged;
|
||||||
}
|
}
|
||||||
public void setLastChanged(long lastChanged) {
|
|
||||||
this.lastChanged = lastChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void lastChangedNow() {
|
protected void lastChangedNow() {
|
||||||
this.lastChanged = System.currentTimeMillis();
|
this.lastChanged = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDeviceName() {
|
||||||
|
return deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceName(String deviceName) {
|
||||||
|
this.deviceName = deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch this device off.
|
||||||
|
*/
|
||||||
public abstract void switchOff();
|
public abstract void switchOff();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch this device on.
|
||||||
|
*/
|
||||||
public abstract void switchOn();
|
public abstract void switchOn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The the internal options corresponding to the given Key Value Map
|
||||||
|
* @param options The options Map.
|
||||||
|
* @return True on success. False otherwise.
|
||||||
|
*/
|
||||||
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
public abstract boolean setValuesFromOptions(Map<String, Object> options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,21 +5,20 @@ import de.ctdo.bunti.dmx.DMXChannel;
|
||||||
|
|
||||||
public class Par56Spot extends BuntiDMXDevice {
|
public class Par56Spot extends BuntiDMXDevice {
|
||||||
|
|
||||||
public final static String CHANNEL_MODE = "mode";
|
private final static String CHANNEL_MODE = "mode";
|
||||||
public final static String CHANNEL_RED = "red";
|
private final static String CHANNEL_RED = "red";
|
||||||
public final static String CHANNEL_GREEN = "green";
|
private final static String CHANNEL_GREEN = "green";
|
||||||
public final static String CHANNEL_BLUE = "blue";
|
private final static String CHANNEL_BLUE = "blue";
|
||||||
public final static String CHANNEL_SPEED = "speed";
|
private final static String CHANNEL_SPEED = "speed";
|
||||||
|
|
||||||
public Par56Spot(int deviceId, int startAddress, String name) {
|
public Par56Spot(int deviceId, int startAddress, String deviceName) {
|
||||||
addChannel(new DMXChannel(0, CHANNEL_MODE));
|
super(deviceId, startAddress, deviceName);
|
||||||
addChannel(new DMXChannel(1, "red"));
|
|
||||||
addChannel(new DMXChannel(2, CHANNEL_GREEN));
|
dmxChannels.addChannel(new DMXChannel(0, CHANNEL_MODE));
|
||||||
addChannel(new DMXChannel(3, CHANNEL_BLUE));
|
dmxChannels.addChannel(new DMXChannel(1, "red"));
|
||||||
addChannel(new DMXChannel(4, CHANNEL_SPEED));
|
dmxChannels.addChannel(new DMXChannel(2, CHANNEL_GREEN));
|
||||||
setStartAddress(startAddress);
|
dmxChannels.addChannel(new DMXChannel(3, CHANNEL_BLUE));
|
||||||
setDeviceName(name);
|
dmxChannels.addChannel(new DMXChannel(4, CHANNEL_SPEED));
|
||||||
setDeviceID(deviceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColorRed(int value) {
|
public void setColorRed(int value) {
|
||||||
|
@ -31,7 +30,6 @@ public class Par56Spot extends BuntiDMXDevice {
|
||||||
public void setColorBlue(int value) {
|
public void setColorBlue(int value) {
|
||||||
setChannelValueByName(CHANNEL_BLUE, value);
|
setChannelValueByName(CHANNEL_BLUE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColorRed() {
|
public int getColorRed() {
|
||||||
return getChannelValueByName(CHANNEL_RED);
|
return getChannelValueByName(CHANNEL_RED);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +60,7 @@ public class Par56Spot extends BuntiDMXDevice {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Par56Spot " + getDeviceID() + ", " + getDeviceName() +
|
return "Par56Spot " + deviceId + ", " + deviceName + " " +
|
||||||
"[" + getColorRed() + "," + getColorGreen() + "," + getColorBlue() + "]";
|
"[" + getColorRed() + "," + getColorGreen() + "," + getColorBlue() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,17 +5,16 @@ import de.ctdo.bunti.dmx.DMXChannel;
|
||||||
|
|
||||||
public class Strobe1500 extends BuntiDMXDevice {
|
public class Strobe1500 extends BuntiDMXDevice {
|
||||||
|
|
||||||
public final static String CHANNEL_SPEED = "speed";
|
private final static String CHANNEL_SPEED = "speed";
|
||||||
public final static String CHANNEL_INTENSITY = "intensity";
|
private final static String CHANNEL_INTENSITY = "intensity";
|
||||||
public final static String CHANNEL_MODE = "mode";
|
private final static String CHANNEL_MODE = "mode";
|
||||||
|
|
||||||
public Strobe1500(int deviceId, int startAddress, String name) {
|
public Strobe1500(int deviceId, int startAddress, String deviceName) {
|
||||||
addChannel(new DMXChannel(0, CHANNEL_SPEED));
|
super(deviceId, startAddress, deviceName);
|
||||||
addChannel(new DMXChannel(1, CHANNEL_INTENSITY));
|
|
||||||
addChannel(new DMXChannel(2, CHANNEL_MODE));
|
this.dmxChannels.addChannel(new DMXChannel(0, CHANNEL_SPEED));
|
||||||
setStartAddress(startAddress);
|
this.dmxChannels.addChannel(new DMXChannel(1, CHANNEL_INTENSITY));
|
||||||
setDeviceName(name);
|
this.dmxChannels.addChannel(new DMXChannel(2, CHANNEL_MODE));
|
||||||
setDeviceID(deviceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeed(int value) {
|
public void setSpeed(int value) {
|
||||||
|
@ -27,7 +26,6 @@ public class Strobe1500 extends BuntiDMXDevice {
|
||||||
public void setMode(int value) {
|
public void setMode(int value) {
|
||||||
setChannelValueByName(CHANNEL_MODE, value);
|
setChannelValueByName(CHANNEL_MODE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSpeed() {
|
public int getSpeed() {
|
||||||
return getChannelValueByName(CHANNEL_SPEED);
|
return getChannelValueByName(CHANNEL_SPEED);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +52,7 @@ public class Strobe1500 extends BuntiDMXDevice {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Strobe1500 " + getDeviceID() + ", " + getDeviceName() +
|
return "Strobe1500 " + deviceId + ", " + deviceName +
|
||||||
"[" + getSpeed() + "," + getIntensity() + "," + getMode() + "]";
|
"[" + getSpeed() + "," + getIntensity() + "," + getMode() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import de.ctdo.bunti.control.BuntiController;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class TestController {
|
public class TestController {
|
||||||
Logger logger = LoggerFactory.getLogger(getClass());
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
BuntiController buntiController;
|
BuntiController buntiController;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -25,8 +25,6 @@ public class TestController {
|
||||||
|
|
||||||
@RequestMapping("/foobar")
|
@RequestMapping("/foobar")
|
||||||
public ModelAndView blafasel() {
|
public ModelAndView blafasel() {
|
||||||
|
|
||||||
|
|
||||||
Map<String,Object> options = new HashMap<String,Object>();
|
Map<String,Object> options = new HashMap<String,Object>();
|
||||||
|
|
||||||
options.put("red", 124);
|
options.put("red", 124);
|
||||||
|
|
|
@ -7,14 +7,12 @@ import com.sun.grizzly.websockets.DefaultWebSocket;
|
||||||
import com.sun.grizzly.websockets.ProtocolHandler;
|
import com.sun.grizzly.websockets.ProtocolHandler;
|
||||||
import com.sun.grizzly.websockets.WebSocketListener;
|
import com.sun.grizzly.websockets.WebSocketListener;
|
||||||
|
|
||||||
import de.ctdo.bunti.control.BroadcastListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ein DMXControllerWebSocket gehoert immer zu einem Browserfenster/Tab
|
* Ein DMXControllerWebSocket gehoert immer zu einem Browserfenster/Tab
|
||||||
* @author lucas
|
* @author lucas
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class BuntiControllerWebSocket extends DefaultWebSocket implements BroadcastListener {
|
public class BuntiControllerWebSocket extends DefaultWebSocket {
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger(BuntiControllerWebSocket.class);
|
Logger logger = LoggerFactory.getLogger(BuntiControllerWebSocket.class);
|
||||||
|
|
||||||
|
@ -22,11 +20,6 @@ public class BuntiControllerWebSocket extends DefaultWebSocket implements Broadc
|
||||||
super(protocolHandler, listeners);
|
super(protocolHandler, listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void Broadcast(String message) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void DMXDataChanged(int[] dmx512data) {
|
// public void DMXDataChanged(int[] dmx512data) {
|
||||||
|
|
|
@ -12,5 +12,4 @@
|
||||||
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
|
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
|
||||||
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
|
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
|
||||||
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
Loading…
Reference in New Issue