diff --git a/src/main.rs b/src/main.rs index 4235941..b3a631b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -234,6 +234,10 @@ struct Args { /// PLC address, e.g. 172.18.0.10:48898 pub plc_addr: SocketAddr, + + /// Pass plc net id over cli argument, this will skip fetching data over UDP! + #[arg(long)] + pub plc_ams_net_id: Option, } async fn read_ams_packet(reader: &mut T, buf: &mut BytesMut, packet_size: usize) -> Result @@ -360,12 +364,20 @@ where async fn connect_plc(args: Arc, table: Table) -> Result<()> { // detect plc info - let plc_info = ads::udp::get_info((&args.plc_addr.ip().to_string(), ads::UDP_PORT))?; - log::info!("plc net_id={}", plc_info.netid); - log::info!("plc hostname={}", plc_info.hostname); - log::info!("plc twincat_version={:?}", plc_info.twincat_version); - log::info!("plc os_version={:?}", plc_info.os_version); - log::info!("plc fingerprint={}", plc_info.fingerprint); + let plc_ams_net_id = args.plc_ams_net_id.unwrap_or_else(|| { + log::info!( + "plc_ams_net_id not passed through cli interface, will try to fetch information + from PLC over UDP!" + ); + let plc_info = ads::udp::get_info((&args.plc_addr.ip().to_string(), ads::UDP_PORT)) + .expect("unable to get system information from PLC over UDP!"); + log::info!("plc net_id={}", plc_info.netid); + log::info!("plc hostname={}", plc_info.hostname); + log::info!("plc twincat_version={:?}", plc_info.twincat_version); + log::info!("plc os_version={:?}", plc_info.os_version); + log::info!("plc fingerprint={}", plc_info.fingerprint); + plc_info.netid.into() + }); // connect plc backend log::info!("connecting plc {}...", args.plc_addr); @@ -398,8 +410,7 @@ async fn connect_plc(args: Arc, table: Table) -> Result<()> { let (stop_tx, stop_rx) = broadcast::channel(1); // update proxy table with plc ams net id - log::info!("updating proxy table with plc {}", plc_info.netid); - let plc_ams_net_id = plc_info.netid.into(); + log::info!("updating proxy table with plc {}", plc_ams_net_id); let plc_ams_addr = AmsAddr(plc_ams_net_id, 0); table.write().await.insert(plc_ams_addr, (plc_addr, data_tx.clone()));