netkitty 0.0.17 → 0.0.18

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 (256) hide show
  1. package/dist/CodecExports.d.ts +33 -0
  2. package/dist/CodecExports.d.ts.map +1 -0
  3. package/dist/CodecExports.js +23 -0
  4. package/dist/CodecHeaderExports.d.ts +2 -0
  5. package/dist/CodecHeaderExports.d.ts.map +1 -0
  6. package/dist/CodecHeaderExports.js +17 -0
  7. package/dist/HelperExports.d.ts +11 -0
  8. package/dist/HelperExports.d.ts.map +1 -0
  9. package/dist/HelperExports.js +72 -0
  10. package/dist/NetKitty.d.ts +1 -0
  11. package/dist/NetKitty.d.ts.map +1 -0
  12. package/dist/NetKitty.js +90 -0
  13. package/dist/NetworkExports.d.ts +13 -0
  14. package/dist/NetworkExports.d.ts.map +1 -0
  15. package/dist/NetworkExports.js +13 -0
  16. package/dist/PcapExports.d.ts +17 -0
  17. package/dist/PcapExports.d.ts.map +1 -0
  18. package/dist/PcapExports.js +18 -0
  19. package/dist/errors/ActionNotFoundError.d.ts +5 -0
  20. package/dist/errors/ActionNotFoundError.d.ts.map +1 -0
  21. package/dist/errors/ActionNotFoundError.js +12 -0
  22. package/dist/errors/CodecSchemaValidateError.d.ts +5 -0
  23. package/dist/errors/CodecSchemaValidateError.d.ts.map +1 -0
  24. package/dist/errors/CodecSchemaValidateError.js +12 -0
  25. package/dist/errors/DeviceNotFoundError.d.ts +5 -0
  26. package/dist/errors/DeviceNotFoundError.d.ts.map +1 -0
  27. package/dist/errors/DeviceNotFoundError.js +12 -0
  28. package/dist/errors/NoAvailableCodecError.d.ts +5 -0
  29. package/dist/errors/NoAvailableCodecError.d.ts.map +1 -0
  30. package/dist/errors/NoAvailableCodecError.js +12 -0
  31. package/dist/errors/NpcapLoadError.d.ts +5 -0
  32. package/dist/errors/NpcapLoadError.d.ts.map +1 -0
  33. package/dist/errors/NpcapLoadError.js +12 -0
  34. package/dist/errors/SocketDownError.d.ts +5 -0
  35. package/dist/errors/SocketDownError.d.ts.map +1 -0
  36. package/dist/errors/SocketDownError.js +12 -0
  37. package/dist/errors/UnknownPipeMessageTypeError.d.ts +5 -0
  38. package/dist/errors/UnknownPipeMessageTypeError.d.ts.map +1 -0
  39. package/dist/errors/UnknownPipeMessageTypeError.js +12 -0
  40. package/dist/errors/common/ErrorCode.d.ts +31 -0
  41. package/dist/errors/common/ErrorCode.d.ts.map +1 -0
  42. package/dist/errors/common/ErrorCode.js +33 -0
  43. package/dist/lib/GeneratePipeAddress.d.ts +7 -0
  44. package/dist/lib/GeneratePipeAddress.d.ts.map +1 -0
  45. package/dist/lib/GeneratePipeAddress.js +23 -0
  46. package/dist/lib/GetBinding.d.ts +2 -0
  47. package/dist/lib/GetBinding.d.ts.map +1 -0
  48. package/dist/lib/GetBinding.js +6 -0
  49. package/dist/lib/GetCaptureTemporaryDirectory.d.ts +7 -0
  50. package/dist/lib/GetCaptureTemporaryDirectory.d.ts.map +1 -0
  51. package/dist/lib/GetCaptureTemporaryDirectory.js +15 -0
  52. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts +8 -0
  53. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +1 -0
  54. package/dist/lib/GetDeviceCaptureTemporaryFilename.js +18 -0
  55. package/dist/lib/codec/Codec.d.ts +32 -0
  56. package/dist/lib/codec/Codec.d.ts.map +1 -0
  57. package/dist/lib/codec/Codec.js +183 -0
  58. package/dist/lib/codec/PacketHeaders.d.ts +14 -0
  59. package/dist/lib/codec/PacketHeaders.d.ts.map +1 -0
  60. package/dist/lib/codec/PacketHeaders.js +29 -0
  61. package/dist/lib/codec/abstracts/BaseHeader.d.ts +217 -0
  62. package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +1 -0
  63. package/dist/lib/codec/abstracts/BaseHeader.js +356 -0
  64. package/dist/lib/codec/headers/ARP.d.ts +10 -0
  65. package/dist/lib/codec/headers/ARP.d.ts.map +1 -0
  66. package/dist/lib/codec/headers/ARP.js +224 -0
  67. package/dist/lib/codec/headers/EthernetII.d.ts +10 -0
  68. package/dist/lib/codec/headers/EthernetII.d.ts.map +1 -0
  69. package/dist/lib/codec/headers/EthernetII.js +81 -0
  70. package/dist/lib/codec/headers/Goose.d.ts +13 -0
  71. package/dist/lib/codec/headers/Goose.d.ts.map +1 -0
  72. package/dist/lib/codec/headers/Goose.js +720 -0
  73. package/dist/lib/codec/headers/ICMP.d.ts +15 -0
  74. package/dist/lib/codec/headers/ICMP.d.ts.map +1 -0
  75. package/dist/lib/codec/headers/ICMP.js +147 -0
  76. package/dist/lib/codec/headers/ICMPv6.d.ts +15 -0
  77. package/dist/lib/codec/headers/ICMPv6.d.ts.map +1 -0
  78. package/dist/lib/codec/headers/ICMPv6.js +128 -0
  79. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts +13 -0
  80. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts.map +1 -0
  81. package/dist/lib/codec/headers/IEC61850SampledValues.js +370 -0
  82. package/dist/lib/codec/headers/IPv4.d.ts +16 -0
  83. package/dist/lib/codec/headers/IPv4.d.ts.map +1 -0
  84. package/dist/lib/codec/headers/IPv4.js +339 -0
  85. package/dist/lib/codec/headers/IPv6.d.ts +10 -0
  86. package/dist/lib/codec/headers/IPv6.d.ts.map +1 -0
  87. package/dist/lib/codec/headers/IPv6.js +177 -0
  88. package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts +71 -0
  89. package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts.map +1 -0
  90. package/dist/lib/codec/headers/IPv6HopByHopOptions.js +497 -0
  91. package/dist/lib/codec/headers/RawData.d.ts +11 -0
  92. package/dist/lib/codec/headers/RawData.d.ts.map +1 -0
  93. package/dist/lib/codec/headers/RawData.js +36 -0
  94. package/dist/lib/codec/headers/TCP.d.ts +16 -0
  95. package/dist/lib/codec/headers/TCP.d.ts.map +1 -0
  96. package/dist/lib/codec/headers/TCP.js +899 -0
  97. package/dist/lib/codec/headers/UDP.d.ts +16 -0
  98. package/dist/lib/codec/headers/UDP.d.ts.map +1 -0
  99. package/dist/lib/codec/headers/UDP.js +192 -0
  100. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts +10 -0
  101. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts.map +1 -0
  102. package/dist/lib/codec/headers/VLAN_802dot1Q.js +78 -0
  103. package/dist/lib/codec/lib/FlexibleObject.d.ts +28 -0
  104. package/dist/lib/codec/lib/FlexibleObject.d.ts.map +1 -0
  105. package/dist/lib/codec/lib/FlexibleObject.js +102 -0
  106. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts +14 -0
  107. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +1 -0
  108. package/dist/lib/codec/lib/ProcessPacketPostHandlers.js +53 -0
  109. package/dist/lib/codec/lib/SortPostHandlers.d.ts +8 -0
  110. package/dist/lib/codec/lib/SortPostHandlers.d.ts.map +1 -0
  111. package/dist/lib/codec/lib/SortPostHandlers.js +11 -0
  112. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts +11 -0
  113. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts.map +1 -0
  114. package/dist/lib/codec/lib/StringContentEncodingEnum.js +14 -0
  115. package/dist/lib/codec/types/CodecData.d.ts +7 -0
  116. package/dist/lib/codec/types/CodecData.d.ts.map +1 -0
  117. package/dist/lib/codec/types/CodecData.js +2 -0
  118. package/dist/lib/codec/types/CodecDecodeResult.d.ts +11 -0
  119. package/dist/lib/codec/types/CodecDecodeResult.d.ts.map +1 -0
  120. package/dist/lib/codec/types/CodecDecodeResult.js +2 -0
  121. package/dist/lib/codec/types/CodecEncodeInput.d.ts +9 -0
  122. package/dist/lib/codec/types/CodecEncodeInput.d.ts.map +1 -0
  123. package/dist/lib/codec/types/CodecEncodeInput.js +2 -0
  124. package/dist/lib/codec/types/CodecEncodeResult.d.ts +6 -0
  125. package/dist/lib/codec/types/CodecEncodeResult.d.ts.map +1 -0
  126. package/dist/lib/codec/types/CodecEncodeResult.js +2 -0
  127. package/dist/lib/codec/types/CodecErrorInfo.d.ts +6 -0
  128. package/dist/lib/codec/types/CodecErrorInfo.d.ts.map +1 -0
  129. package/dist/lib/codec/types/CodecErrorInfo.js +2 -0
  130. package/dist/lib/codec/types/CodecModule.d.ts +3 -0
  131. package/dist/lib/codec/types/CodecModule.d.ts.map +1 -0
  132. package/dist/lib/codec/types/CodecModule.js +2 -0
  133. package/dist/lib/codec/types/CodecModuleConstructor.d.ts +3 -0
  134. package/dist/lib/codec/types/CodecModuleConstructor.d.ts.map +1 -0
  135. package/dist/lib/codec/types/CodecModuleConstructor.js +2 -0
  136. package/dist/lib/codec/types/CodecSchema.d.ts +7 -0
  137. package/dist/lib/codec/types/CodecSchema.d.ts.map +1 -0
  138. package/dist/lib/codec/types/CodecSchema.js +2 -0
  139. package/dist/lib/codec/types/HeaderTreeNode.d.ts +5 -0
  140. package/dist/lib/codec/types/HeaderTreeNode.d.ts.map +1 -0
  141. package/dist/lib/codec/types/HeaderTreeNode.js +2 -0
  142. package/dist/lib/codec/types/PostHandlerItem.d.ts +5 -0
  143. package/dist/lib/codec/types/PostHandlerItem.d.ts.map +1 -0
  144. package/dist/lib/codec/types/PostHandlerItem.js +2 -0
  145. package/dist/lib/helper/BufferToHex.d.ts +2 -0
  146. package/dist/lib/helper/BufferToHex.d.ts.map +1 -0
  147. package/dist/lib/helper/BufferToHex.js +6 -0
  148. package/dist/lib/helper/BufferToIP.d.ts +13 -0
  149. package/dist/lib/helper/BufferToIP.d.ts.map +1 -0
  150. package/dist/lib/helper/BufferToIP.js +21 -0
  151. package/dist/lib/helper/BufferToNumber.d.ts +10 -0
  152. package/dist/lib/helper/BufferToNumber.d.ts.map +1 -0
  153. package/dist/lib/helper/BufferToNumber.js +22 -0
  154. package/dist/lib/helper/HexToBuffer.d.ts +8 -0
  155. package/dist/lib/helper/HexToBuffer.d.ts.map +1 -0
  156. package/dist/lib/helper/HexToBuffer.js +27 -0
  157. package/dist/lib/helper/HexToNumber.d.ts +10 -0
  158. package/dist/lib/helper/HexToNumber.d.ts.map +1 -0
  159. package/dist/lib/helper/HexToNumber.js +39 -0
  160. package/dist/lib/helper/IPToBuffer.d.ts +13 -0
  161. package/dist/lib/helper/IPToBuffer.d.ts.map +1 -0
  162. package/dist/lib/helper/IPToBuffer.js +28 -0
  163. package/dist/lib/helper/NumberToBERBuffer.d.ts +9 -0
  164. package/dist/lib/helper/NumberToBERBuffer.d.ts.map +1 -0
  165. package/dist/lib/helper/NumberToBERBuffer.js +20 -0
  166. package/dist/lib/helper/NumberToBERHex.d.ts +9 -0
  167. package/dist/lib/helper/NumberToBERHex.d.ts.map +1 -0
  168. package/dist/lib/helper/NumberToBERHex.js +23 -0
  169. package/dist/lib/helper/NumberToBuffer.d.ts +10 -0
  170. package/dist/lib/helper/NumberToBuffer.d.ts.map +1 -0
  171. package/dist/lib/helper/NumberToBuffer.js +22 -0
  172. package/dist/lib/helper/NumberToHex.d.ts +10 -0
  173. package/dist/lib/helper/NumberToHex.d.ts.map +1 -0
  174. package/dist/lib/helper/NumberToHex.js +26 -0
  175. package/dist/lib/nodepcap/Capture.d.ts +75 -0
  176. package/dist/lib/nodepcap/Capture.d.ts.map +1 -0
  177. package/dist/lib/nodepcap/Capture.js +309 -0
  178. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts +7 -0
  179. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts.map +1 -0
  180. package/dist/lib/nodepcap/GetNetworkInterfaces.js +22 -0
  181. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts +16 -0
  182. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +1 -0
  183. package/dist/lib/nodepcap/interfaces/IBindingCapture.js +2 -0
  184. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +5 -0
  185. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +1 -0
  186. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.js +2 -0
  187. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +19 -0
  188. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +1 -0
  189. package/dist/lib/nodepcap/interfaces/ICaptureOptions.js +2 -0
  190. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts +5 -0
  191. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +1 -0
  192. package/dist/lib/nodepcap/interfaces/INetworkInterface.js +2 -0
  193. package/dist/lib/nodepcap/lib/BindingCapture.d.ts +15 -0
  194. package/dist/lib/nodepcap/lib/BindingCapture.d.ts.map +1 -0
  195. package/dist/lib/nodepcap/lib/BindingCapture.js +35 -0
  196. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts +2 -0
  197. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +1 -0
  198. package/dist/lib/nodepcap/lib/GetNodePcapBinding.js +55 -0
  199. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +3 -0
  200. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +1 -0
  201. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.js +18 -0
  202. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts +2 -0
  203. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts.map +1 -0
  204. package/dist/lib/nodepcap/workers/CaptureWorker.js +25 -0
  205. package/dist/lib/pcap/PCAPGenerator.d.ts +34 -0
  206. package/dist/lib/pcap/PCAPGenerator.d.ts.map +1 -0
  207. package/dist/lib/pcap/PCAPGenerator.js +95 -0
  208. package/dist/lib/pcap/PcapParser.d.ts +27 -0
  209. package/dist/lib/pcap/PcapParser.d.ts.map +1 -0
  210. package/dist/lib/pcap/PcapParser.js +149 -0
  211. package/dist/lib/pcap/PcapReader.d.ts +89 -0
  212. package/dist/lib/pcap/PcapReader.d.ts.map +1 -0
  213. package/dist/lib/pcap/PcapReader.js +209 -0
  214. package/dist/lib/pcap/PcapWriter.d.ts +29 -0
  215. package/dist/lib/pcap/PcapWriter.d.ts.map +1 -0
  216. package/dist/lib/pcap/PcapWriter.js +80 -0
  217. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts +13 -0
  218. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +1 -0
  219. package/dist/lib/pcap/interfaces/IPcapPacketInfo.js +2 -0
  220. package/dist/lib/pipe/PipeClient.d.ts +35 -0
  221. package/dist/lib/pipe/PipeClient.d.ts.map +1 -0
  222. package/dist/lib/pipe/PipeClient.js +71 -0
  223. package/dist/lib/pipe/PipeClientSocket.d.ts +39 -0
  224. package/dist/lib/pipe/PipeClientSocket.d.ts.map +1 -0
  225. package/dist/lib/pipe/PipeClientSocket.js +82 -0
  226. package/dist/lib/pipe/PipeMessage.d.ts +27 -0
  227. package/dist/lib/pipe/PipeMessage.d.ts.map +1 -0
  228. package/dist/lib/pipe/PipeMessage.js +61 -0
  229. package/dist/lib/pipe/PipeMessageHandler.d.ts +16 -0
  230. package/dist/lib/pipe/PipeMessageHandler.d.ts.map +1 -0
  231. package/dist/lib/pipe/PipeMessageHandler.js +95 -0
  232. package/dist/lib/pipe/PipeServer.d.ts +25 -0
  233. package/dist/lib/pipe/PipeServer.d.ts.map +1 -0
  234. package/dist/lib/pipe/PipeServer.js +59 -0
  235. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts +35 -0
  236. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts.map +1 -0
  237. package/dist/lib/schema/ProtocolFieldJSONSchema.js +2 -0
  238. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +3 -0
  239. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +1 -0
  240. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
  241. package/dist/lib/schema/ProtocolJSONSchema.d.ts +32 -0
  242. package/dist/lib/schema/ProtocolJSONSchema.d.ts.map +1 -0
  243. package/dist/lib/schema/ProtocolJSONSchema.js +2 -0
  244. package/dist/tests/Test.spec.d.ts +2 -0
  245. package/dist/tests/Test.spec.d.ts.map +1 -0
  246. package/dist/tests/Test.spec.js +25 -0
  247. package/dist/tests/units/CaptureTest.spec.d.ts +2 -0
  248. package/dist/tests/units/CaptureTest.spec.d.ts.map +1 -0
  249. package/dist/tests/units/CaptureTest.spec.js +31 -0
  250. package/dist/tests/units/Codec.spec.d.ts +2 -0
  251. package/dist/tests/units/Codec.spec.d.ts.map +1 -0
  252. package/dist/tests/units/Codec.spec.js +73 -0
  253. package/dist/tests/units/ReadPCAP.spec.d.ts +2 -0
  254. package/dist/tests/units/ReadPCAP.spec.d.ts.map +1 -0
  255. package/dist/tests/units/ReadPCAP.spec.js +14 -0
  256. package/package.json +1 -1
@@ -0,0 +1,720 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Goose = void 0;
7
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
8
+ const node_tlv_1 = __importDefault(require("node-tlv"));
9
+ const HexToNumber_1 = require("../../helper/HexToNumber");
10
+ const NumberToBERHex_1 = require("../../helper/NumberToBERHex");
11
+ const NumberToHex_1 = require("../../helper/NumberToHex");
12
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
13
+ const NumberToBERBuffer_1 = require("../../helper/NumberToBERBuffer");
14
+ const BufferToNumber_1 = require("../../helper/BufferToNumber");
15
+ const NumberToBuffer_1 = require("../../helper/NumberToBuffer");
16
+ class Goose extends BaseHeader_1.BaseHeader {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.TLVChild = [];
20
+ this.SCHEMA = {
21
+ type: 'object',
22
+ properties: {
23
+ appid: {
24
+ type: 'integer',
25
+ minimum: 0,
26
+ maximum: 65535,
27
+ label: 'APPID',
28
+ decode: () => {
29
+ this.instance.appid.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(0, 2)));
30
+ },
31
+ encode: () => {
32
+ const APPID = this.instance.appid.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
33
+ this.instance.appid.setValue(APPID);
34
+ this.writeBytes(0, (0, NumberToBuffer_1.UInt16ToBuffer)(APPID));
35
+ }
36
+ },
37
+ length: {
38
+ type: 'integer',
39
+ minimum: 0,
40
+ maximum: 65535,
41
+ label: 'Length',
42
+ decode: () => {
43
+ this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
44
+ },
45
+ encode: () => {
46
+ const length = this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
47
+ if (length > 0) {
48
+ this.instance.length.setValue(length);
49
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
50
+ }
51
+ else {
52
+ this.addPostSelfEncodeHandler(() => {
53
+ const finalLength = parseInt(this.instance.length.getValue().toString());
54
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(finalLength));
55
+ });
56
+ }
57
+ }
58
+ },
59
+ reserved1: {
60
+ type: 'object',
61
+ label: 'Reserved1',
62
+ properties: {
63
+ simulated: {
64
+ type: 'boolean',
65
+ label: 'Simulated',
66
+ decode: () => {
67
+ this.instance.reserved1.simulated.setValue(!!this.readBits(4, 2, 0, 1));
68
+ },
69
+ encode: () => {
70
+ const simulated = this.instance.reserved1.simulated.getValue(false);
71
+ this.writeBits(4, 2, 0, 1, simulated ? 1 : 0);
72
+ }
73
+ },
74
+ reserved: {
75
+ type: 'number',
76
+ minimum: 0,
77
+ maximum: 32767,
78
+ label: 'Reserved',
79
+ decode: () => {
80
+ this.instance.reserved1.reserved.setValue(this.readBits(4, 2, 1, 16));
81
+ },
82
+ encode: () => {
83
+ let reserved = this.instance.reserved1.reserved.getValue(0);
84
+ this.writeBits(4, 2, 1, 16, reserved);
85
+ }
86
+ }
87
+ }
88
+ },
89
+ reserved2: {
90
+ type: 'object',
91
+ label: 'Reserved2',
92
+ properties: {
93
+ reserved: {
94
+ type: 'number',
95
+ minimum: 0,
96
+ maximum: 65535,
97
+ label: 'Reserved',
98
+ decode: () => {
99
+ this.instance.reserved2.reserved.setValue(this.readBits(4, 2, 0, 16));
100
+ },
101
+ encode: () => {
102
+ const reserved = this.instance.reserved2.reserved.getValue(0);
103
+ this.writeBits(4, 2, 0, 16, reserved);
104
+ }
105
+ }
106
+ }
107
+ },
108
+ goosePdu: {
109
+ type: 'object',
110
+ label: 'GOOSE PDU',
111
+ decode: () => {
112
+ let redTLVBufferLength = this.instance.length.getValue() - 8;
113
+ while (!this.TLVInstance) {
114
+ try {
115
+ const buffer = this.readBytes(8, redTLVBufferLength, true);
116
+ this.TLVInstance = node_tlv_1.default.parse(buffer);
117
+ this.readBytes(8, this.TLVInstance.length, false); //Update header length
118
+ }
119
+ catch (e) {
120
+ redTLVBufferLength -= 1;
121
+ if (!redTLVBufferLength)
122
+ break;
123
+ }
124
+ }
125
+ this.TLVChild = this.TLVInstance ? this.TLVInstance.getChild() : [];
126
+ },
127
+ encode: () => {
128
+ let buffers = Buffer.from([]);
129
+ this.TLVChild.forEach(item => buffers = Buffer.concat([buffers, item.bTag, item.bLength, item.bValue]));
130
+ const goosePduTLV = new node_tlv_1.default(0x61, buffers);
131
+ const goosePduBuffer = Buffer.concat([goosePduTLV.bTag, goosePduTLV.bLength, goosePduTLV.bValue]);
132
+ this.writeBytes(8, goosePduBuffer);
133
+ /**
134
+ * Update the length only if it is not set
135
+ * Update length(APPID's length + Length's length + Reserved1's length + Reserved2's length + goosePdu's length)
136
+ */
137
+ if (this.instance.length.getValue() > 0)
138
+ return;
139
+ this.instance.length.setValue(2 + 2 + 2 + 2 + goosePduBuffer.length);
140
+ },
141
+ properties: {
142
+ gocbRef: {
143
+ type: 'string',
144
+ maxLength: 129,
145
+ label: 'GoCBReference',
146
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.ASCII,
147
+ decode: () => {
148
+ const gocbRefTLV = this.TLVChild.find(tlv => tlv.getTag('number') === 0x80);
149
+ if (!gocbRefTLV)
150
+ return this.recordError(this.instance.goosePdu.gocbRef.getPath(), 'Not Found');
151
+ this.instance.goosePdu.gocbRef.setValue(gocbRefTLV.getValue('buffer').toString('ascii'));
152
+ },
153
+ encode: () => {
154
+ const gocbRefValue = this.instance.goosePdu.gocbRef.getValue('', (nodePath) => this.recordError(nodePath, 'Not Found'));
155
+ if (!gocbRefValue)
156
+ return;
157
+ let gocbRefBuffer = Buffer.from(gocbRefValue, 'ascii');
158
+ if (gocbRefBuffer.length > 129) {
159
+ this.recordError(this.instance.goosePdu.gocbRef.getPath(), 'This VisibleString shall have a maximum size of 129 octets');
160
+ gocbRefBuffer = gocbRefBuffer.subarray(0, 129);
161
+ }
162
+ this.TLVChild.push(new node_tlv_1.default(0x80, gocbRefBuffer));
163
+ }
164
+ },
165
+ timeAllowedtoLive: {
166
+ type: 'number',
167
+ minimum: 1,
168
+ maximum: 4294967295,
169
+ label: 'TimeAllowedtoLive',
170
+ decode: () => {
171
+ const timeAllowedtoLiveString = this.TLVChild.find(tlv => tlv.getTag('number') === 0x81)?.getValue('hex');
172
+ if (!timeAllowedtoLiveString)
173
+ return this.recordError(this.instance.goosePdu.timeAllowedtoLive.getPath(), 'Not Found');
174
+ this.instance.goosePdu.timeAllowedtoLive.setValue((0, HexToNumber_1.HexToUInt32)(timeAllowedtoLiveString));
175
+ },
176
+ encode: () => {
177
+ let timeAllowedtoLiveValue = this.instance.goosePdu.timeAllowedtoLive.getValue(-1, (nodePath) => this.recordError(nodePath, 'Not Found'));
178
+ if (timeAllowedtoLiveValue === -1)
179
+ return;
180
+ if (timeAllowedtoLiveValue < 1 || timeAllowedtoLiveValue > 4294967295) {
181
+ this.recordError(this.instance.goosePdu.timeAllowedtoLive.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295');
182
+ timeAllowedtoLiveValue = 4294967295;
183
+ }
184
+ const timeAllowedtoLiveTLV = new node_tlv_1.default(0x81, (0, NumberToBERBuffer_1.UInt32ToBERBuffer)(timeAllowedtoLiveValue));
185
+ this.TLVChild.push(timeAllowedtoLiveTLV);
186
+ }
187
+ },
188
+ datSet: {
189
+ type: 'string',
190
+ maxLength: 129,
191
+ label: 'DatSet',
192
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.ASCII,
193
+ decode: () => {
194
+ const datSetTLV = this.TLVChild.find(tlv => tlv.getTag('number') === 0x82);
195
+ if (!datSetTLV)
196
+ return this.recordError(this.instance.goosePdu.datSet.getPath(), 'Not Found');
197
+ this.instance.goosePdu.datSet.setValue(datSetTLV.getValue('buffer').toString('ascii'));
198
+ },
199
+ encode: () => {
200
+ const datSetValue = this.instance.goosePdu.datSet.getValue('', (nodePath) => this.recordError(nodePath, 'Not Found'));
201
+ if (!datSetValue)
202
+ return;
203
+ let datSetBuffer = Buffer.from(datSetValue, 'ascii');
204
+ if (datSetBuffer.length > 129) {
205
+ this.recordError(this.instance.goosePdu.datSet.getPath(), 'This VisibleString shall have a maximum size of 129 octets');
206
+ datSetBuffer = datSetBuffer.subarray(0, 129);
207
+ }
208
+ this.TLVChild.push(new node_tlv_1.default(0x82, datSetBuffer));
209
+ }
210
+ },
211
+ goID: {
212
+ type: 'string',
213
+ maxLength: 65,
214
+ label: 'GoID',
215
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.ASCII,
216
+ decode: () => {
217
+ const goIDTLV = this.TLVChild.find(tlv => tlv.getTag('number') === 0x83);
218
+ if (!goIDTLV)
219
+ return this.recordError(this.instance.goosePdu.goID.getPath(), 'Not Found');
220
+ this.instance.goosePdu.goID.setValue(goIDTLV.getValue('buffer').toString('ascii'));
221
+ },
222
+ encode: () => {
223
+ const goIDValue = this.instance.goosePdu.goID.getValue('', (nodePath) => this.recordError(nodePath, 'Not Found'));
224
+ if (!goIDValue)
225
+ return;
226
+ let goIDBuffer = Buffer.from(goIDValue, 'ascii');
227
+ if (goIDBuffer.length > 65) {
228
+ this.recordError(this.instance.goosePdu.goID.getPath(), 'This VisibleString shall have a maximum size of 65 octets');
229
+ goIDBuffer = goIDBuffer.subarray(0, 65);
230
+ }
231
+ this.TLVChild.push(new node_tlv_1.default(0x83, goIDBuffer));
232
+ }
233
+ },
234
+ t: {
235
+ type: 'string',
236
+ label: 'TimeStamp',
237
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.BIGINT,
238
+ decode: () => {
239
+ const tStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x84)?.getValue('hex');
240
+ if (!tStr)
241
+ return this.recordError(this.instance.goosePdu.t.getPath(), 'Not Found');
242
+ this.instance.goosePdu.t.setValue(BigInt(`0x${tStr}`).toString());
243
+ },
244
+ encode: () => {
245
+ const tStr = this.instance.goosePdu.t.getValue('', (nodePath) => this.recordError(nodePath, 'Not Found'));
246
+ if (!tStr)
247
+ return;
248
+ const tBigIntValue = BigInt(tStr);
249
+ const tTLV = new node_tlv_1.default(0x84, Buffer.from(tBigIntValue.toString(16).padStart(8 * 2, '0'), 'hex'));
250
+ this.TLVChild.push(tTLV);
251
+ }
252
+ },
253
+ stNum: {
254
+ type: 'integer',
255
+ minimum: 1,
256
+ maximum: 4294967295,
257
+ label: 'StNum',
258
+ decode: () => {
259
+ const stNumStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x85)?.getValue('hex');
260
+ if (!stNumStr)
261
+ return this.recordError(this.instance.goosePdu.stNum.getPath(), 'Not Found');
262
+ this.instance.goosePdu.stNum.setValue((0, HexToNumber_1.HexToUInt32)(stNumStr));
263
+ if (this.instance.goosePdu.stNum.getValue() < 1 || this.instance.goosePdu.stNum.getValue() > 4294967295)
264
+ this.recordError(this.instance.goosePdu.stNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295');
265
+ },
266
+ encode: () => {
267
+ let stNumValue = this.instance.goosePdu.stNum.getValue(-1, (nodePath) => this.recordError(nodePath, 'Not Found'));
268
+ if (stNumValue < 0)
269
+ return;
270
+ if (stNumValue < 1 || stNumValue > 4294967295) {
271
+ stNumValue = 4294967295;
272
+ this.recordError(this.instance.goosePdu.stNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295');
273
+ }
274
+ if (stNumValue === undefined)
275
+ return this.recordError(this.instance.goosePdu.stNum.getPath(), 'Not Found');
276
+ const stNumTLV = new node_tlv_1.default(0x85, (0, NumberToBERBuffer_1.UInt32ToBERBuffer)(stNumValue));
277
+ this.TLVChild.push(stNumTLV);
278
+ }
279
+ },
280
+ sqNum: {
281
+ type: 'integer',
282
+ minimum: 0,
283
+ maximum: 4294967295,
284
+ label: 'SqNum',
285
+ decode: () => {
286
+ const sqNumStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x86)?.getValue('hex');
287
+ if (!sqNumStr)
288
+ return this.recordError(this.instance.goosePdu.sqNum.getPath(), 'Not Found');
289
+ this.instance.goosePdu.sqNum.setValue((0, HexToNumber_1.HexToUInt32)(sqNumStr));
290
+ },
291
+ encode: () => {
292
+ let sqNumValue = this.instance.goosePdu.sqNum.getValue(-1, (nodePath) => this.recordError(nodePath, 'Not Found'));
293
+ if (sqNumValue < 0)
294
+ return;
295
+ if (sqNumValue < 0 || sqNumValue > 4294967295) {
296
+ sqNumValue = 4294967295;
297
+ this.recordError(this.instance.goosePdu.sqNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295');
298
+ }
299
+ if (sqNumValue === undefined)
300
+ return this.recordError(this.instance.goosePdu.sqNum.getPath(), 'Not Found');
301
+ const sqNumTLV = new node_tlv_1.default(0x86, (0, NumberToBERBuffer_1.UInt32ToBERBuffer)(sqNumValue));
302
+ this.TLVChild.push(sqNumTLV);
303
+ }
304
+ },
305
+ simulation: {
306
+ type: 'boolean',
307
+ label: 'Simulation',
308
+ decode: () => {
309
+ const simulationStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x87)?.getValue('hex');
310
+ if (!simulationStr)
311
+ return this.recordError(this.instance.goosePdu.simulation.getPath(), 'Not Found');
312
+ const simulationNum = parseInt(simulationStr, 16);
313
+ if (simulationNum > 1)
314
+ this.recordError(this.instance.goosePdu.simulation.getPath(), 'This Boolean shall have a range of TRUE, FALSE');
315
+ this.instance.goosePdu.simulation.setValue(!!simulationNum);
316
+ },
317
+ encode: () => {
318
+ let simulationValue = this.instance.goosePdu.simulation.getValue(undefined, (nodePath) => this.recordError(nodePath, 'Not Found'));
319
+ if (simulationValue === undefined)
320
+ return;
321
+ const simulationNum = simulationValue ? 1 : 0;
322
+ const simulationTLV = new node_tlv_1.default(0x87, Buffer.from(simulationNum.toString(16).padStart(2, '0'), 'hex'));
323
+ this.TLVChild.push(simulationTLV);
324
+ }
325
+ },
326
+ confRev: {
327
+ type: 'integer',
328
+ label: 'ConfRev',
329
+ decode: () => {
330
+ const confRevStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x88)?.getValue('hex');
331
+ if (!confRevStr)
332
+ return this.recordError(this.instance.goosePdu.confRev.getPath(), 'Not Found');
333
+ this.instance.goosePdu.confRev.setValue((0, HexToNumber_1.HexToUInt32)(confRevStr));
334
+ },
335
+ encode: () => {
336
+ let confRevValue = this.instance.goosePdu.confRev.getValue(-1, (nodePath) => this.recordError(nodePath, 'Not Found'));
337
+ if (confRevValue > 4294967295) {
338
+ confRevValue = 4294967295;
339
+ this.recordError(this.instance.goosePdu.confRev.getPath(), 'This INTEGER value shall have a range of 0 to 4294967295');
340
+ }
341
+ if (confRevValue === -1)
342
+ return;
343
+ const confRevTLV = new node_tlv_1.default(0x88, (0, NumberToBERBuffer_1.UInt32ToBERBuffer)(confRevValue));
344
+ this.TLVChild.push(confRevTLV);
345
+ }
346
+ },
347
+ ndsCom: {
348
+ type: 'boolean',
349
+ label: 'NdsCom',
350
+ decode: () => {
351
+ const ndsComStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x89)?.getValue('hex');
352
+ if (!ndsComStr)
353
+ return this.recordError(this.instance.goosePdu.ndsCom.getPath(), 'Not Found');
354
+ const ndsComNum = parseInt(ndsComStr, 16);
355
+ if (ndsComNum > 1)
356
+ this.recordError(this.instance.goosePdu.ndsCom.getPath(), 'This Boolean shall have a range of TRUE, FALSE');
357
+ this.instance.goosePdu.ndsCom.setValue(!!ndsComNum);
358
+ },
359
+ encode: () => {
360
+ let ndsComValue = this.instance.goosePdu.ndsCom.getValue(undefined, (nodePath) => this.recordError(nodePath, 'Not Found'));
361
+ if (ndsComValue === undefined)
362
+ return;
363
+ const ndsComNum = ndsComValue ? 1 : 0;
364
+ const ndsComTLV = new node_tlv_1.default(0x89, Buffer.from(ndsComNum.toString(16).padStart(2, '0'), 'hex'));
365
+ this.TLVChild.push(ndsComTLV);
366
+ }
367
+ },
368
+ numDatSetEntries: {
369
+ type: 'integer',
370
+ label: 'NumDatSetEntries',
371
+ decode: () => {
372
+ const numDatSetEntriesStr = this.TLVChild.find(tlv => tlv.getTag('number') === 0x8A)?.getValue('hex');
373
+ if (!numDatSetEntriesStr)
374
+ return this.recordError(this.instance.goosePdu.numDatSetEntries.getPath(), 'Not Found');
375
+ this.instance.goosePdu.numDatSetEntries.setValue(parseInt(numDatSetEntriesStr, 16));
376
+ },
377
+ encode: () => {
378
+ let numDatSetEntriesValue = this.instance.goosePdu.numDatSetEntries.getValue(undefined, (nodePath) => this.recordError(nodePath, 'Not Found'));
379
+ if (numDatSetEntriesValue === undefined)
380
+ return;
381
+ const numDatSetEntriesTLV = new node_tlv_1.default(0x8A, (0, NumberToBERBuffer_1.UInt32ToBERBuffer)(numDatSetEntriesValue));
382
+ this.TLVChild.push(numDatSetEntriesTLV);
383
+ }
384
+ },
385
+ allData: {
386
+ type: 'array',
387
+ label: 'AllData',
388
+ items: {
389
+ type: 'object',
390
+ label: 'Data',
391
+ properties: {
392
+ dataType: {
393
+ type: 'string',
394
+ label: 'DataType',
395
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
396
+ enum: [
397
+ 'Boolean',
398
+ 'INT8',
399
+ 'INT16',
400
+ 'INT32',
401
+ 'INT64',
402
+ 'INT8U',
403
+ 'INT16U',
404
+ 'INT32U',
405
+ 'FLOAT32',
406
+ 'CODED-ENUM',
407
+ 'OCTET-STRING',
408
+ 'VISIBLE-STRING',
409
+ 'TimeStamp',
410
+ 'Quality'
411
+ ]
412
+ },
413
+ value: {
414
+ type: 'string',
415
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.UTF8,
416
+ label: 'Value'
417
+ }
418
+ }
419
+ },
420
+ /**
421
+ * +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
422
+ * | Data types according to IEC 61850-7-2 | ASN.1 Tag for Data | ASN.1 Length | Comments |
423
+ * +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
424
+ * | Boolean | 0x83 | 1 | 8 Bit set to 0 FALSE; anything else = TRUE |
425
+ * | INT8 | 0x85 | 2 | 8 Bit Big Endian; signed |
426
+ * | INT16 | 0x85 | 3 | 16 Bit Big Endian; signed |
427
+ * | INT32 | 0x85 | 5 | 32 Bit Big Endian; signed |
428
+ * | INT64 | 0x85 | 9 | 64Bit Big Endian; signed |
429
+ * | INT8U | 0x86 | 2 | 8 Bit Big Endian; unsigned |
430
+ * | INT16U | 0x86 | 3 | 16 Bit Big Endian; unsigned |
431
+ * | INT24U | - | - | Not used |
432
+ * | INT32U | 0x86 | 5 | 32 Bit Big Endian; unsigned |
433
+ * | FLOAT32 | 0x87 | 4 | 32 Bit IEEE Floating Point (IEEE 754) |
434
+ * | CODED-ENUM | 0x84 | 2 | Bit-string; depending on CODED ENUM definition – most of the time, can be encoded with 2 bytes (1st Byte = number of unused bit, 2nd Byte = Value) |
435
+ * | OCTET-STRING | 0x89 | 20 | 20 Bytes ASCII Text, Null terminated |
436
+ * | VISIBLE-STRING | 0x8a | 35 | 35 Bytes ASCII Text, Null terminated |
437
+ * | TimeStamp | 0x91 | 8 | 64 Bit TimeStamp as defined in 8.1.3.7 IEC 6 |
438
+ * | Quality | 0x84 | 3 | Bit-string |
439
+ * +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
440
+ */
441
+ decode: () => {
442
+ const allDataTLV = this.TLVChild.find(tlv => tlv.getTag('number') === 0xAB);
443
+ const dataTLVs = allDataTLV ? allDataTLV.getChild() : [];
444
+ const allData = [];
445
+ dataTLVs.forEach((dataTLV) => {
446
+ const length = dataTLV.getLength('number');
447
+ const value = dataTLV.getValue('buffer');
448
+ const dataItem = {
449
+ dataType: '',
450
+ value: ''
451
+ };
452
+ switch (dataTLV.getTag('number')) {
453
+ case 0x83:
454
+ {
455
+ dataItem.dataType = 'Boolean';
456
+ dataItem.value = String(!!parseInt(value.toString('hex'), 16));
457
+ }
458
+ break;
459
+ case 0x84:
460
+ {
461
+ switch (length) {
462
+ case 2:
463
+ {
464
+ dataItem.dataType = 'CODED-ENUM';
465
+ dataItem.value = parseInt(value.toString('hex'), 16).toString();
466
+ }
467
+ break;
468
+ case 3:
469
+ {
470
+ dataItem.dataType = 'Quality';
471
+ dataItem.value = parseInt(value.toString('hex'), 16).toString(2).padStart(24, '0');
472
+ }
473
+ break;
474
+ }
475
+ }
476
+ break;
477
+ case 0x85:
478
+ {
479
+ if (length === 2) {
480
+ {
481
+ dataItem.dataType = 'INT8';
482
+ dataItem.value = (0, HexToNumber_1.HexToInt8)(value.toString('hex')).toString();
483
+ }
484
+ }
485
+ else if (length === 3) {
486
+ {
487
+ dataItem.dataType = 'INT16';
488
+ dataItem.value = (0, HexToNumber_1.HexToInt16)(value.toString('hex')).toString();
489
+ }
490
+ }
491
+ else if (length === 5) {
492
+ {
493
+ dataItem.dataType = 'INT32';
494
+ dataItem.value = (0, HexToNumber_1.HexToInt32)(value.toString('hex')).toString();
495
+ }
496
+ }
497
+ else if (length === 9) {
498
+ {
499
+ dataItem.dataType = 'INT64';
500
+ dataItem.value = (0, HexToNumber_1.HexToInt64)(value.toString('hex')).toString();
501
+ }
502
+ }
503
+ }
504
+ break;
505
+ case 0x86:
506
+ {
507
+ switch (length) {
508
+ case 2:
509
+ {
510
+ dataItem.dataType = 'INT8U';
511
+ dataItem.value = (0, HexToNumber_1.HexToUInt8)(value.toString('hex')).toString();
512
+ }
513
+ break;
514
+ case 3:
515
+ {
516
+ dataItem.dataType = 'INT16U';
517
+ dataItem.value = (0, HexToNumber_1.HexToUInt16)(value.toString('hex')).toString();
518
+ }
519
+ break;
520
+ case 5:
521
+ {
522
+ dataItem.dataType = 'INT32U';
523
+ dataItem.value = (0, HexToNumber_1.HexToUInt32)(value.toString('hex')).toString();
524
+ }
525
+ break;
526
+ }
527
+ }
528
+ break;
529
+ case 0x87:
530
+ {
531
+ dataItem.dataType = 'FLOAT32';
532
+ dataItem.value = (0, HexToNumber_1.HexToFloat32)(value.toString('hex')).toString();
533
+ }
534
+ break;
535
+ case 0x89:
536
+ {
537
+ dataItem.dataType = 'OCTET-STRING';
538
+ dataItem.value = value.toString('ascii');
539
+ }
540
+ break;
541
+ case 0x8a:
542
+ {
543
+ dataItem.dataType = 'VISIBLE-STRING';
544
+ dataItem.value = value.toString('ascii');
545
+ }
546
+ break;
547
+ case 0x91:
548
+ {
549
+ dataItem.dataType = 'TimeStamp';
550
+ dataItem.value = parseInt(value.toString('hex'), 16).toString();
551
+ }
552
+ break;
553
+ }
554
+ if (!dataItem.dataType)
555
+ return;
556
+ allData.push(dataItem);
557
+ });
558
+ if (allData.length)
559
+ this.instance.goosePdu.allData.setValue(allData);
560
+ },
561
+ encode: () => {
562
+ const allData = this.instance.goosePdu.allData.getValue([], (nodePath) => this.recordError(nodePath, 'Not Found'));
563
+ const dataItemTLVs = allData
564
+ .map((dataItem, index) => {
565
+ const errorNodePath = this.instance.goosePdu.allData.getPath(index);
566
+ dataItem.value = dataItem.value.trim();
567
+ switch (dataItem.dataType) {
568
+ case 'Boolean': {
569
+ const availableStringValues = ['FALSE', 'TRUE'];
570
+ const stringValue = dataItem.value.toUpperCase();
571
+ let booleanIntValue = 0;
572
+ if (availableStringValues.includes(stringValue)) {
573
+ booleanIntValue = availableStringValues.indexOf(stringValue);
574
+ }
575
+ else {
576
+ this.recordError(errorNodePath, 'Invalid Boolean value');
577
+ }
578
+ return new node_tlv_1.default(0x83, Buffer.from(booleanIntValue.toString(16).padStart(2, '0'), 'hex'));
579
+ }
580
+ case 'INT8': {
581
+ let intValue = parseInt(dataItem.value);
582
+ if (isNaN(intValue))
583
+ this.recordError(errorNodePath, 'Invalid INT8 value');
584
+ intValue = intValue ? intValue : 0;
585
+ if (intValue < -128 || intValue > 127)
586
+ this.recordError(errorNodePath, 'Invalid INT8 value');
587
+ return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int8ToBERHex)(intValue).padStart(2 * 2, '0'), 'hex'));
588
+ }
589
+ case 'INT16': {
590
+ let intValue = parseInt(dataItem.value);
591
+ if (isNaN(intValue))
592
+ this.recordError(errorNodePath, 'Invalid INT16 value');
593
+ intValue = intValue ? intValue : 0;
594
+ if (intValue < -32768 || intValue > 32767)
595
+ this.recordError(errorNodePath, 'Invalid INT16 value');
596
+ return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int16ToBERHex)(intValue).padStart(3 * 2, '0'), 'hex'));
597
+ }
598
+ case 'INT32': {
599
+ let intValue = parseInt(dataItem.value);
600
+ if (isNaN(intValue))
601
+ this.recordError(errorNodePath, 'Invalid INT32 value');
602
+ intValue = intValue ? intValue : 0;
603
+ if (intValue < -2147483648 || intValue > 2147483647)
604
+ this.recordError(errorNodePath, 'Invalid INT32 value');
605
+ return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int32ToBERHex)(intValue).padStart(5 * 2, '0'), 'hex'));
606
+ }
607
+ case 'INT64': {
608
+ let intValue = BigInt(dataItem.value);
609
+ if (intValue < BigInt('-9223372036854775808') || intValue > BigInt('9223372036854775807'))
610
+ this.recordError(errorNodePath, 'Invalid INT64 value');
611
+ return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int64ToBERHex)(intValue).padStart(9 * 2, '0'), 'hex'));
612
+ }
613
+ case 'INT8U': {
614
+ let uintValue = parseInt(dataItem.value);
615
+ if (isNaN(uintValue))
616
+ this.recordError(errorNodePath, 'Invalid INT8U value');
617
+ uintValue = uintValue ? uintValue : 0;
618
+ if (uintValue < 0 || uintValue > 255)
619
+ this.recordError(errorNodePath, 'Invalid INT8U value');
620
+ return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt8ToBERHex)(uintValue).padStart(2 * 2, '0'), 'hex'));
621
+ }
622
+ case 'INT16U': {
623
+ let uintValue = parseInt(dataItem.value);
624
+ if (isNaN(uintValue))
625
+ this.recordError(errorNodePath, 'Invalid INT16U value');
626
+ uintValue = uintValue ? uintValue : 0;
627
+ if (uintValue < 0 || uintValue > 65535)
628
+ this.recordError(errorNodePath, 'Invalid INT16U value');
629
+ return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt16ToBERHex)(uintValue).padStart(3 * 2, '0'), 'hex'));
630
+ }
631
+ case 'INT32U': {
632
+ let uintValue = parseInt(dataItem.value);
633
+ if (isNaN(uintValue))
634
+ this.recordError(errorNodePath, 'Invalid INT32U value');
635
+ uintValue = uintValue ? uintValue : 0;
636
+ if (uintValue < 0 || uintValue > 4294967295)
637
+ this.recordError(errorNodePath, 'Invalid INT32U value');
638
+ return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt32ToBERHex)(uintValue).padStart(5 * 2, '0'), 'hex'));
639
+ }
640
+ case 'FLOAT32': {
641
+ let float32Value = parseFloat(dataItem.value);
642
+ if (isNaN(float32Value))
643
+ this.recordError(errorNodePath, 'Invalid FLOAT32 value');
644
+ float32Value = float32Value ? float32Value : 0;
645
+ return new node_tlv_1.default(0x86, Buffer.from((0, NumberToHex_1.Float32ToHex)(float32Value).padStart(4 * 2, '0'), 'hex'));
646
+ }
647
+ case 'CODED-ENUM': {
648
+ let codedEnumValue = parseInt(dataItem.value);
649
+ if (isNaN(codedEnumValue))
650
+ this.recordError(errorNodePath, 'Invalid CODED-ENUM value');
651
+ codedEnumValue = codedEnumValue ? codedEnumValue : 0;
652
+ return new node_tlv_1.default(0x84, Buffer.from((0, NumberToBERHex_1.UInt16ToBERHex)(codedEnumValue).padStart(2 * 2, '0'), 'hex'));
653
+ }
654
+ case 'OCTET-STRING': {
655
+ const asciiText = dataItem.value;
656
+ if (!asciiText) {
657
+ this.recordError(errorNodePath, 'Empty OCTET-STRING, ignored');
658
+ return null;
659
+ }
660
+ if (asciiText.length > 20)
661
+ this.recordError(errorNodePath, 'OCTET-STRING too long');
662
+ const hex = Buffer.from(asciiText, 'ascii').toString('hex').padStart(20 * 2);
663
+ return new node_tlv_1.default(0x89, Buffer.from(hex, 'hex').subarray(0, 20));
664
+ }
665
+ case 'VISIBLE-STRING': {
666
+ const asciiText = dataItem.value;
667
+ if (!asciiText) {
668
+ this.recordError(errorNodePath, 'Empty VISIBLE-STRING, ignored');
669
+ return null;
670
+ }
671
+ if (asciiText.length > 35)
672
+ this.recordError(errorNodePath, 'VISIBLE-STRING too long');
673
+ const hex = Buffer.from(asciiText, 'ascii').toString('hex').padStart(35 * 2);
674
+ return new node_tlv_1.default(0x8a, Buffer.from(hex, 'hex').subarray(0, 35));
675
+ }
676
+ case 'TimeStamp': {
677
+ let timestamp = parseInt(dataItem.value);
678
+ if (isNaN(timestamp))
679
+ this.recordError(errorNodePath, 'Invalid TimeStamp value');
680
+ timestamp = timestamp ? timestamp : 0;
681
+ return new node_tlv_1.default(0x91, Buffer.from(timestamp.toString(16).padStart(8 * 2, '0'), 'hex'));
682
+ }
683
+ case 'Quality': {
684
+ const bitString = dataItem.value;
685
+ let intValue = parseInt(bitString, 2);
686
+ if (isNaN(intValue))
687
+ this.recordError(errorNodePath, 'Invalid Quality value');
688
+ intValue = intValue ? intValue : 0;
689
+ return new node_tlv_1.default(0x84, Buffer.from(intValue.toString(16).padStart(3 * 2, '0'), 'hex'));
690
+ }
691
+ default: {
692
+ this.recordError(errorNodePath, 'Invalid dataType, ignored');
693
+ return null;
694
+ }
695
+ }
696
+ })
697
+ .filter((dataItemTLV) => !!dataItemTLV);
698
+ if (dataItemTLVs.length) {
699
+ let dataItemsHex = '';
700
+ dataItemTLVs.forEach(dataItemTLV => dataItemsHex = `${dataItemsHex}${dataItemTLV.toString()}`);
701
+ const allDataTLV = new node_tlv_1.default(0xAB, dataItemsHex);
702
+ this.TLVChild.push(allDataTLV);
703
+ }
704
+ }
705
+ }
706
+ }
707
+ }
708
+ }
709
+ };
710
+ this.id = 'goose';
711
+ this.name = 'IEC61850 GOOSE';
712
+ this.nickname = 'GOOSE';
713
+ }
714
+ match() {
715
+ if (!this.prevCodecModule)
716
+ return false;
717
+ return this.prevCodecModule.instance.etherType.getValue() === (0, NumberToHex_1.UInt16ToHex)(0x88b8);
718
+ }
719
+ }
720
+ exports.Goose = Goose;