Anderungen am Controller. Die Kanalwerte werden nicht in der DB gespeichert, deswegen bekommt man immer 0 zurueck wenn man sich die Geräte holt.

Leider nicht funktional soweit
This commit is contained in:
Lucas Ple 2012-05-25 15:52:42 +02:00
parent f98ab7c225
commit 8c363fbf64
7 changed files with 54 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package de.ctdo.bunti.control;
import de.ctdo.bunti.model.BuntiDevice;
import de.ctdo.bunti.model.DeviceUpdate;
import de.ctdo.bunti.model.Room;
import java.util.Collection;
@ -16,4 +17,6 @@ public interface BuntiController {
Collection<Room> getAllRooms();
Room getRoomById(int roomId);
DeviceUpdate getDeviceValues(int deviceId);
}

View File

@ -1,10 +1,12 @@
package de.ctdo.bunti.control;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import de.ctdo.bunti.dao.RoomsDAO;
import de.ctdo.bunti.model.*;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,6 +22,7 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
private ApplicationEventPublisher applicationEventPublisher = null;
private BuntiDevicesDAO devicesDAO;
private RoomsDAO roomsDAO;
private Map<Integer, Map<String, Object>> deviceCache = new HashMap<Integer, Map<String, Object>>();
@Autowired
@ -45,6 +48,15 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
if (device != null) {
LOGGER.debug("publishEvent in BuntiController");
Map<String, Object> cached = deviceCache.get(deviceId);
if(cached == null ) {
cached = new HashMap<String, Object>();
deviceCache.put(deviceId, cached);
}
cached.putAll(options);
device.setValuesFromOptions(options) ;
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
return true;
@ -53,6 +65,16 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPu
return false;
}
@Override
public DeviceUpdate getDeviceValues(int deviceId) {
Map<String, Object> cached = deviceCache.get(deviceId);
DeviceUpdate du = new DeviceUpdate();
du.setDeviceId(deviceId);
du.setOptions(cached);
return du;
}
@Override
public Collection<Room> getAllRooms() {
return roomsDAO.getRooms();

View File

@ -40,6 +40,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
@Scheduled(fixedDelay = NET_SEND_INTERVAL)
public final void sendOutDMXBuffer() {
/*
if (dmxMap.size() == 0) {
initDMXData();
}
@ -48,7 +49,7 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
LOGGER.debug("sending DMX Data");
artNetSender.sendDMXData(dmxMap, artNetDeviceAddress);
hasDataChanged = false;
}
}*/
}
@Override
@ -59,16 +60,16 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
BuntiDMXDevice dmxDev = (BuntiDMXDevice) device;
if (dmxDev.setValuesFromOptions(options)) {
//if (dmxDev.setValuesFromOptions(options)) {
dmxMap.putAll(dmxDev.getChannelData());
LOGGER.info("setValuesFromOptions on " + device);
return true;
}
//}
LOGGER.info("setValuesFromOptions on " + device + " failed");
return false;
// LOGGER.info("setValuesFromOptions on " + device + " failed");
// return false;
}
@Override

View File

@ -1,4 +1,4 @@
package de.ctdo.bunti.web.model;
package de.ctdo.bunti.model;
import java.util.Map;

View File

@ -1,7 +1,7 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.web.model.DeviceUpdate;
import de.ctdo.bunti.model.DeviceUpdate;
import de.ctdo.bunti.web.model.DeviceUpdates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,7 +22,7 @@ public class DeviceControlController {
@RequestMapping(value = "/devices", method = RequestMethod.POST)
public void setDevices(@RequestBody DeviceUpdates updates) {
LOGGER.info("handle PUT /devices" + " request update=" + updates.toString() );
LOGGER.info("handle POST /devices" + " request update=" + updates.toString() );
for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId());
@ -30,4 +30,12 @@ public class DeviceControlController {
}
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
public DeviceUpdate getDeviceValues(@PathVariable("id") int id) {
LOGGER.info("handle GET /devices/{id} " + id );
return controller.getDeviceValues(id);
}
}

View File

@ -1,5 +1,6 @@
package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.BuntiDevice;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,28 +13,34 @@ import java.util.Collection;
@RequestMapping(value = "/devices")
public class DevicesController {
private BuntiDevicesDAO devicesDAO;
private BuntiController buntiController;
@Autowired
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO;
}
@Autowired
public void setBuntiController(BuntiController buntiController) {
this.buntiController = buntiController;
}
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public Collection<BuntiDevice> getAll() {
return devicesDAO.getAllDevices();
return buntiController.getAllDevices();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public BuntiDevice getDeviceById(@PathVariable("id") int id) {
return devicesDAO.getDeviceById(id);
return buntiController.getDeviceById(id);
}
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
public BuntiDevice setDevices(@RequestBody BuntiDevice device) {
devicesDAO.addDevice(device);
//buntiController.addDevice(device);
return device;
}
}

View File

@ -1,5 +1,7 @@
package de.ctdo.bunti.web.model;
import de.ctdo.bunti.model.DeviceUpdate;
import java.util.ArrayList;
import java.util.List;