Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
RoboPLC
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄新宇
RoboPLC
Commits
4facb7f2
提交
4facb7f2
authored
1月 05, 2025
作者:
Serhij S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
show versions
上级
86eba48f
全部展开
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
71 行增加
和
4 行删除
+71
-4
Cargo.lock
roboplc-cli/Cargo.lock
+0
-0
arguments.rs
roboplc-cli/src/arguments.rs
+7
-1
main.rs
roboplc-cli/src/main.rs
+2
-2
remote.rs
roboplc-cli/src/remote.rs
+62
-1
没有找到文件。
roboplc-cli/Cargo.lock
浏览文件 @
4facb7f2
差异被折叠。
点击展开。
roboplc-cli/src/arguments.rs
浏览文件 @
4facb7f2
...
@@ -32,7 +32,7 @@ pub enum SubCommand {
...
@@ -32,7 +32,7 @@ pub enum SubCommand {
#[clap(name
=
"new"
,
about
=
"Generate a new project"
)]
#[clap(name
=
"new"
,
about
=
"Generate a new project"
)]
New
(
NewCommand
),
New
(
NewCommand
),
#[clap(name
=
"stat"
,
about
=
"Get program status"
)]
#[clap(name
=
"stat"
,
about
=
"Get program status"
)]
Stat
,
Stat
(
StatCommand
)
,
#[clap(name
=
"config"
,
about
=
"Switch remote into CONFIG mode"
)]
#[clap(name
=
"config"
,
about
=
"Switch remote into CONFIG mode"
)]
Config
,
Config
,
#[clap(name
=
"run"
,
about
=
"Switch remote into RUN mode"
)]
#[clap(name
=
"run"
,
about
=
"Switch remote into RUN mode"
)]
...
@@ -118,6 +118,12 @@ impl LockingPolicy {
...
@@ -118,6 +118,12 @@ impl LockingPolicy {
}
}
}
}
#[derive(Parser)]
pub
struct
StatCommand
{
#[clap(long,
help
=
"Show remote versions (requires RoboPLC Pro)"
)]
pub
show_versions
:
bool
,
}
#[derive(Parser)]
#[derive(Parser)]
pub
struct
FlashCommand
{
pub
struct
FlashCommand
{
#[clap(long,
env
=
"CARGO"
,
help
=
"cargo/cross binary path"
)]
#[clap(long,
env
=
"CARGO"
,
help
=
"cargo/cross binary path"
)]
...
...
roboplc-cli/src/main.rs
浏览文件 @
4facb7f2
...
@@ -102,8 +102,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
...
@@ -102,8 +102,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
SubCommand
::
New
(
_
)
=>
{
SubCommand
::
New
(
_
)
=>
{
panic!
(
"BUG"
);
panic!
(
"BUG"
);
}
}
SubCommand
::
Stat
=>
{
SubCommand
::
Stat
(
opts
)
=>
{
remote
::
stat
(
&
url
,
&
key
,
agent
)
?
;
remote
::
stat
(
&
url
,
&
key
,
agent
,
opts
.show_versions
)
?
;
}
}
SubCommand
::
Config
=>
{
SubCommand
::
Config
=>
{
remote
::
set_mode
(
&
url
,
&
key
,
&
agent
,
Mode
::
Config
,
true
)
?
;
remote
::
set_mode
(
&
url
,
&
key
,
&
agent
,
Mode
::
Config
,
true
)
?
;
...
...
roboplc-cli/src/remote.rs
浏览文件 @
4facb7f2
use
bma_ts
::
Timestamp
;
use
prettytable
::{
cell
,
row
,
Table
};
use
serde
::
Deserialize
;
use
ureq
::
Agent
;
use
ureq
::
Agent
;
use
crate
::{
use
crate
::{
...
@@ -6,7 +9,12 @@ use crate::{
...
@@ -6,7 +9,12 @@ use crate::{
API_PREFIX
,
API_PREFIX
,
};
};
pub
fn
stat
(
url
:
&
str
,
key
:
&
str
,
agent
:
Agent
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
pub
fn
stat
(
url
:
&
str
,
key
:
&
str
,
agent
:
Agent
,
show_versions
:
bool
,
)
->
Result
<
(),
Box
<
dyn
std
::
error
::
Error
>>
{
let
resp
=
agent
let
resp
=
agent
.post
(
&
format!
(
"{}{}/query.stats.program"
,
url
,
API_PREFIX
))
.post
(
&
format!
(
"{}{}/query.stats.program"
,
url
,
API_PREFIX
))
.set
(
"x-auth-key"
,
key
)
.set
(
"x-auth-key"
,
key
)
...
@@ -14,9 +22,62 @@ pub fn stat(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error
...
@@ -14,9 +22,62 @@ pub fn stat(url: &str, key: &str, agent: Agent) -> Result<(), Box<dyn std::error
.process_error
()
?
;
.process_error
()
?
;
let
stats
:
State
=
resp
.into_json
()
?
;
let
stats
:
State
=
resp
.into_json
()
?
;
stats
.print_std
();
stats
.print_std
();
if
show_versions
{
println!
();
let
resp
=
agent
.post
(
&
format!
(
"{}{}/query.program.meta"
,
url
,
API_PREFIX
))
.set
(
"x-auth-key"
,
key
)
.call
()
.process_error
()
?
;
let
meta
:
PlcMetadata
=
resp
.into_json
()
?
;
let
mut
table
=
Table
::
new
();
table
.add_row
(
row!
[
"Program"
,
"Exists"
,
"Created"
]);
table
.add_row
(
row!
[
"current"
,
meta
.program_current
.exists_as_cell
(),
meta
.program_current
.created_iso
()
?
]);
for
(
i
,
program
)
in
meta
.program_previous
.iter
()
.enumerate
()
{
table
.add_row
(
row!
[
format!
(
"prev.{}"
,
i
),
program
.exists_as_cell
(),
program
.created_iso
()
?
]);
}
table
.printstd
();
}
Ok
(())
Ok
(())
}
}
#[derive(Deserialize)]
struct
PlcMetadata
{
program_current
:
ProgramFileMetdata
,
#[serde(default)]
program_previous
:
Vec
<
ProgramFileMetdata
>
,
}
#[derive(Deserialize)]
struct
ProgramFileMetdata
{
exists
:
bool
,
created
:
Timestamp
,
}
impl
ProgramFileMetdata
{
fn
exists_as_cell
(
&
self
)
->
prettytable
::
Cell
{
if
!
self
.exists
{
cell!
(
"YES"
)
}
else
{
cell!
(
Fr
->
"NO"
)
}
}
fn
created_iso
(
&
self
)
->
Result
<
String
,
Box
<
dyn
std
::
error
::
Error
>>
{
Ok
(
self
.created
.try_into_datetime_local
()
?
.to_rfc3339_opts
(
chrono
::
SecondsFormat
::
Secs
,
true
))
}
}
pub
fn
set_mode
(
pub
fn
set_mode
(
url
:
&
str
,
url
:
&
str
,
key
:
&
str
,
key
:
&
str
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论