summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2012-10-15 23:38:17 -0700
committerJesse Morgan <jesse@jesterpm.net>2012-10-15 23:38:17 -0700
commitca0b4614ae545e30b3f65b5414e7e7f535915c86 (patch)
tree3588b583a4689b97ed864a19af040f5a4fc1ae42
Initial commit
-rw-r--r--.classpath11
-rw-r--r--.project17
-rw-r--r--.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--rxtx/RXTXcomm.jarbin0 -> 60984 bytes
-rw-r--r--rxtx/rxtxParallel.dllbin0 -> 84992 bytes
-rw-r--r--rxtx/rxtxSerial.dllbin0 -> 129536 bytes
-rw-r--r--src/MyClass.java16
-rw-r--r--src/net/tuschhcm/routercontrol/Preset.java39
-rw-r--r--src/net/tuschhcm/routercontrol/SwitcherApp.java75
-rw-r--r--src/net/tuschhcm/routercontrol/router/Router.java29
-rw-r--r--src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java37
-rw-r--r--src/net/tuschhcm/routercontrol/ui/ConsoleUI.java35
-rw-r--r--src/net/tuschhcm/routercontrol/ui/UserInterface.java42
13 files changed, 312 insertions, 0 deletions
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..39185dc
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="lib" path="rxtx/RXTXcomm.jar">
+ <attributes>
+ <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="RouterControl/rxtx"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.project b/.project
new file mode 100644
index 0000000..0276cf1
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RouterControl</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..838bd9d
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/rxtx/RXTXcomm.jar b/rxtx/RXTXcomm.jar
new file mode 100644
index 0000000..e1e7503
--- /dev/null
+++ b/rxtx/RXTXcomm.jar
Binary files differ
diff --git a/rxtx/rxtxParallel.dll b/rxtx/rxtxParallel.dll
new file mode 100644
index 0000000..92666dd
--- /dev/null
+++ b/rxtx/rxtxParallel.dll
Binary files differ
diff --git a/rxtx/rxtxSerial.dll b/rxtx/rxtxSerial.dll
new file mode 100644
index 0000000..211e006
--- /dev/null
+++ b/rxtx/rxtxSerial.dll
Binary files differ
diff --git a/src/MyClass.java b/src/MyClass.java
new file mode 100644
index 0000000..4fac53f
--- /dev/null
+++ b/src/MyClass.java
@@ -0,0 +1,16 @@
+import java.util.Enumeration;
+
+import gnu.io.CommPortIdentifier;
+
+public class MyClass {
+ public static void main(String... args) {
+ Enumeration ports = CommPortIdentifier.getPortIdentifiers();
+
+ while (ports.hasMoreElements()) {
+ CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
+
+ System.out.println(port.getName());
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/net/tuschhcm/routercontrol/Preset.java b/src/net/tuschhcm/routercontrol/Preset.java
new file mode 100644
index 0000000..e58fcf9
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/Preset.java
@@ -0,0 +1,39 @@
+package net.tuschhcm.routercontrol;
+
+/**
+ * Class to represent a router preset.
+ */
+public class Preset {
+
+ /**
+ * Load a preset from the given file.
+ *
+ * @param filename The file to load.
+ * @return the Preset object
+ */
+ public static Preset loadPresetFile(String filename) {
+ // TODO: Implement
+ return null;
+ }
+
+ /**
+ * Get the name of the preset.
+ *
+ * @return The preset name
+ */
+ public String getName() {
+ // TODO: Implement
+ return null;
+ }
+
+ /**
+ * Get an input for the given output.
+ *
+ * @param output
+ * @return Input number, or 0 if no change.
+ */
+ public int getInputForOutput(final int output) {
+ // TODO: Implement
+ return 0;
+ }
+}
diff --git a/src/net/tuschhcm/routercontrol/SwitcherApp.java b/src/net/tuschhcm/routercontrol/SwitcherApp.java
new file mode 100644
index 0000000..648d0b5
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/SwitcherApp.java
@@ -0,0 +1,75 @@
+package net.tuschhcm.routercontrol;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import net.tuschhcm.routercontrol.router.Router;
+import net.tuschhcm.routercontrol.router.ShinyBow5544Router;
+import net.tuschhcm.routercontrol.ui.ConsoleUI;
+import net.tuschhcm.routercontrol.ui.UserInterface;
+import net.tuschhcm.routercontrol.ui.UserInterface.Action;
+
+public class SwitcherApp {
+ /**
+ * The router I control.
+ */
+ private final Router mRouter;
+
+ /**
+ * My user interface.
+ */
+ private final UserInterface mUI;
+
+ /**
+ * My list of presets.
+ */
+ private final Map<Integer, Preset> mPresets;
+
+ /**
+ * Create a switcher app.
+ * @param portName the port name for the router.
+ */
+ public SwitcherApp(final String portName) {
+ mUI = new ConsoleUI();
+ mRouter = new ShinyBow5544Router(portName);
+ mPresets = new HashMap<Integer, Preset>();
+
+ // TODO: Load the presets
+
+ // TODO: Setup UI hooks
+ mUI.setPresetSelectionAction(new Action() {
+ public void onAction() {
+ handlePresetSelected();
+ }
+ });
+
+ // TODO: Send the presets to the UI
+ }
+
+ /**
+ * Start the application.
+ */
+ public void run() {
+ mUI.run();
+ }
+
+ /**
+ * Handles a preset selection.
+ */
+ private void handlePresetSelected() {
+ int selectedPreset = mUI.getSelectedPreset();
+ // TODO: What to do when the preset is selected
+ }
+
+ /**
+ * Entry-point for the application.
+ * @param args Command line arguments
+ */
+ public static void main(String[] args) {
+ // TODO: Parse command line arguments
+ String comPort = "COM1";
+
+ SwitcherApp app = new SwitcherApp(comPort);
+ app.run();
+ }
+}
diff --git a/src/net/tuschhcm/routercontrol/router/Router.java b/src/net/tuschhcm/routercontrol/router/Router.java
new file mode 100644
index 0000000..d6fe2dd
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/router/Router.java
@@ -0,0 +1,29 @@
+package net.tuschhcm.routercontrol.router;
+
+/**
+ * Interface specification for a router
+ */
+public interface Router {
+ /**
+ * Send the given input to the given output.
+ *
+ * @param output
+ * @param input
+ *
+ * @throws IllegalArgumentException if input or output are out of range.
+ */
+ public void switchInput(int output, int input) throws IllegalArgumentException;
+
+ /**
+ * Power on or power off the router
+ *
+ * @param True to turn on the router
+ */
+ public void setPower(boolean on);
+
+ /**
+ * Enable or disable physical controls
+ * @param enabled true to disable the controls.
+ */
+ public void setLockControls(boolean enabled);
+}
diff --git a/src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java b/src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java
new file mode 100644
index 0000000..ee60bfc
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/router/ShinyBow5544Router.java
@@ -0,0 +1,37 @@
+package net.tuschhcm.routercontrol.router;
+
+/**
+ * Router implementation for a ShinyBow SB-5544
+ *
+ */
+public class ShinyBow5544Router implements Router {
+
+ /**
+ * Create a new ShinyBow router using the given comm port.
+ *
+ * @param portName Com port name
+ */
+ public ShinyBow5544Router(final String portName) {
+
+ }
+
+ @Override
+ public void switchInput(int output, int input)
+ throws IllegalArgumentException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setPower(boolean on) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLockControls(boolean enabled) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/net/tuschhcm/routercontrol/ui/ConsoleUI.java b/src/net/tuschhcm/routercontrol/ui/ConsoleUI.java
new file mode 100644
index 0000000..52baa65
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/ui/ConsoleUI.java
@@ -0,0 +1,35 @@
+package net.tuschhcm.routercontrol.ui;
+
+public class ConsoleUI implements UserInterface {
+
+ @Override
+ public void addPreset(int number, String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setPresetSelectionAction(Action action) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getSelectedPreset() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void run() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setControlsLockAction(Action action) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/net/tuschhcm/routercontrol/ui/UserInterface.java b/src/net/tuschhcm/routercontrol/ui/UserInterface.java
new file mode 100644
index 0000000..7a441c5
--- /dev/null
+++ b/src/net/tuschhcm/routercontrol/ui/UserInterface.java
@@ -0,0 +1,42 @@
+package net.tuschhcm.routercontrol.ui;
+
+/**
+ * Interface specification for the view.
+ */
+public interface UserInterface {
+ /**
+ * Tell the user interface about a preset.
+ *
+ * @param number Preset number
+ * @param name Preset name
+ */
+ public void addPreset(final int number, final String name);
+
+ /**
+ * Set the action handler called when a preset is selected.
+ * @param action
+ */
+ public void setPresetSelectionAction(final Action action);
+
+ /**
+ * @return the selected preset.
+ */
+ public int getSelectedPreset();
+
+ /**
+ * Handle toggling the control lock
+ */
+ public void setControlsLockAction(final Action action);
+
+ /**
+ * Start the user interface.
+ */
+ public void run();
+
+ /**
+ * Interface specification for an action handler.
+ */
+ public interface Action {
+ public void onAction();
+ }
+}