1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00

[X10 Express] Spectrum analyser, first version

This commit is contained in:
Bertrand Songis 2019-08-19 16:21:44 +02:00
parent 01c88fbba8
commit ffb731dc30
No known key found for this signature in database
GPG key ID: F189F79290FEC50F
11 changed files with 281 additions and 140 deletions

View file

@ -22,6 +22,7 @@
#include <ctype.h>
#include <stdio.h>
#include <algorithm>
#include "opentx.h"
#include "bin_allocator.h"
#include "lua_api.h"
@ -1073,7 +1074,6 @@ uint32_t luaGetMemUsed(lua_State * L)
return L ? (lua_gc(L, LUA_GCCOUNT, 0) << 10) + lua_gc(L, LUA_GCCOUNTB, 0) : 0;
}
void luaInit()
{
TRACE("luaInit");
@ -1116,3 +1116,46 @@ void luaInit()
}
}
}
bool readToolName(char * toolName, const char * filename)
{
FIL file;
char buffer[1024];
UINT count;
if (f_open(&file, filename, FA_READ) != FR_OK) {
return "Error opening file";
}
if (f_read(&file, &buffer, sizeof(buffer), &count) != FR_OK) {
f_close(&file);
return false;
}
const char * tns = "TNS|";
auto * start = std::search(buffer, buffer + sizeof(buffer), tns, tns + 4);
if (start >= buffer + sizeof(buffer))
return false;
start += 4;
const char * tne = "|TNE";
auto * end = std::search(buffer, buffer + sizeof(buffer), tne, tne + 4);
if (end >= buffer + sizeof(buffer) || end <= start)
return false;
uint8_t len = end - start;
if (len > TOOL_NAME_MAXLEN)
return false;
strncpy(toolName, start, len);
memclear(toolName + len, TOOL_NAME_MAXLEN + 1 - len);
return true;
}
bool isRadioScriptTool(const char * filename)
{
const char * ext = getFileExtension(filename);
return ext && !strcasecmp(ext, SCRIPT_EXT);
}

View file

@ -171,6 +171,10 @@ void registerBitmapClass(lua_State * L);
void luaSetInstructionsLimit(lua_State* L, int count);
int luaLoadScriptFileToState(lua_State * L, const char * filename, const char * mode);
#define TOOL_NAME_MAXLEN 16
bool readToolName(char * toolName, const char * filename);
bool isRadioScriptTool(const char * filename);
struct LuaMemTracer {
const char * script;
int lineno;