struktur vereinfacht
This commit is contained in:
parent
bef28b854d
commit
7402c8f8cf
|
@ -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,7 +18,6 @@ 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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue