WS support preliminary
This commit is contained in:
parent
63acddf1a5
commit
82faa46531
@ -249,6 +249,15 @@
|
|||||||
#define MAX_LEDS_PER_BUS 4096
|
#define MAX_LEDS_PER_BUS 4096
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX_WASM_BIN_SIZE
|
||||||
|
#define MAX_WASM_BIN_SIZE 8192
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define WASM_STATE_UNLOADED 0
|
||||||
|
#define WASM_STATE_READY 1
|
||||||
|
#define WASM_STATE_STALE 2
|
||||||
|
#define WASM_STATE_ERROR 3
|
||||||
|
|
||||||
// string temp buffer (now stored in stack locally)
|
// string temp buffer (now stored in stack locally)
|
||||||
#define OMAX 2048
|
#define OMAX 2048
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ IM3Runtime runtime;
|
|||||||
IM3Module module;
|
IM3Module module;
|
||||||
IM3Function fu;
|
IM3Function fu;
|
||||||
|
|
||||||
uint32_t app_wasm_len = 8192; //max 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*)
|
||||||
|
@ -144,7 +144,6 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
|
|||||||
#include "NodeStruct.h"
|
#include "NodeStruct.h"
|
||||||
#include "pin_manager.h"
|
#include "pin_manager.h"
|
||||||
#include "bus_manager.h"
|
#include "bus_manager.h"
|
||||||
//#include "wasmfx.h"
|
|
||||||
|
|
||||||
#ifndef CLIENT_SSID
|
#ifndef CLIENT_SSID
|
||||||
#define CLIENT_SSID DEFAULT_CLIENT_SSID
|
#define CLIENT_SSID DEFAULT_CLIENT_SSID
|
||||||
@ -591,6 +590,8 @@ 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 byte wasm_state _INIT(WASM_STATE_UNLOADED);
|
||||||
|
|
||||||
// Usermod manager
|
// Usermod manager
|
||||||
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
|
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
|
||||||
|
@ -22,9 +22,9 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
|
|||||||
} else if(type == WS_EVT_DATA) {
|
} else if(type == WS_EVT_DATA) {
|
||||||
//data packet
|
//data packet
|
||||||
AwsFrameInfo * info = (AwsFrameInfo*)arg;
|
AwsFrameInfo * info = (AwsFrameInfo*)arg;
|
||||||
if(info->final && info->index == 0 && info->len == len){
|
if(info->opcode == WS_TEXT) {
|
||||||
//the whole message is in a single frame and we got all of its data (max. 1450byte)
|
//the whole message is in a single frame and we got all of its data (max. 1450byte)
|
||||||
if(info->opcode == WS_TEXT)
|
if(info->final && info->index == 0 && info->len == len)
|
||||||
{
|
{
|
||||||
bool verboseResponse = false;
|
bool verboseResponse = false;
|
||||||
{ //scope JsonDocument so it releases its buffer
|
{ //scope JsonDocument so it releases its buffer
|
||||||
@ -51,8 +51,27 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
|
|||||||
}
|
}
|
||||||
//update if it takes longer than 300ms until next "broadcast"
|
//update if it takes longer than 300ms until next "broadcast"
|
||||||
if (verboseResponse && (millis() - lastInterfaceUpdate < 1700 || !interfaceUpdateCallMode)) sendDataWs(client);
|
if (verboseResponse && (millis() - lastInterfaceUpdate < 1700 || !interfaceUpdateCallMode)) sendDataWs(client);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
if((info->index + len) == info->len){
|
||||||
|
if(info->final){
|
||||||
|
client->text(F("{\"error\":9}")); //we do not handle split packets right now
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (info->opcode == WS_BINARY){ //wasm custom FX binary
|
||||||
|
if (len > MAX_WASM_BIN_SIZE) return;
|
||||||
|
if(info->index == 0){
|
||||||
|
delete[] wasm_buffer;
|
||||||
|
wasm_buffer = new uint8_t[len];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info->index + info->len <= len) {
|
||||||
|
memcpy(wasm_buffer + info->index, data, info->len);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info->final) {
|
||||||
|
//reload WASM on the next frame
|
||||||
|
}
|
||||||
//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){
|
||||||
//if (!wsFrameBuffer && len < 4096) wsFrameBuffer = new uint8_t[4096];
|
//if (!wsFrameBuffer && len < 4096) wsFrameBuffer = new uint8_t[4096];
|
||||||
@ -63,13 +82,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
|
|||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if((info->index + len) == info->len){
|
|
||||||
if(info->final){
|
|
||||||
if(info->message_opcode == WS_TEXT) {
|
|
||||||
client->text(F("{\"error\":9}")); //we do not handle split packets right now
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if(type == WS_EVT_ERROR){
|
} else if(type == WS_EVT_ERROR){
|
||||||
//error was received from the other end
|
//error was received from the other end
|
||||||
|
Loading…
Reference in New Issue
Block a user