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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
package de.ctdo.bunti.web; package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController; 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 de.ctdo.bunti.web.model.DeviceUpdates;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,7 +22,7 @@ public class DeviceControlController {
@RequestMapping(value = "/devices", method = RequestMethod.POST) @RequestMapping(value = "/devices", method = RequestMethod.POST)
public void setDevices(@RequestBody DeviceUpdates updates) { 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()) { for (DeviceUpdate update: updates.getUpdates()) {
LOGGER.info("Update deviceId=" + update.getDeviceId()); 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; package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.dao.BuntiDevicesDAO; import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.BuntiDevice; import de.ctdo.bunti.model.BuntiDevice;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -12,28 +13,34 @@ import java.util.Collection;
@RequestMapping(value = "/devices") @RequestMapping(value = "/devices")
public class DevicesController { public class DevicesController {
private BuntiDevicesDAO devicesDAO; private BuntiDevicesDAO devicesDAO;
private BuntiController buntiController;
@Autowired @Autowired
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) { public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO; this.devicesDAO = devicesDAO;
} }
@Autowired
public void setBuntiController(BuntiController buntiController) {
this.buntiController = buntiController;
}
@RequestMapping(value = "", method = RequestMethod.GET) @RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Collection<BuntiDevice> getAll() { public Collection<BuntiDevice> getAll() {
return devicesDAO.getAllDevices(); return buntiController.getAllDevices();
} }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public BuntiDevice getDeviceById(@PathVariable("id") int id) { public BuntiDevice getDeviceById(@PathVariable("id") int id) {
return devicesDAO.getDeviceById(id); return buntiController.getDeviceById(id);
} }
@RequestMapping(value = "", method = RequestMethod.POST) @RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public BuntiDevice setDevices(@RequestBody BuntiDevice device) { public BuntiDevice setDevices(@RequestBody BuntiDevice device) {
devicesDAO.addDevice(device); //buntiController.addDevice(device);
return device; return device;
} }
} }

View File

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