mirror of
https://github.com/jwetzell/acn-js.git
synced 2026-09-10 15:59:25 +00:00
type/enum cleanup
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
export enum Protocol {
|
||||||
|
SDT = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum SDTVector {
|
||||||
|
REL_WRAP = 1,
|
||||||
|
UNREL_WRAP,
|
||||||
|
CHANNEL_PARAMS,
|
||||||
|
JOIN,
|
||||||
|
JOIN_REFUSE,
|
||||||
|
JOIN_ACCEPT,
|
||||||
|
LEAVE,
|
||||||
|
LEAVING,
|
||||||
|
CONNECT,
|
||||||
|
CONNECT_ACCEPT,
|
||||||
|
CONNECT_REFUSE,
|
||||||
|
DISCONNECT,
|
||||||
|
DISCONNECTING,
|
||||||
|
ACK,
|
||||||
|
NAK,
|
||||||
|
GET_SESSIONS,
|
||||||
|
SESSIONS,
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum TransportLayerAddressType {
|
||||||
|
SDT_ADDR_NULL = 0,
|
||||||
|
SDT_ADDR_IPV4,
|
||||||
|
SDT_ADDR_IPV6,
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum SDTReasonCode {
|
||||||
|
NONSPECIFIC = 1,
|
||||||
|
ILLEGAL_PARAMETERS,
|
||||||
|
LOW_RESOURCES,
|
||||||
|
ALREADY_MEMBER,
|
||||||
|
BAD_ADDRESS_TYPE,
|
||||||
|
NO_RECIPROCAL_CHANNEL,
|
||||||
|
CHANNEL_EXPIRED,
|
||||||
|
LOST_SEQUENCE,
|
||||||
|
SATURATED,
|
||||||
|
TRANSPORT_ADDRESS_CHANGING,
|
||||||
|
ASKED_TO_LEAVE,
|
||||||
|
NO_RECIPIENT,
|
||||||
|
ONLY_UNICAST_SUPPORTED,
|
||||||
|
}
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
export * from './models';
|
export * from './types';
|
||||||
export * from './udp';
|
export * from './udp';
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import pdu from '.';
|
import pdu from '.';
|
||||||
import { Protocols, RootLayerPDU, SessionDataTransportPDU } from '../models';
|
import { Protocol } from '../enums';
|
||||||
|
import { RootLayerPDU, SessionDataTransportPDU } from '../types';
|
||||||
import { toHex } from '../utils';
|
import { toHex } from '../utils';
|
||||||
|
|
||||||
function decode(bytes: Uint8Array): RootLayerPDU {
|
function decode(bytes: Uint8Array): RootLayerPDU {
|
||||||
@@ -52,8 +53,10 @@ function decode(bytes: Uint8Array): RootLayerPDU {
|
|||||||
const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 4 + 16);
|
const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 4 + 16);
|
||||||
let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength);
|
let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength);
|
||||||
|
|
||||||
if (vector === Protocols.SDT) {
|
if (vector === Protocol.SDT) {
|
||||||
data = pdu.sdt.decode(data);
|
data = pdu.sdt.decode(data);
|
||||||
|
} else {
|
||||||
|
console.error(`unhandled protocol in RLP: ${vector}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
+18
-19
@@ -1,5 +1,5 @@
|
|||||||
|
import { Protocol, SDTVector } from '../enums';
|
||||||
import {
|
import {
|
||||||
Protocols,
|
|
||||||
SDTAckData,
|
SDTAckData,
|
||||||
SDTConnectAcceptData,
|
SDTConnectAcceptData,
|
||||||
SDTConnectData,
|
SDTConnectData,
|
||||||
@@ -14,9 +14,8 @@ import {
|
|||||||
SDTNakData,
|
SDTNakData,
|
||||||
SDTWrapperData,
|
SDTWrapperData,
|
||||||
SessionDataTransportPDU,
|
SessionDataTransportPDU,
|
||||||
SessionDataTransportVectors,
|
|
||||||
TransportLayerAddress,
|
TransportLayerAddress,
|
||||||
} from '../models';
|
} from '../types';
|
||||||
import { toHex } from '../utils';
|
import { toHex } from '../utils';
|
||||||
|
|
||||||
// TODO(jwetzell): work out flag inheritance, will need previous PDU
|
// TODO(jwetzell): work out flag inheritance, will need previous PDU
|
||||||
@@ -115,7 +114,7 @@ function decodeClientBlock(bytes: Uint8Array) {
|
|||||||
const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 2 + 6);
|
const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 2 + 6);
|
||||||
let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength);
|
let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength);
|
||||||
|
|
||||||
if (clientProtocol === Protocols.SDT) {
|
if (clientProtocol === Protocol.SDT) {
|
||||||
data = decode(data);
|
data = decode(data);
|
||||||
} else {
|
} else {
|
||||||
console.error(`SDT client block contains unknown protocol: ${clientProtocol}`);
|
console.error(`SDT client block contains unknown protocol: ${clientProtocol}`);
|
||||||
@@ -129,7 +128,7 @@ function decodeClientBlock(bytes: Uint8Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function decodeData(
|
function decodeData(
|
||||||
vector: SessionDataTransportVectors,
|
vector: SDTVector,
|
||||||
bytes: Uint8Array
|
bytes: Uint8Array
|
||||||
):
|
):
|
||||||
| SDTJoinData
|
| SDTJoinData
|
||||||
@@ -148,7 +147,7 @@ function decodeData(
|
|||||||
| Uint8Array {
|
| Uint8Array {
|
||||||
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||||
switch (vector) {
|
switch (vector) {
|
||||||
case SessionDataTransportVectors.JOIN: {
|
case SDTVector.JOIN: {
|
||||||
const destinationAddress: TransportLayerAddress = {
|
const destinationAddress: TransportLayerAddress = {
|
||||||
type: view.getUint8(30),
|
type: view.getUint8(30),
|
||||||
};
|
};
|
||||||
@@ -180,7 +179,7 @@ function decodeData(
|
|||||||
};
|
};
|
||||||
return joinData;
|
return joinData;
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.JOIN_ACCEPT: {
|
case SDTVector.JOIN_ACCEPT: {
|
||||||
const joinData = {
|
const joinData = {
|
||||||
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
||||||
channelNumber: view.getUint16(16),
|
channelNumber: view.getUint16(16),
|
||||||
@@ -190,7 +189,7 @@ function decodeData(
|
|||||||
};
|
};
|
||||||
return joinData;
|
return joinData;
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.JOIN_REFUSE: {
|
case SDTVector.JOIN_REFUSE: {
|
||||||
const joinData = {
|
const joinData = {
|
||||||
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
||||||
channelNumber: view.getUint16(16),
|
channelNumber: view.getUint16(16),
|
||||||
@@ -201,8 +200,8 @@ function decodeData(
|
|||||||
|
|
||||||
return joinData;
|
return joinData;
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.REL_WRAP:
|
case SDTVector.REL_WRAP:
|
||||||
case SessionDataTransportVectors.UNREL_WRAP: {
|
case SDTVector.UNREL_WRAP: {
|
||||||
const wrapperData: SDTWrapperData = {
|
const wrapperData: SDTWrapperData = {
|
||||||
channelNumber: view.getUint16(0),
|
channelNumber: view.getUint16(0),
|
||||||
totalSequenceNumber: view.getUint32(2),
|
totalSequenceNumber: view.getUint32(2),
|
||||||
@@ -216,12 +215,12 @@ function decodeData(
|
|||||||
|
|
||||||
return wrapperData;
|
return wrapperData;
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.ACK: {
|
case SDTVector.ACK: {
|
||||||
return {
|
return {
|
||||||
reliableSequenceNumber: view.getUint32(0),
|
reliableSequenceNumber: view.getUint32(0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.LEAVING: {
|
case SDTVector.LEAVING: {
|
||||||
return {
|
return {
|
||||||
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
||||||
channelNumber: view.getUint16(16),
|
channelNumber: view.getUint16(16),
|
||||||
@@ -230,12 +229,12 @@ function decodeData(
|
|||||||
reasonCode: view.getUint8(24),
|
reasonCode: view.getUint8(24),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.GET_SESSIONS: {
|
case SDTVector.GET_SESSIONS: {
|
||||||
return {
|
return {
|
||||||
componentID: toHex(bytes.subarray(0, 16)),
|
componentID: toHex(bytes.subarray(0, 16)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.NAK: {
|
case SDTVector.NAK: {
|
||||||
return {
|
return {
|
||||||
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
leaderComponentID: toHex(bytes.subarray(0, 16)),
|
||||||
channelNumber: view.getUint16(16),
|
channelNumber: view.getUint16(16),
|
||||||
@@ -245,20 +244,20 @@ function decodeData(
|
|||||||
lastMissedSequence: view.getUint32(28),
|
lastMissedSequence: view.getUint32(28),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.DISCONNECT:
|
case SDTVector.DISCONNECT:
|
||||||
case SessionDataTransportVectors.CONNECT:
|
case SDTVector.CONNECT:
|
||||||
case SessionDataTransportVectors.CONNECT_ACCEPT: {
|
case SDTVector.CONNECT_ACCEPT: {
|
||||||
return {
|
return {
|
||||||
protocolID: view.getUint32(0),
|
protocolID: view.getUint32(0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.CONNECT_REFUSE: {
|
case SDTVector.CONNECT_REFUSE: {
|
||||||
return {
|
return {
|
||||||
protocolID: view.getUint32(0),
|
protocolID: view.getUint32(0),
|
||||||
refuseCode: view.getUint8(4),
|
refuseCode: view.getUint8(4),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case SessionDataTransportVectors.DISCONNECTING: {
|
case SDTVector.DISCONNECTING: {
|
||||||
return {
|
return {
|
||||||
protocolID: view.getUint32(0),
|
protocolID: view.getUint32(0),
|
||||||
reasonCode: view.getUint8(4),
|
reasonCode: view.getUint8(4),
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
export enum Protocols {
|
import { TransportLayerAddressType, SDTVector, SDTReasonCode } from './enums';
|
||||||
SDT = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
export type UDPPreamble = {
|
export type UDPPreamble = {
|
||||||
preambleSize: number;
|
preambleSize: number;
|
||||||
@@ -20,32 +18,6 @@ export type RootLayerPDU = {
|
|||||||
data: SessionDataTransportPDU | Uint8Array;
|
data: SessionDataTransportPDU | Uint8Array;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum SessionDataTransportVectors {
|
|
||||||
REL_WRAP = 1,
|
|
||||||
UNREL_WRAP,
|
|
||||||
CHANNEL_PARAMS,
|
|
||||||
JOIN,
|
|
||||||
JOIN_REFUSE,
|
|
||||||
JOIN_ACCEPT,
|
|
||||||
LEAVE,
|
|
||||||
LEAVING,
|
|
||||||
CONNECT,
|
|
||||||
CONNECT_ACCEPT,
|
|
||||||
CONNECT_REFUSE,
|
|
||||||
DISCONNECT,
|
|
||||||
DISCONNECTING,
|
|
||||||
ACK,
|
|
||||||
NAK,
|
|
||||||
GET_SESSIONS,
|
|
||||||
SESSIONS,
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum TransportLayerAddressTypes {
|
|
||||||
SDT_ADDR_NULL = 0,
|
|
||||||
SDT_ADDR_IPV4,
|
|
||||||
SDT_ADDR_IPV6,
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SDTChannelParams = {
|
export type SDTChannelParams = {
|
||||||
expiry: number;
|
expiry: number;
|
||||||
nakOutboundFlag: number;
|
nakOutboundFlag: number;
|
||||||
@@ -55,7 +27,7 @@ export type SDTChannelParams = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type TransportLayerAddress = {
|
export type TransportLayerAddress = {
|
||||||
type: TransportLayerAddressTypes;
|
type: TransportLayerAddressType;
|
||||||
port?: number;
|
port?: number;
|
||||||
address?: string;
|
address?: string;
|
||||||
};
|
};
|
||||||
@@ -85,7 +57,7 @@ export type SDTJoinRefuseData = {
|
|||||||
channelNumber: number;
|
channelNumber: number;
|
||||||
memberID: number;
|
memberID: number;
|
||||||
reliableSequenceNumber: number;
|
reliableSequenceNumber: number;
|
||||||
refuseCode: number;
|
refuseCode: SDTReasonCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SDTLeavingData = {
|
export type SDTLeavingData = {
|
||||||
@@ -93,7 +65,7 @@ export type SDTLeavingData = {
|
|||||||
channelNumber: number;
|
channelNumber: number;
|
||||||
memberID: number;
|
memberID: number;
|
||||||
reliableSequenceNumber: number;
|
reliableSequenceNumber: number;
|
||||||
reasonCode: number;
|
reasonCode: SDTReasonCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SDTWrapperData = {
|
export type SDTWrapperData = {
|
||||||
@@ -127,13 +99,13 @@ export type SDTConnectData = {
|
|||||||
export type SDTConnectAcceptData = SDTConnectData;
|
export type SDTConnectAcceptData = SDTConnectData;
|
||||||
export type SDTConnectRefuseData = {
|
export type SDTConnectRefuseData = {
|
||||||
protocolID: number;
|
protocolID: number;
|
||||||
refuseCode: number;
|
refuseCode: SDTReasonCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SDTDisconnectData = SDTConnectData;
|
export type SDTDisconnectData = SDTConnectData;
|
||||||
export type SDTDisconnectingData = {
|
export type SDTDisconnectingData = {
|
||||||
protocolID: number;
|
protocolID: number;
|
||||||
reasonCode: number;
|
reasonCode: SDTReasonCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SDTGetSessionsData = {
|
export type SDTGetSessionsData = {
|
||||||
@@ -141,7 +113,7 @@ export type SDTGetSessionsData = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type SessionDataTransportPDU = {
|
export type SessionDataTransportPDU = {
|
||||||
vector: SessionDataTransportVectors;
|
vector: SDTVector;
|
||||||
// TODO(jwetzell): cleanup these types
|
// TODO(jwetzell): cleanup these types
|
||||||
data:
|
data:
|
||||||
| SDTJoinData
|
| SDTJoinData
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ACNPacket, RootLayerPDU, UDPPreamble } from './models';
|
import { ACNPacket, RootLayerPDU, UDPPreamble } from './types';
|
||||||
import pdu from './pdu';
|
import pdu from './pdu';
|
||||||
|
|
||||||
// ANSI E1.17 - 2015 (R2020) EPI 17
|
// ANSI E1.17 - 2015 (R2020) EPI 17
|
||||||
|
|||||||
Reference in New Issue
Block a user