Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disable-networking and clear-config command line opts #892

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions photon-client/src/components/settings/NetworkingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,36 @@ const saveGeneralSettings = () => {
The NetworkTables Server Address is not set or is invalid. NetworkTables is unable to connect.
</v-banner>
<cv-radio
v-show="useSettingsStore().network.shouldManage"
v-model="useSettingsStore().network.connectionType"
label="IP Assignment Mode"
tooltip="DHCP will make the radio (router) automatically assign an IP address; this may result in an IP address that changes across reboots. Static IP assignment means that you pick the IP address and it won't change."
:disabled="!useSettingsStore().network.shouldManage"
:input-cols="12-3"
:list="['DHCP','Static']"
/>
<cv-input
v-if="useSettingsStore().network.connectionType === NetworkConnectionType.Static"
v-model="useSettingsStore().network.staticIp"
:input-cols="12-3"
:disabled="useSettingsStore().network.connectionType !== NetworkConnectionType.Static || !useSettingsStore().network.shouldManage"
label="Static IP"
:rules="[v => isValidIPv4(v) || 'Invalid IPv4 address']"
:input-cols="12-3"
:rules="[v => (isValidIPv4(v) || !useSettingsStore().network.shouldManage) || 'Invalid IPv4 address']"
/>
<cv-input
v-show="useSettingsStore().network.shouldManage"
v-model="useSettingsStore().network.hostname"
label="Hostname"
:disabled="!useSettingsStore().network.shouldManage"
:input-cols="12-3"
:rules="[v => isValidHostname(v) || 'Invalid hostname']"
/>
<v-divider/>
<span>Advanced Networking</span>
<cv-switch
v-model="useSettingsStore().network.shouldManage"
label="Manage Device Networking"
tooltip="If enabled, Photon will manage device hostname and network settings."
class="mt-3 mb-3"
:label-cols="3"
/>
<cv-switch
v-model="useSettingsStore().network.runNTServer"
label="Run NetworkTables Server (Debugging Only)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ private void translateLegacyIfPresent(Path folderPath) {
// Cannot import into SQL if we aren't in SQL mode rn
return;
}
logger.info("Translating settings zip!");

var maybeCams = Path.of(folderPath.toAbsolutePath().toString(), "cameras").toFile();
var maybeCamsBak = Path.of(folderPath.toAbsolutePath().toString(), "cameras_backup").toFile();

if (maybeCams.exists() && maybeCams.isDirectory()) {
logger.info("Translating settings zip!");
var legacy = new LegacyConfigProvider(folderPath);
legacy.load();
var loadedConfig = legacy.getConfig();
Expand Down Expand Up @@ -264,6 +264,12 @@ public void unloadCameraConfigs() {
this.getConfig().getCameraConfigurations().clear();
}

public void clearConfig() {
logger.info("Clearing configuration!");
m_provider.clearConfig();
m_provider.saveToDisk();
}

public void saveToDisk() {
m_provider.saveToDisk();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.nio.file.Path;

public abstract class ConfigProvider {
private PhotonConfiguration config;
protected PhotonConfiguration config;

abstract void load();

Expand All @@ -30,6 +30,10 @@ PhotonConfiguration getConfig() {
return config;
}

public void clearConfig() {
config = new PhotonConfiguration();
}

public abstract boolean saveUploadedHardwareConfig(Path uploadPath);

public abstract boolean saveUploadedHardwareSettings(Path uploadPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class NetworkConfig {
private boolean shouldManage;

public NetworkConfig() {
setShouldManage(false);
setShouldManage(deviceCanManageNetwork());
}

@JsonCreator
Expand Down Expand Up @@ -95,12 +95,16 @@ public String getEscapedIfaceName() {

@JsonGetter("shouldManage")
public boolean shouldManage() {
return this.shouldManage || Platform.isLinux();
return this.shouldManage;
}

@JsonSetter("shouldManage")
public void setShouldManage(boolean shouldManage) {
this.shouldManage = shouldManage || Platform.isLinux();
this.shouldManage = shouldManage && this.deviceCanManageNetwork();
}

private boolean deviceCanManageNetwork() {
return Platform.isLinux();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public PhotonConfiguration(
this.cameraConfigurations = cameraConfigurations;
}

public PhotonConfiguration() {
this(new HardwareConfig(), new HardwareSettings(), new NetworkConfig());
}

public HardwareConfig getHardwareConfig() {
return hardwareConfig;
}
Expand Down Expand Up @@ -140,17 +144,4 @@ public static class UICameraConfiguration {
public List<HashMap<String, Object>> calibrations;
public boolean isFovConfigurable = true;
}

@Override
public String toString() {
return "PhotonConfiguration [hardwareConfig="
+ hardwareConfig
+ ", hardwareSettings="
+ hardwareSettings
+ ", networkConfig="
+ networkConfig
+ ", cameraConfigurations="
+ cameraConfigurations
+ "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ static class TableKeys {
private static final String dbName = "photon.sqlite";
private final String dbPath;

private PhotonConfiguration config;
private final Object m_mutex = new Object();
private final File rootFolder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public static NetworkManager getInstance() {
}

private boolean isManaged = false;
public boolean networkingIsDisabled = false; // Passed in via CLI

public void initialize(boolean shouldManage) {
isManaged = shouldManage;
isManaged = shouldManage && !networkingIsDisabled;
if (!isManaged) {
return;
}
Expand Down
20 changes: 18 additions & 2 deletions photon-server/src/main/java/org/photonvision/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ private static boolean handleArgs(String[] args) throws ParseException {
"ignore-cameras",
true,
"Ignore cameras that match a regex. Uses camera name as provided by cscore.");
options.addOption("n", "disable-networking", false, "Disables control device network settings");
options.addOption(
"c",
"clear-config",
false,
"Clears PhotonVision pipeline and networking settings. Preserves log files");

CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
Expand Down Expand Up @@ -109,6 +115,14 @@ private static boolean handleArgs(String[] args) throws ParseException {
VisionSourceManager.getInstance()
.setIgnoredCamerasRegex(cmd.getOptionValue("ignore-cameras"));
}

if (cmd.hasOption("disable-networking")) {
NetworkManager.getInstance().networkingIsDisabled = true;
}

if (cmd.hasOption("clear-config")) {
ConfigManager.getInstance().clearConfig();
}
}
return true;
}
Expand Down Expand Up @@ -313,9 +327,11 @@ public static void main(String[] args) {
}

try {
LibCameraJNI.forceLoad();
if (Platform.isRaspberryPi()) {
LibCameraJNI.forceLoad();
}
} catch (IOException e) {
logger.error("Failed to load native libraries!", e);
logger.error("Failed to load libcamera-JNI!", e);
}

try {
Expand Down