Skip to content
Open
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
27 changes: 19 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AmsNetId>,
}

async fn read_ams_packet<T>(reader: &mut T, buf: &mut BytesMut, packet_size: usize) -> Result<usize>
Expand Down Expand Up @@ -360,12 +364,20 @@ where

async fn connect_plc(args: Arc<Args>, 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);
Expand Down Expand Up @@ -398,8 +410,7 @@ async fn connect_plc(args: Arc<Args>, 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()));

Expand Down