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