From fc80ae77245a36ea3e2692c1b49b2f69d7301d6c Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Tue, 5 Mar 2019 14:18:30 +0100 Subject: [PATCH] sys/app_metadata: Add app_metadata module This allows a access to application metadata such as BOARD, CPU, etc. It prints the contents to the stdio in a standard json form --- sys/Makefile.include | 7 +++++ sys/app_metadata/Makefile | 1 + sys/app_metadata/app_metadata.c | 31 +++++++++++++++++++ sys/include/app_metadata.h | 55 +++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 sys/app_metadata/Makefile create mode 100644 sys/app_metadata/app_metadata.c create mode 100644 sys/include/app_metadata.h diff --git a/sys/Makefile.include b/sys/Makefile.include index b87126c538..7c1fab6e97 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -31,6 +31,13 @@ ifneq (,$(filter oneway_malloc,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/oneway-malloc/include endif +ifneq (,$(filter app_metadata,$(USEMODULE))) + # Overwrite the interface version + ifdef APP_SHELL_FMT + CFLAGS += -DAPP_SHELL_FMT=\"$(APP_SHELL_FMT)\" + endif +endif + ifneq (,$(filter vfs,$(USEMODULE))) USEMODULE_INCLUDES += $(RIOTBASE)/sys/posix/include endif diff --git a/sys/app_metadata/Makefile b/sys/app_metadata/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/app_metadata/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/app_metadata/app_metadata.c b/sys/app_metadata/app_metadata.c new file mode 100644 index 0000000000..af3fef960d --- /dev/null +++ b/sys/app_metadata/app_metadata.c @@ -0,0 +1,31 @@ +/** +Copyright (C) 2019, HAW Hamburg. + * + * 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 sys_app_metadata + * @{ + * @file + * @brief Prints application metadata such as BOARD, CPU, OS_VERSION. + * @author Kevin Weiss + * @} + */ + +#include + +void app_metadata_print_json(void) +{ + puts("{\"cmd\": \"app_metadata_print_json()\"}"); + printf("{\"data\": {\"APP_NAME\": \"%s\"}}\n", RIOT_APPLICATION); + printf("{\"data\": {\"BOARD\": \"%s\"}}\n", RIOT_BOARD); + printf("{\"data\": {\"CPU\": \"%s\"}}\n", RIOT_CPU); +#ifdef APP_SHELL_FMT + printf("{\"data\": {\"APP_SHELL_FMT\": \"%s\"}}\n", APP_SHELL_FMT); +#endif + printf("{\"data\": {\"MCU\": \"%s\"}}\n", RIOT_MCU); + printf("{\"data\": {\"OS_VERSION\": \"%s\"}}\n", RIOT_VERSION); + + printf("{\"result\": \"SUCCESS\"}\n"); +} diff --git a/sys/include/app_metadata.h b/sys/include/app_metadata.h new file mode 100644 index 0000000000..fcbd847b84 --- /dev/null +++ b/sys/include/app_metadata.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 HAW Hamburg + * + * 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. + */ + + +/** + * @defgroup sys_app_metadata app_metadata + * @ingroup sys + * @brief Module for the application metadata + * @{ + * + * @author Kevin Weiss + */ + +#ifndef APP_METADATA_H +#define APP_METADATA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef DOXYGEN +/** + * @brief Application Shell Format is an optional application metadata + * parameter intended to help coordinate any specific formats that + * are being used. + * + * @details An example is if the application is following a specific format, + * say semantics defined in a RDM or schema, that could be specified + * by adding APP_SHELL_FMT="RDM001_v1", that would inform anything + * using the shell that the formatting should follow what is dictated. + * This define is only for documentation, to use the APP_SHELL_FMT + * add it to the application makefile with APP_SHELL_FMT= + * or when calling make such as `APP_SHELL_FMT= make flash` + */ +#define APP_SHELL_FMT +#endif + +/** + * @brief Prints the application metadata in json. + * + * @details Examples of application metadata are BOARD, OS_VERSION, APP_NAME... + */ +void app_metadata_print_json(void); + +#ifdef __cplusplus +} +#endif + +#endif /* APP_METADATA_H */ +/** @} */