WS support preliminary

This commit is contained in:
cschwinne 2021-08-16 12:30:45 +02:00
parent 63acddf1a5
commit 82faa46531
4 changed files with 36 additions and 13 deletions

View File

@ -249,6 +249,15 @@
#define MAX_LEDS_PER_BUS 4096
#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)
#define OMAX 2048

View File

@ -195,7 +195,7 @@ IM3Runtime runtime;
IM3Module module;
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;
void wasm_task(void*)

View File

@ -144,7 +144,6 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
#include "NodeStruct.h"
#include "pin_manager.h"
#include "bus_manager.h"
//#include "wasmfx.h"
#ifndef CLIENT_SSID
#define CLIENT_SSID DEFAULT_CLIENT_SSID
@ -591,6 +590,8 @@ WLED_GLOBAL bool doInitBusses _INIT(false);
// WASM
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
WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());

View File

@ -19,12 +19,12 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
} else if(type == WS_EVT_DISCONNECT){
//client disconnected
if (client->id() == wsLiveClientId) wsLiveClientId = 0;
} else if(type == WS_EVT_DATA){
} else if(type == WS_EVT_DATA) {
//data packet
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)
if(info->opcode == WS_TEXT)
if(info->final && info->index == 0 && info->len == len)
{
bool verboseResponse = false;
{ //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"
if (verboseResponse && (millis() - lastInterfaceUpdate < 1700 || !interfaceUpdateCallMode)) sendDataWs(client);
}
} 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
//if(info->index == 0){
//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){
//error was received from the other end