From 5fafa6378c251cd8f03e05bfd7a20bdc67a27bfc Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 19 Jul 2019 21:24:22 +0200 Subject: [PATCH] change to better UI and get information directly from .h file --- .gitignore | 3 ++ app/modules/node.c | 99 ++++++++++++++++++++++++++++++++------- app/user/user_main.c | 2 +- docs/modules/node.md | 67 ++++++++++++++++++-------- tools/update_buildinfo.sh | 54 ++++++++++----------- 5 files changed, 160 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 83360907..736ae691 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ local/ user_config.h server-ca.crt luac.cross +luac.cross.int uz_unzip uz_zip tools/toolchains/ @@ -15,4 +16,6 @@ tools/toolchains/ .project .settings/ .vscode + +#ignore temp file for build infos buildinfo.h diff --git a/app/modules/node.c b/app/modules/node.c index af39f2c6..962e6073 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -120,24 +120,87 @@ static int node_sleep( lua_State* L ) #endif //PMSLEEP_ENABLE static int node_info( lua_State* L ) { - lua_pushinteger(L, NODE_VERSION_MAJOR); - lua_pushinteger(L, NODE_VERSION_MINOR); - lua_pushinteger(L, NODE_VERSION_REVISION); - lua_pushinteger(L, system_get_chip_id()); // chip id - lua_pushinteger(L, spi_flash_get_id()); // flash id - lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB - lua_pushinteger(L, flash_rom_get_mode()); - lua_pushinteger(L, flash_rom_get_speed()); - lua_pushstring(L, BUILDINFO_BRANCH); - lua_pushstring(L, BUILDINFO_COMMIT_ID); - lua_pushstring(L, BUILDINFO_RELEASE); - lua_pushstring(L, BUILDINFO_RELEASE_DTS); - lua_pushboolean(L, BUILDINFO_SSL); - lua_pushstring(L, BUILDINFO_LFS); - lua_pushstring(L, BUILDINFO_MODULES); - lua_pushstring(L, BUILDINFO_BUILD_TYPE); - - return 16; + const char* options[] = {"hw", "sw_version", "build_config", "legacy", NULL}; + int option = luaL_checkoption (L, 1, options[3], options); + + switch (option) { + case 0: { // hw + lua_createtable (L, 0, 5); + int table_index = lua_gettop(L); + lua_pushliteral(L, "chip_id"); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_settable(L, table_index); + lua_pushliteral(L, "flash_id"); + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_settable(L, table_index); + lua_pushliteral(L, "flash_size"); + lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB + lua_settable(L, table_index); + lua_pushliteral(L, "flash_mode"); + lua_pushinteger(L, flash_rom_get_mode()); + lua_settable(L, table_index); + lua_pushliteral(L, "flash_speed"); + lua_pushinteger(L, flash_rom_get_speed()); + lua_settable(L, table_index); + return 1; + } + case 1: { // sw_version + lua_createtable (L, 0, 7); + int table_index = lua_gettop(L); + lua_pushliteral(L, "node_version_major"); + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_settable(L, table_index); + lua_pushliteral(L, "node_version_minor"); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_settable(L, table_index); + lua_pushliteral(L, "node_version_revision"); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_settable(L, table_index); + lua_pushliteral(L, "git_branch"); + lua_pushstring(L, BUILDINFO_BRANCH); + lua_settable(L, table_index); + lua_pushliteral(L, "git_commit_id"); + lua_pushstring(L, BUILDINFO_COMMIT_ID); + lua_settable(L, table_index); + lua_pushliteral(L, "git_release"); + lua_pushstring(L, BUILDINFO_RELEASE); + lua_settable(L, table_index); + lua_pushliteral(L, "git_commit_dts"); + lua_pushstring(L, BUILDINFO_RELEASE_DTS); + lua_settable(L, table_index); + return 1; + } + case 2: { // build_config + lua_createtable (L, 0, 4); + int table_index = lua_gettop(L); + lua_pushliteral(L, "ssl"); + lua_pushboolean(L, BUILDINFO_SSL); + lua_settable(L, table_index); + lua_pushliteral(L, "lfs_size"); + lua_pushnumber(L, BUILDINFO_LFS); + lua_settable(L, table_index); + lua_pushliteral(L, "modules"); + lua_pushstring(L, BUILDINFO_MODULES); + lua_settable(L, table_index); + lua_pushliteral(L, "number_type"); + lua_pushstring(L, BUILDINFO_BUILD_TYPE); + lua_settable(L, table_index); + return 1; + } + default: + { + platform_print_deprecation_note("node.info() without parameter", "in the next version"); + lua_pushinteger(L, NODE_VERSION_MAJOR); + lua_pushinteger(L, NODE_VERSION_MINOR); + lua_pushinteger(L, NODE_VERSION_REVISION); + lua_pushinteger(L, system_get_chip_id()); // chip id + lua_pushinteger(L, spi_flash_get_id()); // flash id + lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB + lua_pushinteger(L, flash_rom_get_mode()); + lua_pushinteger(L, flash_rom_get_speed()); + return 8; + } + } } // Lua: chipid() diff --git a/app/user/user_main.c b/app/user/user_main.c index 9afb1fb8..2b9e97b1 100644 --- a/app/user/user_main.c +++ b/app/user/user_main.c @@ -103,7 +103,7 @@ extern void _ResetHandler(void); * the use of a partition table (PT) to control flash allocation. The NodeMCU uses * this PT for overall allocation of its flash resources. The non_OS SDK calls the * user_pre_init() entry to do all of this startup configuration. Note that this - * runs with Icache enabled -- that is the IROM0 partition is already mapped the + * runs with Icache enabled -- that is the IROM0 partition is already mapped to the * address space at 0x40210000 and so that most SDK services are available, such * as system_get_flash_size_map() which returns the valid flash size (including the * 8Mb and 16Mb variants). diff --git a/docs/modules/node.md b/docs/modules/node.md index ee04db21..2a16f751 100644 --- a/docs/modules/node.md +++ b/docs/modules/node.md @@ -276,32 +276,50 @@ system heap size left in bytes (number) ## node.info() -Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed, branch, git commit_id, release, release_dts, ssl, lfs info, modules and the build_type. +Returns information about hardware, software version and build configuration. + #### Syntax -`node.info()` +`node.info([kind])` #### Parameters -none +`kind` kind of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`. #### Returns - - `majorVer` (number) - - `minorVer` (number) - - `devVer` (number) - - `chipid` (number) - - `flashid` (number) - - `flashsize` (number) - - `flashmode` (number) - - `flashspeed` (number) - - `branch` (string) - - `git commit_id` (string) - - `release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" - - `release_dts` (string) in an ordering format. e.g. "201908111200" - - `ssl` (boolean) - - `lfs info` (string) "disabled" or "Size: {whatever is in user_config.h}" - - `modules` (string) comma separated list - - `build_type` (string) `integer` or `float` + if a `kind` is given the return value will be a table containing the following elements: + - for `kind` = `"hw"` + - `chip_id` (number) + - `flash_id` (number) + - `flash_size` (number) + - `flash_mode` (number) QIO = 0, QOUT = 1, DIO = 2, DOUT = 15. + - `flash_speed` (number) + - for `kind` = `"sw_version"` + - `git_branch` (string) + - `git_commit_id` (string) + - `git_release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403" + - `git_commit_dts` (string) in an ordering format. e.g. "201908111200" + - `node_verion_major` (number) + - `node_verion_minor` (number) + - `node_verion_revision` (number) + - for `kind` = `"build_config"` + - `ssl` (boolean) + - `lfs_size` (number) as defined at build time + - `modules` (string) comma separated list + - `number_type` (string) `integer` or `float` +!!! attention + +This interface is deprecated and will be removed in one of the next releases. Use the above calls instead. + + - for no `kind` given: --deprecated + - `majorVer` (number) + - `minorVer` (number) + - `devVer` (number) + - `chipid` (number) + - `flashid` (number) + - `flashsize` (number) + - `flashmode` (number) + - `flashspeed` (number) #### Example ```lua @@ -309,6 +327,17 @@ majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = print("NodeMCU "..majorVer.."."..minorVer.."."..devVer) ``` +```lua +for k,v in pairs(node.info("build_config")) do +print (k,v) +end +``` + +```lua +print(node.info("sw_version").git_release) +``` + + ## node.input() Submits a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation. diff --git a/tools/update_buildinfo.sh b/tools/update_buildinfo.sh index d07c51dd..19aed018 100755 --- a/tools/update_buildinfo.sh +++ b/tools/update_buildinfo.sh @@ -9,28 +9,6 @@ BRANCH="$(git rev-parse --abbrev-ref HEAD | sed -r 's/[\/\\]+/_/g')" RELEASE="$(git describe --tags --long | sed -r 's/(.*)-(.*)-.*/\1 +\2/g' | sed 's/ +0$//')" RELEASE_DTS=$(git show -s --format=%cd --date=format:"%Y%m%d%H%M" HEAD) -# figure out whether SSL is enabled in user_config.h -if grep -Eq "^#define CLIENT_SSL_ENABLE" $USER_CONFIG_H; then - SSL="true" -else - SSL="false" -fi - -# figure out whether LFS configuration in user_config.h -LFS=$(grep "^#define LUA_FLASH_STORE" $USER_CONFIG_H | tr -d '\r' | cut -d ' ' -f 3-) -if [ -z "$LFS" ]; then - LFS="disabled" -else - LFS="Size: ${LFS}" -fi - -# figure out whether Int build is enabled in user_config.h -if grep -Eq "^#define LUA_NUMBER_INTEGRAL" $USER_CONFIG_H; then - BUILD_TYPE=integer -else - BUILD_TYPE=float -fi - MODULES=$(awk '/^[ \t]*#define LUA_USE_MODULES/{modules=modules sep tolower(substr($2,17));sep=","}END{if(length(modules)==0)modules="-";print modules}' $USER_MODULES_H | tr -d '\r') # create temp buildinfo @@ -38,6 +16,32 @@ TEMPFILE=/tmp/buildinfo.h cat > $TEMPFILE << EndOfMessage #ifndef __BUILDINFO_H__ #define __BUILDINFO_H__ + +#include "user_config.h" + +#define BUILDINFO_STR_HELPER(x) #x +#define BUILDINFO_TO_STR(x) BUILDINFO_STR_HELPER(x) + +#ifdef LUA_FLASH_STORE +#define BUILDINFO_LFS LUA_FLASH_STORE +#else +#define BUILDINFO_LFS 0 +#endif + +#ifdef CLIENT_SSL_ENABLE +#define BUILDINFO_SSL true +#define BUILDINFO_SSL_STR "true" +#else +#define BUILDINFO_SSL false +#define BUILDINFO_SSL_STR "false" +#endif + +#ifdef LUA_NUMBER_INTEGRAL +#define BUILDINFO_BUILD_TYPE "integer" +#else +#define BUILDINFO_BUILD_TYPE "float" +#endif + EndOfMessage echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE @@ -45,10 +49,6 @@ echo "#define BUILDINFO_BRANCH \""$BRANCH"\"" >> $TEMPFILE echo "#define BUILDINFO_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE echo "#define BUILDINFO_RELEASE_DTS \""$RELEASE_DTS"\"" >> $TEMPFILE -echo "#define BUILDINFO_SSL "$SSL >> $TEMPFILE -echo "#define BUILDINFO_SSL_STR \""$SSL"\"" >> $TEMPFILE -echo "#define BUILDINFO_BUILD_TYPE \""$BUILD_TYPE"\"" >> $TEMPFILE -echo "#define BUILDINFO_LFS \""$LFS"\"" >> $TEMPFILE echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE cat >> $TEMPFILE << EndOfMessage2 @@ -60,7 +60,7 @@ cat >> $TEMPFILE << EndOfMessage2 "\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\ "\tSSL: " BUILDINFO_SSL_STR "\n" \\ "\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\ - "\tLFS: " BUILDINFO_LFS "\n" \\ + "\tLFS: " BUILDINFO_TO_STR(BUILDINFO_LFS) "\n" \\ "\tmodules: " BUILDINFO_MODULES "\n" EndOfMessage2