Skip to content

Commit

Permalink
Merge branch 'disable-networking' into 2023-08-21_networkmanager-dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Aug 23, 2023
2 parents e8c0a9e + b6dea89 commit 2b52cb0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 27 deletions.
15 changes: 12 additions & 3 deletions photon-client/src/components/settings/NetworkingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,35 @@ const netManagerIfaceIdx = computed<number>({
:items="ifaceNames()"
/>
<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."
:input-cols="12 - 4"
:list="['DHCP', 'Static']"
:disabled="!useSettingsStore().network.shouldManage"
/>
<cv-input
v-if="useSettingsStore().network.connectionType === NetworkConnectionType.Static"
v-model="useSettingsStore().network.staticIp"
:input-cols="12 - 4"
label="Static IP"
:rules="[(v) => isValidIPv4(v) || 'Invalid IPv4 address']"
:disabled="useSettingsStore().network.connectionType !== NetworkConnectionType.Static || !useSettingsStore().network.shouldManage"
/>
<cv-input
v-show="useSettingsStore().network.shouldManage"
v-model="useSettingsStore().network.hostname"
label="Hostname"
:input-cols="12-4"
:rules="[(v) => isValidHostname(v) || 'Invalid hostname']"
:disabled="!useSettingsStore().network.shouldManage"
/>
<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"
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 @@ -55,7 +55,7 @@ public NetworkConfig() {
}

// We can (usually) manage networking on Linux devices, and if we can we should try to. Command line inhibitions happen at a level above this class
setShouldManage(Platform.isLinux());
setShouldManage(deviceCanManageNetwork());
}

@JsonCreator
Expand Down Expand Up @@ -107,7 +107,11 @@ public boolean shouldManage() {

@JsonIgnore
public void setShouldManage(boolean shouldManage) {
this.shouldManage = shouldManage;
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 @@ -56,6 +56,10 @@ public PhotonConfiguration(
this.cameraConfigurations = cameraConfigurations;
}

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

public HardwareConfig getHardwareConfig() {
return hardwareConfig;
}
Expand Down Expand Up @@ -146,17 +150,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
21 changes: 16 additions & 5 deletions photon-server/src/main/java/org/photonvision/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +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(
"n",
"disable-networking",
"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 @@ -114,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 @@ -301,9 +310,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

0 comments on commit 2b52cb0

Please sign in to comment.