struktur vereinfacht

This commit is contained in:
Lucas Pleß 2012-05-30 14:37:55 +02:00
parent bef28b854d
commit 7402c8f8cf
4 changed files with 24 additions and 61 deletions

View File

@ -7,8 +7,8 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import java.io.IOException; import java.io.*;
import java.io.UnsupportedEncodingException; import java.net.Socket;
/** /**
* User: lpless * User: lpless
@ -18,7 +18,6 @@ import java.io.UnsupportedEncodingException;
public class BuntiClient { public class BuntiClient {
private String baseAddress; private String baseAddress;
private HttpClient client = new DefaultHttpClient(); private HttpClient client = new DefaultHttpClient();
private LampelClient lampel = new LampelClient();
public BuntiClient(String server, int port) { public BuntiClient(String server, int port) {
baseAddress = "http://" + server + ":" + port + "/"; baseAddress = "http://" + server + ":" + port + "/";
@ -52,16 +51,30 @@ public class BuntiClient {
} }
public void setLampel(boolean red, boolean yellow, boolean green) { public void setLampel(boolean red, boolean yellow, boolean green) {
int value = 0; int value = 0;
if( green ) value |= 0x01; if( green ) value |= 0x01;
if( yellow ) value |= 0x02; if( yellow ) value |= 0x02;
if( red ) value |= 0x04; 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 { /* try {
HttpPost post = new HttpPost(baseAddress + "/control/devices"); HttpPost post = new HttpPost(baseAddress + "/control/devices");
post.addHeader("Content-Type", "application/json"); post.addHeader("Content-Type", "application/json");
@ -78,6 +91,7 @@ public class BuntiClient {
post.abort(); post.abort();
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
} catch (ClientProtocolException e) { } catch (ClientProtocolException e) {

View File

@ -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();
}
}
}

View File

@ -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();
}
}

View File

@ -22,6 +22,10 @@ public class SteuerungFrame extends JFrame implements StateChangeListener {
Statemachine machine = new Statemachine(); Statemachine machine = new Statemachine();
BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080); BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
public static void main(String args[]) {
new SteuerungFrame();
}
public SteuerungFrame() { public SteuerungFrame() {
//setType(Type.UTILITY); //setType(Type.UTILITY);
setBackground(Color.black); setBackground(Color.black);