Skip to content

Commit 3f5aa4f

Browse files
Merge pull request #14 from ncsurobotics/pool_test
Raw and Local Minimal Control
2 parents a81b4e7 + 8648dca commit 3f5aa4f

25 files changed

+1073
-9
lines changed

.classpath

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="app/src/main/java"/>
4+
<classpathentry kind="src" path="app/src/test/java"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
6+
<attributes>
7+
<attribute name="module" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="lib" path="gradle/wrapper/gradle-wrapper.jar"/>
11+
<classpathentry kind="lib" path="C:/Users/vaibh/Downloads/jSerialComm-2.9.2.jar"/>
12+
<classpathentry kind="output" path="bin"/>
13+
</classpath>

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.gradle
22
/build/
33

4+
*.class
5+
46
# Ignore Gradle GUI config
57
gradle-app.setting
68

@@ -15,3 +17,5 @@ gradle-app.setting
1517

1618
# Ignore Gradle build output directory
1719
build
20+
/bin/
21+
.idea

.project

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>SW8S-Java</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
<filteredResources>
24+
<filter>
25+
<id>1665775838382</id>
26+
<name></name>
27+
<type>30</type>
28+
<matcher>
29+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
30+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31+
</matcher>
32+
</filter>
33+
</filteredResources>
34+
</projectDescription>

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}
2.71 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

app/build.gradle

+31-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
plugins {
1010
// Apply the application plugin to add support for building a CLI application in Java.
1111
id 'application'
12+
// Support for generating project metadata
13+
id 'eclipse'
1214
}
1315

16+
mainClassName = "org.aquapackrobotics.sw8s.App"
17+
1418
java {
1519
// Set Java version to 11
1620
// https://docs.gradle.org/current/userguide/toolchains.html
@@ -19,6 +23,31 @@ java {
1923
}
2024
}
2125

26+
run {
27+
standardInput = System.in
28+
}
29+
30+
jar {
31+
manifest {
32+
attributes(
33+
'Main-Class': "$mainClassName"
34+
)
35+
}
36+
}
37+
38+
task fatJar(type: Jar) {
39+
manifest.from jar.manifest
40+
classifier = 'all'
41+
from {
42+
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
43+
} {
44+
exclude "META-INF/*.SF"
45+
exclude "META-INF/*.DSA"
46+
exclude "META-INF/*.RSA"
47+
}
48+
with jar
49+
}
50+
2251
repositories {
2352
// Use Maven Central for resolving dependencies.
2453
mavenCentral()
@@ -30,9 +59,10 @@ dependencies {
3059

3160
// This dependency is used by the application.
3261
implementation 'com.google.guava:guava:31.0.1-jre'
62+
implementation 'com.fazecast:jSerialComm:[2.0.0,3.0.0)'
3363
}
3464

3565
application {
3666
// Define the main class for the application.
37-
mainClass = 'org.aquapackrobotics.sw8s.App'
67+
mainClass = mainClassName
3868
}

app/src/main/java/org/aquapackrobotics/sw8s/App.java

+51-5
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,67 @@
55

66
import java.util.concurrent.ScheduledThreadPoolExecutor;
77

8-
import org.aquapackrobotics.sw8s.missions.Mission;
9-
import org.aquapackrobotics.sw8s.missions.AutoMission;
8+
import org.aquapackrobotics.sw8s.missions.*;
9+
10+
import java.util.concurrent.*;
1011

1112
public class App {
1213

1314
static final int POOLSIZE = 1;
14-
15+
1516
public String getGreeting() {
1617
return "Hello World!";
1718
}
1819

19-
public static void main(String[] args) {
20+
public static void main(String[] args) throws ExecutionException, InterruptedException {
2021
ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(POOLSIZE);
22+
String helpFlag[] = {"\nBasic Utility:", "\n'test' -- The Command Flag used in Testing", "'help' or 'h' -- displays list of command flags", "\nStates:", "\n"};
23+
System.out.println("Basic Format: gradle run --args='_'");
24+
for (String str: args) {
25+
switch (str) {
26+
case "--test":
27+
System.out.println("Yay! it worked!");
28+
break;
29+
case "-h":
30+
for(int i = 0; i < helpFlag.length; i++){
31+
System.out.println(helpFlag[i]);
32+
}
33+
case "--help":
34+
for(int i = 0; i < helpFlag.length; i++){
35+
System.out.println(helpFlag[i]);
36+
}
37+
break;
38+
case "--raw_test":
39+
Mission missionRaw_Test = (Mission) new Raw_Test(pool);
40+
missionRaw_Test.run();
41+
break;
42+
case "--local_test":
43+
Mission missionLocal_Test = (Mission) new Local_Test(pool);
44+
missionLocal_Test.run();
45+
break;
46+
// case "-s1":
47+
// executeState(State1);
48+
// break;
49+
// case "-s2":
50+
// executeState(State2);
51+
// break;
52+
// case "-s3":
53+
// executeState(State3);
54+
// break;
55+
case "manual":
56+
Mission missionManual = (Mission) new ManualMission(pool);
57+
missionManual.run();
58+
break;
59+
default:
60+
Mission missionAuto = (Mission) new AutoMission(pool);
61+
missionAuto.run();
62+
break;
63+
64+
}
65+
}
66+
2167
Mission mission = (Mission) new AutoMission(pool);
2268

23-
mission.run();
69+
2470
}
2571
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.aquapackrobotics.sw8s.comms;
2+
3+
/**
4+
* Comms-only helper class to encode CRC.
5+
*/
6+
class CRC
7+
{
8+
/**
9+
* Calculate 16-bit CRC (CCITT-FALSE) of the given data
10+
* @param data Data to calculate crc of
11+
* @param len The length to calculate the CRC of
12+
* @return Calculated crc
13+
*/
14+
static short CITT16_False(byte[] data, int len) {
15+
short crc = (short) 0xFFFF;
16+
int pos = 0;
17+
while (pos < len) {
18+
byte b = data[pos];
19+
for(int i = 0; i < 8; ++i){
20+
byte bit = ((b >> (7 - i) & 1) == 1) ? (byte) 1 : (byte) 0;
21+
byte c15 = ((crc >> 15 & 1) == 1) ? (byte) 1 : (byte) 0;
22+
crc <<= 1;
23+
if ((c15 ^ bit) != 0) {
24+
crc ^= 0x1021;
25+
}
26+
}
27+
28+
pos++;
29+
}
30+
return crc;
31+
}
32+
}

0 commit comments

Comments
 (0)