Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e1b74a583 | ||
|
|
ee93bb150d | ||
|
|
208fe5734f | ||
|
|
2abb6b2ce0 | ||
|
|
6f986d3c45 |
No files matched your search
@@ -126,6 +126,16 @@ in {
|
||||
value = "-20";
|
||||
}
|
||||
];
|
||||
# needed so dnsmasq can get managed by server
|
||||
security.polkit.extraConfig = ''
|
||||
polkit.addRule(function(action, subject) {
|
||||
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
||||
action.lookup("unit") == "dnsmasq.service" &&
|
||||
subject.user == "${cfg.user}") {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
});
|
||||
'';
|
||||
|
||||
# Desktop integration
|
||||
xdg.mime.enable = true;
|
||||
|
||||
@@ -322,10 +322,12 @@ in {
|
||||
|
||||
services.dnsmasq = {
|
||||
enable = true;
|
||||
resolveLocalQueries = false;
|
||||
|
||||
settings = {
|
||||
interface = "enp1s0"; # only this interface
|
||||
bind-interfaces = true;
|
||||
server = [ "1.1.1.1" "8.8.8.8" ];
|
||||
|
||||
# DHCP subnet + pool
|
||||
dhcp-range = "10.10.10.50,10.10.10.250,255.255.255.0,12h";
|
||||
|
||||
@@ -19,6 +19,7 @@ use ethercat_hal::devices::wago_modules::ip20_ec_di8_do8::{
|
||||
IP20_EC_DI8_DO8_PRODUCT_ID, IP20_EC_DI8_DO8_VENDOR_ID, IP20EcDi8Do8,
|
||||
};
|
||||
|
||||
use crate::utils::{start_dnsmasq, stop_dnsmasq};
|
||||
use ethercrab::std::ethercat_now;
|
||||
use ethercrab::{MainDevice, MainDeviceConfig, PduStorage, RetryBehaviour, Timeouts};
|
||||
use machines::machine_identification::{
|
||||
@@ -172,6 +173,14 @@ pub async fn setup_loop(
|
||||
) -> Result<EthercatSetup, anyhow::Error> {
|
||||
tracing::info!("Starting Ethercat PDU loop");
|
||||
|
||||
let res = stop_dnsmasq();
|
||||
match res {
|
||||
Ok(_) => (),
|
||||
Err(e) => tracing::error!("Failed to stop dnsmasq: {:?}", e),
|
||||
};
|
||||
// Small Timeout to ensure interfaces get released
|
||||
smol::Timer::after(Duration::from_millis(1500)).await;
|
||||
|
||||
// Setup ethercrab tx/rx task
|
||||
let pdu_storage = Box::leak(Box::new(PduStorage::<MAX_FRAMES, MAX_PDU_DATA>::new()));
|
||||
let (tx, rx, pdu) = pdu_storage.try_split().expect("can only split once");
|
||||
@@ -481,6 +490,12 @@ pub async fn setup_loop(
|
||||
main_namespace.emit(MainNamespaceEvents::EthercatDevicesEvent(event));
|
||||
}
|
||||
|
||||
let res = start_dnsmasq();
|
||||
match res {
|
||||
Ok(o) => o,
|
||||
Err(e) => tracing::error!("Failed to start dnsmasq: {:?}", e),
|
||||
};
|
||||
|
||||
Ok(EthercatSetup {
|
||||
devices,
|
||||
group: group_op,
|
||||
|
||||
+5
-2
@@ -16,6 +16,7 @@ use machines::{
|
||||
};
|
||||
#[cfg(feature = "development-build")]
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use utils::start_dnsmasq;
|
||||
|
||||
use app_state::{HotThreadMessage, SharedState};
|
||||
use ethercat::ethercat_discovery_info::send_ethercat_discovering;
|
||||
@@ -57,6 +58,7 @@ pub mod panic;
|
||||
pub mod performance_metrics;
|
||||
pub mod rest;
|
||||
pub mod socketio;
|
||||
pub mod utils;
|
||||
|
||||
pub async fn send_empty_machines_event(shared_state: Arc<SharedState>) {
|
||||
shared_state.current_machines_meta.lock().await.clear();
|
||||
@@ -137,7 +139,6 @@ pub async fn start_interface_discovery(
|
||||
let interface = find_ethercat_interface().await;
|
||||
tracing::info!("Inferface found {}, setting up EtherCAT loop", interface);
|
||||
set_ethercat_iface(interface.clone());
|
||||
|
||||
let res = setup_loop(&interface, app_state.clone()).await;
|
||||
|
||||
match res {
|
||||
@@ -152,9 +153,10 @@ pub async fn start_interface_discovery(
|
||||
module_path!(),
|
||||
e
|
||||
);
|
||||
// if this doesnt work, unlucky
|
||||
let _ = start_dnsmasq();
|
||||
}
|
||||
}
|
||||
|
||||
send_ethercat_found(app_state.clone(), &interface).await;
|
||||
}
|
||||
|
||||
@@ -338,6 +340,7 @@ fn main() {
|
||||
let app_state = Arc::new(shared_state);
|
||||
let _loop_thread = start_loop_thread(receiver, CYCLE_TARGET_TIME);
|
||||
let _ = start_api_thread(app_state.clone());
|
||||
|
||||
spawn_runtime_metrics_sampler(RuntimeMetricsConfig {
|
||||
csv_path: "runtime_metrics.csv".to_string(),
|
||||
interval: Duration::from_secs(1),
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
use std::process::Command;
|
||||
|
||||
pub fn start_dnsmasq() -> std::io::Result<()> {
|
||||
// action can be "start", "stop", or "restart"
|
||||
let status = Command::new("systemctl")
|
||||
.arg("start")
|
||||
.arg("dnsmasq.service")
|
||||
.status()?;
|
||||
|
||||
if status.success() {
|
||||
tracing::info!("Successfully started dnsmasq");
|
||||
} else {
|
||||
tracing::info!("Failed to start dnsmasq");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn stop_dnsmasq() -> std::io::Result<()> {
|
||||
// action can be "start", "stop", or "restart"
|
||||
let status = Command::new("systemctl")
|
||||
.arg("stop")
|
||||
.arg("dnsmasq.service")
|
||||
.status()?;
|
||||
|
||||
if status.success() {
|
||||
tracing::info!("Successfully stopped");
|
||||
} else {
|
||||
tracing::info!("Failed to stop dnsmasq");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user