From 9204feb07b3f7f3c0c5a58d268a952c737ea26bc Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 19 Jun 2018 10:02:17 +0200 Subject: [PATCH 1/3] sniffer: use fmt instead of printf I was able to reduce stack usage by 2/3 on `samr21-xpro`. Additionally, I removed the leading `0x` for the hexadecimal numbers. The parsing script knows which numbers are hex (all of them) and they just waste time both on the node and in the parsing script --- sniffer/Makefile | 1 + sniffer/main.c | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sniffer/Makefile b/sniffer/Makefile index 88c1a5c220f7..01e46cb67bcc 100644 --- a/sniffer/Makefile +++ b/sniffer/Makefile @@ -8,6 +8,7 @@ BOARD ?= native RIOTBASE ?= $(CURDIR)/../../RIOT # Define modules that are used +USEMODULE += fmt USEMODULE += gnrc USEMODULE += gnrc_netdev_default USEMODULE += auto_init_gnrc_netif diff --git a/sniffer/main.c b/sniffer/main.c index 8dd481fdbd76..998a55b4aaef 100644 --- a/sniffer/main.c +++ b/sniffer/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Freie Universität Berlin + * Copyright (C) 2015-18 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -15,12 +15,14 @@ * @brief Sniffer application for RIOT * * @author Hauke Petersen + * @author Martine Lenders * * @} */ #include +#include "fmt.h" #include "thread.h" #include "xtimer.h" #include "shell.h" @@ -59,16 +61,21 @@ void dump_pkt(gnrc_pktsnip_t *pkt) pkt = gnrc_pktbuf_remove_snip(pkt, pkt->next); uint64_t now_us = xtimer_usec_from_ticks64(xtimer_now64()); - printf("rftest-rx --- len 0x%02x lqi 0x%02x rx_time 0x%08" PRIx32 "%08" PRIx32 "\n\n", - gnrc_pkt_len(pkt), lqi, (uint32_t)(now_us >> 32), (uint32_t)(now_us & 0xffffffff)); - + print_str("rftest-rx --- len "); + print_u32_hex((uint32_t)gnrc_pkt_len(pkt)); + print_str(" lqi "); + print_byte_hex(lqi); + print_str(" rx_time "); + print_u64_hex(now_us); + print_str("\n"); while (snip) { for (size_t i = 0; i < snip->size; i++) { - printf("0x%02x ", ((uint8_t *)(snip->data))[i]); + print_byte_hex(((uint8_t *)(snip->data))[i]); + print_str(" "); } snip = snip->next; } - puts("\n"); + print_str("\n\n"); gnrc_pktbuf_release(pkt); } From 3ef810ffd13790661f5d4f3657c57a6fdf1ace9b Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Tue, 19 Jun 2018 10:04:02 +0200 Subject: [PATCH 2/3] sniffer: adapt parsing script --- sniffer/tools/sniffer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sniffer/tools/sniffer.py b/sniffer/tools/sniffer.py index 7d09d217bd85..470520e81033 100755 --- a/sniffer/tools/sniffer.py +++ b/sniffer/tools/sniffer.py @@ -85,7 +85,7 @@ def generate_pcap(port, out): while True: line = port.readline().rstrip() - pkt_header = re.match(r">? *rftest-rx --- len 0x(\w\w).*", + pkt_header = re.match(r">? *rftest-rx --- len (\w+).*", line.decode(errors="ignore")) if pkt_header: now = time() @@ -98,10 +98,10 @@ def generate_pcap(port, out): sys.stderr.write("RX: %i\r" % count) continue - pkt_data = re.match(r"(0x\w\w )+", line.decode(errors="ignore")) + pkt_data = re.match(r"(\w\w )+", line.decode(errors="ignore")) if pkt_data: for part in line.decode(errors="ignore").split(' '): - byte = re.match(r"0x(\w\w)", part) + byte = re.match(r"(\w\w)", part) if byte: out.write(pack(' Date: Tue, 19 Jun 2018 10:55:19 +0200 Subject: [PATCH 3/3] sniffer: reduce rawdump thread stack size --- sniffer/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sniffer/main.c b/sniffer/main.c index 998a55b4aaef..3f78e7142293 100644 --- a/sniffer/main.c +++ b/sniffer/main.c @@ -47,7 +47,7 @@ /** * @brief Stack for the raw dump thread */ -static char rawdmp_stack[THREAD_STACKSIZE_MAIN]; +static char rawdmp_stack[THREAD_STACKSIZE_SMALL]; /** * @brief Make a raw dump of the given packet contents