knx.ts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -0
  3. package/dist/@types/interfaces/DPTs.d.ts +144 -0
  4. package/dist/@types/interfaces/DPTs.js +3 -0
  5. package/dist/@types/interfaces/EMI.d.ts +396 -0
  6. package/dist/@types/interfaces/EMI.js +2 -0
  7. package/dist/@types/interfaces/ServiceMessage.d.ts +11 -0
  8. package/dist/@types/interfaces/ServiceMessage.js +2 -0
  9. package/dist/@types/interfaces/SystemStatus.d.ts +18 -0
  10. package/dist/@types/interfaces/SystemStatus.js +2 -0
  11. package/dist/@types/interfaces/connection.d.ts +139 -0
  12. package/dist/@types/interfaces/connection.js +2 -0
  13. package/dist/@types/interfaces/localEndPoint.d.ts +5 -0
  14. package/dist/@types/interfaces/localEndPoint.js +2 -0
  15. package/dist/@types/types/AllDpts.d.ts +3 -0
  16. package/dist/@types/types/AllDpts.js +3 -0
  17. package/dist/@types/types/DecodedDPTType.d.ts +21 -0
  18. package/dist/@types/types/DecodedDPTType.js +2 -0
  19. package/dist/connection/KNXService.d.ts +58 -0
  20. package/dist/connection/KNXService.js +242 -0
  21. package/dist/connection/KNXTunneling.d.ts +44 -0
  22. package/dist/connection/KNXTunneling.js +509 -0
  23. package/dist/connection/KNXnetIPServer.d.ts +64 -0
  24. package/dist/connection/KNXnetIPServer.js +900 -0
  25. package/dist/connection/Router.d.ts +49 -0
  26. package/dist/connection/Router.js +269 -0
  27. package/dist/connection/TPUART.d.ts +32 -0
  28. package/dist/connection/TPUART.js +497 -0
  29. package/dist/connection/TunnelConnection.d.ts +57 -0
  30. package/dist/connection/TunnelConnection.js +167 -0
  31. package/dist/core/CEMI.d.ts +1130 -0
  32. package/dist/core/CEMI.js +1281 -0
  33. package/dist/core/ControlField.d.ts +57 -0
  34. package/dist/core/ControlField.js +120 -0
  35. package/dist/core/ControlFieldExtended.d.ts +56 -0
  36. package/dist/core/ControlFieldExtended.js +114 -0
  37. package/dist/core/EMI.d.ts +2515 -0
  38. package/dist/core/EMI.js +3898 -0
  39. package/dist/core/KNXAddInfoTypes.d.ts +225 -0
  40. package/dist/core/KNXAddInfoTypes.js +602 -0
  41. package/dist/core/KNXnetIPHeader.d.ts +10 -0
  42. package/dist/core/KNXnetIPHeader.js +38 -0
  43. package/dist/core/KNXnetIPStructures.d.ts +179 -0
  44. package/dist/core/KNXnetIPStructures.js +622 -0
  45. package/dist/core/MessageCodeField.d.ts +886 -0
  46. package/dist/core/MessageCodeField.js +399 -0
  47. package/dist/core/SystemStatus.d.ts +144 -0
  48. package/dist/core/SystemStatus.js +325 -0
  49. package/dist/core/data/KNXData.d.ts +7 -0
  50. package/dist/core/data/KNXData.js +30 -0
  51. package/dist/core/data/KNXDataDecode.d.ts +396 -0
  52. package/dist/core/data/KNXDataDecode.js +1186 -0
  53. package/dist/core/data/KNXDataEncode.d.ts +332 -0
  54. package/dist/core/data/KNXDataEncode.js +1504 -0
  55. package/dist/core/enum/APCIEnum.d.ts +587 -0
  56. package/dist/core/enum/APCIEnum.js +591 -0
  57. package/dist/core/enum/EnumControlField.d.ts +24 -0
  58. package/dist/core/enum/EnumControlField.js +36 -0
  59. package/dist/core/enum/EnumControlFieldExtended.d.ts +36 -0
  60. package/dist/core/enum/EnumControlFieldExtended.js +41 -0
  61. package/dist/core/enum/EnumShortACKFrame.d.ts +6 -0
  62. package/dist/core/enum/EnumShortACKFrame.js +10 -0
  63. package/dist/core/enum/ErrorCodeSet.d.ts +57 -0
  64. package/dist/core/enum/ErrorCodeSet.js +2 -0
  65. package/dist/core/enum/KNXnetIPEnum.d.ts +95 -0
  66. package/dist/core/enum/KNXnetIPEnum.js +90 -0
  67. package/dist/core/enum/SAP.d.ts +19 -0
  68. package/dist/core/enum/SAP.js +23 -0
  69. package/dist/core/layers/data/APDU.d.ts +38 -0
  70. package/dist/core/layers/data/APDU.js +115 -0
  71. package/dist/core/layers/data/NPDU.d.ts +73 -0
  72. package/dist/core/layers/data/NPDU.js +103 -0
  73. package/dist/core/layers/data/TPDU.d.ts +53 -0
  74. package/dist/core/layers/data/TPDU.js +73 -0
  75. package/dist/core/layers/interfaces/APCI.d.ts +61 -0
  76. package/dist/core/layers/interfaces/APCI.js +92 -0
  77. package/dist/core/layers/interfaces/TPCI.d.ts +110 -0
  78. package/dist/core/layers/interfaces/TPCI.js +196 -0
  79. package/dist/core/resources/DeviceDescriptorType.d.ts +46 -0
  80. package/dist/core/resources/DeviceDescriptorType.js +69 -0
  81. package/dist/errors/DPTNotFound.d.ts +6 -0
  82. package/dist/errors/DPTNotFound.js +15 -0
  83. package/dist/errors/InvalidKnxAddresExeption.d.ts +3 -0
  84. package/dist/errors/InvalidKnxAddresExeption.js +9 -0
  85. package/dist/index.d.ts +7 -0
  86. package/dist/index.js +18 -0
  87. package/dist/utils/CEMIAdapter.d.ts +16 -0
  88. package/dist/utils/CEMIAdapter.js +94 -0
  89. package/dist/utils/KNXHelper.d.ts +78 -0
  90. package/dist/utils/KNXHelper.js +338 -0
  91. package/dist/utils/Logger.d.ts +17 -0
  92. package/dist/utils/Logger.js +96 -0
  93. package/dist/utils/MessageCodeTranslator.d.ts +19 -0
  94. package/dist/utils/MessageCodeTranslator.js +77 -0
  95. package/dist/utils/checksumFrame.d.ts +18 -0
  96. package/dist/utils/checksumFrame.js +41 -0
  97. package/dist/utils/localIp.d.ts +7 -0
  98. package/dist/utils/localIp.js +45 -0
  99. package/package.json +49 -0
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NPDU = void 0;
4
+ const EnumControlFieldExtended_1 = require("../../enum/EnumControlFieldExtended");
5
+ const TPDU_1 = require("./TPDU");
6
+ /**
7
+ * Clase que representa la Network Protocol Data Unit (NPDU).
8
+ * * Responsabilidades:
9
+ * 1. Gestionar el Hop Count (Contador de saltos) para el enrutamiento.
10
+ * 2. Gestionar la longitud de la trama de datos (Length).
11
+ * 3. Encapsular el TPDU (Transport Layer PDU), que a su vez contiene el TPCI y el APDU.
12
+ * * Estructura del Byte NPCI (Network Protocol Control Information):
13
+ * Bits [7] : Reservado (normalmente 0 en tramas estándar)
14
+ * Bits [6-4] : Hop Count (0-7)
15
+ * Bits [3-0] : Longitud del Payload (APDU)
16
+ * @see 03_03_03 Network Layer v02.01.01 AS
17
+ */
18
+ class NPDU {
19
+ _hopCount = 6; // Valor por defecto estándar en KNX
20
+ TPDU; // Datos puros (payload del usuario)
21
+ _addressType;
22
+ constructor(InstanceOfTPDU = new TPDU_1.TPDU(), addressType = EnumControlFieldExtended_1.AddressType.GROUP, hopCount = 6) {
23
+ this._addressType = addressType;
24
+ this.hopCount = hopCount; // Usa el setter para validar
25
+ this.TPDU = InstanceOfTPDU;
26
+ }
27
+ /**
28
+ * Obtiene el Hop Count (0-7).
29
+ */
30
+ get hopCount() {
31
+ return this._hopCount;
32
+ }
33
+ /**
34
+ * Establece el Hop Count. Lanza error si está fuera de rango (0-7).
35
+ */
36
+ set hopCount(value) {
37
+ if (value < 0 || value > 7) {
38
+ throw new Error("Hop Count must be between 0 and 7");
39
+ }
40
+ this._hopCount = value;
41
+ }
42
+ get addressType() {
43
+ return this._addressType;
44
+ }
45
+ set addressType(value) {
46
+ if (value > 1 || value < 0)
47
+ throw new Error("The address type is not mayor or minor than 0..1");
48
+ this._addressType = value;
49
+ }
50
+ toBuffer() {
51
+ const tpduBuffer = this.TPDU.toBuffer();
52
+ const length = tpduBuffer.length;
53
+ // Construcción del Byte NPCI (Octeto 0 del NPDU)
54
+ // Bits 7: Reservado (0) -> parece ser el AddressType
55
+ // Bits 6-4: Hop Count
56
+ // Bits 3-0: Length (Longitud del TPDU)
57
+ const npciByte = (this.addressType << 7) | (this._hopCount << 4) | (length & 0x0f);
58
+ const buffer = Buffer.alloc(1 + length);
59
+ buffer.writeUInt8(npciByte, 0);
60
+ tpduBuffer.copy(buffer, 1);
61
+ return buffer;
62
+ }
63
+ describe() {
64
+ return {
65
+ layer: "Network Layer (NPDU)",
66
+ addressType: EnumControlFieldExtended_1.AddressType[this.addressType],
67
+ hopCount: this.hopCount,
68
+ TPDU: this.TPDU.describe(),
69
+ };
70
+ }
71
+ /**
72
+ * Crea una instancia de NPDU a partir de un Buffer crudo.
73
+ * Estructura: [NPCI] [TPDU...]
74
+ * @param buffer El buffer completo comenzando con el byte NPCI.
75
+ */
76
+ static fromBuffer(buffer) {
77
+ if (buffer.length < 2) {
78
+ // Mínimo 1 byte NPCI + 1 byte payload
79
+ throw new Error("Buffer too short for NPDU");
80
+ }
81
+ // 1. Parsear el Byte NPCI (Octeto 0)
82
+ // Bits 7: Reservado (0)
83
+ // Bits 6-4: Hop Count
84
+ // Bits 3-0: Length (Longitud del TPDU)
85
+ const npci = buffer.readUInt8(0);
86
+ const hopCount = (npci >> 4) & 0x07;
87
+ const length = npci & 0x0f;
88
+ // Validación de longitud según especificación 03_03_03
89
+ // Nota: 'length' en NPCI indica la longitud del TPDU en bytes.
90
+ if (buffer.length - 1 < length) {
91
+ throw new Error(`NPDU declared length ${length} but buffer has only ${buffer.length - 1} bytes payload`);
92
+ }
93
+ // 2. Extraer el TPDU (Transport Layer PDU)
94
+ // El payload comienza en el índice 1.
95
+ const tpduBuffer = buffer.subarray(1, 1 + length);
96
+ // Llamada estática recursiva a la siguiente capa
97
+ const tpdu = TPDU_1.TPDU.fromBuffer(tpduBuffer);
98
+ // 3. Retornar nueva instancia
99
+ // Nota: AddressType no viene en el NPDU, viene del cEMI. Asumimos GROUP por defecto.
100
+ return new NPDU(tpdu, EnumControlFieldExtended_1.AddressType.GROUP, hopCount);
101
+ }
102
+ }
103
+ exports.NPDU = NPDU;
@@ -0,0 +1,53 @@
1
+ import { ServiceMessage } from "../../../@types/interfaces/ServiceMessage";
2
+ import { TPCI } from "../interfaces/TPCI";
3
+ import { APDU } from "./APDU";
4
+ export declare class TPDU implements ServiceMessage {
5
+ tpci: TPCI;
6
+ apdu: APDU;
7
+ data: Buffer;
8
+ constructor(tpci?: TPCI, apdu?: APDU, data?: Buffer);
9
+ /**
10
+ * Get length all TPDU
11
+ */
12
+ get length(): number;
13
+ get TSDU(): APDU;
14
+ /**
15
+ * Devuelve un buffer con TPCI/APCI + data
16
+ */
17
+ toBuffer(): Buffer;
18
+ describe(): {
19
+ layer: string;
20
+ tpci: {
21
+ buffer: Buffer<ArrayBufferLike>;
22
+ hex: string;
23
+ dataOrControlFlag: string;
24
+ numbered: boolean;
25
+ sequenceNumber: number;
26
+ firstTwoBitsFromAPCI: number;
27
+ TPCIType: string;
28
+ };
29
+ APDU: {
30
+ layer: string;
31
+ tpci: {
32
+ buffer: Buffer<ArrayBufferLike>;
33
+ hex: string;
34
+ dataOrControlFlag: string;
35
+ numbered: boolean;
36
+ sequenceNumber: number;
37
+ firstTwoBitsFromAPCI: number;
38
+ TPCIType: string;
39
+ };
40
+ apci: {
41
+ obj: string;
42
+ command: string;
43
+ value: string;
44
+ };
45
+ data: Buffer<ArrayBufferLike>;
46
+ };
47
+ };
48
+ /**
49
+ * Crea una instancia de TPDU.
50
+ * Estructura: [TPCI + APCI_High] [APCI_Low + Data] [Data...]
51
+ */
52
+ static fromBuffer(buffer: Buffer): TPDU;
53
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TPDU = void 0;
4
+ const KNXHelper_1 = require("../../../utils/KNXHelper");
5
+ const TPCI_1 = require("../interfaces/TPCI");
6
+ const APDU_1 = require("./APDU");
7
+ class TPDU {
8
+ tpci;
9
+ apdu;
10
+ data;
11
+ constructor(tpci = new TPCI_1.TPCI(TPCI_1.TPCIType.T_DATA_GROUP_PDU), apdu = new APDU_1.APDU(), data = Buffer.alloc(0)) {
12
+ this.tpci = tpci;
13
+ this.apdu = apdu;
14
+ this.data = data;
15
+ }
16
+ /**
17
+ * Get length all TPDU
18
+ */
19
+ get length() {
20
+ return this.toBuffer().length;
21
+ }
22
+ get TSDU() {
23
+ return this.apdu;
24
+ }
25
+ /**
26
+ * Devuelve un buffer con TPCI/APCI + data
27
+ */
28
+ toBuffer() {
29
+ if (this.tpci.dataControlFlag) {
30
+ const buffer = Buffer.alloc(1);
31
+ buffer.writeUint8(this.tpci.getValue(), 0);
32
+ return buffer;
33
+ }
34
+ const buffer = Buffer.alloc(1 + this.apdu.length);
35
+ // La clase APDU tiene el tpci y el apci en su buffer
36
+ // para simplificar la envoltura de los octetos por lo tanto
37
+ // se escribe el tpci desde del apdu para evitar problemas
38
+ buffer.writeUint8(this.tpci.getValue(), 0);
39
+ const packNumber = this.apdu.apci.packNumber();
40
+ buffer.writeUInt8(packNumber[1], 1);
41
+ KNXHelper_1.KNXHelper.WriteData(buffer, this.data, 1);
42
+ return buffer;
43
+ }
44
+ describe() {
45
+ return {
46
+ layer: "Transport Layer (TPDU)",
47
+ tpci: this.tpci.describe(),
48
+ APDU: this.apdu.describe(),
49
+ };
50
+ }
51
+ /**
52
+ * Crea una instancia de TPDU.
53
+ * Estructura: [TPCI + APCI_High] [APCI_Low + Data] [Data...]
54
+ */
55
+ static fromBuffer(buffer) {
56
+ if (buffer.length < 1)
57
+ throw new Error("Buffer too short for TPDU");
58
+ // 1. Extraer TPCI (Transport Protocol Control Information)
59
+ // El TPCI ocupa los primeros 6 bits del primer octeto.
60
+ // Máscara: 1111 1100 (0xFC)
61
+ // ** Se evita usar la mascara 0xfc para que el tpci tenga los dos bits más
62
+ // ** significativos del APCI
63
+ const tpciByte = buffer.readUInt8(0);
64
+ const tpciValue = tpciByte;
65
+ const tpci = new TPCI_1.TPCI(tpciValue);
66
+ // 2. Extraer APDU (Application Protocol Data Unit)
67
+ // IMPORTANTE: Pasamos TODO el buffer, porque el APDU necesita los
68
+ // últimos 2 bits del primer byte (que son parte del APCI).
69
+ const apdu = APDU_1.APDU.fromBuffer(buffer);
70
+ return new TPDU(tpci, apdu, apdu.data);
71
+ }
72
+ }
73
+ exports.TPDU = TPDU;
@@ -0,0 +1,61 @@
1
+ import { APCIEnum } from "../../enum/APCIEnum";
2
+ /**
3
+ * Clase para manejar el Application Control Field (APCI) en comunicaciones KNX,
4
+ * específicamente para el modo T_Data_Group.
5
+ *
6
+ * El APCI se compone de 4 o 10 bits
7
+ *
8
+ * @see {@link https://my.knx.org/es/shop/knx-specifications?product_type=knx-specifications} - "Application Layer of the KNX System, Version 02.01.01"
9
+ *
10
+ */
11
+ export declare class APCI {
12
+ private _value;
13
+ constructor(apci?: APCIEnum);
14
+ /**
15
+ * Obtiene el valor crudo del APCI (10 bits).
16
+ */
17
+ get value(): number;
18
+ /**
19
+ * Asigna un nuevo valor crudo al APCI.
20
+ * Se preservan solo en la máscara de 10 bits (0x3FF).
21
+ * @param val Valor numérico (0-1023) que representa el APCI
22
+ */
23
+ set value(val: number);
24
+ /**
25
+ * Obtiene el comando APCI
26
+ */
27
+ get command(): string;
28
+ /**
29
+ * Establece el comando APCI.
30
+ * @param cmd Comando APCI (uno de los valores del enum APCIEnum)
31
+ */
32
+ set command(cmd: APCIEnum);
33
+ /**
34
+ * Retorna una representación hexadecimal del APCI.
35
+ */
36
+ toHex(): string;
37
+ /**
38
+ * Devuelve el APCI como Buffer (2 octeto).
39
+ */
40
+ toBuffer(): Buffer;
41
+ /**
42
+ * Enpaqueta el valor del APCI en una mascara 0000 0011 1111 1111 o 0000 0011 1100 0000 (dependiendo si el valor es de 4 bits o 10 bits)
43
+ * @returns {[number, number]}
44
+ */
45
+ packNumber(): [number, number];
46
+ /**
47
+ * Desenpaqueta el valor real del APCI apartir de dos octetos
48
+ * @param octet1
49
+ * @param octet2
50
+ * @returns {number}
51
+ */
52
+ unpackNumber(octet1: number, octet2: number): number;
53
+ /**
54
+ * Proporciona una descripción legible del APCI.
55
+ */
56
+ describe(): {
57
+ obj: string;
58
+ command: string;
59
+ value: string;
60
+ };
61
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APCI = void 0;
4
+ const APCIEnum_1 = require("../../enum/APCIEnum");
5
+ /**
6
+ * Clase para manejar el Application Control Field (APCI) en comunicaciones KNX,
7
+ * específicamente para el modo T_Data_Group.
8
+ *
9
+ * El APCI se compone de 4 o 10 bits
10
+ *
11
+ * @see {@link https://my.knx.org/es/shop/knx-specifications?product_type=knx-specifications} - "Application Layer of the KNX System, Version 02.01.01"
12
+ *
13
+ */
14
+ class APCI {
15
+ _value;
16
+ constructor(apci = APCIEnum_1.APCIEnum.A_GroupValue_Write_Protocol_Data_Unit) {
17
+ this._value = apci & 0x3ff;
18
+ }
19
+ /**
20
+ * Obtiene el valor crudo del APCI (10 bits).
21
+ */
22
+ get value() {
23
+ return this._value;
24
+ }
25
+ /**
26
+ * Asigna un nuevo valor crudo al APCI.
27
+ * Se preservan solo en la máscara de 10 bits (0x3FF).
28
+ * @param val Valor numérico (0-1023) que representa el APCI
29
+ */
30
+ set value(val) {
31
+ this._value = val & 0x3ff;
32
+ }
33
+ /**
34
+ * Obtiene el comando APCI
35
+ */
36
+ get command() {
37
+ return APCIEnum_1.APCIEnum[this._value & 0x3ff];
38
+ }
39
+ /**
40
+ * Establece el comando APCI.
41
+ * @param cmd Comando APCI (uno de los valores del enum APCIEnum)
42
+ */
43
+ set command(cmd) {
44
+ this._value = cmd;
45
+ }
46
+ /**
47
+ * Retorna una representación hexadecimal del APCI.
48
+ */
49
+ toHex() {
50
+ return `0x${this._value.toString(16).padStart(2, "0").toUpperCase()}`;
51
+ }
52
+ /**
53
+ * Devuelve el APCI como Buffer (2 octeto).
54
+ */
55
+ toBuffer() {
56
+ return Buffer.from([this._value >> 8, this._value & 0xff]);
57
+ }
58
+ /**
59
+ * Enpaqueta el valor del APCI en una mascara 0000 0011 1111 1111 o 0000 0011 1100 0000 (dependiendo si el valor es de 4 bits o 10 bits)
60
+ * @returns {[number, number]}
61
+ */
62
+ packNumber() {
63
+ // bits altos -> posiciones 0 y 1 del primer octeto
64
+ const high = (this.value >> 8) & 0x03; // b9 b8
65
+ const low = this.value & 0xff; // b7..b0
66
+ const octet1 = high; // ya queda en los 2 LSB
67
+ const octet2 = low;
68
+ return [octet1, octet2];
69
+ }
70
+ /**
71
+ * Desenpaqueta el valor real del APCI apartir de dos octetos
72
+ * @param octet1
73
+ * @param octet2
74
+ * @returns {number}
75
+ */
76
+ unpackNumber(octet1, octet2) {
77
+ const high = octet1 & 0x03; // bits en posiciones 0 y 1
78
+ const low = octet2;
79
+ return (high << 8) | low;
80
+ }
81
+ /**
82
+ * Proporciona una descripción legible del APCI.
83
+ */
84
+ describe() {
85
+ return {
86
+ obj: this.constructor.name,
87
+ command: this.command,
88
+ value: `${this.toHex()} (Buffer: ${this.toBuffer().toString("hex").toUpperCase()})`
89
+ };
90
+ }
91
+ }
92
+ exports.APCI = APCI;
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Este enumerable se basa en el esquema numero 3 del titulo "2. TPDU" del documento "Transport Layer of the KNX System, Version 01.02.03"
3
+ * @see {@link https://my.knx.org/es/shop/knx-specifications?product_type=knx-specifications} - "Transport Layer of the KNX System, Version 01.02.03"
4
+ */
5
+ export declare enum TPCIType {
6
+ /** Destination address = 0
7
+ * - The T_Data_Broadcast service shall be applied by the user of Transport Layer, to transmit a TSDU (Transport Service Data Unit) over a connectionless communication mode to all remote partners.
8
+ */
9
+ T_DATA_BROADCAST_PDU = 0,
10
+ /** Destination address ≠ 0
11
+ * - The T_Data_Group service shall be applied by the user of Transport Layer, to transmit a TSDU (Transport Service Data Unit) over a multicast communication mode to one or more remote partners.
12
+ */
13
+ T_DATA_GROUP_PDU = 0,
14
+ /** The T_Data_Tag_Group-service shall be applied by the user of Transport Layer, to transmit a TSDU over a multicast communication mode to one or more remote partners. */
15
+ T_DATA_TAG_GROUP_PDU = 4,
16
+ /** PDU (Protocol Data Unit) individual
17
+ * - The T_Data_Individual service shall be applied by the user of Transport Layer, to transmit a TSDU over a connectionless point-to-point communication mode to exactly one remote partner.
18
+ */
19
+ T_DATA_INDIVIDUAL_PDU = 0,
20
+ /** PDU (Protocol Data Unit) connected
21
+ * - The T_Data_Connected service shall b applied by the user of Transport Layer, to transmit a TSDU over a Transport Layer connection on a connection-oriented communication mode to a remote partner.
22
+ */
23
+ T_DATA_CONNECTED_PDU = 64,
24
+ /** Establish connection
25
+ * - The T_Connect service shall be applied by the user of Transport Layer, to establish a Transport Layer connection on a connection-oriented point-to-point communication mode.
26
+ */
27
+ T_CONNECT_PDU = 128,
28
+ /** End connection
29
+ * - The T_Disconnect service shall be applied by the user of Transport Layer, to release a Transport Layer connection on a connection-oriented point-to-point communication mode.
30
+ */
31
+ T_DISCONNECT_PDU = 129,
32
+ /** Acknowledgement */
33
+ T_ACK_PDU = 194,
34
+ /** Negative Acknowledgement */
35
+ T_NAK_PDU = 195
36
+ }
37
+ /**
38
+ * Clase para manejar el TPCI (Transport Protocol Control Field)
39
+ * en KNX, correspondiente al primer octeto del TPDU (Transport Layer Protocol Data Unit).
40
+ *
41
+ * **Estructura del TPCI (8 bits):**
42
+ * - Bit 7 : Data/Control Flag (1 = Control, 0 = Data)
43
+ * - Bit 6 : Numbered flag (1 = Mensaje numerado, 0 = No numerado)
44
+ * - Bits 5..2 : Número de secuencia (4 bits: 0..15)
45
+ * - Bits 1..0 : Reservados para el Application Layer Control Field (APCI) (se fijan a 0)
46
+ *
47
+ * @see {@link https://my.knx.org/es/shop/knx-specifications?product_type=knx-specifications} - "Transport Layer of the KNX System, Version 01.02.03"
48
+ */
49
+ export declare class TPCI {
50
+ private _buffer;
51
+ constructor(initialValue?: TPCIType);
52
+ /**
53
+ * Devuelve el valor crudo (8 bits) del TPCI/APCI.
54
+ */
55
+ getValue(): number;
56
+ /**
57
+ * Asigna el valor crudo (8 bits) del TPCI.
58
+ */
59
+ setValue(value: number): void;
60
+ /**
61
+ * Data/Control Flag (Bit 7):
62
+ * - true → Bit 7 = 1 (Control)
63
+ * - false → Bit 7 = 0 (Data)
64
+ */
65
+ get dataControlFlag(): boolean;
66
+ set dataControlFlag(flag: boolean);
67
+ /**
68
+ * Numbered Flag (Bit 6):
69
+ * - true → Bit 6 = 1 (Mensaje numerado)
70
+ * - false → Bit 6 = 0 (No numerado)
71
+ */
72
+ get numberedFlag(): boolean;
73
+ set numberedFlag(flag: boolean);
74
+ /**
75
+ * Número de Secuencia (Bits 5 a 2):
76
+ * Valor de 0 a 15.
77
+ */
78
+ get sequenceNumber(): number;
79
+ set sequenceNumber(seq: number);
80
+ /**
81
+ * Bits Reservados para APCI (Bits 1 a 0).
82
+ * En esta clase se asumen en 0
83
+ */
84
+ get first2bitsOfAPCI(): number;
85
+ /**
86
+ * Primeros dos bits para el Application Layer Control Field (APCI)
87
+ */
88
+ set first2bitsOfAPCI(val: number);
89
+ /**
90
+ * Representa el TPCI como un Buffer (1 octeto).
91
+ */
92
+ toBuffer(): Buffer;
93
+ /**
94
+ * Representa el TPCI en hexadecimal.
95
+ */
96
+ toHex(): string;
97
+ /**
98
+ * Describe la codificación actual del objecto KNXTPCI (Transport Layer Control Field)
99
+ */
100
+ describe(): {
101
+ buffer: Buffer<ArrayBufferLike>;
102
+ hex: string;
103
+ dataOrControlFlag: string;
104
+ numbered: boolean;
105
+ sequenceNumber: number;
106
+ firstTwoBitsFromAPCI: number;
107
+ TPCIType: string;
108
+ };
109
+ mapTPCIType(value: TPCIType | number, isForce?: boolean): string;
110
+ }
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TPCI = exports.TPCIType = void 0;
4
+ /**
5
+ * Este enumerable se basa en el esquema numero 3 del titulo "2. TPDU" del documento "Transport Layer of the KNX System, Version 01.02.03"
6
+ * @see {@link https://my.knx.org/es/shop/knx-specifications?product_type=knx-specifications} - "Transport Layer of the KNX System, Version 01.02.03"
7
+ */
8
+ var TPCIType;
9
+ (function (TPCIType) {
10
+ /** Destination address = 0
11
+ * - The T_Data_Broadcast service shall be applied by the user of Transport Layer, to transmit a TSDU (Transport Service Data Unit) over a connectionless communication mode to all remote partners.
12
+ */
13
+ TPCIType[TPCIType["T_DATA_BROADCAST_PDU"] = 0] = "T_DATA_BROADCAST_PDU";
14
+ /** Destination address ≠ 0
15
+ * - The T_Data_Group service shall be applied by the user of Transport Layer, to transmit a TSDU (Transport Service Data Unit) over a multicast communication mode to one or more remote partners.
16
+ */
17
+ TPCIType[TPCIType["T_DATA_GROUP_PDU"] = 0] = "T_DATA_GROUP_PDU";
18
+ /** The T_Data_Tag_Group-service shall be applied by the user of Transport Layer, to transmit a TSDU over a multicast communication mode to one or more remote partners. */
19
+ TPCIType[TPCIType["T_DATA_TAG_GROUP_PDU"] = 4] = "T_DATA_TAG_GROUP_PDU";
20
+ /** PDU (Protocol Data Unit) individual
21
+ * - The T_Data_Individual service shall be applied by the user of Transport Layer, to transmit a TSDU over a connectionless point-to-point communication mode to exactly one remote partner.
22
+ */
23
+ TPCIType[TPCIType["T_DATA_INDIVIDUAL_PDU"] = 0] = "T_DATA_INDIVIDUAL_PDU";
24
+ /** PDU (Protocol Data Unit) connected
25
+ * - The T_Data_Connected service shall b applied by the user of Transport Layer, to transmit a TSDU over a Transport Layer connection on a connection-oriented communication mode to a remote partner.
26
+ */
27
+ TPCIType[TPCIType["T_DATA_CONNECTED_PDU"] = 64] = "T_DATA_CONNECTED_PDU";
28
+ /** Establish connection
29
+ * - The T_Connect service shall be applied by the user of Transport Layer, to establish a Transport Layer connection on a connection-oriented point-to-point communication mode.
30
+ */
31
+ TPCIType[TPCIType["T_CONNECT_PDU"] = 128] = "T_CONNECT_PDU";
32
+ /** End connection
33
+ * - The T_Disconnect service shall be applied by the user of Transport Layer, to release a Transport Layer connection on a connection-oriented point-to-point communication mode.
34
+ */
35
+ TPCIType[TPCIType["T_DISCONNECT_PDU"] = 129] = "T_DISCONNECT_PDU";
36
+ /** Acknowledgement */
37
+ TPCIType[TPCIType["T_ACK_PDU"] = 194] = "T_ACK_PDU";
38
+ /** Negative Acknowledgement */
39
+ TPCIType[TPCIType["T_NAK_PDU"] = 195] = "T_NAK_PDU";
40
+ })(TPCIType || (exports.TPCIType = TPCIType = {}));
41
+ /**
42
+ * Clase para manejar el TPCI (Transport Protocol Control Field)
43
+ * en KNX, correspondiente al primer octeto del TPDU (Transport Layer Protocol Data Unit).
44
+ *
45
+ * **Estructura del TPCI (8 bits):**
46
+ * - Bit 7 : Data/Control Flag (1 = Control, 0 = Data)
47
+ * - Bit 6 : Numbered flag (1 = Mensaje numerado, 0 = No numerado)
48
+ * - Bits 5..2 : Número de secuencia (4 bits: 0..15)
49
+ * - Bits 1..0 : Reservados para el Application Layer Control Field (APCI) (se fijan a 0)
50
+ *
51
+ * @see {@link https://my.knx.org/es/shop/knx-specifications?product_type=knx-specifications} - "Transport Layer of the KNX System, Version 01.02.03"
52
+ */
53
+ class TPCI {
54
+ _buffer;
55
+ constructor(initialValue = 0) {
56
+ this._buffer = Buffer.alloc(1);
57
+ this._buffer.writeUint8(initialValue, 0);
58
+ }
59
+ /**
60
+ * Devuelve el valor crudo (8 bits) del TPCI/APCI.
61
+ */
62
+ getValue() {
63
+ return this._buffer[0];
64
+ }
65
+ /**
66
+ * Asigna el valor crudo (8 bits) del TPCI.
67
+ */
68
+ setValue(value) {
69
+ this._buffer[0] = (value & 0x3f) << 2;
70
+ }
71
+ /**
72
+ * Data/Control Flag (Bit 7):
73
+ * - true → Bit 7 = 1 (Control)
74
+ * - false → Bit 7 = 0 (Data)
75
+ */
76
+ get dataControlFlag() {
77
+ return ((this._buffer[0] >> 7) & 0x01) === 1;
78
+ }
79
+ set dataControlFlag(flag) {
80
+ if (flag) {
81
+ this._buffer[0] |= 0x80; // Fija bit7 en 1
82
+ }
83
+ else {
84
+ this._buffer[0] &= 0x7f; // Limpia bit7
85
+ }
86
+ }
87
+ /**
88
+ * Numbered Flag (Bit 6):
89
+ * - true → Bit 6 = 1 (Mensaje numerado)
90
+ * - false → Bit 6 = 0 (No numerado)
91
+ */
92
+ get numberedFlag() {
93
+ return ((this._buffer[0] >> 6) & 0x01) === 1;
94
+ }
95
+ set numberedFlag(flag) {
96
+ if (flag) {
97
+ this._buffer[0] |= 0x40; // Fija bit6 en 1
98
+ }
99
+ else {
100
+ this._buffer[0] &= 0xbf; // 0xBF = 10111111, limpia bit6
101
+ }
102
+ }
103
+ /**
104
+ * Número de Secuencia (Bits 5 a 2):
105
+ * Valor de 0 a 15.
106
+ */
107
+ get sequenceNumber() {
108
+ return (this._buffer[0] >> 2) & 0x0f;
109
+ }
110
+ set sequenceNumber(seq) {
111
+ if (seq < 0 || seq > 15) {
112
+ throw new Error("El número de secuencia debe estar entre 0 y 15");
113
+ }
114
+ // Limpiar bits 5..2: máscara para bits 5..2 es 0x3C (0011 1100)
115
+ this._buffer[0] &= ~0x3c;
116
+ // Pegar seq en bits 5..2
117
+ this._buffer[0] |= (seq & 0x0f) << 2;
118
+ }
119
+ /**
120
+ * Bits Reservados para APCI (Bits 1 a 0).
121
+ * En esta clase se asumen en 0
122
+ */
123
+ get first2bitsOfAPCI() {
124
+ return this._buffer[0] & 0x03; // Máscara 00000011
125
+ }
126
+ /**
127
+ * Primeros dos bits para el Application Layer Control Field (APCI)
128
+ */
129
+ set first2bitsOfAPCI(val) {
130
+ if (val < 0 || val > 3) {
131
+ throw new Error("Los bits reservados deben estar entre 0 y 3");
132
+ }
133
+ this._buffer[0] |= val & 0x03;
134
+ }
135
+ /**
136
+ * Representa el TPCI como un Buffer (1 octeto).
137
+ */
138
+ toBuffer() {
139
+ return Buffer.from(this._buffer);
140
+ }
141
+ /**
142
+ * Representa el TPCI en hexadecimal.
143
+ */
144
+ toHex() {
145
+ return `0x${this._buffer[0].toString(16).padStart(2, "0").toUpperCase()}`;
146
+ }
147
+ /**
148
+ * Describe la codificación actual del objecto KNXTPCI (Transport Layer Control Field)
149
+ */
150
+ describe() {
151
+ return {
152
+ buffer: this.toBuffer(),
153
+ hex: this.toHex(),
154
+ dataOrControlFlag: this.dataControlFlag ? "Control" : "Data",
155
+ numbered: this.numberedFlag,
156
+ sequenceNumber: this.sequenceNumber,
157
+ firstTwoBitsFromAPCI: this.first2bitsOfAPCI,
158
+ TPCIType: this.mapTPCIType(this.getValue())
159
+ };
160
+ }
161
+ mapTPCIType(value, isForce = false) {
162
+ switch (value) {
163
+ case TPCIType.T_DATA_BROADCAST_PDU:
164
+ return "T_Data_Broadcast_PDU";
165
+ case TPCIType.T_DATA_GROUP_PDU:
166
+ return "T_Data_Group_PDU";
167
+ case TPCIType.T_DATA_CONNECTED_PDU:
168
+ return "T_DATA_CONNECTED_PDU";
169
+ case TPCIType.T_CONNECT_PDU:
170
+ return "T_CONNECT_PDU";
171
+ case TPCIType.T_DISCONNECT_PDU:
172
+ return "T_DISCONNECT_PDU";
173
+ case TPCIType.T_ACK_PDU:
174
+ return "T_ACK_PDU";
175
+ case TPCIType.T_NAK_PDU:
176
+ return "T_NAK_PDU";
177
+ default:
178
+ if (!isForce) {
179
+ /**
180
+ * This is to try to analyze if it is:
181
+ * T_Data_Broadcast-PDU (destination_address = 0)
182
+ * T_Data_Group-PDU (destination_address <> 0)
183
+ * T_Data_Tag_Group-PDU
184
+ * T_Data_Individual-PDU
185
+ * T_Data_Connected-PDU
186
+ */
187
+ const forceAnalysis = value & 0xFC;
188
+ return this.mapTPCIType(forceAnalysis, true);
189
+ }
190
+ else {
191
+ return 'Unknown PDU';
192
+ }
193
+ }
194
+ }
195
+ }
196
+ exports.TPCI = TPCI;