Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement packet split for realtime udp frames #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions dist/lib/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,21 +516,28 @@ export class Light {
throw new Error("UDP not supported in browser");
// Generate the header
let tokenArray = this.token.getTokenDecoded();
let udpHeader = Buffer.alloc(tokenArray.length + 4);
udpHeader.writeUInt8(0x03); // the version number
udpHeader.fill(tokenArray, 1); // the actual token, 8 bytes
udpHeader.writeUInt8(0x00, tokenArray.length + 1); // zero blanking
udpHeader.writeUInt8(0x00, tokenArray.length + 2); // zero blanking
udpHeader.writeUInt8(0x00, tokenArray.length + 3); // number of packets (currently only 1 as i only hav 250 leds)
// Generate the body
const data = Buffer.alloc(udpHeader.length + frame.getNLeds() * 3);
data.fill(udpHeader);
data.fill(frame.toOctet(), udpHeader.length);
this.udpClient.send(data, 7777, this.ipaddr, (error) => {
if (error) {
console.warn(error);
}
});
let rawFrame = frame.toOctet();
let packetId = 0;
do {
let framePart = rawFrame.slice(0, 900);
rawFrame = rawFrame.slice(900);
let udpHeader = Buffer.alloc(tokenArray.length + 4);
udpHeader.writeUInt8(0x03); // the version number
udpHeader.fill(tokenArray, 1); // the actual token, 8 bytes
udpHeader.writeUInt8(0x00, tokenArray.length + 1); // zero blanking
udpHeader.writeUInt8(0x00, tokenArray.length + 2); // zero blanking
udpHeader.writeUInt8(packetId, tokenArray.length + 3);
// Generate the body
const data = Buffer.alloc(udpHeader.length + framePart.length);
data.fill(udpHeader);
data.fill(framePart, udpHeader.length);
this.udpClient.send(data, 7777, this.ipaddr, (error) => {
if (error) {
console.warn(error);
}
});
packetId++;
} while (rawFrame.length > 0);
});
}
/**
Expand Down
42 changes: 25 additions & 17 deletions src/lib/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,31 @@ export class Light {

// Generate the header
let tokenArray = this.token.getTokenDecoded();
let udpHeader = Buffer.alloc(tokenArray.length + 4);

udpHeader.writeUInt8(0x03); // the version number
udpHeader.fill(tokenArray, 1); // the actual token, 8 bytes
udpHeader.writeUInt8(0x00, tokenArray.length + 1); // zero blanking
udpHeader.writeUInt8(0x00, tokenArray.length + 2); // zero blanking
udpHeader.writeUInt8(0x00, tokenArray.length + 3); // number of packets (currently only 1 as i only hav 250 leds)

// Generate the body
const data = Buffer.alloc(udpHeader.length + frame.getNLeds() * 3);
data.fill(udpHeader);
data.fill(frame.toOctet(), udpHeader.length);
this.udpClient.send(data, 7777, this.ipaddr, (error: any) => {
if (error) {
console.warn(error);
}
});

let rawFrame = frame.toOctet();
let packetId = 0;
do {
let framePart = rawFrame.slice(0, 900);
rawFrame = rawFrame.slice(900);

let udpHeader = Buffer.alloc(tokenArray.length + 4);
udpHeader.writeUInt8(0x03); // the version number
udpHeader.fill(tokenArray, 1); // the actual token, 8 bytes
udpHeader.writeUInt8(0x00, tokenArray.length + 1); // zero blanking
udpHeader.writeUInt8(0x00, tokenArray.length + 2); // zero blanking
udpHeader.writeUInt8(packetId, tokenArray.length + 3);

// Generate the body
const data = Buffer.alloc(udpHeader.length + framePart.length);
data.fill(udpHeader);
data.fill(framePart, udpHeader.length);
this.udpClient.send(data, 7777, this.ipaddr, (error: any) => {
if (error) {
console.warn(error);
}
});
packetId++;
} while (rawFrame.length > 0);
}
/**
* Get a list of movies
Expand Down