Neues Objekt Command aufgenommen
authorfelix <felix@a944a559-bf0e-0410-8ddc-85264b264b6c>
Tue, 15 May 2007 18:36:09 +0000 (18:36 +0000)
committerfelix <felix@a944a559-bf0e-0410-8ddc-85264b264b6c>
Tue, 15 May 2007 18:36:09 +0000 (18:36 +0000)
git-svn-id: https://www.internetallee.de/svn/bytewurf@23 a944a559-bf0e-0410-8ddc-85264b264b6c

projekte/netzschalter/src/de/bytewurf/projekte/netzschalter/Command.java
projekte/netzschalter/src/de/bytewurf/projekte/netzschalter/CommandPanel.java
projekte/netzschalter/src/de/bytewurf/projekte/netzschalter/Netzdose.java
projekte/netzschalter/test/de/bytewurf/projekte/netzschalter/NetzdosenMockup.java

index 859169b..adcd547 100644 (file)
@@ -25,6 +25,16 @@ public class Command {
                }
        }
        
+       public String toString() {
+               StringBuffer result = new StringBuffer();
+               for (int i = 0; i < commandBytes.length; i++) {
+                       result.append(Integer.toHexString(commandBytes[i] & 0xFF));
+                       if (i < commandBytes.length - 1);
+                               result.append(", ");
+               }
+               return result.toString();
+       }
+       
        public byte[] getCommandBytes() {
                if (commandBytes == null)
                        throw new RuntimeException("No Command configured yet.");
index 974ef4d..b4eb294 100644 (file)
@@ -82,8 +82,16 @@ public class CommandPanel extends JPanel {
        }
 
        protected void apply() {
-               LogMediator.getInstance().log("Sende " + command.getText());
-               answers.append(++commandCounter + ": " + command.getText() + "\n");
+               Command cmd;
+               String commandText = command.getText();
+               try {
+                       cmd = new Command(commandText);
+               } catch (RuntimeException e) {
+                       LogMediator.getInstance().log("Kann \"" + commandText + "\" nicht in Command wandeln.");
+                       return;
+               }
+               LogMediator.getInstance().log("Sende " + cmd);
+               answers.append(++commandCounter + ": " + cmd + "\n");
                command.setText("");
        }
        
index 49e50fa..5ba89e3 100644 (file)
@@ -26,5 +26,7 @@ public interface Netzdose {
        public void setHostConfig(HostConfig hostConfig);
        
        public HostConfig getHostConfig();
+       
+       public byte[] sendCommand(Command command);
 
 }
\ No newline at end of file
index 8d0c17b..a22b038 100644 (file)
@@ -59,5 +59,10 @@ public class NetzdosenMockup implements Netzdose {
                return hostConfig;
        }
 
+       public byte[] sendCommand(Command command) {
+               LogMediator.getInstance().log("Send Command: " + command.toString());
+               return command.getCommandBytes();
+       }
+
        
 }