Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Robert Hartung
ieee802154-radio-eval
Commits
86e5974f
Commit
86e5974f
authored
Jan 11, 2018
by
Robert Hartung
Browse files
adds latest coordinator (cleaned up)
parent
2f4819b4
Changes
1
Show whitespace changes
Inline
Side-by-side
software/coordinator2.py
View file @
86e5974f
...
@@ -56,18 +56,7 @@ def calculate_checksum(*args):
...
@@ -56,18 +56,7 @@ def calculate_checksum(*args):
s
+=
sum
(
bytes
(
a
,
'utf-8'
))
s
+=
sum
(
bytes
(
a
,
'utf-8'
))
return
hex
(
s
&
0xFF
)[
2
:].
upper
().
zfill
(
2
)
return
hex
(
s
&
0xFF
)[
2
:].
upper
().
zfill
(
2
)
def
handle_match_tx
(
src_id
,
ts
,
match_tx
):
def
handle_serial_rx
(
d
):
src_id
=
d
[
'src'
][
'id'
][
0
]
ts
=
d
[
'ts'
]
line
=
d
[
'line'
].
strip
()
match_ifconfig
=
re_ifconfig
.
match
(
line
)
if
match_ifconfig
is
not
None
:
return
True
match_tx
=
re_tx
.
match
(
line
)
if
match_tx
is
not
None
:
seq_nr
=
match_tx
.
group
(
"seq_nr"
)
seq_nr
=
match_tx
.
group
(
"seq_nr"
)
checksum
=
match_tx
.
group
(
"checksum"
)
checksum
=
match_tx
.
group
(
"checksum"
)
...
@@ -81,8 +70,8 @@ def handle_serial_rx(d):
...
@@ -81,8 +70,8 @@ def handle_serial_rx(d):
else
:
else
:
logger
.
debug
(
"Corrupt Line"
)
logger
.
debug
(
"Corrupt Line"
)
return
False
return
False
match_rx
=
re_rx
.
match
(
line
)
if
match_rx
is
not
None
:
def
handle_match_rx
(
src_id
,
ts
,
match_rx
)
:
node_id
=
match_rx
.
group
(
"node_id"
)
node_id
=
match_rx
.
group
(
"node_id"
)
seq_nr
=
match_rx
.
group
(
"seq_nr"
)
seq_nr
=
match_rx
.
group
(
"seq_nr"
)
rssi
=
match_rx
.
group
(
'rssi'
)
rssi
=
match_rx
.
group
(
'rssi'
)
...
@@ -93,15 +82,15 @@ def handle_serial_rx(d):
...
@@ -93,15 +82,15 @@ def handle_serial_rx(d):
if
expected_checksum
==
checksum
:
if
expected_checksum
==
checksum
:
session
=
Session
()
session
=
Session
()
session
.
add
(
RX
(
serial_id
=
src_id
,
ts
=
ts
,
seq_nr
=
seq_nr
,
node_id
=
node_id
,
rssi
=
rssi
,
lqi
=
lqi
))
session
.
add
(
RX
(
serial_id
=
src_id
,
ts
=
ts
,
seq_nr
=
seq_nr
,
node_id
=
node_id
,
rssi
=
rssi
,
lqi
=
lqi
))
# TODO(rh): Add sqlite3.OperationalError
session
.
commit
()
session
.
commit
()
#logger.log("[{}] RX: #{} from {}".format( src_id, node_id, seq_nr ))
#logger.log("[{}] RX: #{} from {}".format( src_id, node_id, seq_nr ))
return
True
return
True
else
:
else
:
logger
.
debug
(
"Corrupt Line {} != {}"
.
format
(
expected_checksum
,
checksum
)
)
logger
.
debug
(
"Corrupt Line {} != {}"
.
format
(
expected_checksum
,
checksum
)
)
return
False
return
False
return
True
match_rx_corrupt
=
re_rx_corrupt
.
match
(
line
)
def
handle_match_rx_corrupt
(
src_id
,
ts
,
match_rx_corrupt
):
if
match_rx_corrupt
is
not
None
:
rssi
=
match_rx_corrupt
.
group
(
'rssi'
)
rssi
=
match_rx_corrupt
.
group
(
'rssi'
)
lqi
=
match_rx_corrupt
.
group
(
'lqi'
)
lqi
=
match_rx_corrupt
.
group
(
'lqi'
)
payload
=
match_rx_corrupt
.
group
(
'payload'
).
strip
()
payload
=
match_rx_corrupt
.
group
(
'payload'
).
strip
()
...
@@ -110,6 +99,24 @@ def handle_serial_rx(d):
...
@@ -110,6 +99,24 @@ def handle_serial_rx(d):
session
.
add
(
Corrupt
(
serial_id
=
src_id
,
ts
=
ts
,
rssi
=
rssi
,
lqi
=
lqi
,
payload
=
payload
))
session
.
add
(
Corrupt
(
serial_id
=
src_id
,
ts
=
ts
,
rssi
=
rssi
,
lqi
=
lqi
,
payload
=
payload
))
session
.
commit
()
session
.
commit
()
return
True
return
True
def
handle_serial_rx
(
d
):
src_id
=
d
[
'src'
][
'id'
][
0
]
ts
=
d
[
'ts'
]
line
=
d
[
'line'
].
strip
()
match_ifconfig
=
re_ifconfig
.
match
(
line
)
if
match_ifconfig
is
not
None
:
return
True
match_tx
=
re_tx
.
match
(
line
)
if
match_tx
is
not
None
:
return
handle_match_tx
(
src_id
,
ts
,
match_tx
)
match_rx
=
re_rx
.
match
(
line
)
if
match_rx
is
not
None
:
return
handle_match_rx
(
src_id
,
ts
,
match_rx
)
match_rx_corrupt
=
re_rx_corrupt
.
match
(
line
)
if
match_rx_corrupt
is
not
None
:
return
handle_match_rx_corrupt
(
src_id
,
ts
,
match_rx_corrupt
)
return
False
return
False
class
PRREvalClient
(
Client
):
class
PRREvalClient
(
Client
):
...
@@ -130,10 +137,15 @@ class PRREvalClient(Client):
...
@@ -130,10 +137,15 @@ class PRREvalClient(Client):
logger
.
log
(
"PAYLOAD={} "
.
format
(
payload
)
)
logger
.
log
(
"PAYLOAD={} "
.
format
(
payload
)
)
self
.
send_all
(
"payload {}
\n
"
.
format
(
payload
)
)
self
.
send_all
(
"payload {}
\n
"
.
format
(
payload
)
)
sleep
(
0.5
)
sleep
(
0.5
)
# TODO(rh) START ROUND:
# round = Round( channel=channel, power=power, payload=payload )
# session.add( round )
# sessionc.commit()
for
sender
in
NODES
:
for
sender
in
NODES
:
self
.
send
({
'dst'
:
{
'id'
:
sender
},
'type'
:
'serial_tx'
,
'line'
:
'tx 5 200000
\n
'
})
self
.
send
({
'dst'
:
{
'id'
:
sender
},
'type'
:
'serial_tx'
,
'line'
:
'tx 5 200000
\n
'
})
# 5 packets, 200ms -> 1 second
# 5 packets, 200ms -> 1 second
sleep
(
1.5
)
sleep
(
1.5
)
self
.
send
({
'dst'
:
{
'id'
:
sender
},
'type'
:
'serial_tx'
,
'line'
:
'ifconfig 3 set state idle
\n
'
})
def
run
(
self
):
def
run
(
self
):
while
True
:
while
True
:
...
@@ -144,7 +156,7 @@ class PRREvalClient(Client):
...
@@ -144,7 +156,7 @@ class PRREvalClient(Client):
break
break
def
set_channel
(
self
,
channel
):
def
set_channel
(
self
,
channel
):
self
.
send_all
(
"ifconfig 3 set state idle
\n
"
)
#
self.send_all("ifconfig 3 set state idle\n")
self
.
send_all
(
"ifconfig 3 set channel {}
\n
"
.
format
(
channel
))
self
.
send_all
(
"ifconfig 3 set channel {}
\n
"
.
format
(
channel
))
def
set_txpower
(
self
,
power
):
def
set_txpower
(
self
,
power
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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