From 90af3bd0263f5084a8ff9aa8a7e706ea5f8adeb3 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Wed, 27 Apr 2022 09:07:23 +0200 Subject: [PATCH] examples/twr_aloha: add channel and txpower to ifconfig --- .../twr_aloha/tests-with-config/01-run.py | 6 +++++- examples/twr_aloha/twr_shell.c | 21 +++++++++++++++++++ examples/twr_aloha/twr_shell.py | 5 +++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/examples/twr_aloha/tests-with-config/01-run.py b/examples/twr_aloha/tests-with-config/01-run.py index 3346919b27..a75ad7f1ff 100755 --- a/examples/twr_aloha/tests-with-config/01-run.py +++ b/examples/twr_aloha/tests-with-config/01-run.py @@ -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) diff --git a/examples/twr_aloha/twr_shell.c b/examples/twr_aloha/twr_shell.c index 438fbd3e52..64c2c92ce4 100644 --- a/examples/twr_aloha/twr_shell.c +++ b/examples/twr_aloha/twr_shell.c @@ -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; } diff --git a/examples/twr_aloha/twr_shell.py b/examples/twr_aloha/twr_shell.py index d479327214..d002251108 100644 --- a/examples/twr_aloha/twr_shell.py +++ b/examples/twr_aloha/twr_shell.py @@ -18,6 +18,7 @@ class TwrIfconfigParser(ShellInteractionParser): hwaddr_c = re.compile(r"HWaddr:\s+(?P[0-9a-fA-F:]+)\s") hwaddr64_c = re.compile(r"Long HWaddr:\s+(?P[0-9a-fA-F:]+)") panid_c = re.compile(r"NID:\s+(?P[0-9a-fA-F:]+)") + channel_c = re.compile(r"Channel:\s+(?P[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