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:
parent
f3a2a33cca
commit
47ffb7c1f6
|
@ -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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,20 +17,22 @@ public class Mixer {
|
||||||
final int TICKS_BETWEEN_DMX_SEND = 20;
|
final int TICKS_BETWEEN_DMX_SEND = 20;
|
||||||
final int DMX_MIN_CHANNEL = 0;
|
final int DMX_MIN_CHANNEL = 0;
|
||||||
final int DMX_MAX_CHANNEL = 512;
|
final int DMX_MAX_CHANNEL = 512;
|
||||||
|
final String ARTNET_DEVICE_ADDRESS = "192.168.0.90";
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger(Mixer.class);
|
Logger logger = LoggerFactory.getLogger(Mixer.class);
|
||||||
int[] dmx512databuffer = new int[512];
|
int[] dmx512databuffer = new int[512];
|
||||||
static int sequenceID = 0;
|
static int sequenceID = 0;
|
||||||
ArtNet artnet = new ArtNet();
|
ArtNet artnet = new ArtNet();
|
||||||
ArtNetNode firstNodeFound = null;
|
ArtNetNode firstNodeFound = null;
|
||||||
|
ArtDmxPacket artnetDmxPacket = null;
|
||||||
long ticksLastBufferFlush = 0;
|
long ticksLastBufferFlush = 0;
|
||||||
|
|
||||||
|
|
||||||
protected final List<DMXDataChangedListener> listeners = new ArrayList<DMXDataChangedListener>();
|
protected final List<DMXDataChangedListener> listeners = new ArrayList<DMXDataChangedListener>();
|
||||||
|
|
||||||
public static Mixer getInstance() {
|
public static Mixer getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(DMXDataChangedListener l) {
|
public void addListener(DMXDataChangedListener l) {
|
||||||
synchronized (listeners) {
|
synchronized (listeners) {
|
||||||
listeners.add(l);
|
listeners.add(l);
|
||||||
|
@ -45,6 +47,9 @@ public class Mixer {
|
||||||
|
|
||||||
private Mixer() {
|
private Mixer() {
|
||||||
|
|
||||||
|
artnetDmxPacket = new ArtDmxPacket();
|
||||||
|
artnetDmxPacket.setUniverse(0, 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
artnet.start();
|
artnet.start();
|
||||||
}
|
}
|
||||||
|
@ -59,28 +64,18 @@ public class Mixer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendOutDMXBuffer() {
|
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];
|
byte[] arr = new byte[dmx512databuffer.length];
|
||||||
for (int i = 0; i < dmx512databuffer.length; i++) {
|
for (int i = 0; i < dmx512databuffer.length; i++) {
|
||||||
arr[i] = (byte)dmx512databuffer[i];
|
arr[i] = (byte)dmx512databuffer[i];
|
||||||
}
|
}
|
||||||
dmx.setDMX(arr, arr.length);
|
artnetDmxPacket.setSequenceID(sequenceID % 255);
|
||||||
artnet.unicastPacket(dmx, "192.168.0.90");
|
artnetDmxPacket.setDMX(arr, arr.length);
|
||||||
|
artnet.unicastPacket(artnetDmxPacket, ARTNET_DEVICE_ADDRESS);
|
||||||
|
|
||||||
sequenceID++;
|
sequenceID++;
|
||||||
|
|
||||||
ticksLastBufferFlush = System.currentTimeMillis();
|
ticksLastBufferFlush = System.currentTimeMillis();
|
||||||
// logger.debug("Send out DMX Data");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendOutDMXBufferIfNeeded() {
|
public void sendOutDMXBufferIfNeeded() {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,13 +11,13 @@ import com.sun.grizzly.websockets.WebSocketListener;
|
||||||
|
|
||||||
import de.ctdo.dmx.Mixer;
|
import de.ctdo.dmx.Mixer;
|
||||||
|
|
||||||
public class DMXControllerApplication extends WebSocketApplication {
|
public class BuntiControllerApplication extends WebSocketApplication {
|
||||||
Logger logger = LoggerFactory.getLogger(DMXControllerApplication.class);
|
Logger logger = LoggerFactory.getLogger(BuntiControllerApplication.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
|
public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
|
||||||
logger.debug("createSocket ");
|
logger.debug("createSocket ");
|
||||||
DMXControllerWebSocket socket = new DMXControllerWebSocket(protocolHandler, listeners);
|
BuntiControllerWebSocket socket = new BuntiControllerWebSocket(protocolHandler, listeners);
|
||||||
Mixer.getInstance().addListener(socket);
|
Mixer.getInstance().addListener(socket);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@ public class DMXControllerApplication extends WebSocketApplication {
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicationRequest(Request request) {
|
public boolean isApplicationRequest(Request request) {
|
||||||
final String uri = request.requestURI().toString();
|
final String uri = request.requestURI().toString();
|
||||||
return uri.endsWith("/dmx");
|
return uri.endsWith("/bunti");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClose(WebSocket socket, com.sun.grizzly.websockets.DataFrame frame) {
|
public void onClose(WebSocket socket, com.sun.grizzly.websockets.DataFrame frame) {
|
||||||
DMXControllerWebSocket ws = (DMXControllerWebSocket) socket;
|
BuntiControllerWebSocket ws = (BuntiControllerWebSocket) socket;
|
||||||
Mixer.getInstance().removeListener(ws);
|
Mixer.getInstance().removeListener(ws);
|
||||||
logger.debug("removed websocket");
|
logger.debug("removed websocket");
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ package de.ctdo.websocket;
|
||||||
|
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
//import javax.servlet.annotation.WebServlet;
|
import javax.servlet.annotation.WebServlet;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -10,11 +10,12 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.sun.grizzly.websockets.WebSocketEngine;
|
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;
|
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
|
@Override
|
||||||
public void init(ServletConfig config) throws ServletException {
|
public void init(ServletConfig config) throws ServletException {
|
|
@ -17,11 +17,11 @@ import de.ctdo.dmx.DMXDataChangedListener;
|
||||||
* @author lucas
|
* @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);
|
super(protocolHandler, listeners);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,20 +10,20 @@
|
||||||
<welcome-file>default.jsp</welcome-file>
|
<welcome-file>default.jsp</welcome-file>
|
||||||
</welcome-file-list>
|
</welcome-file-list>
|
||||||
|
|
||||||
<description>CTDO DMX control Server</description>
|
<description>CTDO bunti control Server</description>
|
||||||
|
<!--
|
||||||
<servlet>
|
<servlet>
|
||||||
<description></description>
|
<description></description>
|
||||||
<servlet-name>DMXControllerServlet</servlet-name>
|
<servlet-name>BuntiControllerServlet</servlet-name>
|
||||||
<servlet-class>de.ctdo.websocket.DMXControllerServlet</servlet-class>
|
<servlet-class>de.ctdo.websocket.BuntiControllerServlet</servlet-class>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>DMXControllerServlet</servlet-name>
|
<servlet-name>BuntiControllerServlet</servlet-name>
|
||||||
<url-pattern>/dmx</url-pattern>
|
<url-pattern>/bunti</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
-->
|
||||||
<session-config>
|
<session-config>
|
||||||
<session-timeout>25</session-timeout>
|
<session-timeout>25</session-timeout>
|
||||||
</session-config>
|
</session-config>
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
$(document).ready(
|
$(document).ready(
|
||||||
function() {
|
function() {
|
||||||
|
var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket;
|
||||||
ws = new MozWebSocket("ws://localhost:8080/bunti_server/dmx");
|
ws = new MozWebSocket("ws://localhost:8080/bunti_server/bunti");
|
||||||
//ws = new MozWebSocket("ws://localhost:8080/grizzly-websockets-chat/chat");
|
//ws = new MozWebSocket("ws://localhost:8080/grizzly-websockets-chat/chat");
|
||||||
|
|
||||||
ws.onmessage = function (message) {
|
ws.onmessage = function (message) {
|
||||||
|
|
Loading…
Reference in New Issue