Files
PhotonVision/photon-server/src/main/java/org/photonvision/server/TestRequestHandler.java

70 lines
2.5 KiB
Java
Raw Normal View History

2025-12-04 22:25:48 -06:00
/*
* 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;
2026-05-24 13:05:10 -04:00
import io.avaje.jsonb.Json;
import io.avaje.jsonb.Jsonb;
2025-12-04 22:25:48 -06:00
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();
}
2026-05-24 13:05:10 -04:00
@Json
record PlatformOverrideRequest(Platform platform) {}
2025-12-04 22:25:48 -06:00
public static void handlePlatformOverrideRequest(Context ctx) {
try {
PlatformOverrideRequest request =
2026-05-24 13:05:10 -04:00
Jsonb.instance().type(PlatformOverrideRequest.class).fromJson(ctx.body());
2025-12-04 22:25:48 -06:00
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");
}
}