Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Heizung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
c3pb
Heizung
Commits
490b1c9a
Commit
490b1c9a
authored
1 year ago
by
Benjamin Koch
Browse files
Options
Downloads
Patches
Plain Diff
add reset via Modbus
parent
c9b44d26
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
firmware/rust1/rtumaster_pymodbus.py
+4
-0
4 additions, 0 deletions
firmware/rust1/rtumaster_pymodbus.py
firmware/rust1/src/bin/heizung.rs
+20
-0
20 additions, 0 deletions
firmware/rust1/src/bin/heizung.rs
with
24 additions
and
0 deletions
firmware/rust1/rtumaster_pymodbus.py
+
4
−
0
View file @
490b1c9a
...
...
@@ -54,6 +54,10 @@ def main():
write_registers
=
[
struct
.
unpack
(
"
>H
"
,
b
"
PI
"
)[
0
],
103
],
slave
=
DEVICE_ADDR
)
logger
.
info
(
"
read/write regs: %s: %r
"
,
x
,
x
.
registers
)
if
False
:
x
=
client
.
write_registers
(
1
,
struct
.
unpack
(
"
>H
"
,
b
"
RE
"
)[
0
],
slave
=
DEVICE_ADDR
)
logger
.
info
(
"
write to reset: %s
"
,
x
)
x
=
client
.
read_file_record
([
# documentation says tuple of: Reference type, File number, Record Number, Record Length
# but actually an object is expected:
...
...
This diff is collapsed.
Click to expand it.
firmware/rust1/src/bin/heizung.rs
+
20
−
0
View file @
490b1c9a
...
...
@@ -306,6 +306,13 @@ async fn adc_task(shared_data: &'static AdcData, adc: ADC, mut en_measure_curren
}
#[embassy_executor::task]
async
fn
reset_soon
(
delay
:
Duration
)
{
Timer
::
after
(
delay
)
.await
;
cortex_m
::
peripheral
::
SCB
::
sys_reset
();
}
const
FLASH_SIZE
:
usize
=
2
*
1024
*
1024
;
#[derive(Clone,
Copy,
PartialEq,
Eq)]
...
...
@@ -334,6 +341,8 @@ struct ModBusRegs<'a> {
consistent_read_addr
:
u16
,
consistent_read_length
:
u16
,
consistent_read_data
:
[
u16
;
4
],
spawner
:
Spawner
,
}
impl
<
'a
>
ModBusRegs
<
'a
>
{
...
...
@@ -471,6 +480,7 @@ impl<'a> ModbusRegisters for ModBusRegs<'a> {
const
OK
:
u16
=
be
(
"OK"
);
// mark booted
const
UP
:
u16
=
be
(
"UP"
);
// mark updated -> swap to DFU on next reset
const
PI
:
u16
=
be
(
"PI"
);
// ping / no-op
const
RE
:
u16
=
be
(
"RE"
);
// reset
match
value
{
OK
=>
{
self
.uf2updater
.mark_booted
()
.map
(|
_
|
value
)
...
...
@@ -484,6 +494,15 @@ impl<'a> ModbusRegisters for ModBusRegs<'a> {
PI
=>
{
Ok
(
value
)
},
RE
=>
{
match
self
.spawner
.spawn
(
reset_soon
(
Duration
::
from_millis
(
100
)))
{
Ok
(())
=>
Ok
(
value
),
Err
(
err
)
=>
{
error!
(
"Couldn't spawn reset_soon: {:?}"
,
err
);
Err
(
ModbusErrorCode
::
ServerDeviceFailure
)
}
}
},
_
=>
Err
(
ModbusErrorCode
::
IllegalDataValue
),
}
},
...
...
@@ -649,6 +668,7 @@ async fn main2(spawner: Spawner) {
consistent_read_addr
:
u16
::
default
(),
consistent_read_length
:
u16
::
default
(),
consistent_read_data
:
[
0
;
4
],
spawner
:
spawner
.clone
(),
}),
);
unwrap!
(
spawner
.spawn
(
uart_task
(
rs485
)));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment