diff --git a/companion/src/cmake/Macros.cmake b/companion/src/cmake/Macros.cmake index 12bc8d030..9d9cbda90 100644 --- a/companion/src/cmake/Macros.cmake +++ b/companion/src/cmake/Macros.cmake @@ -24,3 +24,15 @@ MACRO (NOW RESULT) ENDIF (WIN32) ENDMACRO (NOW) +MACRO (GIT_ID RESULT) + IF (WIN32) + EXECUTE_PROCESS(COMMAND "cmd" " /C git rev-parse HEAD" OUTPUT_VARIABLE ${RESULT}) + string(REGEX REPLACE "(..):(..).*" "\\1:\\2:00" ${RESULT} ${${RESULT}}) + ELSEIF(UNIX) + EXECUTE_PROCESS(COMMAND "git" "rev-parse" "HEAD" OUTPUT_VARIABLE ${RESULT}) + string(REGEX REPLACE "(.*)\n" "\\1" ${RESULT} ${${RESULT}}) + ELSE (WIN32) + MESSAGE(SEND_ERROR "Git ID implemented") + SET(${RESULT} 0) + ENDIF (WIN32) +ENDMACRO (GIT_ID) diff --git a/companion/src/firmwares/opentx/simulator/CMakeLists.txt b/companion/src/firmwares/opentx/simulator/CMakeLists.txt index cedd22808..5861fea30 100644 --- a/companion/src/firmwares/opentx/simulator/CMakeLists.txt +++ b/companion/src/firmwares/opentx/simulator/CMakeLists.txt @@ -70,6 +70,7 @@ add_custom_target(firmware_translations DEPENDS ${translations_files}) TODAY(DATE) NOW(TIME) +GIT_ID(GIT_STR) configure_file(${RADIO_SRC_DIRECTORY}/stamp.h.in ${RADIO_SRC_DIRECTORY}/stamp.h @ONLY) diff --git a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp index 79243d6b4..a2c9f7742 100644 --- a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp +++ b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp @@ -422,6 +422,7 @@ namespace NAMESPACE { #include "radio/src/thirdparty/Lua/src/ltablib.c" #include "radio/src/thirdparty/Lua/src/lcorolib.c" #include "radio/src/thirdparty/Lua/src/liolib.c" +#include "radio/src/thirdparty/Lua/src/lstrlib.c" #endif int16_t g_anas[NUM_STICKS+NUM_POTS]; diff --git a/radio/src/Makefile b/radio/src/Makefile index fa379deb4..f0212a764 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -404,7 +404,11 @@ else endif TRANSLATE = -$(PYTHON) ../util/translate.py -VERSION = 2.2.0$(OPENTX_VERSION_SUFFIX) +VERSION_MAJOR = 2 +VERSION_MINOR = 2 +VERSION_REVISION = 0 + +VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)$(OPENTX_VERSION_SUFFIX) THIRDPARTY = thirdparty COOSDIR = $(THIRDPARTY)/CoOS @@ -1036,7 +1040,7 @@ ifeq ($(PCB), TARANIS) CPPSRC += lua/interface.cpp lua/api_general.cpp lua/api_lcd.cpp lua/api_model.cpp LUASRC = $(LUADIR)/lapi.c $(LUADIR)/lcode.c $(LUADIR)/lctype.c $(LUADIR)/ldebug.c $(LUADIR)/ldo.c $(LUADIR)/ldump.c $(LUADIR)/lfunc.c $(LUADIR)/lgc.c $(LUADIR)/llex.c $(LUADIR)/lmem.c \ $(LUADIR)/lobject.c $(LUADIR)/lopcodes.c $(LUADIR)/lparser.c $(LUADIR)/lstate.c $(LUADIR)/lstring.c $(LUADIR)/ltable.c $(LUADIR)/lrotable.c $(LUADIR)/ltm.c $(LUADIR)/lundump.c $(LUADIR)/lvm.c $(LUADIR)/lzio.c \ - $(LUADIR)/lbaselib.c $(LUADIR)/linit.c $(LUADIR)/lmathlib.c $(LUADIR)/lbitlib.c $(LUADIR)/loadlib.c $(LUADIR)/lauxlib.c $(LUADIR)/ltablib.c $(LUADIR)/lcorolib.c $(LUADIR)/liolib.c + $(LUADIR)/lbaselib.c $(LUADIR)/linit.c $(LUADIR)/lmathlib.c $(LUADIR)/lbitlib.c $(LUADIR)/loadlib.c $(LUADIR)/lauxlib.c $(LUADIR)/ltablib.c $(LUADIR)/lcorolib.c $(LUADIR)/liolib.c $(LUADIR)/lstrlib.c SRC += $(LUASRC) LUADEP = lua/lua_exports_taranis.inc ifeq ($(USE_BIN_ALLOCATOR), YES) @@ -1785,9 +1789,23 @@ sym: $(TARGET).sym # Build stamp-file stamp.h: + @echo "// Automatically generated file (Makefile) - do not edit" > stamp.h @echo "#define DATE \"`date +%Y-%m-%d | tr -d '\r\n'`\"" > stamp.h @echo "#define TIME \"`date +%H:%M:%S | tr -d '\r\n'`\"" >> stamp.h @echo "#define VERSION \"$(VERSION)\"" >> stamp.h + @echo "" >> stamp.h + @echo "#define VERSION_MAJOR $(VERSION_MAJOR)" >> stamp.h + @echo "#define VERSION_MINOR $(VERSION_MINOR)" >> stamp.h + @echo "#define VERSION_REVISION $(VERSION_REVISION)" >> stamp.h + @echo "#define GIT_STR \"$(shell git rev-parse HEAD)\"" >> stamp.h + +opentx-stamp: + @echo "#define DATE_STR \"`date +%Y-%m-%d`\"" > stamp-opentx.txt + @echo "#define TIME_STR \"`date +%H:%M:%S`\"" >> stamp-opentx.txt + @echo "#define VERS_STR \"$(VERSION)\"" >> stamp-opentx.txt + @echo "#define GIT_STR \"$(shell git rev-parse HEAD)\"" >> stamp-opentx.txt + @cat stamp-opentx.txt + translations/en.h: translations/en.h.txt @echo diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index eafd2f3f3..6bcea27c7 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -81,22 +81,28 @@ Return OpenTX version @retval string OpenTX version (ie "2.1.5") -@retval list (available since 2.1.7) returns two values: - * `string` OpenTX version (ie "2.1.5") - * `string` radio version: `taranisx9e`, `taranisplus` or `taranis`. +@retval multiple (available since 2.1.7) returns 5 values: + * (string) OpenTX version (ie "2.1.5") + * (string) radio version: `taranisx9e`, `taranisplus` or `taranis`. If running in simulator the "-simu" is added + * (number) major version (ie 2 if version 2.1.5) + * (number) minor version (ie 1 if version 2.1.5) + * (number) revison number (ie 5 if version 2.1.5) @status current Introduced in 2.0.0, expanded in 2.1.7 ### Example -This example also runs in OpenTX versions where the radio version was not available: +This example also runs in OpenTX versions where the function returned only one value: ```lua local function run(event) - local ver, radio = getVersion() + local ver, radio, maj, minor, rev = getVersion() print("version: "..ver) if radio then print ("radio: "..radio) end + if maj then print ("maj: "..maj) end + if minor then print ("minor: "..minor) end + if rev then print ("rev: "..rev) end return 1 end @@ -106,14 +112,19 @@ Output of the above script in simulator: ``` version: 2.1.7 radio: taranis-simu -Script finished with status 1 +maj: 2 +minor: 1 +rev: 7 ``` */ static int luaGetVersion(lua_State *L) { lua_pushstring(L, VERSION); lua_pushstring(L, RADIO_VERSION); - return 2; + lua_pushnumber(L, VERSION_MAJOR); + lua_pushnumber(L, VERSION_MINOR); + lua_pushnumber(L, VERSION_REVISION); + return 5; } /*luadoc @@ -168,20 +179,15 @@ static int luaGetDateTime(lua_State *L) static void luaPushLatLon(TelemetrySensor & telemetrySensor, TelemetryItem & telemetryItem) /* result is lua table containing members ["lat"] and ["lon"] as lua_Number (doubles) in decimal degrees */ { - lua_Number lat = 0.0; - lua_Number lon = 0.0; uint32_t gpsLat = 0; uint32_t gpsLon = 0; - telemetryItem.gps.extractLatitudeLongitude(&gpsLat, &gpsLon); /* close, but not the format we want */ - lat = gpsLat / 1000000.0; - if (telemetryItem.gps.latitudeNS == 'S') lat = -lat; - lon = gpsLon / 1000000.0; - if (telemetryItem.gps.longitudeEW == 'W') lon = -lon; - lua_createtable(L, 0, 2); - lua_pushtablenumber(L, "lat", lat); - lua_pushtablenumber(L, "lon", lon); + lua_createtable(L, 0, 4); + lua_pushtablenumber(L, "lat", gpsLat / ((telemetryItem.gps.latitudeNS == 'S') ? -1000000.0 : 1000000.0)); + lua_pushtablenumber(L, "pilot-lat", telemetryItem.pilotLatitude / ((telemetryItem.gps.latitudeNS == 'S') ? -1000000.0 : 1000000.0)); + lua_pushtablenumber(L, "lon", gpsLon / ((telemetryItem.gps.longitudeEW == 'W') ? -1000000.0 : 1000000.0)); + lua_pushtablenumber(L, "pilot-lon", telemetryItem.pilotLongitude / ((telemetryItem.gps.longitudeEW == 'W') ? -1000000.0 : 1000000.0)); } static void luaPushTelemetryDateTime(TelemetrySensor & telemetrySensor, TelemetryItem & telemetryItem) @@ -379,6 +385,8 @@ or a name (string) of the source. @retval table GPS position is returned in a table: * `lat` (number) latitude, positive is North * `lon` (number) longitude, positive is East + * `pilot-lat` (number) pilot latitude, positive is North + * `pilot-lon` (number) pilot longitude, positive is East @retval table GPS date/time, see getDateTime() diff --git a/radio/src/stamp.h.in b/radio/src/stamp.h.in index b843d18a7..f360b3a90 100644 --- a/radio/src/stamp.h.in +++ b/radio/src/stamp.h.in @@ -1,3 +1,8 @@ #define DATE "@DATE@" #define TIME "@TIME@" #define VERSION "@VERSION@" + +#define VERSION_MAJOR @VERSION_MAJOR@ +#define VERSION_MINOR @VERSION_MINOR@ +#define VERSION_REVISION @VERSION_REVISION@ +#define GIT_STR "@GIT_STR@" diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index bae81ce8e..11229541a 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -845,7 +845,7 @@ FRESULT f_open (FIL * fil, const TCHAR *name, BYTE flag) fil->fs = (FATFS*)fopen(realPath, (flag & FA_WRITE) ? ((flag & FA_CREATE_ALWAYS) ? "wb+" : "ab+") : "rb+"); fil->fptr = 0; if (fil->fs) { - TRACE("f_open(%s, %x) = %p", path, flag, (FILE*)fil->fs); + TRACE("f_open(%s, %x) = %p (FIL %p)", path, flag, fil->fs, fil); return FR_OK; } TRACE("f_open(%s) = error %d (%s)", path, errno, strerror(errno)); @@ -894,8 +894,9 @@ UINT f_size(FIL* fil) FRESULT f_close (FIL * fil) { - if (fil && fil->fs) { - TRACE("f_close(%p)", (FILE*)fil->fs); + assert(fil); + TRACE("f_close(%p) (FIL:%p)", fil->fs, fil); + if (fil->fs) { fclose((FILE*)fil->fs); fil->fs = NULL; } diff --git a/radio/src/thirdparty/Lua/src/lauxlib.h b/radio/src/thirdparty/Lua/src/lauxlib.h index 9699cb697..aab96bd1c 100644 --- a/radio/src/thirdparty/Lua/src/lauxlib.h +++ b/radio/src/thirdparty/Lua/src/lauxlib.h @@ -28,6 +28,7 @@ extern const luaL_Reg baselib[]; extern const luaL_Reg mathlib[]; extern const luaL_Reg bitlib[]; extern const luaL_Reg iolib[]; +extern const luaL_Reg strlib[]; extern const luaL_Reg opentxLib[]; extern const luaL_Reg lcdLib[]; diff --git a/radio/src/thirdparty/Lua/src/linit.c b/radio/src/thirdparty/Lua/src/linit.c index 6e9113a6e..a39b84bc1 100644 --- a/radio/src/thirdparty/Lua/src/linit.c +++ b/radio/src/thirdparty/Lua/src/linit.c @@ -46,6 +46,7 @@ const luaR_table lua_rotable[] = {LUA_MATHLIBNAME, mathlib, mathlib_vals}, {LUA_BITLIBNAME, bitlib, NULL}, {LUA_IOLIBNAME, iolib, NULL}, + {LUA_STRLIBNAME, strlib, NULL}, {"lcd", lcdLib, NULL}, {"model", modelLib, NULL}, {"__baselib", baselib, NULL}, diff --git a/radio/src/thirdparty/Lua/src/liolib.c b/radio/src/thirdparty/Lua/src/liolib.c index d5476d298..2bdb89ebf 100644 --- a/radio/src/thirdparty/Lua/src/liolib.c +++ b/radio/src/thirdparty/Lua/src/liolib.c @@ -203,16 +203,17 @@ static int io_close (lua_State *L) { #endif } -#if !defined(USE_FATFS) static int f_gc (lua_State *L) { #if !defined(USE_FATFS) LStream *p = tolstream(L); if (!isclosed(p) && p->f != NULL) aux_close(L); /* ignore closed and incompletely open files */ #endif + f_close(tofile(L)); // no need to check if file was already closed (fatfs will not close it if p->f->fs is 0) return 0; } +#if !defined(USE_FATFS) /* ** function to close regular files */ @@ -659,31 +660,27 @@ const luaL_Reg iolib[] = { {NULL, NULL} }; -#if !defined(USE_FATFS) - /* ** methods for file handles */ static const luaL_Reg flib[] = { - {"close", io_close}, - {"flush", f_flush}, - {"lines", f_lines}, - {"read", io_read}, - {"seek", f_seek}, - {"setvbuf", f_setvbuf}, - {"write", f_write}, - {"__gc", f_gc}, - {"__tostring", f_tostring}, + // {"close", io_close}, + // {"flush", f_flush}, + // {"lines", f_lines}, + // {"read", io_read}, + // {"seek", f_seek}, + // {"setvbuf", f_setvbuf}, + // {"write", f_write}, + {"__gc", f_gc}, // we define only garbage collector to close any leftover open files + // {"__tostring", f_tostring}, {NULL, NULL} }; -#endif - static void createmeta (lua_State *L) { luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ lua_pushvalue(L, -1); /* push metatable */ - // lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ - // luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */ lua_pop(L, 1); /* pop new metatable */ } diff --git a/radio/src/thirdparty/Lua/src/lstrlib.c b/radio/src/thirdparty/Lua/src/lstrlib.c index e60d2ba29..d6c70fb45 100644 --- a/radio/src/thirdparty/Lua/src/lstrlib.c +++ b/radio/src/thirdparty/Lua/src/lstrlib.c @@ -9,6 +9,7 @@ #include #include #include +#include #define lstrlib_c @@ -975,7 +976,7 @@ static int str_format (lua_State *L) { /* }====================================================== */ -static const luaL_Reg strlib[] = { +const luaL_Reg strlib[] = { {"byte", str_byte}, {"char", str_char}, {"dump", str_dump}, @@ -993,7 +994,7 @@ static const luaL_Reg strlib[] = { {NULL, NULL} }; - +#if 0 static void createmetatable (lua_State *L) { lua_createtable(L, 0, 1); /* table to be metatable for strings */ lua_pushliteral(L, ""); /* dummy string */ @@ -1014,4 +1015,4 @@ LUAMOD_API int luaopen_string (lua_State *L) { createmetatable(L); return 1; } - +#endif