100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Start on KNX protocol
Marcus Redeker7a80e2abd21b
diff --git a/agent/build.gradle b/agent/build.gradleindex 2bb204206..c430bd6f1 100644--- a/agent/build.gradle+++ b/agent/build.gradle@@ -10,4 +10,8 @@ dependencies {compile "com.luckycatlabs:SunriseSunsetCalculator:$sunriseSunsetCalculatorVersion"compile "org.quartz-scheduler:quartz:$quartzVersion"++ compile "com.github.calimero:calimero-core:$calimeroVersion"+ compile "com.github.calimero:calimero-tools:$calimeroVersion"+}\ No newline at end of filediff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.java b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.javanew file mode 100644index 000000000..15352f4a5--- /dev/null+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXConnection.java@@ -0,0 +1,9 @@+package org.openremote.agent.protocol.knx;++public class KNXConnection {++ public KNXConnection() {+ // TODO+ }++}diff --git a/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.javanew file mode 100644index 000000000..90acddcfa--- /dev/null+++ b/agent/src/main/java/org/openremote/agent/protocol/knx/KNXProtocol.java@@ -0,0 +1,76 @@+package org.openremote.agent.protocol.knx;++import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;++import java.util.Optional;+import java.util.logging.Logger;++import org.openremote.agent.protocol.AbstractProtocol;+import org.openremote.agent.protocol.ConnectionStatus;+import org.openremote.model.AbstractValueHolder;+import org.openremote.model.asset.AssetAttribute;+import org.openremote.model.attribute.AttributeEvent;+import org.openremote.model.attribute.AttributeState;++public class KNXProtocol extends AbstractProtocol {++ private static final Logger LOG = Logger.getLogger(KNXProtocol.class.getName());+++ public static final String PROTOCOL_NAME = PROTOCOL_NAMESPACE + ":knx";+ public static final String KNX_GATEWAY_IP = PROTOCOL_NAME + ":gatewayIp";+++ @Override+ public String getProtocolName() {+ return PROTOCOL_NAME;+ }++ @Override+ protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {+ Optional<String> gatewayIp = protocolConfiguration.getMetaItem(KNX_GATEWAY_IP).flatMap(AbstractValueHolder::getValueAsString);+ if (!gatewayIp.isPresent()) {+ LOG.severe("No KNX gateway IP address provided for protocol configuration: " + protocolConfiguration);+ updateStatus(protocolConfiguration.getReferenceOrThrow(), ConnectionStatus.ERROR);+ return;+ }++ if (!protocolConfiguration.isEnabled()) {+ updateStatus(protocolConfiguration.getReferenceOrThrow(), ConnectionStatus.DISABLED);+ return;+ }++ updateStatus(protocolConfiguration.getReferenceOrThrow(), ConnectionStatus.CONNECTED);+ //TODO Create KNXConnection for given IP and config. KNXConnection will be main class for KNX communication and will be the listener for bus events+ }++ @Override+ protected void doUnlinkProtocolConfiguration(AssetAttribute protocolConfiguration) {+ // TODO retrieve related KNX connection and close link to KNX bus++ }++ @Override+ protected void doLinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {+ // TODO different attributes can have same group address+ //create calimero StateDP ga, name, read address, write address++ }++ @Override+ protected void doUnlinkAttribute(AssetAttribute attribute, AssetAttribute protocolConfiguration) {+ // TODO++ }++ @Override+ protected void processLinkedAttributeWrite(AttributeEvent event, AssetAttribute protocolConfiguration) {+ // TODO groupWrite - event.getAttributeRef() to identify groupaddress+ // event.getValue() - new value to send to knx++ }++++ //TODO call updateLinkedAttribute(AttributeState state, long timestamp) when receiving event from KNX bus+}diff --git a/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol b/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocolindex b95463ff8..cfd06659c 100644--- a/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol+++ b/agent/src/main/resources/META-INF/services/org.openremote.agent.protocol.Protocol@@ -1,3 +1,4 @@org.openremote.agent.protocol.simulator.SimulatorProtocolorg.openremote.agent.protocol.macro.MacroProtocol-org.openremote.agent.protocol.timer.TimerProtocol\ No newline at end of file+org.openremote.agent.protocol.timer.TimerProtocol+org.openremote.agent.protocol.knx.KNXProtocol\ No newline at end of filediff --git a/gradle.properties b/gradle.propertiesindex 7e2256c53..2e0bda1f0 100644--- a/gradle.properties+++ b/gradle.properties@@ -28,4 +28,5 @@ camelVersion = 2.19.0tyrusVersion = 1.10sunriseSunsetCalculatorVersion = 1.2droolsVersion = 6.5.0.Final-quartzVersion= 2.2.3\ No newline at end of file+quartzVersion= 2.2.3+calimeroVersion = 2.3\ No newline at end of filediff --git a/manager/test/build.gradle b/manager/test/build.gradleindex 3e8762775..52923f02e 100644--- a/manager/test/build.gradle+++ b/manager/test/build.gradle@@ -26,6 +26,7 @@ dependencies {compile "junit:junit:$junitVersion"compile "org.spockframework:spock-core:$spockVersion"+ compile "com.github.calimero:calimero-server:$calimeroVersion"}test {diff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovynew file mode 100644index 000000000..ee35b01c0--- /dev/null+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy@@ -0,0 +1,87 @@+/*+ * Copyright 2017, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <http://www.gnu.org/licenses/>.+ */+package org.openremote.test.protocol++import org.openremote.agent.protocol.AbstractProtocol+import org.openremote.agent.protocol.knx.KNXProtocol+import org.openremote.agent.protocol.ConnectionStatus+import org.openremote.manager.server.agent.AgentService+import org.openremote.manager.server.asset.AssetProcessingService+import org.openremote.manager.server.asset.AssetStorageService+import org.openremote.manager.server.asset.ServerAsset+import org.openremote.model.Constants+import org.openremote.model.asset.AssetAttribute+import org.openremote.model.asset.AssetMeta+import org.openremote.model.asset.AssetType+import org.openremote.model.asset.agent.ProtocolConfiguration+import org.openremote.model.attribute.*+import org.openremote.model.value.Values+import org.openremote.test.ManagerContainerTrait+import spock.lang.Specification+import spock.util.concurrent.PollingConditions++/**+ * This tests the KNX protocol and protocol implementation.+ */+class KNXProtocolTest extends Specification implements ManagerContainerTrait {++ def "Check KNX protocol"() {++ given: "expected conditions"+ def conditions = new PollingConditions(timeout: 10, delay: 1)++ and: "the container is started"+ def serverPort = findEphemeralPort()+ def container = startContainerNoDemoAssets(defaultConfig(serverPort), defaultServices())+ def assetStorageService = container.getService(AssetStorageService.class)+ def agentService = container.getService(AgentService.class)+ def assetProcessingService = container.getService(AssetProcessingService.class)++ and: "the KNX emulation server is started"+ //TODO++ when: "a KNX agent that uses the KNX protocol is created with a valid protocol configuration"+ def knxAgent = new ServerAsset()+ knxAgent.setName("KNX Agent")+ knxAgent.setType(AssetType.AGENT)+ knxAgent.setAttributes(+ ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("knxConfig"), KNXProtocol.PROTOCOL_NAME)+ .addMeta(+ new MetaItem(KNXProtocol.KNX_GATEWAY_IP, Values.create("localhost"))+ ),+ ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("knxConfigError"), KNXProtocol.PROTOCOL_NAME)+ )+ knxAgent.setRealmId(Constants.MASTER_REALM)+ knxAgent = assetStorageService.merge(knxAgent)++ then: "the protocol configurations should be linked and their deployment status should be available in the agent service"+ conditions.eventually {+ assert agentService.getProtocolDeploymentStatus(knxAgent.getAttribute("knxConfig").get().getReferenceOrThrow()) == ConnectionStatus.CONNECTED+ }++ conditions.eventually {+ assert agentService.getProtocolDeploymentStatus(knxAgent.getAttribute("knxConfigError").get().getReferenceOrThrow()) == ConnectionStatus.ERROR+ }+++ cleanup: "the server should be stopped"+ stopContainer(container)+ }+}\ No newline at end of filediff --git a/manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy b/manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovyindex 4bb39ca8c..c023b1cea 100644--- a/manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/protocol/TimerProtocolTest.groovy@@ -32,7 +32,7 @@ class TimerProtocolTest extends Specification implements ManagerContainerTrait {when: "the container starts"def serverPort = findEphemeralPort()- def container = startContainerWithDemoScenesAndRules(defaultConfig(serverPort) << [(SETUP_IMPORT_DEMO_SCENES): "true"], defaultServices())+ def container = startContainerWithDemoScenesAndRules(defaultConfig(serverPort), defaultServices())def assetStorageService = container.getService(AssetStorageService.class)def assetProcessingService = container.getService(AssetProcessingService.class)def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)diff --git a/manager/test/src/test/resources/knx-server-config.xml b/manager/test/src/test/resources/knx-server-config.xmlnew file mode 100644index 000000000..7aad42827--- /dev/null+++ b/manager/test/src/test/resources/knx-server-config.xml@@ -0,0 +1,32 @@+<?xml version="1.0" encoding="UTF-8"?>+<!-- Calimero 2 server settings -->+<knxServer name="knx-server" friendlyName="Calimero KNXnet/IP Test Server">++ <!-- KNXnet/IP search & discovery -->+ <discovery listenNetIf="all" outgoingNetIf="all" activate="true" />++ <!-- Provides the KNXnet/IP-side configuration for access to one KNX subnet -->+ <serviceContainer activate="true" routing="false" networkMonitoring="true"+ udpPort="3671" listenNetIf="any" reuseCtrlEP="false">+ <knxAddress type="individual">1.1.1</knxAddress>+ <disruptionBuffer expirationTimeout="30" udpPort="5555-5559" />++ <knxSubnet type="emulate">1.1.1</knxSubnet>++ <!-- KNX group address filter applied for this service container (optional) -->+ <groupAddressFilter>+ <knxAddress type="group">0/0/0</knxAddress>+ <knxAddress type="group">2/1/1</knxAddress>+ <knxAddress type="group">2/1/0</knxAddress>+ <knxAddress type="group">2/1/20</knxAddress>+ </groupAddressFilter>+ <!-- Additional KNX individual addresses assigned to KNXnet/IP connections (optional) -->+ <additionalAddresses>+ <knxAddress type="individual">1.1.10</knxAddress>+ <knxAddress type="individual">1.1.11</knxAddress>+ <knxAddress type="individual">1.1.12</knxAddress>+ <knxAddress type="individual">1.1.13</knxAddress>+ </additionalAddresses>+ </serviceContainer>+ <!-- Next service container (optional) -->+</knxServer>