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
a69fc4c8
Commit
a69fc4c8
authored
Mar 31, 2018
by
Michael Watzko
Browse files
Add SetNetworkIpSubnetGateway and SetNetworkMac handling
parent
1586d035
Changes
2
Hide whitespace changes
Inline
Side-by-side
Cargo.toml
View file @
a69fc4c8
...
...
@@ -12,7 +12,7 @@
[package]
name
=
"hebeanlage"
version
=
"0.
2.4
"
version
=
"0.
3.0
"
#authors = ["Jorge Aparicio <jorge@japaric.io>"]
#description = "A template for building applications for ARM Cortex-M microcontrollers"
#keywords = ["arm", "cortex-m", "template"]
...
...
src/main.rs
View file @
a69fc4c8
...
...
@@ -166,7 +166,7 @@ fn main() {
let
mut
ds93c46
=
DS93C46
::
new
(
&
mut
cs_eeprom
);
let
configuration
=
match
NetworkConfiguration
::
from
(
&
mut
ds93c46
,
&
mut
spi
,
&
mut
delay
)
{
let
mut
configuration
=
match
NetworkConfiguration
::
from
(
&
mut
ds93c46
,
&
mut
spi
,
&
mut
delay
)
{
Ok
(
configuration
)
=>
{
/*
loop {
...
...
@@ -229,7 +229,7 @@ fn main() {
}
}
match
handle_udp_requests
(
&
configuration
,
&
mut
wire
,
&
mut
delay
,
&
mut
w5500
,
&
mut
spi
,
Socket
::
Socket1
,
Socket
::
Socket0
,
&
mut
[
0u8
;
2048
])
{
match
handle_udp_requests
(
&
mut
configuration
,
&
mut
self_reset
,
&
mut
ds93c46
,
&
mut
wire
,
&
mut
delay
,
&
mut
w5500
,
&
mut
spi
,
Socket
::
Socket1
,
Socket
::
Socket0
,
&
mut
[
0u8
;
2048
])
{
Err
(
e
)
=>
{
// writeln!(display, "Error:");
// writeln!(display, "{:?}", e);
...
...
@@ -246,10 +246,11 @@ fn main() {
}
}
fn
handle_udp_requests
<
T
:
InputPin
+
OutputPin
,
S
:
FullDuplex
<
u8
,
Error
=
spi
::
Error
>>
(
net_conf
:
&
NetworkConfiguration
,
wire
:
&
mut
OneWire
<
T
>
,
delay
:
&
mut
Delay
,
w5500
:
&
mut
W5500
,
spi
:
&
mut
S
,
socket_rcv
:
Socket
,
socket_send
:
Socket
,
buffer
:
&
mut
[
u8
])
->
Result
<
Option
<
(
IpAddress
,
u16
)
>
,
HandleError
>
{
fn
handle_udp_requests
<
T
:
InputPin
+
OutputPin
,
S
:
FullDuplex
<
u8
,
Error
=
spi
::
Error
>>
(
net_conf
:
&
mut
NetworkConfiguration
,
self_reset
:
&
mut
OutputPin
,
eeprom
:
&
mut
DS93C46
,
wire
:
&
mut
OneWire
<
T
>
,
delay
:
&
mut
Delay
,
w5500
:
&
mut
W5500
,
spi
:
&
mut
S
,
socket_rcv
:
Socket
,
socket_send
:
Socket
,
buffer
:
&
mut
[
u8
])
->
Result
<
Option
<
(
IpAddress
,
u16
)
>
,
HandleError
>
{
if
let
Some
((
ip
,
port
,
size
))
=
w5500
.try_receive_udp
(
spi
,
socket_rcv
,
buffer
)
?
{
let
(
whole_request_buffer
,
response_buffer
)
=
buffer
.split_at_mut
(
size
);
let
mut
reset
=
false
;
let
response_size
=
{
let
writer
=
&
mut
&
mut
*
response_buffer
as
&
mut
::
sensor_common
::
Write
;
...
...
@@ -281,6 +282,21 @@ fn handle_udp_requests<T: InputPin + OutputPin, S: FullDuplex<u8, Error=spi::Err
transmit_requested_on_one_wire
(
wire
,
delay
,
&
mut
&*
request_content_buffer
,
writer
)
?
;
},
Request
::
SetNetworkMac
(
id
,
mac
)
=>
{
net_conf
.mac.address
.copy_from_slice
(
&
mac
);
net_conf
.write
(
eeprom
,
spi
,
delay
)
?
;
Response
::
Ok
(
id
,
Format
::
Empty
)
.write
(
writer
)
?
;
reset
=
true
;
},
Request
::
SetNetworkIpSubnetGateway
(
id
,
ip
,
subnet
,
gateway
)
=>
{
net_conf
.ip.address
.copy_from_slice
(
&
ip
);
net_conf
.subnet.address
.copy_from_slice
(
&
subnet
);
net_conf
.gateway.address
.copy_from_slice
(
&
gateway
);
net_conf
.write
(
eeprom
,
spi
,
delay
)
?
;
Response
::
Ok
(
id
,
Format
::
Empty
)
.write
(
writer
)
?
;
reset
=
true
;
},
Request
::
RetrieveNetworkConfiguration
(
id
)
=>
{
Response
::
Ok
(
id
,
Format
::
ValueOnly
(
Type
::
Bytes
(
6
+
3
*
4
)))
.write
(
writer
)
?
;
writer
.write_all
(
&
net_conf
.mac.address
)
?
;
...
...
@@ -312,6 +328,11 @@ fn handle_udp_requests<T: InputPin + OutputPin, S: FullDuplex<u8, Error=spi::Err
port
,
&
response_buffer
[
..
response_size
]
)
?
;
if
reset
{
// increase possibility that packet is out
delay
.delay_ms
(
100_u16
);
self_reset
.set_low
();
}
Ok
(
Some
((
ip
,
port
)))
}
else
{
Ok
(
None
)
...
...
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