diff --git a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java index f9e4581..2b388d9 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.Map; import de.ctdo.bunti.dao.RoomsDAO; +import de.ctdo.bunti.model.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -12,7 +13,6 @@ import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.stereotype.Component; import de.ctdo.bunti.dao.BuntiDevicesDAO; -import de.ctdo.bunti.model.*; @Component public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware { diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java index 5c27899..4394618 100644 --- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java +++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java @@ -1,9 +1,9 @@ package de.ctdo.bunti.dao; -import java.util.Collection; import java.util.List; -import de.ctdo.bunti.model.*; +import de.ctdo.bunti.model.BuntiDMXDevice; +import de.ctdo.bunti.model.BuntiDevice; public interface BuntiDevicesDAO { diff --git a/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java b/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java index 521e4e7..371b6f4 100644 --- a/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java +++ b/src/main/java/de/ctdo/bunti/dmx/DMXChannels.java @@ -1,6 +1,6 @@ package de.ctdo.bunti.dmx; -import de.ctdo.bunti.dmx.model.DMXChannel; +import de.ctdo.bunti.model.DMXChannel; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/de/ctdo/bunti/ethersex/EthersexMixer.java b/src/main/java/de/ctdo/bunti/ethersex/EthersexMixer.java new file mode 100644 index 0000000..b0cc117 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/ethersex/EthersexMixer.java @@ -0,0 +1,10 @@ +package de.ctdo.bunti.ethersex; + +import de.ctdo.bunti.model.BuntiDevice; + +import java.util.Map; + +public interface EthersexMixer { + boolean updateDevice(BuntiDevice device, Map options); + +} diff --git a/src/main/java/de/ctdo/bunti/ethersex/EthersexMixerImpl.java b/src/main/java/de/ctdo/bunti/ethersex/EthersexMixerImpl.java new file mode 100644 index 0000000..ca9a347 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/ethersex/EthersexMixerImpl.java @@ -0,0 +1,42 @@ +package de.ctdo.bunti.ethersex; + +import de.ctdo.bunti.control.DeviceChangedEvent; +import de.ctdo.bunti.model.BuntiEthersexDevice; +import de.ctdo.bunti.model.BuntiDevice; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationListener; + +import java.util.Map; + +public class EthersexMixerImpl implements EthersexMixer, ApplicationListener { + private static final Logger LOGGER = LoggerFactory.getLogger(EthersexMixerImpl.class); + private boolean hasDataChanged = true; + + @Override + public final boolean updateDevice(BuntiDevice device, Map options) { + if(device == null || options == null || options.size() == 0) { + return false; + } + +// BuntiDMXDevice dmxDev = (BuntiDMXDevice) device; +// +// if (dmxDev.setValuesFromOptions(options)) { +// +// dmxMap.putAll(dmxDev.getChannelData()); +// +// LOGGER.info("setValuesFromOptions on " + device); +// return true; +// } + + LOGGER.info("setValuesFromOptions on " + device + " failed"); + return false; + } + + @Override + public final void onApplicationEvent(DeviceChangedEvent arg0) { + if (arg0.getDevice() instanceof BuntiEthersexDevice) { + updateDevice(arg0.getDevice(), arg0.getOptions()); + } + } +} diff --git a/src/main/java/de/ctdo/bunti/dmx/model/BuntiDMXDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java similarity index 97% rename from src/main/java/de/ctdo/bunti/dmx/model/BuntiDMXDevice.java rename to src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java index 8daf9d9..69ec0c8 100644 --- a/src/main/java/de/ctdo/bunti/dmx/model/BuntiDMXDevice.java +++ b/src/main/java/de/ctdo/bunti/model/BuntiDMXDevice.java @@ -1,9 +1,7 @@ -package de.ctdo.bunti.dmx.model; +package de.ctdo.bunti.model; import de.ctdo.bunti.dmx.DMX; -import de.ctdo.bunti.dmx.model.DMXChannel; import de.ctdo.bunti.dmx.DMXChannels; -import de.ctdo.bunti.model.BuntiDevice; import org.codehaus.jackson.annotate.JsonIgnore; import org.hibernate.annotations.Entity; diff --git a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java index 4bcb9d3..11ebd92 100644 --- a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java +++ b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java @@ -11,7 +11,7 @@ import java.util.Map; @Entity @Table(name = "devices") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) -public abstract class BuntiDevice { +public class BuntiDevice { private int id; private String deviceName; private String picture; @@ -85,12 +85,12 @@ public abstract class BuntiDevice { /** * Switch this device off. */ - public abstract void switchOff(); + public void switchOff() {} /** * Switch this device on. */ - public abstract void switchOn(); + public void switchOn() {} /** * The the internal options corresponding to the given Key Value Map @@ -98,11 +98,15 @@ public abstract class BuntiDevice { * @param options The options Map. * @return True on success. False otherwise. */ - public abstract boolean setValuesFromOptions(Map options); + public boolean setValuesFromOptions(Map options) { + return false; + } @Transient - public abstract Map getOptions(); + public Map getOptions() { + return null; + } } diff --git a/src/main/java/de/ctdo/bunti/model/BuntiEthersexDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiEthersexDevice.java new file mode 100644 index 0000000..7f04c23 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/model/BuntiEthersexDevice.java @@ -0,0 +1,91 @@ +package de.ctdo.bunti.model; + +import de.ctdo.bunti.model.BuntiDevice; +import org.hibernate.annotations.Entity; + +import javax.persistence.Transient; +import java.util.HashMap; +import java.util.Map; + +@Entity +public abstract class BuntiEthersexDevice extends BuntiDevice { + private String hostname; + private int port; + private static final Map ports = new HashMap(); + + + public BuntiEthersexDevice() { + + } + + public String getHostname() { + return hostname; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public final boolean setPortByName(String name, int value) { + if (ports.containsKey(name)) { + + ports.put(name, value); + return true; + } + return false; + } + + @Transient + public final int getPortByName(String name) { + if (ports.containsKey(name)) { + return ports.get(name); + } + return 0; + } + + @Override + public boolean setValuesFromOptions(Map options) { + for (Map.Entry opt : options.entrySet()) { + try { + int value = Integer.parseInt(opt.getValue().toString()); + + if (!setPortByName(opt.getKey(), value)) { + return false; + } + } catch (Exception e) { + return false; + } + } + return true; + } + + @Override + public Map getOptions() { + Map options = new HashMap(); + + for(Map.Entry p: ports.entrySet()) { + options.put(p.getKey(), p.getValue()); + } + + return options; + } + + /** + * Add a channel to this DMX Device + * used internally by subclasses to define their structure + * @param channel DMXChannel to add (name and offset) + * @return True on success, false otherwise. + */ + public final void addPort(String channel) { + ports.put(channel, 0x00); + } + +} diff --git a/src/main/java/de/ctdo/bunti/dmx/model/DMXChannel.java b/src/main/java/de/ctdo/bunti/model/DMXChannel.java similarity index 95% rename from src/main/java/de/ctdo/bunti/dmx/model/DMXChannel.java rename to src/main/java/de/ctdo/bunti/model/DMXChannel.java index 9e386af..a258507 100644 --- a/src/main/java/de/ctdo/bunti/dmx/model/DMXChannel.java +++ b/src/main/java/de/ctdo/bunti/model/DMXChannel.java @@ -1,4 +1,4 @@ -package de.ctdo.bunti.dmx.model; +package de.ctdo.bunti.model; public class DMXChannel { private int offset; diff --git a/src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java b/src/main/java/de/ctdo/bunti/model/Lampel.java similarity index 82% rename from src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java rename to src/main/java/de/ctdo/bunti/model/Lampel.java index 6e2b338..7b0fed7 100644 --- a/src/main/java/de/ctdo/bunti/ethersex/model/Lampel.java +++ b/src/main/java/de/ctdo/bunti/model/Lampel.java @@ -1,14 +1,7 @@ -package de.ctdo.bunti.ethersex.model; - -import de.ctdo.bunti.dmx.DMX; -import de.ctdo.bunti.dmx.model.DMXChannel; -import de.ctdo.bunti.model.BuntiDevice; -import org.codehaus.jackson.annotate.JsonIgnore; +package de.ctdo.bunti.model; import javax.persistence.Entity; import javax.persistence.Transient; -import java.util.HashMap; -import java.util.Map; @Entity public class Lampel extends BuntiEthersexDevice { @@ -40,7 +33,7 @@ public class Lampel extends BuntiEthersexDevice { @Override public final void switchOn() { - setPortByName(PORTC, LAMPEL_GREEN | LAMPEL_RED | LAMPEL_YELLOW ); + setPortByName(PORTC, LAMPEL_GREEN | LAMPEL_RED | LAMPEL_YELLOW); } diff --git a/src/main/java/de/ctdo/bunti/dmx/model/Par56Spot.java b/src/main/java/de/ctdo/bunti/model/Par56Spot.java similarity index 98% rename from src/main/java/de/ctdo/bunti/dmx/model/Par56Spot.java rename to src/main/java/de/ctdo/bunti/model/Par56Spot.java index c732b4f..824f4e7 100644 --- a/src/main/java/de/ctdo/bunti/dmx/model/Par56Spot.java +++ b/src/main/java/de/ctdo/bunti/model/Par56Spot.java @@ -1,4 +1,4 @@ -package de.ctdo.bunti.dmx.model; +package de.ctdo.bunti.model; import de.ctdo.bunti.dmx.DMX; import org.codehaus.jackson.annotate.JsonIgnore; diff --git a/src/main/java/de/ctdo/bunti/dmx/model/Strobe1500.java b/src/main/java/de/ctdo/bunti/model/Strobe1500.java similarity index 98% rename from src/main/java/de/ctdo/bunti/dmx/model/Strobe1500.java rename to src/main/java/de/ctdo/bunti/model/Strobe1500.java index 7eabdad..e03d770 100644 --- a/src/main/java/de/ctdo/bunti/dmx/model/Strobe1500.java +++ b/src/main/java/de/ctdo/bunti/model/Strobe1500.java @@ -1,4 +1,4 @@ -package de.ctdo.bunti.dmx.model; +package de.ctdo.bunti.model; import de.ctdo.bunti.dmx.DMX; import org.codehaus.jackson.annotate.JsonIgnore; diff --git a/src/main/resources/META-INF/spring/hibernate-beans.xml b/src/main/resources/META-INF/spring/hibernate-beans.xml index b8f1cad..6c1ea95 100755 --- a/src/main/resources/META-INF/spring/hibernate-beans.xml +++ b/src/main/resources/META-INF/spring/hibernate-beans.xml @@ -19,7 +19,7 @@ - + @@ -40,7 +40,6 @@ - diff --git a/src/main/resources/init_data.sql b/src/main/resources/init_data.sql index aa3b737..f00cc2e 100755 --- a/src/main/resources/init_data.sql +++ b/src/main/resources/init_data.sql @@ -6,14 +6,18 @@ insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Eta insert into rooms (ROOM_ID, floor, roomName, xCord, yCord) values (null, '2. Etage', 'Flur', '1', '1'); -insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress) - values ('Par56Spot',null,'Lampe1',null, 1); -insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress) - values ('Par56Spot',null,'Lampe2',null, 6); -insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress) - values ('Par56Spot',null,'Lampe3',null, 11); -insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress) - values ('Par56Spot',null,'Lampe4',null, 16); +insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) + values ('Par56Spot',null,'Lampe1',null, 1, null, null); +insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) + values ('Par56Spot',null,'Lampe2',null, 6, null, null); +insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) + values ('Par56Spot',null,'Lampe3',null, 11, null, null); +insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) + values ('Par56Spot',null,'Lampe4',null, 16, null, null); + + +insert into devices (DTYPE, BUNTIDEVICE_ID, deviceName, picture, startAddress, hostname, port) + values ('Lampel',null,'Die Lampel',null, null, 'lampel.ctdo.de', 2701); insert into ROOM_BUNTIDEVICE (ROOM_ID, BUNTIDEVICE_ID) VALUES (2, 1); diff --git a/src/main/resources/init_schema.sql b/src/main/resources/init_schema.sql index 72ae1bc..baa4a71 100755 --- a/src/main/resources/init_schema.sql +++ b/src/main/resources/init_schema.sql @@ -10,6 +10,8 @@ create table devices (DTYPE varchar(31) not null, deviceName varchar(255), picture varchar(255), startAddress integer, + hostname varchar(255), + port integer, primary key (BUNTIDEVICE_ID)); create table rooms (ROOM_ID integer generated by default as identity (start with 1), diff --git a/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java b/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java index f926a49..e35d840 100644 --- a/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java +++ b/src/test/java/de/ctdo/bunti/dao/BuntiDevicesDAOImplTest.java @@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import java.util.Collection; import java.util.List; import static junit.framework.Assert.assertEquals; @@ -24,13 +23,13 @@ public class BuntiDevicesDAOImplTest { @Test public void testGetAllDMXDevices() throws Exception { List deviceList = dut.getAllDMXDevices(); - assertEquals(4, deviceList.size()); + assertEquals(5, deviceList.size()); } @Test public void testGetAllDevices() throws Exception { List deviceList = dut.getAllDevices(); - assertEquals(4, deviceList.size()); + assertEquals(5, deviceList.size()); } @Test diff --git a/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java b/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java index 6bb8375..ac7a767 100644 --- a/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java +++ b/src/test/java/de/ctdo/bunti/dmx/DMXChannelTest.java @@ -1,6 +1,6 @@ package de.ctdo.bunti.dmx; -import de.ctdo.bunti.dmx.model.DMXChannel; +import de.ctdo.bunti.model.DMXChannel; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java b/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java index d24c8b8..3c67d37 100644 --- a/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java +++ b/src/test/java/de/ctdo/bunti/dmx/DMXChannelsTest.java @@ -1,6 +1,6 @@ package de.ctdo.bunti.dmx; -import de.ctdo.bunti.dmx.model.DMXChannel; +import de.ctdo.bunti.model.DMXChannel; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java b/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java index 6d9b321..99cf2b7 100644 --- a/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java +++ b/src/test/java/de/ctdo/bunti/dmx/DMXMixerImplTest.java @@ -1,6 +1,5 @@ package de.ctdo.bunti.dmx; -import de.ctdo.bunti.model.BuntiDevice; import de.ctdo.bunti.model.Par56Spot; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java index 8e69918..8afb344 100644 --- a/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java +++ b/src/test/java/de/ctdo/bunti/model/BuntiDMXDeviceTest.java @@ -1,6 +1,8 @@ package de.ctdo.bunti.model; -import de.ctdo.bunti.dmx.model.DMXChannel; +import de.ctdo.bunti.model.BuntiDMXDevice; +import de.ctdo.bunti.model.DMXChannel; +import de.ctdo.bunti.model.Par56Spot; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java index 5c304c3..e726ae6 100644 --- a/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java +++ b/src/test/java/de/ctdo/bunti/model/Par56SpotTest.java @@ -1,5 +1,6 @@ package de.ctdo.bunti.model; +import de.ctdo.bunti.model.Par56Spot; import org.junit.Before; import org.junit.Test; import static junit.framework.Assert.*; diff --git a/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java b/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java index 433556b..87cde4c 100644 --- a/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java +++ b/src/test/java/de/ctdo/bunti/model/Strobe1500Test.java @@ -1,5 +1,6 @@ package de.ctdo.bunti.model; +import de.ctdo.bunti.model.Strobe1500; import org.junit.Before; import org.junit.Test;