Skip to content

Commit

Permalink
detect corrupt packets. hid
Browse files Browse the repository at this point in the history
  • Loading branch information
DevL0rd committed Apr 29, 2020
1 parent 3f918ff commit 1dea781
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion SkyNX-Streamer/NxStreamingService/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function startVideoProcess() {
});
}
hidStreamClient.on('connect', function () {
hidStreamClient.setNoDelay(true);
console.log('Connected to Switch!');
if (usingVideo) {
startVideoProcess();
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion SkyNX/source/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
2 changes: 1 addition & 1 deletion SkyNX/source/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void inputHandlerLoop(void *dummy)
while (appletMainLoop())
{
handleInput(connection);
svcSleepThread(23333333);
svcSleepThread(23333333ULL);
}

freeJoyConSocket(connection);
Expand Down
2 changes: 1 addition & 1 deletion SkyNX/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions SkyNX/source/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1dea781

Please sign in to comment.