1 | export function multicastGroup(universe: number): string {
|
2 | if ((universe > 0 && universe <= 63999) || universe === 64214) {
|
3 |
|
4 | return `239.255.${universe >> 8}.${universe & 255}`;
|
5 | }
|
6 | throw new RangeError('universe must be between 1-63999');
|
7 | }
|
8 |
|
9 | export const dp = (n: number, decimals = 2): number =>
|
10 | Math.round(n * 10 ** decimals) / 10 ** decimals;
|
11 |
|
12 | export function objectify(buf: Buffer): Record<number, number> {
|
13 | const data = {};
|
14 | buf.forEach((val, ch) => {
|
15 | if (val > 0) data[ch + 1] = dp(val / 2.55, 2);
|
16 | });
|
17 | return data;
|
18 | }
|
19 |
|
20 | export const inRange = (n: number): number =>
|
21 | Math.min(255, Math.max(Math.round(n), 0));
|
22 |
|
23 | export function bit(bitt: 8 | 16 | 32, num: number): number[] {
|
24 |
|
25 |
|
26 | const arr = new ArrayBuffer(bitt / 8);
|
27 |
|
28 |
|
29 | const view = new DataView(arr);
|
30 | view[`setUint${bitt}`](0, num, false);
|
31 |
|
32 | return Array.from(new Uint8Array(arr));
|
33 | }
|
34 | export const empty = (len: number): number[] =>
|
35 | Array.from(new Uint8Array(new ArrayBuffer(len)));
|