netkitty 0.0.15 → 0.0.17

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 (262) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +1 -1
  2. package/README.md +1 -1
  3. package/assets/NetKitty.png +0 -0
  4. package/package.json +28 -4
  5. package/src/CodecExports.ts +33 -0
  6. package/src/CodecHeaderExports.ts +1 -0
  7. package/src/HelperExports.ts +78 -0
  8. package/src/NetKitty.ts +91 -31
  9. package/src/NetworkExports.ts +12 -0
  10. package/src/PcapExports.ts +16 -0
  11. package/src/lib/codec/Codec.ts +2 -21
  12. package/src/lib/codec/PacketHeaders.ts +13 -0
  13. package/src/lib/codec/headers/ARP.ts +7 -7
  14. package/src/lib/codec/headers/EthernetII.ts +1 -1
  15. package/src/lib/codec/headers/Goose.ts +6 -6
  16. package/src/lib/codec/headers/ICMP.ts +151 -0
  17. package/src/lib/codec/headers/ICMPv6.ts +128 -0
  18. package/src/lib/codec/headers/IEC61850SampledValues.ts +5 -5
  19. package/src/lib/codec/headers/IPv4.ts +8 -8
  20. package/src/lib/codec/headers/IPv6.ts +176 -0
  21. package/src/lib/codec/headers/IPv6HopByHopOptions.ts +532 -0
  22. package/src/lib/codec/headers/RawData.ts +1 -1
  23. package/src/lib/codec/headers/TCP.ts +6 -5
  24. package/src/lib/codec/headers/UDP.ts +3 -3
  25. package/src/lib/codec/headers/VLAN_802dot1Q.ts +2 -2
  26. package/src/lib/helper/HexToBuffer.ts +22 -0
  27. package/src/tests/units/Codec.spec.ts +13 -14
  28. package/dist/NetKitty.d.ts +0 -32
  29. package/dist/NetKitty.d.ts.map +0 -1
  30. package/dist/NetKitty.js +0 -34
  31. package/dist/errors/ActionNotFoundError.d.ts +0 -5
  32. package/dist/errors/ActionNotFoundError.d.ts.map +0 -1
  33. package/dist/errors/ActionNotFoundError.js +0 -12
  34. package/dist/errors/CodecSchemaValidateError.d.ts +0 -5
  35. package/dist/errors/CodecSchemaValidateError.d.ts.map +0 -1
  36. package/dist/errors/CodecSchemaValidateError.js +0 -12
  37. package/dist/errors/DeviceNotFoundError.d.ts +0 -5
  38. package/dist/errors/DeviceNotFoundError.d.ts.map +0 -1
  39. package/dist/errors/DeviceNotFoundError.js +0 -12
  40. package/dist/errors/NoAvailableCodecError.d.ts +0 -5
  41. package/dist/errors/NoAvailableCodecError.d.ts.map +0 -1
  42. package/dist/errors/NoAvailableCodecError.js +0 -12
  43. package/dist/errors/NpcapLoadError.d.ts +0 -5
  44. package/dist/errors/NpcapLoadError.d.ts.map +0 -1
  45. package/dist/errors/NpcapLoadError.js +0 -12
  46. package/dist/errors/SocketDownError.d.ts +0 -5
  47. package/dist/errors/SocketDownError.d.ts.map +0 -1
  48. package/dist/errors/SocketDownError.js +0 -12
  49. package/dist/errors/UnknownPipeMessageTypeError.d.ts +0 -5
  50. package/dist/errors/UnknownPipeMessageTypeError.d.ts.map +0 -1
  51. package/dist/errors/UnknownPipeMessageTypeError.js +0 -12
  52. package/dist/errors/common/ErrorCode.d.ts +0 -31
  53. package/dist/errors/common/ErrorCode.d.ts.map +0 -1
  54. package/dist/errors/common/ErrorCode.js +0 -33
  55. package/dist/lib/GeneratePipeAddress.d.ts +0 -7
  56. package/dist/lib/GeneratePipeAddress.d.ts.map +0 -1
  57. package/dist/lib/GeneratePipeAddress.js +0 -23
  58. package/dist/lib/GetBinding.d.ts +0 -2
  59. package/dist/lib/GetBinding.d.ts.map +0 -1
  60. package/dist/lib/GetBinding.js +0 -6
  61. package/dist/lib/GetCaptureTemporaryDirectory.d.ts +0 -7
  62. package/dist/lib/GetCaptureTemporaryDirectory.d.ts.map +0 -1
  63. package/dist/lib/GetCaptureTemporaryDirectory.js +0 -15
  64. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts +0 -8
  65. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +0 -1
  66. package/dist/lib/GetDeviceCaptureTemporaryFilename.js +0 -18
  67. package/dist/lib/codec/Codec.d.ts +0 -33
  68. package/dist/lib/codec/Codec.d.ts.map +0 -1
  69. package/dist/lib/codec/Codec.js +0 -168
  70. package/dist/lib/codec/abstracts/BaseHeader.d.ts +0 -217
  71. package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +0 -1
  72. package/dist/lib/codec/abstracts/BaseHeader.js +0 -356
  73. package/dist/lib/codec/headers/ARP.d.ts +0 -10
  74. package/dist/lib/codec/headers/ARP.d.ts.map +0 -1
  75. package/dist/lib/codec/headers/ARP.js +0 -224
  76. package/dist/lib/codec/headers/EthernetII.d.ts +0 -10
  77. package/dist/lib/codec/headers/EthernetII.d.ts.map +0 -1
  78. package/dist/lib/codec/headers/EthernetII.js +0 -81
  79. package/dist/lib/codec/headers/Goose.d.ts +0 -13
  80. package/dist/lib/codec/headers/Goose.d.ts.map +0 -1
  81. package/dist/lib/codec/headers/Goose.js +0 -720
  82. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts +0 -13
  83. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts.map +0 -1
  84. package/dist/lib/codec/headers/IEC61850SampledValues.js +0 -370
  85. package/dist/lib/codec/headers/IPv4.d.ts +0 -16
  86. package/dist/lib/codec/headers/IPv4.d.ts.map +0 -1
  87. package/dist/lib/codec/headers/IPv4.js +0 -339
  88. package/dist/lib/codec/headers/RawData.d.ts +0 -11
  89. package/dist/lib/codec/headers/RawData.d.ts.map +0 -1
  90. package/dist/lib/codec/headers/RawData.js +0 -36
  91. package/dist/lib/codec/headers/TCP.d.ts +0 -16
  92. package/dist/lib/codec/headers/TCP.d.ts.map +0 -1
  93. package/dist/lib/codec/headers/TCP.js +0 -898
  94. package/dist/lib/codec/headers/UDP.d.ts +0 -16
  95. package/dist/lib/codec/headers/UDP.d.ts.map +0 -1
  96. package/dist/lib/codec/headers/UDP.js +0 -192
  97. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts +0 -10
  98. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts.map +0 -1
  99. package/dist/lib/codec/headers/VLAN_802dot1Q.js +0 -78
  100. package/dist/lib/codec/lib/BufferToHex.d.ts +0 -2
  101. package/dist/lib/codec/lib/BufferToHex.d.ts.map +0 -1
  102. package/dist/lib/codec/lib/BufferToHex.js +0 -6
  103. package/dist/lib/codec/lib/BufferToIP.d.ts +0 -13
  104. package/dist/lib/codec/lib/BufferToIP.d.ts.map +0 -1
  105. package/dist/lib/codec/lib/BufferToIP.js +0 -21
  106. package/dist/lib/codec/lib/BufferToNumber.d.ts +0 -10
  107. package/dist/lib/codec/lib/BufferToNumber.d.ts.map +0 -1
  108. package/dist/lib/codec/lib/BufferToNumber.js +0 -22
  109. package/dist/lib/codec/lib/FixHexString.d.ts +0 -7
  110. package/dist/lib/codec/lib/FixHexString.d.ts.map +0 -1
  111. package/dist/lib/codec/lib/FixHexString.js +0 -11
  112. package/dist/lib/codec/lib/FlexibleObject.d.ts +0 -28
  113. package/dist/lib/codec/lib/FlexibleObject.d.ts.map +0 -1
  114. package/dist/lib/codec/lib/FlexibleObject.js +0 -102
  115. package/dist/lib/codec/lib/HexToNumber.d.ts +0 -10
  116. package/dist/lib/codec/lib/HexToNumber.d.ts.map +0 -1
  117. package/dist/lib/codec/lib/HexToNumber.js +0 -39
  118. package/dist/lib/codec/lib/IPToBuffer.d.ts +0 -13
  119. package/dist/lib/codec/lib/IPToBuffer.d.ts.map +0 -1
  120. package/dist/lib/codec/lib/IPToBuffer.js +0 -28
  121. package/dist/lib/codec/lib/NumberToBERBuffer.d.ts +0 -9
  122. package/dist/lib/codec/lib/NumberToBERBuffer.d.ts.map +0 -1
  123. package/dist/lib/codec/lib/NumberToBERBuffer.js +0 -20
  124. package/dist/lib/codec/lib/NumberToBERHex.d.ts +0 -9
  125. package/dist/lib/codec/lib/NumberToBERHex.d.ts.map +0 -1
  126. package/dist/lib/codec/lib/NumberToBERHex.js +0 -23
  127. package/dist/lib/codec/lib/NumberToBuffer.d.ts +0 -10
  128. package/dist/lib/codec/lib/NumberToBuffer.d.ts.map +0 -1
  129. package/dist/lib/codec/lib/NumberToBuffer.js +0 -22
  130. package/dist/lib/codec/lib/NumberToHex.d.ts +0 -10
  131. package/dist/lib/codec/lib/NumberToHex.d.ts.map +0 -1
  132. package/dist/lib/codec/lib/NumberToHex.js +0 -26
  133. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts +0 -14
  134. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +0 -1
  135. package/dist/lib/codec/lib/ProcessPacketPostHandlers.js +0 -53
  136. package/dist/lib/codec/lib/SortPostHandlers.d.ts +0 -8
  137. package/dist/lib/codec/lib/SortPostHandlers.d.ts.map +0 -1
  138. package/dist/lib/codec/lib/SortPostHandlers.js +0 -11
  139. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts +0 -11
  140. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts.map +0 -1
  141. package/dist/lib/codec/lib/StringContentEncodingEnum.js +0 -14
  142. package/dist/lib/codec/types/CodecData.d.ts +0 -7
  143. package/dist/lib/codec/types/CodecData.d.ts.map +0 -1
  144. package/dist/lib/codec/types/CodecData.js +0 -2
  145. package/dist/lib/codec/types/CodecDecodeResult.d.ts +0 -11
  146. package/dist/lib/codec/types/CodecDecodeResult.d.ts.map +0 -1
  147. package/dist/lib/codec/types/CodecDecodeResult.js +0 -2
  148. package/dist/lib/codec/types/CodecEncodeInput.d.ts +0 -9
  149. package/dist/lib/codec/types/CodecEncodeInput.d.ts.map +0 -1
  150. package/dist/lib/codec/types/CodecEncodeInput.js +0 -2
  151. package/dist/lib/codec/types/CodecEncodeResult.d.ts +0 -6
  152. package/dist/lib/codec/types/CodecEncodeResult.d.ts.map +0 -1
  153. package/dist/lib/codec/types/CodecEncodeResult.js +0 -2
  154. package/dist/lib/codec/types/CodecErrorInfo.d.ts +0 -6
  155. package/dist/lib/codec/types/CodecErrorInfo.d.ts.map +0 -1
  156. package/dist/lib/codec/types/CodecErrorInfo.js +0 -2
  157. package/dist/lib/codec/types/CodecModule.d.ts +0 -3
  158. package/dist/lib/codec/types/CodecModule.d.ts.map +0 -1
  159. package/dist/lib/codec/types/CodecModule.js +0 -2
  160. package/dist/lib/codec/types/CodecModuleConstructor.d.ts +0 -3
  161. package/dist/lib/codec/types/CodecModuleConstructor.d.ts.map +0 -1
  162. package/dist/lib/codec/types/CodecModuleConstructor.js +0 -2
  163. package/dist/lib/codec/types/CodecSchema.d.ts +0 -7
  164. package/dist/lib/codec/types/CodecSchema.d.ts.map +0 -1
  165. package/dist/lib/codec/types/CodecSchema.js +0 -2
  166. package/dist/lib/codec/types/HeaderTreeNode.d.ts +0 -5
  167. package/dist/lib/codec/types/HeaderTreeNode.d.ts.map +0 -1
  168. package/dist/lib/codec/types/HeaderTreeNode.js +0 -2
  169. package/dist/lib/codec/types/PostHandlerItem.d.ts +0 -5
  170. package/dist/lib/codec/types/PostHandlerItem.d.ts.map +0 -1
  171. package/dist/lib/codec/types/PostHandlerItem.js +0 -2
  172. package/dist/lib/nodepcap/Capture.d.ts +0 -75
  173. package/dist/lib/nodepcap/Capture.d.ts.map +0 -1
  174. package/dist/lib/nodepcap/Capture.js +0 -309
  175. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts +0 -7
  176. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts.map +0 -1
  177. package/dist/lib/nodepcap/GetNetworkInterfaces.js +0 -22
  178. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts +0 -16
  179. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +0 -1
  180. package/dist/lib/nodepcap/interfaces/IBindingCapture.js +0 -2
  181. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +0 -5
  182. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +0 -1
  183. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.js +0 -2
  184. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +0 -19
  185. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +0 -1
  186. package/dist/lib/nodepcap/interfaces/ICaptureOptions.js +0 -2
  187. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts +0 -5
  188. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +0 -1
  189. package/dist/lib/nodepcap/interfaces/INetworkInterface.js +0 -2
  190. package/dist/lib/nodepcap/lib/BindingCapture.d.ts +0 -15
  191. package/dist/lib/nodepcap/lib/BindingCapture.d.ts.map +0 -1
  192. package/dist/lib/nodepcap/lib/BindingCapture.js +0 -35
  193. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts +0 -2
  194. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +0 -1
  195. package/dist/lib/nodepcap/lib/GetNodePcapBinding.js +0 -55
  196. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +0 -3
  197. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +0 -1
  198. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.js +0 -18
  199. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts +0 -2
  200. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts.map +0 -1
  201. package/dist/lib/nodepcap/workers/CaptureWorker.js +0 -25
  202. package/dist/lib/pcap/PCAPGenerator.d.ts +0 -34
  203. package/dist/lib/pcap/PCAPGenerator.d.ts.map +0 -1
  204. package/dist/lib/pcap/PCAPGenerator.js +0 -95
  205. package/dist/lib/pcap/PcapParser.d.ts +0 -27
  206. package/dist/lib/pcap/PcapParser.d.ts.map +0 -1
  207. package/dist/lib/pcap/PcapParser.js +0 -149
  208. package/dist/lib/pcap/PcapReader.d.ts +0 -89
  209. package/dist/lib/pcap/PcapReader.d.ts.map +0 -1
  210. package/dist/lib/pcap/PcapReader.js +0 -209
  211. package/dist/lib/pcap/PcapWriter.d.ts +0 -29
  212. package/dist/lib/pcap/PcapWriter.d.ts.map +0 -1
  213. package/dist/lib/pcap/PcapWriter.js +0 -80
  214. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts +0 -13
  215. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +0 -1
  216. package/dist/lib/pcap/interfaces/IPcapPacketInfo.js +0 -2
  217. package/dist/lib/pipe/PipeClient.d.ts +0 -35
  218. package/dist/lib/pipe/PipeClient.d.ts.map +0 -1
  219. package/dist/lib/pipe/PipeClient.js +0 -71
  220. package/dist/lib/pipe/PipeClientSocket.d.ts +0 -39
  221. package/dist/lib/pipe/PipeClientSocket.d.ts.map +0 -1
  222. package/dist/lib/pipe/PipeClientSocket.js +0 -82
  223. package/dist/lib/pipe/PipeMessage.d.ts +0 -27
  224. package/dist/lib/pipe/PipeMessage.d.ts.map +0 -1
  225. package/dist/lib/pipe/PipeMessage.js +0 -61
  226. package/dist/lib/pipe/PipeMessageHandler.d.ts +0 -16
  227. package/dist/lib/pipe/PipeMessageHandler.d.ts.map +0 -1
  228. package/dist/lib/pipe/PipeMessageHandler.js +0 -95
  229. package/dist/lib/pipe/PipeServer.d.ts +0 -25
  230. package/dist/lib/pipe/PipeServer.d.ts.map +0 -1
  231. package/dist/lib/pipe/PipeServer.js +0 -59
  232. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts +0 -35
  233. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts.map +0 -1
  234. package/dist/lib/schema/ProtocolFieldJSONSchema.js +0 -2
  235. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +0 -3
  236. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +0 -1
  237. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.js +0 -2
  238. package/dist/lib/schema/ProtocolJSONSchema.d.ts +0 -32
  239. package/dist/lib/schema/ProtocolJSONSchema.d.ts.map +0 -1
  240. package/dist/lib/schema/ProtocolJSONSchema.js +0 -2
  241. package/dist/tests/Test.spec.d.ts +0 -2
  242. package/dist/tests/Test.spec.d.ts.map +0 -1
  243. package/dist/tests/Test.spec.js +0 -25
  244. package/dist/tests/units/CaptureTest.spec.d.ts +0 -2
  245. package/dist/tests/units/CaptureTest.spec.d.ts.map +0 -1
  246. package/dist/tests/units/CaptureTest.spec.js +0 -31
  247. package/dist/tests/units/Codec.spec.d.ts +0 -2
  248. package/dist/tests/units/Codec.spec.d.ts.map +0 -1
  249. package/dist/tests/units/Codec.spec.js +0 -76
  250. package/dist/tests/units/ReadPCAP.spec.d.ts +0 -2
  251. package/dist/tests/units/ReadPCAP.spec.d.ts.map +0 -1
  252. package/dist/tests/units/ReadPCAP.spec.js +0 -14
  253. package/src/lib/codec/lib/FixHexString.ts +0 -8
  254. /package/src/lib/{codec/lib → helper}/BufferToHex.ts +0 -0
  255. /package/src/lib/{codec/lib → helper}/BufferToIP.ts +0 -0
  256. /package/src/lib/{codec/lib → helper}/BufferToNumber.ts +0 -0
  257. /package/src/lib/{codec/lib → helper}/HexToNumber.ts +0 -0
  258. /package/src/lib/{codec/lib → helper}/IPToBuffer.ts +0 -0
  259. /package/src/lib/{codec/lib → helper}/NumberToBERBuffer.ts +0 -0
  260. /package/src/lib/{codec/lib → helper}/NumberToBERHex.ts +0 -0
  261. /package/src/lib/{codec/lib → helper}/NumberToBuffer.ts +0 -0
  262. /package/src/lib/{codec/lib → helper}/NumberToHex.ts +0 -0
@@ -1,720 +0,0 @@
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("../lib/HexToNumber");
10
- const NumberToBERHex_1 = require("../lib/NumberToBERHex");
11
- const NumberToHex_1 = require("../lib/NumberToHex");
12
- const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
13
- const NumberToBERBuffer_1 = require("../lib/NumberToBERBuffer");
14
- const BufferToNumber_1 = require("../lib/BufferToNumber");
15
- const NumberToBuffer_1 = require("../lib/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;