Loading from wasm file
This commit is contained in:
parent
a84e242a37
commit
63acddf1a5
@ -82,6 +82,7 @@ bool writeObjectToFileUsingId(const char* file, uint16_t id, JsonDocument* conte
|
|||||||
bool writeObjectToFile(const char* file, const char* key, JsonDocument* content);
|
bool writeObjectToFile(const char* file, const char* key, JsonDocument* content);
|
||||||
bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest);
|
bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest);
|
||||||
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest);
|
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest);
|
||||||
|
bool readToBuffer(const char* file, uint8_t** buf, uint32_t* len);
|
||||||
void updateFSInfo();
|
void updateFSInfo();
|
||||||
void closeFile();
|
void closeFile();
|
||||||
|
|
||||||
|
@ -409,3 +409,21 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//provide maximum buffer size in len variable
|
||||||
|
//if this returns true, the buffer array must be deleted by the caller
|
||||||
|
bool readToBuffer(const char* file, uint8_t** buf, uint32_t* len) {
|
||||||
|
Serial.println("opening file");
|
||||||
|
File f = WLED_FS.open(file,"r");
|
||||||
|
if (!f) return false;
|
||||||
|
uint32_t sz = f.size();
|
||||||
|
Serial.println(sz);
|
||||||
|
if (!sz || sz > *len) {f.close(); return false;}
|
||||||
|
*buf = new uint8_t[sz];
|
||||||
|
if (!*buf) {f.close(); return false;}
|
||||||
|
*len = sz;
|
||||||
|
f.read(*buf, sz);
|
||||||
|
f.close();
|
||||||
|
Serial.println("done");
|
||||||
|
return true;
|
||||||
|
}
|
@ -8,7 +8,7 @@
|
|||||||
// For (most) devices that cannot allocate a 64KiB wasm page
|
// For (most) devices that cannot allocate a 64KiB wasm page
|
||||||
#define WASM_MEMORY_LIMIT 4096
|
#define WASM_MEMORY_LIMIT 4096
|
||||||
|
|
||||||
unsigned char app_wasm[] = {
|
/*unsigned char app_wasm[] = {
|
||||||
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x03, 0x60,
|
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0f, 0x03, 0x60,
|
||||||
0x00, 0x01, 0x7f, 0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x60, 0x00,
|
0x00, 0x01, 0x7f, 0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x60, 0x00,
|
||||||
0x00, 0x02, 0x2b, 0x04, 0x03, 0x6c, 0x65, 0x64, 0x03, 0x6e, 0x6f, 0x77,
|
0x00, 0x02, 0x2b, 0x04, 0x03, 0x6c, 0x65, 0x64, 0x03, 0x6e, 0x6f, 0x77,
|
||||||
@ -26,8 +26,8 @@ unsigned char app_wasm[] = {
|
|||||||
0x20, 0x10, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4d, 0x61, 0x70, 0x70,
|
0x20, 0x10, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4d, 0x61, 0x70, 0x70,
|
||||||
0x69, 0x6e, 0x67, 0x55, 0x52, 0x4c, 0x0e, 0x2e, 0x2f, 0x61, 0x70, 0x70,
|
0x69, 0x6e, 0x67, 0x55, 0x52, 0x4c, 0x0e, 0x2e, 0x2f, 0x61, 0x70, 0x70,
|
||||||
0x2e, 0x77, 0x61, 0x73, 0x6d, 0x2e, 0x6d, 0x61, 0x70
|
0x2e, 0x77, 0x61, 0x73, 0x6d, 0x2e, 0x6d, 0x61, 0x70
|
||||||
};
|
};*/
|
||||||
unsigned int app_wasm_len = 201;
|
//unsigned int app_wasm_len = 201;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -195,6 +195,9 @@ IM3Runtime runtime;
|
|||||||
IM3Module module;
|
IM3Module module;
|
||||||
IM3Function fu;
|
IM3Function fu;
|
||||||
|
|
||||||
|
uint32_t app_wasm_len = 8192; //max bin size
|
||||||
|
uint8_t* app_wasm = nullptr;
|
||||||
|
|
||||||
void wasm_task(void*)
|
void wasm_task(void*)
|
||||||
{
|
{
|
||||||
result = m3Err_none;
|
result = m3Err_none;
|
||||||
@ -209,9 +212,24 @@ void wasm_task(void*)
|
|||||||
runtime->memoryLimit = WASM_MEMORY_LIMIT;
|
runtime->memoryLimit = WASM_MEMORY_LIMIT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!readToBuffer("/fx.wasm", &app_wasm, &app_wasm_len)) {
|
||||||
|
result = "fload";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Serial.println(app_wasm_len);
|
||||||
|
//Serial.println((uint32_t)app_wasm);
|
||||||
|
|
||||||
|
if (app_wasm == nullptr) {
|
||||||
|
result = "npr";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
result = m3_ParseModule (env, &module, app_wasm, app_wasm_len);
|
result = m3_ParseModule (env, &module, app_wasm, app_wasm_len);
|
||||||
if (result) FATAL("Prs", result);
|
if (result) FATAL("Prs", result);
|
||||||
|
|
||||||
|
delete[] app_wasm;
|
||||||
|
|
||||||
result = m3_LoadModule (runtime, module);
|
result = m3_LoadModule (runtime, module);
|
||||||
if (result) FATAL("Load", result);
|
if (result) FATAL("Load", result);
|
||||||
|
|
||||||
@ -241,7 +259,8 @@ void wasmInit()
|
|||||||
void wasmRun() {
|
void wasmRun() {
|
||||||
if (result) {
|
if (result) {
|
||||||
//Serial.println(F("You fucked up... Majorly..."));
|
//Serial.println(F("You fucked up... Majorly..."));
|
||||||
Serial.println("If only...");
|
Serial.print("If only... ");
|
||||||
|
Serial.println(result);
|
||||||
//Serial.println("That could save us🥺");
|
//Serial.println("That could save us🥺");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -266,7 +285,9 @@ void wasmRun() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wasmEnd() {
|
void wasmEnd() {
|
||||||
if (module) m3_FreeModule(module); module = nullptr;
|
//if (module) m3_FreeModule(module); module = nullptr;
|
||||||
|
Serial.println("F");
|
||||||
if (runtime) m3_FreeRuntime(runtime); runtime = nullptr;
|
if (runtime) m3_FreeRuntime(runtime); runtime = nullptr;
|
||||||
if (env) m3_FreeEnvironment(env); env = nullptr;
|
if (env) m3_FreeEnvironment(env); env = nullptr;
|
||||||
|
Serial.println("F later");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user