8 releases
0.1.0 | Jul 28, 2024 |
---|---|
0.0.7 | Jul 17, 2024 |
0.0.4 | Jun 28, 2024 |
#686 in Embedded development
Used in 3 crates
(2 directly)
29KB
623 lines
RFlow
Chat-like HMI for embedded Rust applications and PLCs
RFlow is a part of RoboPLC project.
The idea
Many of embedded applications and PLC programs do not have any human-machine interface and not supposed to have one by design.
However, sometimes it is very useful to have a simple way to interact with the application, e.g. for debugging purposes or having a basic emergency interface in production.
RFlow provides the most possible lightweight way to have a chat-like interface between the application (server) and its clients, which does not affect the application real-time run-flow and consumes minimal system resources.
The RFlow protocol is fully text-based and can be used with no special client.
MSRV: 1.68.0
Clients
-
RFlow Chat - a dedicated RFlow chat client (terminal).
-
Custom clients, built with the crate
Client
API. -
Any terminal TCP client, e.g.
telnet
,nc
.
A very basic example
use std::{thread, time::Duration};
use rtsc::time::interval;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data_channel = rflow::take_data_channel()?;
thread::spawn(move || {
rflow::serve("127.0.0.1:4001").expect("failed to start server");
});
thread::spawn(move || {
for _ in interval(Duration::from_secs(5)) {
rflow::send("ping".to_string());
}
});
for data in data_channel {
println!("Received data: {}", data);
rflow::send(format!("command accepted: {}", data));
let command = data.trim();
if command == "quit" {
break;
}
}
Ok(())
}
Locking safety
Note: the asynchronous client uses parking_lot_rt
locking only.
By default, the crate (both the server and the client modules) uses parking_lot for locking. For real-time applications, the following features are available:
-
locking-rt
- use parking_lot_rt crate which is a spin-free fork of parking_lot. -
locking-rt-safe
- use rtsc priority-inheritance locking, which is not affected by priority inversion (Linux only).
Note: to switch locking policy, disable the crate default features.
About
RFlow is a part of RoboPLC project.
Dependencies
~3–12MB
~137K SLoC