Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
6d5800dc
提交
6d5800dc
authored
3月 19, 2024
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
raw udp for primary ipc
上级
e805cf4f
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
27 行增加
和
14 行删除
+27
-14
Cargo.toml
Cargo.toml
+1
-1
raw-udp.rs
examples/raw-udp.rs
+5
-3
mod.rs
src/io/mod.rs
+3
-1
raw_udp.rs
src/io/raw_udp.rs
+18
-9
没有找到文件。
Cargo.toml
浏览文件 @
6d5800dc
[package]
name
=
"roboplc"
version
=
"0.1.1
4
"
version
=
"0.1.1
5
"
edition
=
"2021"
authors
=
[
"Serhij S. <div@altertech.com>"
]
license
=
"Apache-2.0"
...
...
examples/raw-udp.rs
浏览文件 @
6d5800dc
use
roboplc
::
io
::
raw_udp
::{
UdpInput
,
UdpOutput
};
use
roboplc
::
io
::
{
UdpReceiver
,
UdpSender
};
use
roboplc
::
prelude
::
*
;
use
roboplc
::
time
::
interval
;
use
tracing
::{
error
,
info
};
...
...
@@ -10,6 +10,8 @@ enum Message {
// A raw UDP structure, to be sent and received
//
// The recommended way of IPC for RoboPLC
//
// Raw UDP structures are used by various software, e.g. Matlab, LabView, etc. as well as by some
// fieldbus devices
#[derive(Debug,
Clone)]
...
...
@@ -28,7 +30,7 @@ struct UdpIn {}
impl
Worker
<
Message
,
()
>
for
UdpIn
{
fn
run
(
&
mut
self
,
context
:
&
Context
<
Message
,
()
>
)
->
WResult
{
let
server
=
Udp
Input
::
<
EnvData
>
::
bind
(
"127.0.0.1:25000"
,
24
)
?
;
let
server
=
Udp
Receiver
::
<
EnvData
>
::
bind
(
"127.0.0.1:25000"
,
24
)
?
;
// [`UdpInput`] is an iterator of incoming UDP packets which are automatically parsed
for
data
in
server
{
match
data
{
...
...
@@ -52,7 +54,7 @@ struct UdpOut {}
impl
Worker
<
Message
,
()
>
for
UdpOut
{
fn
run
(
&
mut
self
,
context
:
&
Context
<
Message
,
()
>
)
->
WResult
{
let
mut
client
=
Udp
Output
::
connect
(
"localhost:25000"
)
?
;
let
mut
client
=
Udp
Sender
::
connect
(
"localhost:25000"
)
?
;
for
_
in
interval
(
Duration
::
from_secs
(
1
))
{
let
data
=
EnvData
{
temp
:
25.0
,
...
...
src/io/mod.rs
浏览文件 @
6d5800dc
...
...
@@ -4,7 +4,9 @@ use binrw::{BinRead, BinWrite};
use
crate
::
Result
;
pub
mod
modbus
;
pub
mod
raw_udp
;
mod
raw_udp
;
pub
use
raw_udp
::{
UdpReceiver
,
UdpSender
};
#[allow(clippy
::
module_name_repetitions)]
pub
trait
IoMapping
{
...
...
src/io/raw_udp.rs
浏览文件 @
6d5800dc
...
...
@@ -7,7 +7,8 @@ use std::{
use
crate
::{
Error
,
Result
};
pub
struct
UdpInput
<
T
>
/// Raw UDP receiver
pub
struct
UdpReceiver
<
T
>
where
T
:
for
<
'a
>
BinRead
<
Args
<
'a
>
=
()
>
,
{
...
...
@@ -16,7 +17,7 @@ where
_phantom
:
PhantomData
<
T
>
,
}
impl
<
T
>
Udp
Input
<
T
>
impl
<
T
>
Udp
Receiver
<
T
>
where
T
:
for
<
'a
>
BinRead
<
Args
<
'a
>
=
()
>
,
{
...
...
@@ -30,7 +31,7 @@ where
}
}
impl
<
T
>
Iterator
for
Udp
Input
<
T
>
impl
<
T
>
Iterator
for
Udp
Receiver
<
T
>
where
T
:
for
<
'a
>
BinRead
<
Args
<
'a
>
=
()
>
,
{
...
...
@@ -47,13 +48,23 @@ where
}
}
pub
struct
UdpOutput
{
/// Raw UDP sender
pub
struct
UdpSender
<
T
>
where
T
:
for
<
'a
>
BinWrite
<
Args
<
'a
>
=
()
>
,
{
socket
:
UdpSocket
,
target
:
SocketAddr
,
data_buf
:
Vec
<
u8
>
,
// keep the generic `T` global (including traits) as each instance is dedicated to send a
// specific type only
_phantom
:
PhantomData
<
T
>
,
}
impl
UdpOutput
{
impl
<
T
>
UdpSender
<
T
>
where
T
:
for
<
'a
>
BinWrite
<
Args
<
'a
>
=
()
>
,
{
pub
fn
connect
<
A
:
ToSocketAddrs
>
(
addr
:
A
)
->
Result
<
Self
>
{
let
socket
=
UdpSocket
::
bind
((
"0.0.0.0"
,
0
))
?
;
let
target
=
addr
...
...
@@ -64,13 +75,11 @@ impl UdpOutput {
socket
,
target
,
data_buf
:
<
_
>
::
default
(),
_phantom
:
PhantomData
,
})
}
pub
fn
send
<
T
>
(
&
mut
self
,
value
:
T
)
->
Result
<
()
>
where
T
:
for
<
'a
>
BinWrite
<
Args
<
'a
>
=
()
>
,
{
pub
fn
send
(
&
mut
self
,
value
:
T
)
->
Result
<
()
>
{
let
mut
buf
=
Cursor
::
new
(
&
mut
self
.data_buf
);
value
.write_le
(
&
mut
buf
)
?
;
self
.socket
.send_to
(
&
self
.data_buf
,
self
.target
)
?
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论