94 lines
2.8 KiB
Java
94 lines
2.8 KiB
Java
package de.ctdo.crashtest;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.ClientProtocolException;
|
|
import org.apache.http.client.HttpClient;
|
|
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;
|
|
|
|
/**
|
|
* User: lpless
|
|
* Date: 10.05.12
|
|
* Time: 11:03
|
|
*/
|
|
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 + "/";
|
|
}
|
|
|
|
public void setPar56(int id, int red, int green, int blue) {
|
|
if(true) return;
|
|
try {
|
|
HttpPost post = new HttpPost(baseAddress + "/control/devices");
|
|
post.addHeader("Content-Type", "application/json");
|
|
|
|
StringEntity entity = new StringEntity(
|
|
"{ \"timeStamp\": 0, \"updates\": [ {\"deviceId\": "+id+", \"options\": { \"red\": "+
|
|
red+", \"green\": "+green+", \"blue\": "+blue+" } } ] }" ,
|
|
"UTF-8");
|
|
|
|
post.setEntity(entity);
|
|
|
|
HttpResponse response = client.execute(post);
|
|
System.out.println(response);
|
|
|
|
post.abort();
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
} catch (ClientProtocolException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
public void setLampel(boolean red, boolean yellow, boolean green) {
|
|
|
|
if(true) return;
|
|
|
|
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 {
|
|
HttpPost post = new HttpPost(baseAddress + "/control/devices");
|
|
post.addHeader("Content-Type", "application/json");
|
|
|
|
StringEntity entity = new StringEntity(
|
|
"{ \"timeStamp\": 0, \"updates\": [ {\"deviceId\": 4, \"options\": { \"red\": "+
|
|
red+", \"green\": "+green+", \"yellow\": "+yellow+" } } ] }" ,
|
|
"UTF-8");
|
|
|
|
post.setEntity(entity);
|
|
|
|
HttpResponse response = client.execute(post);
|
|
System.out.println(response);
|
|
|
|
post.abort();
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
} catch (ClientProtocolException e) {
|
|
e.printStackTrace();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}*/
|
|
}
|
|
|
|
}
|