mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal] Update DS API to new format (#7977)
This commit is contained in:
@@ -136,11 +136,11 @@ Java_edu_wpi_first_hal_DriverStationJNI_nativeGetAllianceStation
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickAxesRaw
|
||||
* Signature: (B[I)I
|
||||
* Signature: (B[S)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickAxesRaw
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jintArray axesRawArray)
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jshortArray axesRawArray)
|
||||
{
|
||||
HAL_JoystickAxes axes;
|
||||
HAL_GetJoystickAxes(joystickNum, &axes);
|
||||
@@ -155,11 +155,7 @@ Java_edu_wpi_first_hal_DriverStationJNI_getJoystickAxesRaw
|
||||
return 0;
|
||||
}
|
||||
|
||||
jint raw[HAL_kMaxJoystickAxes];
|
||||
for (int16_t i = 0; i < axes.count; i++) {
|
||||
raw[i] = axes.raw[i];
|
||||
}
|
||||
env->SetIntArrayRegion(axesRawArray, 0, axes.count, raw);
|
||||
env->SetShortArrayRegion(axesRawArray, 0, axes.count, axes.raw);
|
||||
|
||||
return axes.count;
|
||||
}
|
||||
@@ -194,11 +190,11 @@ Java_edu_wpi_first_hal_DriverStationJNI_getJoystickAxes
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickPOVs
|
||||
* Signature: (B[S)I
|
||||
* Signature: (B[B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickPOVs
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jshortArray povsArray)
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray)
|
||||
{
|
||||
HAL_JoystickPOVs povs;
|
||||
HAL_GetJoystickPOVs(joystickNum, &povs);
|
||||
@@ -213,7 +209,8 @@ Java_edu_wpi_first_hal_DriverStationJNI_getJoystickPOVs
|
||||
return 0;
|
||||
}
|
||||
|
||||
env->SetShortArrayRegion(povsArray, 0, povs.count, povs.povs);
|
||||
env->SetByteArrayRegion(povsArray, 0, povs.count,
|
||||
reinterpret_cast<const jbyte*>(povs.povs));
|
||||
|
||||
return povs.count;
|
||||
}
|
||||
@@ -221,12 +218,12 @@ Java_edu_wpi_first_hal_DriverStationJNI_getJoystickPOVs
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getAllJoystickData
|
||||
* Signature: ([F[B[S[J)V
|
||||
* Signature: ([F[S[B[J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getAllJoystickData
|
||||
(JNIEnv* env, jclass cls, jfloatArray axesArray, jbyteArray rawAxesArray,
|
||||
jshortArray povsArray, jlongArray buttonsAndMetadataArray)
|
||||
(JNIEnv* env, jclass cls, jfloatArray axesArray, jshortArray rawAxesArray,
|
||||
jbyteArray povsArray, jlongArray buttonsAndMetadataArray)
|
||||
{
|
||||
HAL_JoystickAxes axes[HAL_kMaxJoysticks];
|
||||
HAL_JoystickPOVs povs[HAL_kMaxJoysticks];
|
||||
@@ -235,8 +232,8 @@ Java_edu_wpi_first_hal_DriverStationJNI_getAllJoystickData
|
||||
HAL_GetAllJoystickData(axes, povs, buttons);
|
||||
|
||||
CriticalJSpan<jfloat> jAxes(env, axesArray);
|
||||
CriticalJSpan<jbyte> jRawAxes(env, rawAxesArray);
|
||||
CriticalJSpan<jshort> jPovs(env, povsArray);
|
||||
CriticalJSpan<jshort> jRawAxes(env, rawAxesArray);
|
||||
CriticalJSpan<jbyte> jPovs(env, povsArray);
|
||||
CriticalJSpan<jlong> jButtons(env, buttonsAndMetadataArray);
|
||||
|
||||
static_assert(sizeof(jAxes[0]) == sizeof(axes[0].axes[0]));
|
||||
@@ -288,14 +285,14 @@ Java_edu_wpi_first_hal_DriverStationJNI_setJoystickOutputs
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_DriverStationJNI
|
||||
* Method: getJoystickIsXbox
|
||||
* Method: getJoystickIsGamepad
|
||||
* Signature: (B)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickIsXbox
|
||||
Java_edu_wpi_first_hal_DriverStationJNI_getJoystickIsGamepad
|
||||
(JNIEnv*, jclass, jbyte port)
|
||||
{
|
||||
return HAL_GetJoystickIsXbox(port);
|
||||
return HAL_GetJoystickIsGamepad(port);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -452,15 +452,15 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickAxes
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickPOVs
|
||||
* Signature: (B[S)V
|
||||
* Signature: (B[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickPOVs
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jshortArray povsArray)
|
||||
(JNIEnv* env, jclass, jbyte joystickNum, jbyteArray povsArray)
|
||||
{
|
||||
HAL_JoystickPOVs povs;
|
||||
{
|
||||
JSpan<const jshort> jArrayRef(env, povsArray);
|
||||
JSpan<const jbyte> jArrayRef(env, povsArray);
|
||||
auto arrayRef = jArrayRef.array();
|
||||
auto arraySize = arrayRef.size();
|
||||
int maxCount =
|
||||
@@ -701,14 +701,14 @@ Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickButtonCount
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_simulation_DriverStationDataJNI
|
||||
* Method: setJoystickIsXbox
|
||||
* Method: setJoystickIsGamepad
|
||||
* Signature: (IZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickIsXbox
|
||||
(JNIEnv*, jclass, jint stick, jboolean isXbox)
|
||||
Java_edu_wpi_first_hal_simulation_DriverStationDataJNI_setJoystickIsGamepad
|
||||
(JNIEnv*, jclass, jint stick, jboolean isGamepad)
|
||||
{
|
||||
HALSIM_SetJoystickIsXbox(stick, isXbox);
|
||||
HALSIM_SetJoystickIsGamepad(stick, isGamepad);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "hal/proto/ControlData.h"
|
||||
@@ -13,6 +10,8 @@ static_assert(sizeof(mrc::ControlFlags) == sizeof(uint32_t));
|
||||
|
||||
namespace {
|
||||
constexpr uint32_t EnabledMask = 0x1;
|
||||
constexpr uint32_t AutoMask = 0x2;
|
||||
constexpr uint32_t TestMask = 0x4;
|
||||
constexpr uint32_t EStopMask = 0x8;
|
||||
constexpr uint32_t FmsConnectedMask = 0x10;
|
||||
constexpr uint32_t DsConnectedMask = 0x20;
|
||||
@@ -20,6 +19,8 @@ constexpr uint32_t WatchdogActiveMask = 0x40;
|
||||
constexpr uint32_t AllianceMask = 0x1F80;
|
||||
|
||||
constexpr uint32_t EnabledShift = 0;
|
||||
constexpr uint32_t AutoShift = 1;
|
||||
constexpr uint32_t TestShift = 2;
|
||||
constexpr uint32_t EStopShift = 3;
|
||||
constexpr uint32_t FmsConnectedShift = 4;
|
||||
constexpr uint32_t DsConnectedShift = 5;
|
||||
@@ -31,6 +32,8 @@ constexpr uint32_t AllianceShift = 7;
|
||||
constexpr uint32_t FromControlWord(mrc::ControlFlags Word) {
|
||||
uint32_t Ret = 0;
|
||||
WORD_TO_INT(Enabled);
|
||||
WORD_TO_INT(Auto);
|
||||
WORD_TO_INT(Test);
|
||||
WORD_TO_INT(EStop);
|
||||
WORD_TO_INT(FmsConnected);
|
||||
WORD_TO_INT(DsConnected);
|
||||
@@ -46,6 +49,8 @@ constexpr uint32_t FromControlWord(mrc::ControlFlags Word) {
|
||||
constexpr mrc::ControlFlags ToControlWord(uint32_t Word) {
|
||||
mrc::ControlFlags Ret = {};
|
||||
INT_TO_WORD(Enabled);
|
||||
INT_TO_WORD(Auto);
|
||||
INT_TO_WORD(Test);
|
||||
INT_TO_WORD(EStop);
|
||||
INT_TO_WORD(FmsConnected);
|
||||
INT_TO_WORD(DsConnected);
|
||||
@@ -59,13 +64,12 @@ constexpr mrc::ControlFlags ToControlWord(uint32_t Word) {
|
||||
std::optional<mrc::ControlData> wpi::Protobuf<mrc::ControlData>::Unpack(
|
||||
InputStream& Stream) {
|
||||
wpi::UnpackCallback<mrc::Joystick, MRC_MAX_NUM_JOYSTICKS> JoystickCb;
|
||||
wpi::UnpackCallback<std::string> OpModeCb;
|
||||
|
||||
mrc_proto_ProtobufControlData Msg{
|
||||
.ControlWord = 0,
|
||||
.MatchTime = 0,
|
||||
.Joysticks = JoystickCb.Callback(),
|
||||
.OpMode = OpModeCb.Callback(),
|
||||
.CurrentOpMode = 0,
|
||||
};
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
@@ -73,16 +77,12 @@ std::optional<mrc::ControlData> wpi::Protobuf<mrc::ControlData>::Unpack(
|
||||
}
|
||||
|
||||
auto Joysticks = JoystickCb.Items();
|
||||
auto OpMode = OpModeCb.Items();
|
||||
|
||||
mrc::ControlData ControlData;
|
||||
|
||||
if (!OpMode.empty()) {
|
||||
ControlData.MoveOpMode(std::move(OpMode[0]));
|
||||
}
|
||||
|
||||
ControlData.ControlWord = ToControlWord(Msg.ControlWord);
|
||||
ControlData.MatchTime = Msg.MatchTime;
|
||||
ControlData.CurrentOpMode = Msg.CurrentOpMode;
|
||||
ControlData.SetJoystickCount(Joysticks.size());
|
||||
|
||||
for (size_t i = 0; i < ControlData.GetJoystickCount(); i++) {
|
||||
@@ -94,8 +94,6 @@ std::optional<mrc::ControlData> wpi::Protobuf<mrc::ControlData>::Unpack(
|
||||
|
||||
bool wpi::Protobuf<mrc::ControlData>::Pack(OutputStream& Stream,
|
||||
const mrc::ControlData& Value) {
|
||||
std::string_view OpMode = Value.GetOpMode();
|
||||
wpi::PackCallback OpModeCb{&OpMode};
|
||||
std::span<const mrc::Joystick> Sticks = Value.Joysticks();
|
||||
wpi::PackCallback Joysticks{Sticks};
|
||||
|
||||
@@ -103,7 +101,7 @@ bool wpi::Protobuf<mrc::ControlData>::Pack(OutputStream& Stream,
|
||||
.ControlWord = FromControlWord(Value.ControlWord),
|
||||
.MatchTime = Value.MatchTime,
|
||||
.Joysticks = Joysticks.Callback(),
|
||||
.OpMode = OpModeCb.Callback(),
|
||||
.CurrentOpMode = Value.CurrentOpMode,
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
@@ -111,14 +109,14 @@ bool wpi::Protobuf<mrc::ControlData>::Pack(OutputStream& Stream,
|
||||
|
||||
std::optional<mrc::Joystick> wpi::Protobuf<mrc::Joystick>::Unpack(
|
||||
InputStream& Stream) {
|
||||
wpi::UnpackCallback<float, MRC_MAX_NUM_AXES> AxesCb;
|
||||
wpi::UnpackCallback<int16_t, MRC_MAX_NUM_POVS> PovsCb;
|
||||
wpi::UnpackCallback<int16_t, MRC_MAX_NUM_AXES> AxesCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickData Msg{
|
||||
.ButtonCount = 0,
|
||||
.Buttons = 0,
|
||||
.Axes = AxesCb.Callback(),
|
||||
.POVs = PovsCb.Callback(),
|
||||
.POVCount = 0,
|
||||
.POVs = 0,
|
||||
};
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
@@ -126,7 +124,6 @@ std::optional<mrc::Joystick> wpi::Protobuf<mrc::Joystick>::Unpack(
|
||||
}
|
||||
|
||||
auto Axes = AxesCb.Items();
|
||||
auto Povs = PovsCb.Items();
|
||||
|
||||
mrc::Joystick Joystick;
|
||||
Joystick.Axes.SetCount(Axes.size());
|
||||
@@ -135,28 +132,36 @@ std::optional<mrc::Joystick> wpi::Protobuf<mrc::Joystick>::Unpack(
|
||||
Joystick.Axes.Axes()[i] = Axes[i];
|
||||
}
|
||||
|
||||
Joystick.Povs.SetCount(Povs.size());
|
||||
|
||||
for (size_t i = 0; i < Joystick.Povs.GetCount(); i++) {
|
||||
Joystick.Povs.Povs()[i] = Povs[i];
|
||||
}
|
||||
|
||||
Joystick.Buttons.SetCount(Msg.ButtonCount);
|
||||
Joystick.Buttons.Buttons = Msg.Buttons;
|
||||
|
||||
Joystick.Povs.SetCount(Msg.POVCount);
|
||||
uint32_t PovsStore = Msg.POVs;
|
||||
for (size_t i = 0; i < Joystick.Povs.GetCount(); i++) {
|
||||
uint8_t Val = PovsStore & 0xF;
|
||||
PovsStore >>= 4;
|
||||
Joystick.Povs.Povs()[i] = Val;
|
||||
}
|
||||
|
||||
return Joystick;
|
||||
}
|
||||
|
||||
bool wpi::Protobuf<mrc::Joystick>::Pack(OutputStream& Stream,
|
||||
const mrc::Joystick& Value) {
|
||||
wpi::PackCallback AxesCb{Value.Axes.Axes()};
|
||||
wpi::PackCallback PovsCb{Value.Povs.Povs()};
|
||||
|
||||
uint32_t PovsStore = 0;
|
||||
for (size_t i = 0; i < Value.Povs.GetCount(); i++) {
|
||||
PovsStore <<= 4;
|
||||
PovsStore |= Value.Povs.Povs()[i] & 0xF;
|
||||
}
|
||||
|
||||
mrc_proto_ProtobufJoystickData Msg{
|
||||
.ButtonCount = static_cast<uint32_t>(Value.Buttons.GetCount()),
|
||||
.Buttons = Value.Buttons.Buttons,
|
||||
.Axes = AxesCb.Callback(),
|
||||
.POVs = PovsCb.Callback(),
|
||||
.POVCount = static_cast<uint32_t>(Value.Povs.GetCount()),
|
||||
.POVs = PovsStore,
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
|
||||
@@ -41,8 +41,9 @@ wpi::Protobuf<mrc::JoystickDescriptor>::Unpack(InputStream& Stream) {
|
||||
OutputData.SetPovsCount(Msg.PovCount);
|
||||
OutputData.SetButtonsCount(Msg.ButtonCount);
|
||||
|
||||
OutputData.IsXbox = Msg.IsXbox ? 1 : 0;
|
||||
OutputData.IsGamepad = Msg.IsGamepad ? 1 : 0;
|
||||
OutputData.Type = Msg.JoystickType;
|
||||
OutputData.RumbleCount = Msg.RumbleCount;
|
||||
|
||||
return OutputData;
|
||||
}
|
||||
@@ -58,10 +59,11 @@ bool wpi::Protobuf<mrc::JoystickDescriptor>::Pack(
|
||||
mrc_proto_ProtobufJoystickDescriptor Msg{
|
||||
.JoystickName = JoystickNameCb.Callback(),
|
||||
.AxisTypes = AxisTypesCb.Callback(),
|
||||
.IsXbox = Value.IsXbox ? true : false,
|
||||
.IsGamepad = Value.IsGamepad ? true : false,
|
||||
.JoystickType = Value.Type,
|
||||
.ButtonCount = static_cast<int32_t>(Value.GetButtonsCount()),
|
||||
.PovCount = static_cast<int32_t>(Value.GetPovsCount()),
|
||||
.RumbleCount = Value.RumbleCount,
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "hal/proto/JoystickOutputData.h"
|
||||
|
||||
std::optional<mrc::JoystickOutputData>
|
||||
wpi::Protobuf<mrc::JoystickOutputData>::Unpack(InputStream& Stream) {
|
||||
mrc_proto_ProtobufJoystickOutputData Msg;
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return mrc::JoystickOutputData{
|
||||
.HidOutputs = Msg.HidOutputs,
|
||||
.LeftRumble = Msg.LeftRumble,
|
||||
.RightRumble = Msg.RightRumble,
|
||||
};
|
||||
}
|
||||
|
||||
bool wpi::Protobuf<mrc::JoystickOutputData>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickOutputData& Value) {
|
||||
mrc_proto_ProtobufJoystickOutputData Msg{
|
||||
.HidOutputs = Value.HidOutputs,
|
||||
.LeftRumble = Value.LeftRumble,
|
||||
.RightRumble = Value.RightRumble,
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
42
hal/src/main/native/cpp/proto/JoystickRumbleDataProto.cpp
Normal file
42
hal/src/main/native/cpp/proto/JoystickRumbleDataProto.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "hal/proto/JoystickRumbleData.h"
|
||||
|
||||
std::optional<mrc::JoystickRumbleData>
|
||||
wpi::Protobuf<mrc::JoystickRumbleData>::Unpack(InputStream& Stream) {
|
||||
wpi::UnpackCallback<uint16_t, MRC_MAX_NUM_RUMBLE> RumbleCb;
|
||||
|
||||
mrc_proto_ProtobufJoystickRumbleData Msg{
|
||||
.Value = RumbleCb.Callback(),
|
||||
};
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Rumbles = RumbleCb.Items();
|
||||
|
||||
mrc::JoystickRumbleData Rumble;
|
||||
Rumble.SetCount(Rumbles.size());
|
||||
|
||||
for (size_t i = 0; i < Rumble.GetCount(); i++) {
|
||||
Rumble.Rumbles()[i] = Rumbles[i];
|
||||
}
|
||||
|
||||
return Rumble;
|
||||
}
|
||||
|
||||
bool wpi::Protobuf<mrc::JoystickRumbleData>::Pack(
|
||||
OutputStream& Stream, const mrc::JoystickRumbleData& Value) {
|
||||
wpi::PackCallback RumbleCb{Value.Rumbles()};
|
||||
|
||||
mrc_proto_ProtobufJoystickRumbleData Msg{
|
||||
.Value = RumbleCb.Callback(),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
76
hal/src/main/native/cpp/proto/OpModeProto.cpp
Normal file
76
hal/src/main/native/cpp/proto/OpModeProto.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "hal/proto/OpMode.h"
|
||||
|
||||
std::optional<mrc::OpMode> wpi::Protobuf<mrc::OpMode>::Unpack(
|
||||
InputStream& Stream) {
|
||||
wpi::UnpackCallback<std::string> NameCb;
|
||||
|
||||
mrc_proto_ProtobufOpMode Msg;
|
||||
Msg.Name = NameCb.Callback();
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Name = NameCb.Items();
|
||||
|
||||
if (Name.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
mrc::OpMode OutputData;
|
||||
OutputData.MoveName(std::move(Name[0]));
|
||||
|
||||
OutputData.Hash = Msg.Hash;
|
||||
|
||||
return OutputData;
|
||||
}
|
||||
|
||||
bool wpi::Protobuf<mrc::OpMode>::Pack(OutputStream& Stream,
|
||||
const mrc::OpMode& Value) {
|
||||
std::string_view EventNameStr = Value.GetName();
|
||||
wpi::PackCallback EventName{&EventNameStr};
|
||||
|
||||
mrc_proto_ProtobufOpMode Msg{
|
||||
.Hash = Value.Hash,
|
||||
.Name = EventName.Callback(),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
|
||||
std::optional<std::vector<mrc::OpMode>>
|
||||
wpi::Protobuf<std::vector<mrc::OpMode>>::Unpack(InputStream& Stream) {
|
||||
wpi::StdVectorUnpackCallback<mrc::OpMode> ModesCb;
|
||||
ModesCb.SetLimits(DecodeLimits::Add);
|
||||
|
||||
mrc_proto_ProtobufAvailableOpModes Msg;
|
||||
Msg.Modes = ModesCb.Callback();
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return ModesCb.Vec();
|
||||
}
|
||||
|
||||
bool wpi::Protobuf<std::vector<mrc::OpMode>>::Pack(
|
||||
OutputStream& Stream, const std::vector<mrc::OpMode>& Value) {
|
||||
std::span<const mrc::OpMode> ModesSpan = Value;
|
||||
wpi::PackCallback Modes{ModesSpan};
|
||||
|
||||
mrc_proto_ProtobufAvailableOpModes Msg{
|
||||
.Modes = Modes.Callback(),
|
||||
};
|
||||
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "hal/proto/VersionInfo.h"
|
||||
|
||||
std::optional<mrc::VersionInfo> wpi::Protobuf<mrc::VersionInfo>::Unpack(
|
||||
InputStream& Stream) {
|
||||
wpi::UnpackCallback<std::string> NameCb;
|
||||
wpi::UnpackCallback<std::string> VersionCb;
|
||||
|
||||
mrc_proto_ProtobufVersionInfo Msg{
|
||||
.DeviceId = 0,
|
||||
.Name = NameCb.Callback(),
|
||||
.Version = VersionCb.Callback(),
|
||||
};
|
||||
|
||||
if (!Stream.Decode(Msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto Name = NameCb.Items();
|
||||
auto Version = VersionCb.Items();
|
||||
|
||||
if (Name.empty() || Version.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
mrc::VersionInfo ToRet;
|
||||
|
||||
ToRet.DeviceId = Msg.DeviceId;
|
||||
ToRet.MoveName(std::move(Name[0]));
|
||||
ToRet.MoveVersion(std::move(Version[0]));
|
||||
|
||||
return ToRet;
|
||||
}
|
||||
|
||||
bool wpi::Protobuf<mrc::VersionInfo>::Pack(OutputStream& Stream,
|
||||
const mrc::VersionInfo& Value) {
|
||||
std::string_view NameView = Value.GetName();
|
||||
std::string_view VersionView = Value.GetVersion();
|
||||
wpi::PackCallback NameCb{&NameView};
|
||||
wpi::PackCallback VersionCb{&VersionView};
|
||||
|
||||
mrc_proto_ProtobufVersionInfo Msg{
|
||||
.DeviceId = Value.DeviceId,
|
||||
.Name = NameCb.Callback(),
|
||||
.Version = VersionCb.Callback(),
|
||||
};
|
||||
return Stream.Encode(Msg);
|
||||
}
|
||||
Reference in New Issue
Block a user