extended controller and created a test web gui

extended BuntiDevice with a picture Path
This commit is contained in:
Lucas Pleß 2012-03-14 00:57:00 +01:00
parent 9c54e5d73c
commit 71421bd559
12 changed files with 165 additions and 111 deletions

View File

@ -123,6 +123,13 @@
<version>4.10</version> <version>4.10</version>
</dependency> </dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId> <artifactId>jetty-server</artifactId>

View File

@ -31,11 +31,11 @@ public class ByteUtils {
this.data = data; this.data = data;
} }
public static final int byteToUint(byte b) { public static int byteToUint(byte b) {
return (b < 0 ? BYTE_OVERFLOW + b : b); return (b < 0 ? BYTE_OVERFLOW + b : b);
} }
public static final byte uintToByte(int i) { public static byte uintToByte(int i) {
return (byte)(i & BYTE_MAX); return (byte)(i & BYTE_MAX);
} }

View File

@ -119,8 +119,8 @@ public class ArtDmxPacket extends ArtNetPacket {
/** /**
* Sets universe and subnet into data array. Needed because subnet and universe are both 4 bit and share one byte * Sets universe and subnet into data array. Needed because subnet and universe are both 4 bit and share one byte
* @param subnetID * @param subnetID The ArtNet Subnet ID from 0 to 3
* @param universeID * @param universeID The ArtNet Universe ID from 0 to 3
*/ */
private void setUniverse(int subnetID, int universeID) { private void setUniverse(int subnetID, int universeID) {
getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE); getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE);

View File

@ -45,6 +45,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
} }
if (hasDataChanged) { if (hasDataChanged) {
LOGGER.debug("sending DMX Data");
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress); artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
hasDataChanged = false; hasDataChanged = false;
} }

View File

@ -10,6 +10,7 @@ import java.util.Map;
public abstract class BuntiDevice { public abstract class BuntiDevice {
private int deviceId; private int deviceId;
private String deviceName; private String deviceName;
private String picture;
public BuntiDevice(int deviceId, String deviceName) { public BuntiDevice(int deviceId, String deviceName) {
this.deviceId = deviceId; this.deviceId = deviceId;
@ -54,6 +55,22 @@ public abstract class BuntiDevice {
this.deviceName = deviceName; this.deviceName = deviceName;
} }
/**
* Get the relative URL to the picture of this device
* @return the relative URL to the picture
*/
public final String getPicture() {
return picture;
}
/**
* Get the relative URL to the picture of this device
* @param picture The relative URL to the picture
*/
public final void setPicture(String picture) {
this.picture = picture;
}
/** /**
* Switch this device off. * Switch this device off.
*/ */
@ -72,4 +89,5 @@ public abstract class BuntiDevice {
*/ */
public abstract boolean setValuesFromOptions(Map<String, Object> options); public abstract boolean setValuesFromOptions(Map<String, Object> options);
} }

View File

@ -21,45 +21,45 @@ public class Par56Spot extends BuntiDMXDevice {
addChannel(new DMXChannel(offset, CHANNEL_SPEED)); addChannel(new DMXChannel(offset, CHANNEL_SPEED));
} }
public final void setColorRed(int value) { public final void setRed(int value) {
setChannelValueByName(CHANNEL_RED, value); setChannelValueByName(CHANNEL_RED, value);
} }
public final void setColorGreen(int value) { public final void setGreen(int value) {
setChannelValueByName(CHANNEL_GREEN, value); setChannelValueByName(CHANNEL_GREEN, value);
} }
public final void setColorBlue(int value) { public final void setBlue(int value) {
setChannelValueByName(CHANNEL_BLUE, value); setChannelValueByName(CHANNEL_BLUE, value);
} }
public final int getColorRed() { public final int getRed() {
return getChannelValueByName(CHANNEL_RED); return getChannelValueByName(CHANNEL_RED);
} }
public final int getColorGreen() { public final int getGreen() {
return getChannelValueByName(CHANNEL_GREEN); return getChannelValueByName(CHANNEL_GREEN);
} }
public final int getColorBlue() { public final int getBlue() {
return getChannelValueByName(CHANNEL_BLUE); return getChannelValueByName(CHANNEL_BLUE);
} }
@Override @Override
public final void switchOff() { public final void switchOff() {
setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN); setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
setColorRed(DMX.DMX_CHANNEL_VALUE_MIN); setRed(DMX.DMX_CHANNEL_VALUE_MIN);
setColorGreen(DMX.DMX_CHANNEL_VALUE_MIN); setGreen(DMX.DMX_CHANNEL_VALUE_MIN);
setColorBlue(DMX.DMX_CHANNEL_VALUE_MIN); setBlue(DMX.DMX_CHANNEL_VALUE_MIN);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN); setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
} }
@Override @Override
public final void switchOn() { public final void switchOn() {
setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN); setChannelValueByName(CHANNEL_MODE, DMX.DMX_CHANNEL_VALUE_MIN);
setColorRed(DMX.DMX_CHANNEL_VALUE_MAX); setRed(DMX.DMX_CHANNEL_VALUE_MAX);
setColorGreen(DMX.DMX_CHANNEL_VALUE_MAX); setGreen(DMX.DMX_CHANNEL_VALUE_MAX);
setColorBlue(DMX.DMX_CHANNEL_VALUE_MAX); setBlue(DMX.DMX_CHANNEL_VALUE_MAX);
setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN); setChannelValueByName(CHANNEL_SPEED, DMX.DMX_CHANNEL_VALUE_MIN);
} }
@ -71,11 +71,11 @@ public class Par56Spot extends BuntiDMXDevice {
sb.append(", "); sb.append(", ");
sb.append(getDeviceName()); sb.append(getDeviceName());
sb.append(" ["); sb.append(" [");
sb.append(getColorRed()); sb.append(getRed());
sb.append(","); sb.append(",");
sb.append(getColorGreen()); sb.append(getGreen());
sb.append(","); sb.append(",");
sb.append(getColorBlue()); sb.append(getBlue());
sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
} }

View File

@ -30,18 +30,6 @@ public class RestController {
this.controller = controller; this.controller = controller;
} }
@RequestMapping(value = "/devices2", method = RequestMethod.GET)
public @ResponseBody DeviceUpdate testGet() {
DeviceUpdate update = new DeviceUpdate();
update.setDeviceId(23);
Map<String, Object> options = new HashMap<String, Object>();
options.put("red", 111);
options.put("green", 2);
options.put("blue", 33);
update.setOptions(options);
return update;
}
@RequestMapping(value = "/devices", method = RequestMethod.GET) @RequestMapping(value = "/devices", method = RequestMethod.GET)
public @ResponseBody Collection<BuntiDevice> getAll() { public @ResponseBody Collection<BuntiDevice> getAll() {
LOGGER.info("handle GET /devices request"); LOGGER.info("handle GET /devices request");
@ -54,37 +42,26 @@ public class RestController {
return controller.getDeviceById(id); return controller.getDeviceById(id);
} }
@RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT) @RequestMapping(value = "/devices/{id}", method = RequestMethod.POST)
public String setDeviceById(@PathVariable("id") int id, @RequestBody Map<String, Object> update) { public @ResponseBody BuntiDevice setDeviceById(@PathVariable("id") int id, @RequestBody DeviceUpdate update) {
LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() ); LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
controller.updateDeviceData(id, update);
return "redirect:devices/" + id; controller.updateDeviceData(id, update.getOptions());
return controller.getDeviceById(id);
} }
@RequestMapping(value = "/devices", method = RequestMethod.PUT) @RequestMapping(value = "/devices", method = RequestMethod.POST)
public String setDevices(@RequestBody ArrayList<DeviceUpdate> updates) { public String setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() ); LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates) { for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId()); LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions()); controller.updateDeviceData(update.getDeviceId(), update.getOptions());
} }
return "redirect:devices"; return "bla";
}
@RequestMapping(value = "/devices2", method = RequestMethod.PUT)
public String setDevices2(@RequestBody DeviceUpdate update) {
LOGGER.info("handle PUT /devices" + " request update=" + update.toString() );
LOGGER.info("Update deviceId=" + update.getDeviceId());
controller.updateDeviceData(update.getDeviceId(), update.getOptions());
return "redirect:devices";
} }
} }

View File

@ -1,10 +1,29 @@
package de.ctdo.bunti.webmodel; package de.ctdo.bunti.webmodel;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
public class DeviceUpdates { public class DeviceUpdates {
private long timeStamp = 0;
private List<DeviceUpdate> updates = new ArrayList<DeviceUpdate>();
public List<DeviceUpdate> getUpdates() {
return updates;
}
public void setUpdates(List<DeviceUpdate> updates) {
this.updates = updates;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
} }

View File

@ -12,7 +12,7 @@
</appender> </appender>
<logger name="org.springframework"> <logger name="org.springframework">
<level value="debug" /> <level value="info" />
</logger> </logger>

View File

@ -14,53 +14,74 @@
<script type="text/javascript" src="<c:url value="/resources/js/jquery-ui-1.8.18.custom.min.js" />"></script> <script type="text/javascript" src="<c:url value="/resources/js/jquery-ui-1.8.18.custom.min.js" />"></script>
<script type="text/javascript"> <script type="text/javascript">
var ws;
var dmxData;
$(document).ready( $(document).ready(
function() { function() {
var dataChanged = false;
var par56eins = $.parseJSON('{"deviceId":1, "options": {"red":0,"blue":0,"green":0} }');
$("#slider1").slider({ min: 0, max: 255, slide: function(event, ui) {
} });
$("#slider2").slider({ min: 0, max: 255, slide: function(event, ui) {
} });
$("#slider3").slider({ min: 0, max: 255, slide: function(event, ui) {
} });
$("#buttonLampe1").click(function() {
$.getJSON('/devices/1', function(data) {
alert("data: " + data.deviceId + " " + data.colorRed );
});
function sendData(data) {
$.ajax({
type: 'POST',
url: "/control/devices/1",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(data)
}); });
}
var senden = function sendOutAllDevices() {
if(dataChanged) {
dataChanged = false;
sendData(par56eins);
}
};
// vielleicht baut man lieber was mit setTimeout und setzt das jeweils neu wenn man daten ändert
// das könnte den Browser entlasten, sofern den das 200ms Aufrufen überhaupt stört :D
window.setInterval(senden, 200);
$("#slider1").slider({ min: 0, max: 255, slide: function(event, ui) {
par56eins.options.red = ui.value;
dataChanged = true;
} });
$("#slider2").slider({ min: 0, max: 255, slide: function(event, ui) {
par56eins.options.green = ui.value;
dataChanged = true;
} });
$("#slider3").slider({ min: 0, max: 255, slide: function(event, ui) {
par56eins.options.blue = ui.value;
dataChanged = true;
} });
$("#buttonLampe1").click(function() {
$.getJSON('/control/devices/1', function(data) {
$("#messages").append("type: " + data.type + " name=" + data.deviceName + "<br/>" );
});
}); });
}
);
</script> </script>
</head> </head>
<body> <body>
<h1>Bunti Steuerung</h1> <h1>Bunti Steuerung</h1>
<div class="demo">
<div id="slider1" style="width: 300px"></div>
<div id="slider2" style="width: 300px; margin-top: 10px"></div>
<div id="slider3" style="width: 300px; margin-top: 10px"></div>
</div>
<div class="demo"> <input type="button" value="Get Device 1" id="buttonLampe1" />
<div id="slider1" style="width: 300px"></div>
<div id="slider2" style="width: 300px; margin-top: 10px"></div>
<div id="slider3" style="width: 300px; margin-top: 10px"></div>
</div>
<div id="messages"></div> <div id="messages"></div>
<input type="button" value="Update Lampe 1" id="buttonLampe1" />
</body> </body>
</html> </html>

View File

@ -142,4 +142,15 @@ public class BuntiDMXDeviceTest {
assertEquals(DEVICEID, dut.getDeviceId()); assertEquals(DEVICEID, dut.getDeviceId());
} }
@Test
public void testGetPicture() throws Exception {
dut.setPicture("urltopicture");
assertEquals("urltopicture", dut.getPicture());
}
@Test
public void testGetType() throws Exception {
assertEquals("Par56Spot", dut.getType());
}
} }

View File

@ -15,55 +15,55 @@ public class Par56SpotTest {
@Test @Test
public void testColorRed() throws Exception { public void testColorRed() throws Exception {
dut.setColorRed(0); dut.setRed(0);
assertEquals(0,dut.getColorRed()); assertEquals(0,dut.getRed());
dut.setColorRed(128); dut.setRed(128);
assertEquals(128,dut.getColorRed()); assertEquals(128,dut.getRed());
dut.setColorRed(255); dut.setRed(255);
assertEquals(255,dut.getColorRed()); assertEquals(255,dut.getRed());
} }
@Test @Test
public void testColorGreen() throws Exception { public void testColorGreen() throws Exception {
dut.setColorGreen(0); dut.setGreen(0);
assertEquals(0,dut.getColorGreen()); assertEquals(0,dut.getGreen());
dut.setColorGreen(128); dut.setGreen(128);
assertEquals(128,dut.getColorGreen()); assertEquals(128,dut.getGreen());
dut.setColorGreen(255); dut.setGreen(255);
assertEquals(255,dut.getColorGreen()); assertEquals(255,dut.getGreen());
} }
@Test @Test
public void testColorBlue() throws Exception { public void testColorBlue() throws Exception {
dut.setColorBlue(0); dut.setBlue(0);
assertEquals(0,dut.getColorBlue()); assertEquals(0,dut.getBlue());
dut.setColorBlue(128); dut.setBlue(128);
assertEquals(128,dut.getColorBlue()); assertEquals(128,dut.getBlue());
dut.setColorBlue(255); dut.setBlue(255);
assertEquals(255,dut.getColorBlue()); assertEquals(255,dut.getBlue());
} }
@Test @Test
public void testSwitchOff() throws Exception { public void testSwitchOff() throws Exception {
dut.switchOff(); dut.switchOff();
assertEquals(0,dut.getColorRed()); assertEquals(0,dut.getRed());
assertEquals(0,dut.getColorGreen()); assertEquals(0,dut.getGreen());
assertEquals(0,dut.getColorBlue()); assertEquals(0,dut.getBlue());
} }
@Test @Test
public void testSwitchOn() throws Exception { public void testSwitchOn() throws Exception {
dut.switchOn(); dut.switchOn();
assertEquals(255,dut.getColorRed()); assertEquals(255,dut.getRed());
assertEquals(255,dut.getColorGreen()); assertEquals(255,dut.getGreen());
assertEquals(255,dut.getColorBlue()); assertEquals(255,dut.getBlue());
} }
@Test @Test
public void testToString() throws Exception { public void testToString() throws Exception {
dut.setColorRed(123); dut.setRed(123);
dut.setColorGreen(111); dut.setGreen(111);
dut.setColorBlue(42); dut.setBlue(42);
assertEquals("Par56Spot 23, device [123,111,42]", dut.toString()); assertEquals("Par56Spot 23, device [123,111,42]", dut.toString());
} }
} }