Add sim hooks to set match data (#1191)

This commit is contained in:
PJ Reiniger
2018-07-22 22:43:24 -04:00
committed by Peter Johnson
parent c25d48fd0c
commit eb2c6e19f8
3 changed files with 47 additions and 10 deletions

View File

@@ -46,7 +46,7 @@ public class DriverStationDataJNI extends JNIWrapper {
public static native void setJoystickPOVs(byte joystickNum, short[] povsArray);
public static native void setJoystickButtons(byte joystickNum, int buttons, int count);
public static native void setMatchInfo(MatchInfoData info);
public static native void setMatchInfo(String eventName, String gameSpecificMessage, int matchNumber, int replayNumber, int matchType);
public static native void registerAllCallbacks(NotifyCallback callback, boolean initialNotify);
public static native void notifyNewData();

View File

@@ -7,10 +7,16 @@
#include <jni.h>
#include <cstring>
#include <wpi/jni_util.h>
#include "CallbackStore.h"
#include "edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI.h"
#include "mockdata/DriverStationData.h"
using namespace wpi::java;
extern "C" {
/*
@@ -388,12 +394,28 @@ Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setJoystickButtons
/*
* 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 info)
{}
(JNIEnv* env, jclass, jstring eventName, jstring gameSpecificMessage,
jint matchNumber, jint replayNumber, jint matchType)
{
JStringRef eventNameRef{env, eventName};
JStringRef gameSpecificMessageRef{env, gameSpecificMessage};
HAL_MatchInfo halMatchInfo;
std::snprintf(halMatchInfo.eventName, sizeof(halMatchInfo.eventName), "%s",
eventNameRef.c_str());
std::snprintf(reinterpret_cast<char*>(halMatchInfo.gameSpecificMessage),
sizeof(halMatchInfo.gameSpecificMessage), "%s",
gameSpecificMessageRef.c_str());
halMatchInfo.gameSpecificMessageSize = gameSpecificMessageRef.size();
halMatchInfo.matchType = (HAL_MatchType)matchType;
halMatchInfo.matchNumber = matchNumber;
halMatchInfo.replayNumber = replayNumber;
HALSIM_SetMatchInfo(&halMatchInfo);
}
/*
* Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI

View File

@@ -9,13 +9,28 @@ package edu.wpi.first.wpilibj.hal;
import org.junit.jupiter.api.Test;
import edu.wpi.first.hal.sim.mockdata.DriverStationDataJNI;
import edu.wpi.first.wpilibj.DriverStation.MatchType;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MatchInfoDataTest {
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
void matchInfoDataDoesNotThrow() {
HAL.initialize(500, 0);
MatchInfoData data = new MatchInfoData();
HAL.getMatchInfo(data);
// Nothing we can assert, so just make sure it didn't throw.
void testSetMatchInfo() {
MatchType matchType = MatchType.Qualification;
DriverStationDataJNI.setMatchInfo("Event Name", "Game Message", 174, 191, matchType.ordinal());
MatchInfoData outMatchInfo = new MatchInfoData();
HAL.getMatchInfo(outMatchInfo);
assertAll(
() -> assertEquals("Event Name", outMatchInfo.eventName),
() -> assertEquals(matchType.ordinal(), outMatchInfo.matchType),
() -> assertEquals(174, outMatchInfo.matchNumber),
() -> assertEquals(191, outMatchInfo.replayNumber),
() -> assertEquals("Game Message", outMatchInfo.gameSpecificMessage)
);
}
}