netkitty 0.0.34 → 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 (428) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +91 -2
  3. package/README.zh-CN.md +89 -0
  4. package/dist/analysis.d.ts +4 -0
  5. package/dist/{CodecHeaderExports.js → analysis.js} +4 -1
  6. package/dist/capture.d.ts +5 -0
  7. package/dist/capture.js +21 -0
  8. package/dist/codec.d.ts +5 -0
  9. package/dist/codec.js +21 -0
  10. package/dist/iface.d.ts +4 -0
  11. package/dist/iface.js +20 -0
  12. package/dist/pcap.d.ts +10 -0
  13. package/dist/pcap.js +27 -0
  14. package/dist/replay.d.ts +5 -0
  15. package/dist/replay.js +21 -0
  16. package/package.json +65 -57
  17. package/.eslintrc.json +0 -53
  18. package/.idea/codeStyles/Project.xml +0 -18
  19. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  20. package/.idea/inspectionProfiles/Project_Default.xml +0 -11
  21. package/.idea/modules.xml +0 -8
  22. package/.idea/netkitty.iml +0 -12
  23. package/.idea/vcs.xml +0 -6
  24. package/assets/NetKitty.png +0 -0
  25. package/binding.gyp +0 -5
  26. package/cpp/nodepcap/deps/include/Packet32.h +0 -429
  27. package/cpp/nodepcap/deps/include/pcap/bluetooth.h +0 -56
  28. package/cpp/nodepcap/deps/include/pcap/bpf.h +0 -292
  29. package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +0 -56
  30. package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +0 -163
  31. package/cpp/nodepcap/deps/include/pcap/dlt.h +0 -1514
  32. package/cpp/nodepcap/deps/include/pcap/funcattrs.h +0 -325
  33. package/cpp/nodepcap/deps/include/pcap/ipnet.h +0 -43
  34. package/cpp/nodepcap/deps/include/pcap/namedb.h +0 -84
  35. package/cpp/nodepcap/deps/include/pcap/nflog.h +0 -94
  36. package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +0 -101
  37. package/cpp/nodepcap/deps/include/pcap/pcap.h +0 -1219
  38. package/cpp/nodepcap/deps/include/pcap/sll.h +0 -149
  39. package/cpp/nodepcap/deps/include/pcap/socket.h +0 -84
  40. package/cpp/nodepcap/deps/include/pcap/usb.h +0 -143
  41. package/cpp/nodepcap/deps/include/pcap/vlan.h +0 -46
  42. package/cpp/nodepcap/deps/include/pcap-bpf.h +0 -45
  43. package/cpp/nodepcap/deps/include/pcap-namedb.h +0 -40
  44. package/cpp/nodepcap/deps/include/pcap.h +0 -43
  45. package/cpp/nodepcap/deps/lib/ARM64/Packet.lib +0 -0
  46. package/cpp/nodepcap/deps/lib/Packet.lib +0 -0
  47. package/cpp/nodepcap/deps/lib/wpcap.lib +0 -0
  48. package/cpp/nodepcap/deps/lib/x64/Packet.lib +0 -0
  49. package/cpp/nodepcap/deps/lib/x64/wpcap.lib +0 -0
  50. package/cpp/nodepcap/nodepcap.gypi +0 -104
  51. package/cpp/nodepcap/src/binding.cc +0 -14
  52. package/cpp/nodepcap/src/capture.cc +0 -400
  53. package/cpp/nodepcap/src/capture.h +0 -53
  54. package/cpp/nodepcap/src/utils.cc +0 -218
  55. package/cpp/nodepcap/src/utils.h +0 -13
  56. package/dist/CodecExports.d.ts +0 -34
  57. package/dist/CodecExports.d.ts.map +0 -1
  58. package/dist/CodecExports.js +0 -23
  59. package/dist/CodecHeaderExports.d.ts +0 -2
  60. package/dist/CodecHeaderExports.d.ts.map +0 -1
  61. package/dist/HelperExports.d.ts +0 -11
  62. package/dist/HelperExports.d.ts.map +0 -1
  63. package/dist/HelperExports.js +0 -72
  64. package/dist/NetworkExports.d.ts +0 -13
  65. package/dist/NetworkExports.d.ts.map +0 -1
  66. package/dist/NetworkExports.js +0 -13
  67. package/dist/PcapExports.d.ts +0 -30
  68. package/dist/PcapExports.d.ts.map +0 -1
  69. package/dist/PcapExports.js +0 -33
  70. package/dist/errors/ActionNotFoundError.d.ts +0 -5
  71. package/dist/errors/ActionNotFoundError.d.ts.map +0 -1
  72. package/dist/errors/ActionNotFoundError.js +0 -12
  73. package/dist/errors/CodecSchemaValidateError.d.ts +0 -5
  74. package/dist/errors/CodecSchemaValidateError.d.ts.map +0 -1
  75. package/dist/errors/CodecSchemaValidateError.js +0 -12
  76. package/dist/errors/DeviceNotFoundError.d.ts +0 -5
  77. package/dist/errors/DeviceNotFoundError.d.ts.map +0 -1
  78. package/dist/errors/DeviceNotFoundError.js +0 -12
  79. package/dist/errors/NoAvailableCodecError.d.ts +0 -5
  80. package/dist/errors/NoAvailableCodecError.d.ts.map +0 -1
  81. package/dist/errors/NoAvailableCodecError.js +0 -12
  82. package/dist/errors/NpcapLoadError.d.ts +0 -5
  83. package/dist/errors/NpcapLoadError.d.ts.map +0 -1
  84. package/dist/errors/NpcapLoadError.js +0 -12
  85. package/dist/errors/SocketDownError.d.ts +0 -5
  86. package/dist/errors/SocketDownError.d.ts.map +0 -1
  87. package/dist/errors/SocketDownError.js +0 -12
  88. package/dist/errors/UnknownPipeMessageTypeError.d.ts +0 -5
  89. package/dist/errors/UnknownPipeMessageTypeError.d.ts.map +0 -1
  90. package/dist/errors/UnknownPipeMessageTypeError.js +0 -12
  91. package/dist/errors/common/ErrorCode.d.ts +0 -31
  92. package/dist/errors/common/ErrorCode.d.ts.map +0 -1
  93. package/dist/errors/common/ErrorCode.js +0 -33
  94. package/dist/lib/GeneratePipeAddress.d.ts +0 -7
  95. package/dist/lib/GeneratePipeAddress.d.ts.map +0 -1
  96. package/dist/lib/GeneratePipeAddress.js +0 -23
  97. package/dist/lib/GetBinding.d.ts +0 -2
  98. package/dist/lib/GetBinding.d.ts.map +0 -1
  99. package/dist/lib/GetBinding.js +0 -6
  100. package/dist/lib/GetCaptureTemporaryDirectory.d.ts +0 -7
  101. package/dist/lib/GetCaptureTemporaryDirectory.d.ts.map +0 -1
  102. package/dist/lib/GetCaptureTemporaryDirectory.js +0 -15
  103. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts +0 -8
  104. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +0 -1
  105. package/dist/lib/GetDeviceCaptureTemporaryFilename.js +0 -18
  106. package/dist/lib/codec/Codec.d.ts +0 -32
  107. package/dist/lib/codec/Codec.d.ts.map +0 -1
  108. package/dist/lib/codec/Codec.js +0 -183
  109. package/dist/lib/codec/PacketHeaders.d.ts +0 -22
  110. package/dist/lib/codec/PacketHeaders.d.ts.map +0 -1
  111. package/dist/lib/codec/PacketHeaders.js +0 -47
  112. package/dist/lib/codec/abstracts/BaseHeader.d.ts +0 -217
  113. package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +0 -1
  114. package/dist/lib/codec/abstracts/BaseHeader.js +0 -356
  115. package/dist/lib/codec/headers/ARP.d.ts +0 -10
  116. package/dist/lib/codec/headers/ARP.d.ts.map +0 -1
  117. package/dist/lib/codec/headers/ARP.js +0 -224
  118. package/dist/lib/codec/headers/EthernetII.d.ts +0 -10
  119. package/dist/lib/codec/headers/EthernetII.d.ts.map +0 -1
  120. package/dist/lib/codec/headers/EthernetII.js +0 -81
  121. package/dist/lib/codec/headers/Goose.d.ts +0 -104
  122. package/dist/lib/codec/headers/Goose.d.ts.map +0 -1
  123. package/dist/lib/codec/headers/Goose.js +0 -975
  124. package/dist/lib/codec/headers/ICMP.d.ts +0 -15
  125. package/dist/lib/codec/headers/ICMP.d.ts.map +0 -1
  126. package/dist/lib/codec/headers/ICMP.js +0 -147
  127. package/dist/lib/codec/headers/ICMPv6.d.ts +0 -15
  128. package/dist/lib/codec/headers/ICMPv6.d.ts.map +0 -1
  129. package/dist/lib/codec/headers/ICMPv6.js +0 -128
  130. package/dist/lib/codec/headers/IEC104_I_Frame.d.ts +0 -10
  131. package/dist/lib/codec/headers/IEC104_I_Frame.d.ts.map +0 -1
  132. package/dist/lib/codec/headers/IEC104_I_Frame.js +0 -6411
  133. package/dist/lib/codec/headers/IEC104_S_Frame.d.ts +0 -10
  134. package/dist/lib/codec/headers/IEC104_S_Frame.d.ts.map +0 -1
  135. package/dist/lib/codec/headers/IEC104_S_Frame.js +0 -105
  136. package/dist/lib/codec/headers/IEC104_U_Frame.d.ts +0 -10
  137. package/dist/lib/codec/headers/IEC104_U_Frame.d.ts.map +0 -1
  138. package/dist/lib/codec/headers/IEC104_U_Frame.js +0 -155
  139. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts +0 -13
  140. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts.map +0 -1
  141. package/dist/lib/codec/headers/IEC61850SampledValues.js +0 -370
  142. package/dist/lib/codec/headers/IPv4.d.ts +0 -16
  143. package/dist/lib/codec/headers/IPv4.d.ts.map +0 -1
  144. package/dist/lib/codec/headers/IPv4.js +0 -339
  145. package/dist/lib/codec/headers/IPv6.d.ts +0 -10
  146. package/dist/lib/codec/headers/IPv6.d.ts.map +0 -1
  147. package/dist/lib/codec/headers/IPv6.js +0 -177
  148. package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts +0 -71
  149. package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts.map +0 -1
  150. package/dist/lib/codec/headers/IPv6HopByHopOptions.js +0 -497
  151. package/dist/lib/codec/headers/RawData.d.ts +0 -11
  152. package/dist/lib/codec/headers/RawData.d.ts.map +0 -1
  153. package/dist/lib/codec/headers/RawData.js +0 -36
  154. package/dist/lib/codec/headers/TCP.d.ts +0 -16
  155. package/dist/lib/codec/headers/TCP.d.ts.map +0 -1
  156. package/dist/lib/codec/headers/TCP.js +0 -899
  157. package/dist/lib/codec/headers/TLS_Alert.d.ts +0 -10
  158. package/dist/lib/codec/headers/TLS_Alert.d.ts.map +0 -1
  159. package/dist/lib/codec/headers/TLS_Alert.js +0 -624
  160. package/dist/lib/codec/headers/TLS_ApplicationData.d.ts +0 -10
  161. package/dist/lib/codec/headers/TLS_ApplicationData.d.ts.map +0 -1
  162. package/dist/lib/codec/headers/TLS_ApplicationData.js +0 -155
  163. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts +0 -10
  164. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts.map +0 -1
  165. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.js +0 -154
  166. package/dist/lib/codec/headers/TLS_Handshake.d.ts +0 -10
  167. package/dist/lib/codec/headers/TLS_Handshake.d.ts.map +0 -1
  168. package/dist/lib/codec/headers/TLS_Handshake.js +0 -339
  169. package/dist/lib/codec/headers/TLS_Heartbeat.d.ts +0 -10
  170. package/dist/lib/codec/headers/TLS_Heartbeat.d.ts.map +0 -1
  171. package/dist/lib/codec/headers/TLS_Heartbeat.js +0 -206
  172. package/dist/lib/codec/headers/UDP.d.ts +0 -16
  173. package/dist/lib/codec/headers/UDP.d.ts.map +0 -1
  174. package/dist/lib/codec/headers/UDP.js +0 -192
  175. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts +0 -10
  176. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts.map +0 -1
  177. package/dist/lib/codec/headers/VLAN_802dot1Q.js +0 -82
  178. package/dist/lib/codec/lib/FlexibleObject.d.ts +0 -28
  179. package/dist/lib/codec/lib/FlexibleObject.d.ts.map +0 -1
  180. package/dist/lib/codec/lib/FlexibleObject.js +0 -102
  181. package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts +0 -7
  182. package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts.map +0 -1
  183. package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.js +0 -16
  184. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts +0 -14
  185. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +0 -1
  186. package/dist/lib/codec/lib/ProcessPacketPostHandlers.js +0 -53
  187. package/dist/lib/codec/lib/SortPostHandlers.d.ts +0 -8
  188. package/dist/lib/codec/lib/SortPostHandlers.d.ts.map +0 -1
  189. package/dist/lib/codec/lib/SortPostHandlers.js +0 -11
  190. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts +0 -11
  191. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts.map +0 -1
  192. package/dist/lib/codec/lib/StringContentEncodingEnum.js +0 -14
  193. package/dist/lib/codec/types/CodecData.d.ts +0 -7
  194. package/dist/lib/codec/types/CodecData.d.ts.map +0 -1
  195. package/dist/lib/codec/types/CodecData.js +0 -2
  196. package/dist/lib/codec/types/CodecDecodeResult.d.ts +0 -11
  197. package/dist/lib/codec/types/CodecDecodeResult.d.ts.map +0 -1
  198. package/dist/lib/codec/types/CodecDecodeResult.js +0 -2
  199. package/dist/lib/codec/types/CodecEncodeInput.d.ts +0 -9
  200. package/dist/lib/codec/types/CodecEncodeInput.d.ts.map +0 -1
  201. package/dist/lib/codec/types/CodecEncodeInput.js +0 -2
  202. package/dist/lib/codec/types/CodecEncodeResult.d.ts +0 -6
  203. package/dist/lib/codec/types/CodecEncodeResult.d.ts.map +0 -1
  204. package/dist/lib/codec/types/CodecEncodeResult.js +0 -2
  205. package/dist/lib/codec/types/CodecErrorInfo.d.ts +0 -6
  206. package/dist/lib/codec/types/CodecErrorInfo.d.ts.map +0 -1
  207. package/dist/lib/codec/types/CodecErrorInfo.js +0 -2
  208. package/dist/lib/codec/types/CodecModule.d.ts +0 -3
  209. package/dist/lib/codec/types/CodecModule.d.ts.map +0 -1
  210. package/dist/lib/codec/types/CodecModule.js +0 -2
  211. package/dist/lib/codec/types/CodecModuleConstructor.d.ts +0 -3
  212. package/dist/lib/codec/types/CodecModuleConstructor.d.ts.map +0 -1
  213. package/dist/lib/codec/types/CodecModuleConstructor.js +0 -2
  214. package/dist/lib/codec/types/CodecSchema.d.ts +0 -7
  215. package/dist/lib/codec/types/CodecSchema.d.ts.map +0 -1
  216. package/dist/lib/codec/types/CodecSchema.js +0 -2
  217. package/dist/lib/codec/types/HeaderTreeNode.d.ts +0 -5
  218. package/dist/lib/codec/types/HeaderTreeNode.d.ts.map +0 -1
  219. package/dist/lib/codec/types/HeaderTreeNode.js +0 -2
  220. package/dist/lib/codec/types/PostHandlerItem.d.ts +0 -5
  221. package/dist/lib/codec/types/PostHandlerItem.d.ts.map +0 -1
  222. package/dist/lib/codec/types/PostHandlerItem.js +0 -2
  223. package/dist/lib/helper/BufferToHex.d.ts +0 -2
  224. package/dist/lib/helper/BufferToHex.d.ts.map +0 -1
  225. package/dist/lib/helper/BufferToHex.js +0 -6
  226. package/dist/lib/helper/BufferToIP.d.ts +0 -13
  227. package/dist/lib/helper/BufferToIP.d.ts.map +0 -1
  228. package/dist/lib/helper/BufferToIP.js +0 -21
  229. package/dist/lib/helper/BufferToNumber.d.ts +0 -10
  230. package/dist/lib/helper/BufferToNumber.d.ts.map +0 -1
  231. package/dist/lib/helper/BufferToNumber.js +0 -22
  232. package/dist/lib/helper/HexToBuffer.d.ts +0 -8
  233. package/dist/lib/helper/HexToBuffer.d.ts.map +0 -1
  234. package/dist/lib/helper/HexToBuffer.js +0 -27
  235. package/dist/lib/helper/HexToNumber.d.ts +0 -10
  236. package/dist/lib/helper/HexToNumber.d.ts.map +0 -1
  237. package/dist/lib/helper/HexToNumber.js +0 -39
  238. package/dist/lib/helper/IPToBuffer.d.ts +0 -13
  239. package/dist/lib/helper/IPToBuffer.d.ts.map +0 -1
  240. package/dist/lib/helper/IPToBuffer.js +0 -28
  241. package/dist/lib/helper/NumberToBERBuffer.d.ts +0 -10
  242. package/dist/lib/helper/NumberToBERBuffer.d.ts.map +0 -1
  243. package/dist/lib/helper/NumberToBERBuffer.js +0 -22
  244. package/dist/lib/helper/NumberToBERHex.d.ts +0 -10
  245. package/dist/lib/helper/NumberToBERHex.d.ts.map +0 -1
  246. package/dist/lib/helper/NumberToBERHex.js +0 -27
  247. package/dist/lib/helper/NumberToBuffer.d.ts +0 -10
  248. package/dist/lib/helper/NumberToBuffer.d.ts.map +0 -1
  249. package/dist/lib/helper/NumberToBuffer.js +0 -22
  250. package/dist/lib/helper/NumberToHex.d.ts +0 -10
  251. package/dist/lib/helper/NumberToHex.d.ts.map +0 -1
  252. package/dist/lib/helper/NumberToHex.js +0 -26
  253. package/dist/lib/nodepcap/Capture.d.ts +0 -81
  254. package/dist/lib/nodepcap/Capture.d.ts.map +0 -1
  255. package/dist/lib/nodepcap/Capture.js +0 -323
  256. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts +0 -7
  257. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts.map +0 -1
  258. package/dist/lib/nodepcap/GetNetworkInterfaces.js +0 -22
  259. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts +0 -16
  260. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +0 -1
  261. package/dist/lib/nodepcap/interfaces/IBindingCapture.js +0 -2
  262. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +0 -5
  263. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +0 -1
  264. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.js +0 -2
  265. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +0 -23
  266. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +0 -1
  267. package/dist/lib/nodepcap/interfaces/ICaptureOptions.js +0 -2
  268. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts +0 -5
  269. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +0 -1
  270. package/dist/lib/nodepcap/interfaces/INetworkInterface.js +0 -2
  271. package/dist/lib/nodepcap/lib/BindingCapture.d.ts +0 -15
  272. package/dist/lib/nodepcap/lib/BindingCapture.d.ts.map +0 -1
  273. package/dist/lib/nodepcap/lib/BindingCapture.js +0 -35
  274. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts +0 -2
  275. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +0 -1
  276. package/dist/lib/nodepcap/lib/GetNodePcapBinding.js +0 -55
  277. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +0 -3
  278. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +0 -1
  279. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.js +0 -18
  280. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts +0 -2
  281. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts.map +0 -1
  282. package/dist/lib/nodepcap/workers/CaptureWorker.js +0 -25
  283. package/dist/lib/pcap/PCAPGenerator.d.ts +0 -34
  284. package/dist/lib/pcap/PCAPGenerator.d.ts.map +0 -1
  285. package/dist/lib/pcap/PCAPGenerator.js +0 -101
  286. package/dist/lib/pcap/PcapParser.d.ts +0 -27
  287. package/dist/lib/pcap/PcapParser.d.ts.map +0 -1
  288. package/dist/lib/pcap/PcapParser.js +0 -149
  289. package/dist/lib/pcap/PcapReader.d.ts +0 -112
  290. package/dist/lib/pcap/PcapReader.d.ts.map +0 -1
  291. package/dist/lib/pcap/PcapReader.js +0 -263
  292. package/dist/lib/pcap/PcapWriter.d.ts +0 -29
  293. package/dist/lib/pcap/PcapWriter.d.ts.map +0 -1
  294. package/dist/lib/pcap/PcapWriter.js +0 -86
  295. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts +0 -13
  296. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +0 -1
  297. package/dist/lib/pcap/interfaces/IPcapPacketInfo.js +0 -2
  298. package/dist/lib/pipe/PipeClient.d.ts +0 -35
  299. package/dist/lib/pipe/PipeClient.d.ts.map +0 -1
  300. package/dist/lib/pipe/PipeClient.js +0 -71
  301. package/dist/lib/pipe/PipeClientSocket.d.ts +0 -39
  302. package/dist/lib/pipe/PipeClientSocket.d.ts.map +0 -1
  303. package/dist/lib/pipe/PipeClientSocket.js +0 -82
  304. package/dist/lib/pipe/PipeMessage.d.ts +0 -27
  305. package/dist/lib/pipe/PipeMessage.d.ts.map +0 -1
  306. package/dist/lib/pipe/PipeMessage.js +0 -61
  307. package/dist/lib/pipe/PipeMessageHandler.d.ts +0 -16
  308. package/dist/lib/pipe/PipeMessageHandler.d.ts.map +0 -1
  309. package/dist/lib/pipe/PipeMessageHandler.js +0 -95
  310. package/dist/lib/pipe/PipeServer.d.ts +0 -25
  311. package/dist/lib/pipe/PipeServer.d.ts.map +0 -1
  312. package/dist/lib/pipe/PipeServer.js +0 -59
  313. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts +0 -35
  314. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts.map +0 -1
  315. package/dist/lib/schema/ProtocolFieldJSONSchema.js +0 -2
  316. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +0 -3
  317. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +0 -1
  318. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.js +0 -2
  319. package/dist/lib/schema/ProtocolJSONSchema.d.ts +0 -32
  320. package/dist/lib/schema/ProtocolJSONSchema.d.ts.map +0 -1
  321. package/dist/lib/schema/ProtocolJSONSchema.js +0 -2
  322. package/dist/tests/Test.spec.d.ts +0 -2
  323. package/dist/tests/Test.spec.d.ts.map +0 -1
  324. package/dist/tests/Test.spec.js +0 -25
  325. package/dist/tests/units/CaptureTest.spec.d.ts +0 -2
  326. package/dist/tests/units/CaptureTest.spec.d.ts.map +0 -1
  327. package/dist/tests/units/CaptureTest.spec.js +0 -32
  328. package/dist/tests/units/Codec.spec.d.ts +0 -2
  329. package/dist/tests/units/Codec.spec.d.ts.map +0 -1
  330. package/dist/tests/units/Codec.spec.js +0 -86
  331. package/dist/tests/units/ReadPCAP.spec.d.ts +0 -2
  332. package/dist/tests/units/ReadPCAP.spec.d.ts.map +0 -1
  333. package/dist/tests/units/ReadPCAP.spec.js +0 -14
  334. package/src/CodecExports.ts +0 -33
  335. package/src/CodecHeaderExports.ts +0 -1
  336. package/src/HelperExports.ts +0 -78
  337. package/src/NetworkExports.ts +0 -12
  338. package/src/PcapExports.ts +0 -32
  339. package/src/errors/ActionNotFoundError.ts +0 -6
  340. package/src/errors/CodecSchemaValidateError.ts +0 -6
  341. package/src/errors/DeviceNotFoundError.ts +0 -6
  342. package/src/errors/NoAvailableCodecError.ts +0 -6
  343. package/src/errors/NpcapLoadError.ts +0 -6
  344. package/src/errors/SocketDownError.ts +0 -6
  345. package/src/errors/UnknownPipeMessageTypeError.ts +0 -6
  346. package/src/errors/common/ErrorCode.ts +0 -30
  347. package/src/lib/GeneratePipeAddress.ts +0 -17
  348. package/src/lib/GetBinding.ts +0 -3
  349. package/src/lib/GetCaptureTemporaryDirectory.ts +0 -12
  350. package/src/lib/GetDeviceCaptureTemporaryFilename.ts +0 -13
  351. package/src/lib/codec/Codec.ts +0 -164
  352. package/src/lib/codec/PacketHeaders.ts +0 -23
  353. package/src/lib/codec/abstracts/BaseHeader.ts +0 -435
  354. package/src/lib/codec/headers/ARP.ts +0 -220
  355. package/src/lib/codec/headers/EthernetII.ts +0 -79
  356. package/src/lib/codec/headers/Goose.ts +0 -1003
  357. package/src/lib/codec/headers/ICMP.ts +0 -151
  358. package/src/lib/codec/headers/ICMPv6.ts +0 -128
  359. package/src/lib/codec/headers/IEC104_I_Frame.ts +0 -7373
  360. package/src/lib/codec/headers/IEC104_S_Frame.ts +0 -97
  361. package/src/lib/codec/headers/IEC104_U_Frame.ts +0 -139
  362. package/src/lib/codec/headers/IEC61850SampledValues.ts +0 -361
  363. package/src/lib/codec/headers/IPv4.ts +0 -331
  364. package/src/lib/codec/headers/IPv6.ts +0 -176
  365. package/src/lib/codec/headers/IPv6HopByHopOptions.ts +0 -532
  366. package/src/lib/codec/headers/RawData.ts +0 -38
  367. package/src/lib/codec/headers/TCP.ts +0 -934
  368. package/src/lib/codec/headers/TLS_Alert.ts +0 -539
  369. package/src/lib/codec/headers/TLS_ApplicationData.ts +0 -145
  370. package/src/lib/codec/headers/TLS_ChangeCipherSpec.ts +0 -146
  371. package/src/lib/codec/headers/TLS_Handshake.ts +0 -313
  372. package/src/lib/codec/headers/TLS_Heartbeat.ts +0 -188
  373. package/src/lib/codec/headers/UDP.ts +0 -182
  374. package/src/lib/codec/headers/VLAN_802dot1Q.ts +0 -79
  375. package/src/lib/codec/lib/FlexibleObject.ts +0 -100
  376. package/src/lib/codec/lib/GetBERIntegerLengthFromBuffer.ts +0 -12
  377. package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +0 -53
  378. package/src/lib/codec/lib/SortPostHandlers.ts +0 -10
  379. package/src/lib/codec/lib/StringContentEncodingEnum.ts +0 -10
  380. package/src/lib/codec/types/CodecData.ts +0 -7
  381. package/src/lib/codec/types/CodecDecodeResult.ts +0 -11
  382. package/src/lib/codec/types/CodecEncodeInput.ts +0 -9
  383. package/src/lib/codec/types/CodecEncodeResult.ts +0 -6
  384. package/src/lib/codec/types/CodecErrorInfo.ts +0 -5
  385. package/src/lib/codec/types/CodecModule.ts +0 -3
  386. package/src/lib/codec/types/CodecModuleConstructor.ts +0 -3
  387. package/src/lib/codec/types/CodecSchema.ts +0 -7
  388. package/src/lib/codec/types/HeaderTreeNode.ts +0 -5
  389. package/src/lib/codec/types/PostHandlerItem.ts +0 -4
  390. package/src/lib/helper/BufferToHex.ts +0 -3
  391. package/src/lib/helper/BufferToIP.ts +0 -19
  392. package/src/lib/helper/BufferToNumber.ts +0 -31
  393. package/src/lib/helper/HexToBuffer.ts +0 -22
  394. package/src/lib/helper/HexToNumber.ts +0 -25
  395. package/src/lib/helper/IPToBuffer.ts +0 -25
  396. package/src/lib/helper/NumberToBERBuffer.ts +0 -21
  397. package/src/lib/helper/NumberToBERHex.ts +0 -17
  398. package/src/lib/helper/NumberToBuffer.ts +0 -21
  399. package/src/lib/helper/NumberToHex.ts +0 -15
  400. package/src/lib/nodepcap/Capture.ts +0 -304
  401. package/src/lib/nodepcap/GetNetworkInterfaces.ts +0 -18
  402. package/src/lib/nodepcap/interfaces/IBindingCapture.ts +0 -27
  403. package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +0 -4
  404. package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +0 -24
  405. package/src/lib/nodepcap/interfaces/INetworkInterface.ts +0 -4
  406. package/src/lib/nodepcap/lib/BindingCapture.ts +0 -46
  407. package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +0 -17
  408. package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +0 -15
  409. package/src/lib/nodepcap/workers/CaptureWorker.ts +0 -30
  410. package/src/lib/pcap/PCAPGenerator.ts +0 -123
  411. package/src/lib/pcap/PcapParser.ts +0 -170
  412. package/src/lib/pcap/PcapReader.ts +0 -306
  413. package/src/lib/pcap/PcapWriter.ts +0 -98
  414. package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +0 -12
  415. package/src/lib/pipe/PipeClient.ts +0 -91
  416. package/src/lib/pipe/PipeClientSocket.ts +0 -99
  417. package/src/lib/pipe/PipeMessage.ts +0 -74
  418. package/src/lib/pipe/PipeMessageHandler.ts +0 -91
  419. package/src/lib/pipe/PipeServer.ts +0 -74
  420. package/src/lib/schema/ProtocolFieldJSONSchema.ts +0 -45
  421. package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +0 -3
  422. package/src/lib/schema/ProtocolJSONSchema.ts +0 -37
  423. package/src/tests/Test.spec.ts +0 -22
  424. package/src/tests/units/CaptureTest.spec.ts +0 -31
  425. package/src/tests/units/Codec.spec.ts +0 -102
  426. package/src/tests/units/ReadPCAP.spec.ts +0 -13
  427. package/test.pcap +0 -0
  428. package/tsconfig.json +0 -42
@@ -1,1003 +0,0 @@
1
- import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
- import {BaseHeader} from '../abstracts/BaseHeader'
3
- import TLV from 'node-tlv'
4
- import {
5
- HexToFloat32,
6
- HexToInt16,
7
- HexToInt32,
8
- HexToInt64,
9
- HexToInt8,
10
- HexToUInt16,
11
- HexToUInt32,
12
- HexToUInt8
13
- } from '../../helper/HexToNumber'
14
- import {
15
- Float32ToBERHex,
16
- Int16ToBERHex,
17
- Int32ToBERHex,
18
- Int64ToBERHex,
19
- Int8ToBERHex,
20
- UInt16ToBERHex,
21
- UInt32ToBERHex,
22
- UInt8ToBERHex
23
- } from '../../helper/NumberToBERHex'
24
- import {UInt16ToHex} from '../../helper/NumberToHex'
25
- import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
26
- import {UInt32ToBERBuffer} from '../../helper/NumberToBERBuffer'
27
- import {BufferToUInt16} from '../../helper/BufferToNumber'
28
- import {UInt16ToBuffer} from '../../helper/NumberToBuffer'
29
- import {GetBERIntegerLengthFromBuffer} from '../lib/GetBERIntegerLengthFromBuffer'
30
-
31
- enum ItemDataType {
32
- Boolean = 'Boolean',
33
- INT8 = 'INT8',
34
- INT16 = 'INT16',
35
- INT32 = 'INT32',
36
- INT64 = 'INT64',
37
- INT8U = 'INT8U',
38
- INT16U = 'INT16U',
39
- INT32U = 'INT32U',
40
- FLOAT32 = 'FLOAT32',
41
- CODEDENUM = 'CODED-ENUM',
42
- OCTETSTRING = 'OCTET-STRING',
43
- VISIBLESTRING = 'VISIBLE-STRING',
44
- TimeStamp = 'TimeStamp',
45
- Quality = 'Quality',
46
- Structure = 'Structure'
47
- }
48
-
49
- type BooleanDataItem = {
50
- dataType: ItemDataType.Boolean
51
- value: boolean
52
- }
53
- type INT8DataItem = {
54
- dataType: ItemDataType.INT8
55
- value: number
56
- }
57
- type INT16DataItem = {
58
- dataType: ItemDataType.INT16
59
- value: number
60
- }
61
- type INT32DataItem = {
62
- dataType: ItemDataType.INT32
63
- value: number
64
- }
65
- type INT64DataItem = {
66
- dataType: ItemDataType.INT64
67
- value: bigint
68
- }
69
- type INT8UDataItem = {
70
- dataType: ItemDataType.INT8U
71
- value: number
72
- }
73
- type INT16UDataItem = {
74
- dataType: ItemDataType.INT16U
75
- value: number
76
- }
77
- type INT32UDataItem = {
78
- dataType: ItemDataType.INT32U
79
- value: number
80
- }
81
- type FLOAT32DataItem = {
82
- dataType: ItemDataType.FLOAT32
83
- value: number
84
- }
85
- type CODEDENUMDataItem = {
86
- dataType: ItemDataType.CODEDENUM
87
- value: number
88
- }
89
- type OCTETSTRINGDataItem = {
90
- dataType: ItemDataType.OCTETSTRING
91
- value: string
92
- }
93
- type VISIBLESTRINGDataItem = {
94
- dataType: ItemDataType.VISIBLESTRING
95
- value: string
96
- }
97
- type TimeStampDataItem = {
98
- dataType: ItemDataType.TimeStamp
99
- value: string
100
- }
101
- type QualityDataItem = {
102
- dataType: ItemDataType.Quality
103
- value: string
104
- }
105
- type StructureDataItem = {
106
- dataType: ItemDataType.Structure
107
- value: DataItem[]
108
- }
109
-
110
- type DataItem = BooleanDataItem |
111
- INT8DataItem |
112
- INT16DataItem |
113
- INT32DataItem |
114
- INT64DataItem |
115
- INT8UDataItem |
116
- INT16UDataItem |
117
- INT32UDataItem |
118
- FLOAT32DataItem |
119
- CODEDENUMDataItem |
120
- OCTETSTRINGDataItem |
121
- VISIBLESTRINGDataItem |
122
- TimeStampDataItem |
123
- QualityDataItem |
124
- StructureDataItem
125
-
126
- export class Goose extends BaseHeader {
127
-
128
- protected TLVInstance: TLV
129
-
130
- protected TLVChild: TLV[] = []
131
-
132
- public SCHEMA: ProtocolJSONSchema = {
133
- type: 'object',
134
- properties: {
135
- appid: {
136
- type: 'integer',
137
- minimum: 0,
138
- maximum: 65535,
139
- label: 'APPID',
140
- decode: (): void => {
141
- this.instance.appid.setValue(BufferToUInt16(this.readBytes(0, 2)))
142
- },
143
- encode: (): void => {
144
- const APPID: number = this.instance.appid.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
145
- this.instance.appid.setValue(APPID)
146
- this.writeBytes(0, UInt16ToBuffer(APPID))
147
- }
148
- },
149
- length: {
150
- type: 'integer',
151
- minimum: 0,
152
- maximum: 65535,
153
- label: 'Length',
154
- decode: (): void => {
155
- this.instance.length.setValue(BufferToUInt16(this.readBytes(2, 2)))
156
- },
157
- encode: (): void => {
158
- const length: number = this.instance.length.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
159
- if (length > 0) {
160
- this.instance.length.setValue(length)
161
- this.writeBytes(2, UInt16ToBuffer(length))
162
- } else {
163
- this.addPostSelfEncodeHandler((): void => {
164
- const finalLength: number = parseInt(this.instance.length.getValue().toString())
165
- this.writeBytes(2, UInt16ToBuffer(finalLength))
166
- })
167
- }
168
- }
169
- },
170
- reserved1: {
171
- type: 'object',
172
- label: 'Reserved1',
173
- properties: {
174
- simulated: {
175
- type: 'boolean',
176
- label: 'Simulated',
177
- decode: (): void => {
178
- this.instance.reserved1.simulated.setValue(!!this.readBits(4, 2, 0, 1))
179
- },
180
- encode: (): void => {
181
- const simulated: boolean = this.instance.reserved1.simulated.getValue(false)
182
- this.writeBits(4, 2, 0, 1, simulated ? 1 : 0)
183
- }
184
- },
185
- reserved: {
186
- type: 'number',
187
- minimum: 0,
188
- maximum: 32767,
189
- label: 'Reserved',
190
- decode: (): void => {
191
- this.instance.reserved1.reserved.setValue(this.readBits(4, 2, 1, 16))
192
- },
193
- encode: (): void => {
194
- const reserved: number = this.instance.reserved1.reserved.getValue(0)
195
- this.writeBits(4, 2, 1, 16, reserved)
196
- }
197
- }
198
- }
199
- },
200
- reserved2: {
201
- type: 'object',
202
- label: 'Reserved2',
203
- properties: {
204
- reserved: {
205
- type: 'number',
206
- minimum: 0,
207
- maximum: 65535,
208
- label: 'Reserved',
209
- decode: (): void => {
210
- this.instance.reserved2.reserved.setValue(this.readBits(4, 2, 0, 16))
211
- },
212
- encode: (): void => {
213
- const reserved: number = this.instance.reserved2.reserved.getValue(0)
214
- this.writeBits(4, 2, 0, 16, reserved)
215
- }
216
- }
217
- }
218
- },
219
- goosePdu: {
220
- type: 'object',
221
- label: 'GOOSE PDU',
222
- decode: (): void => {
223
- let readTLVBufferLength: number = this.packet.length - this.startPos - 8
224
- while (!this.TLVInstance) {
225
- try {
226
- const buffer: Buffer = this.readBytes(8, readTLVBufferLength, true)
227
- this.TLVInstance = TLV.parse(buffer)
228
- const tagWithLength: string[] = buffer.toString('hex').replace(this.TLVInstance.bValue.toString('hex'), '#').split('#')
229
- const tagWithLengthBytes: number = Math.max(...tagWithLength.map((value: string): number => Math.ceil(value.length / 2)))
230
- const TLVBufferLength: number = this.TLVInstance.bValue.length + tagWithLengthBytes
231
- this.TLVInstance = TLV.parse(this.readBytes(8, TLVBufferLength, false))
232
- } catch (e) {
233
- readTLVBufferLength -= 1
234
- if (!readTLVBufferLength) break
235
- }
236
- }
237
- this.TLVChild = this.TLVInstance ? this.TLVInstance.getChild() : []
238
- },
239
- encode: (): void => {
240
- let buffers: Buffer = Buffer.from([])
241
- this.TLVChild.forEach(item => buffers = Buffer.concat([buffers, item.bTag, item.bLength, item.bValue]))
242
- const goosePduTLV: TLV = new TLV(0x61, buffers)
243
- const goosePduBuffer: Buffer = Buffer.concat([goosePduTLV.bTag, goosePduTLV.bLength, goosePduTLV.bValue])
244
- this.writeBytes(8, goosePduBuffer)
245
- /**
246
- * Update the length only if it is not set
247
- * Update length(APPID's length + Length's length + Reserved1's length + Reserved2's length + goosePdu's length)
248
- */
249
- if (this.instance.length.getValue() > 0) return
250
- this.instance.length.setValue(2 + 2 + 2 + 2 + goosePduBuffer.length)
251
- },
252
- properties: {
253
- gocbRef: {
254
- type: 'string',
255
- maxLength: 129,
256
- label: 'GoCBReference',
257
- contentEncoding: StringContentEncodingEnum.ASCII,
258
- decode: (): void => {
259
- const gocbRefTLV: TLV | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x80)
260
- if (!gocbRefTLV) return this.recordError(this.instance.goosePdu.gocbRef.getPath(), 'Not Found')
261
- this.instance.goosePdu.gocbRef.setValue(gocbRefTLV.getValue('buffer').toString('ascii'))
262
- },
263
- encode: (): void => {
264
- const gocbRefValue: string = this.instance.goosePdu.gocbRef.getValue('', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
265
- if (!gocbRefValue) return
266
- let gocbRefBuffer: Buffer = Buffer.from(gocbRefValue, 'ascii')
267
- if (gocbRefBuffer.length > 129) {
268
- this.recordError(this.instance.goosePdu.gocbRef.getPath(), 'This VisibleString shall have a maximum size of 129 octets')
269
- gocbRefBuffer = gocbRefBuffer.subarray(0, 129)
270
- }
271
- this.TLVChild.push(new TLV(0x80, gocbRefBuffer))
272
- }
273
- },
274
- timeAllowedtoLive: {
275
- type: 'number',
276
- minimum: 0,
277
- maximum: 4294967295,
278
- label: 'TimeAllowedtoLive',
279
- decode: (): void => {
280
- const timeAllowedtoLiveString: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x81)?.getValue('hex')
281
- if (!timeAllowedtoLiveString) return this.recordError(this.instance.goosePdu.timeAllowedtoLive.getPath(), 'Not Found')
282
- this.instance.goosePdu.timeAllowedtoLive.setValue(HexToUInt32(timeAllowedtoLiveString))
283
- },
284
- encode: (): void => {
285
- let timeAllowedtoLiveValue: number = this.instance.goosePdu.timeAllowedtoLive.getValue(-1, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
286
- if (timeAllowedtoLiveValue === -1) return
287
- if (timeAllowedtoLiveValue < 1 || timeAllowedtoLiveValue > 4294967295) {
288
- this.recordError(this.instance.goosePdu.timeAllowedtoLive.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295')
289
- timeAllowedtoLiveValue = 4294967295
290
- }
291
- const timeAllowedtoLiveTLV: TLV = new TLV(0x81, UInt32ToBERBuffer(timeAllowedtoLiveValue))
292
- this.TLVChild.push(timeAllowedtoLiveTLV)
293
- }
294
- },
295
- datSet: {
296
- type: 'string',
297
- maxLength: 129,
298
- label: 'DatSet',
299
- contentEncoding: StringContentEncodingEnum.ASCII,
300
- decode: (): void => {
301
- const datSetTLV: TLV | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x82)
302
- if (!datSetTLV) return this.recordError(this.instance.goosePdu.datSet.getPath(), 'Not Found')
303
- this.instance.goosePdu.datSet.setValue(datSetTLV.getValue('buffer').toString('ascii'))
304
- },
305
- encode: (): void => {
306
- const datSetValue: string = this.instance.goosePdu.datSet.getValue('', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
307
- if (!datSetValue) return
308
- let datSetBuffer: Buffer = Buffer.from(datSetValue, 'ascii')
309
- if (datSetBuffer.length > 129) {
310
- this.recordError(this.instance.goosePdu.datSet.getPath(), 'This VisibleString shall have a maximum size of 129 octets')
311
- datSetBuffer = datSetBuffer.subarray(0, 129)
312
- }
313
- this.TLVChild.push(new TLV(0x82, datSetBuffer))
314
- }
315
- },
316
- goID: {
317
- type: 'string',
318
- maxLength: 65,
319
- label: 'GoID',
320
- contentEncoding: StringContentEncodingEnum.ASCII,
321
- decode: (): void => {
322
- const goIDTLV: TLV | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x83)
323
- if (!goIDTLV) return this.recordError(this.instance.goosePdu.goID.getPath(), 'Not Found')
324
- this.instance.goosePdu.goID.setValue(goIDTLV.getValue('buffer').toString('ascii'))
325
- },
326
- encode: (): void => {
327
- const goIDValue: string = this.instance.goosePdu.goID.getValue('', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
328
- if (!goIDValue) return
329
- let goIDBuffer: Buffer = Buffer.from(goIDValue, 'ascii')
330
- if (goIDBuffer.length > 65) {
331
- this.recordError(this.instance.goosePdu.goID.getPath(), 'This VisibleString shall have a maximum size of 65 octets')
332
- goIDBuffer = goIDBuffer.subarray(0, 65)
333
- }
334
- this.TLVChild.push(new TLV(0x83, goIDBuffer))
335
- }
336
- },
337
- t: {
338
- type: 'string',
339
- label: 'TimeStamp',
340
- contentEncoding: StringContentEncodingEnum.BIGINT,
341
- decode: (): void => {
342
- const tStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x84)?.getValue('hex')
343
- if (!tStr) return this.recordError(this.instance.goosePdu.t.getPath(), 'Not Found')
344
- this.instance.goosePdu.t.setValue(BigInt(`0x${tStr}`).toString())
345
- },
346
- encode: (): void => {
347
- const tStr: string = this.instance.goosePdu.t.getValue('', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
348
- if (!tStr) return
349
- const tBigIntValue: bigint = BigInt(tStr)
350
- const tTLV: TLV = new TLV(0x84, Buffer.from(tBigIntValue.toString(16).padStart(8 * 2, '0'), 'hex'))
351
- this.TLVChild.push(tTLV)
352
- }
353
- },
354
- stNum: {
355
- type: 'integer',
356
- minimum: 0,
357
- maximum: 4294967295,
358
- label: 'StNum',
359
- decode: (): void => {
360
- const stNumStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x85)?.getValue('hex')
361
- if (!stNumStr) return this.recordError(this.instance.goosePdu.stNum.getPath(), 'Not Found')
362
- this.instance.goosePdu.stNum.setValue(HexToUInt32(stNumStr))
363
- if (this.instance.goosePdu.stNum.getValue() < 1 || this.instance.goosePdu.stNum.getValue() > 4294967295) this.recordError(this.instance.goosePdu.stNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295')
364
- },
365
- encode: (): void => {
366
- let stNumValue: number = this.instance.goosePdu.stNum.getValue(-1, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
367
- if (stNumValue < 0) return
368
- if (stNumValue > 4294967295) {
369
- stNumValue = 4294967295
370
- this.recordError(this.instance.goosePdu.stNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295')
371
- }
372
- if (stNumValue === undefined) return this.recordError(this.instance.goosePdu.stNum.getPath(), 'Not Found')
373
- const stNumTLV: TLV = new TLV(0x85, UInt32ToBERBuffer(stNumValue))
374
- this.TLVChild.push(stNumTLV)
375
- }
376
- },
377
- sqNum: {
378
- type: 'integer',
379
- minimum: 0,
380
- maximum: 4294967295,
381
- label: 'SqNum',
382
- decode: (): void => {
383
- const sqNumStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x86)?.getValue('hex')
384
- if (!sqNumStr) return this.recordError(this.instance.goosePdu.sqNum.getPath(), 'Not Found')
385
- this.instance.goosePdu.sqNum.setValue(HexToUInt32(sqNumStr))
386
- },
387
- encode: (): void => {
388
- let sqNumValue: number = this.instance.goosePdu.sqNum.getValue(-1, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
389
- if (sqNumValue < 0) return
390
- if (sqNumValue > 4294967295) {
391
- sqNumValue = 4294967295
392
- this.recordError(this.instance.goosePdu.sqNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295')
393
- }
394
- if (sqNumValue === undefined) return this.recordError(this.instance.goosePdu.sqNum.getPath(), 'Not Found')
395
- const sqNumTLV: TLV = new TLV(0x86, UInt32ToBERBuffer(sqNumValue))
396
- this.TLVChild.push(sqNumTLV)
397
- }
398
- },
399
- simulation: {
400
- type: 'boolean',
401
- label: 'Simulation',
402
- decode: (): void => {
403
- const simulationStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x87)?.getValue('hex')
404
- if (!simulationStr) return this.recordError(this.instance.goosePdu.simulation.getPath(), 'Not Found')
405
- const simulationNum: number = parseInt(simulationStr, 16)
406
- if (simulationNum > 1) this.recordError(this.instance.goosePdu.simulation.getPath(), 'This Boolean shall have a range of TRUE, FALSE')
407
- this.instance.goosePdu.simulation.setValue(!!simulationNum)
408
- },
409
- encode: (): void => {
410
- const simulationValue: boolean | undefined = this.instance.goosePdu.simulation.getValue(undefined, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
411
- if (simulationValue === undefined) return
412
- const simulationNum: number = simulationValue ? 1 : 0
413
- const simulationTLV: TLV = new TLV(0x87, Buffer.from(simulationNum.toString(16).padStart(2, '0'), 'hex'))
414
- this.TLVChild.push(simulationTLV)
415
- }
416
- },
417
- confRev: {
418
- type: 'integer',
419
- label: 'ConfRev',
420
- decode: (): void => {
421
- const confRevStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x88)?.getValue('hex')
422
- if (!confRevStr) return this.recordError(this.instance.goosePdu.confRev.getPath(), 'Not Found')
423
- this.instance.goosePdu.confRev.setValue(HexToUInt32(confRevStr))
424
- },
425
- encode: (): void => {
426
- let confRevValue: number = this.instance.goosePdu.confRev.getValue(-1, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
427
- if (confRevValue > 4294967295) {
428
- confRevValue = 4294967295
429
- this.recordError(this.instance.goosePdu.confRev.getPath(), 'This INTEGER value shall have a range of 0 to 4294967295')
430
- }
431
- if (confRevValue === -1) return
432
- const confRevTLV: TLV = new TLV(0x88, UInt32ToBERBuffer(confRevValue))
433
- this.TLVChild.push(confRevTLV)
434
- }
435
- },
436
- ndsCom: {
437
- type: 'boolean',
438
- label: 'NdsCom',
439
- decode: (): void => {
440
- const ndsComStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x89)?.getValue('hex')
441
- if (!ndsComStr) return this.recordError(this.instance.goosePdu.ndsCom.getPath(), 'Not Found')
442
- const ndsComNum: number = parseInt(ndsComStr, 16)
443
- if (ndsComNum > 1) this.recordError(this.instance.goosePdu.ndsCom.getPath(), 'This Boolean shall have a range of TRUE, FALSE')
444
- this.instance.goosePdu.ndsCom.setValue(!!ndsComNum)
445
- },
446
- encode: (): void => {
447
- const ndsComValue: boolean | undefined = this.instance.goosePdu.ndsCom.getValue(undefined, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
448
- if (ndsComValue === undefined) return
449
- const ndsComNum: number = ndsComValue ? 1 : 0
450
- const ndsComTLV: TLV = new TLV(0x89, Buffer.from(ndsComNum.toString(16).padStart(2, '0'), 'hex'))
451
- this.TLVChild.push(ndsComTLV)
452
- }
453
- },
454
- numDatSetEntries: {
455
- type: 'integer',
456
- label: 'NumDatSetEntries',
457
- decode: (): void => {
458
- const numDatSetEntriesStr: string | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0x8A)?.getValue('hex')
459
- if (!numDatSetEntriesStr) return this.recordError(this.instance.goosePdu.numDatSetEntries.getPath(), 'Not Found')
460
- this.instance.goosePdu.numDatSetEntries.setValue(parseInt(numDatSetEntriesStr, 16))
461
- },
462
- encode: (): void => {
463
- const numDatSetEntriesValue: number | undefined = this.instance.goosePdu.numDatSetEntries.getValue(undefined, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
464
- if (numDatSetEntriesValue === undefined) return
465
- const numDatSetEntriesTLV: TLV = new TLV(0x8A, UInt32ToBERBuffer(numDatSetEntriesValue))
466
- this.TLVChild.push(numDatSetEntriesTLV)
467
- }
468
- },
469
- allData: {
470
- type: 'array',
471
- label: 'AllData',
472
- items: {
473
- anyOf: [
474
- {
475
- type: 'object',
476
- label: ItemDataType.Boolean,
477
- properties: {
478
- dataType: {
479
- type: 'string',
480
- label: 'DataType',
481
- enum: [ItemDataType.Boolean]
482
- },
483
- value: {
484
- type: 'boolean',
485
- label: 'Value'
486
- }
487
- }
488
- },
489
- {
490
- type: 'object',
491
- label: ItemDataType.INT8,
492
- properties: {
493
- dataType: {
494
- type: 'string',
495
- label: 'DataType',
496
- enum: [ItemDataType.INT8]
497
- },
498
- value: {
499
- type: 'integer',
500
- label: 'Value'
501
- }
502
- }
503
- },
504
- {
505
- type: 'object',
506
- label: ItemDataType.INT16,
507
- properties: {
508
- dataType: {
509
- type: 'string',
510
- label: 'DataType',
511
- enum: [ItemDataType.INT16]
512
- },
513
- value: {
514
- type: 'integer',
515
- label: 'Value'
516
- }
517
- }
518
- },
519
- {
520
- type: 'object',
521
- label: ItemDataType.INT32,
522
- properties: {
523
- dataType: {
524
- type: 'string',
525
- label: 'DataType',
526
- enum: [ItemDataType.INT32]
527
- },
528
- value: {
529
- type: 'integer',
530
- label: 'Value'
531
- }
532
- }
533
- },
534
- {
535
- type: 'object',
536
- label: ItemDataType.INT64,
537
- properties: {
538
- dataType: {
539
- type: 'string',
540
- label: 'DataType',
541
- enum: [ItemDataType.INT64]
542
- },
543
- value: {
544
- type: 'string',
545
- label: 'Value',
546
- contentEncoding: StringContentEncodingEnum.BIGINT
547
- }
548
- }
549
- },
550
- {
551
- type: 'object',
552
- label: ItemDataType.INT8U,
553
- properties: {
554
- dataType: {
555
- type: 'string',
556
- label: 'DataType',
557
- enum: [ItemDataType.INT8U]
558
- },
559
- value: {
560
- type: 'integer',
561
- label: 'Value'
562
- }
563
- }
564
- },
565
- {
566
- type: 'object',
567
- label: ItemDataType.INT16U,
568
- properties: {
569
- dataType: {
570
- type: 'string',
571
- label: 'DataType',
572
- enum: [ItemDataType.INT16U]
573
- },
574
- value: {
575
- type: 'integer',
576
- label: 'Value'
577
- }
578
- }
579
- },
580
- {
581
- type: 'object',
582
- label: ItemDataType.INT32U,
583
- properties: {
584
- dataType: {
585
- type: 'string',
586
- label: 'DataType',
587
- enum: [ItemDataType.INT32U]
588
- },
589
- value: {
590
- type: 'integer',
591
- label: 'Value'
592
- }
593
- }
594
- },
595
- {
596
- type: 'object',
597
- label: ItemDataType.FLOAT32,
598
- properties: {
599
- dataType: {
600
- type: 'string',
601
- label: 'DataType',
602
- enum: [ItemDataType.FLOAT32]
603
- },
604
- value: {
605
- type: 'number',
606
- label: 'Value'
607
- }
608
- }
609
- },
610
- {
611
- type: 'object',
612
- label: ItemDataType.CODEDENUM,
613
- properties: {
614
- dataType: {
615
- type: 'string',
616
- label: 'DataType',
617
- enum: [ItemDataType.CODEDENUM]
618
- },
619
- value: {
620
- type: 'integer',
621
- label: 'Value'
622
- }
623
- }
624
- },
625
- {
626
- type: 'object',
627
- label: ItemDataType.OCTETSTRING,
628
- properties: {
629
- dataType: {
630
- type: 'string',
631
- label: 'DataType',
632
- enum: [ItemDataType.OCTETSTRING]
633
- },
634
- value: {
635
- type: 'string',
636
- label: 'Value',
637
- contentEncoding: StringContentEncodingEnum.HEX
638
- }
639
- }
640
- },
641
- {
642
- type: 'object',
643
- label: ItemDataType.VISIBLESTRING,
644
- properties: {
645
- dataType: {
646
- type: 'string',
647
- label: 'DataType',
648
- enum: [ItemDataType.VISIBLESTRING]
649
- },
650
- value: {
651
- type: 'string',
652
- label: 'Value',
653
- contentEncoding: StringContentEncodingEnum.ASCII
654
- }
655
- }
656
- },
657
- {
658
- type: 'object',
659
- label: ItemDataType.TimeStamp,
660
- properties: {
661
- dataType: {
662
- type: 'string',
663
- label: 'DataType',
664
- enum: [ItemDataType.TimeStamp]
665
- },
666
- value: {
667
- type: 'string',
668
- label: 'Value'
669
- }
670
- }
671
- },
672
- {
673
- type: 'object',
674
- label: ItemDataType.Quality,
675
- properties: {
676
- dataType: {
677
- type: 'string',
678
- label: 'DataType',
679
- enum: [ItemDataType.Quality]
680
- },
681
- value: {
682
- type: 'string',
683
- label: 'Value',
684
- contentEncoding: StringContentEncodingEnum.BINARY
685
- }
686
- }
687
- },
688
- {
689
- type: 'object',
690
- label: ItemDataType.Structure,
691
- properties: {
692
- dataType: {
693
- type: 'string',
694
- label: 'DataType',
695
- enum: [ItemDataType.Structure]
696
- },
697
- value: {
698
- $ref: '#/properties/goosePdu/properties/allData',
699
- label: 'Value'
700
- }
701
- }
702
- }
703
- ]
704
- },
705
- /**
706
- * +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
707
- * | Data types according to IEC 61850-7-2 | ASN.1 Tag for Data | ASN.1 Length | Comments |
708
- * +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
709
- * | Boolean | 0x83 | 1 | 8 Bit set to 0 FALSE; anything else = TRUE |
710
- * | INT8 | 0x85 | 2 | 8 Bit Big Endian; signed |
711
- * | INT16 | 0x85 | 3 | 16 Bit Big Endian; signed |
712
- * | INT32 | 0x85 | 5 | 32 Bit Big Endian; signed |
713
- * | INT64 | 0x85 | 9 | 64Bit Big Endian; signed |
714
- * | INT8U | 0x86 | 2 | 8 Bit Big Endian; unsigned |
715
- * | INT16U | 0x86 | 3 | 16 Bit Big Endian; unsigned |
716
- * | INT24U | - | - | Not used |
717
- * | INT32U | 0x86 | 5 | 32 Bit Big Endian; unsigned |
718
- * | FLOAT32 | 0x87 | 4 | 32 Bit IEEE Floating Point (IEEE 754) |
719
- * | 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) |
720
- * | OCTET-STRING | 0x89 | 20 | 20 Bytes ASCII Text, Null terminated |
721
- * | VISIBLE-STRING | 0x8a | 35 | 35 Bytes ASCII Text, Null terminated |
722
- * | TimeStamp | 0x91 | 8 | 64 Bit TimeStamp as defined in 8.1.3.7 IEC 6 |
723
- * | Quality | 0x84 | 3 | Bit-string |
724
- * +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
725
- */
726
- decode: (): void => {
727
- const allDataTLV: TLV | undefined = this.TLVChild.find(tlv => tlv.getTag('number') === 0xAB)
728
- const dataTLVs: TLV[] = allDataTLV ? allDataTLV.getChild() : []
729
- const allData: DataItem[] = this.decodeDataTLVItem(dataTLVs)
730
- if (allData.length) this.instance.goosePdu.allData.setValue(allData)
731
- },
732
- encode: (): void => {
733
- const allData: DataItem[] = this.instance.goosePdu.allData.getValue([], (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
734
- const dataItemTLVs: TLV[] = this.encodeDataTLVItem(allData)
735
- if (dataItemTLVs.length) {
736
- const allDataTLV: TLV = new TLV(0xAB, Buffer.concat(dataItemTLVs.map((dataItemTLV: TLV): Buffer => Buffer.concat([dataItemTLV.bTag, dataItemTLV.bLength, dataItemTLV.bValue]))))
737
- this.TLVChild.push(allDataTLV)
738
- }
739
- }
740
- }
741
- }
742
- }
743
- }
744
- }
745
-
746
- /**
747
- * Decode data TLV items
748
- * @param dataTLVs
749
- * @protected
750
- */
751
- protected decodeDataTLVItem(dataTLVs: TLV[]): DataItem[] {
752
- const dataItems: DataItem[] = []
753
- dataTLVs.forEach((dataTLV: TLV): void => {
754
- const length: number = dataTLV.getLength('number')
755
- const value: Buffer = dataTLV.getValue('buffer')
756
- switch (dataTLV.getTag('number')) {
757
- case 0x83: {
758
- dataItems.push({
759
- dataType: ItemDataType.Boolean,
760
- value: !!parseInt(value.toString('hex'), 16)
761
- })
762
- }
763
- break
764
- case 0x84: {
765
- switch (length) {
766
- case 2: {
767
- dataItems.push({
768
- dataType: ItemDataType.CODEDENUM,
769
- value: parseInt(value.toString('hex'), 16)
770
- })
771
- }
772
- break
773
- case 3: {
774
- dataItems.push({
775
- dataType: ItemDataType.Quality,
776
- value: parseInt(value.toString('hex'), 16).toString(2).padStart(24, '0')
777
- })
778
- }
779
- break
780
- }
781
- }
782
- break
783
- case 0x85: {
784
- const integerRealLength: number = GetBERIntegerLengthFromBuffer(value)
785
- if (integerRealLength === 1) {
786
- dataItems.push({
787
- dataType: ItemDataType.INT8,
788
- value: HexToInt8(value.toString('hex'))
789
- })
790
- } else if (integerRealLength === 2) {
791
- dataItems.push({
792
- dataType: ItemDataType.INT16,
793
- value: HexToInt16(value.toString('hex'))
794
- })
795
- } else if (integerRealLength === 4) {
796
- dataItems.push({
797
- dataType: ItemDataType.INT32,
798
- value: HexToInt32(value.toString('hex'))
799
- })
800
- } else if (integerRealLength === 8) {
801
- dataItems.push({
802
- dataType: ItemDataType.INT64,
803
- value: HexToInt64(value.toString('hex'))
804
- })
805
- }
806
- }
807
- break
808
- case 0x86: {
809
- const unsignedIntegerRealLength: number = GetBERIntegerLengthFromBuffer(value)
810
- switch (unsignedIntegerRealLength) {
811
- case 1: {
812
- dataItems.push({
813
- dataType: ItemDataType.INT8U,
814
- value: HexToUInt8(value.toString('hex'))
815
- })
816
- }
817
- break
818
- case 2: {
819
- dataItems.push({
820
- dataType: ItemDataType.INT16U,
821
- value: HexToUInt16(value.toString('hex'))
822
- })
823
- }
824
- break
825
- case 4: {
826
- dataItems.push({
827
- dataType: ItemDataType.INT32U,
828
- value: HexToUInt32(value.toString('hex'))
829
- })
830
- }
831
- break
832
- }
833
- }
834
- break
835
- case 0x87: {
836
- dataItems.push({
837
- dataType: ItemDataType.FLOAT32,
838
- value: HexToFloat32(value.toString('hex'))
839
- })
840
- }
841
- break
842
- case 0x89: {
843
- dataItems.push({
844
- dataType: ItemDataType.OCTETSTRING,
845
- value: value.toString('hex')
846
- })
847
- }
848
- break
849
- case 0x8a: {
850
- dataItems.push({
851
- dataType: ItemDataType.VISIBLESTRING,
852
- value: value.toString('ascii')
853
- })
854
- }
855
- break
856
- case 0x91: {
857
- dataItems.push({
858
- dataType: ItemDataType.TimeStamp,
859
- value: parseInt(value.toString('hex'), 16).toString()
860
- })
861
- }
862
- break
863
- case 0xa2: {
864
- const subDataTLVs: TLV[] = TLV.parseList(value)
865
- dataItems.push({
866
- dataType: ItemDataType.Structure,
867
- value: this.decodeDataTLVItem(subDataTLVs)
868
- })
869
- }
870
- break
871
- }
872
- })
873
- return dataItems
874
- }
875
-
876
- /**
877
- * Encode data TLV items
878
- * @param dataItems
879
- * @protected
880
- */
881
- protected encodeDataTLVItem(dataItems: DataItem[]): TLV[] {
882
- return dataItems
883
- .map((dataItem: DataItem, index: number): TLV | null => {
884
- const errorNodePath: string = this.instance.goosePdu.allData.getPath(index)
885
- switch (dataItem.dataType) {
886
- case ItemDataType.Boolean: {
887
- const booleanIntValue: number = dataItem.value ? 1 : 0
888
- return new TLV(0x83, Buffer.from(booleanIntValue.toString(16).padStart(2, '0'), 'hex'))
889
- }
890
- case ItemDataType.INT8: {
891
- let intValue: number = dataItem.value
892
- if (isNaN(intValue)) this.recordError(errorNodePath, 'Invalid INT8 value')
893
- intValue = intValue ? intValue : 0
894
- if (intValue < -128 || intValue > 127) this.recordError(errorNodePath, 'Invalid INT8 value')
895
- return new TLV(0x85, Buffer.from(Int8ToBERHex(intValue), 'hex'))
896
- }
897
- case ItemDataType.INT16: {
898
- let intValue: number = dataItem.value
899
- if (isNaN(intValue)) this.recordError(errorNodePath, 'Invalid INT16 value')
900
- intValue = intValue ? intValue : 0
901
- if (intValue < -32768 || intValue > 32767) this.recordError(errorNodePath, 'Invalid INT16 value')
902
- return new TLV(0x85, Buffer.from(Int16ToBERHex(intValue), 'hex'))
903
- }
904
- case ItemDataType.INT32: {
905
- let intValue: number = dataItem.value
906
- if (isNaN(intValue)) this.recordError(errorNodePath, 'Invalid INT32 value')
907
- intValue = intValue ? intValue : 0
908
- if (intValue < -2147483648 || intValue > 2147483647) this.recordError(errorNodePath, 'Invalid INT32 value')
909
- return new TLV(0x85, Buffer.from(Int32ToBERHex(intValue), 'hex'))
910
- }
911
- case ItemDataType.INT64: {
912
- const intValue: bigint = BigInt(dataItem.value)
913
- if (intValue < BigInt('-9223372036854775808') || intValue > BigInt('9223372036854775807')) this.recordError(errorNodePath, 'Invalid INT64 value')
914
- return new TLV(0x85, Buffer.from(Int64ToBERHex(intValue), 'hex'))
915
- }
916
- case ItemDataType.INT8U: {
917
- let uintValue: number = dataItem.value
918
- if (isNaN(uintValue)) this.recordError(errorNodePath, 'Invalid INT8U value')
919
- uintValue = uintValue ? uintValue : 0
920
- if (uintValue < 0 || uintValue > 255) this.recordError(errorNodePath, 'Invalid INT8U value')
921
- return new TLV(0x86, Buffer.from(UInt8ToBERHex(uintValue), 'hex'))
922
- }
923
- case ItemDataType.INT16U: {
924
- let uintValue: number = dataItem.value
925
- if (isNaN(uintValue)) this.recordError(errorNodePath, 'Invalid INT16U value')
926
- uintValue = uintValue ? uintValue : 0
927
- if (uintValue < 0 || uintValue > 65535) this.recordError(errorNodePath, 'Invalid INT16U value')
928
- return new TLV(0x86, Buffer.from(UInt16ToBERHex(uintValue), 'hex'))
929
- }
930
- case ItemDataType.INT32U: {
931
- let uintValue: number = dataItem.value
932
- if (isNaN(uintValue)) this.recordError(errorNodePath, 'Invalid INT32U value')
933
- uintValue = uintValue ? uintValue : 0
934
- if (uintValue < 0 || uintValue > 4294967295) this.recordError(errorNodePath, 'Invalid INT32U value')
935
- return new TLV(0x86, Buffer.from(UInt32ToBERHex(uintValue), 'hex'))
936
- }
937
- case ItemDataType.FLOAT32: {
938
- let float32Value: number = dataItem.value
939
- if (isNaN(float32Value)) this.recordError(errorNodePath, 'Invalid FLOAT32 value')
940
- float32Value = float32Value ? float32Value : 0
941
- return new TLV(0x87, Buffer.from(Float32ToBERHex(float32Value), 'hex'))
942
- }
943
- case ItemDataType.CODEDENUM: {
944
- let codedEnumValue: number = dataItem.value
945
- if (isNaN(codedEnumValue)) this.recordError(errorNodePath, 'Invalid CODED-ENUM value')
946
- codedEnumValue = codedEnumValue ? codedEnumValue : 0
947
- return new TLV(0x84, Buffer.from(UInt16ToBERHex(codedEnumValue), 'hex'))
948
- }
949
- case ItemDataType.OCTETSTRING: {
950
- const hexText: string = dataItem.value
951
- if (!hexText) {
952
- this.recordError(errorNodePath, 'Empty OCTET-STRING, ignored')
953
- return null
954
- }
955
- if (hexText.length > 20) this.recordError(errorNodePath, 'OCTET-STRING too long')
956
- return new TLV(0x89, Buffer.from(hexText, 'hex').subarray(0, 20))
957
- }
958
- case ItemDataType.VISIBLESTRING: {
959
- const asciiText: string = dataItem.value
960
- if (!asciiText) {
961
- this.recordError(errorNodePath, 'Empty VISIBLE-STRING, ignored')
962
- return null
963
- }
964
- if (asciiText.length > 35) this.recordError(errorNodePath, 'VISIBLE-STRING too long')
965
- const hex: string = Buffer.from(asciiText, 'ascii').toString('hex').padStart(35 * 2)
966
- return new TLV(0x8a, Buffer.from(hex, 'hex').subarray(0, 35))
967
- }
968
- case ItemDataType.TimeStamp: {
969
- let timestamp: number = parseInt(dataItem.value)
970
- if (isNaN(timestamp)) this.recordError(errorNodePath, 'Invalid TimeStamp value')
971
- timestamp = timestamp ? timestamp : 0
972
- return new TLV(0x91, Buffer.from(timestamp.toString(16), 'hex'))
973
- }
974
- case ItemDataType.Quality: {
975
- const bitString: string = dataItem.value
976
- let intValue: number = parseInt(bitString, 2)
977
- if (isNaN(intValue)) this.recordError(errorNodePath, 'Invalid Quality value')
978
- intValue = intValue ? intValue : 0
979
- return new TLV(0x84, Buffer.from(intValue.toString(16).padStart(3 * 2, '0'), 'hex'))
980
- }
981
- case ItemDataType.Structure: {
982
- return new TLV(0xa2, Buffer.concat(this.encodeDataTLVItem(dataItem.value).map((tlv: TLV): Buffer => Buffer.concat([tlv.bTag, tlv.bLength, tlv.bValue]))))
983
- }
984
- default: {
985
- this.recordError(errorNodePath, 'Invalid dataType, ignored')
986
- return null
987
- }
988
- }
989
- })
990
- .filter((value: TLV | null): value is TLV => !!value)
991
- }
992
-
993
- public readonly id: string = 'goose'
994
-
995
- public readonly name: string = 'IEC61850 GOOSE'
996
-
997
- public readonly nickname: string = 'GOOSE'
998
-
999
- public match(): boolean {
1000
- if (!this.prevCodecModule) return false
1001
- return this.prevCodecModule.instance.etherType.getValue() === UInt16ToHex(0x88b8)
1002
- }
1003
- }