Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Improvements for C++ simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger committed Jul 23, 2018
1 parent 3a16a4f commit c8e295a
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 111 deletions.
2 changes: 1 addition & 1 deletion fast_build.bat
@@ -1 +1 @@
gradlew build -x checkstyleMain -x checkstyleTest -x findbugsMain -x findbugsTest -x pmdMain -x pmdTest %1
gradlew build -x checkstyleMain -x checkstyleTest -x findbugsMain -x findbugsTest -x pmdMain -x pmdTest %*
5 changes: 3 additions & 2 deletions sim_adx_family/build.gradle
Expand Up @@ -13,7 +13,7 @@ ext
'edu.wpi.first.hal.sim.mockdata.ADXRS450_GyroDataJNI'
]

libraryBaseName = 'adx_family_jni'
libraryBaseName = 'adx_family'
librarySrcDirs = ['src/main/native/cpp/sim']
libraryHeaderDirs = ['src/main/native/cpp/sim']

Expand Down Expand Up @@ -88,7 +88,8 @@ dependencies {
wpilibNativeDeps project(':sim_adx_family').packageNativeFiles.outputs.files

//testCompile 'edu.wpi.first.hal:hal-java:' + allwpilibVersion()
testCompile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
testCompile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
testRuntime 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
testRuntime 'edu.wpi.first.ntcore:ntcore-java:' + getNtCoreVersion()
testRuntime 'edu.wpi.first.cscore:cscore-java:' + getCsCoreVersion()
testRuntime 'edu.wpi.first.ntcore:ntcore-jni:' + getNtCoreVersion() + ':all'
Expand Down
Expand Up @@ -10,21 +10,16 @@
import edu.wpi.first.wpilibj.SPI;
import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
import edu.wpi.first.wpiutil.RuntimeDetector;

public class TestLinking
{
@Test
public void testLinking()
{
if (!RuntimeDetector.isWindows())
{
JniLibraryResourceLoader.loadLibrary("uv");
}
JniLibraryResourceLoader.loadLibrary("wpiutil");
JniLibraryResourceLoader.loadLibrary("wpiHal");
JniLibraryResourceLoader.loadLibrary("halsim_adx_gyro_accelerometer");
JniLibraryResourceLoader.loadLibrary("adx_family_jni");
JniLibraryResourceLoader.loadLibrary("adx_family");
HAL.initialize(0, 0);

SPI.Port port = SPI.Port.kOnboardCS1;
Expand Down
4 changes: 3 additions & 1 deletion sim_extension_navx/build.gradle
Expand Up @@ -11,7 +11,7 @@ ext
[':sim_extension_navx', 'navx_simulator', 'shared']
]

libraryBaseName = 'navx_simulator_jni'
libraryBaseName = 'navx_simulator'
librarySrcDirs = [ 'src/main/native/sim']
libraryHeaderDirs = [ "src/main/native/include", ]

Expand Down Expand Up @@ -61,6 +61,7 @@ model {
}
components {
navx_simulator(NativeLibrarySpec) {
baseName = "navx_simulator_base"
sources {
cpp {
source {
Expand Down Expand Up @@ -93,6 +94,7 @@ dependencies {
//testCompile 'edu.wpi.first.hal:hal-java:' + allwpilibVersion()
testCompile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
//testRuntime 'edu.wpi.first.cameraserver:cameraserver-java:' + allwpilibVersion()
testRuntime 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
testCompile 'edu.wpi.first.ntcore:ntcore-java:' + getNtCoreVersion()
testRuntime 'edu.wpi.first.cscore:cscore-java:' + getCsCoreVersion()
testRuntime 'edu.wpi.first.ntcore:ntcore-jni:' + getNtCoreVersion() + ':all'
Expand Down
23 changes: 1 addition & 22 deletions snobot_sim/build.gradle
Expand Up @@ -62,7 +62,7 @@ model {
}
components {
snobotSimCpp(NativeLibrarySpec) {
baseName = 'snobotSimCpp'
baseName = 'snobot_sim'

apply from: "../create_version_file.gradle"
createCppVersion("src/main/native/cpp/SnobotSim", "SnobotSim", "SnobotSimHalVersion", getVersionName())
Expand All @@ -80,27 +80,6 @@ model {
}
}
}

standaloneSnobotSimBase(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs = ['src/standalone/native/cpp']
includes = ['**/*.cpp']
}
exportedHeaders {
srcDirs = ["src/standalone/native/include"]
}
lib project: ':snobot_sim', library: 'snobotSimCpp', linkage: 'shared'
lib project: ':sim_extension_navx', library: 'navx_simulator', linkage: 'shared'
}
}
}
}
binaries {
withType(StaticLibraryBinarySpec) {
it.buildable = false
}
}
}

Expand Down
47 changes: 7 additions & 40 deletions snobot_sim/publish.gradle
@@ -1,10 +1,9 @@

apply plugin: 'maven-publish'

def libraryZipBaseName = '_GROUP_com_snobot_simulator_snobot_sim_ID_snobot_sim_CLS'
def standaloneZipBaseName = '_GROUP_com_snobot_simulator_snobot_sim_ID_snobot_sim_standalone_CLS'
def zipBaseName = '_GROUP_com_snobot_simulator_snobot_sim_ID_snobot_sim_CLS'

task libraryCppSourcesZip(type: Zip) {
task cppSourcesZip(type: Zip) {
destinationDir = project.buildDir
classifier = "sources"

Expand All @@ -13,7 +12,7 @@ task libraryCppSourcesZip(type: Zip) {
}
}

task libraryCppHeadersZip(type: Zip) {
task cppHeadersZip(type: Zip) {
destinationDir = project.buildDir
classifier = "headers"

Expand All @@ -22,24 +21,6 @@ task libraryCppHeadersZip(type: Zip) {
}
}

task standaloneCppSourcesZip(type: Zip) {
destinationDir = project.buildDir
classifier = "sources"

from('src/standalone/native') {
into 'SnobotSim'
}
}

task standaloneCppHeadersZip(type: Zip) {
destinationDir = project.buildDir
classifier = "headers"

from('src/standalone/native/include') {
into '/'
}
}

model {
publishing {
repositories {
Expand All @@ -48,9 +29,8 @@ model {
}
}

def snobotSimTaskList = createComponentZipTasks($.components, 'snobotSimCpp', libraryZipBaseName, Zip, project, includeStandardZipFormat)
def snobotSimStandaloneTaskList = createComponentZipTasks($.components, 'standaloneSnobotSimBase', standaloneZipBaseName, Zip, project, includeStandardZipFormat)

def snobotSimTaskList = createComponentZipTasks($.components, 'snobotSimCpp', zipBaseName, Zip, project, includeStandardZipFormat)

publications {
snobot_sim(MavenPublication) {
groupId 'com.snobot.simulator'
Expand All @@ -61,21 +41,8 @@ model {
artifact it
}

artifact libraryCppHeadersZip
artifact libraryCppSourcesZip
}

snobot_sim_standalone(MavenPublication) {
groupId 'com.snobot.simulator'
artifactId 'snobot_sim_cpp_standalone'
version maven_version

snobotSimStandaloneTaskList.each {
artifact it
}

artifact standaloneCppHeadersZip
artifact standaloneCppSourcesZip
artifact cppHeadersZip
artifact cppSourcesZip
}
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
* Author: PJ
*/

#include "StandaloneSimulator.h"
#include "SnobotSim/StandaloneSimulator.h"

#include <thread>

Expand Down
Expand Up @@ -10,7 +10,8 @@

#include <iostream>

#include <StandaloneSimulator.h>
#include "SnobotSim/StandaloneSimulator.h"
#include "SnobotSim/Logging/SnobotLogger.h"

#define START_STANDALONE_SIMULATOR(_ClassName_, _SimulatorName_) \
int main() \
Expand Down
3 changes: 1 addition & 2 deletions snobot_sim_gui/build.gradle
Expand Up @@ -23,8 +23,6 @@ configurations.maybeCreate("wpilibNativeDeps")
dependencies {

// WPILib
compile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
compile 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
compile 'edu.wpi.first.cscore:cscore-java:' + getCsCoreVersion()
runtime 'edu.wpi.first.cscore:cscore-jni:' + getCsCoreVersion() + ':all'
compile 'edu.wpi.first.ntcore:ntcore-java:' + getNtCoreVersion()
Expand Down Expand Up @@ -64,6 +62,7 @@ dependencies {
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testRuntime 'org.junit.platform:junit-platform-launcher:1.2.0'
testCompile 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
runtime 'com.snobot.simulator:ctre_sim_override:' + getCtreSimVersion() + ':native-all'
testRuntime jar.outputs.files // Necessary for having resources in jar

Expand Down
1 change: 1 addition & 0 deletions snobot_sim_java/build.gradle
Expand Up @@ -36,6 +36,7 @@ dependencies {
testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testRuntime 'org.junit.platform:junit-platform-launcher:1.2.0'
testRuntime 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
testRuntime 'edu.wpi.first.ntcore:ntcore-jni:' + getNtCoreVersion() + ':all'
testRuntime 'edu.wpi.first.cscore:cscore-jni:' + getCsCoreVersion() + ':all'
testRuntime 'org.opencv:opencv-java:' + getWpilibOpencvVersion()
Expand Down
Expand Up @@ -3,23 +3,16 @@
import com.snobot.simulator.JniLibraryResourceLoader;

import edu.wpi.first.wpilibj.hal.HAL;
import edu.wpi.first.wpiutil.RuntimeDetector;

public class BaseSnobotJni
{
static
{
if (!RuntimeDetector.isWindows())
{
JniLibraryResourceLoader.loadLibrary("uv");
}

JniLibraryResourceLoader.loadLibrary("wpiutil");
JniLibraryResourceLoader.loadLibrary("wpiHal");
JniLibraryResourceLoader.loadLibrary("halsim_adx_gyro_accelerometer");
JniLibraryResourceLoader.loadLibrary("navx_simulator");
JniLibraryResourceLoader.loadLibrary("navx_simulator_jni");
JniLibraryResourceLoader.loadLibrary("adx_family_jni");
JniLibraryResourceLoader.loadLibrary("adx_family");
JniLibraryResourceLoader.loadLibrary("CTRE_PhoenixCCI");
JniLibraryResourceLoader.loadLibrary("temp_hal_interface_jni");

Expand Down
Expand Up @@ -8,7 +8,6 @@

import edu.wpi.first.hal.sim.mockdata.DriverStationDataJNI;
import edu.wpi.first.hal.sim.mockdata.SimulatorJNI;
import edu.wpi.first.wpilibj.hal.MatchInfoData;

public class JavaDriverStationWrapperAccessor implements DriverStationDataAccessor
{
Expand Down Expand Up @@ -85,13 +84,7 @@ public void setJoystickInformation(int aJoystickHandle, float[] aAxesArray, shor
@Override
public void setMatchInfo(String aEventName, MatchType aMatchType, int aMatchNumber, int aReplayNumber, String aGameSpecificMessage)
{
MatchInfoData data = new MatchInfoData();
data.eventName = aEventName;
data.matchType = aMatchType.ordinal();
data.matchNumber = aMatchNumber;
data.replayNumber = aReplayNumber;
data.gameSpecificMessage = aGameSpecificMessage;
DriverStationDataJNI.setMatchInfo(data);
DriverStationDataJNI.setMatchInfo(aEventName, aGameSpecificMessage, aMatchNumber, aReplayNumber, aMatchType.ordinal());
}

@Override
Expand Down
1 change: 1 addition & 0 deletions snobot_sim_jni/build.gradle
Expand Up @@ -60,6 +60,7 @@ dependencies {

testCompile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
//testCompile 'edu.wpi.first.hal:hal-java:' + allwpilibVersion()
testRuntime 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
testRuntime 'edu.wpi.first.ntcore:ntcore-jni:' + getNtCoreVersion() + ':all'
testRuntime 'edu.wpi.first.cscore:cscore-jni:' + getCsCoreVersion() + ':all'
testRuntime 'org.opencv:opencv-java:' + getWpilibOpencvVersion()
Expand Down
Expand Up @@ -2,8 +2,6 @@

import com.snobot.simulator.JniLibraryResourceLoader;

import edu.wpi.first.wpiutil.RuntimeDetector;

public abstract class BaseSimulatorJni // NOPMD
{
static
Expand All @@ -13,10 +11,6 @@ public abstract class BaseSimulatorJni // NOPMD

public static void initilaize()
{
if (!RuntimeDetector.isWindows())
{
JniLibraryResourceLoader.loadLibrary("uv");
}
JniLibraryResourceLoader.loadLibrary("wpiutil");
JniLibraryResourceLoader.loadLibrary("wpiHal");
JniLibraryResourceLoader.loadLibrary("halsim_adx_gyro_accelerometer");
Expand Down
1 change: 0 additions & 1 deletion snobot_sim_utilities/build.gradle
Expand Up @@ -7,7 +7,6 @@ ext
apply from: "${rootDir}/common/base_java_script.gradle"

dependencies {
compile 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
compile 'org.apache.logging.log4j:log4j-api:2.11.0'
compile 'org.apache.logging.log4j:log4j-core:2.11.0'

Expand Down
Expand Up @@ -73,6 +73,7 @@ public static boolean loadLibrary(String aLibraryname)
{
try
{
sLOGGER.log(Level.DEBUG, "Loading native library" + aLibraryname);
System.loadLibrary(aLibraryname);
return true;
}
Expand Down
@@ -1,7 +1,5 @@
package edu.wpi.first.hal.sim.mockdata;

import edu.wpi.first.wpilibj.hal.MatchInfoData;

public class DriverStationDataJNI
{
public static native void setEnabled(boolean b);
Expand All @@ -18,6 +16,6 @@ public class DriverStationDataJNI

public static native void setJoystickButtons(byte aJoystickHandle, int aButtonMask, int aButtonCount);

public static native void setMatchInfo(MatchInfoData info);
public static native void setMatchInfo(String eventName, String gameSpecificMessage, int matchNumber, int replayNumber, int matchType);

}
14 changes: 5 additions & 9 deletions temp_hal_interface/src/main/native/cpp/DriverStationDataJNI.cpp
@@ -1,6 +1,8 @@

#include <jni.h>

#include <cstring>

#include "MockData/DriverStationData.h"
#include "edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI.h"

Expand Down Expand Up @@ -111,22 +113,16 @@ Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setJoystickButtons
joystickButtons.buttons = buttons;
HALSIM_SetJoystickButtons(joystickNum, &joystickButtons);
}

/*
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI
* Method: setMatchInfo
* Signature: (Ljava/lang/Object;)V
* Signature: (Ljava/lang/String;Ljava/lang/String;III)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setMatchInfo
(JNIEnv* env, jclass, jobject matchInfo)
(JNIEnv* env, jclass, jstring eventName, jstring gameSpecificMessage,
jint matchNumber, jint replayNumber, jint matchType)
{
jstring eventName = (jstring)env->GetObjectField(matchInfo, env->GetFieldID(env->GetObjectClass(matchInfo), "eventName", "Ljava/lang/String;"));
jstring gameSpecificMessage = (jstring)env->GetObjectField(matchInfo, env->GetFieldID(env->GetObjectClass(matchInfo), "gameSpecificMessage", "Ljava/lang/String;"));
int matchNumber = env->GetIntField(matchInfo, env->GetFieldID(env->GetObjectClass(matchInfo), "matchNumber", "I"));
int replayNumber = env->GetIntField(matchInfo, env->GetFieldID(env->GetObjectClass(matchInfo), "replayNumber", "I"));
int matchType = env->GetIntField(matchInfo, env->GetFieldID(env->GetObjectClass(matchInfo), "matchType", "I"));

HAL_MatchInfo halMatchInfo;
halMatchInfo.eventName = const_cast<char*>(env->GetStringUTFChars(eventName, NULL));
halMatchInfo.gameSpecificMessage = const_cast<char*>(env->GetStringUTFChars(gameSpecificMessage, NULL));
Expand Down

0 comments on commit c8e295a

Please sign in to comment.