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
18095043
Commit
18095043
authored
1 year ago
by
Benjamin Koch
Browse files
Options
Downloads
Patches
Plain Diff
use to_be_bytes() instead of byteorder crate
parent
f4a2935d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
firmware/rust1/Cargo.lock
+0
-1
0 additions, 1 deletion
firmware/rust1/Cargo.lock
firmware/rust1/Cargo.toml
+0
-1
0 additions, 1 deletion
firmware/rust1/Cargo.toml
firmware/rust1/src/modbus_server.rs
+7
-7
7 additions, 7 deletions
firmware/rust1/src/modbus_server.rs
with
7 additions
and
9 deletions
firmware/rust1/Cargo.lock
+
0
−
1
View file @
18095043
...
...
@@ -1027,7 +1027,6 @@ name = "heizung"
version = "0.1.0"
dependencies = [
"byte-slice-cast 1.2.2",
"byteorder",
"cortex-m",
"cortex-m-rt",
"crc",
...
...
This diff is collapsed.
Click to expand it.
firmware/rust1/Cargo.toml
+
0
−
1
View file @
18095043
...
...
@@ -56,7 +56,6 @@ pio = "0.2.1"
heapless
=
"0.7.16"
crc
=
"3.0.1"
byteorder
=
"1.4.3"
[
profile.release
]
debug
=
true
This diff is collapsed.
Click to expand it.
firmware/rust1/src/modbus_server.rs
+
7
−
7
View file @
18095043
...
...
@@ -4,8 +4,6 @@ use futures::Future;
use
heapless
::
Vec
;
use
crc
::{
Crc
,
CRC_16_MODBUS
,
Digest
};
use
embassy_rp
::
uart
;
use
core
::
fmt
::
Write
;
use
byteorder
::{
BigEndian
,
ReadBytesExt
,
WriteBytesExt
};
use
crate
::
rs485
::{
RS485Handler
};
...
...
@@ -102,18 +100,20 @@ impl<REGS: ModbusRegisters> ModbusServer<REGS> {
txbuf
.clear
();
let
capacity
=
txbuf
.capacity
();
let
map_err
=
|
x
:
Result
<
(),
()
>
|
x
.or
(
Err
(
ServerDeviceFailure
));
fn
map_err
<
T
>
(
x
:
Result
<
(),
T
>
)
->
Result
<
(),
ModbusErrorCode
>
{
x
.or
(
Err
(
ServerDeviceFailure
))
}
fn
push
(
txbuf
:
&
mut
Vec
<
u8
,
BUF_LENGTH
>
,
x
:
u8
)
->
Result
<
(),
ModbusErrorCode
>
{
map_err
(
txbuf
.push
(
x
))
;
map_err
(
txbuf
.push
(
x
))
}
fn
push_many
(
txbuf
:
&
mut
Vec
<
u8
,
BUF_LENGTH
>
,
xs
:
&
[
u8
])
->
Result
<
(),
ModbusErrorCode
>
{
for
x
in
xs
{
push
(
txbuf
,
x
)
?
;
push
(
txbuf
,
*
x
)
?
;
}
Ok
(())
}
fn
push_u16be
(
txbuf
:
&
mut
Vec
<
u8
,
BUF_LENGTH
>
,
x
:
u16
)
->
Result
<
(),
ModbusErrorCode
>
{
map_err
(
txbuf
.write_u16
::
<
BigEndian
>
(
x
))
;
push_many
(
txbuf
,
&
x
.to_be_bytes
(
))
}
// see https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf
...
...
@@ -210,7 +210,7 @@ impl<REGS: ModbusRegisters> ModbusServer<REGS> {
let
actual_new_value
=
self
.regs
.write_register
(
rxbuf
[
0
],
start
,
value
)
?
;
if
should_reply
{
push_many
(
txbuf
,
&
rxbuf
[
0
..
4
])
?
;
push_u16be
(
txbuf
,
value
)
?
;
push_u16be
(
txbuf
,
actual_new_
value
)
?
;
}
Ok
(())
},
...
...
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