Skip to content

Commit

Permalink
Beginning work on serial interface, command line parsing
Browse files Browse the repository at this point in the history
-added support libraries for RXTX and Apache Commons CLI parser

Log.java:
-moved logging functionality out of Coordinator and into seperate class

SerialConnection.java:
-beginning work on serial interface.  Code is borrowed and very sloppy

Coordinator.java:
-drivers are no longer children of Coordinator, interaction is done through Coordinator.someMethod() instead of a call to super
-moved logging to seperate class
-changed protected methods to public
-removed redundant logMessage()
-added command line parsing to get serial port name and network port number
-manually loads the LedFlash driver and starts it running (it works!)
  • Loading branch information
ciasaboark committed Jan 25, 2014
1 parent 82b4425 commit 64c15c5
Show file tree
Hide file tree
Showing 38 changed files with 1,221 additions and 70 deletions.
25 changes: 17 additions & 8 deletions Coordinator/drivers/org/apparatus_templi/LedFlash.java
Expand Up @@ -2,7 +2,6 @@

/**
* LedFlash
* @author Jonathan Nelson <ciasaboark@gmail.com>
* Controls a remote array of LED pixels.
*
* Remote side expects commands in the form of:
Expand All @@ -11,12 +10,21 @@
* Valid values are 4 - 9
*
* Driver does not listen for any responses
* @author Jonathan Nelson <ciasaboark@gmail.com>
*/

public class LedFlash extends Coordinator implements ControllerModule, Runnable {
public class LedFlash implements ControllerModule, Runnable {
private String moduleName = "LED_FLASH";
private volatile boolean running = true;

public LedFlash() {

}

public LedFlash(String message) {

}

/*
* I'm uncertain what the best way to implement this is. Either
* we can return back the strings "Controller","Sensor","Combo",
Expand Down Expand Up @@ -102,16 +110,16 @@ public String getControllerStatusXML(String controllerName) {
public void tellController(String controllerName, String command) {
switch (controllerName) {
case "LED 1":
super.sendCommand(moduleName, "4");
Coordinator.sendCommand(moduleName, "4");
break;
case "LED 2":
super.sendCommand(moduleName, "5");
Coordinator.sendCommand(moduleName, "5");
break;
case "LED 3":
super.sendCommand(moduleName, "6");
Coordinator.sendCommand(moduleName, "6");
break;
default:
super.logMessage(moduleName, "tellController() Given invalid LED name");
Log.e(moduleName, "tellController() Given invalid LED name");
break;
}
}
Expand All @@ -130,15 +138,16 @@ public void tellController(String controllerName, String command) {
*/
@Override
public void run() {
if (super.isModulePresent(moduleName)) {
if (Coordinator.isModulePresent(moduleName)) {
while (running) {
/*
* This is our main loop. All of the processing will happen here
* Our simple driver will repeatedly send three messages to the
* remote module, sleeping 5 seconds between each message.
*/
for (int i = 3; i < 6; i++) {
super.sendCommand(moduleName, String.valueOf(i));
Log.d(moduleName, "flashing LED on pin " + i);
Coordinator.sendCommand(moduleName, String.valueOf(i));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Expand Down
16 changes: 8 additions & 8 deletions Coordinator/drivers/org/apparatus_templi/StatefullLed.java
Expand Up @@ -2,7 +2,6 @@

/**
* StatefullLed
* @author Jonathan Nelson <ciasaboark@gmail.com>
* A driver for a remote module with a number of LEDs. Each LED
* can be turned on or off, and the driver keeps track of the state
* of each 'pixel'
Expand All @@ -19,10 +18,11 @@
* "RESETOK" - the reset command was received and all LEDs
* were reset to off.
* "OK(int)" - the state of the LED on pin number (int) was
* toggled.
* toggled.
* @author Jonathan Nelson <ciasaboark@gmail.com>
*/

public class StatefullLed extends Coordinator implements ControllerModule, Runnable {
public class StatefullLed implements ControllerModule, Runnable {
private String moduleName = "StatefullLED";
private boolean running = true;

Expand Down Expand Up @@ -71,8 +71,8 @@ public void run() {
//since we don't know the state of the remote module at the beginning we
//+ tell it to reset to a default state (all LEDs off). If the remote
//+ side does not respond within 3 seconds then the driver will terminate
if (super.isModulePresent(moduleName)) {
if (super.sendCommandAndWait(moduleName, "RESET", 3).equals("OKRESET")) {
if (Coordinator.isModulePresent(moduleName)) {
if (Coordinator.sendCommandAndWait(moduleName, "RESET", 3).equals("OKRESET")) {
for (boolean ledState: ledsState) {
ledState = false;
}
Expand Down Expand Up @@ -100,15 +100,15 @@ public void run() {
}

//thread is terminating, do whatever cleanup is needed
super.sendCommand(moduleName, "RESET");
Coordinator.sendCommand(moduleName, "RESET");
Log.d(moduleName, "terminating");

}

private void toggleLED(int ledNum) {
Log.d(moduleName, "toggling LED " + ledNum + " on pin " + leds[ledNum] + " to state: " +
(ledsState[ledNum]? "OFF" : "ON"));
super.sendCommand(moduleName, String.valueOf(leds[ledNum]) + ":" + (ledsState[ledNum]? "0" : "1"));
Coordinator.sendCommand(moduleName, String.valueOf(leds[ledNum]) + ":" + (ledsState[ledNum]? "0" : "1"));
ledsState[ledNum] = !ledsState[ledNum];
}

Expand All @@ -127,7 +127,7 @@ public String getControllerStatusXML(String controllerName) {
@Override
public void tellController(String controllerName, String command) {
Log.d(moduleName, "tellController() not validating command, passing without verification");
super.sendCommand(moduleName, command);
Coordinator.sendCommand(moduleName, command);

}

Expand Down
7 changes: 7 additions & 0 deletions Coordinator/lib/RXTX/linux-i386/BuildInfo.txt
@@ -0,0 +1,7 @@
Hardware Arch: i386
Kernel: Linux 2.6.18-92.1.17.el5
Build Date: Sun Dec 7 22:50:11 PST 2008
Java Virtual Machine:
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)
33 changes: 33 additions & 0 deletions Coordinator/lib/RXTX/linux-i386/Install.txt
@@ -0,0 +1,33 @@

Windows
----------------------------------------------------

Choose your binary build - x64 or x86 (based on which version of
the JVM you are installing to)

NOTE: You MUST match your architecture. You can't install the i386
version on a 64-bit version of the JDK and vice-versa.

For a JDK installation:

Copy RXTXcomm.jar ---> <JAVA_HOME>\jre\lib\ext
Copy rxtxSerial.dll ---> <JAVA_HOME>\jre\bin
Copy rxtxParallel.dll ---> <JAVA_HOME>\jre\bin

Linux
----------------------------------------------------

Choose your binary build - x86_64 or i386 (based on which version of
the JVM you are installing to)

NOTE: You MUST match your architecture. You can't install the i386
version on a 64-bit version of the JDK and vice-versa.

For a JDK installation on architecture=i386

Copy RXTXcomm.jar ---> <JAVA_HOME>/jre/lib/ext
Copy librxtxSerial.so ---> <JAVA_HOME>/jre/lib/i386/
Copy librxtxParallel.so ---> <JAVA_HOME>/jre/lib/i386/

NOTE: For a JDK installation on architecture=x86_64, just change the
i386 to x86_64 above.
Binary file added Coordinator/lib/RXTX/linux-i386/RXTXcomm.jar
Binary file not shown.
62 changes: 62 additions & 0 deletions Coordinator/lib/RXTX/linux-i386/Readme.txt
@@ -0,0 +1,62 @@
Overview
-----------------------------------------------
This package contains a custom binary distribution of
the RXTX serial package for Java.

Courtesy of Mfizz, Inc. (http://mfizz.com/)
http://mfizz.com/oss/rxtx-for-java

NOTE: If you include my builds in any of your distributions,
please make sure to at least provide a note of thanks to
Cloudhopper in your own ReleaseNotes. For example,

"RXTX binary builds provided by Mfizz Inc. (http://mfizz.com/).
Please see http://mfizz.com/oss/rxtx-for-java for more info."

RXTX is a great package, but they were lacking pre-built
binaries for x64 versions of Windows. I also wanted a
version built explicitly with Microsoft Visual Studio
rather than MinGW.

Please see ReleaseNotes.txt for information about this
specific release.


Customization
-----------------------------------------------

1. I've based my build on recent CVS snapshots. Please
see the ReleaseNotes.txt for information about which
snapshot I based this distribution on.

2. Removed UTS_NAME warning from .c files to match
kernel with the version you compiled against.

3. Changed version in RXTXVersion.jar and in SerialImp.c
to match my release so that I know its compiled via a CVS
snapshot.


win-x86, win-x64, ia64
-----------------------------------------------
Built using Microsoft Visual C++ 2008 - not MinGW. The
x86 and x64 versions are native and do not rely on
any other non-standard windows libraries. Just drop
in the compiled .dlls that are specific to the version
of Java you run. If you installed the 64-bit version
of the JDK, then install the x64 build.

I've tested the x86 and x64 version with Windows 2008,
2003, and Vista SP1.


linux-i386 & linux-x86_64
-----------------------------------------------
Built using CentOS 5.2 and gcc 4.1.2.

Just drop in the compiled .dlls that are specific to
the version of Java you run. If you installed the 64-bit
version of the JDK, then install the x64 build.

I've tested the x86 and x64 versions with x86 and x64
versions of CentOS 5.0 and 5.2.
21 changes: 21 additions & 0 deletions Coordinator/lib/RXTX/linux-i386/ReleaseNotes.txt
@@ -0,0 +1,21 @@
Release Notes
--------------------------------------------------

Mfizz distibution of RXTX serial package for Java.

http://mfizz.com/oss/rxtx-for-java

2.2-20081207

* Initial distribution
* linux-i386 and linux-x86_64 using CentOS 5.2 and GCC 4.1.2
* win-x86, win-x64, and win-ia64 builds using MSCV 2008
* CVS snapshot of RXTX-2.2 from 12/07/2008
* Please see BuildInfo.txt for more information about the
particular build you downloaded
* All windows builds crash the JVM if a COM port becomes
unavailable. For example, if using a USB-to-serial port
cable and you pull it out while your app is connected to the
port. The linux version throws an exception in this scenario.
Please note that even when compiled using mingw vs. MSVC, the
build will have the same behavior.
Binary file not shown.
Binary file added Coordinator/lib/RXTX/linux-i386/librxtxSerial.so
Binary file not shown.
36 changes: 36 additions & 0 deletions Coordinator/lib/RXTX/linux-i386/run-install.sh
@@ -0,0 +1,36 @@
#!/bin/sh

# check that we're root
if [ $(whoami) != "root" ]
then
echo "You must run this script as root. Try running 'su -'"
exit 1
fi

if [ -z "${JAVA_HOME}" ]
then
echo "Your JAVA_HOME environment variable must be set"
exit 1
fi

echo "Installing Cloudhopper RXTX Build to JAVA_HOME=${JAVA_HOME}"
export HWVER=$(uname -i)

if [ $HWVER = "x86_64" ]
then
# rename to what java uses
export HWVER="amd64"
fi

echo "Trying to install for hardware type ${HWVER}"

cp RXTXcomm.jar $JAVA_HOME/jre/lib/ext/
if [ "$?" -ne 0 ]; then echo "Copy failed"; exit 1; fi

cp librxtxSerial.so $JAVA_HOME/jre/lib/$HWVER/
if [ "$?" -ne 0 ]; then echo "Copy failed"; exit 1; fi

cp librxtxParallel.so $JAVA_HOME/jre/lib/$HWVER/
if [ "$?" -ne 0 ]; then echo "Copy failed"; exit 1; fi

echo "Cloudhopper RXTX Build Installed"
7 changes: 7 additions & 0 deletions Coordinator/lib/RXTX/linux-x86_64/BuildInfo.txt
@@ -0,0 +1,7 @@
Hardware Arch: x86_64
Kernel: Linux 2.6.18-92.1.18.el5
Build Date: Sun Dec 7 22:48:59 PST 2008
Java Virtual Machine:
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode)
33 changes: 33 additions & 0 deletions Coordinator/lib/RXTX/linux-x86_64/Install.txt
@@ -0,0 +1,33 @@

Windows
----------------------------------------------------

Choose your binary build - x64 or x86 (based on which version of
the JVM you are installing to)

NOTE: You MUST match your architecture. You can't install the i386
version on a 64-bit version of the JDK and vice-versa.

For a JDK installation:

Copy RXTXcomm.jar ---> <JAVA_HOME>\jre\lib\ext
Copy rxtxSerial.dll ---> <JAVA_HOME>\jre\bin
Copy rxtxParallel.dll ---> <JAVA_HOME>\jre\bin

Linux
----------------------------------------------------

Choose your binary build - x86_64 or i386 (based on which version of
the JVM you are installing to)

NOTE: You MUST match your architecture. You can't install the i386
version on a 64-bit version of the JDK and vice-versa.

For a JDK installation on architecture=i386

Copy RXTXcomm.jar ---> <JAVA_HOME>/jre/lib/ext
Copy librxtxSerial.so ---> <JAVA_HOME>/jre/lib/i386/
Copy librxtxParallel.so ---> <JAVA_HOME>/jre/lib/i386/

NOTE: For a JDK installation on architecture=x86_64, just change the
i386 to x86_64 above.
Binary file added Coordinator/lib/RXTX/linux-x86_64/RXTXcomm.jar
Binary file not shown.

0 comments on commit 64c15c5

Please sign in to comment.