Skip to content

Commit 28e7df7

Browse files
committed
riotctrl: add ieee802154 commands
1 parent 7c2e239 commit 28e7df7

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import re
2+
3+
from riotctrl.shell import ShellInteraction
4+
5+
# ==== ShellInteractions ====
6+
7+
class IEEE802154Phy(ShellInteraction):
8+
def ieee802154_config_phy(self, phy_mode, channel, tx_pow, timeout=None, async_=False):
9+
cmd = "config_phy {phy_mode} {channel} {tx_pow}" \
10+
.format(phy_mode=phy_mode, channel=channel, tx_pow=tx_pow)
11+
12+
try:
13+
res = self.cmd(cmd, timeout=timeout, async_=async_)
14+
except Exception as e:
15+
print("Error:", e)
16+
17+
if "Success" not in res:
18+
raise RuntimeError(res)
19+
20+
if str(channel) not in res:
21+
raise RuntimeError(res)
22+
23+
def ieee802154_print_info(self, timeout=None, async_=False):
24+
cmd = "get_info" \
25+
.format()
26+
27+
try:
28+
res = self.cmd(cmd, timeout=timeout, async_=async_)
29+
except Exception as e:
30+
print("Error:", e)
31+
32+
address_regex = re.compile(r"Address: (.*)$")
33+
channel_regex = re.compile(r"Channel: (.*)$")
34+
for line in res.splitlines():
35+
address_group = re.match(address_regex, line)
36+
channel_group = re.match(channel_regex, line)
37+
if (address_group):
38+
addr = address_group.groups()[0]
39+
elif (channel_group):
40+
channel = channel_group.groups()[0]
41+
break
42+
43+
return addr, channel
44+
45+
def ieee802154_tx_mode(self, command, timeout=None, async_=False):
46+
cmd = "tx_mode {command}" \
47+
.format(command=command)
48+
49+
try:
50+
res = self.cmd(cmd, timeout=timeout, async_=async_)
51+
except Exception as e:
52+
print("Error:", e)
53+
54+
if "Ok" not in res:
55+
raise RuntimeError(res)
56+
57+
def ieee802154_check_last_packet(self, long_addr, channel, timeout=None, async_=False):
58+
cmd = "check_last_packet {long_addr} {channel}" \
59+
.format(long_addr=long_addr, channel=channel)
60+
61+
try:
62+
res = self.cmd(cmd, timeout=timeout, async_=async_)
63+
except Exception as e:
64+
print("Error:", e)
65+
66+
if "Success" not in res:
67+
raise RuntimeError(res)
68+
69+
def ieee802154_reply_mode_cmd(self, reply_mode, timeout=None, async_=False):
70+
cmd = "reply {reply_mode} " \
71+
.format(reply_mode=reply_mode)
72+
73+
try:
74+
res = self.cmd(cmd, timeout=timeout, async_=async_)
75+
except Exception as e:
76+
print("Error:", e)
77+
78+
if "Success" not in res:
79+
raise RuntimeError(res)
80+
81+
def ieee802154_txtsnd(self, long_addr, length, timeout=None, async_=False):
82+
cmd = "txtsnd {long_addr} {length} " \
83+
.format(long_addr=long_addr, length=length)
84+
85+
try:
86+
res = self.cmd(cmd, timeout=timeout, async_=async_)
87+
except Exception as e:
88+
print("Error:", e)
89+
90+
def ieee802154_txtspam(self, long_addr, length, number_of_packets, time_betweeen_packets, async_=False):
91+
timeout = (number_of_packets * time_betweeen_packets) / 1000 + 1
92+
cmd = "txtspam {long_addr} {length} {number_of_packets} {time_betweeen_packets} " \
93+
.format(long_addr=long_addr, length=length, number_of_packets=number_of_packets,
94+
time_betweeen_packets=time_betweeen_packets)
95+
96+
try:
97+
res = self.cmd(cmd, timeout=timeout, async_=async_)
98+
percentages = []
99+
number_ack_packets = None
100+
percentage_ack = None
101+
for line in res.splitlines():
102+
regex_summary = re.match("-------Summary of the test-------", line)
103+
regex_send_packets = re.match("Send Packets: (.*)$", line)
104+
regex_ack_packets = re.match("Acknowledged Packets: (.*)$", line)
105+
regex_received_packets = re.match("Received Packets: (.*)$", line)
106+
regex_percentage = re.match(".*Percentage: ([\d]+)\%$", line)
107+
if (regex_summary):
108+
continue
109+
elif (regex_send_packets):
110+
number_send_packets = int(regex_send_packets.groups()[0])
111+
elif (regex_ack_packets):
112+
number_ack_packets = int(regex_ack_packets.groups()[0])
113+
elif (regex_percentage):
114+
percentages.append(int(regex_percentage.groups()[0]))
115+
elif (regex_received_packets):
116+
number_received_packets = int(regex_received_packets.groups()[0])
117+
118+
except Exception as e:
119+
print("Error:", e)
120+
121+
if len(percentages) == 2:
122+
percentage_ack = percentages[0]
123+
percentage_received = percentages[1]
124+
else:
125+
percentage_received = percentages[0]
126+
127+
return {"tx_packets": number_send_packets, "ack_packets": number_ack_packets, "percentage_ack": percentage_ack,
128+
"num_rx": number_received_packets, "percentage_rx": percentage_received}

0 commit comments

Comments
 (0)