Skip to content

Commit 38ee59f

Browse files
committedMar 24, 2015
Full support of Raspberry.
1 parent fc08e8d commit 38ee59f

28 files changed

+1235
-655
lines changed
 

‎.settings/org.eclipse.jdt.core.prefs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
45
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5-
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.compliance=1.7
67
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
78
org.eclipse.jdt.core.compiler.debug.localVariable=generate
89
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
910
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
1011
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
1112
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12-
org.eclipse.jdt.core.compiler.source=1.8
13+
org.eclipse.jdt.core.compiler.source=1.7

‎README.md

+48-52
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,48 @@
1-
# optolink
2-
3-
Viessmann heating systems with vitotronic has a optolink Interface for maintenance.
4-
This interface can use for get/set data in the heating system.
5-
For more information about this interface see: http://openv.wikispaces.com/
6-
7-
The java-application is a slim adapter to this interface.
8-
On southbound it use the serial interface for connect the optolink interface (special hardware requert).
9-
On northbound it provides a TCP/IP raw Port for communication and a UDP/IP Port as broadcast interface
10-
to search the adapter in the local network.
11-
12-
Primary is is develop for a adaption from [openhab2](https://github.com/openhab/openhab2/).
13-
It supports on the northbound the concept of openhab2 things.
14-
15-
##Build
16-
The application is develop in Eclipse (Luna) with maven support.
17-
Requierd Lib's: rxtx, slf4j, logback (see pom.xml file)
18-
You can build runtime by Run->Run As->Maven install.
19-
jar file is found in the folder ./traget
20-
21-
##Install & running
22-
All test was running on a Raspberry PI B with Raspbian "wheezy".
23-
Installing:
24-
25-
1. Install the rxtx (apt)
26-
2. Config /dev/ttyAMA0 (see: https://cae2100.wordpress.com/2012/12/23/raspberry-pi-and-the-serial-port/)
27-
3. Install your optolink hardware
28-
4. copy: optolink-<version>-SNAPSHOT-jar-with-dependencies.jar from the target folder to Rasberry
29-
5. copy optolink.xml and logback.xml to Rasberry - same folder than jar file.
30-
6. Edit optolink.xml for your heading system.
31-
7. start it: ```java -Dlogback.configurationFile=./logback.xml -Djava.library.path=/usr/lib/jni -Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0 -jar optolink-0.0.1-SNAPSHOT-jar-with-dependencies.jar ```
32-
33-
34-
##Test it
35-
Run a terminal programm (like putty), connect to you raspberry by using port 31113 and raw protocol.
36-
Suported command:
37-
38-
* list -> list all (thing) definition (in xml-File)
39-
* get <Thing.id> -> get Data for thing from heating system.
40-
41-
##Further doing (my ToDo List)
42-
1. integration to openlink2 (binding) -> priority
43-
2. implement set function
44-
3. implementaion of logfile.
45-
3. bug-fixing
46-
4. Full integration in PI (start.sh, logfile, run it with startup PI,..)
47-
last: Build a stable version (together with openhab2).
48-
49-
50-
51-
52-
1+
# optolink
2+
3+
Viessmann heating systems with vitotronic has a optolink Interface for maintenance.
4+
This interface can use for get/set data in the heating system.
5+
For more information about this interface see: http://openv.wikispaces.com/
6+
7+
The java-application is a slim adapter to this interface.
8+
On southbound it use the serial interface for connect the optolink interface (special hardware requert).
9+
On northbound it provides a TCP/IP raw Port for communication and a UDP/IP Port as broadcast interface
10+
to search the adapter in the local network.
11+
12+
Primary is is develop for a adaption from [openhab2](https://github.com/openhab/openhab2/).
13+
It supports on the northbound the concept of openhab2 things.
14+
15+
##Build
16+
The application is develop in Eclipse (Luna) with maven support.
17+
Requierd Lib's: rxtx, slf4j, logback (see pom.xml file)
18+
You can build runtime by Run->Run As->Maven install.
19+
Files for runtime are found in ./traget
20+
21+
##Install & running
22+
All test was running on a Raspberry PI B with Raspbian "wheezy".
23+
Installing:
24+
25+
1. Install the rxtx (apt)
26+
2. Config /dev/ttyAMA0 (see: https://cae2100.wordpress.com/2012/12/23/raspberry-pi-and-the-serial-port/)
27+
3. Install your optolink hardware
28+
4. copy: optolink-runtime.zip from the target folder to Rasberry and extract it.
29+
5. Edit conf/optolink.xml for your heading system.
30+
6. start it: ```./start_debug.sh ```
31+
32+
33+
##Test it
34+
Run a terminal programm (like putty), connect to you raspberry by using port 31113 and raw protocol.
35+
Suported command:
36+
37+
* list -> list all (thing) definition (in xml-File)
38+
* get <Thing.id> -> get Data for thing from heating system.
39+
* set <ThingId>:<ChannelId> <value> (The syntax of Value is not checked)
40+
41+
##Further doing (my ToDo List)
42+
1. bug-fixing (if bugs found ;-)
43+
2. Build a stable version (together with openhab2).
44+
45+
46+
47+
48+

‎logback.xml

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<configuration scan="true" scanPeriod="15 seconds">
3+
4+
5+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6+
<file>logs/optolink.log</file>
7+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8+
<!-- weekly rollover and archiving -->
9+
<fileNamePattern>logs/optolink-%d{yyyy-ww}.log.zip</fileNamePattern>
10+
<!-- maximum number of archive files to keep -->
11+
<maxHistory>12</maxHistory>
12+
</rollingPolicy>
13+
<encoder>
14+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
15+
</encoder>
16+
</appender>
17+
318
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
419
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
520
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
621
</encoder>
722
</appender>
8-
9-
<root level="TRACE">
10-
<appender-ref ref="CONSOLE" />
11-
</root>
23+
24+
<logger name="de.myandres" level="INFO">
25+
<appender-ref ref="FILE" />
26+
</logger>
27+
28+
<root level="WARN">
29+
<appender-ref ref="FILE" />
30+
<appender-ref ref="STDOUT" />
31+
</root>
32+
33+
1234
</configuration>

‎logback_debug.xml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds">
3+
4+
5+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6+
<file>logs/optolink.log</file>
7+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8+
<!-- weekly rollover and archiving -->
9+
<fileNamePattern>logs/optolink-%d{yyyy-ww}.log.zip</fileNamePattern>
10+
<!-- maximum number of archive files to keep -->
11+
<maxHistory>12</maxHistory>
12+
</rollingPolicy>
13+
<encoder>
14+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
15+
</encoder>
16+
</appender>
17+
18+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
19+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
20+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
21+
</encoder>
22+
</appender>
23+
24+
<logger name="de.myandres" level="INFO">
25+
<appender-ref ref="FILE" />
26+
</logger>
27+
28+
<logger name="de.myandres" level="DEBUG">
29+
<appender-ref ref="STDOUT" />
30+
</logger>
31+
32+
<root level="WARN">
33+
<appender-ref ref="FILE" />
34+
<appender-ref ref="STDOUT" />
35+
</root>
36+
37+
38+
</configuration>

‎logback_trace.xml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds">
3+
4+
5+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6+
<file>logs/optolink.log</file>
7+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8+
<!-- weekly rollover and archiving -->
9+
<fileNamePattern>logs/optolink-%d{yyyy-ww}.log.zip</fileNamePattern>
10+
<!-- maximum number of archive files to keep -->
11+
<maxHistory>12</maxHistory>
12+
</rollingPolicy>
13+
<encoder>
14+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
15+
</encoder>
16+
</appender>
17+
18+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
19+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
20+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
21+
</encoder>
22+
</appender>
23+
24+
<logger name="de.myandres" level="INFO">
25+
<appender-ref ref="FILE" />
26+
</logger>
27+
28+
<logger name="de.myandres" level="TRACE">
29+
<appender-ref ref="STDOUT" />
30+
</logger>
31+
32+
<root level="WARN">
33+
<appender-ref ref="FILE" />
34+
<appender-ref ref="STDOUT" />
35+
</root>
36+
37+
38+
</configuration>

‎optolink.xml

+228-167
Large diffs are not rendered by default.

‎pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>de.myandres.optolink</groupId>
44
<artifactId>optolink</artifactId>
5-
<version>0.0.1-SNAPSHOT</version>
5+
<version>0.0.2-SNAPSHOT</version>
66
<packaging>jar</packaging>
77
<name>optolink</name>
88
<build>
@@ -19,6 +19,8 @@
1919
<mainClass>de.myandres.optolink.Main</mainClass>
2020
</manifest>
2121
</archive>
22+
<descriptor>src/assembly/runtime.xml</descriptor>
23+
<finalName>optolink</finalName>
2224
</configuration>
2325
<executions>
2426
<execution>

‎src/assembly/runtime.xml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
4+
<id>runtime</id>
5+
<formats>
6+
<format>tar.gz</format>
7+
<format>tar.bz2</format>
8+
<format>zip</format>
9+
</formats>
10+
11+
<fileSets>
12+
<fileSet>
13+
<includes>
14+
<include>README*</include>
15+
<include>LICENCE</include>
16+
</includes>
17+
<lineEnding>unix</lineEnding>
18+
</fileSet>
19+
20+
<fileSet>
21+
<directory>src/main/resources</directory>
22+
<outputDirectory>conf</outputDirectory>
23+
<includes>
24+
<include>*.xml</include>
25+
</includes>
26+
<lineEnding>unix</lineEnding>
27+
</fileSet>
28+
<fileSet>
29+
<directory>src/main/resources</directory>
30+
<outputDirectory></outputDirectory>
31+
<includes>
32+
<include>*.sh</include>
33+
<include>*.txt</include>
34+
</includes>
35+
<lineEnding>unix</lineEnding>
36+
<fileMode>0755</fileMode>
37+
</fileSet>
38+
<fileSet>
39+
<directory>target</directory>
40+
<outputDirectory>lib</outputDirectory>
41+
<includes>
42+
<include>*jar-with-dependencies.jar</include>
43+
</includes>
44+
</fileSet>
45+
</fileSets>
46+
</assembly>
47+
48+
49+
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,108 @@
1-
/*******************************************************************************
2-
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3-
*
4-
* All rights reserved. This program and the accompanying materials
5-
* are made available under the terms of the GNU Lesser General Public License
6-
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7-
* http://www.gnu.org/licenses/lgpl-3.0.html
8-
*
9-
* This library is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
* Lesser General Public License for more details.
13-
*******************************************************************************/
14-
package de.myandres.optolink;
15-
16-
import java.net.DatagramPacket;
17-
import java.net.DatagramSocket;
18-
import java.net.InetAddress;
19-
import org.slf4j.Logger;
20-
import org.slf4j.LoggerFactory;
21-
22-
public class BroadcastListner implements Runnable {
23-
24-
static Logger log = LoggerFactory.getLogger(BroadcastListner.class);
25-
26-
static final String BROADCAST_MESSAGE = "@@@@VITOTRONIC@@@@/";
27-
int port;
28-
String connectedIP;
29-
String adapterID;
30-
31-
32-
33-
BroadcastListner(int port, String adapterID) {
34-
log.debug("Init Broadcast Listener on Port", port);
35-
this.port = port;
36-
connectedIP = "";
37-
this.adapterID =adapterID;
38-
}
39-
40-
41-
@Override
42-
public void run() {
43-
// Runs Listner
44-
log.debug("Listening for Broadcast....");
45-
DatagramSocket datagramSocket = null;
46-
InetAddress remoteIPAddress;
47-
int remotePort;
48-
byte[] byteArray = new byte[1024];
49-
50-
try {
51-
datagramSocket = new DatagramSocket(port, InetAddress.getByName("0.0.0.0"));
52-
datagramSocket.setBroadcast(true);
53-
54-
55-
String str;
56-
57-
while (true) {
58-
try {
59-
DatagramPacket resivedPacket = new DatagramPacket(byteArray , byteArray.length);
60-
datagramSocket.receive(resivedPacket);
61-
str = new String(resivedPacket.getData()).trim();
62-
log.debug("Resived Broadcast Message: {}", str);
63-
remotePort = resivedPacket.getPort();
64-
log.debug("From Port: {}", remotePort);
65-
remoteIPAddress = resivedPacket.getAddress();
66-
log.debug("From Host: {}",remoteIPAddress.toString());
67-
68-
if (str.startsWith(BROADCAST_MESSAGE+adapterID) ||
69-
str.startsWith(BROADCAST_MESSAGE+"*")) {
70-
// Someone calls me
71-
str = BROADCAST_MESSAGE + "/"+adapterID;
72-
byteArray = str.getBytes();
73-
DatagramPacket sendPacket = new DatagramPacket(byteArray,
74-
byteArray.length, remoteIPAddress, remotePort);
75-
log.debug("Send: '{}' to {}:{}", str, remoteIPAddress.getHostAddress(), remotePort );
76-
datagramSocket.send(sendPacket);
77-
78-
79-
} else {
80-
log.debug("Host: {}:{} calls with wrong message: {}",
81-
remoteIPAddress.getHostAddress(),
82-
remotePort,
83-
str);
84-
log.debug("Message will be ignor!");
85-
}
86-
87-
} catch (Exception e) {
88-
// TODO Auto-generated catch block
89-
log.error("Something is wrong in broadcast listner thread!!! Diagnostic {}", e);
90-
log.error("Broadcast Listner die - no again");
91-
92-
} }
93-
94-
} catch (Exception e) {
95-
// TODO Auto-generated catch block
96-
log.error("Something is wrong in broadcast listner thread!!! Diagnostic {}", e);
97-
log.error("Broadcast Listner die - no again");
98-
99-
} finally {
100-
try {
101-
if (datagramSocket != null)
102-
datagramSocket.close();
103-
} catch (Exception e) {
104-
// Ignore
105-
}
106-
}
107-
}
108-
109-
}
1+
/*******************************************************************************
2+
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the GNU Lesser General Public License
6+
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7+
* http://www.gnu.org/licenses/lgpl-3.0.html
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*******************************************************************************/
14+
package de.myandres.optolink;
15+
16+
import java.net.DatagramPacket;
17+
import java.net.DatagramSocket;
18+
import java.net.InetAddress;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
22+
public class BroadcastListner implements Runnable {
23+
24+
static Logger log = LoggerFactory.getLogger(BroadcastListner.class);
25+
26+
static final String BROADCAST_MESSAGE = "@@@@VITOTRONIC@@@@/";
27+
int port;
28+
String connectedIP;
29+
String adapterID;
30+
31+
32+
33+
BroadcastListner(int port, String adapterID) {
34+
log.debug("Init Broadcast Listener on Port", port);
35+
this.port = port;
36+
connectedIP = "";
37+
this.adapterID =adapterID;
38+
}
39+
40+
41+
@Override
42+
public void run() {
43+
// Runs Listner
44+
log.debug("Listening for Broadcast....");
45+
DatagramSocket datagramSocket = null;
46+
InetAddress remoteIPAddress;
47+
int remotePort;
48+
byte[] byteArray = new byte[1024];
49+
50+
try {
51+
datagramSocket = new DatagramSocket(port, InetAddress.getByName("0.0.0.0"));
52+
datagramSocket.setBroadcast(true);
53+
54+
55+
String str;
56+
57+
while (true) {
58+
try {
59+
DatagramPacket resivedPacket = new DatagramPacket(byteArray , byteArray.length);
60+
datagramSocket.receive(resivedPacket);
61+
str = new String(resivedPacket.getData()).trim();
62+
log.debug("Resived Broadcast Message: {}", str);
63+
remotePort = resivedPacket.getPort();
64+
log.debug("From Port: {}", remotePort);
65+
remoteIPAddress = resivedPacket.getAddress();
66+
log.debug("From Host: {}",remoteIPAddress.toString());
67+
68+
if (str.startsWith(BROADCAST_MESSAGE+adapterID) ||
69+
str.startsWith(BROADCAST_MESSAGE+"*")) {
70+
// Someone calls me
71+
str = BROADCAST_MESSAGE + adapterID;
72+
byteArray = str.getBytes();
73+
DatagramPacket sendPacket = new DatagramPacket(byteArray,
74+
byteArray.length, remoteIPAddress, remotePort);
75+
log.debug("Send: '{}' to {}:{}", str, remoteIPAddress.getHostAddress(), remotePort );
76+
datagramSocket.send(sendPacket);
77+
78+
79+
} else {
80+
log.debug("Host: {}:{} calls with wrong message: {}",
81+
remoteIPAddress.getHostAddress(),
82+
remotePort,
83+
str);
84+
log.debug("Message will be ignor!");
85+
}
86+
87+
} catch (Exception e) {
88+
log.error("Something is wrong in broadcast listner thread!!! Diagnostic {}", e);
89+
log.error("Broadcast Listner die ");
90+
91+
} }
92+
93+
} catch (Exception e) {
94+
// TODO Auto-generated catch block
95+
log.error("Something is wrong in broadcast listner thread!!! Diagnostic {}", e);
96+
log.error("Broadcast Listner die");
97+
98+
} finally {
99+
try {
100+
if (datagramSocket != null)
101+
datagramSocket.close();
102+
} catch (Exception e) {
103+
// Ignore
104+
}
105+
}
106+
}
107+
108+
}

‎src/main/java/de/myandres/optolink/Channel.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,19 @@ public class Channel {
2121
static Logger logger = LoggerFactory.getLogger(Channel.class);
2222

2323

24-
private String type;
2524
private String id;
2625
private String description;
2726
private Telegram telegram;
2827

2928
Channel (Channel channel) {
30-
logger.trace("Init type: '{}' id: '{}'", channel.getType(), channel.getId() );
31-
this.type = channel.getType();
29+
logger.trace("Init id: '{}'", channel.getId() );
3230
this.id = channel.getId();
3331
this.description = channel.getDescription();
3432
this.telegram = channel.getTelegram();
3533
}
3634

37-
Channel (String id, String type ) {
38-
logger.trace("Init type: '{}' id: '{}'", type, id );
39-
this.type = type;
35+
Channel (String id ) {
36+
logger.trace("Init id: '{}'", id );
4037
this.id = id;
4138
this.description = null;
4239
this.telegram = null;
@@ -51,13 +48,6 @@ public void setTelegram(Telegram telegram) {
5148
this.telegram = telegram;
5249
}
5350

54-
public String getType() {
55-
return type;
56-
}
57-
58-
public void setType(String type) {
59-
this.type = type;
60-
}
6151
public String getId() {
6252
return id;
6353
}

‎src/main/java/de/myandres/optolink/Config.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public void startElement(String uri, String localName, String pName,
216216
thing = new Thing(attr.getValue("id"), attr.getValue("type"));
217217
break;
218218
case "root.optolink.thing.channel":
219-
channel = new Channel (attr.getValue("id"), attr.getValue("type"));
219+
channel = new Channel (attr.getValue("id"));
220220
break;
221221
case "root.optolink.thing.channel.telegram":
222222
channel.setTelegram(new Telegram(attr.getValue("address"),

‎src/main/java/de/myandres/optolink/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) {
3333
try {
3434

3535
// config = new Config("src/main/resources/optolink.xml");
36-
config = new Config("optolink.xml");
36+
config = new Config("conf/optolink.xml");
3737

3838
// Init TTY Handling for Optolink
3939
optolinkInterface = new OptolinkInterface(config.getTTY(), config.getTtyTimeOut());

‎src/main/java/de/myandres/optolink/SocketHandler.java

+55-36
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.ServerSocket;
2828
import java.net.Socket;
2929
import java.util.List;
30+
import java.util.Map;
3031

3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
@@ -54,6 +55,8 @@ public void start() {
5455

5556
BroadcastListner broadcastListner = new BroadcastListner(config.getPort(), config.getAdapterID());
5657

58+
// Put broadcast listner in background
59+
5760
Thread broadcastListnerThread = new Thread(broadcastListner);
5861
broadcastListnerThread.setName("BcListner");
5962
broadcastListnerThread.start();
@@ -83,86 +86,102 @@ private void open(Socket socket) throws Exception {
8386

8487
boolean exit=false;
8588

86-
out.println("#Helo from viessmann");
89+
out.println("<!-- #Helo from viessmann -->");
90+
out.println("<optolink>");
8791

8892
String command;
89-
String param;
93+
String param1;
94+
String param2;
95+
9096
while(!exit) {
9197
String [] inStr = in.readLine().trim().split(" +");
9298
command=inStr[0];
93-
if (inStr.length > 1) param = inStr[1]; else param="";
99+
if (inStr.length > 1) param1 = inStr[1]; else param1="";
100+
if (inStr.length > 2) param2 = inStr[2]; else param2="";
94101
if (log.isTraceEnabled()) {
95102
log.trace("Command): |{}|", command);
96-
log.trace("param : |{}|", param);
103+
log.trace("param1 : |{}|", param1);
104+
log.trace("param2 : |{}|", param2);
97105
}
98106
switch (command.toLowerCase()) {
99107

100108
case "list" : list(); break;
101-
case "get" : getThing(param); break;
102-
case "set" : set(); break;
109+
case "get" : getThing(param1); break;
110+
case "set" : set(param1, param2); break;
103111
case "exit" : exit=true; break;
104112
default: log.error("Unknown Client Command:", inStr[0]);
105113
}
106114
}
107115

108-
out.println("#Bye from viessmann");
116+
out.println("<!-- #Bye from viessmann -->");
109117

110118
}
111119

112120

113121

114-
private void set() {
115-
// TODO Auto-generated method stub
116-
out.println("set() not implemented jet");
117-
log.info("set() not implemented jet");
122+
private void set(String id, String value) {
123+
// Format id = <thing>:<channel>
124+
125+
String[] ids = id.trim().split(":");
126+
127+
if (ids.length != 2) {
128+
log.error("Wrong format '{}' of id", id);
129+
return;
130+
}
131+
Telegram telegram = config.getThing(ids[0]).getChannel(ids[1]).getTelegram();
132+
if (telegram != null) {
133+
out.println("<data>");
134+
out.println(" <thing id=\"" + ids[0] + "\">");
135+
136+
out.println(" <channel id=\""+ ids[1] +"\" value=\""+
137+
viessmannHandler.setValue(telegram, value.toUpperCase())+
138+
"\"/>");
139+
out.println(" </thing>");
140+
out.println("<data>");
141+
}
118142

119143
}
120144

121145
private void getThing(String id) {
122-
List<Channel> channelList;
123-
Channel channel;
124-
125146
log.debug("Try to get Thing for ID: {}", id);
126147
Thing thing = config.getThing(id);
127148
if (thing != null) {
128-
out.println("<thing id=\"" + thing.getId() + "\" type=\"" + thing.getType() + "\">");
129-
channelList = thing.getChannelList();
130-
for (int i=0; i<channelList.size(); i++) {
131-
channel = channelList.get(i);
149+
out.println("<data>");
150+
out.println(" <thing id=\"" + thing.getId() + "\">");
151+
for (Channel channel : thing.getChannelMap()){
132152
if (!channel.getId().startsWith("*")) {
133-
out.println(" <channel id=\""+ channel.getId() +"\" value=\""+
153+
out.println(" <channel id=\""+ channel.getId() +"\" value=\""+
134154
viessmannHandler.getValue(channel.getTelegram())+"\"/>");
135155
}
136156
}
137-
out.println("</thing>");
157+
out.println(" </thing>");
158+
out.println("<data>");
138159
}
139160
}
140161

141162

142163

143164
private void list() {
144165
log.debug("List Things for ID");
145-
List<Thing> thingList = config.getThingList();
146-
List<Channel> channelList;
147-
Thing thing;
148-
Channel channel;
149-
for (int t=0; t<thingList.size(); t++) {
150-
thing = thingList.get(t);
151-
if ((thing != null) && !thing.getId().startsWith("*") ) {
152-
out.println("<thing id=\"" + thing.getId() + "\" type=\"" + thing.getType() + "\">");
153-
out.println(" <discribtion>" + thing.getDescription() + "</describtion>");
154-
channelList = thing.getChannelList();
155-
for (int i=0; i<channelList.size(); i++) {
156-
channel = channelList.get(i);
166+
out.println("<define>");
167+
for (Thing thing : config.getThingList()) {
168+
169+
if ((thing != null) && !thing.getId().startsWith("*") ) {
170+
171+
out.println(" <thing id=\"" + thing.getId() + "\" type=\"" + thing.getType() + "\">");
172+
// out.println(" <description" + thing.getDescription() + "</description>");
173+
for (Channel channel : thing.getChannelMap()) {
157174
if (!channel.getId().startsWith("*")) {
158-
out.println(" <channel id=\""+ channel.getId() +"\" type=\""+channel.getType()+"\">");
159-
out.println(" <discribtion>" + channel.getDescription() + "</describtion>");
160-
out.println("</channel>");
175+
out.println(" <channel id=\""+ channel.getId() + "\"/>");
176+
// out.println(" <description>" + channel.getDescription() + "</description>");
177+
// out.println(" </channel>");
161178
}
162179
}
163-
out.println("</thing>");
180+
out.println(" </thing>");
181+
164182
}
165183
}
184+
out.println("</define>");
166185

167186
}
168187

‎src/main/java/de/myandres/optolink/Thing.java

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the GNU Lesser General Public License
6+
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7+
* http://www.gnu.org/licenses/lgpl-3.0.html
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*******************************************************************************/
114
package de.myandres.optolink;
215

3-
import java.util.ArrayList;
416
import java.util.List;
17+
import java.util.ArrayList;
18+
import java.util.HashMap;
19+
import java.util.Map;
520

621
import org.slf4j.Logger;
722
import org.slf4j.LoggerFactory;
@@ -13,20 +28,24 @@ public class Thing {
1328
private String type;
1429
private String id;
1530
private String description;
16-
private List<Channel> channelList;
31+
private Map<String,Channel> channelMap = new HashMap<String,Channel>();
1732

33+
public List<Channel> getChannelMap() {
34+
return new ArrayList<Channel>(channelMap.values());
35+
}
36+
1837
Thing(String id, String type) {
1938
logger.trace("Init type: '{}' id: '{}'", type, id );
20-
channelList = new ArrayList<Channel>();
39+
channelMap.clear();
2140
this.type = type;
2241
this.id = id;
2342
this.description = null;;
2443
}
2544

2645
Thing(Thing thing) {
2746
logger.trace("Init type: '{}' id: '{}'", thing.type, thing.id );
28-
channelList = new ArrayList<Channel>();
29-
this.channelList = thing.channelList;
47+
channelMap.clear();
48+
this.channelMap = thing.channelMap;
3049
this.type = thing.type;
3150
this.id = thing.id;
3251
this.description = thing.description;
@@ -57,16 +76,12 @@ public void setDescription(String description) {
5776
this.description = description;
5877
}
5978

60-
public List<Channel> getChannelList() {
61-
return channelList;
62-
}
63-
64-
public void setChannelList(List<Channel> channelList) {
65-
this.channelList = channelList;
79+
public void addChannel(Channel channel) {
80+
channelMap.put(channel.getId(), new Channel(channel));
6681
}
6782

68-
public void addChannel(Channel channel) {
69-
channelList.add(new Channel(channel));
83+
public Channel getChannel(String id) {
84+
return channelMap.get(id);
7085
}
7186

7287

‎src/main/java/de/myandres/optolink/Viessmann300.java

+66-5
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,75 @@ public synchronized int getData (byte[] buffer, int address, int length) {
7070
} }
7171
}
7272
log.error("!!!!!!!!!!!!!!!! Trouble with communication to OptolinkInterface !!!!!!!!" );
73-
log.error("!!!!!!!!!!!!!!!! Pleace check hardware !!!!!!!!" );
73+
log.error("Try to start session again .... " );
74+
startSession();
75+
log.error("If error continues pleace check hardware !!!!!!!!" );
7476

7577
return -1; // UPS
7678
}
7779

7880
@Override
79-
public void setData(byte[] buffer, int address, int length) {
80-
// TODO Auto-generated method stub
81+
public synchronized int setData(byte[] buffer, int address, int length, int value) {
82+
byte[] localBuffer = new byte[16];
83+
int returNumberOfBytes;
84+
85+
for (int i=0; i<2; i++) {
86+
87+
log.debug(String.format("Set Data for address %04X .... ", address));
88+
89+
// construct TxD
90+
91+
localBuffer[0] = 0x00; // Request
92+
localBuffer[1] = 0x02; // write Data
93+
localBuffer[2] = (byte)(address >> 8); // upper Byte of address
94+
localBuffer[3] = (byte)(address & 0xff); // lower Byte of address
95+
localBuffer[4] = (byte)length; // number bytes
96+
switch (length) {
97+
case 1: localBuffer[5] = (byte)(value & 0xff);
98+
break;
99+
case 2: localBuffer[5] = (byte)(value >> 8);
100+
localBuffer[6] = (byte)(value & 0xff);
101+
break;
102+
case 4: localBuffer[5] = (byte)(value >> 24);
103+
localBuffer[6] = (byte)(value >> 16);
104+
localBuffer[7] = (byte)(value >> 8);
105+
localBuffer[8] = (byte)(value & 0xff);
106+
break;
107+
}
108+
109+
if ( transmit(localBuffer,5+length)) {; // send Buffer
110+
111+
// RxD
112+
returNumberOfBytes = resive(localBuffer); // read answer
113+
114+
if (returNumberOfBytes > 0) {
115+
116+
// check RxD
117+
int returnAddress;
118+
if (localBuffer[0] == 0x03)
119+
log.error("Answer Byte is 0x03: Return Error(Wrong Adress,maybe)");
120+
if (localBuffer[0] != 0x01)
121+
log.error("Answer Byte (0x01) expect, but: 0x{} resived",
122+
String.format("%02X", localBuffer[0]));
123+
if (localBuffer[1] != 0x02)
124+
log.error("Data Write Byte (0x02) expect, but: 0x{} resived",
125+
String.format("%02X",buffer[1]));
126+
returnAddress = ((localBuffer[2] & 0xFF) << 8) + ((int)localBuffer[3] & 0xFF); // Address
127+
if (returnAddress != address)
128+
log.error(String.format("Adress (%04X) expect, but: %04X resived", address, returnAddress));
129+
for (int j=0;j<localBuffer[4];j++) buffer[j] =localBuffer[j+5]; // copy Result
130+
log.debug(String.format("Data for address %04X got ", address));
131+
return (localBuffer[4]); // buffer length
132+
}
133+
}
134+
}
135+
log.error("!!!!!!!!!!!!!!!! Trouble with communication to OptolinkInterface !!!!!!!!" );
136+
log.error("Try to start session again .... " );
137+
startSession();
138+
log.error("If error continues pleace check hardware !!!!!!!!" );
139+
140+
return -1; // UPS
141+
81142

82143
}
83144

@@ -108,7 +169,7 @@ private synchronized void startSession() {
108169
log.trace("Open Session to Optolink [ACK] failed");
109170
}
110171
log.error("!!! Trouble with communication to OptolinkInterface !!!" );
111-
log.error("!!! Pleace check hardware !!!" );
172+
log.error("!!! Please check hardware !!!" );
112173
}
113174

114175
public synchronized void stopSession() {
@@ -181,7 +242,7 @@ private synchronized boolean transmit(byte[] buffer, int len) {
181242
for (int i=0;i<len;i++) checksum+=buffer[i];
182243

183244
optolinkInterface.write(0x41); // Telegram start byte
184-
optolinkInterface.write(len); // nuber of byte
245+
optolinkInterface.write(len); // number of byte
185246

186247
for (int i=0; i<len; i++) { // send data
187248
optolinkInterface.write(buffer[i]);
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,128 @@
1-
/*******************************************************************************
2-
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3-
*
4-
* All rights reserved. This program and the accompanying materials
5-
* are made available under the terms of the GNU Lesser General Public License
6-
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7-
* http://www.gnu.org/licenses/lgpl-3.0.html
8-
*
9-
* This library is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
* Lesser General Public License for more details.
13-
*******************************************************************************/
14-
package de.myandres.optolink;
15-
16-
import java.util.Locale;
17-
18-
import org.slf4j.Logger;
19-
import org.slf4j.LoggerFactory;
20-
21-
public class ViessmannHandler {
22-
static Logger log = LoggerFactory.getLogger(ViessmannHandler.class);
23-
private ViessmannProtocol viessmannProtocol;
24-
@SuppressWarnings("unused")
25-
private OptolinkInterface optolinkInterface;
26-
27-
ViessmannHandler(String interfaceProtocol, OptolinkInterface optolinkInterface) throws Exception {
28-
log.debug("Init Handler for Protokoll {} ...", interfaceProtocol);
29-
switch (interfaceProtocol) {
30-
case "300":
31-
viessmannProtocol = new Viessmann300(optolinkInterface);
32-
break;
33-
case "KW":
34-
viessmannProtocol = new ViessmannKW(optolinkInterface);
35-
break;
36-
default:
37-
log.error("Unknown Protokol: {}", interfaceProtocol);
38-
throw new RuntimeException();
39-
}
40-
log.trace("Handler for Class {} initalisiert", viessmannProtocol.getClass().getName());
41-
42-
log.info("Handler for Protocol {} initalisiert", interfaceProtocol);
43-
}
44-
45-
public synchronized void close() {
46-
viessmannProtocol.close();
47-
}
48-
49-
50-
public synchronized String setValue(Telegram t, String value) {
51-
52-
log.info("Set not implemented jet");
53-
return null;
54-
55-
}
56-
57-
58-
59-
public synchronized String getValue(Telegram telegram) {
60-
byte [] buffer = new byte[16];
61-
long result=0;
62-
63-
int resultLength=viessmannProtocol.getData(buffer,telegram.getAddress(), telegram.getLength());
64-
if (log.isTraceEnabled()) {
65-
log.trace("Number of Bytes: {}", resultLength);
66-
for (int i=0; i<resultLength; i++) log.trace("[{}] {} ",i,buffer[i]);
67-
}
68-
switch (telegram.getType()) {
69-
case Telegram.BOOLEAN:
70-
if (buffer[0] == 0) return "OFF";
71-
return "ON";
72-
case Telegram.DATE:
73-
//TODO check it
74-
return String.format("%02x.%02x.%02x%02x %02x:%02x:%02x",
75-
buffer[3],buffer[2],buffer[0],buffer[1],buffer[5],buffer[6],buffer[7]) ;
76-
case Telegram.BYTE:
77-
result = buffer[0];
78-
break;
79-
case Telegram.UBYTE:
80-
result = 0xFF & buffer[0];
81-
break;
82-
case Telegram.SHORT:
83-
result = ((long)(buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
84-
break;
85-
case Telegram.USHORT:
86-
result = ((long)(0xFF & buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
87-
break;
88-
case Telegram.INT:
89-
result = ((long)(buffer[3]))*0x1000000 + ((long)(0xFF & buffer[2]))*0x10000 + ((long)(0xFF & buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
90-
break;
91-
case Telegram.UINT:
92-
result = ((long)(0xFF & buffer[3]))*0x1000000 + ((long)(0xFF & buffer[2]))*0x10000 + ((long)(0xFF & buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
93-
break;
94-
}
95-
if (telegram.getDivider() !=1 )
96-
return String.format(Locale.US,"%.2f", (float)result / telegram.getDivider());
97-
else return String.format("%d", result);
98-
99-
}
100-
101-
102-
}
1+
/*******************************************************************************
2+
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the GNU Lesser General Public License
6+
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7+
* http://www.gnu.org/licenses/lgpl-3.0.html
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*******************************************************************************/
14+
package de.myandres.optolink;
15+
16+
import java.util.Locale;
17+
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
21+
public class ViessmannHandler {
22+
static Logger log = LoggerFactory.getLogger(ViessmannHandler.class);
23+
private ViessmannProtocol viessmannProtocol;
24+
@SuppressWarnings("unused")
25+
private OptolinkInterface optolinkInterface;
26+
27+
ViessmannHandler(String interfaceProtocol, OptolinkInterface optolinkInterface) throws Exception {
28+
29+
log.debug("Init Handler for Protokoll {} ...", interfaceProtocol);
30+
switch (interfaceProtocol) {
31+
case "300":
32+
viessmannProtocol = new Viessmann300(optolinkInterface);
33+
break;
34+
case "KW":
35+
viessmannProtocol = new ViessmannKW(optolinkInterface);
36+
break;
37+
default:
38+
log.error("Unknown Protokol: {}", interfaceProtocol);
39+
throw new RuntimeException();
40+
}
41+
log.trace("Handler for Class {} initalisiert", viessmannProtocol.getClass().getName());
42+
43+
log.info("Handler for Protocol {} initalisiert", interfaceProtocol);
44+
}
45+
46+
public synchronized void close() {
47+
viessmannProtocol.close();
48+
}
49+
50+
51+
public synchronized String setValue(Telegram telegram, String value) {
52+
byte [] buffer = new byte[16];
53+
int locValue;
54+
55+
switch (telegram.getType()) {
56+
case Telegram.BOOLEAN:
57+
if (value.equals("ON")) locValue=1; else locValue=0;
58+
break;
59+
60+
case Telegram.DATE:
61+
log.error("Updat of Date not implemented");
62+
return null ;
63+
default : float fl = (new Float(value)) * telegram.getDivider();
64+
locValue = (int) fl;
65+
break;
66+
}
67+
int resultLength = viessmannProtocol.setData(buffer, telegram.getAddress() , telegram.getLength(), locValue);
68+
69+
if (resultLength == 0) return null;
70+
else return formatValue(buffer, telegram.getType(), telegram.getDivider());
71+
72+
}
73+
74+
75+
76+
public synchronized String getValue(Telegram telegram) {
77+
byte [] buffer = new byte[16];
78+
long result=0;
79+
80+
int resultLength=viessmannProtocol.getData(buffer,telegram.getAddress(), telegram.getLength());
81+
if (log.isTraceEnabled()) {
82+
log.trace("Number of Bytes: {}", resultLength);
83+
for (int i=0; i<resultLength; i++) log.trace("[{}] {} ",i,buffer[i]);
84+
}
85+
return formatValue(buffer, telegram.getType(), telegram.getDivider());
86+
87+
}
88+
89+
private String formatValue(byte[] buffer, byte type, short divider) {
90+
91+
log.trace("Formating....");
92+
long result = 0;
93+
switch (type) {
94+
case Telegram.BOOLEAN:
95+
if (buffer[0] == 0) return "OFF";
96+
return "ON";
97+
case Telegram.DATE:
98+
//TODO check it
99+
return String.format("%02x.%02x.%02x%02x %02x:%02x:%02x",
100+
buffer[3],buffer[2],buffer[0],buffer[1],buffer[5],buffer[6],buffer[7]) ;
101+
case Telegram.BYTE:
102+
result = buffer[0];
103+
break;
104+
case Telegram.UBYTE:
105+
result = 0xFF & buffer[0];
106+
break;
107+
case Telegram.SHORT:
108+
result = ((long)(buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
109+
break;
110+
case Telegram.USHORT:
111+
result = ((long)(0xFF & buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
112+
break;
113+
case Telegram.INT:
114+
result = ((long)(buffer[3]))*0x1000000 + ((long)(0xFF & buffer[2]))*0x10000 + ((long)(0xFF & buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
115+
break;
116+
case Telegram.UINT:
117+
result = ((long)(0xFF & buffer[3]))*0x1000000 + ((long)(0xFF & buffer[2]))*0x10000 + ((long)(0xFF & buffer[1]))*0x100 + (long)(0xFF & buffer[0]);
118+
break;
119+
}
120+
if (divider !=1 )
121+
return String.format(Locale.US,"%.2f", (float)result / divider);
122+
else return String.format("%d", result);
123+
124+
125+
}
126+
127+
128+
}
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,97 @@
1-
/*******************************************************************************
2-
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3-
*
4-
* All rights reserved. This program and the accompanying materials
5-
* are made available under the terms of the GNU Lesser General Public License
6-
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7-
* http://www.gnu.org/licenses/lgpl-3.0.html
8-
*
9-
* This library is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
* Lesser General Public License for more details.
13-
*******************************************************************************/
14-
package de.myandres.optolink;
15-
16-
import org.slf4j.Logger;
17-
import org.slf4j.LoggerFactory;
18-
19-
public class ViessmannKW implements ViessmannProtocol {
20-
21-
22-
static Logger log = LoggerFactory.getLogger(ViessmannKW.class);
23-
24-
private OptolinkInterface optolinkInterface;
25-
26-
27-
ViessmannKW(OptolinkInterface optolinkInterface) {
28-
log.trace("Start Session for Protokoll 'KW' ....");
29-
this.optolinkInterface = optolinkInterface;
30-
log.trace("Start Session for Protokoll 'KW' started");
31-
}
32-
33-
34-
@Override
35-
public int getData(byte[] buffer, int address, int length) {
36-
37-
int j=0;
38-
optolinkInterface.flush();
39-
while (optolinkInterface.read() != 0x05 ) { // Wait for 0x05
40-
if (j++ > 10) {
41-
log.error("Can't send Data to OptolinkInterface, missing 0x05");
42-
log.error("!!!!!!!!!!!!!!!! Trouble with communication to OptolinkInterface !!!!!!!!" );
43-
log.error("!!!!!!!!!!!!!!!! Pleace check hardware !!!!!!!!" );
44-
return -1;
45-
}
46-
47-
}
48-
optolinkInterface.write(0x01); // Anwser to 0x05
49-
optolinkInterface.write(0xF7); // Read Data
50-
optolinkInterface.write((byte)(address >> 8)); // upper Byte of address
51-
optolinkInterface.write((byte)(address & 0xff)); // lower Byte of address
52-
optolinkInterface.write((byte)length); // number of expected bytes
53-
54-
for (int i=0; i<length; i++) {
55-
buffer[i] = (byte) optolinkInterface.read();
56-
}
57-
return length;
58-
}
59-
60-
61-
@Override
62-
public void setData(byte[] buffer, int address, int length) {
63-
// TODO Auto-generated method stub
64-
65-
}
66-
67-
68-
@Override
69-
public void close() {
70-
// nothing to do
71-
72-
}
73-
74-
}
1+
/*******************************************************************************
2+
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the GNU Lesser General Public License
6+
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7+
* http://www.gnu.org/licenses/lgpl-3.0.html
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*******************************************************************************/
14+
package de.myandres.optolink;
15+
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
public class ViessmannKW implements ViessmannProtocol {
20+
21+
22+
static Logger log = LoggerFactory.getLogger(ViessmannKW.class);
23+
24+
private OptolinkInterface optolinkInterface;
25+
26+
27+
ViessmannKW(OptolinkInterface optolinkInterface) {
28+
log.trace("Start Session for Protokoll 'KW' ....");
29+
this.optolinkInterface = optolinkInterface;
30+
log.trace("Start Session for Protokoll 'KW' started");
31+
}
32+
33+
34+
@Override
35+
public int getData(byte[] buffer, int address, int length) {
36+
37+
int j=0;
38+
optolinkInterface.flush();
39+
while (optolinkInterface.read() != 0x05 ) { // Wait for 0x05
40+
if (j++ > 10) {
41+
log.error("Can't send Data to OptolinkInterface, missing 0x05");
42+
log.error("!!!!!!!!!!!!!!!! Trouble with communication to OptolinkInterface !!!!!!!!" );
43+
log.error("!!!!!!!!!!!!!!!! Pleace check hardware !!!!!!!!" );
44+
return -1;
45+
}
46+
47+
}
48+
optolinkInterface.write(0x01); // Anwser to 0x05
49+
optolinkInterface.write(0xF7); // Read Data
50+
optolinkInterface.write((byte)(address >> 8)); // upper Byte of address
51+
optolinkInterface.write((byte)(address & 0xff)); // lower Byte of address
52+
optolinkInterface.write((byte)length); // number of expected bytes
53+
54+
for (int i=0; i<length; i++) {
55+
buffer[i] = (byte) optolinkInterface.read();
56+
}
57+
return length;
58+
}
59+
60+
61+
62+
@Override
63+
public void close() {
64+
// nothing to do
65+
66+
}
67+
68+
69+
@Override
70+
public int setData(byte[] buffer, int address, int length, int value) {
71+
// TODO Test it
72+
73+
int j=0;
74+
optolinkInterface.flush();
75+
while (optolinkInterface.read() != 0x05 ) { // Wait for 0x05
76+
if (j++ > 10) {
77+
log.error("Can't send Data to OptolinkInterface, missing 0x05");
78+
log.error("!!!!!!!!!!!!!!!! Trouble with communication to OptolinkInterface !!!!!!!!" );
79+
log.error("!!!!!!!!!!!!!!!! Pleace check hardware !!!!!!!!" );
80+
return -1;
81+
}
82+
83+
}
84+
optolinkInterface.write(0x01); // Anwser to 0x05
85+
optolinkInterface.write(0xF4); // write Data
86+
optolinkInterface.write((byte)(address >> 8)); // upper Byte of address
87+
optolinkInterface.write((byte)(address & 0xff)); // lower Byte of address
88+
optolinkInterface.write((byte)length); // number of expected bytes
89+
90+
for (int i=0; i<length; i++) {
91+
buffer[i] = (byte) optolinkInterface.read();
92+
}
93+
return length;
94+
95+
}
96+
97+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
/*******************************************************************************
2-
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3-
*
4-
* All rights reserved. This program and the accompanying materials
5-
* are made available under the terms of the GNU Lesser General Public License
6-
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7-
* http://www.gnu.org/licenses/lgpl-3.0.html
8-
*
9-
* This library is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
* Lesser General Public License for more details.
13-
*******************************************************************************/
14-
package de.myandres.optolink;
15-
16-
public interface ViessmannProtocol {
17-
18-
public int getData(byte[] buffer, int address, int length);
19-
public void setData(byte[] buffer, int address, int length);
20-
void close();
21-
22-
23-
}
1+
/*******************************************************************************
2+
* Copyright (c) 2015, Stefan Andres. All rights reserved.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the GNU Lesser General Public License
6+
* (LGPL) version 3.0 which accompanies this distribution, and is available at
7+
* http://www.gnu.org/licenses/lgpl-3.0.html
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*******************************************************************************/
14+
package de.myandres.optolink;
15+
16+
public interface ViessmannProtocol {
17+
18+
public int getData(byte[] buffer, int address, int length);
19+
void close();
20+
int setData(byte[] buffer, int address, int length, int value);
21+
22+
23+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
To start the program at boottime:
2+
3+
1.) edit optolink.init.d (USER & HOME)
4+
5+
2.) sudo cp optolink.init.d /etc/init.d/optolink
6+
7+
3.) sudo 755 /etc/init.d/optolink
8+
9+
4.) sudo update-rc-d optolink defaults
10+
11+
12+
now optolink adapter going to start at boottime.

‎src/main/resources/logback.xml

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<configuration scan="true" scanPeriod="15 seconds">
3-
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4-
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
5-
<pattern>%d{HH:mm:ss.SSS} [%thread] %level %logger{36} - %msg%n</pattern>
6-
</encoder>
7-
</appender>
8-
9-
<root level="TRACE">
10-
<appender-ref ref="CONSOLE" />
11-
</root>
12-
</configuration>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds">
3+
4+
5+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6+
<file>logs/optolink.log</file>
7+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8+
<!-- weekly rollover and archiving -->
9+
<fileNamePattern>logs/optolink-%d{yyyy-ww}.log.zip</fileNamePattern>
10+
<!-- maximum number of archive files to keep -->
11+
<maxHistory>12</maxHistory>
12+
</rollingPolicy>
13+
<encoder>
14+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
15+
</encoder>
16+
</appender>
17+
18+
19+
<logger name="de.myandres" level="INFO">
20+
<appender-ref ref="FILE" />
21+
</logger>
22+
23+
24+
</configuration>

‎src/main/resources/logback_debug.xml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds">
3+
4+
5+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6+
<file>logs/optolink_debug.log</file>
7+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8+
<!-- weekly rollover and archiving -->
9+
<fileNamePattern>logs/optolink-%d{yyyy-ww}.log.zip</fileNamePattern>
10+
<!-- maximum number of archive files to keep -->
11+
<maxHistory>12</maxHistory>
12+
</rollingPolicy>
13+
<encoder>
14+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
15+
</encoder>
16+
</appender>
17+
18+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
19+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
20+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
21+
</encoder>
22+
</appender>
23+
24+
<logger name="de.myandres" level="INFO">
25+
<appender-ref ref="FILE" />
26+
</logger>
27+
28+
<logger name="de.myandres" level="DEBUG">
29+
<appender-ref ref="CONSOLE" />
30+
</logger>
31+
32+
33+
</configuration>

‎src/main/resources/logback_trace.xml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds">
3+
4+
5+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6+
<file>logs/optolink_trace.log</file>
7+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8+
<!-- weekly rollover and archiving -->
9+
<fileNamePattern>logs/optolink-%d{yyyy-ww}.log.zip</fileNamePattern>
10+
<!-- maximum number of archive files to keep -->
11+
<maxHistory>12</maxHistory>
12+
</rollingPolicy>
13+
<encoder>
14+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
15+
</encoder>
16+
</appender>
17+
18+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
19+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
20+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %M - %msg%n</pattern>
21+
</encoder>
22+
</appender>
23+
24+
<logger name="de.myandres" level="INFO">
25+
<appender-ref ref="FILE" />
26+
</logger>
27+
28+
<logger name="de.myandres" level="TRACE">
29+
<appender-ref ref="CONSOLE" />
30+
</logger>
31+
32+
33+
</configuration>

‎src/main/resources/optolink.init.d

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
# Start/stop the optolink
3+
#
4+
### BEGIN INIT INFO
5+
# Provides: optolink
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop:
8+
# Short-Description: Regular background program processing Viessmann optolink adapter
9+
### END INIT INFO
10+
11+
HOME=/home/pi/optolink
12+
USER=pi
13+
14+
PATH=/bin:/usr/bin:/sbin:/usr/sbin
15+
16+
test -f $HOME/start.sh || exit 0
17+
18+
19+
20+
case "$1" in
21+
start) cd $HOME
22+
sudo -u $USER ./start.sh &
23+
;;
24+
stop) cd $HOME
25+
./stop.sh
26+
;;
27+
restart) log_daemon_msg "Restarting periodic command scheduler" "cron"
28+
$0 stop
29+
$0 start
30+
;;
31+
status)
32+
exit 0
33+
;;
34+
*) log_action_msg "Usage: /etc/init.d/cron {start|stop|status|restart}"
35+
exit 2
36+
;;
37+
esac
38+
exit 0

‎src/main/resources/optolink.xml

+100-39
Original file line numberDiff line numberDiff line change
@@ -2,129 +2,190 @@
22
<!--
33
Mapping for vitotronic/optolink addresses to openhab things.
44
5-
type = *none
5+
channel id starts with '*' :
66
- will not send to openhab but it is posible to ask for this ID on the interface.
77
- is not implemented in openhab
8+
9+
Telegram types:
10+
BOOLEAN = 1 Byte -> boolean
11+
BYTE = 1 Byte -> short
12+
UBYTE = 1 Byte -> short
13+
SHORT = 2 Byte -> int
14+
USHORT = 2 Byte -> int
15+
INT = 4 byte -> long
16+
UINT = 4 Byte -> long
17+
DATE = 8 Byte -> date (read only)
18+
19+
For more information about addresses and types see: http://openv.wikispaces.com/
820
921
-->
1022

1123

1224

1325
<optolink device="2033" id="300P" protocol="300">
1426

15-
<adapterID>TEST</adapterID> <!-- Unique ID on the Network-->
27+
<adapterID>VITOLIGNO</adapterID> <!-- Unique ID on the Network-->
1628
<tty>/dev/ttyAMA0</tty> <!-- serial port of the optolink adapter-->
1729
<ttytimeout>2000</ttytimeout> <!-- milliseconds for reading timeout tty -->
18-
<port>31113</port> <!-- port for incomming communication. See also: http://www.iana.org -->
30+
<port>31113</port> <!-- port for incoming communication. See also: http://www.iana.org -->
1931

2032
<!-- Addressen die von diesem 'device' unterst�tzt werden -->
21-
<thing type="heating" id="300p">
33+
34+
<thing type="heating" id="300P">
2235
<description>Viessmann Vitoligno 300P</description>
23-
<channel type="systemid" id="deviceId">
36+
<channel id="systemid">
2437
<description>System ID</description>
2538
<telegram address="00F8" type="short"/>
2639
</channel>
27-
<channel type="systemtime" id="systemtime">
40+
<channel id="systemtime">
2841
<description>System Date and Time</description>
2942
<telegram address="088E" type="date" />
3043
</channel>
31-
<channel type="temperature" id="outside">
44+
<channel id="outside_temp">
3245
<description>Outside Temperature</description>
3346
<telegram address="0800" type="short" divider="10"/>
3447
</channel>
48+
<channel id="boiler_temp">
49+
<description>The furnace temperature of the burner boiler</description>
50+
<telegram address="A202" type="short" divider="100"/>
51+
</channel>
3552
</thing>
3653
<!--# Puffer-StorageTank -->
3754
<thing type="storagetank" id="storagetank">
3855
<description>Hot Water Storage Tank an Buffer</description>
39-
<channel type="temperature" id="hotwater">
56+
<channel id="hotwater_temp">
4057
<description>Hot water temperatur on top of the buffer.</description>
4158
<telegram address="0806" type="short" divider="10"/>
4259
</channel>
43-
<channel type="temperature" id="middle">
60+
<channel id="middle_temp">
4461
<description>Temperature in the middle of the buffer</description>
4562
<telegram address="0810" type="short" divider="10"/>
4663
</channel>
47-
<channel type="temperature" id="bottom">
64+
<channel id="bottom_temp">
4865
<description>Temperature on the bottom of the buffer</description>
4966
<telegram address="0804" type="short" divider="10"/>
5067
</channel>
51-
<channel type="pump" id="hotwater">
68+
<channel id="circuitpump">
5269
<description>Cirulation Pump for Hot Water</description>
5370
<telegram address="0846" type="boolean" />
5471
</channel>
55-
<channel type="pump" id="load">
72+
<channel id="loadpump">
5673
<description>Loading Pump for Buffer</description>
5774
<telegram address="0845" type="boolean" />
5875
</channel>
5976
</thing>
6077
<!--# Kessel -->
6178

6279
<!--# Burner -->
63-
<thing type="burner" id="pelletburner">
80+
<thing type="pelletburner" id="pelletburner">
6481
<description>Burner/Fireplace</description>
65-
<channel type="temperature" id="furnace">
66-
<description>The furnace temperature of the burner</description>
67-
<telegram address="A202" type="short" divider="100"/>
68-
</channel>
69-
<channel type="power" id="Power">
82+
<channel id="power">
7083
<description>The furnace Power in %</description>
7184
<telegram address="A305" type="ubyte" divider="2"/>
7285
</channel>
73-
<channel type="*none" id="stat">
86+
<channel id="*stat">
7487
<!-- Brennerstatus ist noch nicht klar Addresse noch gesucht -->
7588
<description>State of Burner </description>
7689
<telegram address="0962" type="short" />
7790
</channel>
78-
<channel type="counter" id="starts">
91+
<channel id="starts">
7992
<description>Counts the number of starts sience first start of heating. </description>
8093
<telegram address="088A" type="ushort"/>
8194
</channel>
82-
<channel type="time" id="ontime">
95+
<channel id="ontime">
8396
<description>On time of the burner sience first start of heating. </description>
8497
<telegram address="08A7" type="uint" divider="3600"/>
8598
</channel>
86-
<channel type="consumtion" id="consumtion">
99+
<channel id="consumedpellets">
87100
<description>Consumed Pellets since start of heating in t. </description>
88101
<telegram address="08B0" type="uint" divider="1000"/>
89102
</channel>
90103
</thing>
91104
<!--# Heizkreis 1 -->
92-
<thing type="circuit" id="ciruit1">
105+
<thing type="circuit" id="circuit1">
93106
<description>Heading Circuit of the first Floor.</description>
94-
<channel type="temperature" id="flow" >
107+
<channel id="flowtemperature" >
95108
<description>Flow temperature</description>
96109
<telegram address="2900" type="short" divider="10"/>
97110
</channel>
98-
<channel type="pump" id="pump">
111+
<channel id="pump">
99112
<description></description>
100113
<telegram address="2906" type="boolean" />
101114
</channel>
102-
<channel type="gradient" id="gradient">
115+
<channel id="operationmode" >
116+
<description>Party temperature.</description>
117+
<telegram address="2301" type="byte"/>
118+
</channel>
119+
<channel id="savemode">
120+
<description>The savemode.</description>
121+
<telegram address="2302" type="boolean"/>
122+
</channel>
123+
<channel id="partymode" >
124+
<description>Partymode.</description>
125+
<telegram address="2303" type="boolean"/>
126+
</channel>
127+
<channel id="party_temp" >
128+
<description>Party temperature.</description>
129+
<telegram address="2308" type="byte"/>
130+
</channel>
131+
<channel id="room_temp" >
132+
<description>Party temperature.</description>
133+
<telegram address="2306" type="byte"/>
134+
</channel>
135+
<channel id="save_temp" >
136+
<description>Save (Spar) temperature.</description>
137+
<telegram address="2307" type="byte"/>
138+
</channel>
139+
<channel id="gradient">
103140
<description>The gradient relativ to outseite temperature.</description>
104141
<telegram address="2305" type="byte" divider="10"/>
105142
</channel>
106-
<channel type="niveau" id="niveau" >
143+
<channel id="niveau" >
107144
<description>The niveau relativ to outseite temperature.</description>
108145
<telegram address="2304" type="byte"/>
109146
</channel>
110147
</thing>
111148

112149
<!--# Heizkreis 2 -->
113-
<thing type="circuit" id="ciruit2">
150+
<thing type="circuit" id="circuit2">
114151
<description>Heading Circuit of the first Floor.</description>
115-
<channel type="temperature" id="flow" >
152+
<channel id="flowtemperature" >
116153
<description>Flow temperature</description>
117154
<telegram address="3900" type="short" divider="10"/>
118155
</channel>
119-
<channel type="pump" id="pump">
156+
<channel id="pump">
120157
<description></description>
121158
<telegram address="3906" type="boolean" />
122159
</channel>
123-
<channel type="gradient" id="gradient">
160+
<channel id="operationmode" >
161+
<description>Operation mode (0,1,2,3,4).</description>
162+
<telegram address="3301" type="byte"/>
163+
</channel>
164+
<channel id="savemode">
165+
<description>The savemode.</description>
166+
<telegram address="3302" type="boolean"/>
167+
</channel>
168+
<channel id="partymode" >
169+
<description>Partymode.</description>
170+
<telegram address="3303" type="boolean"/>
171+
</channel>
172+
<channel id="party_temp" >
173+
<description>Party temperature.</description>
174+
<telegram address="3308" type="byte"/>
175+
</channel>
176+
<channel id="room_temp" >
177+
<description>Room temperature.</description>
178+
<telegram address="3306" type="byte"/>
179+
</channel>
180+
<channel id="save_temp" >
181+
<description>Save temperature.</description>
182+
<telegram address="3307" type="byte"/>
183+
</channel>
184+
<channel id="gradient">
124185
<description>The gradient relativ to outseite temperature.</description>
125186
<telegram address="3305" type="byte" divider="10"/>
126187
</channel>
127-
<channel type="niveau" id="niveau" >
188+
<channel id="niveau" >
128189
<description>The niveau relativ to outseite temperature.</description>
129190
<telegram address="3304" type="byte"/>
130191
</channel>
@@ -133,33 +194,33 @@ type = *none
133194
<!--# Solaranlage -->
134195
<thing type="solar" id="solar">
135196
<description>Thermo Solar System.</description>
136-
<channel type="temperature" id="collector">
197+
<channel id="collector_temp">
137198
<description>Collector temperature.</description>
138199
<telegram address="6564" length="2" type="short" divider="10"/>
139200
</channel>
140-
<channel type="temperature" id="storagetank">
201+
<channel id="storagetank_temp">
141202
<description>Temperatur of storage tank (same storage tank bottom)</description>
142203
<telegram address="6566" length="2" type="short" divider="10"/>
143204
</channel>
144-
<channel type="pump" id="load">
205+
<channel id="load">
145206
<description>Pump to load the storage tank from the solar panel.</description>
146207
<telegram address="6552" length="1" type="boolean" />
147208
</channel>
148-
<channel type="*none" id="power">
209+
<channel id="*power">
149210
<!-- unclear -->
150211
<description>Maybe the power of the solar pump - TODO check</description>
151212
<telegram address="6553" type="byte"/>
152213
</channel>
153-
<channel type="*none" id="loadstat">
214+
<channel id="*loadstat">
154215
<!-- unclear -->
155216
<description></description>
156217
<telegram address="6551" type="boolean" />
157218
</channel>
158-
<channel type="time" id="ontime">
219+
<channel id="ontime">
159220
<description>On time of the solar pump in hours.</description>
160221
<telegram address="6568" type="ushort"/>
161222
</channel>
162-
<channel type="consumtion" id="power" >
223+
<channel id="producedheat" >
163224
<description>Consumed power from the sun in KW. </description>
164225
<telegram address="6560" type="uint"/>
165226
</channel>

‎src/main/resources/start.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
PID=./optolink.pid
4+
5+
6+
prog_arg="-Dlogback.configurationFile=lib/logback.xml"
7+
prog_arg="${prog_arg} -Djava.library.path=/usr/lib/jni"
8+
prog_arg="${prog_arg} -Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0"
9+
10+
11+
java $prog_arg -jar lib/optolink-jar-with-dependencies.jar >/dev/null 2>&1 &
12+
echo $! >$PID
13+
14+
echo "Optolink adapter started"

‎src/main/resources/start_debug.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
4+
prog_arg="-Dlogback.configurationFile=conf/logback_debug.xml"
5+
prog_arg="${prog_arg} -Djava.library.path=/usr/lib/jni"
6+
prog_arg="${prog_arg} -Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0"
7+
8+
9+
java $prog_arg -jar lib/optolink-jar-with-dependencies.jar

‎src/main/resources/start_trace.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
4+
prog_arg="-Dlogback.configurationFile=conf/logback_trace.xml"
5+
prog_arg="${prog_arg} -Djava.library.path=/usr/lib/jni"
6+
prog_arg="${prog_arg} -Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0"
7+
8+
9+
java $prog_arg -jar lib/optolink-jar-with-dependencies.jar

‎src/main/resources/stop.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
PID=./optolink.pid
4+
5+
6+
if [ -f $PID ]; then
7+
ps `cat $PID`
8+
if [ $? == 0 ]; then
9+
kill `cat $PID`
10+
echo "Optolink adapter killed"
11+
rm $PID
12+
else
13+
echo "Prozess not found"
14+
exit 1
15+
fi
16+
else
17+
echo "File ${PID} found"
18+
exit 1
19+
fi

0 commit comments

Comments
 (0)
Please sign in to comment.