mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
## Description WPILib switched from FasterXML Jackson to Avaje Jsonb for speed reasons in https://github.com/wpilibsuite/allwpilib/pull/8721. This does the same for PhotonVision. Some temporary Jackson adapters are present to allow compatibility with alpha-4 ahead of updating Photon's WPILib version. A few old backwards compatibility migrations were also dropped if they were difficult to port to Avaje Jsonb or otherwise complicated the code. ## Meta Merge checklist: - [x] Pull Request title is [short, imperative summary](https://cbea.ms/git-commit/) of proposed changes - [x] The description documents the _what_ and _why_, including events that led to this PR - [ ] If this PR changes behavior or adds a feature, user documentation is updated - [ ] If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly - [ ] If this PR touches configuration, this is backwards compatible with all settings going back to the previous seasons's last release (seasons end after champs ends) - [ ] If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated - [ ] If this PR addresses a bug, a regression test for it is added - [ ] If this PR adds a dependency, the license has been checked for compatibility and steps taken to follow it --------- Co-authored-by: samfreund <samf.236@proton.me> Co-authored-by: Matt Morley <matthew.morley.ca@gmail.com>
70 lines
2.5 KiB
Java
70 lines
2.5 KiB
Java
/*
|
|
* Copyright (C) Photon Vision.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.photonvision.server;
|
|
|
|
import io.avaje.jsonb.Json;
|
|
import io.avaje.jsonb.Jsonb;
|
|
import io.javalin.http.Context;
|
|
import org.photonvision.common.configuration.ConfigManager;
|
|
import org.photonvision.common.configuration.NeuralNetworkModelManager;
|
|
import org.photonvision.common.hardware.Platform;
|
|
import org.photonvision.common.logging.LogGroup;
|
|
import org.photonvision.common.logging.Logger;
|
|
|
|
public class TestRequestHandler {
|
|
// Treat all 2XX calls as "INFO"
|
|
// Treat all 4XX calls as "ERROR"
|
|
// Treat all 5XX calls as "ERROR"
|
|
|
|
static Logger logger = new Logger(TestRequestHandler.class, LogGroup.WebServer);
|
|
|
|
public static void handleResetRequest(Context ctx) {
|
|
logger.info("Resetting Backend");
|
|
// Reset backend
|
|
ConfigManager.nukeConfigDirectory();
|
|
ConfigManager.getInstance().load();
|
|
}
|
|
|
|
@Json
|
|
record PlatformOverrideRequest(Platform platform) {}
|
|
|
|
public static void handlePlatformOverrideRequest(Context ctx) {
|
|
try {
|
|
PlatformOverrideRequest request =
|
|
Jsonb.instance().type(PlatformOverrideRequest.class).fromJson(ctx.body());
|
|
Platform platform = request.platform();
|
|
logger.info("Overriding platform to: " + platform);
|
|
|
|
Platform.overridePlatform(platform);
|
|
NeuralNetworkModelManager.getInstance(true).extractModels();
|
|
NeuralNetworkModelManager.getInstance().discoverModels();
|
|
ctx.status(200);
|
|
|
|
} catch (Exception e) {
|
|
logger.error("Failed to parse platform override request: " + e.getMessage());
|
|
ctx.status(400).result("Invalid request");
|
|
}
|
|
}
|
|
|
|
public static void testMode(Context ctx) {
|
|
logger.info("Test mode activated");
|
|
RequestHandler.setTestMode(true);
|
|
ctx.status(200).result("Test mode activated");
|
|
}
|
|
}
|