Ein aufruf des TestServlet

unter http://localhost:8080/bunti_server/foobar
macht einen Aufruf an den Controller, und der mergend mit dem DMXMixer
die Werte dann in den DMX Array.
Als nächstes ist dann DeviceValuesChanged Notification dran.
This commit is contained in:
Lucas Pleß 2012-03-03 02:29:06 +01:00
parent 1fcd320aca
commit 1cb2d64324
18 changed files with 814 additions and 181 deletions

View File

@ -0,0 +1,11 @@
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);
}

View File

@ -1,56 +1,9 @@
package de.ctdo.bunti.control; package de.ctdo.bunti.control;
import java.util.ArrayList; import java.util.Map;
import java.util.List;
import net.sf.json.JSONObject; public interface BuntiController {
import de.ctdo.bunti.dmx.DMXMixer;
public class BuntiController {
static BuntiController instance = new BuntiController();
DMXMixer mixer = null;
protected final List<BroadcastListener> listeners = new ArrayList<BroadcastListener>();
public static BuntiController getInstance() {
return instance;
}
private BuntiController() {
mixer = new DMXMixer();
}
public void addListener(BroadcastListener l) {
synchronized (listeners) {
listeners.add(l);
}
}
public void removeListener(BroadcastListener l) {
synchronized (listeners) {
listeners.remove(l);
}
}
boolean setDevice(int deviceID, Map<String, Object> options);
public void performJSONString(String json) {
JSONObject jsonobj = JSONObject.fromObject(json);
if (jsonobj.containsKey("command")) {
String command = jsonobj.get("command").toString();
if (command.equals("setdmxchannels")) {
} else if (command.equals("switchdevice")) {
}
}
}
public void sendBroadcastMessage(String message) {
for (BroadcastListener l : listeners) {
l.Broadcast(message);
}
}
} }

View File

@ -0,0 +1,94 @@
package de.ctdo.bunti.control;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import net.sf.json.JSONObject;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.devices.*;
import de.ctdo.bunti.dmx.*;
import de.ctdo.bunti.model.*;
@Component
public class BuntiControllerImpl implements BuntiController {
Logger logger = LoggerFactory.getLogger(getClass());
BuntiDevicesDAO devicesDAO;
DMXMixer dmxMixer;
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
public void setDevicesDAO(BuntiDevicesDAO 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) {
JSONObject jsonobj = JSONObject.fromObject(json);
if (jsonobj.containsKey("command")) {
String command = jsonobj.get("command").toString();
if (command.equals("setdmxchannels")) {
} else if (command.equals("switchdevice")) {
}
}
}
@Override
public boolean setDevice(int deviceId, Map<String, Object> options) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
if (device != null) {
//TODO hier dann DeviceChangedEvent feuern
if (device instanceof BuntiDMXDevice) {
dmxMixer.setDevice(device, options);
} else if (device instanceof BuntiSwitchingDevice) {
deviceMixer.setDevice(device, options);
}
return true;
}
return false;
}
// public void sendBroadcastMessage(String message) {
// for (BroadcastListener l : listeners) {
// l.Broadcast(message);
// }
// }
}

View File

@ -1,11 +1,12 @@
package de.ctdo.bunti.dao; package de.ctdo.bunti.dao;
import java.util.List; import java.util.Collection;
import de.ctdo.bunti.model.*; import de.ctdo.bunti.model.*;
public interface BuntiDevicesDAO { public interface BuntiDevicesDAO {
public List<BuntiDMXDevice> getAllDMXDevices(); public Collection<BuntiDMXDevice> getAllDMXDevices();
public BuntiDevice getDeviceById(int deviceId);
} }

View File

@ -1,14 +1,18 @@
package de.ctdo.bunti.dao; package de.ctdo.bunti.dao;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import de.ctdo.bunti.dmx.DMXChannel; import org.slf4j.Logger;
import de.ctdo.bunti.model.BuntiDMXDevice; import org.slf4j.LoggerFactory;
import de.ctdo.bunti.model.BuntiDevice; import org.springframework.stereotype.Component;
import de.ctdo.bunti.model.*;
@Component
public class BuntiDevicesDAOImpl implements BuntiDevicesDAO { public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
Logger logger = LoggerFactory.getLogger(getClass());
List<BuntiDevice> devices = new ArrayList<BuntiDevice>(); List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
public BuntiDevicesDAOImpl() { public BuntiDevicesDAOImpl() {
@ -17,62 +21,36 @@ public class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
private void addDummyDevices() { private void addDummyDevices() {
BuntiDMXDevice d1 = new BuntiDMXDevice(); int deviceID = 0;
d1.setDeviceID(1);
d1.setDeviceName("Par65 Lampe 1");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
d1 = new BuntiDMXDevice(); devices.add(new Par56Spot(deviceID++, 1, "Par56 Lampe 1"));
d1.setDeviceID(6); devices.add(new Par56Spot(deviceID++, 6, "Par56 Lampe 2"));
d1.setDeviceName("Par65 Lampe 2"); devices.add(new Par56Spot(deviceID++, 11, "Par56 Lampe 3"));
d1.setStartAddress(1); devices.add(new Par56Spot(deviceID++, 16, "Par56 Lampe 4"));
d1.addChannel(new DMXChannel(0, "mode")); devices.add(new Strobe1500(deviceID++, 21, "Stroboskop 1"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
d1 = new BuntiDMXDevice();
d1.setDeviceID(11);
d1.setDeviceName("Par65 Lampe 4");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
d1 = new BuntiDMXDevice();
d1.setDeviceID(16);
d1.setDeviceName("Par65 Lampe 4");
d1.setStartAddress(1);
d1.addChannel(new DMXChannel(0, "mode"));
d1.addChannel(new DMXChannel(1, "red"));
d1.addChannel(new DMXChannel(2, "green"));
d1.addChannel(new DMXChannel(3, "blue"));
d1.addChannel(new DMXChannel(4, "speed"));
devices.add(d1);
} }
@Override @Override
public List<BuntiDMXDevice> getAllDMXDevices() { public Collection<BuntiDMXDevice> getAllDMXDevices() {
List<BuntiDMXDevice> liste = new ArrayList<BuntiDMXDevice>(); List<BuntiDMXDevice> liste = new ArrayList<BuntiDMXDevice>();
for (BuntiDevice device : devices) { for (BuntiDevice device : devices) {
if( device.getClass().equals(BuntiDMXDevice.class) ) { if( device instanceof BuntiDMXDevice ) {
liste.add((BuntiDMXDevice) device); liste.add((BuntiDMXDevice) device);
} }
} }
return liste; return liste;
} }
@Override
public BuntiDevice getDeviceById(int deviceId) {
for (BuntiDevice dev : devices) {
if(dev.getDeviceID() == deviceId) {
return dev;
}
}
return null;
}
} }

View File

@ -0,0 +1,10 @@
package de.ctdo.bunti.devices;
import de.ctdo.bunti.Mixer;
public interface DeviceMixer extends Mixer {
}

View File

@ -0,0 +1,24 @@
package de.ctdo.bunti.devices;
import java.util.Map;
import org.springframework.stereotype.Component;
import de.ctdo.bunti.model.BuntiDMXDevice;
import de.ctdo.bunti.model.BuntiDevice;
@Component
public class DeviceMixerImpl implements DeviceMixer {
@Override
public boolean setDevice(BuntiDevice device, Map<String, Object> options) {
BuntiDMXDevice dmxDev = (BuntiDMXDevice)device;
return dmxDev.setValuesFromOptions(options);
}
}

View File

@ -18,4 +18,6 @@ public class DMX {
return (channel >= DMX_CHANNELS_MIN && channel <= DMX_CHANNELS_MAX); return (channel >= DMX_CHANNELS_MIN && channel <= DMX_CHANNELS_MAX);
} }
} }

View File

@ -1,13 +1,53 @@
package de.ctdo.bunti.dmx; package de.ctdo.bunti.dmx;
public class DMXChannel { public class DMXChannel {
public int offset; int offset;
public String description; String name;
public int value; int value;
long lastChangedTimestamp = 0;
public DMXChannel(int offset, String description) { public DMXChannel(int offset, String name) {
this.description = description; this.name = name;
this.offset = offset; this.offset = offset;
this.value = 0; this.value = 0;
} }
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
lastChangedTimestamp = System.currentTimeMillis();
}
public long getLastChangedTimestamp() {
return lastChangedTimestamp;
}
public int getOffset() {
return offset;
}
public void setOffset(int offset) {
this.offset = offset;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void hasbeenSendOut() {
this.lastChangedTimestamp = System.currentTimeMillis();
}
@Override
public String toString() {
return "DMXChannel " + getName() + "," + getOffset() + "," + getValue();
}
} }

View File

@ -0,0 +1,117 @@
package de.ctdo.bunti.dmx;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Component;
/**
* DMXChannel container
*/
public class DMXChannels {
protected Map<Integer,DMXChannel> channelByNumber = new HashMap<Integer, DMXChannel>();
protected Map<String,DMXChannel> channelByName = new HashMap<String, DMXChannel>();
/**
* Creates a new DMXChannel container
*/
public DMXChannels() {
}
/**
* Returns the number of channels
* @return number of channels
*/
public int getCount() {
return this.channelByNumber.size();
}
/**
* Returns a channel by name
* @param name channel name
* @return channel or null if not found
*/
public DMXChannel getChannelByName(String name) {
if (name == null) {
return null;
}
return this.channelByName.get(name);
}
/**
* Returns a channel by offset
* @param number number
* @return channel or null if not found
*/
public DMXChannel getChannelByNumber(int number) {
return this.channelByNumber.get(number);
}
/**
* Adds a channel
* @param channel channel to add
* @return true on success, false on error
*/
public boolean addChannel(DMXChannel channel) {
// object cannot be null
if (channel == null) {
return false;
}
// description cannot be null
if (channel.name == null) {
return false;
}
// entry must not exist by offset
if (this.channelByNumber.containsKey(channel.offset) == true) {
return false;
}
// entry must not exist by name
if (this.channelByName.containsKey(channel.name) == true) {
return false;
}
this.channelByNumber.put(channel.offset, channel);
this.channelByName.put(channel.name, channel);
return true;
}
// /**
// * Removes a channel by offset
// * @param offset offset
// * @return removed channel or null if it does not exist
// */
// public DMXChannel removeChannel(int offset) {
// DMXChannel tmpChannel = this.channelByNumber.remove(offset);
// if (tmpChannel != null) {
// this.channelByName.remove(tmpChannel.name);
// }
// return tmpChannel;
// }
// /**
// * Removes a channel by name
// * @param name channel name
// * @return removed channel or null if it does not exist
// */
// public DMXChannel removeChannel(String name) {
// if (name == null) {
// return null;
// }
// DMXChannel tmpChannel = this.channelByName.remove(name);
// if (tmpChannel != null) {
// this.channelByOffset.remove(tmpChannel.offset);
// }
// return tmpChannel;
// }
/**
* Returns an (unmodifiable) collection of all channels
* @return unmodifiable collection of all channels
*/
public Collection<DMXChannel> getAllChannels() {
return Collections.unmodifiableCollection(this.channelByNumber.values());
}
}

View File

@ -0,0 +1,99 @@
package de.ctdo.bunti.dmx;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.*;
@Component
public class DMXMixerImpl implements DMXMixer {
Logger logger = LoggerFactory.getLogger(getClass());
final int TICKS_BETWEEN_DMX_SEND = 20;
final String ARTNET_DEVICE_ADDRESS = "192.168.0.90";
int[] dmx512databuffer = new int[DMX.DMX_CHANNELS_MAX+1];
static int sequenceID = 0;
long ticksLastBufferFlush = 0;
BuntiDevicesDAO devicesDAO;
@Autowired
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO;
}
private void sendOutDMXBuffer() {
StringBuilder sb = new StringBuilder();
sb.append("DMX Data: ");
byte[] arr = new byte[dmx512databuffer.length];
for (int i = 0; i < dmx512databuffer.length; i++) {
arr[i] = (byte)dmx512databuffer[i];
sb.append(i);
sb.append("=");
sb.append(dmx512databuffer[i]);
sb.append(", ");
}
logger.debug(sb.toString());
}
public void sendOutDMXBufferIfNeeded() {
if(ticksLastBufferFlush + TICKS_BETWEEN_DMX_SEND < System.currentTimeMillis()) {
mergeDevicesIntoBuffer();
sendOutDMXBuffer();
ticksLastBufferFlush = System.currentTimeMillis();
}
}
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) {
// if(!DMX.checkChannelBoundaries(channel)) return;
// value = DMX.sanitizeDMXValue(value);
//
// dmx512databuffer[channel] = value;
//
// sendOutDMXBufferIfNeeded();
// }
@Override
public boolean setDevice(BuntiDevice device, Map<String, Object> options) {
boolean retval = false;
if( device instanceof BuntiDMXDevice) {
BuntiDMXDevice dmxDev = (BuntiDMXDevice)device;
retval = dmxDev.setValuesFromOptions(options);
if( retval ) {
sendOutDMXBufferIfNeeded();
}
}
return retval;
}
}

View File

@ -1,99 +1,162 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
import java.util.*; import java.util.*;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.ctdo.bunti.dmx.*; import de.ctdo.bunti.dmx.*;
public class BuntiDMXDevice extends BuntiDevice { public abstract class BuntiDMXDevice extends BuntiDevice {
Logger logger = LoggerFactory.getLogger(getClass());
int startAddress; int startAddress;
List<DMXChannel> dmxValues = new ArrayList<DMXChannel>(); long lastSendOut;
DMXChannels dmxChannels = new DMXChannels();
public DMXChannel getDMXChannelByName(String channel) {
for (DMXChannel dx : dmxValues) { public int getStartAddress() {
if(channel.equals(dx.description)) { return startAddress+1;
return dx;
}
}
return null;
}
public DMXChannel getDMXChannelByOffset(int offset) {
for (DMXChannel dx : dmxValues) {
if(offset == dx.offset) {
return dx;
}
}
return null;
} }
// public DMXChannel getDMXChannelByAddress(int address) { public long getLastSendOut() {
// int offset = address - startAddress; return lastSendOut;
// return getDMXChannelByOffset(offset); }
// }
public void setSendOutNow() {
this.lastSendOut = System.currentTimeMillis();
}
/**
* set the DMX Start Address (1 to 512)
* @param startAddress
*/
public void setStartAddress(int startAddress) {
this.startAddress = startAddress-1;
}
public void addChannel(DMXChannel channel) {
//dmxChannels.add(channel);
dmxChannels.addChannel(channel);
}
public void setChannelValueByName(String name, int value) { public void setChannelValueByName(String name, int value) {
DMXChannel dx = getDMXChannelByName(name); DMXChannel dx = dmxChannels.getChannelByName(name);
if(dx != null) { if(dx != null) {
dx.value = DMX.sanitizeDMXValue(value); dx.setValue(DMX.sanitizeDMXValue(value));
} }
lastChangedNow();
} }
// 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 getChannelValueByName(String name) { public int getChannelValueByName(String name) {
DMXChannel dx = getDMXChannelByName(name); DMXChannel dx = dmxChannels.getChannelByName(name);
if(dx != null) { if(dx != null) {
return dx.value; return dx.getValue();
} }
return 0; return 0;
} }
// 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;
// }
public int getStartAddress() {
return startAddress;
}
public void setStartAddress(int startAddress) {
this.startAddress = startAddress;
}
public void addChannel(DMXChannel channel) {
dmxValues.add(channel);
} /**
public void removeChannel(int offset) { * Merge the DMX values from this device into a global DMX512 Data Array
DMXChannel dx = getDMXChannelByOffset(offset); * @param dmxData
if(dx != null) { * @return
dmxValues.remove(offset); */
public boolean mergeDMXData(int[] dmxData) {
if(dmxData == null) {
return false;
} }
for (DMXChannel channel : dmxChannels.getAllChannels()) {
int index = channel.getOffset() + startAddress;
if(index >= DMX.DMX_CHANNEL_VALUE_MIN && index <= DMX.DMX_CHANNELS_MAX){
dmxData[index] = channel.getValue();
} else {
return false;
}
}
return true;
} }
@Override
public void switchOff() {
}
@Override
public void switchOn() {
}
@Override
public boolean setValuesFromOptions(Map<String, Object> options) {
for (Entry<String, Object> opt : options.entrySet()) {
DMXChannel channel = dmxChannels.getChannelByName(opt.getKey());
if(channel != null) {
try {
int value = Integer.parseInt(opt.getValue().toString());
setChannelValueByName(channel.getName(), value);
} catch (Exception e) {
return false;
}
}
}
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
public String toString() {
return "BuntiDMXDevice " + getDeviceID() + ", " + getDeviceName();
}
} }

View File

@ -1,9 +1,12 @@
package de.ctdo.bunti.model; package de.ctdo.bunti.model;
public class BuntiDevice { import java.util.Map;
public abstract class BuntiDevice {
int deviceID; int deviceID;
String deviceName; String deviceName;
long lastChanged;
public int getDeviceID() { public int getDeviceID() {
return deviceID; return deviceID;
@ -17,6 +20,20 @@ public class BuntiDevice {
public void setDeviceName(String deviceName) { public void setDeviceName(String deviceName) {
this.deviceName = deviceName; this.deviceName = deviceName;
} }
public long getLastChanged() {
return lastChanged;
}
public void setLastChanged(long lastChanged) {
this.lastChanged = lastChanged;
}
protected void lastChangedNow() {
this.lastChanged = System.currentTimeMillis();
}
public abstract void switchOff();
public abstract void switchOn();
public abstract boolean setValuesFromOptions(Map<String, Object> options);
} }

View File

@ -0,0 +1,27 @@
package de.ctdo.bunti.model;
import java.util.Map;
public class BuntiSwitchingDevice extends BuntiDevice {
@Override
public void switchOff() {
// TODO Auto-generated method stub
}
@Override
public void switchOn() {
// TODO Auto-generated method stub
}
@Override
public boolean setValuesFromOptions(Map<String, Object> options) {
// TODO Auto-generated method stub
return false;
}
// zum Beispiel Lampel, also nen Hostname und HTTP Krams hier rein
}

View File

@ -0,0 +1,69 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;
public class Par56Spot extends BuntiDMXDevice {
public final static String CHANNEL_MODE = "mode";
public final static String CHANNEL_RED = "red";
public final static String CHANNEL_GREEN = "green";
public final static String CHANNEL_BLUE = "blue";
public final static String CHANNEL_SPEED = "speed";
public Par56Spot(int deviceId, int startAddress, String name) {
addChannel(new DMXChannel(0, CHANNEL_MODE));
addChannel(new DMXChannel(1, "red"));
addChannel(new DMXChannel(2, CHANNEL_GREEN));
addChannel(new DMXChannel(3, CHANNEL_BLUE));
addChannel(new DMXChannel(4, CHANNEL_SPEED));
setStartAddress(startAddress);
setDeviceName(name);
setDeviceID(deviceId);
}
public void setColorRed(int value) {
setChannelValueByName(CHANNEL_RED, value);
}
public void setColorGreen(int value) {
setChannelValueByName(CHANNEL_GREEN, value);
}
public void setColorBlue(int value) {
setChannelValueByName(CHANNEL_BLUE, value);
}
public int getColorRed() {
return getChannelValueByName(CHANNEL_RED);
}
public int getColorGreen() {
return getChannelValueByName(CHANNEL_GREEN);
}
public int getColorBlue() {
return getChannelValueByName(CHANNEL_BLUE);
}
@Override
public 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);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
}
@Override
public 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);;
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
}
@Override
public String toString() {
return "Par56Spot " + getDeviceID() + ", " + getDeviceName() +
"[" + getColorRed() + "," + getColorGreen() + "," + getColorBlue() + "]";
}
}

View File

@ -0,0 +1,61 @@
package de.ctdo.bunti.model;
import de.ctdo.bunti.dmx.DMX;
import de.ctdo.bunti.dmx.DMXChannel;
public class Strobe1500 extends BuntiDMXDevice {
public final static String CHANNEL_SPEED = "speed";
public final static String CHANNEL_INTENSITY = "intensity";
public final static String CHANNEL_MODE = "mode";
public Strobe1500(int deviceId, int startAddress, String name) {
addChannel(new DMXChannel(0, CHANNEL_SPEED));
addChannel(new DMXChannel(1, CHANNEL_INTENSITY));
addChannel(new DMXChannel(2, CHANNEL_MODE));
setStartAddress(startAddress);
setDeviceName(name);
setDeviceID(deviceId);
}
public void setSpeed(int value) {
setChannelValueByName(CHANNEL_SPEED, value);
}
public void setIntensity(int value) {
setChannelValueByName(CHANNEL_INTENSITY, value);
}
public void setMode(int value) {
setChannelValueByName(CHANNEL_MODE, value);
}
public int getSpeed() {
return getChannelValueByName(CHANNEL_SPEED);
}
public int getIntensity() {
return getChannelValueByName(CHANNEL_INTENSITY);
}
public int getMode() {
return getChannelValueByName(CHANNEL_MODE);
}
@Override
public void switchOff() {
setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
setChannelValueByName(CHANNEL_INTENSITY, DMX.DMX_CHANNEL_VALUE_MIN);
}
@Override
public void switchOn() {
setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MAX);
setChannelValueByName(CHANNEL_INTENSITY, DMX.DMX_CHANNEL_VALUE_MAX);
}
@Override
public String toString() {
return "Strobe1500 " + getDeviceID() + ", " + getDeviceName() +
"[" + getSpeed() + "," + getIntensity() + "," + getMode() + "]";
}
}

View File

@ -1,16 +1,85 @@
package de.ctdo.bunti.web; package de.ctdo.bunti.web;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import de.ctdo.bunti.control.BuntiController;
@Controller @Controller
public class TestController { public class TestController {
Logger logger = LoggerFactory.getLogger(getClass());
BuntiController buntiController;
@Autowired
public void setBuntiController(BuntiController buntiController) {
this.buntiController = buntiController;
}
@RequestMapping("/foobar") @RequestMapping("/foobar")
public ModelAndView blafasel() { public ModelAndView blafasel() {
Map<String,Object> options = new HashMap<String,Object>();
options.put("red", 124);
options.put("green", 23);
options.put("blue", 217);
buntiController.setDevice(0, options);
options.put("red", 0);
options.put("green", 255);
options.put("blue", 255);
buntiController.setDevice(1, options);
options.put("red", 42);
options.put("green", 222);
options.put("blue", 111);
buntiController.setDevice(2, options);
options.put("red", 10);
options.put("green", 25);
options.put("blue", 33);
buntiController.setDevice(3, options);
options.clear();
options.put("speed", 128);
options.put("intensity", 255);
buntiController.setDevice(4, options);
ModelAndView mav = new ModelAndView("hello.jsp");
return mav;
}
@RequestMapping("/foobar2")
public ModelAndView blafasel2() {
Map<String,Object> options = new HashMap<String,Object>();
options.put("red", 0);
options.put("green", 23);
options.put("blue", 42);
buntiController.setDevice(2, options);
options.put("red", 111);
options.put("green", 78);
options.put("blue", 255);
buntiController.setDevice(3, options);
ModelAndView mav = new ModelAndView("hello.jsp"); ModelAndView mav = new ModelAndView("hello.jsp");
return mav; return mav;

View File

@ -10,8 +10,6 @@ import com.sun.grizzly.websockets.WebSocket;
import com.sun.grizzly.websockets.WebSocketApplication; import com.sun.grizzly.websockets.WebSocketApplication;
import com.sun.grizzly.websockets.WebSocketListener; import com.sun.grizzly.websockets.WebSocketListener;
import de.ctdo.bunti.control.BuntiController;
@Component @Component
public class BuntiControllerApplication extends WebSocketApplication { public class BuntiControllerApplication extends WebSocketApplication {
Logger logger = LoggerFactory.getLogger(BuntiControllerApplication.class); Logger logger = LoggerFactory.getLogger(BuntiControllerApplication.class);
@ -19,7 +17,7 @@ public class BuntiControllerApplication extends WebSocketApplication {
@Override @Override
public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) { public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
BuntiControllerWebSocket socket = new BuntiControllerWebSocket(protocolHandler, listeners); BuntiControllerWebSocket socket = new BuntiControllerWebSocket(protocolHandler, listeners);
BuntiController.getInstance().addListener(socket); // BuntiControllerImpl.getInstance().addListener(socket);
return socket; return socket;
} }
@ -32,14 +30,14 @@ public class BuntiControllerApplication extends WebSocketApplication {
@Override @Override
public void onClose(WebSocket socket, com.sun.grizzly.websockets.DataFrame frame) { public void onClose(WebSocket socket, com.sun.grizzly.websockets.DataFrame frame) {
BuntiControllerWebSocket ws = (BuntiControllerWebSocket) socket; BuntiControllerWebSocket ws = (BuntiControllerWebSocket) socket;
BuntiController.getInstance().removeListener(ws); // BuntiControllerImpl.getInstance().removeListener(ws);
} }
@Override @Override
public void onMessage(WebSocket socket, String text) { public void onMessage(WebSocket socket, String text) {
BuntiController.getInstance().performJSONString(text); // BuntiControllerImpl.getInstance().performJSONString(text);
// for (final WebSocket webSocket : getWebSockets()) { // for (final WebSocket webSocket : getWebSockets()) {