From a84ea29739f71f5dbd694d1cb1334b273184cb71 Mon Sep 17 00:00:00 2001 From: Augusto Fraga Giachero Date: Fri, 10 Jan 2020 10:52:57 -0300 Subject: [PATCH] Show git revisions for nuttx/, apps/ and the main repo Adds an SCPI (GET:VERsion?) and an CLI (rffe get version) command to check what firmware version is running. --- make.sh | 15 ++++++++++++++- rffe-app/.gitignore | 1 + rffe-app/rffe_console_cfg.c | 10 ++++++++++ rffe-app/rffe_console_cfg.h | 1 + rffe-app/rffe_main.c | 5 +++++ rffe-app/scpi-def.h | 7 ++++--- rffe-app/scpi_rffe_cmd.c | 10 ++++++++++ rffe-app/scpi_rffe_cmd.h | 1 + rffe-app/scpi_tables.c | 1 + 9 files changed, 47 insertions(+), 4 deletions(-) diff --git a/make.sh b/make.sh index fb76798..01ebc78 100755 --- a/make.sh +++ b/make.sh @@ -2,11 +2,23 @@ cmd="$1" +git_hash_tag() { + cd apps/ + APPS_GIT_HASH=$(git describe --no-match --always --dirty --abbrev=40) + cd ../nuttx + NUTTX_GIT_HASH=$(git describe --no-match --always --dirty --abbrev=40) + cd .. + RFFE_GIT_HASH=$(git describe --no-match --always --dirty --abbrev=40) + RFFE_GIT_TAG=$(git describe --exact-match --tags) + echo -e "/* Auto-generated file */\n\n#define APPS_GIT_HASH \"${APPS_GIT_HASH}\"\n#define NUTTX_GIT_HASH \"${NUTTX_GIT_HASH}\"\n#define RFFE_GIT_HASH \"${RFFE_GIT_HASH}\"\n#define RFFE_GIT_TAG \"${RFFE_GIT_TAG}\"\n" > rffe-app/git_version.h +} + if [ -z "$JOBS" ]; then JOBS=1 fi if test "$cmd" = "configure"; then + git_hash_tag cd apps/ rm -f external ln -s ../rffe-app external @@ -15,6 +27,7 @@ if test "$cmd" = "configure"; then ./tools/configure.sh ../rffe-board/rffe cd .. elif test "$cmd" = "build"; then + git_hash_tag cd nuttx/ if [ ! -e .config ]; then echo "Error: Build not configured yet." @@ -27,7 +40,7 @@ elif test "$cmd" = "clean"; then cd nuttx/ make distclean cd .. - rm apps/external + rm -f apps/external rffe-app/git_version.h elif test "$cmd" = "flash"; then openocd -f scripts/openocd/lpc17-cmsis.cfg -c "program nuttx/nuttx.bin 0x10000; reset; shutdown" fi diff --git a/rffe-app/.gitignore b/rffe-app/.gitignore index caa9bde..4b91d66 100644 --- a/rffe-app/.gitignore +++ b/rffe-app/.gitignore @@ -10,3 +10,4 @@ /*.adb /*.lib /*.src +git_version.h diff --git a/rffe-app/rffe_console_cfg.c b/rffe-app/rffe_console_cfg.c index 61e2a82..58e4fdb 100644 --- a/rffe-app/rffe_console_cfg.c +++ b/rffe-app/rffe_console_cfg.c @@ -37,9 +37,15 @@ #include "netconfig.h" #include "config_file.h" +#include "git_version.h" static char* cfg_file = "/dev/feram0"; +void rffe_console_print_version(void) +{ + printf("---Version---\nrelease: %s\nrffe: %s\napps: %s\nnuttx: %s\n", RFFE_GIT_TAG, RFFE_GIT_HASH, APPS_GIT_HASH, NUTTX_GIT_HASH); +} + int rffe_console_cfg(int argc, char *argv[]) { struct netifconfig conf; @@ -127,6 +133,10 @@ int rffe_console_cfg(int argc, char *argv[]) config_get_attenuation("/dev/feram0", &att); printf("%f dB\n", b16tof(att)); } + else if (strcmp(argv[2], "version") == 0) + { + rffe_console_print_version(); + } } else if (strcmp(argv[1], "set") == 0) diff --git a/rffe-app/rffe_console_cfg.h b/rffe-app/rffe_console_cfg.h index c98c17c..ec66645 100644 --- a/rffe-app/rffe_console_cfg.h +++ b/rffe-app/rffe_console_cfg.h @@ -25,5 +25,6 @@ #define RFFE_CONSOLE_CFG_H_ int rffe_console_cfg(int argc, char *argv[]); +void rffe_console_print_version(void); #endif diff --git a/rffe-app/rffe_main.c b/rffe-app/rffe_main.c index fb09cad..bf4d7b3 100644 --- a/rffe-app/rffe_main.c +++ b/rffe-app/rffe_main.c @@ -112,6 +112,11 @@ int rffe_main(int argc, char *argv[]) return rffe_console_cfg(argc, argv); } + /* + * Print git hashs for apps/ nuttx/ and the main repo + */ + rffe_console_print_version(); + /* * Restore previous RF attenuation level */ diff --git a/rffe-app/scpi-def.h b/rffe-app/scpi-def.h index 00ca9c0..19394c7 100644 --- a/rffe-app/scpi-def.h +++ b/rffe-app/scpi-def.h @@ -30,13 +30,14 @@ #define __SCPI_DEF_H_ #include "scpi/scpi.h" +#include "git_version.h" #define SCPI_INPUT_BUFFER_LENGTH 64 #define SCPI_ERROR_QUEUE_SIZE 8 -#define SCPI_IDN1 "LNLS" -#define SCPI_IDN2 "RFFEV4" +#define SCPI_IDN1 "CNPEM LNLS" +#define SCPI_IDN2 "RFFE" #define SCPI_IDN3 NULL -#define SCPI_IDN4 "01-02" +#define SCPI_IDN4 RFFE_GIT_TAG size_t SCPI_Write(scpi_t * context, const char * data, size_t len); int SCPI_Error(scpi_t * context, int_fast16_t err); diff --git a/rffe-app/scpi_rffe_cmd.c b/rffe-app/scpi_rffe_cmd.c index 52ed9ac..ee1b895 100644 --- a/rffe-app/scpi_rffe_cmd.c +++ b/rffe-app/scpi_rffe_cmd.c @@ -36,6 +36,7 @@ #include "scpi_rffe_cmd.h" #include "scpi_interface.h" #include "config_file.h" +#include "git_version.h" static const char* cfg_file = "/dev/feram0"; static const char* dac_file = "/dev/dac0"; @@ -656,6 +657,15 @@ scpi_result_t rffe_get_dhcp_mode(scpi_t* context) return SCPI_RES_OK; } +scpi_result_t rffe_get_version(scpi_t* context) +{ + SCPI_ResultCharacters(context, APPS_GIT_HASH, strlen(APPS_GIT_HASH)); + SCPI_ResultCharacters(context, NUTTX_GIT_HASH, strlen(NUTTX_GIT_HASH)); + SCPI_ResultCharacters(context, RFFE_GIT_HASH, strlen(RFFE_GIT_HASH)); + SCPI_ResultCharacters(context, RFFE_GIT_TAG, strlen(RFFE_GIT_TAG)); + return SCPI_RES_OK; +} + scpi_result_t rffe_reset(scpi_t* context) { boardctl(BOARDIOC_RESET, 0); diff --git a/rffe-app/scpi_rffe_cmd.h b/rffe-app/scpi_rffe_cmd.h index b81c390..dfeaaee 100644 --- a/rffe-app/scpi_rffe_cmd.h +++ b/rffe-app/scpi_rffe_cmd.h @@ -62,5 +62,6 @@ scpi_result_t rffe_set_netmask(scpi_t* context); scpi_result_t rffe_get_netmask(scpi_t* context); scpi_result_t rffe_set_dhcp_mode(scpi_t* context); scpi_result_t rffe_get_dhcp_mode(scpi_t* context); +scpi_result_t rffe_get_version(scpi_t* context); scpi_result_t rffe_reset(scpi_t* context); #endif diff --git a/rffe-app/scpi_tables.c b/rffe-app/scpi_tables.c index a750edf..9641479 100644 --- a/rffe-app/scpi_tables.c +++ b/rffe-app/scpi_tables.c @@ -88,6 +88,7 @@ const scpi_command_t scpi_commands[] = {.pattern = "GET:NETMask?", .callback = rffe_get_netmask,}, {.pattern = "SET:DHCPMode", .callback = rffe_set_dhcp_mode,}, {.pattern = "GET:DHCPMode?", .callback = rffe_get_dhcp_mode,}, + {.pattern = "GET:VERsion?", .callback = rffe_get_version,}, {.pattern = "SYSTem:RESet", .callback = rffe_reset,}, SCPI_CMD_LIST_END