change to better UI and get information directly from .h file
This commit is contained in:
parent
dd1f875283
commit
5fafa6378c
|
@ -6,6 +6,7 @@ local/
|
||||||
user_config.h
|
user_config.h
|
||||||
server-ca.crt
|
server-ca.crt
|
||||||
luac.cross
|
luac.cross
|
||||||
|
luac.cross.int
|
||||||
uz_unzip
|
uz_unzip
|
||||||
uz_zip
|
uz_zip
|
||||||
tools/toolchains/
|
tools/toolchains/
|
||||||
|
@ -15,4 +16,6 @@ tools/toolchains/
|
||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
#ignore temp file for build infos
|
||||||
buildinfo.h
|
buildinfo.h
|
||||||
|
|
|
@ -120,24 +120,87 @@ static int node_sleep( lua_State* L )
|
||||||
#endif //PMSLEEP_ENABLE
|
#endif //PMSLEEP_ENABLE
|
||||||
static int node_info( lua_State* L )
|
static int node_info( lua_State* L )
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, NODE_VERSION_MAJOR);
|
const char* options[] = {"hw", "sw_version", "build_config", "legacy", NULL};
|
||||||
lua_pushinteger(L, NODE_VERSION_MINOR);
|
int option = luaL_checkoption (L, 1, options[3], options);
|
||||||
lua_pushinteger(L, NODE_VERSION_REVISION);
|
|
||||||
lua_pushinteger(L, system_get_chip_id()); // chip id
|
switch (option) {
|
||||||
lua_pushinteger(L, spi_flash_get_id()); // flash id
|
case 0: { // hw
|
||||||
lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB
|
lua_createtable (L, 0, 5);
|
||||||
lua_pushinteger(L, flash_rom_get_mode());
|
int table_index = lua_gettop(L);
|
||||||
lua_pushinteger(L, flash_rom_get_speed());
|
lua_pushliteral(L, "chip_id");
|
||||||
lua_pushstring(L, BUILDINFO_BRANCH);
|
lua_pushinteger(L, system_get_chip_id()); // chip id
|
||||||
lua_pushstring(L, BUILDINFO_COMMIT_ID);
|
lua_settable(L, table_index);
|
||||||
lua_pushstring(L, BUILDINFO_RELEASE);
|
lua_pushliteral(L, "flash_id");
|
||||||
lua_pushstring(L, BUILDINFO_RELEASE_DTS);
|
lua_pushinteger(L, spi_flash_get_id()); // flash id
|
||||||
lua_pushboolean(L, BUILDINFO_SSL);
|
lua_settable(L, table_index);
|
||||||
lua_pushstring(L, BUILDINFO_LFS);
|
lua_pushliteral(L, "flash_size");
|
||||||
lua_pushstring(L, BUILDINFO_MODULES);
|
lua_pushinteger(L, flash_rom_get_size_byte() / 1024); // flash size in KB
|
||||||
lua_pushstring(L, BUILDINFO_BUILD_TYPE);
|
lua_settable(L, table_index);
|
||||||
|
lua_pushliteral(L, "flash_mode");
|
||||||
return 16;
|
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()
|
// Lua: chipid()
|
||||||
|
|
|
@ -103,7 +103,7 @@ extern void _ResetHandler(void);
|
||||||
* the use of a partition table (PT) to control flash allocation. The NodeMCU uses
|
* 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
|
* 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
|
* 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
|
* 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
|
* as system_get_flash_size_map() which returns the valid flash size (including the
|
||||||
* 8Mb and 16Mb variants).
|
* 8Mb and 16Mb variants).
|
||||||
|
|
|
@ -276,32 +276,50 @@ system heap size left in bytes (number)
|
||||||
|
|
||||||
## node.info()
|
## 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
|
#### Syntax
|
||||||
`node.info()`
|
`node.info([kind])`
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
none
|
`kind` kind of information (optional, if ommited return legacy information). May be one of `"hw"`, `"sw_version"`, `"build_config"`.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
- `majorVer` (number)
|
if a `kind` is given the return value will be a table containing the following elements:
|
||||||
- `minorVer` (number)
|
- for `kind` = `"hw"`
|
||||||
- `devVer` (number)
|
- `chip_id` (number)
|
||||||
- `chipid` (number)
|
- `flash_id` (number)
|
||||||
- `flashid` (number)
|
- `flash_size` (number)
|
||||||
- `flashsize` (number)
|
- `flash_mode` (number) QIO = 0, QOUT = 1, DIO = 2, DOUT = 15.
|
||||||
- `flashmode` (number)
|
- `flash_speed` (number)
|
||||||
- `flashspeed` (number)
|
- for `kind` = `"sw_version"`
|
||||||
- `branch` (string)
|
- `git_branch` (string)
|
||||||
- `git commit_id` (string)
|
- `git_commit_id` (string)
|
||||||
- `release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403"
|
- `git_release` (string) Release name +additional commits e.g. "2.0.0-master_20170202 +403"
|
||||||
- `release_dts` (string) in an ordering format. e.g. "201908111200"
|
- `git_commit_dts` (string) in an ordering format. e.g. "201908111200"
|
||||||
- `ssl` (boolean)
|
- `node_verion_major` (number)
|
||||||
- `lfs info` (string) "disabled" or "Size: {whatever is in user_config.h}"
|
- `node_verion_minor` (number)
|
||||||
- `modules` (string) comma separated list
|
- `node_verion_revision` (number)
|
||||||
- `build_type` (string) `integer` or `float`
|
- 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
|
#### Example
|
||||||
```lua
|
```lua
|
||||||
|
@ -309,6 +327,17 @@ majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed =
|
||||||
print("NodeMCU "..majorVer.."."..minorVer.."."..devVer)
|
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()
|
## node.input()
|
||||||
|
|
||||||
Submits a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation.
|
Submits a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation.
|
||||||
|
|
|
@ -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="$(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)
|
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')
|
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
|
# create temp buildinfo
|
||||||
|
@ -38,6 +16,32 @@ TEMPFILE=/tmp/buildinfo.h
|
||||||
cat > $TEMPFILE << EndOfMessage
|
cat > $TEMPFILE << EndOfMessage
|
||||||
#ifndef __BUILDINFO_H__
|
#ifndef __BUILDINFO_H__
|
||||||
#define __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
|
EndOfMessage
|
||||||
|
|
||||||
echo "#define USER_PROLOG \""$USER_PROLOG"\"" >> $TEMPFILE
|
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_COMMIT_ID \""$COMMIT_ID"\"" >> $TEMPFILE
|
||||||
echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE
|
echo "#define BUILDINFO_RELEASE \""$RELEASE"\"" >> $TEMPFILE
|
||||||
echo "#define BUILDINFO_RELEASE_DTS \""$RELEASE_DTS"\"" >> $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
|
echo "#define BUILDINFO_MODULES \""$MODULES"\"" >> $TEMPFILE
|
||||||
|
|
||||||
cat >> $TEMPFILE << EndOfMessage2
|
cat >> $TEMPFILE << EndOfMessage2
|
||||||
|
@ -60,7 +60,7 @@ cat >> $TEMPFILE << EndOfMessage2
|
||||||
"\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\
|
"\trelease DTS: " BUILDINFO_RELEASE_DTS "\n" \\
|
||||||
"\tSSL: " BUILDINFO_SSL_STR "\n" \\
|
"\tSSL: " BUILDINFO_SSL_STR "\n" \\
|
||||||
"\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\
|
"\tBuild type: " BUILDINFO_BUILD_TYPE "\n" \\
|
||||||
"\tLFS: " BUILDINFO_LFS "\n" \\
|
"\tLFS: " BUILDINFO_TO_STR(BUILDINFO_LFS) "\n" \\
|
||||||
"\tmodules: " BUILDINFO_MODULES "\n"
|
"\tmodules: " BUILDINFO_MODULES "\n"
|
||||||
|
|
||||||
EndOfMessage2
|
EndOfMessage2
|
||||||
|
|
Loading…
Reference in New Issue