Skip to content

Commit

Permalink
Merge pull request #1 from Andover-Robotics/master
Browse files Browse the repository at this point in the history
Pulled FTC SDK v4.0 from ARC-Core
  • Loading branch information
a-zeng authored Sep 16, 2018
2 parents c40072e + 56cff27 commit 09dfe2b
Show file tree
Hide file tree
Showing 292 changed files with 39,381 additions and 1,581 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Thumbs.db
build/

# Uniform code style
!.idea/codeStyles
!.idea/codeStyles/*
*ASUS_PC_01*

.flooignore
.floo
gradle/wrapper/gradle-wrapper.properties
51 changes: 37 additions & 14 deletions ARCCore/ARCCore.iml → ARC-Core
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
Expand All @@ -56,6 +57,13 @@
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
Expand All @@ -78,27 +86,42 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/typedefs.txt" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="Gradle: FtcCommon-release:@aar" level="project" />
<orderEntry type="library" exported="" name="Gradle: Blocks-release:@aar" level="project" />
<orderEntry type="library" exported="" name="Gradle: RobotCore-release:@aar" level="project" />
<orderEntry type="library" exported="" name="Gradle: Inspection-release:@aar" level="project" />
<orderEntry type="library" exported="" name="Gradle: Analytics-release:@aar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="Gradle: junit:junit:4.12@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" exported="" name="Gradle: WirelessP2p-release:@aar" level="project" />
<orderEntry type="library" exported="" name="Gradle: Hardware-release:@aar" level="project" />
<orderEntry type="module" module-name="FtcRobotController" exported="" />
<orderEntry type="library" name="Gradle: Blocks-release:@aar" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.objenesis:objenesis:2.6@jar" level="project" />
<orderEntry type="library" name="Gradle: Inspection-release:@aar" level="project" />
<orderEntry type="library" name="Gradle: Analytics-release:@aar" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: net.bytebuddy:byte-buddy:1.8.5@jar" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: junit:junit:4.12@jar" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.mockito:mockito-core:2.18.3@jar" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" name="Gradle: Hardware-release:@aar" level="project" />
<orderEntry type="library" name="Gradle: FtcCommon-release:@aar" level="project" />
<orderEntry type="library" name="Gradle: RobotCore-release:@aar" level="project" />
<orderEntry type="library" name="Gradle: WirelessP2p-release:@aar" level="project" />
<orderEntry type="library" scope="TEST" name="Gradle: net.bytebuddy:byte-buddy-agent:1.8.5@jar" level="project" />
<orderEntry type="module" module-name="FtcRobotController" />
</component>
</module>
</module>
20 changes: 10 additions & 10 deletions ARCCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ android {
}

compileSdkVersion 23
buildToolsVersion '25.0.3'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
Expand All @@ -25,17 +24,18 @@ repositories {
dirs '../libs'
}

mavenCentral()
jcenter()
}

dependencies {
compile project(':FtcRobotController')
compile (name: 'RobotCore-release', ext: 'aar')
compile (name: 'Hardware-release', ext: 'aar')
compile (name: 'FtcCommon-release', ext: 'aar')
compile (name:'Analytics-release', ext:'aar')
compile (name:'WirelessP2p-release', ext:'aar')

testCompile 'junit:junit:4.12'
implementation project(':FtcRobotController')
implementation (name: 'RobotCore-release', ext: 'aar')
implementation (name: 'Hardware-release', ext: 'aar')
implementation (name: 'FtcCommon-release', ext: 'aar')
implementation (name:'Analytics-release', ext:'aar')
implementation (name:'WirelessP2p-release', ext:'aar')

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.18.3'
}

This file was deleted.

4 changes: 0 additions & 4 deletions ARCCore/src/main/com/andoverrobotics/core/Main.java

This file was deleted.

213 changes: 213 additions & 0 deletions ARCCore/src/main/com/andoverrobotics/core/config/Configuration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package com.andoverrobotics.core.config;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;

/**
* A key-value mapping abstraction that allows for the retrieval of values in a variety of types.
* <p> <h2>Schemas</h2> Configuration Schemas are small classes that only contain non-private fields
* that are declared in compatible types. The following is an example:
* <pre>{@code
* class ExampleSchema {
* int numberOfBlocks;
* double servoPositionAtRest;
* boolean usePredefinedAutonomous;
* String selectedProcedureName;
* }
* }</pre>
* <p> Each field in a schema corresponds to an entry in the configuration map with the same name.
* For the example above, a valid configuration map would be as follows, formatted in Properties
* style:
* <pre>{@code
* numberOfBlocks=4
* servoPositionAtRest=0.51
* usePredefinedAutonomous=false
* selectedProcedureName=auto2
* }</pre>
* <p>
*
* @see InvalidFormatError
* @see InvalidSchemaError
*/
public final class Configuration {

private static final String PROPERTIES_DIRECTORY = "/storage/self/primary/FIRST/config";

private final Map<String, String> map;

private Configuration(Map<String, String> map) {
this.map = map;
}

/**
* Reads a file with the given name from the standard directory for configuration file storage,
* parses it into {@link Properties} format, and returns a new instance of {@link Configuration}
* with the parsed mapping.
* @param fileName Name of the file to be read
* @return The Configuration instance whose entries have been read from the given file
* @throws IOException If the file with the given name cannot be read
*/
public static Configuration fromPropertiesFile(String fileName)
throws IOException {
return fromProperties(new FileReader(new File(PROPERTIES_DIRECTORY, fileName)));
}
/**
* Parses data from the given {@link Reader} in Java Properties format, and then creates a new
* instance of {@link Configuration} from the parsed result.
* @param file The Reader from which to parse data
* @return The new Configuration instance
* @throws IOException if an error is encountered while reading from the given Reader
*/
public static Configuration fromProperties(Reader file)
throws IOException {

Properties props = new Properties();
props.load(file);
// Java's sloppiness here. Properties was done in a rush and wasn't adapted to generics.
return Configuration.from(new HashMap(props));
}

/**
* Creates a new instance of {@link Configuration} from the given String-to-String {@link Map}.
*
* @param map The map to apply to the new Configuration instance
* @return The new Configuration instance
*/
public static Configuration from(Map<String, String> map) {
return new Configuration(map);
}

/**
* Loads the entries from this Configuration to the given Schema instance.
* @param schemaInstance Configuration Schema instance into which the entries are loaded
* @param <T> Type of the given Schema instance
* @return The given Schema instance with its fields populated
* @throws InvalidSchemaError if the type of the given Schema instance is not suitable for loading
*/
public <T> T loadToSchema(T schemaInstance) {
Class<?> schemaClass = schemaInstance.getClass();
try {
for (Field field : schemaClass.getDeclaredFields()) {
populateSchemaField(schemaInstance, field);
}
return schemaInstance;
} catch (Exception reflectionError) {
throw new InvalidSchemaError(schemaClass, reflectionError);
}
}

/**
* Retrieves the value of the given key in the mapping, parsed as an integer.
* @param key The key for the requesting value
* @return The parsed integer represented by the key's corresponding value
* @throws InvalidFormatError if the given key's corresponding value cannot be parsed as an integer
* @throws NoSuchFieldError if the given key does not exist in this Configuration instance's mapping
*/
public int getInt(String key) {
String strValue = getString(key);
try {
return Integer.parseInt(strValue);
} catch (NumberFormatException numberException) {
throw new InvalidFormatError(key, strValue, "int");
}
}

/**
* Retrieves the value of the given key in the mapping, parsed as a double.
* @param key The key for the requesting value
* @return The parsed double represented by the key's corresponding value
* @throws InvalidFormatError if the given key's corresponding value cannot be parsed as a double
* @throws NoSuchFieldError if the given key does not exist in this Configuration instance's mapping
*/
public double getDouble(String key) {
String strValue = getString(key);
try {
return Double.parseDouble(strValue);
} catch (NumberFormatException numberException) {
throw new InvalidFormatError(key, strValue, "double");
}
}

/**
* Retrieves the value of the given key in the mapping, parsed as a boolean. Accepted values are
* <code>"true"</code> and <code>"false"</code>, case-insensitive.
* @param key The key for the requesting value
* @return The parsed boolean represented by the key's corresponding value
* @throws InvalidFormatError if the given key's corresponding value is not an accepted value
* @throws NoSuchFieldError if the given key does not exist in this Configuration instance's mapping
*/
public boolean getBoolean(String key) {
String value = getString(key);
if (value.equalsIgnoreCase("true")) {
return true;
} else if (value.equalsIgnoreCase("false")) {
return false;
} else {
throw new InvalidFormatError(key, value, "boolean");
}
}

/**
* Retrieves the value of the given key in the mapping.
* @param key The key for the requesting value
* @return The key's corresponding value
* @throws NoSuchFieldError if the given key does not exist in this mapping
*/
public String getString(String key) {
String value = map.get(key);
if (value == null) {
throw new NoSuchFieldError(key);
}
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Configuration that = (Configuration) o;
return Objects.equals(map, that.map);
}

@Override
public int hashCode() {
return Objects.hash(map);
}

private <T> void populateSchemaField(T schemaInstance, Field field)
throws IllegalAccessException {

String fieldName = field.getName();
String typeName = field.getType().getCanonicalName();

switch (typeName) {
case "int":
field.setInt(schemaInstance, getInt(fieldName));
break;
case "double":
field.setDouble(schemaInstance, getDouble(fieldName));
break;
case "boolean":
field.setBoolean(schemaInstance, getBoolean(fieldName));
break;
case "java.lang.String":
field.set(schemaInstance, getString(fieldName));
break;
default:
throw new InvalidSchemaError(schemaInstance.getClass(),
new UnsupportedOperationException("Invalid type: " + typeName));
}
}

}
Loading

0 comments on commit 09dfe2b

Please sign in to comment.