From 1dea781e369bba5acaac558c54ce2679c05c96fb Mon Sep 17 00:00:00 2001 From: devl0rd Date: Wed, 29 Apr 2020 00:04:49 -0600 Subject: [PATCH] detect corrupt packets. hid --- SkyNX-Streamer/NxStreamingService/main.js | 10 +++++++++- SkyNX/source/audio.c | 1 - SkyNX/source/input.c | 2 +- SkyNX/source/main.c | 2 +- SkyNX/source/network.c | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/SkyNX-Streamer/NxStreamingService/main.js b/SkyNX-Streamer/NxStreamingService/main.js index 6a35628..fd93172 100644 --- a/SkyNX-Streamer/NxStreamingService/main.js +++ b/SkyNX-Streamer/NxStreamingService/main.js @@ -96,6 +96,7 @@ function startVideoProcess() { }); } hidStreamClient.on('connect', function () { + hidStreamClient.setNoDelay(true); console.log('Connected to Switch!'); if (usingVideo) { startVideoProcess(); @@ -476,8 +477,15 @@ function handleGyroAndAccel(hid) { } var fpsPrintTimer = 0; hidStreamClient.on('data', function (data) { + if (data.length < 208) { + console.log("Data incorrect length. Data length: " + data.length) + return; + } //packet is 208 in length. anyless then the data is bad + if (data.length > 208) { + data.length = 208; //ignore extra data + // console.log(data.length / 208) + } switchHidBuffer = new Buffer.from(data); - var hid = parseInputStruct(switchHidBuffer) var controllerCount = hid.get("controllerCount"); if (controllerCount > controllerIds.length) { diff --git a/SkyNX/source/audio.c b/SkyNX/source/audio.c index 48712b1..a95a687 100644 --- a/SkyNX/source/audio.c +++ b/SkyNX/source/audio.c @@ -134,7 +134,6 @@ void audioHandlerLoop() resample((unsigned short *)in_buf, sizeof(in_buf), (unsigned short *)buf_data[curBuf], FACT); play_buf(buffer_size, DATA_SIZE); played++; - // svcSleepThread(16666665); //Nano sleep to keep at 60fps } for (int curBuf = 0; curBuf < BUF_COUNT; curBuf++) diff --git a/SkyNX/source/input.c b/SkyNX/source/input.c index e1f4a38..be36bb3 100644 --- a/SkyNX/source/input.c +++ b/SkyNX/source/input.c @@ -136,7 +136,7 @@ void inputHandlerLoop(void *dummy) while (appletMainLoop()) { handleInput(connection); - svcSleepThread(23333333); + svcSleepThread(23333333ULL); } freeJoyConSocket(connection); diff --git a/SkyNX/source/main.c b/SkyNX/source/main.c index 0945531..e63e222 100644 --- a/SkyNX/source/main.c +++ b/SkyNX/source/main.c @@ -153,7 +153,7 @@ int main(int argc, char **argv) { drawSplash(renderContext); } - svcSleepThread(14285714); //Nano sleep to keep at 70fps to handle drop frames without stutter + svcSleepThread(14285714ULL); //Nano sleep to keep at 70fps to handle drop frames without stutter } /* Deinitialize all used systems */ unInit(); diff --git a/SkyNX/source/network.c b/SkyNX/source/network.c index c8a23be..667afca 100644 --- a/SkyNX/source/network.c +++ b/SkyNX/source/network.c @@ -81,6 +81,7 @@ int connectJoyConSocket(JoyConSocket *connection, int port) void sendJoyConInput(JoyConSocket *connection, const JoyPkg *pkg) { + // printf("%lu\n", sizeof(JoyPkg)); if (send(connection->sock, pkg, sizeof(JoyPkg), 0) != sizeof(JoyPkg)) { connection->sock = -1;