mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
[sim] Add XRP-specific plugin (#5631)
Provides an implementation of a XRP-specific plugin that sends binary messages over UDP (to account for the less performant hardware on the XRP). This plugin leverages the work already done for the WebSocket protocol and does a translation to/from JSON/binary.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// 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 "WSProvider_HAL.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <string_view>
|
||||
|
||||
#include <hal/Extensions.h>
|
||||
#include <hal/HAL.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/simulation/MockHooks.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
namespace wpilibws {
|
||||
|
||||
void HALSimWSProviderHAL::Initialize(WSRegisterFunc webRegisterFunc) {
|
||||
CreateSingleProvider<HALSimWSProviderHAL>("HAL", webRegisterFunc);
|
||||
}
|
||||
|
||||
HALSimWSProviderHAL::~HALSimWSProviderHAL() {
|
||||
DoCancelCallbacks();
|
||||
}
|
||||
|
||||
void HALSimWSProviderHAL::RegisterCallbacks() {
|
||||
m_simPeriodicBeforeCbKey = HALSIM_RegisterSimPeriodicBeforeCallback(
|
||||
[](void* param) {
|
||||
static_cast<HALSimWSProviderHAL*>(param)->ProcessHalCallback(
|
||||
{{">sim_periodic_before", true}});
|
||||
},
|
||||
this);
|
||||
|
||||
m_simPeriodicAfterCbKey = HALSIM_RegisterSimPeriodicAfterCallback(
|
||||
[](void* param) {
|
||||
static_cast<HALSimWSProviderHAL*>(param)->ProcessHalCallback(
|
||||
{{">sim_periodic_after", true}});
|
||||
},
|
||||
this);
|
||||
}
|
||||
|
||||
void HALSimWSProviderHAL::CancelCallbacks() {
|
||||
DoCancelCallbacks();
|
||||
}
|
||||
|
||||
void HALSimWSProviderHAL::DoCancelCallbacks() {
|
||||
HALSIM_CancelSimPeriodicBeforeCallback(m_simPeriodicBeforeCbKey);
|
||||
HALSIM_CancelSimPeriodicAfterCallback(m_simPeriodicAfterCbKey);
|
||||
|
||||
m_simPeriodicBeforeCbKey = 0;
|
||||
m_simPeriodicAfterCbKey = 0;
|
||||
}
|
||||
|
||||
void HALSimWSProviderHAL::OnNetValueChanged(const wpi::json& json) {
|
||||
// no-op. This is all one way
|
||||
}
|
||||
|
||||
} // namespace wpilibws
|
||||
@@ -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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "WSHalProviders.h"
|
||||
|
||||
namespace wpilibws {
|
||||
|
||||
class HALSimWSProviderHAL : public HALSimWSHalProvider {
|
||||
public:
|
||||
static void Initialize(WSRegisterFunc webRegisterFunc);
|
||||
|
||||
using HALSimWSHalProvider::HALSimWSHalProvider;
|
||||
~HALSimWSProviderHAL() override;
|
||||
|
||||
void OnNetValueChanged(const wpi::json& json) override;
|
||||
|
||||
protected:
|
||||
void RegisterCallbacks() override;
|
||||
void CancelCallbacks() override;
|
||||
void DoCancelCallbacks();
|
||||
|
||||
private:
|
||||
int32_t m_simPeriodicBeforeCbKey = 0;
|
||||
int32_t m_simPeriodicAfterCbKey = 0;
|
||||
};
|
||||
|
||||
} // namespace wpilibws
|
||||
Reference in New Issue
Block a user