From 03abf212c10283ffa95ea161a21a157be5cf9112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Fri, 15 Jun 2012 00:30:11 +0200 Subject: [PATCH] made lampel controlled via udp since lampel got new hardware and firmware --- src/de/ctdo/crashtest/TestClass.java | 48 +++++++++++++------ .../ctdo/crashtest/domotics/BuntiClient.java | 20 ++++---- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/de/ctdo/crashtest/TestClass.java b/src/de/ctdo/crashtest/TestClass.java index eb89532..cee0306 100644 --- a/src/de/ctdo/crashtest/TestClass.java +++ b/src/de/ctdo/crashtest/TestClass.java @@ -1,28 +1,48 @@ package de.ctdo.crashtest; +import de.ctdo.crashtest.domotics.BuntiClient; import de.ctdo.crashtest.gui.GuiEventListener; import de.ctdo.crashtest.gui.MainGui; -public class TestClass implements GuiEventListener { +public class TestClass { public TestClass() { - MainGui mg = new MainGui(); - mg.addListener(this); - mg.setCountDown(121411); + + BuntiClient bunti = new BuntiClient("bunti.ctdo.de",8080); + + int pause = 500; + + try { + + while(true) { + for(int i = 0; i< 3; i++) { + Thread.sleep(pause); + bunti.setLampel(true, false, true); + Thread.sleep(pause); + bunti.setLampel(false, true, true); + Thread.sleep(pause); + bunti.setLampel(false, false, true); + Thread.sleep(pause); + bunti.setLampel(false, false, false); + Thread.sleep(pause); + bunti.setLampel(true, true, true); + Thread.sleep(pause); + bunti.setLampel(false, false, true); + Thread.sleep(pause); + bunti.setLampel(true, true, true); + Thread.sleep(pause); + bunti.setLampel(false, false, false); + } + + //Thread.sleep(2000); + } + } + catch (InterruptedException ignored) {} + } public static void main(String args[]) { new TestClass(); } - @Override - public void keyPress(char key) { - - } - - @Override - public void windowClosing() { - System.out.println("closing"); - System.exit(0); - } } diff --git a/src/de/ctdo/crashtest/domotics/BuntiClient.java b/src/de/ctdo/crashtest/domotics/BuntiClient.java index 26dde53..5fffcda 100644 --- a/src/de/ctdo/crashtest/domotics/BuntiClient.java +++ b/src/de/ctdo/crashtest/domotics/BuntiClient.java @@ -8,6 +8,9 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import java.io.*; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; import java.net.Socket; public class BuntiClient implements IBuntiClient { @@ -129,18 +132,13 @@ public class BuntiClient implements IBuntiClient { if( red ) value |= 0x04; try { - Socket client = new Socket("lampel.ctdo.de", 2701); - client.setSoTimeout(800); + byte buffer[] = ("io set port 2 " + Integer.toHexString(value) + '\n').getBytes(); + + DatagramSocket udp = new DatagramSocket(); + InetAddress ia = InetAddress.getByName("lampel.raum.ctdo.de"); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, ia, 2701); - DataOutputStream outToServer = new DataOutputStream(client.getOutputStream()); - BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream())); - - - outToServer.writeBytes("io set port 2 " + Integer.toHexString(value) + '\n'); - - inFromServer.readLine(); - - client.close(); + udp.send(packet); } catch (IOException e) { Logger.sLog("lampel error: " + e.getMessage()); }