Skip to content

Commit 5c72aa5

Browse files
committed
Stable Alpha
1 parent f3bb1f7 commit 5c72aa5

File tree

7 files changed

+224
-219
lines changed

7 files changed

+224
-219
lines changed

optolink.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type = *none
1111

1212
<optolink device="2033" id="300P" protocol="300">
1313

14-
<adapterID>test</adapterID> <!-- Unique ID on the Network-->
14+
<adapterID>TEST</adapterID> <!-- Unique ID on the Network-->
1515
<tty>/dev/ttyAMA0</tty> <!-- serial port of the optolink adapter-->
1616
<ttytimeout>2000</ttytimeout> <!-- milliseconds for reading timeout tty -->
1717
<port>31113</port> <!-- port for incomming communication. See also: http://www.iana.org -->

src/main/java/de/myandres/optolink/BroadcastListner.java

+7-23
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,28 @@
1313
*******************************************************************************/
1414
package de.myandres.optolink;
1515

16-
import java.io.IOException;
1716
import java.net.DatagramPacket;
1817
import java.net.DatagramSocket;
1918
import java.net.InetAddress;
20-
import java.net.SocketException;
21-
2219
import org.slf4j.Logger;
2320
import org.slf4j.LoggerFactory;
2421

2522
public class BroadcastListner implements Runnable {
2623

2724
static Logger log = LoggerFactory.getLogger(BroadcastListner.class);
2825

29-
static String BROADCAST_MESSAGE = "@@@@VITOTRONIC@@@@";
26+
static final String BROADCAST_MESSAGE = "@@@@VITOTRONIC@@@@/";
3027
int port;
31-
boolean isConnect;
3228
String connectedIP;
29+
String adapterID;
3330

3431

3532

36-
BroadcastListner(int port) {
33+
BroadcastListner(int port, String adapterID) {
3734
log.debug("Init Broadcast Listener on Port", port);
3835
this.port = port;
39-
isConnect = false;
4036
connectedIP = "";
41-
}
42-
43-
public void connect(String connectedIP) {
44-
this.connectedIP = connectedIP;
45-
isConnect = true;
46-
}
47-
48-
public void disconnect() {
49-
this.connectedIP = "";
50-
isConnect = false;
37+
this.adapterID =adapterID;
5138
}
5239

5340

@@ -78,13 +65,10 @@ public void run() {
7865
remoteIPAddress = resivedPacket.getAddress();
7966
log.debug("From Host: {}",remoteIPAddress.toString());
8067

81-
if (str.startsWith(BROADCAST_MESSAGE)) {
68+
if (str.startsWith(BROADCAST_MESSAGE+adapterID) ||
69+
str.startsWith(BROADCAST_MESSAGE+"*")) {
8270
// Someone calls me
83-
if (!isConnect) {
84-
str = BROADCAST_MESSAGE + "[WAIT] CONNECTION";
85-
} else {
86-
str = BROADCAST_MESSAGE + "[BUSY] BY " + connectedIP;
87-
}
71+
str = BROADCAST_MESSAGE + "/"+adapterID;
8872
byteArray = str.getBytes();
8973
DatagramPacket sendPacket = new DatagramPacket(byteArray,
9074
byteArray.length, remoteIPAddress, remotePort);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public class Config {
6565
// start parser
6666
log.debug("Start parsing");
6767
xmlReader.parse(inputSource);
68-
log.info("{} Telegram's are parsed", thingList.size());
68+
log.info("{} Things are parsed", thingList.size());
6969
}
7070

7171

7272
public List<Thing> getThingList() {
7373
return thingList;
7474
}
7575

76-
public void addThing(Thing thing) {
76+
private void addThing(Thing thing) {
7777
log.trace("Add thing id: {}", thing.getId());
7878
thingList.add(new Thing(thing));
7979
}

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

+49-70
Original file line numberDiff line numberDiff line change
@@ -13,82 +13,61 @@
1313
*******************************************************************************/
1414
package de.myandres.optolink;
1515

16-
import java.awt.List;
17-
1816
import org.slf4j.Logger;
1917
import org.slf4j.LoggerFactory;
2018

2119
public class Main {
22-
23-
static Logger log = LoggerFactory.getLogger(Main.class);
24-
25-
// Central Classes, singular only!!
26-
static Config config;
27-
static ViessmannHandler viessmannHandler;
28-
static OptolinkInterface optolinkInterface;
29-
20+
21+
static Logger log = LoggerFactory.getLogger(Main.class);
22+
23+
// Central Classes, singular only!!
24+
static Config config;
25+
static ViessmannHandler viessmannHandler;
26+
static OptolinkInterface optolinkInterface;
27+
3028
public static void main(String[] args) {
3129
// TODO Auto-generated method stub
32-
33-
34-
log.info("Programm gestartet");
35-
36-
try {
37-
// TODO ExeptionHandling
38-
// Central Thread Data
39-
// config = new Config("src/main/resources/optolink.xml");
40-
config = new Config("optolink.xml");
41-
42-
43-
44-
// dataStore = new DataStore();
45-
// dataStore.setInterval(config.getInterval());
46-
47-
//Start TTY Handling for Optolink
48-
optolinkInterface = new OptolinkInterface(config.getTTY(),config.getTtyTimeOut());
49-
50-
51-
//Start ViessmannHandler
52-
53-
viessmannHandler = new ViessmannHandler(config.getProtocol(),optolinkInterface);
54-
55-
56-
57-
58-
} catch (Exception e) {
59-
log.error("Something is wrong not init", e);
60-
viessmannHandler.close();
61-
optolinkInterface.close();
62-
System.exit(1);
63-
}
64-
65-
// Install catcher for Kill Signal
66-
Runtime.getRuntime().addShutdownHook(new Thread()
67-
{
68-
@Override
69-
public void run()
70-
{
71-
viessmannHandler.close();
72-
optolinkInterface.close();
73-
log.info("Programm normal terminated by Signal (Kill)");
74-
}
75-
});
76-
77-
78-
try {
79-
80-
81-
82-
// Run SocketHandler
83-
SocketHandler socketHandler = new SocketHandler(config, viessmannHandler);
84-
socketHandler.start();
85-
86-
87-
88-
} catch (Exception e) {
89-
log.error("Programm abnormal terminated.", e);
90-
}
91-
30+
31+
log.info("Programm gestartet");
32+
33+
try {
34+
35+
// config = new Config("src/main/resources/optolink.xml");
36+
config = new Config("optolink.xml");
37+
38+
// Init TTY Handling for Optolink
39+
optolinkInterface = new OptolinkInterface(config.getTTY(), config.getTtyTimeOut());
40+
41+
// Init ViessmannHandler
42+
viessmannHandler = new ViessmannHandler(config.getProtocol(), optolinkInterface);
43+
44+
} catch (Exception e) {
45+
log.error("Something is wrong not init", e);
46+
viessmannHandler.close();
47+
optolinkInterface.close();
48+
System.exit(1);
49+
}
50+
51+
// Install catcher for Kill Signal
52+
Runtime.getRuntime().addShutdownHook(new Thread() {
53+
@Override
54+
public void run() {
55+
viessmannHandler.close();
56+
optolinkInterface.close();
57+
log.info("Programm normal terminated by Signal (Kill)");
58+
}
59+
});
60+
61+
try {
62+
63+
// Start SocketHandler
64+
SocketHandler socketHandler = new SocketHandler(config, viessmannHandler);
65+
socketHandler.start();
66+
67+
} catch (Exception e) {
68+
log.error("Programm abnormal terminated.", e);
69+
}
70+
9271
}
9372

9473
}

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

+4-18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
/*
1717
* Install a Socked Handler for ip communication
1818
*
19+
* Server can found via Broadcast
20+
* Server API Client can connect via TCP
21+
*
1922
*/
2023

2124
import java.io.BufferedReader;
@@ -49,7 +52,7 @@ public class SocketHandler {
4952

5053
public void start() {
5154

52-
BroadcastListner broadcastListner = new BroadcastListner(config.getPort());
55+
BroadcastListner broadcastListner = new BroadcastListner(config.getPort(), config.getAdapterID());
5356

5457
Thread broadcastListnerThread = new Thread(broadcastListner);
5558
broadcastListnerThread.setName("BcListner");
@@ -63,14 +66,11 @@ public void start() {
6366
log.info("Listen on port {} for connection", config.getPort());
6467
Socket socket = server.accept();
6568
log.info("Connection on port {} accept. Remote host {}", config.getPort(), socket.getRemoteSocketAddress());
66-
broadcastListner.connect(socket.getRemoteSocketAddress().toString());
6769
open(socket);
68-
broadcastListner.disconnect();
6970
}
7071

7172
catch (Exception e) {
7273
log.info("Connection on Socket {} rejected or closed by client", config.getPort());
73-
broadcastListner.disconnect();
7474
}
7575
}
7676
}
@@ -98,10 +98,8 @@ private void open(Socket socket) throws Exception {
9898
switch (command.toLowerCase()) {
9999

100100
case "list" : list(); break;
101-
case "getall" : getall(); break;
102101
case "get" : getThing(param); break;
103102
case "set" : set(); break;
104-
case "testme" : testMe(); break;
105103
case "exit" : exit=true; break;
106104
default: log.error("Unknown Client Command:", inStr[0]);
107105
}
@@ -112,18 +110,6 @@ private void open(Socket socket) throws Exception {
112110
}
113111

114112

115-
private void testMe() {
116-
// Listen wenn session closed
117-
118-
}
119-
120-
private void getall() {
121-
log.trace("Try to get Data for all Addresses");
122-
Telegram telegram;
123-
124-
}
125-
126-
127113

128114
private void set() {
129115
// TODO Auto-generated method stub

src/main/java/de/myandres/optolink/TestFormater.java

-50
This file was deleted.

0 commit comments

Comments
 (0)