Skip to content

Commit

Permalink
build: version
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyc committed Jun 12, 2023
1 parent ff8d648 commit eb8d981
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ ctor = "0.2.2"
env_logger = "0.10.0"
log = "0.4.18"
tokio = { version = "1.28.2", features = ["net", "rt", "full"] }

[profile.release]
strip = true
lto = true
opt-level = 2
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ In pyads, connect to `ads-proxy`. For example, client 1 and 2 on a host:
* client 1 `ams_net_id=10.10.10.10.1.1`
* client 2 `ams_net_id=10.10.10.10.1.2`

(Might need to add route entry in shell command with `-r` or in PLC configuration)
Might need to add route entry in shell command with `-r` or in PLC configuration, see [default user and password][password]

[password]: https://infosys.beckhoff.com/english.php?content=../content/1033/sw_os/2019206411.html&id=3176926840725427056

```shell
ads-proxy -d 192.168.0.10:48898
ads-proxy -r 10.10.10.10.1.1 192.168.0.10:48898
```

```python
Expand All @@ -55,6 +57,19 @@ with plc:
...
```

## How it works

```text
client 1 --|
10.10.10.10.1.1 |
| multi-connections one connection
client 2 ---------------------> ads-proxy --------------> PLC
10.10.10.10.1.2 | a.b.c.d route 10.10.10.10.1.1
| a.b.c.d
client n --|
10.10.10.10.x.y
```

## License

MIT
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ async fn main() -> Result<()> {
// add extra route
let plc_client = TcpStream::connect(plc_addr).await?;
let local_addr = plc_client.local_addr().unwrap();
let proxy_host = args.host.unwrap_or(local_addr.ip().to_string());
log::debug!("add route, host {}", proxy_host);
let host = args.host.unwrap_or(local_addr.ip().to_string());
log::debug!("add route, host {}", host);
if let Some(ams_net_id) = args.route {
log::info!("add route {} to plc", ams_net_id);
let route_name = format!("route-{}", ams_net_id);
if let Err(e) = ads::udp::add_route(
(&plc_addr.ip().to_string(), ads::UDP_PORT),
ams_net_id.into(),
&proxy_host,
&host,
Some(&route_name),
username.as_deref(),
password.as_deref(),
Expand All @@ -309,8 +309,8 @@ async fn main() -> Result<()> {
// connect plc backend
log::info!("connecting plc {}...", plc_addr);
let plc_client = TcpStream::connect(plc_addr).await?;
let (mut plc_read, plc_write) = plc_client.into_split();
let plc_write = Arc::new(Mutex::new(plc_write));
let (mut plc_read, plc_write) = plc_client.into_split(); // split
let plc_write = Arc::new(Mutex::new(plc_write)); // shared plc write half

// listen for client
log::info!("listening {}...", args.listen_addr);
Expand Down

0 comments on commit eb8d981

Please sign in to comment.