3个不稳定版本
0.2.0 | 2024年4月12日 |
---|---|
0.1.1 | 2023年9月18日 |
0.1.0 | 2023年9月9日 |
#169 在 内存管理
被profirust使用
26KB
525 行
process-image

process-image
是一个Rust crate,它通过零成本抽象方便地访问进程映像内部的数据。进程映像(简称PI)只不过是一块描述状态的内存块。这个概念起源于工业自动化领域,其中这样的进程映像用于表示控制机器或过程所使用的所有输入和输出的状态。
process-image
为标签(=值)的绝对寻址和构建允许符号访问的标签表提供了抽象。
示例
绝对寻址
use process_image as pi;
let mut buf = [0x00; 8];
// Absolute tag addressing
let sensor_limit_1 = pi::tag!(&mut buf, X, 5, 6); // Read %MX3.6
let sensor_limit_2 = pi::tag!(&mut buf, X, 5, 7); // Read %MX3.7
let temperature: u16 = pi::tag!(&mut buf, W, 2); // Read %MW2
*pi::tag_mut!(&mut buf, X, 0, 2) = true; // Set %MX0.2 := TRUE;
*pi::tag_mut!(&mut buf, W, 6) = 2300; // Set %MW6 := 2300;
符号寻址
use process_image as pi;
let mut buf = [0x00; 8];
// Build tag table definition
pi::process_image! {
// Process Image over 8 bytes
pub struct PiExample, mut PiExampleMut: 8 {
pub indicator_light: (X, 0, 2),
pub sensor_limit_1: (X, 5, 6),
pub sensor_limit_2: (X, 5, 7),
pub temperature: (W, 2),
pub setpoint: (W, 6),
}
}
// Read-access only
let pi = PiExample::try_from(&buf).unwrap();
dbg!(pi.sensor_limit_1());
dbg!(pi.sensor_limit_2());
dbg!(pi.temperature());
// Read-write access
let mut pi = PiExampleMut::try_from(&mut buf).unwrap();
if *pi.sensor_limit_1() {
*pi.indicator_light() = true;
*pi.setpoint() = 2300;
}
许可证
许可协议为以下之一
- Apache许可证版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
贡献
除非你明确声明,否则任何有意提交以包含在作品中并由你定义的Apache-2.0许可证,均应按照上述方式双许可,不附加任何额外条款或条件。