From d18cb7a9c308af9e1ae0bd8afe92d94110a2de03 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 7 Jul 2015 18:22:26 +0200 Subject: [PATCH] sys: add netopt to string map function and netopt module --- sys/Makefile | 4 ++ sys/include/net/netopt.h | 11 +++++ sys/net/crosslayer/netopt/Makefile | 1 + sys/net/crosslayer/netopt/netopt.c | 65 ++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 sys/net/crosslayer/netopt/Makefile create mode 100644 sys/net/crosslayer/netopt/netopt.c diff --git a/sys/Makefile b/sys/Makefile index cbc7292c73..c25602c637 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -59,6 +59,10 @@ ifneq (,$(filter udp,$(USEMODULE))) DIRS += net/transport_layer/udp endif +ifneq (,$(filter netopt,$(USEMODULE))) + DIRS += net/crosslayer/netopt +endif + DIRS += $(dir $(wildcard $(addsuffix /Makefile, ${USEMODULE}))) include $(RIOTBASE)/Makefile.base diff --git a/sys/include/net/netopt.h b/sys/include/net/netopt.h index 5a26497c11..5532a0c159 100644 --- a/sys/include/net/netopt.h +++ b/sys/include/net/netopt.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2015 Freie Universität Berlin + * 2015 Kaspar Schleiser * * 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 @@ -18,6 +19,7 @@ * * @author Hauke Petersen * @author Oliver Hahm + * @author Kaspar Schleiser */ #ifndef NETOPT_H_ @@ -177,6 +179,15 @@ typedef enum { /* add other states if needed */ } netopt_state_t; +/** + * @brief Get a string ptr corresponding to opt, for debugging + * + * @param[in] opt The option to get a string representation for + * + * @return ptr to string representation for given option or "unknown" + */ +const char *netopt2str(netopt_t opt); + #ifdef __cplusplus } #endif diff --git a/sys/net/crosslayer/netopt/Makefile b/sys/net/crosslayer/netopt/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/net/crosslayer/netopt/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/net/crosslayer/netopt/netopt.c b/sys/net/crosslayer/netopt/netopt.c new file mode 100644 index 0000000000..6c05246642 --- /dev/null +++ b/sys/net/crosslayer/netopt/netopt.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser + * + * 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 + * directory for more details. + */ + +/** + * @{ + * @ingroup net_netopt + * @file + * @brief This file contains functionality to map netopt option + * numbers to strings + * + * @author Kaspar Schleiser + * @} + */ + +#include "net/netopt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static const char *_netopt_strmap[] = { + [NETOPT_CHANNEL] = "NETOPT_CHANNEL", + [NETOPT_IS_CHANNEL_CLR] = "NETOPT_IS_CHANNEL_CLR", + [NETOPT_ADDRESS] = "NETOPT_ADDRESS", + [NETOPT_ADDRESS_LONG] = "NETOPT_ADDRESS_LONG", + [NETOPT_ADDR_LEN] = "NETOPT_ADDR_LEN", + [NETOPT_SRC_LEN] = "NETOPT_SRC_LEN", + [NETOPT_NID] = "NETOPT_NID", + [NETOPT_IPV6_IID] = "NETOPT_IPV6_IID", + [NETOPT_TX_POWER] = "NETOPT_TX_POWER", + [NETOPT_MAX_PACKET_SIZE] = "NETOPT_MAX_PACKET_SIZE", + [NETOPT_PRELOADING] = "NETOPT_PRELOADING", + [NETOPT_PROMISCUOUSMODE] = "NETOPT_PROMISCUOUSMODE", + [NETOPT_AUTOACK] = "NETOPT_AUTOACK", + [NETOPT_RETRANS] = "NETOPT_RETRANS", + [NETOPT_PROTO] = "NETOPT_PROTO", + [NETOPT_STATE] = "NETOPT_STATE", + [NETOPT_RAWMODE] = "NETOPT_RAWMODE", + [NETOPT_RX_START_IRQ] = "NETOPT_RX_START_IRQ", + [NETOPT_RX_END_IRQ] = "NETOPT_RX_END_IRQ", + [NETOPT_TX_START_IRQ] = "NETOPT_TX_START_IRQ", + [NETOPT_TX_END_IRQ] = "NETOPT_TX_END_IRQ", + [NETOPT_AUTOCCA] = "NETOPT_AUTOCCA", + [NETOPT_NUMOF] = "NETOPT_NUMOF", +}; + +const char *netopt2str(netopt_t opt) +{ + if (opt >= NETOPT_NUMOF) { + return "unknown"; + } + else { + const char *tmp = _netopt_strmap[opt]; + return tmp ? tmp : "unknown"; + } +} + +#ifdef __cplusplus +} +#endif