Skip to content

Commit

Permalink
Moving eclipse project working directory
Browse files Browse the repository at this point in the history
-moved entire Coordinator workspace to coordinator_eclipse_workspace
-added .metadata

Coordinator.java:
-check for duplicate drivers during initialization

Driver.java:
ControllerModule.java:
SensorModule.java:
-now implemented as abstract classes instead of interfaces

LedFlash.java:
StatefullLed.java:
-extend ControllerModule instead of implement

Log.java
-warning and error messages are now prefixed accordingly
  • Loading branch information
ciasaboark committed Jan 29, 2014
1 parent ba95d7f commit d32835e
Show file tree
Hide file tree
Showing 486 changed files with 69,035 additions and 0 deletions.
264 changes: 264 additions & 0 deletions coordinator_eclipse_workspace/.metadata/.log

Large diffs are not rendered by default.

@@ -0,0 +1,20 @@
*** SESSION Jan 21, 2014 23:28:31.49 -------------------------------------------
*** SESSION Jan 21, 2014 23:37:31.75 -------------------------------------------
*** SESSION Jan 22, 2014 14:16:31.81 -------------------------------------------
*** SESSION Jan 23, 2014 12:00:16.96 -------------------------------------------
*** SESSION Jan 23, 2014 13:37:27.83 -------------------------------------------
*** SESSION Jan 25, 2014 10:21:30.56 -------------------------------------------
*** SESSION Jan 25, 2014 15:12:03.56 -------------------------------------------
*** SESSION Jan 25, 2014 17:59:13.78 -------------------------------------------
*** SESSION Jan 25, 2014 21:23:37.94 -------------------------------------------
*** SESSION Jan 26, 2014 14:03:33.27 -------------------------------------------
*** SESSION Jan 27, 2014 16:54:07.51 -------------------------------------------
*** SESSION Jan 27, 2014 21:56:54.95 -------------------------------------------
*** SESSION Jan 27, 2014 23:32:46.82 -------------------------------------------
*** SESSION Jan 28, 2014 00:21:27.01 -------------------------------------------
*** SESSION Jan 28, 2014 11:54:53.38 -------------------------------------------
*** SESSION Jan 28, 2014 12:11:10.42 -------------------------------------------
*** SESSION Jan 28, 2014 13:31:33.87 -------------------------------------------
*** SESSION Jan 28, 2014 17:17:30.51 -------------------------------------------
*** SESSION Jan 28, 2014 21:25:18.91 -------------------------------------------
*** SESSION Jan 28, 2014 21:30:38.59 -------------------------------------------
@@ -0,0 +1 @@

@@ -0,0 +1 @@

@@ -0,0 +1,6 @@
package org.apparatus_templi;

public interface RemoteModule {
public String getModuleType();
public String getModuleName();
}
@@ -0,0 +1,134 @@
package org.apparatus_templi;

/**
* 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'
*
* Remote side expects one of the following commands:
* "RESET" - reset all attached LEDs to their off state
* "(int):(int)" - set the state of the LED attached to
* the first (int) to the boolean value of the second int.
* Valid values for the first int are 4,5,6.
* The second int may be any valid signed int value, with 0
* equating to false, all other values to true.
*
* Driver listens for the following responses:
* "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.
*/

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

//our remote module has three LEDs attached
private int[] leds = {4, 5, 6};
private boolean[] ledsState = {false, false, false};

@Override
public String getModuleType() {
return "Controller";
}

@Override
public String getModuleName() {
return moduleName;
}

@Override
public void receiveMessage(String message) {
//throw away the message for now
Log.d(moduleName, "received message, ignoring");

}

@Override
public void terminate() {
Log.d(moduleName, "told to terminate");
running = false;

}

@Override
public String getWidgetXML() {
Log.w(moduleName, "getWidgetXML() unimplimented");
return null;
}

@Override
public String getFullPageXML() {
Log.w(moduleName, "getFullPageXML() unimplimented");
return null;
}

@Override
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 (Coordinator.sendCommandAndWait(moduleName, "RESET", 3).equals("OKRESET")) {
for (boolean ledState: ledsState) {
ledState = false;
}
} else {
Log.e(moduleName, "did not get a response from the remote side, exiting");
terminate();
}
} else {
Log.e(moduleName, "remote module is not present, shutting down");
terminate();
}


while (running) {
//run through a hardcoded loop for now.
for (int i = 0; i < 2; i++) {
toggleLED(i);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}

//thread is terminating, do whatever cleanup is needed
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"));
Coordinator.sendCommand(moduleName, String.valueOf(leds[ledNum]) + ":" + (ledsState[ledNum]? "0" : "1"));
ledsState[ledNum] = !ledsState[ledNum];
}

@Override
public String getControllerListXML() {
Log.w(moduleName, "getControllerListXML() unimplimented for now");
return null;
}

@Override
public String getControllerStatusXML(String controllerName) {
Log.w(moduleName, "getControllerStatusXML() unimplimented for now");
return null;
}

@Override
public void tellController(String controllerName, String command) {
Log.d(moduleName, "tellController() not validating command, passing without verification");
Coordinator.sendCommand(moduleName, command);

}

}
@@ -0,0 +1,7 @@
package org.apparatus_templi;

public interface ControllerModule extends Driver {
public String getControllerListXML();
public String getControllerStatusXML(String controllerName);
public void tellController(String controllerName, String command);
}
@@ -0,0 +1,57 @@
package org.apparatus_templi;

public abstract class Driver implements Runnable {
// protected String type; //Controller or Sensor type.
protected final String name; //name of the device Empty String as default or could assign a random name if not assigned one
public volatile int counter = 0; //used to assign the threads random names if not explicitly given one
protected String protocol_version =" "; //this current operating protocol verison the device is running
protected boolean running = false;

public abstract String getModuleType();
public abstract String getModuleName();
public abstract void receiveCommand(String command);
public abstract String getWidgetXML();
public abstract String getFullPageXML();
public abstract void will_run(); //let the thread know it is about to run


/*
* Let the subclass know it is about to terminate.
* The subclass can do any extra serialization or whatever it needs
* to do before terminating.
*/
public abstract void will_terminate();


public void terminate() {
this.will_terminate(); //call the subclass implementation
}

/*
* If the device is not given a name during creation, it will have an empty string as default
* The thread's begin_execution() function (make shift constructor) can handle this. It can assign it a random
* name.
*/
public void setName(String device_name) {
this.name = device_name;
}

public String deviceName() {
return this.name;
}

public void isRunning() {
return this.running;
}

public void setRunning(boolean run) {
this.running = run;
}

/*
* The devices' current running protocol verison. I.e (0.0 or 0.1) and so fourth
*/
public void protocol_version(String version) {
this.protocol_version = version;
}
}

0 comments on commit d32835e

Please sign in to comment.