langjie-m-play 0.0.2 → 0.0.4

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.
@@ -49,11 +49,13 @@ export declare enum JsonRpcMethodEnum {
49
49
  CALL_ATS_START = "R_CALL_PACK.atsStart",
50
50
  CALL_ATS_TERMINATE = "R_CALL_PACK.atsTerminate",
51
51
  CALL_ATS_SET_PARAM = "R_CALL_PACK.atsSetParam",
52
+ CALL_ATS_GET_PARAM = "R_CALL_PACK.atsGetParam",
52
53
  CALL_ATS_PUSH_BUTTON = "R_CALL_PACK.atsPushButton",
53
54
  REPLY_ATS_LOAD = "R_REPLY_PACK.atsLoad",
54
55
  REPLY_ATS_START = "R_REPLY_PACK.atsStart",
55
56
  REPLY_ATS_TERMINATE = "R_REPLY_PACK.atsTerminate",
56
57
  REPLY_ATS_SET_PARAM = "R_REPLY_PACK.atsSetParam",
58
+ REPLY_ATS_GET_PARAM = "R_REPLY_PACK.atsGetParam",
57
59
  REPLY_ATS_PUSH_BUTTON = "R_REPLY_PACK.atsPushButton",
58
60
  CALL_SUBSCRIBE_FOR_DATA_GRAM = "R_CALL_PACK.subscribeForDatagram",
59
61
  REPLY_SUBSCRIBE_FOR_DATA_GRAM = "R_REPLY_PACK.subscribeForDatagram",
@@ -54,11 +54,13 @@ var JsonRpcMethodEnum;
54
54
  JsonRpcMethodEnum["CALL_ATS_START"] = "R_CALL_PACK.atsStart";
55
55
  JsonRpcMethodEnum["CALL_ATS_TERMINATE"] = "R_CALL_PACK.atsTerminate";
56
56
  JsonRpcMethodEnum["CALL_ATS_SET_PARAM"] = "R_CALL_PACK.atsSetParam";
57
+ JsonRpcMethodEnum["CALL_ATS_GET_PARAM"] = "R_CALL_PACK.atsGetParam";
57
58
  JsonRpcMethodEnum["CALL_ATS_PUSH_BUTTON"] = "R_CALL_PACK.atsPushButton";
58
59
  JsonRpcMethodEnum["REPLY_ATS_LOAD"] = "R_REPLY_PACK.atsLoad";
59
60
  JsonRpcMethodEnum["REPLY_ATS_START"] = "R_REPLY_PACK.atsStart";
60
61
  JsonRpcMethodEnum["REPLY_ATS_TERMINATE"] = "R_REPLY_PACK.atsTerminate";
61
62
  JsonRpcMethodEnum["REPLY_ATS_SET_PARAM"] = "R_REPLY_PACK.atsSetParam";
63
+ JsonRpcMethodEnum["REPLY_ATS_GET_PARAM"] = "R_REPLY_PACK.atsGetParam";
62
64
  JsonRpcMethodEnum["REPLY_ATS_PUSH_BUTTON"] = "R_REPLY_PACK.atsPushButton";
63
65
  JsonRpcMethodEnum["CALL_SUBSCRIBE_FOR_DATA_GRAM"] = "R_CALL_PACK.subscribeForDatagram";
64
66
  JsonRpcMethodEnum["REPLY_SUBSCRIBE_FOR_DATA_GRAM"] = "R_REPLY_PACK.subscribeForDatagram";
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "langjie-m-play",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
- "main": "./index.js",
6
- "types": "./index.d.ts",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc"
9
9
  },
@@ -246,4 +246,13 @@ export declare class GtcClient {
246
246
  * @param values 参数values
247
247
  */
248
248
  static atsSetParam(slaveInstId: string | null, serviceType: ServiceTypeEnum, ctrlIndex: number, atsHandle: number, keys: string[], values: Array<string | number>): Promise<null>;
249
+ /**
250
+ * 获取ats参数
251
+ *
252
+ * @param slaveInstId 从机id
253
+ * @param serviceType 服务类型
254
+ * @param ctrlIndex 卡索引
255
+ * @param atsHandle ats句柄
256
+ */
257
+ static atsGetParam<K extends string, V>(slaveInstId: string | null, serviceType: ServiceTypeEnum, ctrlIndex: number, atsHandle: number): Promise<Record<K, V>>;
249
258
  }
@@ -469,5 +469,22 @@ class GtcClient {
469
469
  return GtcServiceFactory_1.default.getGtcService().call(request);
470
470
  });
471
471
  }
472
+ /**
473
+ * 获取ats参数
474
+ *
475
+ * @param slaveInstId 从机id
476
+ * @param serviceType 服务类型
477
+ * @param ctrlIndex 卡索引
478
+ * @param atsHandle ats句柄
479
+ */
480
+ static atsGetParam(slaveInstId, serviceType, ctrlIndex, atsHandle) {
481
+ return __awaiter(this, void 0, void 0, function* () {
482
+ const request = GtcClient.generateRequest(JsonRpcMethodEnum_1.JsonRpcMethodEnum.CALL_ATS_GET_PARAM, slaveInstId);
483
+ request.params[JsonRpcConstant_1.JsonRpcConstant.SERVICE_TYPE] = serviceType;
484
+ request.params[JsonRpcConstant_1.JsonRpcConstant.CTRL_INDEX] = ctrlIndex;
485
+ request.params[JsonRpcConstant_1.JsonRpcConstant.ATS_HANDLE] = atsHandle;
486
+ return GtcServiceFactory_1.default.getGtcService().call(request);
487
+ });
488
+ }
472
489
  }
473
490
  exports.GtcClient = GtcClient;
@@ -4,8 +4,63 @@ export declare class MPlay {
4
4
  private readonly serviceType;
5
5
  private readonly ctrlIndex;
6
6
  private dataGramCallBack;
7
+ private atsHandleNameMap;
8
+ /**
9
+ * Connect to the MPlay server.
10
+ *
11
+ * @param url The URL of the MPlay server.
12
+ */
7
13
  static connect(url: string): Promise<void>;
14
+ /**
15
+ * Create a new MPlay instance.
16
+ *
17
+ * @param instId The instance ID of the MPlay instance.
18
+ * @param serviceType The service type of the MPlay instance.
19
+ * @param ctrlIndex The control index of the MPlay instance.
20
+ */
8
21
  constructor(instId: string | null, serviceType: ServiceTypeEnum | null, ctrlIndex: number | null);
22
+ /**
23
+ * Subscribe datagram to the MPlay server.
24
+ *
25
+ * @param tags The channel tags to subscribe.
26
+ * @param fn The callback function to handle the datagram.
27
+ */
9
28
  subscribeForDatagram(tags: string, fn: (data: Array<Array<string>>) => void): Promise<void>;
29
+ /**
30
+ * Unsubscribe datagram from the MPlay server.
31
+ */
10
32
  unsubscribeForDatagram(): Promise<void>;
33
+ /**
34
+ * Load ATS script to the MPlay server.
35
+ *
36
+ * @param atsScriptName The name of the ATS script to load.
37
+ * @return atsHandle The handle of the ATS script.
38
+ */
39
+ load(atsScriptName: string): Promise<number>;
40
+ /**
41
+ * Start ATS script to the MPlay server by ATS handle.
42
+ *
43
+ * @param atsHandle The handle of the ATS script.
44
+ */
45
+ start(atsHandle: number): Promise<void>;
46
+ /**
47
+ * Trigger ATS script button to the MPlay server by ATS handle.
48
+ *
49
+ * @param atsHandle The handle of the ATS script.
50
+ * @param buttonName The name of the button to trigger.
51
+ */
52
+ pushButton(atsHandle: number, buttonName: string): Promise<void>;
53
+ /**
54
+ * Get the parameter of the ATS script by ATS handle.
55
+ *
56
+ * @param atsHandle The handle of the ATS script.
57
+ */
58
+ atsGetParam(atsHandle: number): Promise<Record<string, number>>;
59
+ /**
60
+ * Set the parameter of the ATS script by ATS handle.
61
+ *
62
+ * @param atsHandle The handle of the ATS script.
63
+ * @param param The parameter to set.
64
+ */
65
+ atsSetParam(atsHandle: number, param: Record<string, number>): Promise<void>;
11
66
  }
package/service/MPlay.js CHANGED
@@ -12,14 +12,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MPlay = void 0;
13
13
  const GtcClient_1 = require("./GtcClient");
14
14
  const ServiceTypeEnum_1 = require("../domain/enums/ServiceTypeEnum");
15
+ const PubSubUtil_1 = require("../utils/PubSubUtil");
16
+ const SubKeyEnum_1 = require("../utils/enums/SubKeyEnum");
17
+ const TaskSynchronizer_1 = require("../utils/TaskSynchronizer");
15
18
  class MPlay {
19
+ /**
20
+ * Connect to the MPlay server.
21
+ *
22
+ * @param url The URL of the MPlay server.
23
+ */
16
24
  static connect(url) {
17
25
  return __awaiter(this, void 0, void 0, function* () {
18
26
  yield GtcClient_1.GtcClient.init(url);
19
27
  });
20
28
  }
29
+ /**
30
+ * Create a new MPlay instance.
31
+ *
32
+ * @param instId The instance ID of the MPlay instance.
33
+ * @param serviceType The service type of the MPlay instance.
34
+ * @param ctrlIndex The control index of the MPlay instance.
35
+ */
21
36
  constructor(instId, serviceType, ctrlIndex) {
22
37
  this.ctrlIndex = 0;
38
+ this.atsHandleNameMap = {};
23
39
  if (instId) {
24
40
  this.instId = instId;
25
41
  }
@@ -40,17 +56,128 @@ class MPlay {
40
56
  this.dataGramCallBack(data.data.DataGramList);
41
57
  }
42
58
  });
59
+ GtcClient_1.GtcClient.listenEventMsg(this.instId, this.serviceType, this.ctrlIndex, (msg) => {
60
+ // console.log(msg);
61
+ // console.log(ctrlIndex + "<<>>" + msg.msgId.toString(16));
62
+ if (msg.msgId === 0x2000) {
63
+ // PubSubUtil.publish(SubKeyEnum.LAUNCH_OK, { instId, ctrlIndex });
64
+ }
65
+ else if (msg.msgId >= 0x0620 && msg.msgId < 0x0630) {
66
+ // ats加载成功
67
+ // PubSubUtil.publish(SubKeyEnum.ATS_LOAD_OK, { instId, ctrlIndex });
68
+ }
69
+ else if (msg.msgId >= 0x0650 && msg.msgId < 0x0660) {
70
+ // ats启动成功
71
+ PubSubUtil_1.PubSubUtil.publish(SubKeyEnum_1.SubKeyEnum.ATS_START_OK, { instId, ctrlIndex });
72
+ }
73
+ else if (msg.msgId >= 0x0700 && msg.msgId < 0x0800) {
74
+ // ats跳转到指定步骤
75
+ // PubSubUtil.publish(SubKeyEnum.ATS_JUMP_ACTION, { instId, ctrlIndex });
76
+ }
77
+ else if (msg.msgId >= 0x0800 && msg.msgId < 0x0900) {
78
+ // ats异常停止
79
+ PubSubUtil_1.PubSubUtil.publish(SubKeyEnum_1.SubKeyEnum.ATS_TERMINATE_ABNORMAL, { instId, ctrlIndex });
80
+ const hAts = msg.msgId & 0x00F0 >> 4;
81
+ delete this.atsHandleNameMap[hAts];
82
+ }
83
+ else if (msg.msgId >= 0x0900 && msg.msgId < 0x0910) {
84
+ // ats正常停止
85
+ PubSubUtil_1.PubSubUtil.publish(SubKeyEnum_1.SubKeyEnum.ATS_TERMINATE, { instId, ctrlIndex });
86
+ const hAts = msg.msgId & 0x00F0 >> 4;
87
+ delete this.atsHandleNameMap[hAts];
88
+ }
89
+ });
43
90
  }
91
+ /**
92
+ * Subscribe datagram to the MPlay server.
93
+ *
94
+ * @param tags The channel tags to subscribe.
95
+ * @param fn The callback function to handle the datagram.
96
+ */
44
97
  subscribeForDatagram(tags, fn) {
45
98
  return __awaiter(this, void 0, void 0, function* () {
46
99
  yield GtcClient_1.GtcClient.subscribeForDatagram(this.instId, this.serviceType, tags);
47
100
  this.dataGramCallBack = fn;
48
101
  });
49
102
  }
103
+ /**
104
+ * Unsubscribe datagram from the MPlay server.
105
+ */
50
106
  unsubscribeForDatagram() {
51
107
  return __awaiter(this, void 0, void 0, function* () {
52
108
  yield GtcClient_1.GtcClient.unsubscribeForDatagram(this.instId, this.serviceType);
53
109
  });
54
110
  }
111
+ /**
112
+ * Load ATS script to the MPlay server.
113
+ *
114
+ * @param atsScriptName The name of the ATS script to load.
115
+ * @return atsHandle The handle of the ATS script.
116
+ */
117
+ load(atsScriptName) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const atsHandle = yield GtcClient_1.GtcClient.atsLoad(this.instId, this.serviceType, this.ctrlIndex, atsScriptName);
120
+ if (atsHandle === 0) {
121
+ throw new Error("Failed to load ATS script");
122
+ }
123
+ this.atsHandleNameMap[atsHandle] = atsScriptName;
124
+ return atsHandle;
125
+ });
126
+ }
127
+ /**
128
+ * Start ATS script to the MPlay server by ATS handle.
129
+ *
130
+ * @param atsHandle The handle of the ATS script.
131
+ */
132
+ start(atsHandle) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const atsStartSynchronizer = new TaskSynchronizer_1.TaskSynchronizer();
135
+ PubSubUtil_1.PubSubUtil.subscribe(SubKeyEnum_1.SubKeyEnum.ATS_START_OK, atsHandle.toString(), (eventMsg) => __awaiter(this, void 0, void 0, function* () { return atsStartSynchronizer.finishTaskKey(atsHandle.toString()); }));
136
+ atsStartSynchronizer.addTaskKey(atsHandle.toString());
137
+ yield GtcClient_1.GtcClient.atsStart(this.instId, this.serviceType, this.ctrlIndex, atsHandle, this.atsHandleNameMap[atsHandle]);
138
+ yield atsStartSynchronizer.waitAll();
139
+ PubSubUtil_1.PubSubUtil.unsubscribe(SubKeyEnum_1.SubKeyEnum.ATS_START_OK, atsHandle.toString());
140
+ });
141
+ }
142
+ /**
143
+ * Trigger ATS script button to the MPlay server by ATS handle.
144
+ *
145
+ * @param atsHandle The handle of the ATS script.
146
+ * @param buttonName The name of the button to trigger.
147
+ */
148
+ pushButton(atsHandle, buttonName) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ if (!this.atsHandleNameMap[atsHandle]) {
151
+ throw new Error("Please load ATS script first");
152
+ }
153
+ yield GtcClient_1.GtcClient.atsPushButton(this.instId, this.serviceType, this.ctrlIndex, atsHandle, buttonName);
154
+ });
155
+ }
156
+ /**
157
+ * Get the parameter of the ATS script by ATS handle.
158
+ *
159
+ * @param atsHandle The handle of the ATS script.
160
+ */
161
+ atsGetParam(atsHandle) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ return yield GtcClient_1.GtcClient.atsGetParam(this.instId, this.serviceType, this.ctrlIndex, atsHandle);
164
+ });
165
+ }
166
+ /**
167
+ * Set the parameter of the ATS script by ATS handle.
168
+ *
169
+ * @param atsHandle The handle of the ATS script.
170
+ * @param param The parameter to set.
171
+ */
172
+ atsSetParam(atsHandle, param) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const keys = Object.keys(param);
175
+ const values = [];
176
+ for (const key in param) {
177
+ values.push(param[key]);
178
+ }
179
+ yield GtcClient_1.GtcClient.atsSetParam(this.instId, this.serviceType, this.ctrlIndex, atsHandle, keys, values);
180
+ });
181
+ }
55
182
  }
56
183
  exports.MPlay = MPlay;
@@ -0,0 +1,8 @@
1
+ export declare class TaskSynchronizer {
2
+ private resolveMap;
3
+ private taskMap;
4
+ private promiseList;
5
+ addTaskKey(key: string): void;
6
+ finishTaskKey(key: string): void;
7
+ waitAll(): Promise<any>;
8
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskSynchronizer = void 0;
4
+ class TaskSynchronizer {
5
+ constructor() {
6
+ this.resolveMap = {};
7
+ this.taskMap = {};
8
+ this.promiseList = [];
9
+ }
10
+ addTaskKey(key) {
11
+ this.taskMap[key] = new Promise(resolve => this.resolveMap[key] = resolve);
12
+ this.promiseList.push(this.taskMap[key]);
13
+ }
14
+ finishTaskKey(key) {
15
+ this.resolveMap[key]();
16
+ }
17
+ waitAll() {
18
+ return new Promise((resolve, reject) => {
19
+ Promise.all(this.promiseList).then(() => resolve(true)).catch(e => reject(e));
20
+ });
21
+ }
22
+ }
23
+ exports.TaskSynchronizer = TaskSynchronizer;