This repository has been archived by the owner on May 17, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binding for relay boards available from http://www.ucprojects.eu
- Loading branch information
Showing
20 changed files
with
990 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src/main/java"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
33 changes: 33 additions & 0 deletions
33
bundles/binding/org.openhab.binding.ucprelayboard/.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.openhab.binding.ucprelayboard</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ds.core.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
4 changes: 4 additions & 0 deletions
4
bundles/binding/org.openhab.binding.ucprelayboard/.settings/org.eclipse.pde.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#Fri Oct 08 00:21:11 CEST 2010 | ||
eclipse.preferences.version=1 | ||
pluginProject.extensions=false | ||
resolve.requirebundle=false |
25 changes: 25 additions & 0 deletions
25
bundles/binding/org.openhab.binding.ucprelayboard/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: openHAB UCProjects.eu RelayBoard Binding | ||
Bundle-SymbolicName: org.openhab.binding.ucprelayboard | ||
Bundle-Version: 1.8.0.qualifier | ||
Bundle-Vendor: openHAB.org | ||
Bundle-RequiredExecutionEnvironment: J2SE-1.5 | ||
Import-Package: gnu.io, | ||
javax.mail;version="1.4.0", | ||
org.apache.commons.io, | ||
org.apache.commons.lang, | ||
org.openhab.core.binding, | ||
org.openhab.core.events, | ||
org.openhab.core.items, | ||
org.openhab.core.library.items, | ||
org.openhab.core.library.types, | ||
org.openhab.core.types, | ||
org.openhab.model.item.binding, | ||
org.osgi.framework, | ||
org.osgi.service.cm, | ||
org.osgi.service.event, | ||
org.slf4j | ||
Export-Package: org.openhab.binding.ucprelayboard | ||
Service-Component: OSGI-INF/binding.xml, OSGI-INF/genericbindingprovider.xml | ||
Bundle-ClassPath: . |
20 changes: 20 additions & 0 deletions
20
bundles/binding/org.openhab.binding.ucprelayboard/OSGI-INF/binding.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2010-2015, openHAB.org and others. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
--> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0" activate="activate" configuration-pid="org.openhab.ucprelayboard" configuration-policy="require" deactivate="deactivate" enabled="true" immediate="true" modified="modified" name="org.openhab.binding.ucprelayboard.binding"> | ||
<implementation class="org.openhab.binding.ucprelayboard.internal.UCPRelayBoardBinding"/> | ||
<service> | ||
<provide interface="org.osgi.service.event.EventHandler" /> | ||
</service> | ||
<property name="event.topics" type="String" value="openhab/command/*"/> | ||
<reference bind="setEventPublisher" cardinality="1..1" interface="org.openhab.core.events.EventPublisher" name="EventPublisher" policy="dynamic" unbind="unsetEventPublisher" /> | ||
<reference bind="addBindingProvider" cardinality="1..n" interface="org.openhab.binding.ucprelayboard.UCPRelayBoardBindingProvider" name="UCPRelayBoardBindingProvider" policy="dynamic" unbind="removeBindingProvider"/> | ||
</scr:component> |
18 changes: 18 additions & 0 deletions
18
bundles/binding/org.openhab.binding.ucprelayboard/OSGI-INF/genericbindingprovider.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2010-2015, openHAB.org and others. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
--> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.openhab.binding.ucprelayboard.genericbindingprovider"> | ||
<implementation class="org.openhab.binding.ucprelayboard.internal.UCPRelayBoardGenericBindingProvider"/> | ||
<service> | ||
<provide interface="org.openhab.model.item.binding.BindingConfigReader"/> | ||
<provide interface="org.openhab.binding.ucprelayboard.UCPRelayBoardBindingProvider"/> | ||
</service> | ||
</scr:component> |
5 changes: 5 additions & 0 deletions
5
bundles/binding/org.openhab.binding.ucprelayboard/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
output.. = target/classes/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
OSGI-INF/ | ||
source.. = src/main/java/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.openhab.bundles</groupId> | ||
<artifactId>binding</artifactId> | ||
<version>1.8.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<name>openHAB UCProjects.eu RelayBoard Binding</name> | ||
|
||
<properties> | ||
<bundle.symbolicName>org.openhab.binding.ucprelayboard</bundle.symbolicName> | ||
<bundle.namespace>org.openhab.binding.ucprelayboard</bundle.namespace> | ||
<deb.name>openhab-addon-binding-ucprelayboard</deb.name> | ||
<deb.description>${project.name}</deb.description> | ||
<deb.depends>openhab-addon-io-serial</deb.depends> | ||
</properties> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.openhab.binding</groupId> | ||
<artifactId>org.openhab.binding.ucprelayboard</artifactId> | ||
|
||
<packaging>eclipse-plugin</packaging> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.vafer</groupId> | ||
<artifactId>jdeb</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
30 changes: 30 additions & 0 deletions
30
...ayboard/src/main/java/org/openhab/binding/ucprelayboard/UCPRelayBoardBindingProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.ucprelayboard; | ||
|
||
/** | ||
* @author Robert Michalak | ||
* @since 1.8.0 | ||
*/ | ||
import org.openhab.binding.ucprelayboard.internal.UCPRelayConfig; | ||
import org.openhab.core.binding.BindingProvider; | ||
import org.openhab.core.items.Item; | ||
|
||
public interface UCPRelayBoardBindingProvider extends BindingProvider { | ||
|
||
/** | ||
* Returns the binding configuration for an item | ||
* @param itemName | ||
* @return | ||
*/ | ||
public UCPRelayConfig getRelayConfigForItem(String itemName); | ||
|
||
public Item getItemForRelayConfig(UCPRelayConfig config); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...inding.ucprelayboard/src/main/java/org/openhab/binding/ucprelayboard/internal/DowCRC.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.ucprelayboard.internal; | ||
/** | ||
* Implementation of Dallas One Wire CRC formula based on http://www.maximintegrated.com/en/app-notes/index.mvp/id/27 | ||
* | ||
* @author Robert Michalak | ||
* | ||
*/ | ||
public class DowCRC { | ||
private static final char crc8[] = { | ||
0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65, | ||
157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220, | ||
35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98, | ||
190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255, | ||
70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7, | ||
219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154, | ||
101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36, | ||
248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185, | ||
140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205, | ||
17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80, | ||
175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238, | ||
50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115, | ||
202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139, | ||
87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22, | ||
233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168, | ||
116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53 | ||
}; | ||
|
||
public static byte compute(byte[] tab) { | ||
int result = 0; | ||
for (byte value : tab) { | ||
result = crc8[ (int)value ^ result]; | ||
} | ||
return (byte) result; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ard/src/main/java/org/openhab/binding/ucprelayboard/internal/InitializationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.ucprelayboard.internal; | ||
|
||
/** | ||
* @author Robert Michalak | ||
* @since 1.8.0 | ||
*/ | ||
public class InitializationException extends Exception { | ||
|
||
private static final long serialVersionUID = -5106059856757667266L; | ||
|
||
public InitializationException(String msg) { | ||
super(msg); | ||
} | ||
|
||
public InitializationException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public InitializationException(String msg, Throwable cause) { | ||
super(msg, cause); | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
....ucprelayboard/src/main/java/org/openhab/binding/ucprelayboard/internal/SerialDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* Copyright (c) 2010-2015, openHAB.org and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.ucprelayboard.internal; | ||
|
||
import gnu.io.CommPortIdentifier; | ||
import gnu.io.NoSuchPortException; | ||
import gnu.io.PortInUseException; | ||
import gnu.io.SerialPort; | ||
import gnu.io.UnsupportedCommOperationException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class represents a serial device | ||
* | ||
* @author Robert Michalak | ||
* @since 1.8.0 | ||
*/ | ||
|
||
public class SerialDevice { | ||
|
||
private static final Logger logger = LoggerFactory | ||
.getLogger(SerialDevice.class); | ||
|
||
private SerialDeviceConfig config; | ||
|
||
private CommPortIdentifier portId; | ||
private SerialPort serialPort; | ||
|
||
private InputStream inputStream; | ||
private OutputStream outputStream; | ||
|
||
public SerialDevice(SerialDeviceConfig config) { | ||
this.config = config; | ||
} | ||
|
||
public SerialDeviceConfig getConfig() { | ||
return config; | ||
} | ||
|
||
/** | ||
* Initialize this device and open the serial port | ||
* | ||
* @throws InitializationException | ||
* if port can not be opened | ||
*/ | ||
public void initialize() throws InitializationException { | ||
try { | ||
portId = CommPortIdentifier.getPortIdentifier(config.getPort()); | ||
|
||
if (portId != null) { | ||
// initialize serial port | ||
serialPort = (SerialPort) portId.open("openHAB", 2000); | ||
|
||
// set port parameters | ||
serialPort.setSerialPortParams(config.getBaud(), | ||
SerialPort.DATABITS_8, SerialPort.STOPBITS_1, | ||
SerialPort.PARITY_NONE); | ||
|
||
inputStream = serialPort.getInputStream(); | ||
|
||
outputStream = serialPort.getOutputStream(); | ||
|
||
} else { | ||
throw new InitializationException("Serial port '" | ||
+ config.getPort() + "' could not be found.\n"); | ||
} | ||
} catch (UnsupportedCommOperationException e) { | ||
throw new InitializationException(e); | ||
} catch (IOException e) { | ||
throw new InitializationException(e); | ||
} catch (PortInUseException e) { | ||
throw new InitializationException(e); | ||
} catch (NoSuchPortException e) { | ||
throw new InitializationException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Sends a string to the serial port of this device | ||
* | ||
* @param relayBoardCommand | ||
* the string to send | ||
*/ | ||
public void writeBytes(byte[] relayBoardCommand) { | ||
try { | ||
// write bytes to serial port | ||
outputStream.write(relayBoardCommand); | ||
outputStream.flush(); | ||
} catch (IOException e) { | ||
logger.error("Error writing to serial port {}: {}", new Object[] { | ||
config.getPort(), e.getMessage() }); | ||
} | ||
} | ||
|
||
public byte[] readBytes(final byte[] buffer) { | ||
try { | ||
if (inputStream.available() > 0) { | ||
inputStream.read(buffer); | ||
} | ||
} catch (IOException e) { | ||
logger.error("Error reading from serial port {}: {}", new Object[] { | ||
config.getPort(), e.getMessage() }); | ||
} | ||
return buffer; | ||
} | ||
|
||
/** | ||
* Close this serial device | ||
*/ | ||
public void close() { | ||
IOUtils.closeQuietly(outputStream); | ||
IOUtils.closeQuietly(inputStream); | ||
serialPort.close(); | ||
} | ||
|
||
} |
Oops, something went wrong.