secs4js 0.1.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 (129) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +442 -0
  3. package/lib/core/AbstractSecsCommunicator.d.ts +76 -0
  4. package/lib/core/AbstractSecsCommunicator.d.ts.map +1 -0
  5. package/lib/core/AbstractSecsCommunicator.js +85 -0
  6. package/lib/core/AbstractSecsCommunicator.js.map +1 -0
  7. package/lib/core/AbstractSecsMessage.d.ts +36 -0
  8. package/lib/core/AbstractSecsMessage.d.ts.map +1 -0
  9. package/lib/core/AbstractSecsMessage.js +66 -0
  10. package/lib/core/AbstractSecsMessage.js.map +1 -0
  11. package/lib/core/enums/HsmsSsControlType.d.ts +59 -0
  12. package/lib/core/enums/HsmsSsControlType.d.ts.map +1 -0
  13. package/lib/core/enums/HsmsSsControlType.js +105 -0
  14. package/lib/core/enums/HsmsSsControlType.js.map +1 -0
  15. package/lib/core/enums/RejectReason.d.ts +11 -0
  16. package/lib/core/enums/RejectReason.d.ts.map +1 -0
  17. package/lib/core/enums/RejectReason.js +13 -0
  18. package/lib/core/enums/RejectReason.js.map +1 -0
  19. package/lib/core/enums/SecsItemType.d.ts +33 -0
  20. package/lib/core/enums/SecsItemType.d.ts.map +1 -0
  21. package/lib/core/enums/SecsItemType.js +22 -0
  22. package/lib/core/enums/SecsItemType.js.map +1 -0
  23. package/lib/core/enums/SelectStatus.d.ts +11 -0
  24. package/lib/core/enums/SelectStatus.d.ts.map +1 -0
  25. package/lib/core/enums/SelectStatus.js +13 -0
  26. package/lib/core/enums/SelectStatus.js.map +1 -0
  27. package/lib/core/secs2item/AbstractSecs2Item.d.ts +34 -0
  28. package/lib/core/secs2item/AbstractSecs2Item.d.ts.map +1 -0
  29. package/lib/core/secs2item/AbstractSecs2Item.js +59 -0
  30. package/lib/core/secs2item/AbstractSecs2Item.js.map +1 -0
  31. package/lib/core/secs2item/Secs2ItemAscii.d.ts +18 -0
  32. package/lib/core/secs2item/Secs2ItemAscii.d.ts.map +1 -0
  33. package/lib/core/secs2item/Secs2ItemAscii.js +27 -0
  34. package/lib/core/secs2item/Secs2ItemAscii.js.map +1 -0
  35. package/lib/core/secs2item/Secs2ItemBinary.d.ts +11 -0
  36. package/lib/core/secs2item/Secs2ItemBinary.d.ts.map +1 -0
  37. package/lib/core/secs2item/Secs2ItemBinary.js +22 -0
  38. package/lib/core/secs2item/Secs2ItemBinary.js.map +1 -0
  39. package/lib/core/secs2item/Secs2ItemBoolean.d.ts +12 -0
  40. package/lib/core/secs2item/Secs2ItemBoolean.d.ts.map +1 -0
  41. package/lib/core/secs2item/Secs2ItemBoolean.js +27 -0
  42. package/lib/core/secs2item/Secs2ItemBoolean.js.map +1 -0
  43. package/lib/core/secs2item/Secs2ItemFactory.d.ts +27 -0
  44. package/lib/core/secs2item/Secs2ItemFactory.d.ts.map +1 -0
  45. package/lib/core/secs2item/Secs2ItemFactory.js +56 -0
  46. package/lib/core/secs2item/Secs2ItemFactory.js.map +1 -0
  47. package/lib/core/secs2item/Secs2ItemList.d.ts +11 -0
  48. package/lib/core/secs2item/Secs2ItemList.d.ts.map +1 -0
  49. package/lib/core/secs2item/Secs2ItemList.js +26 -0
  50. package/lib/core/secs2item/Secs2ItemList.js.map +1 -0
  51. package/lib/core/secs2item/Secs2ItemNumeric.d.ts +14 -0
  52. package/lib/core/secs2item/Secs2ItemNumeric.d.ts.map +1 -0
  53. package/lib/core/secs2item/Secs2ItemNumeric.js +128 -0
  54. package/lib/core/secs2item/Secs2ItemNumeric.js.map +1 -0
  55. package/lib/core/secs2item/Secs2ItemParser.d.ts +12 -0
  56. package/lib/core/secs2item/Secs2ItemParser.d.ts.map +1 -0
  57. package/lib/core/secs2item/Secs2ItemParser.js +74 -0
  58. package/lib/core/secs2item/Secs2ItemParser.js.map +1 -0
  59. package/lib/gem/Clock.d.ts +21 -0
  60. package/lib/gem/Clock.d.ts.map +1 -0
  61. package/lib/gem/Clock.js +65 -0
  62. package/lib/gem/Clock.js.map +1 -0
  63. package/lib/gem/Gem.d.ts +55 -0
  64. package/lib/gem/Gem.d.ts.map +1 -0
  65. package/lib/gem/Gem.js +137 -0
  66. package/lib/gem/Gem.js.map +1 -0
  67. package/lib/helper/Secs2ItemHelper.d.ts +96 -0
  68. package/lib/helper/Secs2ItemHelper.d.ts.map +1 -0
  69. package/lib/helper/Secs2ItemHelper.js +135 -0
  70. package/lib/helper/Secs2ItemHelper.js.map +1 -0
  71. package/lib/hsms/HsmsActiveCommunicator.d.ts +29 -0
  72. package/lib/hsms/HsmsActiveCommunicator.d.ts.map +1 -0
  73. package/lib/hsms/HsmsActiveCommunicator.js +123 -0
  74. package/lib/hsms/HsmsActiveCommunicator.js.map +1 -0
  75. package/lib/hsms/HsmsCommunicator.d.ts +70 -0
  76. package/lib/hsms/HsmsCommunicator.d.ts.map +1 -0
  77. package/lib/hsms/HsmsCommunicator.js +322 -0
  78. package/lib/hsms/HsmsCommunicator.js.map +1 -0
  79. package/lib/hsms/HsmsMessage.d.ts +92 -0
  80. package/lib/hsms/HsmsMessage.d.ts.map +1 -0
  81. package/lib/hsms/HsmsMessage.js +163 -0
  82. package/lib/hsms/HsmsMessage.js.map +1 -0
  83. package/lib/hsms/HsmsPassiveCommunicator.d.ts +48 -0
  84. package/lib/hsms/HsmsPassiveCommunicator.d.ts.map +1 -0
  85. package/lib/hsms/HsmsPassiveCommunicator.js +304 -0
  86. package/lib/hsms/HsmsPassiveCommunicator.js.map +1 -0
  87. package/lib/hsms/enums/HsmsControlType.d.ts +15 -0
  88. package/lib/hsms/enums/HsmsControlType.d.ts.map +1 -0
  89. package/lib/hsms/enums/HsmsControlType.js +17 -0
  90. package/lib/hsms/enums/HsmsControlType.js.map +1 -0
  91. package/lib/hsms/enums/RejectReason.d.ts +11 -0
  92. package/lib/hsms/enums/RejectReason.d.ts.map +1 -0
  93. package/lib/hsms/enums/RejectReason.js +13 -0
  94. package/lib/hsms/enums/RejectReason.js.map +1 -0
  95. package/lib/hsms/enums/SelectStatus.d.ts +11 -0
  96. package/lib/hsms/enums/SelectStatus.d.ts.map +1 -0
  97. package/lib/hsms/enums/SelectStatus.js +13 -0
  98. package/lib/hsms/enums/SelectStatus.js.map +1 -0
  99. package/lib/index.d.ts +28 -0
  100. package/lib/index.js +29 -0
  101. package/lib/secs1/Secs1Communicator.d.ts +51 -0
  102. package/lib/secs1/Secs1Communicator.d.ts.map +1 -0
  103. package/lib/secs1/Secs1Communicator.js +342 -0
  104. package/lib/secs1/Secs1Communicator.js.map +1 -0
  105. package/lib/secs1/Secs1Message.d.ts +21 -0
  106. package/lib/secs1/Secs1Message.d.ts.map +1 -0
  107. package/lib/secs1/Secs1Message.js +77 -0
  108. package/lib/secs1/Secs1Message.js.map +1 -0
  109. package/lib/secs1/Secs1MessageBlock.d.ts +23 -0
  110. package/lib/secs1/Secs1MessageBlock.d.ts.map +1 -0
  111. package/lib/secs1/Secs1MessageBlock.js +86 -0
  112. package/lib/secs1/Secs1MessageBlock.js.map +1 -0
  113. package/lib/secs1/Secs1OnTcpIpActiveCommunicator.d.ts +23 -0
  114. package/lib/secs1/Secs1OnTcpIpActiveCommunicator.d.ts.map +1 -0
  115. package/lib/secs1/Secs1OnTcpIpActiveCommunicator.js +82 -0
  116. package/lib/secs1/Secs1OnTcpIpActiveCommunicator.js.map +1 -0
  117. package/lib/secs1/Secs1OnTcpIpPassiveCommunicator.d.ts +19 -0
  118. package/lib/secs1/Secs1OnTcpIpPassiveCommunicator.d.ts.map +1 -0
  119. package/lib/secs1/Secs1OnTcpIpPassiveCommunicator.js +49 -0
  120. package/lib/secs1/Secs1OnTcpIpPassiveCommunicator.js.map +1 -0
  121. package/lib/secs1/Secs1SerialCommunicator.d.ts +18 -0
  122. package/lib/secs1/Secs1SerialCommunicator.d.ts.map +1 -0
  123. package/lib/secs1/Secs1SerialCommunicator.js +59 -0
  124. package/lib/secs1/Secs1SerialCommunicator.js.map +1 -0
  125. package/lib/sml/SmlParser.d.ts +27 -0
  126. package/lib/sml/SmlParser.d.ts.map +1 -0
  127. package/lib/sml/SmlParser.js +184 -0
  128. package/lib/sml/SmlParser.js.map +1 -0
  129. package/package.json +53 -0
@@ -0,0 +1,66 @@
1
+ //#region src/core/AbstractSecsMessage.ts
2
+ /**
3
+ * @param stream The stream number.
4
+ * @param func The function number.
5
+ * @param wBit Whether the message is a request.
6
+ * @param body The body of the message.
7
+ * @param systemBytes The system bytes.
8
+ * @param deviceId The device ID.
9
+ */
10
+ var SecsMessage = class {
11
+ constructor(stream, func, wBit, body = null, systemBytes = 0, deviceId = 0) {
12
+ this.stream = stream;
13
+ this.func = func;
14
+ this.wBit = wBit;
15
+ this.body = body;
16
+ this.systemBytes = systemBytes;
17
+ this.deviceId = deviceId;
18
+ if (stream < 0 || stream > 127) throw new Error("Stream must be 0-127");
19
+ if (func < 0 || func > 255) throw new Error("Function must be 0-255");
20
+ }
21
+ /**
22
+ * @description Returns the SML representation of the message.
23
+ * @returns The SML representation.
24
+ */
25
+ toSml() {
26
+ const wBitStr = this.wBit ? "W" : "";
27
+ const header = `S${this.stream.toString()}F${this.func.toString()} ${wBitStr}`;
28
+ if (this.body) return `${header}\n${this.body.toSml()}.`;
29
+ return `${header}.`;
30
+ }
31
+ /**
32
+ * @description Returns the binary representation of the message.
33
+ * @returns The binary representation.
34
+ */
35
+ toBuffer() {
36
+ const header = Buffer.from([
37
+ 2,
38
+ this.stream,
39
+ this.func,
40
+ this.wBit ? 128 : 0
41
+ ]);
42
+ const body = this.body?.toBuffer() ?? Buffer.alloc(0);
43
+ const systemBytes = typeof this.systemBytes === "number" ? Buffer.from([
44
+ this.systemBytes >>> 24,
45
+ this.systemBytes >>> 16 & 255,
46
+ this.systemBytes >>> 8 & 255,
47
+ this.systemBytes & 255
48
+ ]) : this.systemBytes;
49
+ const deviceId = Buffer.from([
50
+ this.deviceId >>> 24,
51
+ this.deviceId >>> 16 & 255,
52
+ this.deviceId >>> 8 & 255,
53
+ this.deviceId & 255
54
+ ]);
55
+ return Buffer.concat([
56
+ header,
57
+ systemBytes,
58
+ deviceId,
59
+ body
60
+ ]);
61
+ }
62
+ };
63
+
64
+ //#endregion
65
+ export { SecsMessage };
66
+ //# sourceMappingURL=AbstractSecsMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractSecsMessage.js","names":["stream: number","func: number","wBit: boolean","body: AbstractSecs2Item | null"],"sources":["../../src/core/AbstractSecsMessage.ts"],"sourcesContent":["import { AbstractSecs2Item } from \"./secs2item/AbstractSecs2Item.js\";\n\n/**\n * @param stream The stream number.\n * @param func The function number.\n * @param wBit Whether the message is a request.\n * @param body The body of the message.\n * @param systemBytes The system bytes.\n * @param deviceId The device ID.\n */\nexport class SecsMessage {\n\tconstructor(\n\t\tpublic readonly stream: number,\n\t\tpublic readonly func: number,\n\t\tpublic readonly wBit: boolean,\n\t\tpublic readonly body: AbstractSecs2Item | null = null,\n\t\tpublic readonly systemBytes = 0, // Typically 4 bytes, treated as integer for convenience if it fits, or Buffer\n\t\tpublic readonly deviceId = 0,\n\t) {\n\t\tif (stream < 0 || stream > 127) throw new Error(\"Stream must be 0-127\");\n\t\tif (func < 0 || func > 255) throw new Error(\"Function must be 0-255\");\n\t}\n\n\t/**\n\t * @description Returns the SML representation of the message.\n\t * @returns The SML representation.\n\t */\n\ttoSml(): string {\n\t\tconst wBitStr = this.wBit ? \"W\" : \"\";\n\t\tconst header = `S${this.stream.toString()}F${this.func.toString()} ${wBitStr}`;\n\t\tif (this.body) {\n\t\t\treturn `${header}\\n${this.body.toSml()}.`;\n\t\t}\n\t\treturn `${header}.`;\n\t}\n\n\t/**\n\t * @description Returns the binary representation of the message.\n\t * @returns The binary representation.\n\t */\n\ttoBuffer(): Buffer {\n\t\tconst header = Buffer.from([\n\t\t\t0x02, // SML header\n\t\t\tthis.stream,\n\t\t\tthis.func,\n\t\t\tthis.wBit ? 0x80 : 0x00,\n\t\t]);\n\t\tconst body = this.body?.toBuffer() ?? Buffer.alloc(0);\n\t\tconst systemBytes =\n\t\t\ttypeof this.systemBytes === \"number\"\n\t\t\t\t? Buffer.from([\n\t\t\t\t\t\tthis.systemBytes >>> 24,\n\t\t\t\t\t\t(this.systemBytes >>> 16) & 0xff,\n\t\t\t\t\t\t(this.systemBytes >>> 8) & 0xff,\n\t\t\t\t\t\tthis.systemBytes & 0xff,\n\t\t\t\t\t])\n\t\t\t\t: this.systemBytes;\n\t\tconst deviceId = Buffer.from([\n\t\t\tthis.deviceId >>> 24,\n\t\t\t(this.deviceId >>> 16) & 0xff,\n\t\t\t(this.deviceId >>> 8) & 0xff,\n\t\t\tthis.deviceId & 0xff,\n\t\t]);\n\t\treturn Buffer.concat([header, systemBytes, deviceId, body]);\n\t}\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,cAAb,MAAyB;CACxB,YACC,AAAgBA,QAChB,AAAgBC,MAChB,AAAgBC,MAChB,AAAgBC,OAAiC,MACjD,AAAgB,cAAc,GAC9B,AAAgB,WAAW,GAC1B;EANe;EACA;EACA;EACA;EACA;EACA;AAEhB,MAAI,SAAS,KAAK,SAAS,IAAK,OAAM,IAAI,MAAM,uBAAuB;AACvE,MAAI,OAAO,KAAK,OAAO,IAAK,OAAM,IAAI,MAAM,yBAAyB;;;;;;CAOtE,QAAgB;EACf,MAAM,UAAU,KAAK,OAAO,MAAM;EAClC,MAAM,SAAS,IAAI,KAAK,OAAO,UAAU,CAAC,GAAG,KAAK,KAAK,UAAU,CAAC,GAAG;AACrE,MAAI,KAAK,KACR,QAAO,GAAG,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC;AAExC,SAAO,GAAG,OAAO;;;;;;CAOlB,WAAmB;EAClB,MAAM,SAAS,OAAO,KAAK;GAC1B;GACA,KAAK;GACL,KAAK;GACL,KAAK,OAAO,MAAO;GACnB,CAAC;EACF,MAAM,OAAO,KAAK,MAAM,UAAU,IAAI,OAAO,MAAM,EAAE;EACrD,MAAM,cACL,OAAO,KAAK,gBAAgB,WACzB,OAAO,KAAK;GACZ,KAAK,gBAAgB;GACpB,KAAK,gBAAgB,KAAM;GAC3B,KAAK,gBAAgB,IAAK;GAC3B,KAAK,cAAc;GACnB,CAAC,GACD,KAAK;EACT,MAAM,WAAW,OAAO,KAAK;GAC5B,KAAK,aAAa;GACjB,KAAK,aAAa,KAAM;GACxB,KAAK,aAAa,IAAK;GACxB,KAAK,WAAW;GAChB,CAAC;AACF,SAAO,OAAO,OAAO;GAAC;GAAQ;GAAa;GAAU;GAAK,CAAC"}
@@ -0,0 +1,59 @@
1
+ //#region src/core/enums/HsmsSsControlType.d.ts
2
+ /**
3
+ * HSMS-SS 控制类型(PType + SType 组合)
4
+ * 存储在 Header 的 Byte 4-5
5
+ */
6
+ declare class HsmsSsControlType {
7
+ readonly PType: number;
8
+ readonly SType: number;
9
+ private constructor();
10
+ static readonly Undefined: HsmsSsControlType;
11
+ static readonly Data: HsmsSsControlType;
12
+ static readonly SelectReq: HsmsSsControlType;
13
+ static readonly SelectRsp: HsmsSsControlType;
14
+ static readonly DeselectReq: HsmsSsControlType;
15
+ static readonly DeselectRsp: HsmsSsControlType;
16
+ static readonly LinktestReq: HsmsSsControlType;
17
+ static readonly LinktestRsp: HsmsSsControlType;
18
+ static readonly RejectReq: HsmsSsControlType;
19
+ static readonly SeparateReq: HsmsSsControlType;
20
+ private static readonly KnownTypes;
21
+ /**
22
+ * 从字节解析控制类型
23
+ */
24
+ static fromBytes(pType: number, sType: number): HsmsSsControlType;
25
+ /**
26
+ * 从 Header Bytes 4-5 解析
27
+ */
28
+ static fromHeaderBytes(headerBytes: Uint8Array | number[]): HsmsSsControlType;
29
+ /**
30
+ * 判断是否为数据消息
31
+ */
32
+ get isDataMessage(): boolean;
33
+ /**
34
+ * 判断是否为控制消息
35
+ */
36
+ get isControlMessage(): boolean;
37
+ get isSelectRequest(): boolean;
38
+ get isSelectResponse(): boolean;
39
+ get isLinktestRequest(): boolean;
40
+ get isRejectRequest(): boolean;
41
+ /**
42
+ * 字符串表示
43
+ */
44
+ toString(): string;
45
+ /**
46
+ * 比较两个控制类型是否相等(C# record struct 的值比较语义)
47
+ */
48
+ equals(other: HsmsSsControlType): boolean;
49
+ /**
50
+ * 支持 === 运算符的比较
51
+ */
52
+ valueOf(): {
53
+ PType: number;
54
+ SType: number;
55
+ };
56
+ }
57
+ //#endregion
58
+ export { HsmsSsControlType };
59
+ //# sourceMappingURL=HsmsSsControlType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HsmsSsControlType.d.ts","names":[],"sources":["../../../src/core/enums/HsmsSsControlType.ts"],"sourcesContent":[],"mappings":";;AAIA;;;AAoB0B,cApBb,iBAAA,CAoBa;EACA,SAAA,KAAA,EAAA,MAAA;EACE,SAAA,KAAA,EAAA,MAAA;EACA,QAAA,WAAA,CAAA;EAGA,gBAAA,SAAA,EAZF,iBAYE;EACA,gBAAA,IAAA,EAVP,iBAUO;EAGF,gBAAA,SAAA,EAVA,iBAUA;EAGE,gBAAA,SAAA,EAZF,iBAYE;EAoBqB,gBAAA,WAAA,EA/BrB,iBA+BqB;EAalC,gBAAA,WAAA,EA3Ca,iBA2Cb;EACX,gBAAA,WAAA,EAzCwB,iBAyCxB;EAyDW,gBAAA,WAAA,EAjGa,iBAiGb;EAAiB,gBAAA,SAAA,EA9FN,iBA8FM;+BA3FJ;;;;;kDAoBqB;;;;sCAalC,wBACX;;;;;;;;;;;;;;;;;;;;gBAyDW"}
@@ -0,0 +1,105 @@
1
+ //#region src/core/enums/HsmsSsControlType.ts
2
+ /**
3
+ * HSMS-SS 控制类型(PType + SType 组合)
4
+ * 存储在 Header 的 Byte 4-5
5
+ */
6
+ var HsmsSsControlType = class HsmsSsControlType {
7
+ PType;
8
+ SType;
9
+ constructor(pType, sType) {
10
+ this.PType = pType;
11
+ this.SType = sType;
12
+ }
13
+ static Undefined = new HsmsSsControlType(255, 255);
14
+ static Data = new HsmsSsControlType(0, 0);
15
+ static SelectReq = new HsmsSsControlType(0, 1);
16
+ static SelectRsp = new HsmsSsControlType(0, 2);
17
+ static DeselectReq = new HsmsSsControlType(0, 3);
18
+ static DeselectRsp = new HsmsSsControlType(0, 4);
19
+ static LinktestReq = new HsmsSsControlType(0, 5);
20
+ static LinktestRsp = new HsmsSsControlType(0, 6);
21
+ static RejectReq = new HsmsSsControlType(0, 7);
22
+ static SeparateReq = new HsmsSsControlType(0, 9);
23
+ static KnownTypes = [
24
+ HsmsSsControlType.Data,
25
+ HsmsSsControlType.SelectReq,
26
+ HsmsSsControlType.SelectRsp,
27
+ HsmsSsControlType.DeselectReq,
28
+ HsmsSsControlType.DeselectRsp,
29
+ HsmsSsControlType.LinktestReq,
30
+ HsmsSsControlType.LinktestRsp,
31
+ HsmsSsControlType.RejectReq,
32
+ HsmsSsControlType.SeparateReq
33
+ ];
34
+ /**
35
+ * 从字节解析控制类型
36
+ */
37
+ static fromBytes(pType, sType) {
38
+ for (const known of HsmsSsControlType.KnownTypes) if (known.PType === pType && known.SType === sType) return known;
39
+ return HsmsSsControlType.Undefined;
40
+ }
41
+ /**
42
+ * 从 Header Bytes 4-5 解析
43
+ */
44
+ static fromHeaderBytes(headerBytes) {
45
+ return HsmsSsControlType.fromBytes(headerBytes[4], headerBytes[5]);
46
+ }
47
+ /**
48
+ * 判断是否为数据消息
49
+ */
50
+ get isDataMessage() {
51
+ return this === HsmsSsControlType.Data;
52
+ }
53
+ /**
54
+ * 判断是否为控制消息
55
+ */
56
+ get isControlMessage() {
57
+ return !this.isDataMessage && this !== HsmsSsControlType.Undefined;
58
+ }
59
+ get isSelectRequest() {
60
+ return this === HsmsSsControlType.SelectReq;
61
+ }
62
+ get isSelectResponse() {
63
+ return this === HsmsSsControlType.SelectRsp;
64
+ }
65
+ get isLinktestRequest() {
66
+ return this === HsmsSsControlType.LinktestReq;
67
+ }
68
+ get isRejectRequest() {
69
+ return this === HsmsSsControlType.RejectReq;
70
+ }
71
+ /**
72
+ * 字符串表示
73
+ */
74
+ toString() {
75
+ if (this === HsmsSsControlType.Data) return "DATA";
76
+ if (this === HsmsSsControlType.SelectReq) return "SELECT.req";
77
+ if (this === HsmsSsControlType.SelectRsp) return "SELECT.rsp";
78
+ if (this === HsmsSsControlType.DeselectReq) return "DESELECT.req";
79
+ if (this === HsmsSsControlType.DeselectRsp) return "DESELECT.rsp";
80
+ if (this === HsmsSsControlType.LinktestReq) return "LINKTEST.req";
81
+ if (this === HsmsSsControlType.LinktestRsp) return "LINKTEST.rsp";
82
+ if (this === HsmsSsControlType.RejectReq) return "REJECT.req";
83
+ if (this === HsmsSsControlType.SeparateReq) return "SEPARATE.req";
84
+ return `Unknown(${this.PType.toString(16).toUpperCase()},${this.SType.toString(16).toUpperCase()})`;
85
+ }
86
+ /**
87
+ * 比较两个控制类型是否相等(C# record struct 的值比较语义)
88
+ */
89
+ equals(other) {
90
+ return this.PType === other.PType && this.SType === other.SType;
91
+ }
92
+ /**
93
+ * 支持 === 运算符的比较
94
+ */
95
+ valueOf() {
96
+ return {
97
+ PType: this.PType,
98
+ SType: this.SType
99
+ };
100
+ }
101
+ };
102
+
103
+ //#endregion
104
+ export { HsmsSsControlType };
105
+ //# sourceMappingURL=HsmsSsControlType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HsmsSsControlType.js","names":[],"sources":["../../../src/core/enums/HsmsSsControlType.ts"],"sourcesContent":["/**\n * HSMS-SS 控制类型(PType + SType 组合)\n * 存储在 Header 的 Byte 4-5\n */\nexport class HsmsSsControlType {\n\t// 只读实例属性\n\treadonly PType: number;\n\treadonly SType: number;\n\n\t// 私有构造函数,防止外部直接实例化\n\tprivate constructor(pType: number, sType: number) {\n\t\tthis.PType = pType;\n\t\tthis.SType = sType;\n\t}\n\n\t// ========== 静态只读实例 ==========\n\n\t// 未定义类型\n\tstatic readonly Undefined = new HsmsSsControlType(0xff, 0xff);\n\n\t// 数据消息(携带 SECS-II 数据)\n\tstatic readonly Data = new HsmsSsControlType(0x00, 0x00);\n\n\t// 连接控制消息\n\tstatic readonly SelectReq = new HsmsSsControlType(0x00, 0x01);\n\tstatic readonly SelectRsp = new HsmsSsControlType(0x00, 0x02);\n\tstatic readonly DeselectReq = new HsmsSsControlType(0x00, 0x03);\n\tstatic readonly DeselectRsp = new HsmsSsControlType(0x00, 0x04);\n\n\t// 链路测试消息\n\tstatic readonly LinktestReq = new HsmsSsControlType(0x00, 0x05);\n\tstatic readonly LinktestRsp = new HsmsSsControlType(0x00, 0x06);\n\n\t// 拒绝消息\n\tstatic readonly RejectReq = new HsmsSsControlType(0x00, 0x07);\n\n\t// 分离请求\n\tstatic readonly SeparateReq = new HsmsSsControlType(0x00, 0x09);\n\n\t// 私有已知类型数组\n\tprivate static readonly KnownTypes: HsmsSsControlType[] = [\n\t\tHsmsSsControlType.Data,\n\t\tHsmsSsControlType.SelectReq,\n\t\tHsmsSsControlType.SelectRsp,\n\t\tHsmsSsControlType.DeselectReq,\n\t\tHsmsSsControlType.DeselectRsp,\n\t\tHsmsSsControlType.LinktestReq,\n\t\tHsmsSsControlType.LinktestRsp,\n\t\tHsmsSsControlType.RejectReq,\n\t\tHsmsSsControlType.SeparateReq,\n\t];\n\n\t// ========== 静态工厂方法 ==========\n\n\t/**\n\t * 从字节解析控制类型\n\t */\n\tstatic fromBytes(pType: number, sType: number): HsmsSsControlType {\n\t\tfor (const known of HsmsSsControlType.KnownTypes) {\n\t\t\tif (known.PType === pType && known.SType === sType) {\n\t\t\t\treturn known;\n\t\t\t}\n\t\t}\n\t\treturn HsmsSsControlType.Undefined;\n\t}\n\n\t/**\n\t * 从 Header Bytes 4-5 解析\n\t */\n\tstatic fromHeaderBytes(\n\t\theaderBytes: Uint8Array | number[],\n\t): HsmsSsControlType {\n\t\treturn HsmsSsControlType.fromBytes(headerBytes[4], headerBytes[5]);\n\t}\n\n\t// ========== 实例方法 ==========\n\n\t/**\n\t * 判断是否为数据消息\n\t */\n\tget isDataMessage(): boolean {\n\t\treturn this === HsmsSsControlType.Data;\n\t}\n\n\t/**\n\t * 判断是否为控制消息\n\t */\n\tget isControlMessage(): boolean {\n\t\treturn !this.isDataMessage && this !== HsmsSsControlType.Undefined;\n\t}\n\n\tget isSelectRequest(): boolean {\n\t\treturn this === HsmsSsControlType.SelectReq;\n\t}\n\n\tget isSelectResponse(): boolean {\n\t\treturn this === HsmsSsControlType.SelectRsp;\n\t}\n\n\tget isLinktestRequest(): boolean {\n\t\treturn this === HsmsSsControlType.LinktestReq;\n\t}\n\n\tget isRejectRequest(): boolean {\n\t\treturn this === HsmsSsControlType.RejectReq;\n\t}\n\n\t/**\n\t * 字符串表示\n\t */\n\ttoString(): string {\n\t\tif (this === HsmsSsControlType.Data) return \"DATA\";\n\t\tif (this === HsmsSsControlType.SelectReq) return \"SELECT.req\";\n\t\tif (this === HsmsSsControlType.SelectRsp) return \"SELECT.rsp\";\n\t\tif (this === HsmsSsControlType.DeselectReq) return \"DESELECT.req\";\n\t\tif (this === HsmsSsControlType.DeselectRsp) return \"DESELECT.rsp\";\n\t\tif (this === HsmsSsControlType.LinktestReq) return \"LINKTEST.req\";\n\t\tif (this === HsmsSsControlType.LinktestRsp) return \"LINKTEST.rsp\";\n\t\tif (this === HsmsSsControlType.RejectReq) return \"REJECT.req\";\n\t\tif (this === HsmsSsControlType.SeparateReq) return \"SEPARATE.req\";\n\t\treturn `Unknown(${this.PType.toString(16).toUpperCase()},${this.SType.toString(16).toUpperCase()})`;\n\t}\n\n\t// ========== 值相等性比较 ==========\n\n\t/**\n\t * 比较两个控制类型是否相等(C# record struct 的值比较语义)\n\t */\n\tequals(other: HsmsSsControlType): boolean {\n\t\treturn this.PType === other.PType && this.SType === other.SType;\n\t}\n\n\t/**\n\t * 支持 === 运算符的比较\n\t */\n\tvalueOf(): { PType: number; SType: number } {\n\t\treturn { PType: this.PType, SType: this.SType };\n\t}\n}\n"],"mappings":";;;;;AAIA,IAAa,oBAAb,MAAa,kBAAkB;CAE9B,AAAS;CACT,AAAS;CAGT,AAAQ,YAAY,OAAe,OAAe;AACjD,OAAK,QAAQ;AACb,OAAK,QAAQ;;CAMd,OAAgB,YAAY,IAAI,kBAAkB,KAAM,IAAK;CAG7D,OAAgB,OAAO,IAAI,kBAAkB,GAAM,EAAK;CAGxD,OAAgB,YAAY,IAAI,kBAAkB,GAAM,EAAK;CAC7D,OAAgB,YAAY,IAAI,kBAAkB,GAAM,EAAK;CAC7D,OAAgB,cAAc,IAAI,kBAAkB,GAAM,EAAK;CAC/D,OAAgB,cAAc,IAAI,kBAAkB,GAAM,EAAK;CAG/D,OAAgB,cAAc,IAAI,kBAAkB,GAAM,EAAK;CAC/D,OAAgB,cAAc,IAAI,kBAAkB,GAAM,EAAK;CAG/D,OAAgB,YAAY,IAAI,kBAAkB,GAAM,EAAK;CAG7D,OAAgB,cAAc,IAAI,kBAAkB,GAAM,EAAK;CAG/D,OAAwB,aAAkC;EACzD,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB,kBAAkB;EAClB;;;;CAOD,OAAO,UAAU,OAAe,OAAkC;AACjE,OAAK,MAAM,SAAS,kBAAkB,WACrC,KAAI,MAAM,UAAU,SAAS,MAAM,UAAU,MAC5C,QAAO;AAGT,SAAO,kBAAkB;;;;;CAM1B,OAAO,gBACN,aACoB;AACpB,SAAO,kBAAkB,UAAU,YAAY,IAAI,YAAY,GAAG;;;;;CAQnE,IAAI,gBAAyB;AAC5B,SAAO,SAAS,kBAAkB;;;;;CAMnC,IAAI,mBAA4B;AAC/B,SAAO,CAAC,KAAK,iBAAiB,SAAS,kBAAkB;;CAG1D,IAAI,kBAA2B;AAC9B,SAAO,SAAS,kBAAkB;;CAGnC,IAAI,mBAA4B;AAC/B,SAAO,SAAS,kBAAkB;;CAGnC,IAAI,oBAA6B;AAChC,SAAO,SAAS,kBAAkB;;CAGnC,IAAI,kBAA2B;AAC9B,SAAO,SAAS,kBAAkB;;;;;CAMnC,WAAmB;AAClB,MAAI,SAAS,kBAAkB,KAAM,QAAO;AAC5C,MAAI,SAAS,kBAAkB,UAAW,QAAO;AACjD,MAAI,SAAS,kBAAkB,UAAW,QAAO;AACjD,MAAI,SAAS,kBAAkB,YAAa,QAAO;AACnD,MAAI,SAAS,kBAAkB,YAAa,QAAO;AACnD,MAAI,SAAS,kBAAkB,YAAa,QAAO;AACnD,MAAI,SAAS,kBAAkB,YAAa,QAAO;AACnD,MAAI,SAAS,kBAAkB,UAAW,QAAO;AACjD,MAAI,SAAS,kBAAkB,YAAa,QAAO;AACnD,SAAO,WAAW,KAAK,MAAM,SAAS,GAAG,CAAC,aAAa,CAAC,GAAG,KAAK,MAAM,SAAS,GAAG,CAAC,aAAa,CAAC;;;;;CAQlG,OAAO,OAAmC;AACzC,SAAO,KAAK,UAAU,MAAM,SAAS,KAAK,UAAU,MAAM;;;;;CAM3D,UAA4C;AAC3C,SAAO;GAAE,OAAO,KAAK;GAAO,OAAO,KAAK;GAAO"}
@@ -0,0 +1,11 @@
1
+ //#region src/core/enums/RejectReason.d.ts
2
+ declare enum RejectReason {
3
+ Unknown = 255,
4
+ NotSupportTypeS = 1,
5
+ NotSupportTypeP = 2,
6
+ TransactionNotOpen = 3,
7
+ NotSelected = 4,
8
+ }
9
+ //#endregion
10
+ export { RejectReason };
11
+ //# sourceMappingURL=RejectReason.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RejectReason.d.ts","names":[],"sources":["../../../src/core/enums/RejectReason.ts"],"sourcesContent":[],"mappings":";aAAY,YAAA;EAAA,OAAA,GAAA,GAAA"}
@@ -0,0 +1,13 @@
1
+ //#region src/core/enums/RejectReason.ts
2
+ let RejectReason = /* @__PURE__ */ function(RejectReason$1) {
3
+ RejectReason$1[RejectReason$1["Unknown"] = 255] = "Unknown";
4
+ RejectReason$1[RejectReason$1["NotSupportTypeS"] = 1] = "NotSupportTypeS";
5
+ RejectReason$1[RejectReason$1["NotSupportTypeP"] = 2] = "NotSupportTypeP";
6
+ RejectReason$1[RejectReason$1["TransactionNotOpen"] = 3] = "TransactionNotOpen";
7
+ RejectReason$1[RejectReason$1["NotSelected"] = 4] = "NotSelected";
8
+ return RejectReason$1;
9
+ }({});
10
+
11
+ //#endregion
12
+ export { RejectReason };
13
+ //# sourceMappingURL=RejectReason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RejectReason.js","names":[],"sources":["../../../src/core/enums/RejectReason.ts"],"sourcesContent":["export enum RejectReason {\n\tUnknown = 0xff,\n\tNotSupportTypeS = 0x01,\n\tNotSupportTypeP = 0x02,\n\tTransactionNotOpen = 0x03,\n\tNotSelected = 0x04,\n}\n"],"mappings":";AAAA,IAAY,wDAAL;AACN;AACA;AACA;AACA;AACA"}
@@ -0,0 +1,33 @@
1
+ //#region src/core/enums/SecsItemType.d.ts
2
+ declare enum SecsItemType {
3
+ L = 0,
4
+ // List
5
+ B = 32,
6
+ // Binary
7
+ BOOLEAN = 36,
8
+ // Boolean
9
+ A = 64,
10
+ // ASCII
11
+ I8 = 96,
12
+ // Integer 8
13
+ I1 = 100,
14
+ // Integer 1
15
+ I2 = 104,
16
+ // Integer 2
17
+ I4 = 112,
18
+ // Integer 4
19
+ F8 = 128,
20
+ // Floating Point 8
21
+ F4 = 144,
22
+ // Floating Point 4
23
+ U8 = 160,
24
+ // Unsigned Integer 8
25
+ U1 = 164,
26
+ // Unsigned Integer 1
27
+ U2 = 168,
28
+ // Unsigned Integer 2
29
+ U4 = 176,
30
+ }
31
+ //#endregion
32
+ export { SecsItemType };
33
+ //# sourceMappingURL=SecsItemType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecsItemType.d.ts","names":[],"sources":["../../../src/core/enums/SecsItemType.ts"],"sourcesContent":[],"mappings":";aAAY,YAAA;EAAA,CAAA,GAAA,CAAA;EAAA"}
@@ -0,0 +1,22 @@
1
+ //#region src/core/enums/SecsItemType.ts
2
+ let SecsItemType = /* @__PURE__ */ function(SecsItemType$1) {
3
+ SecsItemType$1[SecsItemType$1["L"] = 0] = "L";
4
+ SecsItemType$1[SecsItemType$1["B"] = 32] = "B";
5
+ SecsItemType$1[SecsItemType$1["BOOLEAN"] = 36] = "BOOLEAN";
6
+ SecsItemType$1[SecsItemType$1["A"] = 64] = "A";
7
+ SecsItemType$1[SecsItemType$1["I8"] = 96] = "I8";
8
+ SecsItemType$1[SecsItemType$1["I1"] = 100] = "I1";
9
+ SecsItemType$1[SecsItemType$1["I2"] = 104] = "I2";
10
+ SecsItemType$1[SecsItemType$1["I4"] = 112] = "I4";
11
+ SecsItemType$1[SecsItemType$1["F8"] = 128] = "F8";
12
+ SecsItemType$1[SecsItemType$1["F4"] = 144] = "F4";
13
+ SecsItemType$1[SecsItemType$1["U8"] = 160] = "U8";
14
+ SecsItemType$1[SecsItemType$1["U1"] = 164] = "U1";
15
+ SecsItemType$1[SecsItemType$1["U2"] = 168] = "U2";
16
+ SecsItemType$1[SecsItemType$1["U4"] = 176] = "U4";
17
+ return SecsItemType$1;
18
+ }({});
19
+
20
+ //#endregion
21
+ export { SecsItemType };
22
+ //# sourceMappingURL=SecsItemType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecsItemType.js","names":[],"sources":["../../../src/core/enums/SecsItemType.ts"],"sourcesContent":["export enum SecsItemType {\n L = 0x00, // List\n B = 0x20, // Binary\n BOOLEAN = 0x24, // Boolean\n A = 0x40, // ASCII\n I8 = 0x60, // Integer 8\n I1 = 0x64, // Integer 1\n I2 = 0x68, // Integer 2\n I4 = 0x70, // Integer 4\n F8 = 0x80, // Floating Point 8\n F4 = 0x90, // Floating Point 4\n U8 = 0xa0, // Unsigned Integer 8\n U1 = 0xa4, // Unsigned Integer 1\n U2 = 0xa8, // Unsigned Integer 2\n U4 = 0xb0, // Unsigned Integer 4\n}\n"],"mappings":";AAAA,IAAY,wDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -0,0 +1,11 @@
1
+ //#region src/core/enums/SelectStatus.d.ts
2
+ declare enum SelectStatus {
3
+ Unknown = 255,
4
+ Success = 0,
5
+ Activated = 1,
6
+ NotReady = 2,
7
+ AlreadyUsed = 3,
8
+ }
9
+ //#endregion
10
+ export { SelectStatus };
11
+ //# sourceMappingURL=SelectStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectStatus.d.ts","names":[],"sources":["../../../src/core/enums/SelectStatus.ts"],"sourcesContent":[],"mappings":";aAAY,YAAA;EAAA,OAAA,GAAA,GAAA"}
@@ -0,0 +1,13 @@
1
+ //#region src/core/enums/SelectStatus.ts
2
+ let SelectStatus = /* @__PURE__ */ function(SelectStatus$1) {
3
+ SelectStatus$1[SelectStatus$1["Unknown"] = 255] = "Unknown";
4
+ SelectStatus$1[SelectStatus$1["Success"] = 0] = "Success";
5
+ SelectStatus$1[SelectStatus$1["Activated"] = 1] = "Activated";
6
+ SelectStatus$1[SelectStatus$1["NotReady"] = 2] = "NotReady";
7
+ SelectStatus$1[SelectStatus$1["AlreadyUsed"] = 3] = "AlreadyUsed";
8
+ return SelectStatus$1;
9
+ }({});
10
+
11
+ //#endregion
12
+ export { SelectStatus };
13
+ //# sourceMappingURL=SelectStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectStatus.js","names":[],"sources":["../../../src/core/enums/SelectStatus.ts"],"sourcesContent":["export enum SelectStatus {\n\tUnknown = 0xff,\n\tSuccess = 0x00,\n\tActivated = 0x01,\n\tNotReady = 0x02,\n\tAlreadyUsed = 0x03,\n}\n"],"mappings":";AAAA,IAAY,wDAAL;AACN;AACA;AACA;AACA;AACA"}
@@ -0,0 +1,34 @@
1
+ import { SecsItemType } from "../enums/SecsItemType.js";
2
+
3
+ //#region src/core/secs2item/AbstractSecs2Item.d.ts
4
+ declare abstract class AbstractSecs2Item<T = unknown> {
5
+ readonly type: SecsItemType;
6
+ protected readonly _value: T;
7
+ [index: number]: unknown;
8
+ constructor(type: SecsItemType, _value: T);
9
+ /**
10
+ * @description Returns the value of the item.
11
+ */
12
+ get value(): T;
13
+ /**
14
+ * @description Returns the value of the item at the given index.
15
+ * @param index The index of the value to return.
16
+ * @returns The value of the item at the given index.
17
+ */
18
+ protected getByIndex(index: number): unknown;
19
+ /**
20
+ * @description Returns the SML representation of the item.
21
+ */
22
+ abstract toSml(): string;
23
+ /**
24
+ * @description Returns the SECS-II encoded buffer of the item.
25
+ */
26
+ abstract toBuffer(): Buffer;
27
+ /**
28
+ * @description Helper to create the header (Type + LengthBytes)
29
+ */
30
+ protected createHeader(length: number): Buffer;
31
+ }
32
+ //#endregion
33
+ export { AbstractSecs2Item };
34
+ //# sourceMappingURL=AbstractSecs2Item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractSecs2Item.d.ts","names":[],"sources":["../../../src/core/secs2item/AbstractSecs2Item.ts"],"sourcesContent":[],"mappings":";;;uBAEsB;iBAIE;EAJF,mBAAA,MAAiB,EAKV,CALU;EAIf,CAAA,KAAA,EAAA,MAAA,CAAA,EAAA,OAAA;EACK,WAAA,CAAA,IAAA,EADL,YACK,EAAA,MAAA,EAAA,CAAA;EADL;;;EAgDF,IAAA,KAAA,CAAA,CAAA,EA7BR,CA6BQ;EAKmB;;;;;;;;;;;;;uBALnB;;;;0CAKmB"}
@@ -0,0 +1,59 @@
1
+ //#region src/core/secs2item/AbstractSecs2Item.ts
2
+ var AbstractSecs2Item = class {
3
+ constructor(type, _value) {
4
+ this.type = type;
5
+ this._value = _value;
6
+ return new Proxy(this, { get: (target, prop, receiver) => {
7
+ if (typeof prop === "string") {
8
+ const index = Number(prop);
9
+ if (Number.isInteger(index) && index >= 0) return target.getByIndex(index);
10
+ }
11
+ return Reflect.get(target, prop, receiver);
12
+ } });
13
+ }
14
+ /**
15
+ * @description Returns the value of the item.
16
+ */
17
+ get value() {
18
+ return this._value;
19
+ }
20
+ /**
21
+ * @description Returns the value of the item at the given index.
22
+ * @param index The index of the value to return.
23
+ * @returns The value of the item at the given index.
24
+ */
25
+ getByIndex(index) {
26
+ const v = this._value;
27
+ if (Array.isArray(v) || Buffer.isBuffer(v) || typeof v === "string") return v[index];
28
+ if (index === 0) return v;
29
+ }
30
+ /**
31
+ * @description Helper to create the header (Type + LengthBytes)
32
+ */
33
+ createHeader(length) {
34
+ let headerByte = this.type;
35
+ let lengthBytes;
36
+ if (length > 16777215) throw new Error(`Length ${length.toString()} is too large for SECS item`);
37
+ if (length > 65535) {
38
+ headerByte |= 3;
39
+ lengthBytes = Buffer.alloc(4);
40
+ lengthBytes.writeUInt8(headerByte, 0);
41
+ lengthBytes.writeUIntBE(length, 1, 3);
42
+ } else if (length > 255) {
43
+ headerByte |= 2;
44
+ lengthBytes = Buffer.alloc(3);
45
+ lengthBytes.writeUInt8(headerByte, 0);
46
+ lengthBytes.writeUInt16BE(length, 1);
47
+ } else {
48
+ headerByte |= 1;
49
+ lengthBytes = Buffer.alloc(2);
50
+ lengthBytes.writeUInt8(headerByte, 0);
51
+ lengthBytes.writeUInt8(length, 1);
52
+ }
53
+ return lengthBytes;
54
+ }
55
+ };
56
+
57
+ //#endregion
58
+ export { AbstractSecs2Item };
59
+ //# sourceMappingURL=AbstractSecs2Item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractSecs2Item.js","names":["type: SecsItemType","_value: T","lengthBytes: Buffer"],"sources":["../../../src/core/secs2item/AbstractSecs2Item.ts"],"sourcesContent":["import { SecsItemType } from \"../enums/SecsItemType.js\";\n\nexport abstract class AbstractSecs2Item<T = unknown> {\n\t[index: number]: unknown;\n\n\tconstructor(\n\t\tpublic readonly type: SecsItemType,\n\t\tprotected readonly _value: T,\n\t) {\n\t\treturn new Proxy(this, {\n\t\t\tget: (target, prop, receiver) => {\n\t\t\t\tif (typeof prop === \"string\") {\n\t\t\t\t\tconst index = Number(prop);\n\t\t\t\t\tif (Number.isInteger(index) && index >= 0) {\n\t\t\t\t\t\treturn target.getByIndex(index);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn Reflect.get(target, prop, receiver);\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * @description Returns the value of the item.\n\t */\n\tget value(): T {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * @description Returns the value of the item at the given index.\n\t * @param index The index of the value to return.\n\t * @returns The value of the item at the given index.\n\t */\n\tprotected getByIndex(index: number): unknown {\n\t\tconst v = this._value;\n\t\tif (Array.isArray(v) || Buffer.isBuffer(v) || typeof v === \"string\") {\n\t\t\treturn v[index];\n\t\t}\n\t\t// Scalar value\n\t\tif (index === 0) {\n\t\t\treturn v;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * @description Returns the SML representation of the item.\n\t */\n\tabstract toSml(): string;\n\n\t/**\n\t * @description Returns the SECS-II encoded buffer of the item.\n\t */\n\tabstract toBuffer(): Buffer;\n\n\t/**\n\t * @description Helper to create the header (Type + LengthBytes)\n\t */\n\tprotected createHeader(length: number): Buffer {\n\t\tlet headerByte = this.type;\n\t\tlet lengthBytes: Buffer;\n\n\t\tif (length > 0xffffff) {\n\t\t\tthrow new Error(`Length ${length.toString()} is too large for SECS item`);\n\t\t}\n\n\t\tif (length > 0xffff) {\n\t\t\t// 3 bytes length\n\t\t\theaderByte |= 0x03;\n\t\t\tlengthBytes = Buffer.alloc(4);\n\t\t\tlengthBytes.writeUInt8(headerByte, 0);\n\t\t\tlengthBytes.writeUIntBE(length, 1, 3);\n\t\t} else if (length > 0xff) {\n\t\t\t// 2 bytes length\n\t\t\theaderByte |= 0x02;\n\t\t\tlengthBytes = Buffer.alloc(3);\n\t\t\tlengthBytes.writeUInt8(headerByte, 0);\n\t\t\tlengthBytes.writeUInt16BE(length, 1);\n\t\t} else {\n\t\t\t// 1 byte length\n\t\t\theaderByte |= 0x01;\n\t\t\tlengthBytes = Buffer.alloc(2);\n\t\t\tlengthBytes.writeUInt8(headerByte, 0);\n\t\t\tlengthBytes.writeUInt8(length, 1);\n\t\t}\n\t\treturn lengthBytes;\n\t}\n}\n"],"mappings":";AAEA,IAAsB,oBAAtB,MAAqD;CAGpD,YACC,AAAgBA,MAChB,AAAmBC,QAClB;EAFe;EACG;AAEnB,SAAO,IAAI,MAAM,MAAM,EACtB,MAAM,QAAQ,MAAM,aAAa;AAChC,OAAI,OAAO,SAAS,UAAU;IAC7B,MAAM,QAAQ,OAAO,KAAK;AAC1B,QAAI,OAAO,UAAU,MAAM,IAAI,SAAS,EACvC,QAAO,OAAO,WAAW,MAAM;;AAGjC,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;KAE3C,CAAC;;;;;CAMH,IAAI,QAAW;AACd,SAAO,KAAK;;;;;;;CAQb,AAAU,WAAW,OAAwB;EAC5C,MAAM,IAAI,KAAK;AACf,MAAI,MAAM,QAAQ,EAAE,IAAI,OAAO,SAAS,EAAE,IAAI,OAAO,MAAM,SAC1D,QAAO,EAAE;AAGV,MAAI,UAAU,EACb,QAAO;;;;;CAkBT,AAAU,aAAa,QAAwB;EAC9C,IAAI,aAAa,KAAK;EACtB,IAAIC;AAEJ,MAAI,SAAS,SACZ,OAAM,IAAI,MAAM,UAAU,OAAO,UAAU,CAAC,6BAA6B;AAG1E,MAAI,SAAS,OAAQ;AAEpB,iBAAc;AACd,iBAAc,OAAO,MAAM,EAAE;AAC7B,eAAY,WAAW,YAAY,EAAE;AACrC,eAAY,YAAY,QAAQ,GAAG,EAAE;aAC3B,SAAS,KAAM;AAEzB,iBAAc;AACd,iBAAc,OAAO,MAAM,EAAE;AAC7B,eAAY,WAAW,YAAY,EAAE;AACrC,eAAY,cAAc,QAAQ,EAAE;SAC9B;AAEN,iBAAc;AACd,iBAAc,OAAO,MAAM,EAAE;AAC7B,eAAY,WAAW,YAAY,EAAE;AACrC,eAAY,WAAW,QAAQ,EAAE;;AAElC,SAAO"}
@@ -0,0 +1,18 @@
1
+ import { AbstractSecs2Item } from "./AbstractSecs2Item.js";
2
+
3
+ //#region src/core/secs2item/Secs2ItemAscii.d.ts
4
+
5
+ /**
6
+ * @description
7
+ * ASCII string item is a string item that contains only ASCII characters.
8
+ * @example
9
+ * new Secs2ItemAscii("Hello World");
10
+ */
11
+ declare class Secs2ItemAscii extends AbstractSecs2Item<string> {
12
+ constructor(value: string);
13
+ toSml(): string;
14
+ toBuffer(): Buffer;
15
+ }
16
+ //#endregion
17
+ export { Secs2ItemAscii };
18
+ //# sourceMappingURL=Secs2ItemAscii.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemAscii.d.ts","names":[],"sources":["../../../src/core/secs2item/Secs2ItemAscii.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;;;;cAAa,cAAA,SAAuB;;;cASd"}
@@ -0,0 +1,27 @@
1
+ import { AbstractSecs2Item } from "./AbstractSecs2Item.js";
2
+ import { SecsItemType } from "../enums/SecsItemType.js";
3
+
4
+ //#region src/core/secs2item/Secs2ItemAscii.ts
5
+ /**
6
+ * @description
7
+ * ASCII string item is a string item that contains only ASCII characters.
8
+ * @example
9
+ * new Secs2ItemAscii("Hello World");
10
+ */
11
+ var Secs2ItemAscii = class extends AbstractSecs2Item {
12
+ constructor(value) {
13
+ super(SecsItemType.A, value);
14
+ }
15
+ toSml() {
16
+ return `<A [${this._value.length}] "${this._value}">`;
17
+ }
18
+ toBuffer() {
19
+ const valueBuffer = Buffer.from(this._value, "ascii");
20
+ const header = this.createHeader(valueBuffer.length);
21
+ return Buffer.concat([header, valueBuffer]);
22
+ }
23
+ };
24
+
25
+ //#endregion
26
+ export { Secs2ItemAscii };
27
+ //# sourceMappingURL=Secs2ItemAscii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemAscii.js","names":[],"sources":["../../../src/core/secs2item/Secs2ItemAscii.ts"],"sourcesContent":["import { SecsItemType } from \"../enums/SecsItemType.js\";\nimport { AbstractSecs2Item } from \"./AbstractSecs2Item.js\";\n\n/**\n * @description\n * ASCII string item is a string item that contains only ASCII characters.\n * @example\n * new Secs2ItemAscii(\"Hello World\");\n */\nexport class Secs2ItemAscii extends AbstractSecs2Item<string> {\n\tconstructor(value: string) {\n\t\tsuper(SecsItemType.A, value);\n\t}\n\n\toverride toSml(): string {\n\t\treturn `<A [${this._value.length}] \"${this._value}\">`;\n\t}\n\n\toverride toBuffer(): Buffer {\n\t\tconst valueBuffer = Buffer.from(this._value, \"ascii\");\n\t\tconst header = this.createHeader(valueBuffer.length);\n\t\treturn Buffer.concat([header, valueBuffer]);\n\t}\n}\n"],"mappings":";;;;;;;;;;AASA,IAAa,iBAAb,cAAoC,kBAA0B;CAC7D,YAAY,OAAe;AAC1B,QAAM,aAAa,GAAG,MAAM;;CAG7B,AAAS,QAAgB;AACxB,SAAO,OAAO,KAAK,OAAO,OAAO,KAAK,KAAK,OAAO;;CAGnD,AAAS,WAAmB;EAC3B,MAAM,cAAc,OAAO,KAAK,KAAK,QAAQ,QAAQ;EACrD,MAAM,SAAS,KAAK,aAAa,YAAY,OAAO;AACpD,SAAO,OAAO,OAAO,CAAC,QAAQ,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { AbstractSecs2Item } from "./AbstractSecs2Item.js";
2
+
3
+ //#region src/core/secs2item/Secs2ItemBinary.d.ts
4
+ declare class Secs2ItemBinary extends AbstractSecs2Item<Buffer> {
5
+ constructor(value: Buffer | number[]);
6
+ toSml(): string;
7
+ toBuffer(): Buffer;
8
+ }
9
+ //#endregion
10
+ export { Secs2ItemBinary };
11
+ //# sourceMappingURL=Secs2ItemBinary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemBinary.d.ts","names":[],"sources":["../../../src/core/secs2item/Secs2ItemBinary.ts"],"sourcesContent":[],"mappings":";;;cAGa,eAAA,SAAwB,kBAAkB;qBACnC;EADP,KAAA,CAAA,CAAA,EAAA,MAAA;EAA0C,QAAA,CAAA,CAAA,EAajC,MAbiC"}
@@ -0,0 +1,22 @@
1
+ import { AbstractSecs2Item } from "./AbstractSecs2Item.js";
2
+ import { SecsItemType } from "../enums/SecsItemType.js";
3
+
4
+ //#region src/core/secs2item/Secs2ItemBinary.ts
5
+ var Secs2ItemBinary = class extends AbstractSecs2Item {
6
+ constructor(value) {
7
+ super(SecsItemType.B, Buffer.isBuffer(value) ? value : Buffer.from(value));
8
+ }
9
+ toSml() {
10
+ const hex = [];
11
+ for (const byte of this._value) hex.push("0x" + byte.toString(16).toUpperCase().padStart(2, "0"));
12
+ return `<B [${this._value.length}] ${hex.join(" ")}>`;
13
+ }
14
+ toBuffer() {
15
+ const header = this.createHeader(this._value.length);
16
+ return Buffer.concat([header, this._value]);
17
+ }
18
+ };
19
+
20
+ //#endregion
21
+ export { Secs2ItemBinary };
22
+ //# sourceMappingURL=Secs2ItemBinary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemBinary.js","names":[],"sources":["../../../src/core/secs2item/Secs2ItemBinary.ts"],"sourcesContent":["import { SecsItemType } from \"../enums/SecsItemType.js\";\nimport { AbstractSecs2Item } from \"./AbstractSecs2Item.js\";\n\nexport class Secs2ItemBinary extends AbstractSecs2Item<Buffer> {\n\tconstructor(value: Buffer | number[]) {\n\t\tsuper(SecsItemType.B, Buffer.isBuffer(value) ? value : Buffer.from(value));\n\t}\n\n\toverride toSml(): string {\n\t\tconst hex = [];\n\t\tfor (const byte of this._value) {\n\t\t\thex.push(\"0x\" + byte.toString(16).toUpperCase().padStart(2, \"0\"));\n\t\t}\n\t\treturn `<B [${this._value.length}] ${hex.join(\" \")}>`;\n\t}\n\n\toverride toBuffer(): Buffer {\n\t\tconst header = this.createHeader(this._value.length);\n\t\treturn Buffer.concat([header, this._value]);\n\t}\n}\n"],"mappings":";;;;AAGA,IAAa,kBAAb,cAAqC,kBAA0B;CAC9D,YAAY,OAA0B;AACrC,QAAM,aAAa,GAAG,OAAO,SAAS,MAAM,GAAG,QAAQ,OAAO,KAAK,MAAM,CAAC;;CAG3E,AAAS,QAAgB;EACxB,MAAM,MAAM,EAAE;AACd,OAAK,MAAM,QAAQ,KAAK,OACvB,KAAI,KAAK,OAAO,KAAK,SAAS,GAAG,CAAC,aAAa,CAAC,SAAS,GAAG,IAAI,CAAC;AAElE,SAAO,OAAO,KAAK,OAAO,OAAO,IAAI,IAAI,KAAK,IAAI,CAAC;;CAGpD,AAAS,WAAmB;EAC3B,MAAM,SAAS,KAAK,aAAa,KAAK,OAAO,OAAO;AACpD,SAAO,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { AbstractSecs2Item } from "./AbstractSecs2Item.js";
2
+
3
+ //#region src/core/secs2item/Secs2ItemBoolean.d.ts
4
+ declare class Secs2ItemBoolean extends AbstractSecs2Item<boolean | boolean[]> {
5
+ constructor(value: boolean | boolean[]);
6
+ get valueAsArray(): boolean[];
7
+ toSml(): string;
8
+ toBuffer(): Buffer;
9
+ }
10
+ //#endregion
11
+ export { Secs2ItemBoolean };
12
+ //# sourceMappingURL=Secs2ItemBoolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemBoolean.d.ts","names":[],"sources":["../../../src/core/secs2item/Secs2ItemBoolean.ts"],"sourcesContent":[],"mappings":";;;cAGa,gBAAA,SAAyB;;EAAzB,IAAA,YAAA,CAAA,CAAA,EAAiB,OAAA,EAAA;;cAcR"}
@@ -0,0 +1,27 @@
1
+ import { AbstractSecs2Item } from "./AbstractSecs2Item.js";
2
+ import { SecsItemType } from "../enums/SecsItemType.js";
3
+
4
+ //#region src/core/secs2item/Secs2ItemBoolean.ts
5
+ var Secs2ItemBoolean = class extends AbstractSecs2Item {
6
+ constructor(value) {
7
+ super(SecsItemType.BOOLEAN, value);
8
+ }
9
+ get valueAsArray() {
10
+ return Array.isArray(this._value) ? this._value : [this._value];
11
+ }
12
+ toSml() {
13
+ return `<BOOLEAN ${this.valueAsArray.map((v) => v ? "T" : "F").join(" ")}>`;
14
+ }
15
+ toBuffer() {
16
+ const values = this.valueAsArray;
17
+ const buffer = Buffer.alloc(values.length);
18
+ values.forEach((v, i) => buffer.writeUInt8(v ? 1 : 0, i));
19
+ values.forEach((v, i) => buffer.writeUInt8(v ? 255 : 0, i));
20
+ const header = this.createHeader(buffer.length);
21
+ return Buffer.concat([header, buffer]);
22
+ }
23
+ };
24
+
25
+ //#endregion
26
+ export { Secs2ItemBoolean };
27
+ //# sourceMappingURL=Secs2ItemBoolean.js.map