Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
b411d08f
提交
b411d08f
authored
1月 06, 2025
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
certain pre-release fixes
上级
41da870a
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
87 行增加
和
113 行删除
+87
-113
Cargo.toml
Cargo.toml
+3
-3
serial.rs
src/comm/serial.rs
+2
-4
hub.rs
src/hub.rs
+1
-0
lib.rs
src/lib.rs
+15
-2
system.rs
src/system.rs
+65
-0
thread_rt.rs
src/thread_rt.rs
+1
-104
没有找到文件。
Cargo.toml
浏览文件 @
b411d08f
...
@@ -36,8 +36,8 @@ sysinfo = "0.29"
...
@@ -36,8 +36,8 @@ sysinfo = "0.29"
thiserror
=
"1.0.57"
thiserror
=
"1.0.57"
tracing
=
"0.1.40"
tracing
=
"0.1.40"
signal-hook
=
"0.3.17"
signal-hook
=
"0.3.17"
eva-common
=
{
version
=
"0.3.85"
,
features
=
[
"events"
,
"payload"
,
"common-payloads"
,
"acl"
],
optional
=
true
}
eva-common
=
{
version
=
"
^
0.3.85"
,
features
=
[
"events"
,
"payload"
,
"common-payloads"
,
"acl"
],
optional
=
true
}
eva-sdk
=
{
version
=
"
0.3.61
"
,
features
=
["controller"]
,
optional
=
true
}
eva-sdk
=
{
version
=
"
^0.3.62
"
,
features
=
["controller"]
,
optional
=
true
}
busrt
=
{
version
=
"0.4.9"
,
features
=
[
"rpc"
,
"ipc"
],
optional
=
true
}
busrt
=
{
version
=
"0.4.9"
,
features
=
[
"rpc"
,
"ipc"
],
optional
=
true
}
tokio
=
{
version
=
"1.36.0"
,
optional
=
true
}
tokio
=
{
version
=
"1.36.0"
,
optional
=
true
}
hostname
=
{
version
=
"0.3.1"
,
optional
=
true
}
hostname
=
{
version
=
"0.3.1"
,
optional
=
true
}
...
@@ -49,7 +49,7 @@ metrics = { version = "0.24", optional = true }
...
@@ -49,7 +49,7 @@ metrics = { version = "0.24", optional = true }
snmp2
=
{
version
=
"0.3"
,
optional
=
true
}
snmp2
=
{
version
=
"0.3"
,
optional
=
true
}
rtsc
=
"^0.3.12"
rtsc
=
"^0.3.12"
rvideo
=
{
version
=
"0.5"
,
optional
=
true
,
default-features
=
false
}
rvideo
=
{
version
=
"0.5"
,
optional
=
true
,
default-features
=
false
}
rflow
=
{
version
=
"
0
.1"
,
optional
=
true
,
default-features
=
false
}
rflow
=
{
version
=
"
^0.1
.1"
,
optional
=
true
,
default-features
=
false
}
once_cell
=
{
version
=
"1.19.0"
,
optional
=
true
}
once_cell
=
{
version
=
"1.19.0"
,
optional
=
true
}
parking_lot
=
{
version
=
"0.12.3"
,
optional
=
true
}
parking_lot
=
{
version
=
"0.12.3"
,
optional
=
true
}
parking_lot_rt
=
{
version
=
"0.12.1"
,
optional
=
true
}
parking_lot_rt
=
{
version
=
"0.12.1"
,
optional
=
true
}
...
...
src/comm/serial.rs
浏览文件 @
b411d08f
...
@@ -187,9 +187,8 @@ impl Communicator for Serial {
...
@@ -187,9 +187,8 @@ impl Communicator for Serial {
.as_mut
()
.as_mut
()
.unwrap
()
.unwrap
()
.write_all
(
buf
)
.write_all
(
buf
)
.
map_err
(|
e
|
{
.
inspect_err
(|
_
|
{
self
.reconnect
();
self
.reconnect
();
e
});
});
if
result
.is_ok
()
{
if
result
.is_ok
()
{
port
.last_frame
.replace
(
Instant
::
now
());
port
.last_frame
.replace
(
Instant
::
now
());
...
@@ -204,9 +203,8 @@ impl Communicator for Serial {
...
@@ -204,9 +203,8 @@ impl Communicator for Serial {
.as_mut
()
.as_mut
()
.unwrap
()
.unwrap
()
.read_exact
(
buf
)
.read_exact
(
buf
)
.
map_err
(|
e
|
{
.
inspect_err
(|
_
|
{
self
.reconnect
();
self
.reconnect
();
e
})
})
.map_err
(
Into
::
into
)
.map_err
(
Into
::
into
)
}
}
...
...
src/hub.rs
浏览文件 @
b411d08f
...
@@ -376,6 +376,7 @@ mod test {
...
@@ -376,6 +376,7 @@ mod test {
use
super
::
Hub
;
use
super
::
Hub
;
#[derive(Clone,
Debug)]
#[derive(Clone,
Debug)]
#[allow(dead_code)]
enum
Message
{
enum
Message
{
Temperature
(
f64
),
Temperature
(
f64
),
Humidity
(
f64
),
Humidity
(
f64
),
...
...
src/lib.rs
浏览文件 @
b411d08f
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
use
core
::{
fmt
,
num
};
use
core
::{
fmt
,
num
};
use
std
::
io
::
Write
;
use
std
::
io
::
Write
;
use
std
::
panic
::
PanicInfo
;
use
std
::
panic
::
PanicInfo
;
use
std
::
sync
::
atomic
;
use
std
::
sync
::
atomic
::{
self
,
AtomicBool
,
Ordering
}
;
use
std
::{
env
,
sync
::
Arc
,
time
::
Duration
};
use
std
::{
env
,
sync
::
Arc
,
time
::
Duration
};
use
colored
::
Colorize
as
_
;
use
colored
::
Colorize
as
_
;
...
@@ -104,9 +104,10 @@ pub mod hub_async;
...
@@ -104,9 +104,10 @@ pub mod hub_async;
pub
mod
io
;
pub
mod
io
;
/// Task supervisor to manage real-time threads
/// Task supervisor to manage real-time threads
pub
mod
supervisor
;
pub
mod
supervisor
;
/// Linux systme tools
pub
mod
system
;
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone, Linux only
/// Real-time thread functions to work with [`supervisor::Supervisor`] and standalone, Linux only
pub
mod
thread_rt
;
pub
mod
thread_rt
;
pub
use
rtsc
::
system
;
/// State helper functions
/// State helper functions
#[cfg(any(feature
=
"json"
,
feature
=
"msgpack"
))]
#[cfg(any(feature
=
"json"
,
feature
=
"msgpack"
))]
...
@@ -115,6 +116,18 @@ pub mod state;
...
@@ -115,6 +116,18 @@ pub mod state;
/// The crate result type
/// The crate result type
pub
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Error
>
;
pub
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Error
>
;
static
REALTIME_MODE
:
AtomicBool
=
AtomicBool
::
new
(
true
);
/// The function can be used in test environments to disable real-time functions but keep all
/// methods running with no errors
pub
fn
set_simulated
()
{
REALTIME_MODE
.store
(
false
,
Ordering
::
Relaxed
);
}
fn
is_realtime
()
->
bool
{
REALTIME_MODE
.load
(
Ordering
::
Relaxed
)
}
/// The crate error type
/// The crate error type
#[derive(thiserror
::
Error,
Debug)]
#[derive(thiserror
::
Error,
Debug)]
pub
enum
Error
{
pub
enum
Error
{
...
...
src/system.rs
0 → 100644
浏览文件 @
b411d08f
use
crate
::{
is_realtime
,
Result
};
use
core
::
fmt
;
/// 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
/// mode.
///
/// Example:
///
/// ```rust,no_run
/// use roboplc::thread_rt::SystemConfig;
///
/// let _sys = SystemConfig::new().set("kernel/sched_rt_runtime_us", -1)
/// .apply()
/// .expect("Unable to set system config");
/// // some code
/// // system config is restored at the end of the scope
/// ```
#[allow(clippy
::
module_name_repetitions)]
#[derive(Default)]
pub
struct
SystemConfig
(
rtsc
::
system
::
linux
::
SystemConfig
);
impl
SystemConfig
{
/// Creates a new system config object
#[must_use]
pub
fn
new
()
->
Self
{
Self
::
default
()
}
/// Set a parameter to configure
pub
fn
set
<
V
:
fmt
::
Display
>
(
mut
self
,
key
:
&
'static
str
,
value
:
V
)
->
Self
{
if
is_realtime
()
{
self
.
0
=
self
.
0
.set
(
key
,
value
);
}
self
}
/// Apply values to /proc/sys keys
pub
fn
apply
(
self
)
->
Result
<
rtsc
::
system
::
linux
::
SystemConfigGuard
>
{
if
is_realtime
()
{
return
self
.
0
.apply
()
.map_err
(
Into
::
into
);
}
Ok
(
rtsc
::
system
::
linux
::
SystemConfigGuard
::
default
())
}
}
/// Configure CPU governors for the given CPUs. A wrapper around
/// [`rtsc::system::linux::CpuGovernor`] which respects simulated/real-time mode.
pub
struct
CpuGovernor
(
#
[
allow
(
dead_code
)]
rtsc
::
system
::
linux
::
CpuGovernor
);
impl
CpuGovernor
{
/// Set performance governor for the given CPUs. This sets the maximum frequency for the CPUs,
/// increasing the power consumption but lowering their latency. It is enough to specify a
/// single logical core number per physical core. The governor is restored when the returned
/// guard object is dropped.
pub
fn
performance
<
I
>
(
performance_cpus
:
I
)
->
Result
<
CpuGovernor
>
where
I
:
IntoIterator
<
Item
=
usize
>
,
{
if
is_realtime
()
{
let
inner
=
rtsc
::
system
::
linux
::
CpuGovernor
::
performance
(
performance_cpus
)
?
;
Ok
(
Self
(
inner
))
}
else
{
Ok
(
Self
(
rtsc
::
system
::
linux
::
CpuGovernor
::
default
()))
}
}
}
src/thread_rt.rs
浏览文件 @
b411d08f
use
crate
::{
time
::
Interval
,
Error
,
Result
};
use
crate
::{
is_realtime
,
time
::
Interval
,
Error
,
Result
};
use
bma_ts
::{
Monotonic
,
Timestamp
};
use
bma_ts
::{
Monotonic
,
Timestamp
};
use
colored
::
Colorize
;
use
colored
::
Colorize
;
use
core
::
fmt
;
use
core
::
fmt
;
...
@@ -7,7 +7,6 @@ use nix::{sys::signal, unistd};
...
@@ -7,7 +7,6 @@ use nix::{sys::signal, unistd};
use
serde
::{
Deserialize
,
Serialize
,
Serializer
};
use
serde
::{
Deserialize
,
Serialize
,
Serializer
};
use
std
::{
use
std
::{
collections
::
BTreeSet
,
collections
::
BTreeSet
,
sync
::
atomic
::{
AtomicBool
,
Ordering
},
thread
::{
self
,
JoinHandle
,
Scope
,
ScopedJoinHandle
},
thread
::{
self
,
JoinHandle
,
Scope
,
ScopedJoinHandle
},
time
::
Duration
,
time
::
Duration
,
};
};
...
@@ -15,18 +14,6 @@ use std::{
...
@@ -15,18 +14,6 @@ use std::{
use
sysinfo
::
PidExt
;
use
sysinfo
::
PidExt
;
use
sysinfo
::{
Pid
,
ProcessExt
,
System
,
SystemExt
};
use
sysinfo
::{
Pid
,
ProcessExt
,
System
,
SystemExt
};
static
REALTIME_MODE
:
AtomicBool
=
AtomicBool
::
new
(
true
);
/// The function can be used in test environments to disable real-time functions but keep all
/// methods running with no errors
pub
fn
set_simulated
()
{
REALTIME_MODE
.store
(
false
,
Ordering
::
Relaxed
);
}
fn
is_realtime
()
->
bool
{
REALTIME_MODE
.load
(
Ordering
::
Relaxed
)
}
#[cfg(not(target_os
=
"linux"
))]
#[cfg(not(target_os
=
"linux"
))]
macro_rules!
panic_os
{
macro_rules!
panic_os
{
()
=>
{
()
=>
{
...
@@ -99,34 +86,6 @@ impl From<Scheduling> for rtsc::thread_rt::Scheduling {
...
@@ -99,34 +86,6 @@ impl From<Scheduling> for rtsc::thread_rt::Scheduling {
}
}
}
}
//#[cfg(target_os = "linux")]
//impl From<Scheduling> for libc::c_int {
//fn from(value: Scheduling) -> Self {
//match value {
//Scheduling::RoundRobin => libc::SCHED_RR,
//Scheduling::FIFO => libc::SCHED_FIFO,
//Scheduling::Idle => libc::SCHED_IDLE,
//Scheduling::Batch => libc::SCHED_BATCH,
//Scheduling::DeadLine => libc::SCHED_DEADLINE,
//Scheduling::Other => libc::SCHED_NORMAL,
//}
//}
//}
//#[cfg(target_os = "linux")]
//impl From<libc::c_int> for Scheduling {
//fn from(value: libc::c_int) -> Self {
//match value {
//libc::SCHED_RR => Scheduling::RoundRobin,
//libc::SCHED_FIFO => Scheduling::FIFO,
//libc::SCHED_IDLE => Scheduling::Idle,
//libc::SCHED_BATCH => Scheduling::Batch,
//libc::SCHED_DEADLINE => Scheduling::DeadLine,
//_ => Scheduling::Other,
//}
//}
//}
macro_rules!
impl_builder_from
{
macro_rules!
impl_builder_from
{
(
$t
:
ty
)
=>
{
(
$t
:
ty
)
=>
{
impl
From
<
$t
>
for
Builder
{
impl
From
<
$t
>
for
Builder
{
...
@@ -650,65 +609,3 @@ fn get_child_pids_recursive(pid: Pid, sys: &System, to: &mut BTreeSet<Pid>) {
...
@@ -650,65 +609,3 @@ fn get_child_pids_recursive(pid: Pid, sys: &System, to: &mut BTreeSet<Pid>) {
};
};
}
}
}
}
/// 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
/// mode.
///
/// Example:
///
/// ```rust,no_run
/// use roboplc::thread_rt::SystemConfig;
///
/// let _sys = SystemConfig::new().set("kernel/sched_rt_runtime_us", -1)
/// .apply()
/// .expect("Unable to set system config");
/// // some code
/// // system config is restored at the end of the scope
/// ```
#[derive(Default)]
pub
struct
SystemConfig
(
rtsc
::
system
::
linux
::
SystemConfig
);
impl
SystemConfig
{
/// Creates a new system config object
#[must_use]
pub
fn
new
()
->
Self
{
Self
::
default
()
}
/// Set a parameter to configure
pub
fn
set
<
V
:
fmt
::
Display
>
(
mut
self
,
key
:
&
'static
str
,
value
:
V
)
->
Self
{
if
is_realtime
()
{
self
.
0
=
self
.
0
.set
(
key
,
value
);
}
self
}
/// Apply values to /proc/sys keys
pub
fn
apply
(
self
)
->
Result
<
rtsc
::
system
::
linux
::
SystemConfigGuard
>
{
if
is_realtime
()
{
return
self
.
0
.apply
()
.map_err
(
Into
::
into
);
}
Ok
(
rtsc
::
system
::
linux
::
SystemConfigGuard
::
default
())
}
}
/// Configure CPU governors for the given CPUs. A wrapper around
/// [`rtsc::system::linux::CpuGovernor`] which respects simulated/real-time mode.
pub
struct
CpuGovernor
(
#
[
allow
(
dead_code
)]
rtsc
::
system
::
linux
::
CpuGovernor
);
impl
CpuGovernor
{
/// Set performance governor for the given CPUs. This sets the maximum frequency for the CPUs,
/// increasing the power consumption but lowering their latency. It is enough to specify a
/// single logical core number per physical core. The governor is restored when the returned
/// guard object is dropped.
pub
fn
performance
<
I
>
(
performance_cpus
:
I
)
->
Result
<
CpuGovernor
>
where
I
:
IntoIterator
<
Item
=
usize
>
,
{
if
is_realtime
()
{
let
inner
=
rtsc
::
system
::
linux
::
CpuGovernor
::
performance
(
performance_cpus
)
?
;
Ok
(
Self
(
inner
))
}
else
{
Ok
(
Self
(
rtsc
::
system
::
linux
::
CpuGovernor
::
default
()))
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论