diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/ErrorReporter.java b/src/org/rocketproplab/marginalstability/flightcomputer/ErrorReporter.java index 74be501..fbe000c 100644 --- a/src/org/rocketproplab/marginalstability/flightcomputer/ErrorReporter.java +++ b/src/org/rocketproplab/marginalstability/flightcomputer/ErrorReporter.java @@ -1,9 +1,9 @@ package org.rocketproplab.marginalstability.flightcomputer; -import java.io.PrintStream; - import org.rocketproplab.marginalstability.flightcomputer.subsystems.Telemetry; +import java.io.PrintStream; + /** * A class to report errors which are encountered during the operation of the * flight computer. Errors get logged to a printstream and to the Telemetry @@ -13,9 +13,8 @@ * along with a copy of that print stream writing to stderr. That was * interactive applications can report errors instantly while all errors will be * recorded. - * - * @author Max Apodaca * + * @author Max Apodaca */ public class ErrorReporter { @@ -23,7 +22,7 @@ public class ErrorReporter { /** * Instantiate the singleton if not already and return it. - * + * * @return A singleton of type ErrorReporter */ public static ErrorReporter getInstance() { @@ -36,7 +35,7 @@ public static ErrorReporter getInstance() { /** * Sets the singleton in case you want to output to a particular stream. This * should be called before any calls to {@link #getInstance()}. - * + * * @param reporter the new singleton */ public static void setInstance(ErrorReporter reporter) { @@ -57,7 +56,7 @@ public ErrorReporter() { /** * Error reporter that should print to the given print stream and send telemetry * to the given telemetry. - * + * * @param stream the stream to print to * @param telemetry the telemetry object to use to send telemetry. */ @@ -112,7 +111,7 @@ public void reportError(Exception exception, String extraInfo) { * Reports a given error, exception and extra info. The String gets sent to the * printstream along with the exception if present. The Errors enum gets * reported to telemetry. All parameters may be null. - * + * * @param error What error should be reported to the telemetry, may be null. * @param exception What exception caused the error, may be null. * @param extraInfo Additional useful text related to the error, may be null. @@ -122,7 +121,7 @@ public void reportError(Errors error, Exception exception, String extraInfo) { stream.print(extraInfo); stream.print("\n"); } - + if (error != null) { stream.print(error); stream.print("\n"); @@ -130,7 +129,7 @@ public void reportError(Errors error, Exception exception, String extraInfo) { telemetry.reportError(error); } } - + if (exception != null) { exception.printStackTrace(stream); } diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/Errors.java b/src/org/rocketproplab/marginalstability/flightcomputer/Errors.java index 9bc822b..0484a50 100644 --- a/src/org/rocketproplab/marginalstability/flightcomputer/Errors.java +++ b/src/org/rocketproplab/marginalstability/flightcomputer/Errors.java @@ -3,25 +3,26 @@ public enum Errors { UNKNOWN_ERROR("Unexpected error occured!"), - TOP_LEVEL_EXCEPTION("Exception in main loop occured"), + TOP_LEVEL_EXCEPTION("Exception in main loop occured"), IMU_IO_ERROR("Unable to read IMU over SPI"), MAX14830_IO_ERROR("Unable to access /dev/spix.x via Pi4J"), LPS22HD_INITIALIZATION_ERROR("Unable to write from i2cDevice IO Exception"), LPS22HD_PRESSURE_IO_ERROR("Unable to read Pressure from i2cDevice IO Exception"); - + private String errorMessage; - + /** * Sets the error message in the error + * * @param errorMessage */ Errors(String errorMessage) { this.errorMessage = errorMessage; } - + @Override public String toString() { return this.errorMessage; } - + } diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/FlightComputer.java b/src/org/rocketproplab/marginalstability/flightcomputer/FlightComputer.java index b2da0a9..4d50e84 100644 --- a/src/org/rocketproplab/marginalstability/flightcomputer/FlightComputer.java +++ b/src/org/rocketproplab/marginalstability/flightcomputer/FlightComputer.java @@ -1,27 +1,120 @@ package org.rocketproplab.marginalstability.flightcomputer; +import org.rocketproplab.marginalstability.flightcomputer.comm.PacketRouter; +import org.rocketproplab.marginalstability.flightcomputer.comm.PacketSources; +import org.rocketproplab.marginalstability.flightcomputer.comm.SCMPacket; import org.rocketproplab.marginalstability.flightcomputer.looper.Looper; -import org.rocketproplab.marginalstability.flightcomputer.subsystems.Subsystem; -import org.rocketproplab.marginalstability.flightcomputer.subsystems.Telemetry; +import org.rocketproplab.marginalstability.flightcomputer.subsystems.*; + +import java.util.logging.Logger; public class FlightComputer { - private Telemetry telemetry; - private Time time; - private Looper looper; + private static FlightComputer instance; + /** + * Creates a FlightComputer instance, which can only be created once. + * + * @param args arguments to configure FightComputer settings + * @return new FlightComputer instance + */ + public static FlightComputer create(String[] args) { + if (instance != null) { + throw new RuntimeException("FlightComputer has already been created."); + } + instance = new FlightComputer(args); + return instance; + } - public FlightComputer(Telemetry telemetry, Time time) { - this.telemetry = telemetry; - this.time = time; - this.looper = new Looper(time); + /** + * Convenient method to create a FlightComputer instance without any arguments. + * + * @return new FlightComputer instance + */ + public static FlightComputer create() { + return create(new String[0]); } + /** + * Time used by all objects created in the FC. + */ + private final Time time; + + /** + * Looper used by objects created in the FC, e.g. subsystems. + */ + private final Looper looper; + + private PacketRouter packetRouter = new PacketRouter(); + private Telemetry telemetry = new Telemetry(Logger.getLogger("Telemetry"), packetRouter); + + /** + * Providers to provide singleton objects to higher level management objects. + */ + private SensorProvider sensorProvider; + + /** + * Private FlightComputer constructor to avoid multiple initializations. + * + * @param args arguments to configure FlightComputer settings + */ + private FlightComputer(String[] args) { + this.time = new Time(); + this.looper = new Looper(this.time); + initWithArgs(args); + } + + /** + * Initialize input/output devices and other settings based on arguments. + * + * @param args arguments for configuration + */ + private void initWithArgs(String[] args) { + ParseCmdLine cmd = new ParseCmdLine(args); + + // use real/fake sensors + sensorProvider = SensorProvider.create(cmd.useRealSensors); + } + + /** + * Allows subsystems to register events and callbacks with the looper. + * + * @param subsystem subsystem to register + */ public void registerSubsystem(Subsystem subsystem) { subsystem.prepare(this.looper); } - public Time getTime() { - return time; + /** + * After all input/output devices and settings are initialized, higher level objects can be created. + * Use objects provided by the providers, and simply inject all objects needed to create any higher level object. + */ + public void initHighLevelObjects() { + + // PacketRouter + PacketRouter packetRouter = new PacketRouter(); + + // Telemetry + Telemetry telemetry = new Telemetry(Logger.getLogger("Telemetry"), packetRouter); + + telemetry.logInfo(Info.INIT_SUBSYSTEMS_START); + + // ParachuteSubsystem + registerSubsystem(new ParachuteSubsystem(null, null, null, null)); + + // SensorSubsystem + SensorSubsystem sensorSubsystem = new SensorSubsystem(this.time); + // add sensors + telemetry.logInfo(Info.DONE_CREATING_SENSORS); + registerSubsystem(sensorSubsystem); + + // SCMCommandSubsystem + registerSubsystem(new SCMCommandSubsystem()); // TODO: should listen to PacketRouter + + // ValveStateSubsystem + packetRouter.addListener(new ValveStateSubsystem(packetRouter), SCMPacket.class, + PacketSources.EngineControllerUnit); + + telemetry.logInfo(Info.FINISH_SUBSYSTEM_START); } public void tick() { @@ -34,4 +127,113 @@ public void tick() { } }); } + + /** + * Builder class to create FlightComputer objects with more customization. + */ + public static class Builder { + private Telemetry telemetry; + private final FlightComputer fc; + + /** + * Creates a new Builder instance, which can be used to customize the FC. + * + * @param args arguments to configure FlightComputer settings. + */ + public Builder(String[] args) { + fc = FlightComputer.create(args); + } + + /** + * Convenient method to create a Builder instance without any arguments. + */ + public Builder() { + this(new String[0]); + } + + /** + * Set custom telemetry. + * + * @param telemetry customized telemetry + * @return this Builder + */ + public Builder withTelemetry(Telemetry telemetry) { + this.telemetry = telemetry; + return this; + } + + /** + * Customizations set programmatically in the Builder will override defaults and arguments. + * + * @return customized FlightComputer + */ + public FlightComputer build() { + if (telemetry != null) fc.telemetry = this.telemetry; + return fc; + } + } + + /** + * Defines command line options and possible arguments. + * Also prints help and exits if invalid arguments are detected. + */ + private static class ParseCmdLine { + /** + * CLI argument names and descriptions + */ + private static final String + HELP = "--help", + HELP_DESC = "print help menu", + REAL_SENSORS = "--real-sensors", + REAL_SENSORS_DESC = "use real sensors"; + + /** + * Real sensor flag + */ + private boolean useRealSensors = false; + + /** + * Constructs a new object to parse CLI arguments + * + * @param args arguments to parse + */ + private ParseCmdLine(String[] args) { + parse(args); + } + + /** + * Checks arguments against each setting + * + * @param args + */ + private void parse(String[] args) { + // help + if (args.length == 1 && args[0].equals("--help")) { + printHelp(); + System.exit(0); + } + + // settings + int i = 0; + while (i < args.length) { + String arg = args[i]; + if (arg.equals(REAL_SENSORS)) { + useRealSensors = true; + System.out.println(REAL_SENSORS_DESC); + } else { + System.out.println("Invalid argument: " + arg); + printHelp(); + System.exit(1); + } + i++; + } + } + + private void printHelp() { + System.out.println("Usage:\n" + + HELP + ": " + HELP_DESC + "\n" + + REAL_SENSORS + ": " + REAL_SENSORS_DESC + ); + } + } } diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/Info.java b/src/org/rocketproplab/marginalstability/flightcomputer/Info.java index 7edd808..3fda0e1 100644 --- a/src/org/rocketproplab/marginalstability/flightcomputer/Info.java +++ b/src/org/rocketproplab/marginalstability/flightcomputer/Info.java @@ -4,13 +4,13 @@ public enum Info { INIT_SUBSYSTEMS_START("Starting Subsystems."), FINISH_SUBSYSTEM_START("Subsystems started."), DONE_CREATING_SENSORS("Finished creating sensors."); - + private String description; - - Info(String description){ + + Info(String description) { this.description = description; } - + public String getDescription() { return this.description; } diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/Main.java b/src/org/rocketproplab/marginalstability/flightcomputer/Main.java index ef8dbb8..889e5a9 100644 --- a/src/org/rocketproplab/marginalstability/flightcomputer/Main.java +++ b/src/org/rocketproplab/marginalstability/flightcomputer/Main.java @@ -1,10 +1,5 @@ package org.rocketproplab.marginalstability.flightcomputer; -import org.rocketproplab.marginalstability.flightcomputer.comm.PacketRouter; -import org.rocketproplab.marginalstability.flightcomputer.comm.PacketSources; -import org.rocketproplab.marginalstability.flightcomputer.comm.SCMPacket; -import org.rocketproplab.marginalstability.flightcomputer.subsystems.*; - /** * The main file contains the entry point to the software stack. It is * responsible for instantiating the @@ -14,7 +9,7 @@ * Subsystems}, and registering subsystems with the * {@link org.rocketproplab.marginalstability.flightcomputer.comm.PacketRouter * Packet Router}. - * + *
* The application is split up into three main sections. *
* {@code | Id | Data | Checksum |}
* {@code AA , BBBBB , FF ;}
*
- *
+ *
* An example of a heartbeat packet would be {@code HB,12345,81;} where the ID
* is HB, data is 12345 and checksum is 81.
* Basic capabilities of this class include executing, starting, and stopping
* commands. Additionally, it can check whether the command is finished or not.
- *
- * @author Hemanth Battu, Enlil Odisho
*
+ * @author Hemanth Battu, Enlil Odisho
*/
public interface Command {
/**
@@ -35,7 +34,7 @@ public interface Command {
/**
* Retrieves a list of dependencies
- *
+ *
* @return array of subsystems
*/
public Subsystem[] getDependencies();
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/commands/HeartbeatCommand.java b/src/org/rocketproplab/marginalstability/flightcomputer/commands/HeartbeatCommand.java
index 76e4bc5..29e3525 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/commands/HeartbeatCommand.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/commands/HeartbeatCommand.java
@@ -9,20 +9,19 @@
* This is the Heartbeat Command class that implements the Command interface.
* The main capabilities of this class includes checking the start time and
* sending a periodic "heartbeat" signal every second.
- *
- * @author Hemanth Battu
*
+ * @author Hemanth Battu
*/
public class HeartbeatCommand implements Command {
private static final Subsystem[] EMPTY_ARRAY = {};
- private int HBcounter;
- private double startTime;
- private Time time;
- private Telemetry telemetry;
+ private int HBcounter;
+ private double startTime;
+ private Time time;
+ private Telemetry telemetry;
/**
* Creates a new HeartbeatCommand object using Time and Telemetry objects.
- *
+ *
* @param time the Time object to use for checking time
* @param telemetry the Telemetry object used to send heartbeat
*/
@@ -33,7 +32,7 @@ public HeartbeatCommand(Time time, Telemetry telemetry) {
/**
* Setter method to set the start time.
- *
+ *
* @param startTime input to set start time with
*/
private void setStartTime(double startTime) {
@@ -62,7 +61,7 @@ public void execute() {
}
} else {
if (currentTime
- - startTime >= ((HBcounter + 1) * (Settings.HEARTBEAT_THRESHOLD))) {
+ - startTime >= ((HBcounter + 1) * (Settings.HEARTBEAT_THRESHOLD))) {
telemetry.sendHeartbeat();
HBcounter += 1;
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/commands/LaunchCommand.java b/src/org/rocketproplab/marginalstability/flightcomputer/commands/LaunchCommand.java
index c8c1d34..c539fec 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/commands/LaunchCommand.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/commands/LaunchCommand.java
@@ -3,36 +3,36 @@
import org.rocketproplab.marginalstability.flightcomputer.subsystems.EngineSubsystem;
import org.rocketproplab.marginalstability.flightcomputer.subsystems.Subsystem;
-public class LaunchCommand implements Command{
- private EngineSubsystem enginesubsystem;
-
- LaunchCommand(EngineSubsystem enginesubsystem){
- this.enginesubsystem = enginesubsystem;
- }
-
- @Override
- public boolean isDone() {
- return true;
- }
-
- @Override
- public void execute() {
- enginesubsystem.activateEngine();
- }
-
- @Override
- public void start() {
-
- }
-
- @Override
- public void end() {
-
- }
-
- @Override
- public Subsystem[] getDependencies() {
- return new Subsystem [0];
- }
+public class LaunchCommand implements Command {
+ private EngineSubsystem enginesubsystem;
+
+ LaunchCommand(EngineSubsystem enginesubsystem) {
+ this.enginesubsystem = enginesubsystem;
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ enginesubsystem.activateEngine();
+ }
+
+ @Override
+ public void start() {
+
+ }
+
+ @Override
+ public void end() {
+
+ }
+
+ @Override
+ public Subsystem[] getDependencies() {
+ return new Subsystem[0];
+ }
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenDrogueChuteCommand.java b/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenDrogueChuteCommand.java
index 2e4e9c4..1271586 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenDrogueChuteCommand.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenDrogueChuteCommand.java
@@ -8,49 +8,51 @@
import org.rocketproplab.marginalstability.flightcomputer.subsystems.Subsystem;
public class OpenDrogueChuteCommand implements Command {
- private ParachuteSubsystem parachuteSubsystem;
- private PacketRelay relay;
-
- private OpenDrogueChuteCommand(ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
- this.parachuteSubsystem = parachuteSubsystem;
- this.relay = relay;
- }
-
- @Override
- public boolean isDone() {
- return true;
- }
-
- @Override
- public void execute() {
- boolean success = parachuteSubsystem.attemptDrogueChuteOpen();
- relay.sendPacket(new SCMPacket(
- SCMPacketType.DD, success? " 1" : " 0"),
- PacketSources.CommandBox);
- }
-
- @Override
- public void start() { }
-
- @Override
- public void end() { }
-
- @Override
- public Subsystem[] getDependencies() {
- return new Subsystem[] {parachuteSubsystem};
- }
-
- public static class OpenDrogueChuteFactory {
- /**
- * Get a new OpenDrogueChuteCommand
- *
- * @param parachuteSubsystem the ParachuteSubsystem this command will operate on
- * @param relay the PacketRelay to send the success status packet through
- * @return a new OpenDrogueChuteCommand
- */
- public static OpenDrogueChuteCommand getOpenDrogueChuteCommand(
- ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
- return new OpenDrogueChuteCommand(parachuteSubsystem, relay);
- }
+ private ParachuteSubsystem parachuteSubsystem;
+ private PacketRelay relay;
+
+ private OpenDrogueChuteCommand(ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
+ this.parachuteSubsystem = parachuteSubsystem;
+ this.relay = relay;
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ boolean success = parachuteSubsystem.attemptDrogueChuteOpen();
+ relay.sendPacket(new SCMPacket(
+ SCMPacketType.DD, success ? " 1" : " 0"),
+ PacketSources.CommandBox);
+ }
+
+ @Override
+ public void start() {
+ }
+
+ @Override
+ public void end() {
+ }
+
+ @Override
+ public Subsystem[] getDependencies() {
+ return new Subsystem[]{parachuteSubsystem};
+ }
+
+ public static class OpenDrogueChuteFactory {
+ /**
+ * Get a new OpenDrogueChuteCommand
+ *
+ * @param parachuteSubsystem the ParachuteSubsystem this command will operate on
+ * @param relay the PacketRelay to send the success status packet through
+ * @return a new OpenDrogueChuteCommand
+ */
+ public static OpenDrogueChuteCommand getOpenDrogueChuteCommand(
+ ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
+ return new OpenDrogueChuteCommand(parachuteSubsystem, relay);
}
+ }
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenMainChuteCommand.java b/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenMainChuteCommand.java
index 0f202ad..1002569 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenMainChuteCommand.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/commands/OpenMainChuteCommand.java
@@ -8,50 +8,52 @@
import org.rocketproplab.marginalstability.flightcomputer.subsystems.Subsystem;
public class OpenMainChuteCommand implements Command {
- private ParachuteSubsystem parachuteSubsystem;
- private PacketRelay relay;
-
- private OpenMainChuteCommand(ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
- this.parachuteSubsystem = parachuteSubsystem;
- this.relay = relay;
- }
-
- @Override
- public boolean isDone() {
- return true;
- }
-
- @Override
- public void execute() {
- boolean success = parachuteSubsystem.attemptMainChuteOpen();
- relay.sendPacket(new SCMPacket(
- SCMPacketType.MD, success? " 1" : " 0"),
- PacketSources.CommandBox);
- }
-
- @Override
- public void start() { }
-
- @Override
- public void end() { }
-
- @Override
- public Subsystem[] getDependencies() {
- return new Subsystem[] {parachuteSubsystem};
- }
-
- public static class OpenMainChuteFactory {
- /**
- * Get a new OpenMainChuteCommand
- *
- * @param parachuteSubsystem the ParachuteSubsystem this command will operate on
- * @param relay the PacketRelay to send the success status packet through
- * @return a new OpenMainChuteCommand
- */
- public static OpenMainChuteCommand getOpenMainChuteCommand(
- ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
- return new OpenMainChuteCommand(parachuteSubsystem, relay);
- }
+ private ParachuteSubsystem parachuteSubsystem;
+ private PacketRelay relay;
+
+ private OpenMainChuteCommand(ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
+ this.parachuteSubsystem = parachuteSubsystem;
+ this.relay = relay;
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ boolean success = parachuteSubsystem.attemptMainChuteOpen();
+ relay.sendPacket(new SCMPacket(
+ SCMPacketType.MD, success ? " 1" : " 0"),
+ PacketSources.CommandBox);
+ }
+
+ @Override
+ public void start() {
+ }
+
+ @Override
+ public void end() {
+ }
+
+ @Override
+ public Subsystem[] getDependencies() {
+ return new Subsystem[]{parachuteSubsystem};
+ }
+
+ public static class OpenMainChuteFactory {
+ /**
+ * Get a new OpenMainChuteCommand
+ *
+ * @param parachuteSubsystem the ParachuteSubsystem this command will operate on
+ * @param relay the PacketRelay to send the success status packet through
+ * @return a new OpenMainChuteCommand
+ */
+ public static OpenMainChuteCommand getOpenMainChuteCommand(
+ ParachuteSubsystem parachuteSubsystem, PacketRelay relay) {
+ return new OpenMainChuteCommand(parachuteSubsystem, relay);
}
+ }
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/commands/SetValveCommand.java b/src/org/rocketproplab/marginalstability/flightcomputer/commands/SetValveCommand.java
index 516df67..fa9d046 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/commands/SetValveCommand.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/commands/SetValveCommand.java
@@ -27,7 +27,7 @@ public void execute() {
valves.setValve(getValveID(), valveState);
} catch (IllegalArgumentException dataOnOffException) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Data from SCMPacket was not On or Off. Data was actually: " + scmpacket.getData();
+ String errorMsg = "Data from SCMPacket was not On or Off. Data was actually: " + scmpacket.getData();
errorReporter.reportError(null, dataOnOffException, errorMsg);
}
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/commands/UpdateSettingCommand.java b/src/org/rocketproplab/marginalstability/flightcomputer/commands/UpdateSettingCommand.java
index 957102c..adbad11 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/commands/UpdateSettingCommand.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/commands/UpdateSettingCommand.java
@@ -6,31 +6,37 @@
import java.util.Collections;
public class UpdateSettingCommand implements Command {
- private final String setting;
-
- UpdateSettingCommand(String setting) {
- this.setting = setting;
- }
-
- public static UpdateSettingCommand getUpdateSettingCommand(String setting) {
- return new UpdateSettingCommand(setting);
- }
-
- @Override
- public boolean isDone() { return true; }
-
- @Override
- public void execute() {
- Settings.readSettingsFromConfig(Collections.singletonList(setting));
- }
-
- @Override
- public void start() { }
-
- @Override
- public void end() { }
-
- @Override
- public Subsystem[] getDependencies() { return new Subsystem[0]; }
+ private final String setting;
+
+ UpdateSettingCommand(String setting) {
+ this.setting = setting;
+ }
+
+ public static UpdateSettingCommand getUpdateSettingCommand(String setting) {
+ return new UpdateSettingCommand(setting);
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ Settings.readSettingsFromConfig(Collections.singletonList(setting));
+ }
+
+ @Override
+ public void start() {
+ }
+
+ @Override
+ public void end() {
+ }
+
+ @Override
+ public Subsystem[] getDependencies() {
+ return new Subsystem[0];
+ }
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/events/EngineEventListener.java b/src/org/rocketproplab/marginalstability/flightcomputer/events/EngineEventListener.java
index 1b83e63..b8badef 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/events/EngineEventListener.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/events/EngineEventListener.java
@@ -14,7 +14,7 @@ public interface EngineEventListener {
/**
* Called when new engine data is received
- *
+ *
* @param type the type of data which was received
* @param value the value of the data which was received
*/
@@ -22,15 +22,16 @@ public interface EngineEventListener {
/**
* The different types of data which relate to the engine
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public enum EngineDataType {
/**
* Temperature of the engine bell
*/
Temperature
- };
+ }
+
+ ;
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/events/FlightStateListener.java b/src/org/rocketproplab/marginalstability/flightcomputer/events/FlightStateListener.java
index 9497805..9eaa514 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/events/FlightStateListener.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/events/FlightStateListener.java
@@ -6,8 +6,9 @@ public interface FlightStateListener {
/**
* Called when the flight mode changes
+ *
* @param newMode the new flight mode we are in
*/
public void onFlightModeChange(FlightMode newMode);
-
+
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/events/PacketListener.java b/src/org/rocketproplab/marginalstability/flightcomputer/events/PacketListener.java
index 0090366..8a5cbe2 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/events/PacketListener.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/events/PacketListener.java
@@ -4,14 +4,13 @@
/**
* Listens for a particular type of packet in a particular direction
- *
- * @author Max Apodaca
*
* @param
* The rotation vector specified how many radians were rotated in the last
* timestep in the local reference frame.
* MSB LSB Complete 24-bit word: | buffer[2] | buffer[1] | buffer[0] |
* Registers: | 0x2A | 0x29 | 0x28 |
*/
@@ -101,7 +99,7 @@ private void readPressure() {
// TODO Read at once so we don't read high on sample 1 and low on sample 2. As
// in if the sample changes while we are reading.
try {
- byte[] buffer = { 0, 0, 0 };
+ byte[] buffer = {0, 0, 0};
i2cDevice.read(REG_PRESSURE_EXTRA_LOW, buffer, 0, 3);
// Out of range if MSB = 1
@@ -112,11 +110,11 @@ private void readPressure() {
}
int rawPressure = (Byte.toUnsignedInt(buffer[2]) << 16) + (Byte.toUnsignedInt(buffer[1]) << 8)
- + Byte.toUnsignedInt(buffer[0]);
+ + Byte.toUnsignedInt(buffer[0]);
pressure = rawPressure / (double) SCALING_FACTOR;
} catch (IOException e) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Unable to read Pressure from i2cDevice IO Exception";
+ String errorMsg = "Unable to read Pressure from i2cDevice IO Exception";
errorReporter.reportError(Errors.LPS22HD_PRESSURE_IO_ERROR, e, errorMsg);
}
sampleTime = clock.getSystemTime();
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1AccelGyro.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1AccelGyro.java
index 18377ff..7097fb1 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1AccelGyro.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1AccelGyro.java
@@ -1,23 +1,22 @@
package org.rocketproplab.marginalstability.flightcomputer.hal;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayDeque;
-import java.util.Arrays;
-
+import com.pi4j.io.i2c.I2CDevice;
import org.rocketproplab.marginalstability.flightcomputer.ErrorReporter;
import org.rocketproplab.marginalstability.flightcomputer.Errors;
import org.rocketproplab.marginalstability.flightcomputer.Settings;
import org.rocketproplab.marginalstability.flightcomputer.math.Vector3;
-import com.pi4j.io.i2c.I2CDevice;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayDeque;
+import java.util.Arrays;
/**
* The HAL implementation for the LSM9DS1 accelerometer and gyroscope sensors.
* Datasheet can be found here: https://www.st.com/resource/en/datasheet/lsm9ds1.pdf
* Every time poll is called this sensor will acquire as many samples as
* possible from the LSM9DS1's internal FIFO buffer. This is done by reading the
* number of samples in the FIFO and then reading the FIFO output registers
@@ -26,9 +25,8 @@
* {@link #getNext()} method. Whether or not the queue is empty can be read
* using the {@link #hasNext()} method. It is recommended to call
* {@link #hasNext()} before each call of {@link #getNext()}.
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public class LSM9DS1AccelGyro implements PollingSensor, AccelerometerGyroscope {
private static final int ODR_MASK = 0b111;
@@ -43,17 +41,17 @@ public class LSM9DS1AccelGyro implements PollingSensor, AccelerometerGyroscope {
private static final int FIFO_MODE_LSB_POS = 5;
private static final int FIFO_THRESHOLD_MASK = 0b11111;
private static final int FIFO_THRESHOLD_LSB_POS = 0;
- public static final int FIFO_THRESHOLD_MAX = 31;
- public static final int FIFO_THRESHOLD_MIN = 0;
- public static final int FIFO_OVERRUN_POS = 6;
- public static final int FIFO_THRESHOLD_STATUS_POS = 7;
- public static final int FIFO_SAMPLES_STORED_MASK = 0b111111;
-
- private static final int BYTES_PER_FIFO_LINE = 12;
-
- public static final double ACCELEROMETER_OUTPUT_TO_MPS_SQUARED = 9.81; // factor to multiply acc output by to
- // convert sensor output to m/s^2
- private static final double ONE_DEGREE_IN_RADIANS = Math.PI / 180.0;
+ public static final int FIFO_THRESHOLD_MAX = 31;
+ public static final int FIFO_THRESHOLD_MIN = 0;
+ public static final int FIFO_OVERRUN_POS = 6;
+ public static final int FIFO_THRESHOLD_STATUS_POS = 7;
+ public static final int FIFO_SAMPLES_STORED_MASK = 0b111111;
+
+ private static final int BYTES_PER_FIFO_LINE = 12;
+
+ public static final double ACCELEROMETER_OUTPUT_TO_MPS_SQUARED = 9.81; // factor to multiply acc output by to
+ // convert sensor output to m/s^2
+ private static final double ONE_DEGREE_IN_RADIANS = Math.PI / 180.0;
/**
* All the registers that can be found in the LSM9DS1 imu for the accelerometer
@@ -120,7 +118,7 @@ public enum Registers {
/**
* Read the address of a register, this is not necessarily the same as the
* ordinal and should be used for I2C access.
- *
+ *
* @return the I2C address of the register.
*/
public int getAddress() {
@@ -165,6 +163,7 @@ public int getValueLSBPos() {
return ACCELEROMETER_SCALE_LSB_POS;
}
}
+
/**
* The current accelerometer scale the sensor is set to.
* Initialize to default value as specified in sensor datasheet.
@@ -191,6 +190,7 @@ public int getValueLSBPos() {
return GYRO_SCALE_LSB_POS;
}
}
+
/**
* The current gyroscope scale the sensor is set to.
* Initialize to default value as specified in sensor datasheet.
@@ -225,13 +225,13 @@ public int getValueLSBPos() {
}
}
- private I2CDevice i2c;
+ private I2CDevice i2c;
private ArrayDeque
* Every time poll is called, this sensor will acquire 1 sample from the LSM9DS1
* magnetometer registers. Each sample gets put into a queue which can be accessed
* with the {@link #getNext()} method. Whether or not the queue is empty can be
* read using the {@link #hasNext()} method. It is recommended to call
* {@link #hasNext()} before each call of {@link #getNext()}.
- *
- * @author Enlil Odisho
*
+ * @author Enlil Odisho
*/
public class LSM9DS1Mag implements PollingSensor, Magnetometer {
- private static final int ODR_MASK = 0b111;
- private static final int ODR_LSB_POS = 2;
- private static final int SCALE_MASK = 0b11;
- private static final int SCALE_LSB_POS = 5;
- private static final int MODE_MASK = 0b11;
- private static final int MODE_LSB_POS = 0;
- private static final int PERFORMANCE_MASK = 0b11;
- private static final int PERFORMANCE_XY_LSB_POS = 5;
- private static final int PERFORMANCE_Z_LSB_POS = 2;
- private static final int TEMP_COMPENSATE_MASK = 0b1;
- private static final int TEMP_COMPENSATE_POS = 7;
- private static final int BLOCK_DATA_UPDATE_MASK = 0b1;
- private static final int BLOCK_DATA_UPDATE_POS = 6;
- private static final int NEW_XYZ_DATA_AVAILABLE_POS = 3;
-
+ private static final int ODR_MASK = 0b111;
+ private static final int ODR_LSB_POS = 2;
+ private static final int SCALE_MASK = 0b11;
+ private static final int SCALE_LSB_POS = 5;
+ private static final int MODE_MASK = 0b11;
+ private static final int MODE_LSB_POS = 0;
+ private static final int PERFORMANCE_MASK = 0b11;
+ private static final int PERFORMANCE_XY_LSB_POS = 5;
+ private static final int PERFORMANCE_Z_LSB_POS = 2;
+ private static final int TEMP_COMPENSATE_MASK = 0b1;
+ private static final int TEMP_COMPENSATE_POS = 7;
+ private static final int BLOCK_DATA_UPDATE_MASK = 0b1;
+ private static final int BLOCK_DATA_UPDATE_POS = 6;
+ private static final int NEW_XYZ_DATA_AVAILABLE_POS = 3;
+
private static final int BYTES_PER_SAMPLE = 6;
private static final int BITS_PER_BYTE = 8;
@@ -72,24 +70,26 @@ public enum Registers {
INT_SRC_M(0x31),
INT_THS_L(0x32),
INT_THS_H(0x33);
-
+
final int address;
-
+
Registers(int address) {
this.address = address;
}
-
+
/**
* Read the address of a register, this is not necessarily the same as the
* ordinal and should be used for I2C access.
- *
+ *
* @return the I2C address of the register.
*/
public int getAddress() {
return this.address;
}
- };
-
+ }
+
+ ;
+
public enum ODR implements RegisterValue {
ODR_0_625,
ODR_1_25,
@@ -109,9 +109,9 @@ public int getValueMask() {
public int getValueLSBPos() {
return ODR_LSB_POS;
}
-
+
}
-
+
public enum SCALE implements RegisterValue {
GAUSS_4,
GAUSS_8,
@@ -128,17 +128,18 @@ public int getValueLSBPos() {
return SCALE_LSB_POS;
}
}
+
/**
* The current scale the magnetometer is set to.
* Initialized to the default value that was specified in the datasheet.
*/
private SCALE scale = SCALE.GAUSS_4;
-
+
public enum MODE implements RegisterValue {
CONTINUOUS_CONVERSION,
SINGLE_CONVERSION,
POWER_DOWN;
-
+
@Override
public int getValueMask() {
return MODE_MASK;
@@ -149,13 +150,13 @@ public int getValueLSBPos() {
return MODE_LSB_POS;
}
}
-
+
public enum PERFORMANCE_XY implements RegisterValue {
LOW,
MEDIUM,
HIGH,
ULTRA;
-
+
@Override
public int getValueMask() {
return PERFORMANCE_MASK;
@@ -166,13 +167,13 @@ public int getValueLSBPos() {
return PERFORMANCE_XY_LSB_POS;
}
}
-
+
public enum PERFORMANCE_Z implements RegisterValue {
LOW,
MEDIUM,
HIGH,
ULTRA;
-
+
@Override
public int getValueMask() {
return PERFORMANCE_MASK;
@@ -183,33 +184,33 @@ public int getValueLSBPos() {
return PERFORMANCE_Z_LSB_POS;
}
}
-
- private I2CDevice i2c;
+
+ private I2CDevice i2c;
private ArrayDeque
* 0x0C (readData[1]) : | Sign | 2^10 | 2^9 | 2^8 | 2^7 | 2^6 | 2^5 | 2^4 |
* 0x0D (readData[2]) : | 2^3 | 2^2 | 2^1 | 2^0 | 2^-1| 2^-2| 2^-3| 2^-4|
* 0x0E (readData[3]) : | 2^-5 | 2^-6 | 2^-7| X | X | X | X | X |
- *
+ *
* @throws IOException
*/
private void readTemp() throws IOException {
byte[] data = {REG_TC_TEMP, 0, 0, 0};
- byte[] readData = this.spi.write(data);
- if (readData.length < 4) {
- return;
- }
-
- // Perform 2's complement if rawData is negative
- byte sign = 0;
- byte mask = (byte) 0b10000000;
- if ((readData[1] & mask) != 0) {
- sign = 1;
- readData[1] = (byte)~readData[1];
- readData[2] = (byte)~readData[2];
- readData[3] = (byte)~readData[3];
- }
-
- // Store 24 bit temperature read into integer placeholder
- int rawData = (Byte.toUnsignedInt(readData[1])<<16) +
- (Byte.toUnsignedInt(readData[2])<<8) +
- Byte.toUnsignedInt(readData[3]) + sign;
-
- // Returns magnitude of temperature read with correct sign
- temp = tempCalc(rawData) * Math.pow(-1, sign);
+ byte[] readData = this.spi.write(data);
+ if (readData.length < 4) {
+ return;
+ }
+
+ // Perform 2's complement if rawData is negative
+ byte sign = 0;
+ byte mask = (byte) 0b10000000;
+ if ((readData[1] & mask) != 0) {
+ sign = 1;
+ readData[1] = (byte) ~readData[1];
+ readData[2] = (byte) ~readData[2];
+ readData[3] = (byte) ~readData[3];
+ }
+
+ // Store 24 bit temperature read into integer placeholder
+ int rawData = (Byte.toUnsignedInt(readData[1]) << 16) +
+ (Byte.toUnsignedInt(readData[2]) << 8) +
+ Byte.toUnsignedInt(readData[3]) + sign;
+
+ // Returns magnitude of temperature read with correct sign
+ temp = tempCalc(rawData) * Math.pow(-1, sign);
}
-
+
/**
* Calculates magnitude of temperature from raw thermocouple read.
- *
+ *
* data : | X | X | X | X | X | X | X | X |
- * | 0 | 2^10 | 2^9 | 2^8 | 2^7 | 2^6 | 2^5 | 2^4 |
- * | 2^3 | 2^2 | 2^1 | 2^0 | 2^-1| 2^-2| 2^-3| 2^-4|
- * | 2^-5 | 2^-6 | 2^-7| X | X | X | X | X |
- *
+ * | 0 | 2^10 | 2^9 | 2^8 | 2^7 | 2^6 | 2^5 | 2^4 |
+ * | 2^3 | 2^2 | 2^1 | 2^0 | 2^-1| 2^-2| 2^-3| 2^-4|
+ * | 2^-5 | 2^-6 | 2^-7| X | X | X | X | X |
+ *
* @param data the 24 bit thermocouple read
* @return Magnitude of linearized temperature
*/
private double tempCalc(int data) {
- data = data >>> 5;
- return data/SCALING_FACTOR;
+ data = data >>> 5;
+ return data / SCALING_FACTOR;
}
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/MagReading.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/MagReading.java
index 77c80c2..821a0f1 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/MagReading.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/MagReading.java
@@ -8,23 +8,22 @@
* strength of the magnetic field at the current location.
* Note that the magnetic field vector from the magnetometer is in the body
* frame (measured x, y, and z are relative to the orientation of the sensor).
- *
- * @author Enlil Odisho
*
+ * @author Enlil Odisho
*/
public class MagReading {
-
+
private Vector3 magField;
-
+
/**
* Construct a new MagReading to store the magnetic field vector.
- *
+ *
* @param magField the magnetic field vector measured from the IMU
*/
public MagReading(Vector3 magField) {
this.magField = magField;
}
-
+
/**
* @return the magnetic field vector
*/
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/Magnetometer.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/Magnetometer.java
index 0ea563f..e606a5c 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/Magnetometer.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/Magnetometer.java
@@ -4,16 +4,15 @@
* An interface for a magnetometer sensor. A sensor implementing this interface
* will give an iterable list of MagReadings. If hasNext returns true there will
* be at least another magnetometer reading.
- *
- * @author max
*
+ * @author max
*/
public interface Magnetometer {
/**
* Read the next magnetometer reading, returns null if {@link #hasNext()}
* returns false.
- *
+ *
* @return the next magnetometer reading or null.
*/
public MagReading getNext();
@@ -21,7 +20,7 @@ public interface Magnetometer {
/**
* Determines if there is another reading from the magnetometer that can be
* read with {@link #getNext()}
- *
+ *
* @return true if {@link #getNext()} will return a new magnetometer reading,
* false otherwise.
*/
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingGroup.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingGroup.java
index adf7f18..df0c69a 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingGroup.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingGroup.java
@@ -5,9 +5,8 @@
* to poll a gyroscope and magnetometer on the same chip.
* The checksum is calculated by summing the char code of each character up the
@@ -21,9 +20,8 @@
* a character sequence from 00 to 99 and then a semicolon is appended. See
* {@link #calculateChecksum(String)} for implementation details of the checksum
* algorithm.
- *
- * @author Daniel Walder, Max Apodaca
*
+ * @author Daniel Walder, Max Apodaca
*/
public class SCMPacket {
@@ -38,7 +36,7 @@ public class SCMPacket {
/**
* Constructor that passes the packet into it's components
- *
+ *
* @param packet the packet to be processed
*/
public SCMPacket(String packet) {
@@ -47,7 +45,7 @@ public SCMPacket(String packet) {
/**
* Create a new packet based off of the ID and data
- *
+ *
* @param id the id of the packet
* @param data the data which the packet holds
*/
@@ -60,7 +58,7 @@ public SCMPacket(SCMPacketType id, String data) {
/**
* Takes the packet assigns its id and data to the instance variables Also calls
* verifyChecksum to confirm packet accuracy
- *
+ *
* @param packet the received packet to work with
*/
private void parsepacket(String packet) {
@@ -123,7 +121,7 @@ private void validate() {
/**
* Helper method for verifyChecksum for calculating the strChecksum
- *
+ *
* @param packet the packet in question
* @return the checksum of the packet
*/
@@ -143,7 +141,7 @@ private static int calculateChecksum(String packet) {
/**
* Gets the ID of this packet. Only valid if {@link SCMPacket#isValid()} returns
* true.
- *
+ *
* @return the id of the packet
*/
public SCMPacketType getID() {
@@ -153,7 +151,7 @@ public SCMPacketType getID() {
/**
* Get the data in this packet. Only valid if {@link SCMPacket#isValid()}
* returns true.
- *
+ *
* @return the data in this packet
*/
public String getData() {
@@ -162,7 +160,7 @@ public String getData() {
/**
* Get whether or not this packet is valid. If invalid nothing is guarantee.
- *
+ *
* @return if the data in the packet is valid
*/
public boolean isValid() {
@@ -172,7 +170,7 @@ public boolean isValid() {
/**
* Encodes id and data into a packet string. Will attempt to encode even with an
* invalid state.
- *
+ *
* @return the packet as String
*/
@Override
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMPacketType.java b/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMPacketType.java
index 321043d..d606994 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMPacketType.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMPacketType.java
@@ -5,20 +5,20 @@ public enum SCMPacketType {
* Change the state of the valves, each index in data is a 1 or 0 that
* Specifies valve 0-4.
*/
- V0("Valve State"),
-
+ V0("Valve State"),
+
/**
* Change the state of the valves, each index in data is a 1 or 0 that
* Specifies valve 5-7.
*/
V1("Valve State"),
-
- V2("Valve State"),
-
- V3("Valve State"),
-
+
+ V2("Valve State"),
+
+ V3("Valve State"),
+
HB("HB"), // TODO fill this packet in
-
+
/**
* Position of the GPS x coordinate. Bits are hex integer value (m)
@@ -99,12 +99,12 @@ public enum SCMPacketType {
* Reading of pressure transducer 4. Bits are integer value (PSI)
*/
P4("Pressure Transducer 4"),
-
+
/**
* Reading of pressure transducer 5. Bits are integer value (PSI)
*/
P5("Pressure Transducer 5"),
-
+
/**
* Reading of pressure transducer 6. Bits are integer value (PSI)
*/
@@ -114,47 +114,47 @@ public enum SCMPacketType {
* Reading of pressure transducer 7. Bits are integer value (PSI)
*/
P7("Pressure Transducer 7"),
-
+
/**
* Reading of pressure transducer 8. Bits are integer value (PSI)
*/
P8("Pressure Transducer 8"),
-
+
/**
* Reading of pressure transducer 9. Bits are integer value (PSI)
*/
P9("Pressure Transducer 9"),
-
+
/**
* Reading of pressure transducer 10. Bits are integer value (PSI)
*/
PA("Pressure Transducer 10"),
-
+
/**
* Reading of pressure transducer 11. Bits are integer value (PSI)
*/
PB("Pressure Transducer 11"),
-
+
/**
* Reading of pressure transducer 12. Bits are integer value (PSI)
*/
PC("Pressure Transducer 12"),
-
+
/**
* Reading of pressure transducer 13. Bits are integer value (PSI)
*/
PD("Pressure Transducer 13"),
-
+
/**
* Reading of pressure transducer 14. Bits are integer value (PSI)
*/
PE("Pressure Transducer 14"),
-
+
/**
* Reading of pressure transducer 15. Bits are integer value (PSI)
*/
PF("Pressure Transducer 15"),
-
+
/**
* Error. The bits are the error code
*/
@@ -164,37 +164,37 @@ public enum SCMPacketType {
* Warning. The bits are the warning code
*/
WA("Warning"), VS("VS"),
-
+
/**
* Drogue Chute Deploy
*/
DD("Drogue Chute Deploy"),
-
+
/**
* Main Chute Deploy
*/
MD("Main Chute Deploy"),
-
+
/**
* A packet to indicate the start of an extra long transmission, @see {@link FramedSCM}
*/
XS("Start extra long transmission"),
-
+
/**
* Indicates data for the extra long transmission, @see {@link FramedSCM}
*/
X0("Extra long data frame zero"),
-
+
/**
* Indicates data for the extra long transmission, @see {@link FramedSCM}
*/
X1("Extra long data frame one"),
-
+
/**
* Acknowledges the receipt of the {@link #X0} packet
*/
XA("Extra long ack to X0"),
-
+
/**
* Acknowledges the receipt of the {@link #X1} packet
*/
@@ -205,7 +205,7 @@ public enum SCMPacketType {
/**
* Create a new SCMPacketType enum element with the appropriate name to print
* when relevant
- *
+ *
* @param name the full name of the packet type
*/
SCMPacketType(String name) {
@@ -214,6 +214,7 @@ public enum SCMPacketType {
/**
* Returns the human readable name of the packet type
+ *
* @return the human readable name of this packet type
*/
public String getName() {
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMTransceiver.java b/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMTransceiver.java
index e1bb4fd..5fc531c 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMTransceiver.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/comm/SCMTransceiver.java
@@ -1,7 +1,6 @@
package org.rocketproplab.marginalstability.flightcomputer.comm;
import org.rocketproplab.marginalstability.flightcomputer.ErrorReporter;
-import org.rocketproplab.marginalstability.flightcomputer.Errors;
import org.rocketproplab.marginalstability.flightcomputer.events.PacketListener;
import org.rocketproplab.marginalstability.flightcomputer.events.SerialListener;
import org.rocketproplab.marginalstability.flightcomputer.hal.SerialPort;
@@ -13,9 +12,8 @@
* chunk it will notify the packet router of the new packet. It uses the
* specified source for this as we can have multiple SCM packet sources. See
* {@link PacketSources} for more info about packet sources.
- *
- * @author Max Apodaca, Antonio
*
+ * @author Max Apodaca, Antonio
*/
public class SCMTransceiver implements SerialListener, PacketListener
- *
+ *
* The acceleration vector is the acceleration felt by the IMU in the local
* reference frame in meters / second^2. If the IMU is lying flat on a table it
* would read (0, 0, 9.81).
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public class AccelGyroReading {
@@ -23,7 +22,7 @@ public class AccelGyroReading {
/**
* Construct a new AccelGyroReading to store the acceleration and rotation.
- *
+ *
* @param acc
* @param rotation
*/
@@ -34,7 +33,7 @@ public AccelGyroReading(Vector3 acc, Vector3 rotation) {
/**
* Get the rotation delta in the given reference frame in radians.
- *
+ *
* @return the difference in rotation from the last reading.
*/
public Vector3 getXYZRotation() {
@@ -43,7 +42,7 @@ public Vector3 getXYZRotation() {
/**
* Get the acceleration at the given sample time in m/s^2.
- *
+ *
* @return the acceleration in m/s^2 as a 3 component x y z vector
*/
public Vector3 getXYZAcceleration() {
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/AccelerometerGyroscope.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/AccelerometerGyroscope.java
index 8140984..53ecf74 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/AccelerometerGyroscope.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/AccelerometerGyroscope.java
@@ -5,16 +5,15 @@
* this interface will give an iterable list of AccelGyroReadings. If hasNext
* returns true there will be at least another accelerometer and gyroscope
* reading.
- *
- * @author max
*
+ * @author max
*/
public interface AccelerometerGyroscope {
/**
* Read the next accelerometer and gyroscope reading, returns null if
* {@link #hasNext()} returns false.
- *
+ *
* @return the next accelerometer and gyroscope reading or null.
*/
public AccelGyroReading getNext();
@@ -22,7 +21,7 @@ public interface AccelerometerGyroscope {
/**
* Determines if there is another reading from the accelerometer/gyroscope
* that can be read with {@link #getNext()}
- *
+ *
* @return true if {@link #getNext()} will return a new accelerometer and
* gyroscope reading, false otherwise.
*/
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/Barometer.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/Barometer.java
index 7cf555e..84d36af 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/Barometer.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/Barometer.java
@@ -3,7 +3,7 @@
public interface Barometer {
/**
* Get the pressure in hPa
- *
+ *
* @return get the pressure in hPa
*/
public double getPressure();
@@ -11,21 +11,21 @@ public interface Barometer {
/**
* Returns if the pressure is in a usable range. If the sensor is in too low or
* too high air pressure the data we get might be garbage.
- *
+ *
* @return if the current pressure is in a usable range
*/
public boolean inUsableRange();
/**
* Gets the time at which the last measurement was made
- *
+ *
* @return the time of the last measurements
*/
public double getLastMeasurementTime();
/**
* Returns an instance to a standard samplable sensor
- *
+ *
* @return the standard samplable sensor
*/
public SamplableSensor
* The i2cDevice parameter is not checked for a valid address.
- *
+ *
* @param i2cDevice the device which should be used to communicate via i2c
* @param time the time to use when reporting measurement time.
*/
@@ -58,7 +56,7 @@ public void init() {
i2cDevice.write(CTRL_REG1, (byte) (ODR_25HZ | LOW_PASS_ENABLE | LOW_PASS_20TH | KEEP_REGISTERS_SYCHONISED_BDU));
} catch (IOException e) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Unable to write from i2cDevice IO Exception";
+ String errorMsg = "Unable to write from i2cDevice IO Exception";
errorReporter.reportError(Errors.LPS22HD_INITIALIZATION_ERROR, e, errorMsg);
}
}
@@ -93,7 +91,7 @@ public void poll() {
/**
* Read the current pressure form the sensor using a one shot read method.
- *
+ *
- *
+ *
*
* Note: No values in newData are masked out.
- *
+ *
* @param toMask the value to mask
* @param newData the value to replace the masked areas of to mask
* @param lsbPos how far to the left the masked value is in toMask
@@ -428,7 +430,7 @@ private void readFromSensor() {
this.parseReadings(data, samplesRead);
} catch (IOException e) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Unable to read from IMU IO Exception";
+ String errorMsg = "Unable to read from IMU IO Exception";
errorReporter.reportError(Errors.IMU_IO_ERROR, e, errorMsg);
}
}
@@ -437,16 +439,16 @@ private void readFromSensor() {
* Take the raw data read and split it into chunks of BYTES_PER_FIFO_LINE bytes
* to correspond to each IMU reading. Then feed those into
* {@link #buildReading(byte[])}.
- *
+ *
* @param data the raw data to parse
* @param bytesRead how many bytes were read.
*/
private void parseReadings(byte[] data, int bytesRead) {
int samplesRead = bytesRead / BYTES_PER_FIFO_LINE;
for (int i = 0; i < samplesRead; i++) {
- int start = i * BYTES_PER_FIFO_LINE;
- int end = (i + 1) * BYTES_PER_FIFO_LINE;
- byte[] samples = Arrays.copyOfRange(data, start, end);
+ int start = i * BYTES_PER_FIFO_LINE;
+ int end = (i + 1) * BYTES_PER_FIFO_LINE;
+ byte[] samples = Arrays.copyOfRange(data, start, end);
AccelGyroReading reading = this.buildReading(samples);
this.samples.add(reading);
}
@@ -455,7 +457,7 @@ private void parseReadings(byte[] data, int bytesRead) {
/**
* Parse a set of BYTES_PER_FIFO_LINE bytes into an AccelGyroReading.
* Use range to normalize to m/s^2
- *
+ *
* @param data the set of six bytes representing a reading
* @return the AccelGyroReading which the six bytes belong to.
*/
@@ -478,13 +480,13 @@ public AccelGyroReading buildReading(byte[] data) {
* Converts the input bytes to shorts where it assumes that the first byte of
* the tuple is less significant.
* The array looks like {@code [L,H,L,H, ..., L, H]}.
- *
+ *
* @param data byte array of little-endian shorts
* @return array of the shorts
*/
private int[] getData(byte[] data) {
ByteBuffer byteBuffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
- int[] results = new int[data.length / 2];
+ int[] results = new int[data.length / 2];
for (int i = 0; i < data.length / 2; i++) {
results[i] = byteBuffer.getShort(i * 2); // i * 2 = index of low byte
}
@@ -500,9 +502,10 @@ public AccelGyroReading getNext() {
public boolean hasNext() {
return !samples.isEmpty();
}
-
+
/**
* Converts accelerometer readings to m/s^2. Uses the current accelerometer scale setting.
+ *
* @param accX x-axis reading from accelerometer
* @param accY y-axis reading from accelerometer
* @param accZ z-axis reading from accelerometer
@@ -511,35 +514,36 @@ public boolean hasNext() {
public Vector3 computeAcceleration(int accX, int accY, int accZ) {
// Get the accelerometer sensitivity.
double sensitivity;
- switch(accelScale) {
- case G_2:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_2G;
- break;
- case G_4:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_4G;
- break;
- case G_8:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_8G;
- break;
- case G_16:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_16G;
- break;
- default:
- throw new IllegalStateException("Sensor has an unknown accelerometer scale.");
+ switch (accelScale) {
+ case G_2:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_2G;
+ break;
+ case G_4:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_4G;
+ break;
+ case G_8:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_8G;
+ break;
+ case G_16:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_ACCELEROMETER_16G;
+ break;
+ default:
+ throw new IllegalStateException("Sensor has an unknown accelerometer scale.");
}
-
+
// This factor converts accelerometer readings to m/s^2
double conversionFactor = sensitivity * ACCELEROMETER_OUTPUT_TO_MPS_SQUARED;
-
+
return new Vector3(
- accX * conversionFactor,
- accY * conversionFactor,
- accZ * conversionFactor
+ accX * conversionFactor,
+ accY * conversionFactor,
+ accZ * conversionFactor
);
}
-
+
/**
* Converts gyroscope readings to radians per second. Uses the current gyroscope scale setting.
+ *
* @param gyroX x-axis reading from gyroscope
* @param gyroY y-axis reading from gyroscope
* @param gyroZ z-axis reading from gyroscope
@@ -548,27 +552,27 @@ public Vector3 computeAcceleration(int accX, int accY, int accZ) {
public Vector3 computeAngularAcceleration(int gyroX, int gyroY, int gyroZ) {
// Get the gyroscope sensitivity.
double sensitivity;
- switch(gyroScale) {
- case DPS_245:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_GYROSCOPE_245DPS;
- break;
- case DPS_500:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_GYROSCOPE_500DPS;
- break;
- case DPS_2000:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_GYROSCOPE_2000DPS;
- break;
- default:
- throw new IllegalStateException("Sensor has an unknown gyroscope scale.");
+ switch (gyroScale) {
+ case DPS_245:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_GYROSCOPE_245DPS;
+ break;
+ case DPS_500:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_GYROSCOPE_500DPS;
+ break;
+ case DPS_2000:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_GYROSCOPE_2000DPS;
+ break;
+ default:
+ throw new IllegalStateException("Sensor has an unknown gyroscope scale.");
}
-
+
// This factor converts gyroscope readings to radians per second
double conversionFactor = sensitivity * ONE_DEGREE_IN_RADIANS;
-
+
return new Vector3(
- gyroX * conversionFactor,
- gyroY * conversionFactor,
- gyroZ * conversionFactor
+ gyroX * conversionFactor,
+ gyroY * conversionFactor,
+ gyroZ * conversionFactor
);
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1Mag.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1Mag.java
index cb3fd16..b2d9d42 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1Mag.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/LSM9DS1Mag.java
@@ -1,46 +1,44 @@
package org.rocketproplab.marginalstability.flightcomputer.hal;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayDeque;
-
+import com.pi4j.io.i2c.I2CDevice;
import org.rocketproplab.marginalstability.flightcomputer.ErrorReporter;
import org.rocketproplab.marginalstability.flightcomputer.Errors;
import org.rocketproplab.marginalstability.flightcomputer.Settings;
import org.rocketproplab.marginalstability.flightcomputer.math.Vector3;
-import com.pi4j.io.i2c.I2CDevice;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayDeque;
/**
* The HAL implementation for the LSM9DS1 magnetometer sensor. Datasheet can be
* found here: https://www.st.com/resource/en/datasheet/lsm9ds1.pdf
- *
+ *
*
* Note: No values in newData are masked out.
- *
+ *
* @param toMask the value to mask
* @param newData the value to replace the masked areas of to mask
* @param lsbPos how far to the left the masked value is in toMask
@@ -327,12 +328,12 @@ private int mask(int toMask, int newData, int lsbPos, int valueMask) {
int result = newData << lsbPos | (toMask & notMask);
return result;
}
-
+
@Override
public void poll() {
this.readFromSensor();
}
-
+
/**
* Read one sample from the sensor. This method will read the sample by
* reading BYTES_PER_SAMPLE number of bytes from the register OUT_X_L_M.
@@ -342,59 +343,59 @@ private void readFromSensor() {
if (!isNewXYZDataAvailable()) {
return;
}
- int dataLength = BYTES_PER_SAMPLE;
- byte[] data = new byte[dataLength];
- int bytesRead = this.i2c.read(Registers.OUT_X_L_M.getAddress(), data, 0, dataLength);
+ int dataLength = BYTES_PER_SAMPLE;
+ byte[] data = new byte[dataLength];
+ int bytesRead = this.i2c.read(Registers.OUT_X_L_M.getAddress(), data, 0, dataLength);
if (bytesRead != BYTES_PER_SAMPLE) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Incorrect number of bytes for magnetometer read from IMU.";
+ String errorMsg = "Incorrect number of bytes for magnetometer read from IMU.";
errorReporter.reportError(Errors.IMU_IO_ERROR, errorMsg);
return;
}
- MagReading reading = this.buildReading(data);
+ MagReading reading = this.buildReading(data);
this.samples.add(reading);
- } catch(IOException e) {
+ } catch (IOException e) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Unable to read from IMU IO Exception";
+ String errorMsg = "Unable to read from IMU IO Exception";
errorReporter.reportError(Errors.IMU_IO_ERROR, e, errorMsg);
}
}
-
+
/**
* Parse a set of BYTES_PER_SAMPLE bytes into an MagReading.
* Normalzie to gauss
- *
+ *
* @param data the set of six bytes representing a reading
* @return the MagReading which the six bytes belong to
*/
public MagReading buildReading(byte[] data) {
int[] results = this.getData(data);
-
+
int xMag = results[0];
int yMag = results[1];
int zMag = results[2];
-
+
Vector3 magVec = computeMagneticField(xMag, yMag, zMag);
return new MagReading(magVec);
}
-
+
/**
* Converts the input bytes to shorts where it assumes that the first byte of
* the tuple is less significant.
* The array looks like {@code [L,H,L,H, ..., L, H]}.
- *
+ *
* @param data byte array of little-endian shorts
* @return array of the shorts
*/
private int[] getData(byte[] data) {
ByteBuffer byteBuffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
- int[] results = new int[data.length / 2];
+ int[] results = new int[data.length / 2];
for (int i = 0; i < data.length / 2; i++) {
results[i] = byteBuffer.getShort(i * 2); // i * 2 = index of low byte
}
return results;
}
-
+
@Override
public MagReading getNext() {
return samples.pollFirst();
@@ -404,9 +405,10 @@ public MagReading getNext() {
public boolean hasNext() {
return !samples.isEmpty();
}
-
+
/**
* Converts magnetometer readings to gauss. Uses the current magnetometer scale setting.
+ *
* @param magX x-axis reading from magnetometer
* @param magY y-axis reading from magnetometer
* @param magZ z-axis reading from magnetometer
@@ -415,28 +417,28 @@ public boolean hasNext() {
public Vector3 computeMagneticField(int magX, int magY, int magZ) {
// Get the sensitivity of the sensor
double sensitivity;
- switch(scale) {
- case GAUSS_4:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_4GAUSS;
- break;
- case GAUSS_8:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_8GAUSS;
- break;
- case GAUSS_12:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_12GAUSS;
- break;
- case GAUSS_16:
- sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_16GAUSS;
- break;
- default:
- throw new IllegalStateException("Sensor has an unknown scale.");
+ switch (scale) {
+ case GAUSS_4:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_4GAUSS;
+ break;
+ case GAUSS_8:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_8GAUSS;
+ break;
+ case GAUSS_12:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_12GAUSS;
+ break;
+ case GAUSS_16:
+ sensitivity = Settings.LSM9DS1_SENSITIVITY_MAGNETOMETER_16GAUSS;
+ break;
+ default:
+ throw new IllegalStateException("Sensor has an unknown scale.");
}
-
+
// Compute magnetic field in gauss
return new Vector3(
- magX * sensitivity,
- magY * sensitivity,
- magZ * sensitivity);
+ magX * sensitivity,
+ magY * sensitivity,
+ magZ * sensitivity);
}
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX14830.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX14830.java
index 9ea745f..5ba4886 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX14830.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX14830.java
@@ -1,29 +1,26 @@
package org.rocketproplab.marginalstability.flightcomputer.hal;
-import java.io.IOException;
-import java.nio.charset.Charset;
-
+import com.pi4j.io.spi.SpiDevice;
import org.rocketproplab.marginalstability.flightcomputer.ErrorReporter;
import org.rocketproplab.marginalstability.flightcomputer.Errors;
import org.rocketproplab.marginalstability.flightcomputer.Settings;
-import com.pi4j.io.spi.SpiDevice;
+import java.io.IOException;
+import java.nio.charset.Charset;
/**
* A class that implements the SPI protocol for the MAX14830, it contains the
* code to emit serial port events to any listeners listening to ports provided
* by the MAX14830.
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public class MAX14830 implements PollingSensor {
/**
* The list of ports which we can access on the MAX14830
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public enum Port {
UART0,
@@ -34,9 +31,8 @@ public enum Port {
/**
* The list of registers found on the MAX14830
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public enum Registers {
// FIFO DATA
@@ -120,7 +116,7 @@ public byte address() {
/**
* Create the MAX14830 and initialize the event handlers with
* {@link SerialPortAdapter}. TODO Use chipselect via gpio
- *
+ *
* @param spi the Spi device to use, no validation is done
*/
public MAX14830(SpiDevice spi) {
@@ -140,7 +136,7 @@ public MAX14830(SpiDevice spi) {
/**
* Read the length of the transmit buffer for a given port. This will return how
* many bytes can currently be written.
- *
+ *
* @param port which of the four uart channels to read from
* @return the number of free bytes in the FIFO buffer
* @throws IOException if we are unable to access /dev/spix.x via Pi4J
@@ -154,7 +150,7 @@ protected int getTXBufferLen(Port port) throws IOException {
/**
* Read the receive buffer length for a given port. This reports the number of
* bytes in the receive buffer that can be currently read.
- *
+ *
* @param port which of the four uart channels to read for.
* @return the number of bytes that can be read from the given FIFO buffer.
* @throws IOException if we are unable to access /dev/spix.x via Pi4J
@@ -179,13 +175,13 @@ protected int getRXBufferLen(Port port) throws IOException {
* above 0x1F (31) are currently not supported as they are read in a different
* way.
*
- *
+ *
* @param command the command to write
* @return -1 on failure or the value of the register
* @throws IOException if we are unable to access /dev/spix.x via Pi4J
*/
private int readRegister(byte command) throws IOException {
- byte[] data = { command, 0 };
+ byte[] data = {command, 0};
byte[] readData = this.spi.write(data);
if (readData.length < 2) {
return -1;
@@ -204,7 +200,7 @@ private int readRegister(byte command) throws IOException {
* {@link #getTXBufferLen(Port)} and therefore it is possible to loose data if
* too many bytes are sent.. If there are too few bytes in the
* {@link #uartBufferArray} then the remaining bytes are written.
- *
+ *
* @param port Which UART channel to use
* @param charCount how many bytes to write at most
* @return how many bytes were actually written.
@@ -230,7 +226,7 @@ protected int writeToTxFifo(Port port, int charCount) throws IOException {
/**
* Try to read from the RX FIFO buffer for the specified UART channel. This
* method does not check if the buffer actually has enough data.
- *
+ *
* @param port which channel to read from
* @param charCount how many characters to read
* @return the characters as a byte stream.
@@ -247,7 +243,7 @@ protected byte[] readFromRxFifo(Port port, int charCount) throws IOException {
/**
* Get a serial port interface compatible representation of the given port. This
* can be used as any other serial port would be.
- *
+ *
* @param port which UART interface to use
* @return the serial port created for the UART interface.
*/
@@ -257,7 +253,7 @@ public SerialPort getPort(Port port) {
/**
* Queue the string to be written to the specified port as soon as possible.
- *
+ *
* @param port which UART interface to write to
* @param data the string to write. Will wait until previous stirngs have been
* written.
@@ -269,7 +265,7 @@ public void writeToPort(Port port, String data) {
/**
* Get the string buffer acting as a queue for the given port.
- *
+ *
* @param port which UART buffer to select.
* @return the string buffer acting as a queue
*/
@@ -284,7 +280,7 @@ private StringBuffer selectBuffer(Port port) {
* The length is cached to prevent unnecessary calls to
* {@link #getTXBufferLen(Port)}. If we see that there is enough space from the
* last call to {@link #getTXBufferLen(Port)} we write to it.
- *
+ *
* @param port Which port to select
* @param length How many characters to write, must be >= 0
* @throws IOException if we are unable to access /dev/spix.x via Pi4J
@@ -306,7 +302,7 @@ private void writeToPort(Port port, int length) throws IOException {
/**
* Read from the given port and call the SerilPort callbacks. Length must be
* smaller or equal to the number of bytes in the RX FIFO.
- *
+ *
* @param port which port to read
* @param length how many bytes to read, passed directly to
* {@link #readFromRxFifo(Port, int)}
@@ -325,7 +321,7 @@ private void readFromPort(Port port, int length) throws IOException {
* the data.
* Then check if we have data to receive in the RX buffer. If so receive it and
* emit events.
- *
+ *
* @param port which UART port to read
* @throws IOException if we are unable to access /dev/spix.x via Pi4J
*/
@@ -349,7 +345,7 @@ public void poll() {
}
} catch (IOException e) {
ErrorReporter errorReporter = ErrorReporter.getInstance();
- String errorMsg = "Unable to access /dev/spix.x via Pi4J";
+ String errorMsg = "Unable to access /dev/spix.x via Pi4J";
errorReporter.reportError(Errors.MAX14830_IO_ERROR, e, errorMsg);
}
@@ -363,8 +359,8 @@ public void poll() {
* {@link Settings#MAX14830_F_REF}. All math is integer math so fREF must be an
* integer multiple of 16 * BaudRate or the actual baud rate will differ from the
* requested.
- *
- * @param port the UART channel to use
+ *
+ * @param port the UART channel to use
* @param baudrate the baud rate in baud
* @throws IOException if we are unable to access /dev/spix.x via Pi4J
*/
@@ -378,7 +374,7 @@ public void setBaudRate(Port port, int baudrate) throws IOException {
byte command = (byte) (uartSelect | WRITE | Registers.BRGConfig.address());
byte leastSignificantBits = (byte) (d & 0xFF);
byte mostSignificantBits = (byte) ((d >> BITS_PER_BYTE) & 0xFF);
- byte[] data = { command, 0, leastSignificantBits, mostSignificantBits };
+ byte[] data = {command, 0, leastSignificantBits, mostSignificantBits};
this.spi.write(data);
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX31856.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX31856.java
index 2932cde..7f4ae58 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX31856.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/MAX31856.java
@@ -1,43 +1,41 @@
package org.rocketproplab.marginalstability.flightcomputer.hal;
-import java.io.IOException;
-
+import com.pi4j.io.spi.SpiDevice;
import org.rocketproplab.marginalstability.flightcomputer.Time;
-import com.pi4j.io.spi.SpiDevice;
+import java.io.IOException;
/**
* Implements SPI protocol for the MAX31856, contains code to read and quantify
* linearized thermocouple temperature data.
- *
- * @author Rudy Thurston
*
+ * @author Rudy Thurston
*/
public class MAX31856 implements Thermocouple, PollingSensor {
- private SpiDevice spi;
- private double temp;
- private long sampleTime;
- private Time clock;
+ private SpiDevice spi;
+ private double temp;
+ private long sampleTime;
+ private Time clock;
- private static final byte REG_TC_TEMP = 0x0C;
- private static final double ZERO_TIME = 0.0;
+ private static final byte REG_TC_TEMP = 0x0C;
+ private static final double ZERO_TIME = 0.0;
private static final double SCALING_FACTOR = 128.0;
- private static final double MINIMUM_RANGE = -200.0;
- private static final double MAXIMUM_RANGE = 1372.0;
- private static final double TEMP_ERROR = 2048.0;
+ private static final double MINIMUM_RANGE = -200.0;
+ private static final double MAXIMUM_RANGE = 1372.0;
+ private static final double TEMP_ERROR = 2048.0;
/**
* Create instance of MAX31856 with given SpiDevice. Time will be used to
* determine the {@link #getLastMeasurementTime()} return value.
- *
- * @param spi SpiDevice communicating with MAX31856, no validation check
- * @param time the time to use when reporting measurement time.
+ *
+ * @param spi SpiDevice communicating with MAX31856, no validation check
+ * @param time the time to use when reporting measurement time.
*/
public MAX31856(SpiDevice spi, Time time) {
- this.spi = spi;
- this.clock = time;
- this.temp = TEMP_ERROR;
+ this.spi = spi;
+ this.clock = time;
+ this.temp = TEMP_ERROR;
}
@Override
@@ -53,7 +51,7 @@ public double getLastMeasurementTime() {
return ZERO_TIME;
}
}
-
+
@Override
public boolean inUsableRange() {
if ((temp >= MINIMUM_RANGE) && (temp <= MAXIMUM_RANGE)) {
@@ -78,53 +76,53 @@ public void poll() {
* Read the linearized thermocouple temperature from the sensor using a
* multi-byte read. Read/Write register memory map,
* https://datasheets.maximintegrated.com/en/ds/MAX31856.pdf
- *
+ *
*
* Each time the group is polled each sensor gets polled in series.
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public class PollingGroup implements PollingSensor {
@@ -15,7 +14,7 @@ public class PollingGroup implements PollingSensor {
/**
* Create a new polling group for the given set of sensors.
- *
+ *
* @param pollingSensors the sensors to poll simultaneously
*/
public PollingGroup(PollingSensor... pollingSensors) {
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingSensor.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingSensor.java
index adeb3a7..6ef7f94 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingSensor.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/PollingSensor.java
@@ -2,9 +2,8 @@
/**
* A sensor that can be polled.
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public interface PollingSensor {
/**
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/RegisterValue.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/RegisterValue.java
index e3a6316..3c506b5 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/RegisterValue.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/RegisterValue.java
@@ -5,9 +5,8 @@
* {@link #getValueMask()} returns a bitmask of what section of the register
* should be read and the {@link #getValueLSBPos()} method returns how many bits
* to the left of the LSB the LSB of the value is.
- *
- * @author Max Apodaca
*
+ * @author Max Apodaca
*/
public interface RegisterValue {
@@ -16,7 +15,7 @@ public interface RegisterValue {
* cover the specified value.
* For instance a register with three values aabbbccc would mean that value a
* has a mask of 0b11000000;
- *
+ *
* @return the mask for this value for its register
*/
public int getValueMask();
@@ -28,9 +27,9 @@ public interface RegisterValue {
* value b would be 3 as the LSB of b is three bits to the left of the LSB of
* the register as a whole. The LSBPos of c would be 0 and the LSBPos of a would
* be 6.
- *
+ *
* @return how many bits to the left of the register's LSB the LSB of the value
- * is
+ * is
*/
public int getValueLSBPos();
@@ -45,9 +44,9 @@ public interface RegisterValue {
* must be ordered correctly to yield a correct return value for ordinal. If the
* enum has 2 members A_0 and A_1 and A_0 should have value 0 then A_0 must be
* the first element in the enum.
- *
+ *
* @return the value of this value
*/
public int ordinal();
-
+
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/SMSSender.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/SMSSender.java
index 9fdbfd4..f52c248 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/SMSSender.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/SMSSender.java
@@ -1,5 +1,5 @@
package org.rocketproplab.marginalstability.flightcomputer.hal;
public interface SMSSender {
- void sendTextMessage(String number, String message);
+ void sendTextMessage(String number, String message);
}
diff --git a/src/org/rocketproplab/marginalstability/flightcomputer/hal/SamplableSensor.java b/src/org/rocketproplab/marginalstability/flightcomputer/hal/SamplableSensor.java
index 7d393c3..0b52cab 100644
--- a/src/org/rocketproplab/marginalstability/flightcomputer/hal/SamplableSensor.java
+++ b/src/org/rocketproplab/marginalstability/flightcomputer/hal/SamplableSensor.java
@@ -2,16 +2,15 @@
/**
* Sensor that exposes a standardized samplable interface
- *
- * @author Max
*
* @param