Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
rust
bluepill_sensor
Commits
4e1e9a13
Commit
4e1e9a13
authored
Aug 26, 2018
by
Michael Watzko
Browse files
Version 0.3.6: Fix RetrieveDeviceInformation error causing operlap in returned values
parent
0618485d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Cargo.toml
View file @
4e1e9a13
...
...
@@ -12,7 +12,7 @@
[package]
name
=
"bluepill_sensor"
version
=
"0.3.
5
"
version
=
"0.3.
6
"
authors
=
[
"Michael Watzko <michael@watzko.de>"
]
description
=
"Stm32f103/Bluepill with W5500 ethernet chip, OneWire interface and sensor_common communication"
keywords
=
[
"arm"
,
"cortex-m"
,
"onewire"
,
"ethernet"
]
...
...
src/main.rs
View file @
4e1e9a13
...
...
@@ -253,6 +253,7 @@ pub fn main() -> ! {
// delay.delay_ms(100_u16);
tick
+=
1
;
platform
.information
.update_uptime_offset
();
}
}
...
...
@@ -343,7 +344,8 @@ fn handle_udp_requests_legacy(
}
Request
::
ReadSpecified
(
id
,
Bus
::
Custom
(
bus
))
=>
{
if
(
bus
as
usize
)
<
am2302
.len
()
{
// somehow 1, 2, 3 are not working atm
if
(
bus
as
usize
)
<
am2302
.len
()
&&
(
bus
<
1
||
bus
>
3
)
{
led_red
.set_low
();
led_yellow
.set_low
();
led_blue
.set_low
();
...
...
@@ -404,15 +406,17 @@ fn handle_udp_requests_legacy(
}
Request
::
RetrieveDeviceInformation
(
id
)
=>
{
let
mut
buffer
=
[
0u8
;
2
*
4
+
40
];
let
mut
buffer
=
[
0u8
;
4
+
8
+
6
];
Response
::
Ok
(
id
,
Format
::
ValueOnly
(
Type
::
Bytes
(
buffer
.len
()
as
u8
)))
.write
(
writer
)
?
;
NetworkEndian
::
write_u32
(
&
mut
buffer
[
0
..
],
info
.frequency
()
.0
);
NetworkEndian
::
write_u32
(
&
mut
buffer
[
4
..
],
info
.uptime
());
NetworkEndian
::
write_u64
(
&
mut
buffer
[
4
..
],
info
.uptime
());
buffer
[
12
]
=
info
.cpu_implementer
();
buffer
[
13
]
=
info
.cpu_variant
();
NetworkEndian
::
write_u16
(
&
mut
buffer
[
14
..
],
info
.cpu_partnumber
());
buffer
[
16
]
=
info
.cpu_revision
();
buffer
[
17
]
=
MAGIC_EEPROM_CRC_START
;
buffer
[
5
]
=
info
.cpu_implementer
();
buffer
[
6
]
=
info
.cpu_variant
();
NetworkEndian
::
write_u16
(
&
mut
buffer
[
7
..
],
info
.cpu_partnumber
());
buffer
[
9
]
=
info
.cpu_revision
();
writer
.write_all
(
&
buffer
)
?
;
}
...
...
src/platform.rs
View file @
4e1e9a13
...
...
@@ -128,6 +128,8 @@ impl<'a, 'inner: 'a> Platform<'a, 'inner> {
pub
struct
DeviceInformation
{
frequency
:
Hertz
,
init
:
Instant
,
init_last
:
u32
,
uptime_offset
:
u64
,
cpuid
:
u32
,
}
...
...
@@ -136,6 +138,8 @@ impl DeviceInformation {
DeviceInformation
{
frequency
:
timer
.frequency
(),
init
:
timer
.now
(),
init_last
:
0
,
uptime_offset
:
0
,
cpuid
,
}
}
...
...
@@ -144,8 +148,15 @@ impl DeviceInformation {
self
.frequency
}
pub
fn
uptime
(
&
self
)
->
u32
{
self
.init
.elapsed
()
pub
fn
update_uptime_offset
(
&
mut
self
)
{
let
elapsed
=
self
.init
.elapsed
();
let
additional_offset
=
elapsed
.wrapping_sub
(
self
.init_last
);
self
.init_last
=
elapsed
;
self
.uptime_offset
+=
additional_offset
as
u64
;
}
pub
fn
uptime
(
&
self
)
->
u64
{
self
.uptime_offset
+
self
.init
.elapsed
()
.wrapping_sub
(
self
.init_last
)
as
u64
}
pub
fn
cpu_id
(
&
self
)
->
u32
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment