From fad87d375f07d75fc2ed1282516549489f96afd0 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Thu, 7 Mar 2024 00:30:19 -0500 Subject: [PATCH] add proto files --- .../DifferentialDriveWheelPositionsProto.cpp | 32 +++++++++++++++++++ .../DifferentialDriveWheelPositionsProto.h | 19 +++++++++++ 2 files changed, 51 insertions(+) create mode 100644 wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp create mode 100644 wpimath/src/main/native/include/frc/kinematics/proto/DifferentialDriveWheelPositionsProto.h diff --git a/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp new file mode 100644 index 00000000000..642a8bceb4e --- /dev/null +++ b/wpimath/src/main/native/cpp/kinematics/proto/DifferentialDriveWheelPositionsProto.cpp @@ -0,0 +1,32 @@ +// 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 "frc/kinematics/proto/DifferentialDriveWheelPositionsProto.h" + +#include "kinematics.pb.h" + +google::protobuf::Message* wpi::Protobuf< + frc::DifferentialDriveWheelPositions>::New(google::protobuf::Arena* arena) { + return google::protobuf::Arena::CreateMessage< + wpi::proto::ProtobufDifferentialDriveWheelPositions>(arena); +} + +frc::DifferentialDriveWheelPositions +wpi::Protobuf::Unpack( + const google::protobuf::Message& msg) { + auto m = static_cast( + &msg); + return frc::DifferentialDriveWheelPositions{ + units::meters_per_second_t{m->left()}, + units::meters_per_second_t{m->right()}, + }; +} + +void wpi::Protobuf::Pack( + google::protobuf::Message* msg, + const frc::DifferentialDriveWheelPositions& value) { + auto m = static_cast(msg); + m->set_left(value.left.value()); + m->set_right(value.right.value()); +} diff --git a/wpimath/src/main/native/include/frc/kinematics/proto/DifferentialDriveWheelPositionsProto.h b/wpimath/src/main/native/include/frc/kinematics/proto/DifferentialDriveWheelPositionsProto.h new file mode 100644 index 00000000000..3cf44eaa40c --- /dev/null +++ b/wpimath/src/main/native/include/frc/kinematics/proto/DifferentialDriveWheelPositionsProto.h @@ -0,0 +1,19 @@ +// 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. + +#pragma once + +#include +#include + +#include "frc/kinematics/DifferentialDriveWheelPositions.h" + +template <> +struct WPILIB_DLLEXPORT wpi::Protobuf { + static google::protobuf::Message* New(google::protobuf::Arena* arena); + static frc::DifferentialDriveWheelPositions Unpack( + const google::protobuf::Message& msg); + static void Pack(google::protobuf::Message* msg, + const frc::DifferentialDriveWheelPositions& value); +};