Skip to content

Commit

Permalink
Stable Alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
steand committed Mar 2, 2015
1 parent f3bb1f7 commit 5c72aa5
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 219 deletions.
2 changes: 1 addition & 1 deletion optolink.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type = *none

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

<adapterID>test</adapterID> <!-- Unique ID on the Network-->
<adapterID>TEST</adapterID> <!-- Unique ID on the Network-->
<tty>/dev/ttyAMA0</tty> <!-- serial port of the optolink adapter-->
<ttytimeout>2000</ttytimeout> <!-- milliseconds for reading timeout tty -->
<port>31113</port> <!-- port for incomming communication. See also: http://www.iana.org -->
Expand Down
30 changes: 7 additions & 23 deletions src/main/java/de/myandres/optolink/BroadcastListner.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,28 @@
*******************************************************************************/
package de.myandres.optolink;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BroadcastListner implements Runnable {

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

static String BROADCAST_MESSAGE = "@@@@VITOTRONIC@@@@";
static final String BROADCAST_MESSAGE = "@@@@VITOTRONIC@@@@/";
int port;
boolean isConnect;
String connectedIP;
String adapterID;



BroadcastListner(int port) {
BroadcastListner(int port, String adapterID) {
log.debug("Init Broadcast Listener on Port", port);
this.port = port;
isConnect = false;
connectedIP = "";
}

public void connect(String connectedIP) {
this.connectedIP = connectedIP;
isConnect = true;
}

public void disconnect() {
this.connectedIP = "";
isConnect = false;
this.adapterID =adapterID;
}


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

if (str.startsWith(BROADCAST_MESSAGE)) {
if (str.startsWith(BROADCAST_MESSAGE+adapterID) ||
str.startsWith(BROADCAST_MESSAGE+"*")) {
// Someone calls me
if (!isConnect) {
str = BROADCAST_MESSAGE + "[WAIT] CONNECTION";
} else {
str = BROADCAST_MESSAGE + "[BUSY] BY " + connectedIP;
}
str = BROADCAST_MESSAGE + "/"+adapterID;
byteArray = str.getBytes();
DatagramPacket sendPacket = new DatagramPacket(byteArray,
byteArray.length, remoteIPAddress, remotePort);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/myandres/optolink/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public class Config {
// start parser
log.debug("Start parsing");
xmlReader.parse(inputSource);
log.info("{} Telegram's are parsed", thingList.size());
log.info("{} Things are parsed", thingList.size());
}


public List<Thing> getThingList() {
return thingList;
}

public void addThing(Thing thing) {
private void addThing(Thing thing) {
log.trace("Add thing id: {}", thing.getId());
thingList.add(new Thing(thing));
}
Expand Down
119 changes: 49 additions & 70 deletions src/main/java/de/myandres/optolink/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,82 +13,61 @@
*******************************************************************************/
package de.myandres.optolink;

import java.awt.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
static Logger log = LoggerFactory.getLogger(Main.class);
// Central Classes, singular only!!
static Config config;
static ViessmannHandler viessmannHandler;
static OptolinkInterface optolinkInterface;

static Logger log = LoggerFactory.getLogger(Main.class);

// Central Classes, singular only!!
static Config config;
static ViessmannHandler viessmannHandler;
static OptolinkInterface optolinkInterface;

public static void main(String[] args) {
// TODO Auto-generated method stub


log.info("Programm gestartet");

try {
// TODO ExeptionHandling
// Central Thread Data
// config = new Config("src/main/resources/optolink.xml");
config = new Config("optolink.xml");



// dataStore = new DataStore();
// dataStore.setInterval(config.getInterval());

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


//Start ViessmannHandler

viessmannHandler = new ViessmannHandler(config.getProtocol(),optolinkInterface);




} catch (Exception e) {
log.error("Something is wrong not init", e);
viessmannHandler.close();
optolinkInterface.close();
System.exit(1);
}

// Install catcher for Kill Signal
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
viessmannHandler.close();
optolinkInterface.close();
log.info("Programm normal terminated by Signal (Kill)");
}
});


try {



// Run SocketHandler
SocketHandler socketHandler = new SocketHandler(config, viessmannHandler);
socketHandler.start();



} catch (Exception e) {
log.error("Programm abnormal terminated.", e);
}


log.info("Programm gestartet");

try {

// config = new Config("src/main/resources/optolink.xml");
config = new Config("optolink.xml");

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

// Init ViessmannHandler
viessmannHandler = new ViessmannHandler(config.getProtocol(), optolinkInterface);

} catch (Exception e) {
log.error("Something is wrong not init", e);
viessmannHandler.close();
optolinkInterface.close();
System.exit(1);
}

// Install catcher for Kill Signal
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
viessmannHandler.close();
optolinkInterface.close();
log.info("Programm normal terminated by Signal (Kill)");
}
});

try {

// Start SocketHandler
SocketHandler socketHandler = new SocketHandler(config, viessmannHandler);
socketHandler.start();

} catch (Exception e) {
log.error("Programm abnormal terminated.", e);
}

}

}
22 changes: 4 additions & 18 deletions src/main/java/de/myandres/optolink/SocketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/*
* Install a Socked Handler for ip communication
*
* Server can found via Broadcast
* Server API Client can connect via TCP
*
*/

import java.io.BufferedReader;
Expand Down Expand Up @@ -49,7 +52,7 @@ public class SocketHandler {

public void start() {

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

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

catch (Exception e) {
log.info("Connection on Socket {} rejected or closed by client", config.getPort());
broadcastListner.disconnect();
}
}
}
Expand Down Expand Up @@ -98,10 +98,8 @@ private void open(Socket socket) throws Exception {
switch (command.toLowerCase()) {

case "list" : list(); break;
case "getall" : getall(); break;
case "get" : getThing(param); break;
case "set" : set(); break;
case "testme" : testMe(); break;
case "exit" : exit=true; break;
default: log.error("Unknown Client Command:", inStr[0]);
}
Expand All @@ -112,18 +110,6 @@ private void open(Socket socket) throws Exception {
}


private void testMe() {
// Listen wenn session closed

}

private void getall() {
log.trace("Try to get Data for all Addresses");
Telegram telegram;

}



private void set() {
// TODO Auto-generated method stub
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/de/myandres/optolink/TestFormater.java

This file was deleted.

Loading

0 comments on commit 5c72aa5

Please sign in to comment.