websocket dmx controller kram umbenannt nach Bunti

da es ja nicht nur dmx steuern soll.
des weiteren die oldschool web.xml servlet config aufgeräumt
und auf die cooleren @WevServlet Annotation umgebaut.
This commit is contained in:
Lucas Pleß 2012-02-26 01:47:08 +01:00
parent f3a2a33cca
commit 47ffb7c1f6
10 changed files with 32 additions and 197 deletions

View File

@ -1,23 +0,0 @@
package de.ctdo;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.PropertyConfigurator;
@WebServlet("/Log4jInit")
public class Log4jInit extends HttpServlet {
private static final long serialVersionUID = 1L;
public void init() {
String prefix = getServletContext().getRealPath("/");
String file = "log4j.properties";
PropertyConfigurator.configure(prefix + file);
}
public void doGet(HttpServletRequest req, HttpServletResponse res) {
}
}

View File

@ -1,30 +0,0 @@
package de.ctdo.dmx;
public abstract class DMXDevice {
private int startaddress = 0;
private String name = "New Device";
public DMXDevice() {
}
public DMXDevice(int startaddress, String name) {
setStartaddress(startaddress);
setName(name);
}
public int getStartaddress() {
return startaddress;
}
public void setStartaddress(int startaddress) {
this.startaddress = startaddress;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,27 +0,0 @@
package de.ctdo.dmx;
import java.util.ArrayList;
import java.util.List;
public class DeviceManager {
private List<DMXDevice> devices = new ArrayList<DMXDevice>();
public DeviceManager() {
// fill device list
devices.add(new Par56Spot(1, "Par1"));
devices.add(new Par56Spot(6, "Par2"));
devices.add(new Par56Spot(11, "Par3"));
devices.add(new Par56Spot(16, "Par4"));
}
public List<DMXDevice> getDevices() {
return new ArrayList<DMXDevice>(devices);
}
}

View File

@ -17,20 +17,22 @@ public class Mixer {
final int TICKS_BETWEEN_DMX_SEND = 20;
final int DMX_MIN_CHANNEL = 0;
final int DMX_MAX_CHANNEL = 512;
final String ARTNET_DEVICE_ADDRESS = "192.168.0.90";
Logger logger = LoggerFactory.getLogger(Mixer.class);
int[] dmx512databuffer = new int[512];
static int sequenceID = 0;
ArtNet artnet = new ArtNet();
ArtNetNode firstNodeFound = null;
ArtDmxPacket artnetDmxPacket = null;
long ticksLastBufferFlush = 0;
protected final List<DMXDataChangedListener> listeners = new ArrayList<DMXDataChangedListener>();
public static Mixer getInstance() {
return instance;
}
public void addListener(DMXDataChangedListener l) {
synchronized (listeners) {
listeners.add(l);
@ -45,6 +47,9 @@ public class Mixer {
private Mixer() {
artnetDmxPacket = new ArtDmxPacket();
artnetDmxPacket.setUniverse(0, 0);
try {
artnet.start();
}
@ -59,28 +64,18 @@ public class Mixer {
}
private void sendOutDMXBuffer() {
// if(firstNodeFound == null) {
// logger.info("No ArtNetNode to send data to");
// return;
// }
ArtDmxPacket dmx = new ArtDmxPacket();
// dmx.setUniverse(firstNodeFound.getSubNet(), firstNodeFound.getDmxOuts()[0]);
// dmx.setSequenceID(sequenceID % 255);
// dmx.setDMX(dmx512databuffer, dmx512databuffer.length);
// artnet.unicastPacket(dmx, firstNodeFound.getIPAddress());
dmx.setUniverse(0, 0);
dmx.setSequenceID(sequenceID % 255);
byte[] arr = new byte[dmx512databuffer.length];
for (int i = 0; i < dmx512databuffer.length; i++) {
arr[i] = (byte)dmx512databuffer[i];
}
dmx.setDMX(arr, arr.length);
artnet.unicastPacket(dmx, "192.168.0.90");
artnetDmxPacket.setSequenceID(sequenceID % 255);
artnetDmxPacket.setDMX(arr, arr.length);
artnet.unicastPacket(artnetDmxPacket, ARTNET_DEVICE_ADDRESS);
sequenceID++;
ticksLastBufferFlush = System.currentTimeMillis();
// logger.debug("Send out DMX Data");
}
public void sendOutDMXBufferIfNeeded() {

View File

@ -1,81 +0,0 @@
package de.ctdo.dmx;
import java.awt.Color;
public class Par56Spot extends DMXDevice {
private final int NUM_CHANNELS = 5;
private byte red = 0;
private byte green = 0;
private byte blue = 0;
public Par56Spot() {
}
public Par56Spot(int startaddress, String name) {
setStartaddress(startaddress);
setName(name);
}
public boolean getDMXValues(byte[] dmx512data) {
int dmxStartAddressInDataArray = getStartaddress()-1;
if( dmx512data == null || dmx512data.length < NUM_CHANNELS+dmxStartAddressInDataArray ) {
return false;
}
dmx512data[dmxStartAddressInDataArray+0] = 0;
dmx512data[dmxStartAddressInDataArray+1] = red;
dmx512data[dmxStartAddressInDataArray+2] = green;
dmx512data[dmxStartAddressInDataArray+3] = blue;
dmx512data[dmxStartAddressInDataArray+4] = 0;
return true;
}
public boolean setDMXValues(byte[] dmx512data) {
int dmxStartAddressInDataArray = getStartaddress()-1;
if( dmx512data == null || dmx512data.length < NUM_CHANNELS+dmxStartAddressInDataArray ) {
return false;
}
red = dmx512data[dmxStartAddressInDataArray+1];
green = dmx512data[dmxStartAddressInDataArray+2];
blue = dmx512data[dmxStartAddressInDataArray+3];
return true;
}
public void setColor(Color c) {
red = (byte) c.getRed();
green = (byte) c.getGreen();
blue = (byte) c.getBlue();
}
public Color getColor() {
return new Color(red, green, blue, 255);
}
public byte getRed() {
return red;
}
public void setRed(byte red) {
this.red = red;
}
public byte getGreen() {
return green;
}
public void setGreen(byte green) {
this.green = green;
}
public byte getBlue() {
return blue;
}
public void setBlue(byte blue) {
this.blue = blue;
}
}

View File

@ -11,13 +11,13 @@ import com.sun.grizzly.websockets.WebSocketListener;
import de.ctdo.dmx.Mixer;
public class DMXControllerApplication extends WebSocketApplication {
Logger logger = LoggerFactory.getLogger(DMXControllerApplication.class);
public class BuntiControllerApplication extends WebSocketApplication {
Logger logger = LoggerFactory.getLogger(BuntiControllerApplication.class);
@Override
public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
logger.debug("createSocket ");
DMXControllerWebSocket socket = new DMXControllerWebSocket(protocolHandler, listeners);
BuntiControllerWebSocket socket = new BuntiControllerWebSocket(protocolHandler, listeners);
Mixer.getInstance().addListener(socket);
return socket;
}
@ -25,12 +25,12 @@ public class DMXControllerApplication extends WebSocketApplication {
@Override
public boolean isApplicationRequest(Request request) {
final String uri = request.requestURI().toString();
return uri.endsWith("/dmx");
return uri.endsWith("/bunti");
}
@Override
public void onClose(WebSocket socket, com.sun.grizzly.websockets.DataFrame frame) {
DMXControllerWebSocket ws = (DMXControllerWebSocket) socket;
BuntiControllerWebSocket ws = (BuntiControllerWebSocket) socket;
Mixer.getInstance().removeListener(ws);
logger.debug("removed websocket");
}

View File

@ -2,7 +2,7 @@ package de.ctdo.websocket;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import org.slf4j.Logger;
@ -10,11 +10,12 @@ import org.slf4j.LoggerFactory;
import com.sun.grizzly.websockets.WebSocketEngine;
public class DMXControllerServlet extends HttpServlet {
@WebServlet(urlPatterns = "/bunti")
public class BuntiControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Logger logger = LoggerFactory.getLogger(DMXControllerServlet.class);
Logger logger = LoggerFactory.getLogger(BuntiControllerServlet.class);
private final DMXControllerApplication app = new DMXControllerApplication();
private final BuntiControllerApplication app = new BuntiControllerApplication();
@Override
public void init(ServletConfig config) throws ServletException {

View File

@ -17,11 +17,11 @@ import de.ctdo.dmx.DMXDataChangedListener;
* @author lucas
*
*/
public class DMXControllerWebSocket extends DefaultWebSocket implements DMXDataChangedListener {
public class BuntiControllerWebSocket extends DefaultWebSocket implements DMXDataChangedListener {
Logger logger = LoggerFactory.getLogger(DMXControllerWebSocket.class);
Logger logger = LoggerFactory.getLogger(BuntiControllerWebSocket.class);
public DMXControllerWebSocket(ProtocolHandler protocolHandler, WebSocketListener[] listeners) {
public BuntiControllerWebSocket(ProtocolHandler protocolHandler, WebSocketListener[] listeners) {
super(protocolHandler, listeners);
}

View File

@ -10,20 +10,20 @@
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<description>CTDO DMX control Server</description>
<description>CTDO bunti control Server</description>
<!--
<servlet>
<description></description>
<servlet-name>DMXControllerServlet</servlet-name>
<servlet-class>de.ctdo.websocket.DMXControllerServlet</servlet-class>
<servlet-name>BuntiControllerServlet</servlet-name>
<servlet-class>de.ctdo.websocket.BuntiControllerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DMXControllerServlet</servlet-name>
<url-pattern>/dmx</url-pattern>
<servlet-name>BuntiControllerServlet</servlet-name>
<url-pattern>/bunti</url-pattern>
</servlet-mapping>
-->
<session-config>
<session-timeout>25</session-timeout>
</session-config>

View File

@ -20,8 +20,8 @@
$(document).ready(
function() {
ws = new MozWebSocket("ws://localhost:8080/bunti_server/dmx");
var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket;
ws = new MozWebSocket("ws://localhost:8080/bunti_server/bunti");
//ws = new MozWebSocket("ws://localhost:8080/grizzly-websockets-chat/chat");
ws.onmessage = function (message) {