WS support working
This commit is contained in:
parent
82faa46531
commit
7c3b96c0e1
@ -254,9 +254,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WASM_STATE_UNLOADED 0
|
#define WASM_STATE_UNLOADED 0
|
||||||
#define WASM_STATE_READY 1
|
#define WASM_STATE_READY 1 //wasm runtime allocated
|
||||||
#define WASM_STATE_STALE 2
|
#define WASM_STATE_STALE 2 //inited, but wasm_buffer has updated. Runtime re-init required.
|
||||||
#define WASM_STATE_ERROR 3
|
#define WASM_STATE_ERROR 3 //runtime wasm error
|
||||||
|
|
||||||
// string temp buffer (now stored in stack locally)
|
// string temp buffer (now stored in stack locally)
|
||||||
#define OMAX 2048
|
#define OMAX 2048
|
||||||
|
@ -195,8 +195,8 @@ IM3Runtime runtime;
|
|||||||
IM3Module module;
|
IM3Module module;
|
||||||
IM3Function fu;
|
IM3Function fu;
|
||||||
|
|
||||||
uint32_t app_wasm_len = MAX_WASM_BIN_SIZE;
|
//uint32_t app_wasm_len = MAX_WASM_BIN_SIZE;
|
||||||
uint8_t* app_wasm = nullptr;
|
//uint8_t* app_wasm = nullptr;
|
||||||
|
|
||||||
void wasm_task(void*)
|
void wasm_task(void*)
|
||||||
{
|
{
|
||||||
@ -212,23 +212,28 @@ 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)) {
|
if (wasm_buffer) { //from websockets
|
||||||
result = "fload";
|
//app_wasm_len = wasm_buffer_len;
|
||||||
return;
|
} else { //from filesystem (fx.wasm)
|
||||||
|
wasm_buffer_len = MAX_WASM_BIN_SIZE;
|
||||||
|
if (!readToBuffer("/fx.wasm", &wasm_buffer, &wasm_buffer_len)) {
|
||||||
|
result = "fload";
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Serial.println(app_wasm_len);
|
//Serial.println(app_wasm_len);
|
||||||
//Serial.println((uint32_t)app_wasm);
|
//Serial.println((uint32_t)app_wasm);
|
||||||
|
|
||||||
if (app_wasm == nullptr) {
|
if (wasm_buffer == nullptr) {
|
||||||
result = "npr";
|
result = "npr";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = m3_ParseModule (env, &module, app_wasm, app_wasm_len);
|
result = m3_ParseModule (env, &module, wasm_buffer, wasm_buffer_len);
|
||||||
if (result) FATAL("Prs", result);
|
if (result) FATAL("Prs", result);
|
||||||
|
|
||||||
delete[] app_wasm;
|
delete[] wasm_buffer; wasm_buffer = nullptr; wasm_buffer_len = 0;
|
||||||
|
|
||||||
result = m3_LoadModule (runtime, module);
|
result = m3_LoadModule (runtime, module);
|
||||||
if (result) FATAL("Load", result);
|
if (result) FATAL("Load", result);
|
||||||
@ -240,10 +245,12 @@ void wasm_task(void*)
|
|||||||
if (result) FATAL("Func", result);
|
if (result) FATAL("Func", result);
|
||||||
|
|
||||||
Serial.println(F("WASM init success!"));
|
Serial.println(F("WASM init success!"));
|
||||||
|
wasm_state = WASM_STATE_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wasmInit()
|
void wasmInit()
|
||||||
{
|
{
|
||||||
|
if (runtime || env) wasmEnd();
|
||||||
//Serial.println("\nWasm3 v" M3_VERSION " (" M3_ARCH "), build " __DATE__ " " __TIME__);
|
//Serial.println("\nWasm3 v" M3_VERSION " (" M3_ARCH "), build " __DATE__ " " __TIME__);
|
||||||
/*
|
/*
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
@ -257,11 +264,16 @@ void wasmInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wasmRun() {
|
void wasmRun() {
|
||||||
|
//re-init after wasm_buffer refresh
|
||||||
|
if (wasm_state == WASM_STATE_STALE) wasmInit();
|
||||||
|
|
||||||
|
if (wasm_state != WASM_STATE_READY) return;
|
||||||
if (result) {
|
if (result) {
|
||||||
//Serial.println(F("You fucked up... Majorly..."));
|
//Serial.println(F("You fucked up... Majorly..."));
|
||||||
Serial.print("If only... ");
|
Serial.print("If only... ");
|
||||||
Serial.println(result);
|
Serial.println(result);
|
||||||
//Serial.println("That could save us🥺");
|
//Serial.println("That could save us🥺");
|
||||||
|
wasm_state = WASM_STATE_ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,6 +293,7 @@ void wasmRun() {
|
|||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
Serial.println(info.line);
|
Serial.println(info.line);
|
||||||
}
|
}
|
||||||
|
wasm_state = WASM_STATE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,4 +303,5 @@ void wasmEnd() {
|
|||||||
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");
|
Serial.println("F later");
|
||||||
|
wasm_state = WASM_STATE_UNLOADED;
|
||||||
}
|
}
|
@ -591,6 +591,7 @@ WLED_GLOBAL bool doInitBusses _INIT(false);
|
|||||||
// WASM
|
// WASM
|
||||||
WLED_GLOBAL WASMFX wasmfx _INIT(WASMFX());
|
WLED_GLOBAL WASMFX wasmfx _INIT(WASMFX());
|
||||||
WLED_GLOBAL uint8_t* wasm_buffer _INIT(nullptr);
|
WLED_GLOBAL uint8_t* wasm_buffer _INIT(nullptr);
|
||||||
|
WLED_GLOBAL uint32_t wasm_buffer_len _INIT(0);
|
||||||
WLED_GLOBAL byte wasm_state _INIT(WASM_STATE_UNLOADED);
|
WLED_GLOBAL byte wasm_state _INIT(WASM_STATE_UNLOADED);
|
||||||
|
|
||||||
// Usermod manager
|
// Usermod manager
|
||||||
|
@ -63,6 +63,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
|
|||||||
if(info->index == 0){
|
if(info->index == 0){
|
||||||
delete[] wasm_buffer;
|
delete[] wasm_buffer;
|
||||||
wasm_buffer = new uint8_t[len];
|
wasm_buffer = new uint8_t[len];
|
||||||
|
wasm_buffer_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->index + info->len <= len) {
|
if (info->index + info->len <= len) {
|
||||||
@ -71,6 +72,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
|
|||||||
|
|
||||||
if (info->final) {
|
if (info->final) {
|
||||||
//reload WASM on the next frame
|
//reload WASM on the next frame
|
||||||
|
wasm_state = WASM_STATE_STALE;
|
||||||
}
|
}
|
||||||
//message is comprised of multiple frames or the frame is split into multiple packets
|
//message is comprised of multiple frames or the frame is split into multiple packets
|
||||||
//if(info->index == 0){
|
//if(info->index == 0){
|
||||||
|
Loading…
Reference in New Issue
Block a user