netkitty 0.0.1

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