mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 01:23:49 +01:00
examples/twr_aloha: add channel and txpower to ifconfig
This commit is contained in:
parent
544551de86
commit
90af3bd026
@ -23,6 +23,7 @@ class TwrShell(Reboot, TwrCmd):
|
||||
"hwaddr": None,
|
||||
"hwaddr64": None,
|
||||
"panid": None,
|
||||
"channel": None,
|
||||
}
|
||||
|
||||
def parse_netif(self):
|
||||
@ -41,6 +42,9 @@ class TwrShell(Reboot, TwrCmd):
|
||||
def panid(self):
|
||||
return self._netif["panid"]
|
||||
|
||||
def channel(self):
|
||||
return self._netif["channel"]
|
||||
|
||||
|
||||
class TestTWRBase(unittest.TestCase):
|
||||
DEBUG = False
|
||||
@ -68,7 +72,7 @@ class TestTWR(TestTWRBase):
|
||||
assert self.shell.panid() == "DE:CA"
|
||||
assert self.shell.hwaddr() is not None
|
||||
assert self.shell.hwaddr64() is not None
|
||||
assert self.shell.panid() is not None
|
||||
assert self.shell.channel() == "5" # default channel is 5
|
||||
|
||||
def test_listen(self):
|
||||
assert "[twr]: start listening" in self.shell.twr_listen(on=True)
|
||||
|
||||
@ -35,6 +35,14 @@
|
||||
#define IEEE802154_SHORT_ADDRESS_LEN_STR_MAX \
|
||||
(sizeof("00:00"))
|
||||
|
||||
/* See 7.2.31.1 Units of TX Power Control */
|
||||
#define DW1000_TX_POWER_COARSE_SHIFT (5)
|
||||
#define DW1000_TX_POWER_COARSE_MASK (0xE0)
|
||||
#define DW1000_TX_POWER_FINE_MASK (0x1F)
|
||||
#define DW1000_TX_POWER_MULTI (10)
|
||||
#define DW1000_TX_POWER_COARSE_STEP (30) /* 3dbM * 10 */
|
||||
#define DW1000_TX_POWER_FINE_STEP (5) /* 0.5dbM * 10 */
|
||||
|
||||
int _twr_ifconfig(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
@ -49,11 +57,24 @@ int _twr_ifconfig(int argc, char **argv)
|
||||
printf("\tHWaddr: %s ",
|
||||
l2util_addr_to_str(buffer, IEEE802154_SHORT_ADDRESS_LEN, addr_str));
|
||||
byteorder_htobebufs(buffer, udev->pan_id);
|
||||
printf("Channel: %d ", udev->config.channel);
|
||||
printf("NID: %s\n\n",
|
||||
l2util_addr_to_str(buffer, IEEE802154_SHORT_ADDRESS_LEN, addr_str));
|
||||
byteorder_htobebufll(buffer, udev->euid);
|
||||
printf("\t\tLong HWaddr: %s\n",
|
||||
l2util_addr_to_str(buffer, IEEE802154_LONG_ADDRESS_LEN, addr_str));
|
||||
/* 000 -> 18dBM gain, 110 -> 0dBm gain */
|
||||
int tx_power =
|
||||
DW1000_TX_POWER_COARSE_STEP *
|
||||
(6 -
|
||||
((udev->config.txrf.BOOSTNORM & DW1000_TX_POWER_COARSE_MASK) >>
|
||||
DW1000_TX_POWER_COARSE_SHIFT)) +
|
||||
(udev->config.txrf.BOOSTNORM & DW1000_TX_POWER_FINE_MASK) *
|
||||
DW1000_TX_POWER_FINE_STEP;
|
||||
|
||||
printf("\t\tTX-Power: %d.%ddBm ", tx_power / DW1000_TX_POWER_MULTI,
|
||||
tx_power > (tx_power / DW1000_TX_POWER_MULTI) * DW1000_TX_POWER_MULTI ? 5 : 0);
|
||||
printf("TC-PGdelay: 0x%02x\n", udev->config.txrf.PGdly);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@ class TwrIfconfigParser(ShellInteractionParser):
|
||||
hwaddr_c = re.compile(r"HWaddr:\s+(?P<name>[0-9a-fA-F:]+)\s")
|
||||
hwaddr64_c = re.compile(r"Long HWaddr:\s+(?P<name>[0-9a-fA-F:]+)")
|
||||
panid_c = re.compile(r"NID:\s+(?P<name>[0-9a-fA-F:]+)")
|
||||
channel_c = re.compile(r"Channel:\s+(?P<name>[0-9]+)")
|
||||
|
||||
def parse(self, cmd_output):
|
||||
netif = {
|
||||
@ -25,6 +26,7 @@ class TwrIfconfigParser(ShellInteractionParser):
|
||||
"hwaddr": None,
|
||||
"hwaddr64": None,
|
||||
"panid": None,
|
||||
"channel": None,
|
||||
}
|
||||
for line in cmd_output.splitlines():
|
||||
m = self.iface_c.search(line)
|
||||
@ -39,6 +41,9 @@ class TwrIfconfigParser(ShellInteractionParser):
|
||||
m = self.panid_c.search(line)
|
||||
if m is not None:
|
||||
netif["panid"] = m.group("name")
|
||||
m = self.channel_c.search(line)
|
||||
if m is not None:
|
||||
netif["channel"] = m.group("name")
|
||||
return netif
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user