|
| 1 | +package jaci.openrio.toast.core.loader.verification; |
| 2 | + |
| 3 | +import groovy.lang.GroovyObject; |
| 4 | +import jaci.openrio.toast.core.Toast; |
| 5 | +import jaci.openrio.toast.core.loader.groovy.GroovyLoader; |
| 6 | +import jaci.openrio.toast.core.loader.module.ModuleContainer; |
| 7 | +import jaci.openrio.toast.core.loader.module.ModuleManager; |
| 8 | +import jaci.openrio.toast.core.loader.simulation.SimulationData; |
| 9 | +import jaci.openrio.toast.lib.log.Logger; |
| 10 | +import jaci.openrio.toast.lib.module.GroovyScript; |
| 11 | +import jaci.openrio.toast.lib.state.RobotState; |
| 12 | + |
| 13 | +import java.util.Map; |
| 14 | + |
| 15 | +/** |
| 16 | + * The Verification Worker. This class is called when the Toast Jar file is launched with the arguments -vf or -verify. |
| 17 | + * This thread runs through the Disabled -> Autonomous -> Teleoperated -> End lifecycle of the robot, and if any errors |
| 18 | + * or uncaught exceptions are encountered along the way, the program will exit with error code -1. If this is launched from |
| 19 | + * gradle using 'gradlew verify', the build will fail. This class is mostly used in Travis CI builds and exists to give |
| 20 | + * a proper 'yes, this code works' requirement to a successful build instead of the typical 'there's no compile errors' |
| 21 | + * requirement, giving repos an accurate look at how the build is passing. |
| 22 | + * |
| 23 | + * @author Jaci |
| 24 | + */ |
| 25 | +public class VerificationWorker extends Thread { |
| 26 | + |
| 27 | + static VerificationWorker worker; |
| 28 | + static Logger logger; |
| 29 | + |
| 30 | + public VerificationWorker() { |
| 31 | + this.setName("Verification Worker"); |
| 32 | + } |
| 33 | + |
| 34 | + public static void begin() { |
| 35 | + logger = new Logger("Verification", Logger.ATTR_DEFAULT); |
| 36 | + worker = new VerificationWorker(); |
| 37 | + worker.start(); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void run() { |
| 42 | + try { |
| 43 | + logger.info("Beginning Code Verification. Echoing environmental data..."); |
| 44 | + echoEnvironment(); |
| 45 | + logger.info("Starting Code Verification in 5 seconds..."); |
| 46 | + Thread.sleep(5 * 1000); |
| 47 | + logger.info("Transferring into Autonomous... (Switching to Teleop in 15 seconds)"); |
| 48 | + SimulationData.currentState = RobotState.AUTONOMOUS; |
| 49 | + Thread.sleep(15 * 1000); |
| 50 | + logger.info("Transferring into Teleoperated... (Switching to Disabled in 1 minute)"); |
| 51 | + SimulationData.currentState = RobotState.TELEOP; |
| 52 | + Thread.sleep(60 * 1000); |
| 53 | + logger.info("Disabling Robot... (Shutting Down in 10 seconds)"); |
| 54 | + SimulationData.currentState = RobotState.DISABLED; |
| 55 | + Thread.sleep(10 * 1000); |
| 56 | + logger.info("Code Verification Successful! Shutting Down..."); |
| 57 | + Toast.getToast().shutdownSafely(); |
| 58 | + } catch (Exception e) { |
| 59 | + logger.error("Exception encountered during verification: " + e); |
| 60 | + logger.exception(e); |
| 61 | + Toast.getToast().shutdownCrash(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + void echoEnvironment() { |
| 66 | + logger.info("\tLoaded Modules:"); |
| 67 | + for (ModuleContainer module : ModuleManager.getContainers()) |
| 68 | + logger.info("\t\t" + module.getDetails()); |
| 69 | + |
| 70 | + logger.info("\tLoaded Groovy Scripts:"); |
| 71 | + for (GroovyScript script : GroovyLoader.scripts) |
| 72 | + logger.info("\t\t" + script.getClass()); |
| 73 | + |
| 74 | + logger.info("\tLoaded Groovy Files:"); |
| 75 | + for (Map.Entry<String, GroovyObject> entry : GroovyLoader.groovyObjects.entrySet()) |
| 76 | + logger.info("\t\t" + entry.getKey() + " : " + entry.getValue()); |
| 77 | + |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | +} |
0 commit comments