Skip to content

Commit 0886476

Browse files
committed
Try to document every single method...
1 parent 0658357 commit 0886476

52 files changed

Lines changed: 933 additions & 27 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/jaci/openrio/toast/core/Environment.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
package jaci.openrio.toast.core;
22

3+
/**
4+
* The Environment Class is used as a set of hooks to obtain data regarding the Environment the Robot is working in.
5+
* This is where modules should check for Verification/Simulated environments, check if FMS is attached, as well as
6+
* operated depending on the Operating System the Robot or Simulation is present in.
7+
*
8+
* @author Jaci
9+
*/
310
public class Environment {
411

12+
/**
13+
* Is this a Verification Environment? A Verification Environment is launched with args --verify to test
14+
* the Robot's behaviour in a generic competition (15 sec Auto, 2 min Teleop). All state changes are done
15+
* in this mode, and any uncaught exceptions render the build as 'failed'
16+
*/
517
public static boolean isVerification() {
618
return ToastBootstrap.isVerification;
719
}
820

21+
/**
22+
* Is this a Simulation Environment? A Simulation Environment is launched with args --sim (--search) as a
23+
* means for Developers to test their code in their IDE without having a robot present. This is used very commonly,
24+
* and in most cases all the Class Patching is done for you, but special cases may require this hook.
25+
*/
926
public static boolean isSimulation() {
1027
return ToastBootstrap.isSimulation;
1128
}
1229

30+
/**
31+
* Is this an Embedded Environment? Embedded environments are simply described as 'non-simulation' environments, and
32+
* are therefore assumed to be running on the NI RoboRIO or standard FRC competition computer onboard the Robot. The
33+
* only time a robot program is embedded is when it has been deployed to a robot and is running.
34+
*/
1335
public static boolean isEmbedded() {
1436
return !isSimulation();
1537
}
1638

39+
/**
40+
* Is this a competition? This returns true if the Robot and Driver Station have adequate communication to the
41+
* Field Management System (FMS). This is NOT a substitute for {@link #isEmbedded()}, as the program can be
42+
* both embedded and not connected to FMS during times when an FRC regulation field is not present.
43+
*/
1744
public static boolean isCompetition() {
1845
return Toast.getToast().station().isFMSAttached();
1946
}
2047

48+
/**
49+
* Get the Environmental Type in String form. This formats {@link #isSimulation()}, {@link #isVerification()} and
50+
* {@link #isEmbedded()} into their String form for writing to a console or other human-readable resources.
51+
*/
2152
public static String getEnvironmentalType() {
2253
if (isVerification())
2354
return "Verification";
@@ -28,26 +59,52 @@ else if (isEmbedded())
2859
return "Unknown";
2960
}
3061

62+
/**
63+
* Get the architecture of the Operating System. This usually contains x86, 32 or 64 bit systems depending on the
64+
* OS.
65+
*/
3166
public static String getOS_Architecture() {
3267
return System.getProperty("os.arch");
3368
}
3469

70+
/**
71+
* Get the OS Name. This returns things such as 'Linux', 'Mac OS X' or 'Windows'. Best practise is to use .contains()
72+
* on the return value, as Windows contains the version number (7, 8, 8.1, 10) in this String and uses os.version
73+
* as the build ID.
74+
*/
3575
public static String getOS_Name() {
3676
return System.getProperty("os.name");
3777
}
3878

79+
/**
80+
* Get the Operating System version. On Mac, this is the OS version such as 10.10, while on Windows this is the OS
81+
* build number such as 6.3. This changes per system, so it is most useful in Crash Logs and debugging.
82+
*/
3983
public static String getOS_Version() {
4084
return System.getProperty("os.version");
4185
}
4286

87+
/**
88+
* Get the Java Vendor. This is usually 'Oracle Corporation' or something similar, unless the user is using some
89+
* bootleg version of Java they got from the shady guy in the street called 'Big Moe'
90+
*/
4391
public static String getJava_vendor() {
4492
return System.getProperty("java.vendor");
4593
}
4694

95+
/**
96+
* Get the Java Version. This follows the standard '1.8.0_33' system. This should be prefixed with '1.8.x_', otherwise
97+
* chances are Java is out of date and Toast won't work properly. Update 25 or above is usually required for Groovy
98+
* to work.
99+
*/
47100
public static String getJava_version() {
48101
return System.getProperty("java.version");
49102
}
50103

104+
/**
105+
* Get the Java Home Directory. This is the location of the JRE and JDK. This is used to keep track of System .jar
106+
* files present on the system to make sure we don't load them for Module candidacy.
107+
*/
51108
public static String getJava_home() {
52109
return System.getProperty("java.home");
53110
}

src/main/java/jaci/openrio/toast/core/StateTracker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public static void removeTransition(StateListener.Transition transition) {
168168
transitioners.removeConcurrent(transition);
169169
}
170170

171+
/**
172+
* Waits for new control data to be received.
173+
*/
171174
private static boolean nextPeriodReady() {
172175
return impl.station().isNewControlData();
173176
}

src/main/java/jaci/openrio/toast/core/Toast.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public void startCompetition() {
118118
}
119119
}
120120

121+
/**
122+
* Register the Garbage Collector to trigger on a regular basis.
123+
*/
121124
void registerGC(final double time) {
122125
Heartbeat.add(new HeartbeatListener() {
123126
int count = 0;
@@ -132,13 +135,22 @@ public void onHeartbeat(int skipped) {
132135
});
133136
}
134137

138+
/**
139+
* Shutdown the robot safely with exit code 0. This will stop all motors and
140+
* ensure all actions on the ThreadPool are completed
141+
*/
135142
public void shutdownSafely() {
136143
log().info("Robot Shutting Down...");
137144
ToastThreadPool.INSTANCE.finish();
138145
MotorRegistry.stopAll();
139146
System.exit(0);
140147
}
141148

149+
/**
150+
* Shutdown the robot when the exit code should not be 0. This is usually when
151+
* the robot has crashed or encountered and error. This will forcefully stop the ThreadPool,
152+
* all motors and yield the exit code -1
153+
*/
142154
public void shutdownCrash() {
143155
log().info("Robot Error Detected... Shutting Down...");
144156
ToastThreadPool.INSTANCE.getService().shutdownNow();

src/main/java/jaci/openrio/toast/core/ToastConfiguration.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ public class ToastConfiguration {
1212

1313
static GroovyPreferences preferences;
1414

15+
/**
16+
* Initialize the Configuration. This creates the Preferences file
17+
* and all the properties required.
18+
*/
1519
public static void init() {
1620
preferences = new GroovyPreferences("Toast");
1721
for (Property prop : Property.values())
1822
prop.read(preferences);
1923
}
2024

25+
/**
26+
* Jet fuel can't melt steel beams.
27+
*/
2128
public static void jetfuel() {
2229
String fuel = Property.JET_FUEL.asString();
2330
if (!fuel.equalsIgnoreCase("steel beams"))
@@ -56,34 +63,59 @@ public static enum Property {
5663
this.comments = MathHelper.splitStringByWords(comment, 15);
5764
}
5865

66+
/**
67+
* Read the property from the GroovyPreferences file, with the default value and comments
68+
* if it doesn't exist.
69+
*/
5970
public void read(GroovyPreferences preferences) {
6071
value = preferences.getObject(key, defaultValue, comments);
6172
}
6273

74+
/**
75+
* Get the property as a Number object
76+
*/
6377
public Number asNumber() {
64-
return (Number) defaultValue;
78+
return (Number) value;
6579
}
6680

81+
/**
82+
* Get the property, casted to an Integer
83+
*/
6784
public int asInt() {
6885
return asNumber().intValue();
6986
}
7087

88+
/**
89+
* Get the property casted to a Double
90+
*/
7191
public double asDouble() {
7292
return asNumber().doubleValue();
7393
}
7494

95+
/**
96+
* Get the property, casted to a Float
97+
*/
7598
public float asFloat() {
7699
return asNumber().floatValue();
77100
}
78101

102+
/**
103+
* Get the property, casted to a Byte
104+
*/
79105
public byte asByte() {
80106
return asNumber().byteValue();
81107
}
82108

109+
/**
110+
* Get the property in String form
111+
*/
83112
public String asString() {
84113
return (String) value;
85114
}
86115

116+
/**
117+
* Get the property as a boolean.
118+
*/
87119
public boolean asBoolean() {
88120
return (boolean) value;
89121
}

src/main/java/jaci/openrio/toast/core/command/AbstractCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public abstract class AbstractCommand {
1212

1313
/**
1414
* Get the command name
15-
*
1615
* e.g. 'cmd' for a command such as 'cmd <your args>
1716
*/
1817
public abstract String getCommandName();

src/main/java/jaci/openrio/toast/core/command/CommandBus.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ public class CommandBus {
2222
public static List<AbstractCommand> commands = new Vector<>();
2323
public static List<FuzzyCommand> parsers = new Vector<>();
2424

25+
/**
26+
* Start the command bus. This is done by Toast, this shouldn't be triggered by Modules.
27+
* This also starts the Simulation Scanner to listen from an IDE's console
28+
*/
2529
public static void init() {
2630
if (ToastBootstrap.isSimulation)
2731
setupSim();
2832

2933
registerNatives();
3034
}
3135

36+
/**
37+
* Register the default commands that come with Toast by default.
38+
*/
3239
private static void registerNatives() {
3340
registerCommand(new CommandGroovyScript());
3441
registerCommand(new CommandUSB());
@@ -147,6 +154,9 @@ public static boolean messageRequested() {
147154
return nextLineRequested;
148155
}
149156

157+
/**
158+
* Setup the simulation environment scanner for the IDE's console
159+
*/
150160
private static void setupSim() {
151161
scanner = new Scanner(System.in);
152162
t = new Thread() {

src/main/java/jaci/openrio/toast/core/command/IHelpable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public interface IHelpable {
1010

1111
/**
1212
* Get the command name
13-
*
1413
* e.g. 'cmd' for a command such as 'cmd <your args>
1514
*/
1615
public String getCommandName();

src/main/java/jaci/openrio/toast/core/command/UsageException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ public UsageException(String usage) {
1515
this.usage = usage;
1616
}
1717

18+
/**
19+
* Get the usage of the command related to the Exception
20+
*/
1821
public String getUsage() {
1922
return usage;
2023
}
2124

25+
/**
26+
* Get the message of the exception used in logging.
27+
*/
2228
public String getMessage() {
2329
return "Invalid command usage. " + usage;
2430
}

src/main/java/jaci/openrio/toast/core/command/cmd/CommandExit.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,31 @@
99
* @author Jaci
1010
*/
1111
public class CommandExit extends AbstractCommand {
12+
13+
/**
14+
* Get the command name
15+
* e.g. 'cmd' for a command such as 'cmd <your args>
16+
*/
1217
@Override
1318
public String getCommandName() {
1419
return "exit";
1520
}
1621

22+
/**
23+
* Returns the 'alias' for the command (other names)
24+
*/
1725
public String[] getAlias() {
1826
return new String[] {"quit", ":q"};
1927
}
2028

29+
/**
30+
* Invoke the command if the name matches the one to be triggered
31+
* @param argLength The amount of arguments in the 'args' param
32+
* @param args The arguments the command was invoked with. This can be empty if
33+
* none were provided. Keep in mind this does NOT include the Command Name.
34+
* Args are separated by spaces
35+
* @param command The full command message
36+
*/
2137
@Override
2238
public void invokeCommand(int argLength, String[] args, String command) {
2339
Toast.getToast().shutdownSafely();

src/main/java/jaci/openrio/toast/core/command/cmd/CommandGroovyScript.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@
1919
* @author Jaci
2020
*/
2121
public class CommandGroovyScript extends FuzzyCommand implements IHelpable {
22+
23+
/**
24+
* Should this Command be invoked with the given message?
25+
*/
2226
@Override
2327
public boolean shouldInvoke(String message) {
2428
return message.startsWith("script ") || message.startsWith("script -c");
2529
}
2630

31+
/**
32+
* Invokes the command if {@link #shouldInvoke} returns true.
33+
* @param message The full command message. This is left un-parsed so you can handle
34+
* it yourself
35+
*/
2736
@Override
2837
public void invokeCommand(String message) {
2938
try {
@@ -52,11 +61,18 @@ public void run() {
5261
}
5362
}
5463

64+
/**
65+
* Get the command name
66+
* e.g. 'cmd' for a command such as 'cmd <your args>
67+
*/
5568
@Override
5669
public String getCommandName() {
5770
return "script";
5871
}
5972

73+
/**
74+
* Returns a help message to display with the 'help' command
75+
*/
6076
@Override
6177
public String getHelp() {
6278
return "Executes a groovy script on-the-fly. Run with -c to execute concurrently. Example: \"script -c println 'Hello World'\"";

0 commit comments

Comments
 (0)