diff --git a/src/de/ctdo/crashtest/BuntiClient.java b/src/de/ctdo/crashtest/BuntiClient.java index 33aaf42..a916284 100644 --- a/src/de/ctdo/crashtest/BuntiClient.java +++ b/src/de/ctdo/crashtest/BuntiClient.java @@ -7,8 +7,8 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; -import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.io.*; +import java.net.Socket; /** * User: lpless @@ -18,8 +18,7 @@ import java.io.UnsupportedEncodingException; public class BuntiClient { private String baseAddress; private HttpClient client = new DefaultHttpClient(); - private LampelClient lampel = new LampelClient(); - + public BuntiClient(String server, int port) { baseAddress = "http://" + server + ":" + port + "/"; } @@ -52,16 +51,30 @@ public class BuntiClient { } public void setLampel(boolean red, boolean yellow, boolean green) { - int value = 0; if( green ) value |= 0x01; if( yellow ) value |= 0x02; if( red ) value |= 0x04; - lampel.sendCommand("io set port 2 " + Integer.toHexString(value)); + try { + Socket client = new Socket("lampel.ctdo.de", 2701); + client.setSoTimeout(2000); + DataOutputStream outToServer = new DataOutputStream(client.getOutputStream()); + BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream())); + + + outToServer.writeBytes("io set port 2 " + Integer.toHexString(value) + '\n'); + + String result = inFromServer.readLine(); + + client.close(); + } catch (IOException e) { + e.printStackTrace(); + } + /* try { HttpPost post = new HttpPost(baseAddress + "/control/devices"); post.addHeader("Content-Type", "application/json"); @@ -78,6 +91,7 @@ public class BuntiClient { post.abort(); + } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { diff --git a/src/de/ctdo/crashtest/LampelClient.java b/src/de/ctdo/crashtest/LampelClient.java deleted file mode 100644 index 941aa8c..0000000 --- a/src/de/ctdo/crashtest/LampelClient.java +++ /dev/null @@ -1,36 +0,0 @@ -package de.ctdo.crashtest; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.Socket; - -public class LampelClient { - - private static final int ECMD_TCP_PORT = 2701; - private static final String LAMPEL_HOST = "lampel.ctdo.de"; - - - public void sendCommand(String command) { - - try { - Socket client = new Socket(LAMPEL_HOST, ECMD_TCP_PORT); - client.setSoTimeout(2000); - - - DataOutputStream outToServer = new DataOutputStream(client.getOutputStream()); - BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream())); - - - outToServer.writeBytes(command + '\n'); - - String result = inFromServer.readLine(); - - client.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } -} diff --git a/src/de/ctdo/crashtest/Steuerung.java b/src/de/ctdo/crashtest/Steuerung.java deleted file mode 100644 index b2c3aa3..0000000 --- a/src/de/ctdo/crashtest/Steuerung.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.ctdo.crashtest; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.CharBuffer; - -public class Steuerung { - - - public static void main(String args[]) { - - new SteuerungFrame(); - - } - - - -} diff --git a/src/de/ctdo/crashtest/SteuerungFrame.java b/src/de/ctdo/crashtest/SteuerungFrame.java index 452ddec..f73adda 100644 --- a/src/de/ctdo/crashtest/SteuerungFrame.java +++ b/src/de/ctdo/crashtest/SteuerungFrame.java @@ -22,6 +22,10 @@ public class SteuerungFrame extends JFrame implements StateChangeListener { Statemachine machine = new Statemachine(); BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080); + public static void main(String args[]) { + new SteuerungFrame(); + } + public SteuerungFrame() { //setType(Type.UTILITY); setBackground(Color.black);