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
package/lib/gem/Gem.js ADDED
@@ -0,0 +1,137 @@
1
+ import { Secs2ItemAscii } from "../core/secs2item/Secs2ItemAscii.js";
2
+ import { Secs2ItemBinary } from "../core/secs2item/Secs2ItemBinary.js";
3
+ import { Secs2ItemList } from "../core/secs2item/Secs2ItemList.js";
4
+ import { A, B, L } from "../helper/Secs2ItemHelper.js";
5
+ import { Clock, ClockType } from "./Clock.js";
6
+
7
+ //#region src/gem/Gem.ts
8
+ let CommAck = /* @__PURE__ */ function(CommAck$1) {
9
+ CommAck$1[CommAck$1["OK"] = 0] = "OK";
10
+ CommAck$1[CommAck$1["DENIED"] = 1] = "DENIED";
11
+ return CommAck$1;
12
+ }({});
13
+ let OflAck = /* @__PURE__ */ function(OflAck$1) {
14
+ OflAck$1[OflAck$1["OK"] = 0] = "OK";
15
+ return OflAck$1;
16
+ }({});
17
+ let OnlAck = /* @__PURE__ */ function(OnlAck$1) {
18
+ OnlAck$1[OnlAck$1["OK"] = 0] = "OK";
19
+ OnlAck$1[OnlAck$1["REFUSE"] = 1] = "REFUSE";
20
+ OnlAck$1[OnlAck$1["ALREADY_ONLINE"] = 2] = "ALREADY_ONLINE";
21
+ return OnlAck$1;
22
+ }({});
23
+ let TiAck = /* @__PURE__ */ function(TiAck$1) {
24
+ TiAck$1[TiAck$1["OK"] = 0] = "OK";
25
+ TiAck$1[TiAck$1["NOT_DONE"] = 1] = "NOT_DONE";
26
+ return TiAck$1;
27
+ }({});
28
+ var Gem = class Gem {
29
+ static DEFAULT_MDLN = " ";
30
+ static DEFAULT_SOFTREV = " ";
31
+ static DEFAULT_CLOCK_TYPE = ClockType.A16;
32
+ mdln = Gem.DEFAULT_MDLN;
33
+ softrev = Gem.DEFAULT_SOFTREV;
34
+ clockType = Gem.DEFAULT_CLOCK_TYPE;
35
+ constructor(comm) {
36
+ this.comm = comm;
37
+ }
38
+ async s1f2(primaryMsg) {
39
+ await this.comm.reply(primaryMsg, 1, 2, L());
40
+ }
41
+ async s1f13() {
42
+ let body;
43
+ if (this.comm.isEquip) body = L(A(this.mdln), A(this.softrev));
44
+ else body = L();
45
+ const reply = await this.comm.send(1, 13, true, body);
46
+ if (reply && reply.body instanceof Secs2ItemList) {
47
+ const list = reply.body;
48
+ if (list.value.length > 0 && list.value[0] instanceof Secs2ItemBinary) return list.value[0].value[0];
49
+ }
50
+ throw new Error("S1F14 invalid response or not COMMACK");
51
+ }
52
+ async s1f14(primaryMsg, commAck) {
53
+ let body;
54
+ if (this.comm.isEquip) body = L(B(Buffer.from([commAck])), L(A(this.mdln), A(this.softrev)));
55
+ else body = L(B(Buffer.from([commAck])), L());
56
+ await this.comm.reply(primaryMsg, 1, 14, body);
57
+ }
58
+ async s1f15() {
59
+ const reply = await this.comm.send(1, 15, true);
60
+ if (reply && reply.body instanceof Secs2ItemBinary) return reply.body.value[0];
61
+ throw new Error("S1F16 invalid response or not OFLACK");
62
+ }
63
+ async s1f16(primaryMsg) {
64
+ await this.comm.reply(primaryMsg, 1, 16, B(Buffer.from([OflAck.OK])));
65
+ }
66
+ async s1f17() {
67
+ const reply = await this.comm.send(1, 17, true);
68
+ if (reply && reply.body instanceof Secs2ItemBinary) return reply.body.value[0];
69
+ throw new Error("S1F18 invalid response or not ONLACK");
70
+ }
71
+ async s1f18(primaryMsg, onlAck) {
72
+ await this.comm.reply(primaryMsg, 1, 18, B(Buffer.from([onlAck])));
73
+ }
74
+ async s2f17() {
75
+ const reply = await this.comm.send(2, 17, true);
76
+ if (reply?.body instanceof Secs2ItemAscii) return Clock.fromAscii(reply.body);
77
+ throw new Error("S2F18 invalid response or not time");
78
+ }
79
+ async s2f18(primaryMsg, clock = Clock.now()) {
80
+ const body = this.clockType === ClockType.A12 ? clock.toA12() : clock.toA16();
81
+ await this.comm.reply(primaryMsg, 2, 18, body);
82
+ }
83
+ async s2f18Now(primaryMsg) {
84
+ return this.s2f18(primaryMsg, Clock.now());
85
+ }
86
+ async s2f31(clock) {
87
+ const body = this.clockType === ClockType.A12 ? clock.toA12() : clock.toA16();
88
+ const reply = await this.comm.send(2, 31, true, body);
89
+ if (reply && reply.body instanceof Secs2ItemBinary) return reply.body.value[0];
90
+ throw new Error("S2F32 invalid response or not TIACK");
91
+ }
92
+ async s2f31Now() {
93
+ return this.s2f31(Clock.now());
94
+ }
95
+ async s2f32(primaryMsg, tiAck) {
96
+ await this.comm.reply(primaryMsg, 2, 32, B(Buffer.from([tiAck])));
97
+ }
98
+ async s9f1(refMsg) {
99
+ await this.s9fy(refMsg, 1);
100
+ }
101
+ async s9f3(refMsg) {
102
+ await this.s9fy(refMsg, 3);
103
+ }
104
+ async s9f5(refMsg) {
105
+ await this.s9fy(refMsg, 5);
106
+ }
107
+ async s9f7(refMsg) {
108
+ await this.s9fy(refMsg, 7);
109
+ }
110
+ async s9f9(refMsg) {
111
+ await this.s9fy(refMsg, 9);
112
+ }
113
+ async s9f11(refMsg) {
114
+ await this.s9fy(refMsg, 11);
115
+ }
116
+ async s9fy(refMsg, func) {
117
+ const header = this.getHeader10Bytes(refMsg);
118
+ await this.comm.send(9, func, false, B(header));
119
+ }
120
+ getHeader10Bytes(msg) {
121
+ const buffer = Buffer.alloc(10);
122
+ buffer.writeUInt16BE(msg.deviceId & 32767, 0);
123
+ let streamByte = msg.stream & 127;
124
+ if (msg.wBit) streamByte |= 128;
125
+ buffer.writeUInt8(streamByte, 2);
126
+ buffer.writeUInt8(msg.func, 3);
127
+ buffer.writeUInt8(0, 4);
128
+ buffer.writeUInt8(0, 5);
129
+ if (typeof msg.systemBytes === "number") buffer.writeUInt32BE(msg.systemBytes, 6);
130
+ else msg.systemBytes.copy(buffer, 6, 0, 4);
131
+ return buffer;
132
+ }
133
+ };
134
+
135
+ //#endregion
136
+ export { CommAck, Gem, OflAck, OnlAck, TiAck };
137
+ //# sourceMappingURL=Gem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Gem.js","names":["comm: AbstractSecsCommunicator","body: Secs2ItemList"],"sources":["../../src/gem/Gem.ts"],"sourcesContent":["import { AbstractSecsCommunicator } from \"../core/AbstractSecsCommunicator.js\";\nimport { SecsMessage } from \"../core/AbstractSecsMessage.js\";\nimport { Secs2ItemAscii } from \"../core/secs2item/Secs2ItemAscii.js\";\nimport { Secs2ItemBinary } from \"../core/secs2item/Secs2ItemBinary.js\";\nimport { Secs2ItemList } from \"../core/secs2item/Secs2ItemList.js\";\nimport { A, B, L } from \"../helper/Secs2ItemHelper.js\";\nimport { Clock, ClockType } from \"./Clock.js\";\n\nexport enum CommAck {\n\tOK = 0x0,\n\tDENIED = 0x1,\n}\n\nexport enum OflAck {\n\tOK = 0x0,\n}\n\nexport enum OnlAck {\n\tOK = 0x0,\n\tREFUSE = 0x1,\n\tALREADY_ONLINE = 0x2,\n}\n\nexport enum TiAck {\n\tOK = 0x0,\n\tNOT_DONE = 0x1,\n}\n\nexport class Gem {\n\tprivate static readonly DEFAULT_MDLN = \" \";\n\tprivate static readonly DEFAULT_SOFTREV = \" \";\n\tprivate static readonly DEFAULT_CLOCK_TYPE = ClockType.A16;\n\n\tpublic mdln: string = Gem.DEFAULT_MDLN;\n\tpublic softrev: string = Gem.DEFAULT_SOFTREV;\n\tpublic clockType: ClockType = Gem.DEFAULT_CLOCK_TYPE;\n\n\tconstructor(public comm: AbstractSecsCommunicator) {}\n\n\t// S1F2 - Are You There?\n\tasync s1f2(primaryMsg: SecsMessage): Promise<void> {\n\t\tawait this.comm.reply(primaryMsg, 1, 2, L());\n\t}\n\n\t// S1F13 - Establish Communications Request\n\tasync s1f13(): Promise<number> {\n\t\tlet body: Secs2ItemList;\n\t\tif (this.comm.isEquip) {\n\t\t\tbody = L(A(this.mdln), A(this.softrev));\n\t\t} else {\n\t\t\tbody = L();\n\t\t}\n\n\t\tconst reply = await this.comm.send(1, 13, true, body);\n\t\tif (reply && reply.body instanceof Secs2ItemList) {\n\t\t\tconst list = reply.body;\n\t\t\tif (list.value.length > 0 && list.value[0] instanceof Secs2ItemBinary) {\n\t\t\t\tconst bin = list.value[0];\n\t\t\t\treturn bin.value[0];\n\t\t\t}\n\t\t}\n\t\tthrow new Error(\"S1F14 invalid response or not COMMACK\");\n\t}\n\n\t// S1F14 - Establish Communications Acknowledge\n\tasync s1f14(primaryMsg: SecsMessage, commAck: CommAck): Promise<void> {\n\t\tlet body: Secs2ItemList;\n\t\tif (this.comm.isEquip) {\n\t\t\tbody = L(B(Buffer.from([commAck])), L(A(this.mdln), A(this.softrev)));\n\t\t} else {\n\t\t\tbody = L(B(Buffer.from([commAck])), L());\n\t\t}\n\t\tawait this.comm.reply(primaryMsg, 1, 14, body);\n\t}\n\n\t// S1F15 - Request OFF-LINE\n\tasync s1f15(): Promise<number> {\n\t\tconst reply = await this.comm.send(1, 15, true);\n\t\tif (reply && reply.body instanceof Secs2ItemBinary) {\n\t\t\treturn reply.body.value[0];\n\t\t}\n\t\tthrow new Error(\"S1F16 invalid response or not OFLACK\");\n\t}\n\n\t// S1F16 - OFF-LINE Acknowledge\n\tasync s1f16(primaryMsg: SecsMessage): Promise<void> {\n\t\tawait this.comm.reply(primaryMsg, 1, 16, B(Buffer.from([OflAck.OK])));\n\t}\n\n\t// S1F17 - Request ON-LINE\n\tasync s1f17(): Promise<number> {\n\t\tconst reply = await this.comm.send(1, 17, true);\n\t\tif (reply && reply.body instanceof Secs2ItemBinary) {\n\t\t\treturn reply.body.value[0];\n\t\t}\n\t\tthrow new Error(\"S1F18 invalid response or not ONLACK\");\n\t}\n\n\t// S1F18 - ON-LINE Acknowledge\n\tasync s1f18(primaryMsg: SecsMessage, onlAck: OnlAck): Promise<void> {\n\t\tawait this.comm.reply(primaryMsg, 1, 18, B(Buffer.from([onlAck])));\n\t}\n\n\t// S2F17 - Date and Time Request\n\tasync s2f17(): Promise<Clock> {\n\t\tconst reply = await this.comm.send(2, 17, true);\n\t\tif (reply?.body instanceof Secs2ItemAscii) {\n\t\t\treturn Clock.fromAscii(reply.body);\n\t\t}\n\t\tthrow new Error(\"S2F18 invalid response or not time\");\n\t}\n\n\t// S2F18 - Date and Time Data\n\tasync s2f18(\n\t\tprimaryMsg: SecsMessage,\n\t\tclock: Clock = Clock.now(),\n\t): Promise<void> {\n\t\tconst body =\n\t\t\tthis.clockType === ClockType.A12 ? clock.toA12() : clock.toA16();\n\t\tawait this.comm.reply(primaryMsg, 2, 18, body);\n\t}\n\n\tasync s2f18Now(primaryMsg: SecsMessage): Promise<void> {\n\t\treturn this.s2f18(primaryMsg, Clock.now());\n\t}\n\n\t// S2F31 - Date and Time Set Request\n\tasync s2f31(clock: Clock): Promise<number> {\n\t\tconst body =\n\t\t\tthis.clockType === ClockType.A12 ? clock.toA12() : clock.toA16();\n\t\tconst reply = await this.comm.send(2, 31, true, body);\n\t\tif (reply && reply.body instanceof Secs2ItemBinary) {\n\t\t\treturn reply.body.value[0];\n\t\t}\n\t\tthrow new Error(\"S2F32 invalid response or not TIACK\");\n\t}\n\n\tasync s2f31Now(): Promise<number> {\n\t\treturn this.s2f31(Clock.now());\n\t}\n\n\t// S2F32 - Date and Time Set Acknowledge\n\tasync s2f32(primaryMsg: SecsMessage, tiAck: TiAck): Promise<void> {\n\t\tawait this.comm.reply(primaryMsg, 2, 32, B(Buffer.from([tiAck])));\n\t}\n\n\t// S9Fx Helpers\n\tasync s9f1(refMsg: SecsMessage): Promise<void> {\n\t\tawait this.s9fy(refMsg, 1);\n\t}\n\tasync s9f3(refMsg: SecsMessage): Promise<void> {\n\t\tawait this.s9fy(refMsg, 3);\n\t}\n\tasync s9f5(refMsg: SecsMessage): Promise<void> {\n\t\tawait this.s9fy(refMsg, 5);\n\t}\n\tasync s9f7(refMsg: SecsMessage): Promise<void> {\n\t\tawait this.s9fy(refMsg, 7);\n\t}\n\tasync s9f9(refMsg: SecsMessage): Promise<void> {\n\t\tawait this.s9fy(refMsg, 9);\n\t}\n\tasync s9f11(refMsg: SecsMessage): Promise<void> {\n\t\tawait this.s9fy(refMsg, 11);\n\t}\n\n\tprivate async s9fy(refMsg: SecsMessage, func: number): Promise<void> {\n\t\tconst header = this.getHeader10Bytes(refMsg);\n\t\tawait this.comm.send(9, func, false, B(header));\n\t}\n\n\tprivate getHeader10Bytes(msg: SecsMessage): Buffer {\n\t\tconst buffer = Buffer.alloc(10);\n\t\t// Session ID (Device ID)\n\t\tbuffer.writeUInt16BE(msg.deviceId & 0x7fff, 0);\n\n\t\t// Stream + W-bit\n\t\tlet streamByte = msg.stream & 0x7f;\n\t\tif (msg.wBit) {\n\t\t\tstreamByte |= 0x80;\n\t\t}\n\t\tbuffer.writeUInt8(streamByte, 2);\n\n\t\t// Function\n\t\tbuffer.writeUInt8(msg.func, 3);\n\n\t\t// P-Type, S-Type (Assuming 0 for now)\n\t\tbuffer.writeUInt8(0, 4);\n\t\tbuffer.writeUInt8(0, 5);\n\n\t\t// System Bytes\n\t\tif (typeof msg.systemBytes === \"number\") {\n\t\t\tbuffer.writeUInt32BE(msg.systemBytes, 6);\n\t\t} else {\n\t\t\t// Assuming Buffer\n\t\t\tconst sysBuf = msg.systemBytes as Buffer;\n\t\t\tsysBuf.copy(buffer, 6, 0, 4);\n\t\t}\n\n\t\treturn buffer;\n\t}\n}\n"],"mappings":";;;;;;;AAQA,IAAY,8CAAL;AACN;AACA;;;AAGD,IAAY,4CAAL;AACN;;;AAGD,IAAY,4CAAL;AACN;AACA;AACA;;;AAGD,IAAY,0CAAL;AACN;AACA;;;AAGD,IAAa,MAAb,MAAa,IAAI;CAChB,OAAwB,eAAe;CACvC,OAAwB,kBAAkB;CAC1C,OAAwB,qBAAqB,UAAU;CAEvD,AAAO,OAAe,IAAI;CAC1B,AAAO,UAAkB,IAAI;CAC7B,AAAO,YAAuB,IAAI;CAElC,YAAY,AAAOA,MAAgC;EAAhC;;CAGnB,MAAM,KAAK,YAAwC;AAClD,QAAM,KAAK,KAAK,MAAM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,QAAQ,EAAE;;CAE3B,MAAM,KAAK,QAAoC;AAC9C,QAAM,KAAK,KAAK,QAAQ,EAAE;;CAE3B,MAAM,KAAK,QAAoC;AAC9C,QAAM,KAAK,KAAK,QAAQ,EAAE;;CAE3B,MAAM,MAAM,QAAoC;AAC/C,QAAM,KAAK,KAAK,QAAQ,GAAG;;CAG5B,MAAc,KAAK,QAAqB,MAA6B;EACpE,MAAM,SAAS,KAAK,iBAAiB,OAAO;AAC5C,QAAM,KAAK,KAAK,KAAK,GAAG,MAAM,OAAO,EAAE,OAAO,CAAC;;CAGhD,AAAQ,iBAAiB,KAA0B;EAClD,MAAM,SAAS,OAAO,MAAM,GAAG;AAE/B,SAAO,cAAc,IAAI,WAAW,OAAQ,EAAE;EAG9C,IAAI,aAAa,IAAI,SAAS;AAC9B,MAAI,IAAI,KACP,eAAc;AAEf,SAAO,WAAW,YAAY,EAAE;AAGhC,SAAO,WAAW,IAAI,MAAM,EAAE;AAG9B,SAAO,WAAW,GAAG,EAAE;AACvB,SAAO,WAAW,GAAG,EAAE;AAGvB,MAAI,OAAO,IAAI,gBAAgB,SAC9B,QAAO,cAAc,IAAI,aAAa,EAAE;MAIxC,CADe,IAAI,YACZ,KAAK,QAAQ,GAAG,GAAG,EAAE;AAG7B,SAAO"}
@@ -0,0 +1,96 @@
1
+ import { AbstractSecs2Item } from "../core/secs2item/AbstractSecs2Item.js";
2
+ import { Secs2ItemAscii } from "../core/secs2item/Secs2ItemAscii.js";
3
+ import { Secs2ItemBinary } from "../core/secs2item/Secs2ItemBinary.js";
4
+ import { Secs2ItemBoolean } from "../core/secs2item/Secs2ItemBoolean.js";
5
+ import { Secs2ItemNumeric } from "../core/secs2item/Secs2ItemNumeric.js";
6
+ import { Secs2ItemList } from "../core/secs2item/Secs2ItemList.js";
7
+
8
+ //#region src/helper/Secs2ItemHelper.d.ts
9
+
10
+ /**
11
+ * @description Creates a SECS-II list item.
12
+ * @param items The items in the list.
13
+ * @returns The SECS-II list item.
14
+ */
15
+ declare function L(...items: AbstractSecs2Item[]): Secs2ItemList;
16
+ /**
17
+ * @description Creates a SECS-II ASCII item.
18
+ * @param value The value of the item.
19
+ * @returns The SECS-II ASCII item.
20
+ */
21
+ declare function A(value: string): Secs2ItemAscii;
22
+ /**
23
+ * @description Creates a SECS-II boolean item.
24
+ * @param value The value of the item.
25
+ * @returns The SECS-II boolean item.
26
+ */
27
+ declare function BOOLEAN(value: string): Secs2ItemBoolean;
28
+ /**
29
+ * @description Creates a SECS-II binary item.
30
+ * @param value The value of the item.
31
+ * @returns The SECS-II binary item.
32
+ */
33
+ declare function B(value: string | Buffer): Secs2ItemBinary;
34
+ /**
35
+ * @description Creates a SECS-II unsigned 8-bit integer item.
36
+ * @param value The value of the item.
37
+ * @returns The SECS-II unsigned 8-bit integer item.
38
+ */
39
+ declare function U1(...value: number[]): Secs2ItemNumeric;
40
+ /**
41
+ * @description Creates a SECS-II unsigned 16-bit integer item.
42
+ * @param value The value of the item.
43
+ * @returns The SECS-II unsigned 16-bit integer item.
44
+ */
45
+ declare function U2(...value: number[]): Secs2ItemNumeric;
46
+ /**
47
+ * @description Creates a SECS-II unsigned 32-bit integer item.
48
+ * @param value The value of the item.
49
+ * @returns The SECS-II unsigned 32-bit integer item.
50
+ */
51
+ declare function U4(...value: number[]): Secs2ItemNumeric;
52
+ /**
53
+ * @description Creates a SECS-II unsigned 64-bit integer item.
54
+ * @param value The value of the item.
55
+ * @returns The SECS-II unsigned 64-bit integer item.
56
+ */
57
+ declare function U8(...value: number[] | bigint[]): Secs2ItemNumeric;
58
+ /**
59
+ * @description Creates a SECS-II signed 8-bit integer item.
60
+ * @param value The value of the item.
61
+ * @returns The SECS-II signed 8-bit integer item.
62
+ */
63
+ declare function I1(...value: number[]): Secs2ItemNumeric;
64
+ /**
65
+ * @description Creates a SECS-II signed 16-bit integer item.
66
+ * @param value The value of the item.
67
+ * @returns The SECS-II signed 16-bit integer item.
68
+ */
69
+ declare function I2(...value: number[]): Secs2ItemNumeric;
70
+ /**
71
+ * @description Creates a SECS-II signed 32-bit integer item.
72
+ * @param value The value of the item.
73
+ * @returns The SECS-II signed 32-bit integer item.
74
+ */
75
+ declare function I4(...value: number[]): Secs2ItemNumeric;
76
+ /**
77
+ * @description Creates a SECS-II signed 64-bit integer item.
78
+ * @param value The value of the item.
79
+ * @returns The SECS-II signed 64-bit integer item.
80
+ */
81
+ declare function I8(...value: number[] | bigint[]): Secs2ItemNumeric;
82
+ /**
83
+ * @description Creates a SECS-II float 32-bit number item.
84
+ * @param value The value of the item.
85
+ * @returns The SECS-II float 32-bit number item.
86
+ */
87
+ declare function F4(...value: number[]): Secs2ItemNumeric;
88
+ /**
89
+ * @description Creates a SECS-II float 64-bit number item.
90
+ * @param value The value of the item.
91
+ * @returns The SECS-II float 64-bit number item.
92
+ */
93
+ declare function F8(...value: number[]): Secs2ItemNumeric;
94
+ //#endregion
95
+ export { A, B, BOOLEAN, F4, F8, I1, I2, I4, I8, L, U1, U2, U4, U8 };
96
+ //# sourceMappingURL=Secs2ItemHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemHelper.d.ts","names":[],"sources":["../../src/helper/Secs2ItemHelper.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAaA;AASA;AASA;AAqBgB,iBAvCA,CAAA,CAuCkB,GAAS,KAAA,EAvCf,iBAuC8B,EAAA,CAAA,EAvCR,aAuCQ;AAsB1D;AAYA;AAYA;AAYA;AAYA;AASgB,iBA7GA,CAAA,CA6GwB,KAAA,EAAA,MAAgB,CAAA,EA7GtB,cA6GsB;AASxD;AASA;AASA;AAYA;;iBA3IgB,OAAA,iBAAwB;;;;;;iBAqBxB,CAAA,iBAAkB,SAAS;;;;;;iBAsB3B,EAAA,sBAAwB;;;;;;iBAYxB,EAAA,sBAAwB;;;;;;iBAYxB,EAAA,sBAAwB;;;;;;iBAYxB,EAAA,iCAAmC;;;;;;iBAYnC,EAAA,sBAAwB;;;;;;iBASxB,EAAA,sBAAwB;;;;;;iBASxB,EAAA,sBAAwB;;;;;;iBASxB,EAAA,iCAAmC;;;;;;iBASnC,EAAA,sBAAwB;;;;;;iBAYxB,EAAA,sBAAwB"}
@@ -0,0 +1,135 @@
1
+ import { Secs2ItemFactory } from "../core/secs2item/Secs2ItemFactory.js";
2
+
3
+ //#region src/helper/Secs2ItemHelper.ts
4
+ /**
5
+ * @description Creates a SECS-II list item.
6
+ * @param items The items in the list.
7
+ * @returns The SECS-II list item.
8
+ */
9
+ function L(...items) {
10
+ return Secs2ItemFactory.createListItem(...items);
11
+ }
12
+ /**
13
+ * @description Creates a SECS-II ASCII item.
14
+ * @param value The value of the item.
15
+ * @returns The SECS-II ASCII item.
16
+ */
17
+ function A(value) {
18
+ return Secs2ItemFactory.createAsciiItem(value);
19
+ }
20
+ /**
21
+ * @description Creates a SECS-II boolean item.
22
+ * @param value The value of the item.
23
+ * @returns The SECS-II boolean item.
24
+ */
25
+ function BOOLEAN(value) {
26
+ const booleanValues = [];
27
+ value.split("").map((v) => {
28
+ if (v !== "TRUE" && v !== "FALSE") throw new Error("BOOLEAN value must be TRUE or FALSE");
29
+ if (v === "TRUE") booleanValues.push(true);
30
+ else booleanValues.push(false);
31
+ });
32
+ return Secs2ItemFactory.createBooleanItem(...booleanValues);
33
+ }
34
+ /**
35
+ * @description Creates a SECS-II binary item.
36
+ * @param value The value of the item.
37
+ * @returns The SECS-II binary item.
38
+ */
39
+ function B(value) {
40
+ if (typeof value === "string") {
41
+ const stringToBytes = (s) => s.split(/\s+/).map((v) => v.trim().startsWith("0x") ? parseInt(v, 16) : parseInt(v, 10));
42
+ const binaryValues = stringToBytes(value);
43
+ return Secs2ItemFactory.createBinaryItem(Buffer.from(binaryValues));
44
+ }
45
+ return Secs2ItemFactory.createBinaryItem(value);
46
+ }
47
+ /**
48
+ * @description Creates a SECS-II unsigned 8-bit integer item.
49
+ * @param value The value of the item.
50
+ * @returns The SECS-II unsigned 8-bit integer item.
51
+ */
52
+ function U1(...value) {
53
+ if (value.some((v) => v < 0)) throw new Error("U1 value must be unsigned 8-bit integer");
54
+ return Secs2ItemFactory.createU1Item(...value);
55
+ }
56
+ /**
57
+ * @description Creates a SECS-II unsigned 16-bit integer item.
58
+ * @param value The value of the item.
59
+ * @returns The SECS-II unsigned 16-bit integer item.
60
+ */
61
+ function U2(...value) {
62
+ if (value.some((v) => v < 0)) throw new Error("U2 value must be unsigned 16-bit integer");
63
+ return Secs2ItemFactory.createU2Item(...value);
64
+ }
65
+ /**
66
+ * @description Creates a SECS-II unsigned 32-bit integer item.
67
+ * @param value The value of the item.
68
+ * @returns The SECS-II unsigned 32-bit integer item.
69
+ */
70
+ function U4(...value) {
71
+ if (value.some((v) => v < 0)) throw new Error("U4 value must be unsigned 32-bit integer");
72
+ return Secs2ItemFactory.createU4Item(...value);
73
+ }
74
+ /**
75
+ * @description Creates a SECS-II unsigned 64-bit integer item.
76
+ * @param value The value of the item.
77
+ * @returns The SECS-II unsigned 64-bit integer item.
78
+ */
79
+ function U8(...value) {
80
+ if (value.some((v) => v < 0)) throw new Error("U8 value must be unsigned 64-bit integer");
81
+ return Secs2ItemFactory.createU8Item(...value);
82
+ }
83
+ /**
84
+ * @description Creates a SECS-II signed 8-bit integer item.
85
+ * @param value The value of the item.
86
+ * @returns The SECS-II signed 8-bit integer item.
87
+ */
88
+ function I1(...value) {
89
+ return Secs2ItemFactory.createI1Item(...value);
90
+ }
91
+ /**
92
+ * @description Creates a SECS-II signed 16-bit integer item.
93
+ * @param value The value of the item.
94
+ * @returns The SECS-II signed 16-bit integer item.
95
+ */
96
+ function I2(...value) {
97
+ return Secs2ItemFactory.createI2Item(...value);
98
+ }
99
+ /**
100
+ * @description Creates a SECS-II signed 32-bit integer item.
101
+ * @param value The value of the item.
102
+ * @returns The SECS-II signed 32-bit integer item.
103
+ */
104
+ function I4(...value) {
105
+ return Secs2ItemFactory.createI4Item(...value);
106
+ }
107
+ /**
108
+ * @description Creates a SECS-II signed 64-bit integer item.
109
+ * @param value The value of the item.
110
+ * @returns The SECS-II signed 64-bit integer item.
111
+ */
112
+ function I8(...value) {
113
+ return Secs2ItemFactory.createI8Item(...value);
114
+ }
115
+ /**
116
+ * @description Creates a SECS-II float 32-bit number item.
117
+ * @param value The value of the item.
118
+ * @returns The SECS-II float 32-bit number item.
119
+ */
120
+ function F4(...value) {
121
+ if (value.some((v) => v % 1 !== 0)) throw new Error("F4 value must be float 32-bit number");
122
+ return Secs2ItemFactory.createF4Item(...value);
123
+ }
124
+ /**
125
+ * @description Creates a SECS-II float 64-bit number item.
126
+ * @param value The value of the item.
127
+ * @returns The SECS-II float 64-bit number item.
128
+ */
129
+ function F8(...value) {
130
+ return Secs2ItemFactory.createF8Item(...value);
131
+ }
132
+
133
+ //#endregion
134
+ export { A, B, BOOLEAN, F4, F8, I1, I2, I4, I8, L, U1, U2, U4, U8 };
135
+ //# sourceMappingURL=Secs2ItemHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Secs2ItemHelper.js","names":["booleanValues: boolean[]","binaryValues: number[]"],"sources":["../../src/helper/Secs2ItemHelper.ts"],"sourcesContent":["import { AbstractSecs2Item } from \"../core/secs2item/AbstractSecs2Item.js\";\nimport { Secs2ItemAscii } from \"../core/secs2item/Secs2ItemAscii.js\";\nimport { Secs2ItemBinary } from \"../core/secs2item/Secs2ItemBinary.js\";\nimport { Secs2ItemBoolean } from \"../core/secs2item/Secs2ItemBoolean.js\";\nimport { Secs2ItemFactory } from \"../core/secs2item/Secs2ItemFactory.js\";\nimport { Secs2ItemList } from \"../core/secs2item/Secs2ItemList.js\";\nimport { Secs2ItemNumeric } from \"../core/secs2item/Secs2ItemNumeric.js\";\n\n/**\n * @description Creates a SECS-II list item.\n * @param items The items in the list.\n * @returns The SECS-II list item.\n */\nexport function L(...items: AbstractSecs2Item[]): Secs2ItemList {\n\treturn Secs2ItemFactory.createListItem(...items);\n}\n\n/**\n * @description Creates a SECS-II ASCII item.\n * @param value The value of the item.\n * @returns The SECS-II ASCII item.\n */\nexport function A(value: string): Secs2ItemAscii {\n\treturn Secs2ItemFactory.createAsciiItem(value);\n}\n\n/**\n * @description Creates a SECS-II boolean item.\n * @param value The value of the item.\n * @returns The SECS-II boolean item.\n */\nexport function BOOLEAN(value: string): Secs2ItemBoolean {\n\tconst booleanValues: boolean[] = [];\n\tconst values = value.split(\"\");\n\tvalues.map((v) => {\n\t\tif (v !== \"TRUE\" && v !== \"FALSE\") {\n\t\t\tthrow new Error(\"BOOLEAN value must be TRUE or FALSE\");\n\t\t}\n\t\tif (v === \"TRUE\") {\n\t\t\tbooleanValues.push(true);\n\t\t} else {\n\t\t\tbooleanValues.push(false);\n\t\t}\n\t});\n\treturn Secs2ItemFactory.createBooleanItem(...booleanValues);\n}\n\n/**\n * @description Creates a SECS-II binary item.\n * @param value The value of the item.\n * @returns The SECS-II binary item.\n */\nexport function B(value: string | Buffer): Secs2ItemBinary {\n\tconst valueType = typeof value;\n\tif (valueType === \"string\") {\n\t\tconst stringToBytes = (s: string) =>\n\t\t\ts\n\t\t\t\t.split(/\\s+/)\n\t\t\t\t.map((v) =>\n\t\t\t\t\tv.trim().startsWith(\"0x\") ? parseInt(v, 16) : parseInt(v, 10),\n\t\t\t\t);\n\n\t\tconst binaryValues: number[] = stringToBytes(value as string);\n\t\treturn Secs2ItemFactory.createBinaryItem(Buffer.from(binaryValues));\n\t}\n\n\treturn Secs2ItemFactory.createBinaryItem(value as Buffer);\n}\n\n/**\n * @description Creates a SECS-II unsigned 8-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II unsigned 8-bit integer item.\n */\nexport function U1(...value: number[]): Secs2ItemNumeric {\n\tif (value.some((v) => v < 0)) {\n\t\tthrow new Error(\"U1 value must be unsigned 8-bit integer\");\n\t}\n\treturn Secs2ItemFactory.createU1Item(...value);\n}\n\n/**\n * @description Creates a SECS-II unsigned 16-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II unsigned 16-bit integer item.\n */\nexport function U2(...value: number[]): Secs2ItemNumeric {\n\tif (value.some((v) => v < 0)) {\n\t\tthrow new Error(\"U2 value must be unsigned 16-bit integer\");\n\t}\n\treturn Secs2ItemFactory.createU2Item(...value);\n}\n\n/**\n * @description Creates a SECS-II unsigned 32-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II unsigned 32-bit integer item.\n */\nexport function U4(...value: number[]): Secs2ItemNumeric {\n\tif (value.some((v) => v < 0)) {\n\t\tthrow new Error(\"U4 value must be unsigned 32-bit integer\");\n\t}\n\treturn Secs2ItemFactory.createU4Item(...value);\n}\n\n/**\n * @description Creates a SECS-II unsigned 64-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II unsigned 64-bit integer item.\n */\nexport function U8(...value: number[] | bigint[]): Secs2ItemNumeric {\n\tif (value.some((v) => v < 0)) {\n\t\tthrow new Error(\"U8 value must be unsigned 64-bit integer\");\n\t}\n\treturn Secs2ItemFactory.createU8Item(...value);\n}\n\n/**\n * @description Creates a SECS-II signed 8-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II signed 8-bit integer item.\n */\nexport function I1(...value: number[]): Secs2ItemNumeric {\n\treturn Secs2ItemFactory.createI1Item(...value);\n}\n\n/**\n * @description Creates a SECS-II signed 16-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II signed 16-bit integer item.\n */\nexport function I2(...value: number[]): Secs2ItemNumeric {\n\treturn Secs2ItemFactory.createI2Item(...value);\n}\n\n/**\n * @description Creates a SECS-II signed 32-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II signed 32-bit integer item.\n */\nexport function I4(...value: number[]): Secs2ItemNumeric {\n\treturn Secs2ItemFactory.createI4Item(...value);\n}\n\n/**\n * @description Creates a SECS-II signed 64-bit integer item.\n * @param value The value of the item.\n * @returns The SECS-II signed 64-bit integer item.\n */\nexport function I8(...value: number[] | bigint[]): Secs2ItemNumeric {\n\treturn Secs2ItemFactory.createI8Item(...value);\n}\n\n/**\n * @description Creates a SECS-II float 32-bit number item.\n * @param value The value of the item.\n * @returns The SECS-II float 32-bit number item.\n */\nexport function F4(...value: number[]): Secs2ItemNumeric {\n\tif (value.some((v) => v % 1 !== 0)) {\n\t\tthrow new Error(\"F4 value must be float 32-bit number\");\n\t}\n\treturn Secs2ItemFactory.createF4Item(...value);\n}\n\n/**\n * @description Creates a SECS-II float 64-bit number item.\n * @param value The value of the item.\n * @returns The SECS-II float 64-bit number item.\n */\nexport function F8(...value: number[]): Secs2ItemNumeric {\n\treturn Secs2ItemFactory.createF8Item(...value);\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,EAAE,GAAG,OAA2C;AAC/D,QAAO,iBAAiB,eAAe,GAAG,MAAM;;;;;;;AAQjD,SAAgB,EAAE,OAA+B;AAChD,QAAO,iBAAiB,gBAAgB,MAAM;;;;;;;AAQ/C,SAAgB,QAAQ,OAAiC;CACxD,MAAMA,gBAA2B,EAAE;AAEnC,CADe,MAAM,MAAM,GAAG,CACvB,KAAK,MAAM;AACjB,MAAI,MAAM,UAAU,MAAM,QACzB,OAAM,IAAI,MAAM,sCAAsC;AAEvD,MAAI,MAAM,OACT,eAAc,KAAK,KAAK;MAExB,eAAc,KAAK,MAAM;GAEzB;AACF,QAAO,iBAAiB,kBAAkB,GAAG,cAAc;;;;;;;AAQ5D,SAAgB,EAAE,OAAyC;AAE1D,KADkB,OAAO,UACP,UAAU;EAC3B,MAAM,iBAAiB,MACtB,EACE,MAAM,MAAM,CACZ,KAAK,MACL,EAAE,MAAM,CAAC,WAAW,KAAK,GAAG,SAAS,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,CAC7D;EAEH,MAAMC,eAAyB,cAAc,MAAgB;AAC7D,SAAO,iBAAiB,iBAAiB,OAAO,KAAK,aAAa,CAAC;;AAGpE,QAAO,iBAAiB,iBAAiB,MAAgB;;;;;;;AAQ1D,SAAgB,GAAG,GAAG,OAAmC;AACxD,KAAI,MAAM,MAAM,MAAM,IAAI,EAAE,CAC3B,OAAM,IAAI,MAAM,0CAA0C;AAE3D,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,KAAI,MAAM,MAAM,MAAM,IAAI,EAAE,CAC3B,OAAM,IAAI,MAAM,2CAA2C;AAE5D,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,KAAI,MAAM,MAAM,MAAM,IAAI,EAAE,CAC3B,OAAM,IAAI,MAAM,2CAA2C;AAE5D,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAA8C;AACnE,KAAI,MAAM,MAAM,MAAM,IAAI,EAAE,CAC3B,OAAM,IAAI,MAAM,2CAA2C;AAE5D,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAA8C;AACnE,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,KAAI,MAAM,MAAM,MAAM,IAAI,MAAM,EAAE,CACjC,OAAM,IAAI,MAAM,uCAAuC;AAExD,QAAO,iBAAiB,aAAa,GAAG,MAAM;;;;;;;AAQ/C,SAAgB,GAAG,GAAG,OAAmC;AACxD,QAAO,iBAAiB,aAAa,GAAG,MAAM"}
@@ -0,0 +1,29 @@
1
+ import { HsmsMessage } from "./HsmsMessage.js";
2
+ import { SelectStatus } from "./enums/SelectStatus.js";
3
+ import { HsmsCommunicator, HsmsCommunicatorConfig } from "./HsmsCommunicator.js";
4
+
5
+ //#region src/hsms/HsmsActiveCommunicator.d.ts
6
+
7
+ /**
8
+ * @description HsmsActiveCommunicator is a class that extends HsmsCommunicator and implements the active communicator logic.
9
+ */
10
+ declare class HsmsActiveCommunicator extends HsmsCommunicator {
11
+ private shouldStop;
12
+ private reconnectTimer;
13
+ private connectionPromiseResolver;
14
+ private heartbeatTimer;
15
+ heartbeatIntervalMs: number;
16
+ constructor(config: HsmsCommunicatorConfig);
17
+ open(): Promise<void>;
18
+ private connect;
19
+ private scheduleReconnect;
20
+ private runHeartbeatLoop;
21
+ private startHeartbeat;
22
+ private stopHeartbeat;
23
+ protected handleSelectReq(msg: HsmsMessage): void;
24
+ untilConnected(): Promise<SelectStatus>;
25
+ close(): Promise<void>;
26
+ }
27
+ //#endregion
28
+ export { HsmsActiveCommunicator };
29
+ //# sourceMappingURL=HsmsActiveCommunicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HsmsActiveCommunicator.d.ts","names":[],"sources":["../../src/hsms/HsmsActiveCommunicator.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAaA;AAOqB,cAPR,sBAAA,SAA+B,gBAAA,CAOvB;EAoBN,QAAA,UAAA;EAwG0B,QAAA,cAAA;EAIR,QAAA,yBAAA;EAAR,QAAA,cAAA;EAYT,mBAAA,EAAA,MAAA;EAnJ4B,WAAA,CAAA,MAAA,EAOvB,sBAPuB;EAAgB,IAAA,CAAA,CAAA,EA2B7C,OA3B6C,CAAA,IAAA,CAAA;;;;;;iCAmInB;oBAIhB,QAAQ;WAYjB"}
@@ -0,0 +1,123 @@
1
+ import { RejectReason } from "./enums/RejectReason.js";
2
+ import { SelectStatus } from "./enums/SelectStatus.js";
3
+ import { HsmsCommunicator, HsmsState } from "./HsmsCommunicator.js";
4
+ import { Socket } from "net";
5
+
6
+ //#region src/hsms/HsmsActiveCommunicator.ts
7
+ /**
8
+ * @description HsmsActiveCommunicator is a class that extends HsmsCommunicator and implements the active communicator logic.
9
+ */
10
+ var HsmsActiveCommunicator = class extends HsmsCommunicator {
11
+ shouldStop = false;
12
+ reconnectTimer = null;
13
+ connectionPromiseResolver = null;
14
+ heartbeatTimer = null;
15
+ heartbeatIntervalMs = 5e3;
16
+ constructor(config) {
17
+ super(config);
18
+ if (config.linkTestInterval !== void 0) this.heartbeatIntervalMs = config.linkTestInterval;
19
+ this.on("disconnected", () => {
20
+ this.stopHeartbeat();
21
+ if (!this.shouldStop) {
22
+ console.log(`Connection lost. Reconnecting in ${String(this.timeoutT5)}s...`);
23
+ this.scheduleReconnect();
24
+ }
25
+ });
26
+ this.on("selected", () => {
27
+ this.startHeartbeat();
28
+ });
29
+ }
30
+ async open() {
31
+ if (this.socket && !this.socket.destroyed) return;
32
+ this.shouldStop = false;
33
+ return new Promise((resolve) => {
34
+ this.connectionPromiseResolver = resolve;
35
+ this.connect();
36
+ });
37
+ }
38
+ connect() {
39
+ if (this.shouldStop) return;
40
+ const socket = new Socket();
41
+ const onError = (err) => {
42
+ socket.destroy();
43
+ console.log(`Connection failed: ${err.message}. Retrying in ${String(this.timeoutT5)}s...`);
44
+ if (!this.shouldStop) this.scheduleReconnect();
45
+ };
46
+ socket.once("error", onError);
47
+ socket.connect(this.port, this.ip, () => {
48
+ socket.removeListener("error", onError);
49
+ this.handleSocketEvents(socket);
50
+ this.sendSelectReq().then(() => {}).catch((err) => {
51
+ if (err instanceof Error) console.error(`SelectReq failed: ${err.message}`);
52
+ else console.error(`SelectReq failed: ${err}`);
53
+ if (!socket.destroyed) socket.destroy();
54
+ });
55
+ if (this.connectionPromiseResolver) {
56
+ this.connectionPromiseResolver();
57
+ this.connectionPromiseResolver = null;
58
+ }
59
+ });
60
+ }
61
+ scheduleReconnect() {
62
+ if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
63
+ this.reconnectTimer = setTimeout(() => {
64
+ this.reconnectTimer = null;
65
+ this.connect();
66
+ }, this.timeoutT5 * 1e3);
67
+ }
68
+ async runHeartbeatLoop() {
69
+ if (this.state !== HsmsState.Selected || this.shouldStop) return;
70
+ try {
71
+ await this.sendLinkTestReq();
72
+ } catch (err) {
73
+ console.error("Heartbeat failed, closing connection:", err);
74
+ if (this.socket) this.socket.destroy();
75
+ return;
76
+ }
77
+ if (this.state === HsmsState.Selected && !this.shouldStop) this.heartbeatTimer = setTimeout(() => {
78
+ this.runHeartbeatLoop();
79
+ }, this.heartbeatIntervalMs);
80
+ }
81
+ startHeartbeat() {
82
+ this.stopHeartbeat();
83
+ this.heartbeatTimer = setTimeout(() => {
84
+ this.runHeartbeatLoop();
85
+ }, this.heartbeatIntervalMs);
86
+ }
87
+ stopHeartbeat() {
88
+ if (this.heartbeatTimer) {
89
+ clearTimeout(this.heartbeatTimer);
90
+ this.heartbeatTimer = null;
91
+ }
92
+ }
93
+ handleSelectReq(msg) {
94
+ this.sendReject(msg, RejectReason.NotSupportTypeS);
95
+ }
96
+ async untilConnected() {
97
+ if (this.state === HsmsState.Selected) return SelectStatus.Success;
98
+ return new Promise((resolve) => {
99
+ const onSelected = () => {
100
+ resolve(SelectStatus.Success);
101
+ };
102
+ this.once("selected", onSelected);
103
+ });
104
+ }
105
+ async close() {
106
+ this.shouldStop = true;
107
+ this.stopHeartbeat();
108
+ if (this.reconnectTimer) {
109
+ clearTimeout(this.reconnectTimer);
110
+ this.reconnectTimer = null;
111
+ }
112
+ if (this.socket) {
113
+ this.socket.end();
114
+ this.socket.destroy();
115
+ this.socket = null;
116
+ }
117
+ await Promise.resolve();
118
+ }
119
+ };
120
+
121
+ //#endregion
122
+ export { HsmsActiveCommunicator };
123
+ //# sourceMappingURL=HsmsActiveCommunicator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HsmsActiveCommunicator.js","names":[],"sources":["../../src/hsms/HsmsActiveCommunicator.ts"],"sourcesContent":["import { Socket } from \"net\";\nimport {\n\tHsmsCommunicator,\n\tHsmsCommunicatorConfig,\n\tHsmsState,\n} from \"./HsmsCommunicator.js\";\nimport { HsmsMessage } from \"./HsmsMessage.js\";\nimport { RejectReason } from \"./enums/RejectReason.js\";\nimport { SelectStatus } from \"./enums/SelectStatus.js\";\n\n/**\n * @description HsmsActiveCommunicator is a class that extends HsmsCommunicator and implements the active communicator logic.\n */\nexport class HsmsActiveCommunicator extends HsmsCommunicator {\n\tprivate shouldStop = false;\n\tprivate reconnectTimer: NodeJS.Timeout | null = null;\n\tprivate connectionPromiseResolver: (() => void) | null = null;\n\tprivate heartbeatTimer: NodeJS.Timeout | null = null;\n\tpublic heartbeatIntervalMs = 5000;\n\n\tconstructor(config: HsmsCommunicatorConfig) {\n\t\tsuper(config);\n\t\tif (config.linkTestInterval !== undefined) {\n\t\t\tthis.heartbeatIntervalMs = config.linkTestInterval;\n\t\t}\n\t\tthis.on(\"disconnected\", () => {\n\t\t\tthis.stopHeartbeat();\n\t\t\tif (!this.shouldStop) {\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Connection lost. Reconnecting in ${String(this.timeoutT5)}s...`,\n\t\t\t\t);\n\t\t\t\tthis.scheduleReconnect();\n\t\t\t}\n\t\t});\n\n\t\tthis.on(\"selected\", () => {\n\t\t\tthis.startHeartbeat();\n\t\t});\n\t}\n\n\tasync open(): Promise<void> {\n\t\tif (this.socket && !this.socket.destroyed) {\n\t\t\treturn; // Already open\n\t\t}\n\n\t\tthis.shouldStop = false;\n\n\t\treturn new Promise((resolve) => {\n\t\t\tthis.connectionPromiseResolver = resolve;\n\t\t\tthis.connect();\n\t\t});\n\t}\n\n\tprivate connect() {\n\t\tif (this.shouldStop) return;\n\n\t\tconst socket = new Socket();\n\n\t\tconst onError = (err: Error) => {\n\t\t\tsocket.destroy();\n\t\t\tconsole.log(\n\t\t\t\t`Connection failed: ${err.message}. Retrying in ${String(this.timeoutT5)}s...`,\n\t\t\t);\n\t\t\tif (!this.shouldStop) {\n\t\t\t\tthis.scheduleReconnect();\n\t\t\t}\n\t\t};\n\n\t\tsocket.once(\"error\", onError);\n\n\t\tsocket.connect(this.port, this.ip, () => {\n\t\t\tsocket.removeListener(\"error\", onError);\n\t\t\tthis.handleSocketEvents(socket);\n\n\t\t\t// Automatically send SelectReq upon connection\n\t\t\tvoid this.sendSelectReq()\n\t\t\t\t.then(() => {\n\t\t\t\t\t// Select success, state updated in handleSelectRsp\n\t\t\t\t})\n\t\t\t\t.catch((err) => {\n\t\t\t\t\tif (err instanceof Error) {\n\t\t\t\t\t\tconsole.error(`SelectReq failed: ${err.message}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.error(`SelectReq failed: ${err}`);\n\t\t\t\t\t}\n\t\t\t\t\t// If Select fails, close connection to trigger reconnect logic\n\t\t\t\t\tif (!socket.destroyed) {\n\t\t\t\t\t\tsocket.destroy();\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\tif (this.connectionPromiseResolver) {\n\t\t\t\tthis.connectionPromiseResolver();\n\t\t\t\tthis.connectionPromiseResolver = null;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate scheduleReconnect() {\n\t\tif (this.reconnectTimer) {\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t}\n\t\tthis.reconnectTimer = setTimeout(() => {\n\t\t\tthis.reconnectTimer = null;\n\t\t\tthis.connect();\n\t\t}, this.timeoutT5 * 1000);\n\t}\n\n\tprivate async runHeartbeatLoop() {\n\t\tif (this.state !== HsmsState.Selected || this.shouldStop) return;\n\n\t\ttry {\n\t\t\tawait this.sendLinkTestReq();\n\t\t} catch (err) {\n\t\t\tconsole.error(\"Heartbeat failed, closing connection:\", err);\n\t\t\t// Force close to trigger reconnect\n\t\t\tif (this.socket) {\n\t\t\t\tthis.socket.destroy();\n\t\t\t}\n\t\t\treturn; // Stop loop\n\t\t}\n\n\t\tif (this.state === HsmsState.Selected && !this.shouldStop) {\n\t\t\tthis.heartbeatTimer = setTimeout(() => {\n\t\t\t\tvoid this.runHeartbeatLoop();\n\t\t\t}, this.heartbeatIntervalMs);\n\t\t}\n\t}\n\n\tprivate startHeartbeat() {\n\t\tthis.stopHeartbeat();\n\t\t// Start first heartbeat after interval\n\t\tthis.heartbeatTimer = setTimeout(() => {\n\t\t\tvoid this.runHeartbeatLoop();\n\t\t}, this.heartbeatIntervalMs);\n\t}\n\n\tprivate stopHeartbeat() {\n\t\tif (this.heartbeatTimer) {\n\t\t\tclearTimeout(this.heartbeatTimer);\n\t\t\tthis.heartbeatTimer = null;\n\t\t}\n\t}\n\n\tprotected override handleSelectReq(msg: HsmsMessage) {\n\t\tvoid this.sendReject(msg, RejectReason.NotSupportTypeS);\n\t}\n\n\tasync untilConnected(): Promise<SelectStatus> {\n\t\tif (this.state === HsmsState.Selected) {\n\t\t\treturn SelectStatus.Success;\n\t\t}\n\t\treturn new Promise((resolve) => {\n\t\t\tconst onSelected = () => {\n\t\t\t\tresolve(SelectStatus.Success);\n\t\t\t};\n\t\t\tthis.once(\"selected\", onSelected);\n\t\t});\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.shouldStop = true;\n\t\tthis.stopHeartbeat();\n\t\tif (this.reconnectTimer) {\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t\tthis.reconnectTimer = null;\n\t\t}\n\t\tif (this.socket) {\n\t\t\tthis.socket.end();\n\t\t\tthis.socket.destroy();\n\t\t\tthis.socket = null;\n\t\t}\n\t\tawait Promise.resolve();\n\t}\n}\n"],"mappings":";;;;;;;;;AAaA,IAAa,yBAAb,cAA4C,iBAAiB;CAC5D,AAAQ,aAAa;CACrB,AAAQ,iBAAwC;CAChD,AAAQ,4BAAiD;CACzD,AAAQ,iBAAwC;CAChD,AAAO,sBAAsB;CAE7B,YAAY,QAAgC;AAC3C,QAAM,OAAO;AACb,MAAI,OAAO,qBAAqB,OAC/B,MAAK,sBAAsB,OAAO;AAEnC,OAAK,GAAG,sBAAsB;AAC7B,QAAK,eAAe;AACpB,OAAI,CAAC,KAAK,YAAY;AACrB,YAAQ,IACP,oCAAoC,OAAO,KAAK,UAAU,CAAC,MAC3D;AACD,SAAK,mBAAmB;;IAExB;AAEF,OAAK,GAAG,kBAAkB;A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U,YAAY,CAAC,KAAK,WAC9C,MAAK,iBAAiB,iBAAiB;AACtC,GAAK,KAAK,kBAAkB;KAC1B,KAAK,oBAAoB;;CAI9B,AAAQ,iBAAiB;AACxB,OAAK,eAAe;AAEpB,OAAK,iBAAiB,iBAAiB;AACtC,GAAK,KAAK,kBAAkB;KAC1B,KAAK,oBAAoB;;CAG7B,AAAQ,gBAAgB;AACvB,MAAI,KAAK,gBAAgB;AACxB,gBAAa,KAAK,eAAe;AACjC,QAAK,iBAAiB;;;CAIxB,AAAmB,gBAAgB,KAAkB;AACpD,EAAK,KAAK,WAAW,KAAK,aAAa,gBAAgB;;CAGxD,MAAM,iBAAwC;AAC7C,MAAI,KAAK,UAAU,UAAU,SAC5B,QAAO,aAAa;AAErB,SAAO,IAAI,SAAS,YAAY;GAC/B,MAAM,mBAAmB;AACxB,YAAQ,aAAa,QAAQ;;AAE9B,QAAK,KAAK,YAAY,WAAW;IAChC;;CAGH,MAAM,QAAuB;AAC5B,OAAK,aAAa;AAClB,OAAK,eAAe;AACpB,MAAI,KAAK,gBAAgB;AACxB,gBAAa,KAAK,eAAe;AACjC,QAAK,iBAAiB;;AAEvB,MAAI,KAAK,QAAQ;AAChB,QAAK,OAAO,KAAK;AACjB,QAAK,OAAO,SAAS;AACrB,QAAK,SAAS;;AAEf,QAAM,QAAQ,SAAS"}
@@ -0,0 +1,70 @@
1
+ import { AbstractSecs2Item } from "../core/secs2item/AbstractSecs2Item.js";
2
+ import { SecsMessage } from "../core/AbstractSecsMessage.js";
3
+ import { AbstractSecsCommunicator, SecsCommunicatorConfig, SecsCommunicatorEvents } from "../core/AbstractSecsCommunicator.js";
4
+ import { RejectReason } from "./enums/RejectReason.js";
5
+ import { HsmsMessage } from "./HsmsMessage.js";
6
+ import { SelectStatus } from "./enums/SelectStatus.js";
7
+ import { Socket } from "net";
8
+
9
+ //#region src/hsms/HsmsCommunicator.d.ts
10
+ declare enum HsmsState {
11
+ NotConnected = "NotConnected",
12
+ Connected = "Connected",
13
+ // TCP Connected
14
+ Selected = "Selected",
15
+ }
16
+ /**
17
+ * @description HsmsCommunicatorConfig is the configuration interface for HsmsCommunicator.
18
+ * @param ip The IP address of the remote device.
19
+ * @param port The port number of the remote device.
20
+ * @param linkTestInterval The interval in milliseconds to send link test messages.
21
+ */
22
+ interface HsmsCommunicatorConfig extends SecsCommunicatorConfig {
23
+ ip: string;
24
+ port: number;
25
+ linkTestInterval?: number;
26
+ }
27
+ interface HsmsCommunicatorEvents extends SecsCommunicatorEvents {
28
+ selected: [];
29
+ deselected: [];
30
+ }
31
+ declare abstract class HsmsCommunicator extends AbstractSecsCommunicator<HsmsCommunicatorEvents> {
32
+ ip: string;
33
+ port: number;
34
+ protected socket: Socket | null;
35
+ protected state: HsmsState;
36
+ private buffer;
37
+ private t7Timer;
38
+ private t8Timer;
39
+ get connectionState(): HsmsState;
40
+ constructor(config: HsmsCommunicatorConfig);
41
+ protected sendBuffer(buffer: Buffer): Promise<void>;
42
+ protected createMessage(stream: number, func: number, wBit: boolean, body: AbstractSecs2Item | null, systemBytes: number): SecsMessage;
43
+ protected handleSocketEvents(socket: Socket): void;
44
+ private resetT7Timer;
45
+ private clearT7Timer;
46
+ private resetT8Timer;
47
+ private clearT8Timer;
48
+ private processBuffer;
49
+ private processHsmsMessage;
50
+ private handleControlMessage;
51
+ protected handleSelectReq(msg: HsmsMessage): void;
52
+ protected handleSelectRsp(msg: HsmsMessage): void;
53
+ protected handleLinkTestReq(msg: HsmsMessage): void;
54
+ protected handleLinkTestRsp(msg: HsmsMessage): void;
55
+ protected handleDeselectReq(msg: HsmsMessage): void;
56
+ protected handleDeselectRsp(msg: HsmsMessage): void;
57
+ protected handleSeparateReq(_msg: HsmsMessage): void;
58
+ protected sendSelectRsp(req: HsmsMessage, status: number): Promise<void>;
59
+ protected sendDeselectRsp(req: HsmsMessage, status: number): Promise<void>;
60
+ protected sendLinkTestRsp(req: HsmsMessage): Promise<void>;
61
+ protected sendReject(req: HsmsMessage, reason: RejectReason): Promise<void>;
62
+ send(stream: number, func: number, wBit: boolean, body?: AbstractSecs2Item | null): Promise<SecsMessage | null>;
63
+ sendSelectReq(): Promise<SelectStatus>;
64
+ sendLinkTestReq(): Promise<void>;
65
+ sendSeparateReq(): Promise<void>;
66
+ private rejectAllTransactions;
67
+ }
68
+ //#endregion
69
+ export { HsmsCommunicator, HsmsCommunicatorConfig, HsmsCommunicatorEvents, HsmsState };
70
+ //# sourceMappingURL=HsmsCommunicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HsmsCommunicator.d.ts","names":[],"sources":["../../src/hsms/HsmsCommunicator.ts"],"sourcesContent":[],"mappings":";;;;;;;;;aAaY,SAAA;;EAAA,SAAA,GAAS,WAAA;EAAA;EAYJ,QAAA,GAAA,UAAA;AAMjB;AAKA;;;;;;AAuBoC,UAlCnB,sBAAA,SAA+B,sBAkCZ,CAAA;EAAS,EAAA,EAAA,MAAA;EAiBrC,IAAA,EAAA,MAAA;EAEJ,gBAAA,CAAA,EAAA,MAAA;;AAwL4B,UAvOf,sBAAA,SAA+B,sBAuOhB,CAAA;EAgBA,QAAA,EAAA,EAAA;EAsBE,UAAA,EAAA,EAAA;;AAeA,uBAvRZ,gBAAA,SAAyB,wBAuRb,CAvRsC,sBAuRtC,CAAA,CAAA;EAWA,EAAA,EAAA,MAAA;EAiBC,IAAA,EAAA,MAAA;EAUC,UAAA,MAAA,EAzTjB,MAyTiB,GAAA,IAAA;EAA2B,UAAA,KAAA,EAxT7C,SAwT6C;EAKzB,QAAA,MAAA;EAA2B,QAAA,OAAA;EAK3B,QAAA,OAAA;EAAW,IAAA,eAAA,CAAA,CAAA,EA1TlB,SA0TkB;EAKhB,WAAA,CAAA,MAAA,EA3TZ,sBA2TY;EAAqB,UAAA,UAAA,CAAA,MAAA,EArTlB,MAqTkB,CAAA,EArTT,OAqTS,CAAA,IAAA,CAAA;EAAY,UAAA,aAAA,CAAA,MAAA,EAAA,MAAA,EAAA,IAAA,EAAA,M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