Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
e89669cc
提交
e89669cc
authored
3月 06, 2025
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
system state
上级
ce45994c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
95 行增加
和
2 行删除
+95
-2
Cargo.toml
Cargo.toml
+3
-1
lib.rs
src/lib.rs
+1
-1
system.rs
src/system.rs
+91
-0
没有找到文件。
Cargo.toml
浏览文件 @
e89669cc
...
...
@@ -71,7 +71,6 @@ rflow = ["dep:rflow"]
modbus
=
["dep:rmodbus"]
metrics
=
[
"dep:metrics"
,
"dep:metrics-exporter-prometheus"
,
"dep:metrics-exporter-scope"
,
"dep:tokio"
]
async
=
["dep:parking_lot_rt"]
full
=
[
"eapi"
,
"modbus"
,
"metrics"
,
"pipe"
,
"rvideo"
,
"rflow"
,
"async"
,
"json"
,
"msgpack"
,
"hmi"
,
"input-events"
]
hmi
=
[
"dep:egui"
,
"dep:eframe"
,
"dep:winit"
,
"dep:once_cell"
]
input-events
=
["dep:evdev"]
...
...
@@ -84,6 +83,9 @@ msgpack = ["dep:rmp-serde"]
default
=
["locking-default"]
full
=
[
"eapi"
,
"modbus"
,
"metrics"
,
"pipe"
,
"rvideo"
,
"rflow"
,
"async"
,
"json"
,
"msgpack"
,
"hmi"
,
"input-events"
]
[dev-dependencies]
insta
=
"1.36.1"
log
=
"0.4.21"
...
...
src/lib.rs
浏览文件 @
e89669cc
...
...
@@ -107,7 +107,7 @@ pub mod hub_async;
pub
mod
io
;
/// Task supervisor to manage real-time threads
pub
mod
supervisor
;
/// Linux syst
me
tools
/// Linux syst
em
tools
pub
mod
system
;
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone, Linux only
pub
mod
thread_rt
;
...
...
src/system.rs
浏览文件 @
e89669cc
use
crate
::{
is_realtime
,
Result
};
use
core
::
fmt
;
use
std
::
convert
::
Infallible
;
use
std
::
str
::
FromStr
;
/// Configure system parameters (global) while the process is running. Does nothing in simulated
/// mode. A wrapper around [`rtsc::system::linux::SystemConfig`] which respects simulated/real-time
...
...
@@ -63,3 +65,92 @@ impl CpuGovernor {
}
}
}
/// Standard systemd system state variants.
#[derive(Debug,
Copy,
Clone,
Eq,
PartialEq)]
pub
enum
StateVariant
{
/// The system is initializing.
Initializing
,
/// The system is starting.
Starting
,
/// The system is running.
Running
,
/// The system is degraded.
Degraded
,
/// The system is in maintenance mode.
Maintenance
,
/// The system is stopping.
Stopping
,
/// The system is in some other state.
Other
,
}
impl
fmt
::
Display
for
StateVariant
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
match
*
self
{
StateVariant
::
Initializing
=>
write!
(
f
,
"initializing"
),
StateVariant
::
Starting
=>
write!
(
f
,
"starting"
),
StateVariant
::
Running
=>
write!
(
f
,
"running"
),
StateVariant
::
Degraded
=>
write!
(
f
,
"degraded"
),
StateVariant
::
Maintenance
=>
write!
(
f
,
"maintenance"
),
StateVariant
::
Stopping
=>
write!
(
f
,
"stopping"
),
StateVariant
::
Other
=>
write!
(
f
,
"other"
),
}
}
}
impl
FromStr
for
StateVariant
{
type
Err
=
Infallible
;
fn
from_str
(
s
:
&
str
)
->
std
::
result
::
Result
<
Self
,
Self
::
Err
>
{
Ok
(
match
s
{
"initializing"
=>
StateVariant
::
Initializing
,
"starting"
=>
StateVariant
::
Starting
,
"running"
=>
StateVariant
::
Running
,
"degraded"
=>
StateVariant
::
Degraded
,
"maintenance"
=>
StateVariant
::
Maintenance
,
"stopping"
=>
StateVariant
::
Stopping
,
_
=>
StateVariant
::
Other
,
})
}
}
/// Get the current system state. Use CLI instead of direct D-Bus calls to avoid unnecessary
/// dependencies.
pub
fn
state
()
->
Result
<
StateVariant
>
{
std
::
process
::
Command
::
new
(
"systemctl"
)
.arg
(
"is-system-running"
)
.output
()
.map_err
(
Into
::
into
)
.and_then
(|
output
|
{
let
state
=
std
::
str
::
from_utf8
(
&
output
.stdout
)
.unwrap_or_default
();
state
.trim
()
.parse
()
.map_err
(
Into
::
into
)
})
}
/// Wait until the system is in the running state.
pub
fn
wait_running_state
()
->
Result
<
()
>
{
loop
{
if
state
()
?
==
StateVariant
::
Running
{
break
;
}
std
::
thread
::
sleep
(
std
::
time
::
Duration
::
from_millis
(
500
));
}
Ok
(())
}
// A variant with D-Bus for future reference
/*
let connection = Connection::new_system()?;
let proxy = connection.with_proxy(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
Duration::from_millis(5000),
);
let (state_variant,): (Variant<String>,) = proxy.method_call(
"org.freedesktop.DBus.Properties",
"Get",
("org.freedesktop.systemd1.Manager", "SystemState"),
)?;
state_variant.0.parse::<SystemStateVariant>()?;
*/
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论