langjie-m-play 0.0.4 → 0.0.6

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.
@@ -0,0 +1,4 @@
1
+ export interface AtsLoadResponse<K extends string, V> {
2
+ atsHandle: number;
3
+ atsParam: Record<K, V>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langjie-m-play",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -4,6 +4,7 @@ import { GtcCallBackMsg } from "../domain/GtcCallBackMsg";
4
4
  import { ReadDataDO } from "../domain/ReadDataDO";
5
5
  import { VinChnl } from "../domain/VinChnl";
6
6
  import { OutMsg } from "../domain/OutMsg";
7
+ import { AtsLoadResponse } from "../domain/AtsLoadResponse";
7
8
  /**
8
9
  * 提供给前端接口调用
9
10
  */
@@ -205,7 +206,7 @@ export declare class GtcClient {
205
206
  * @param script ats脚本
206
207
  * @return ats句柄
207
208
  */
208
- static atsLoad(slaveInstId: string | null, serviceType: ServiceTypeEnum, ctrlIndex: number, script: string): Promise<number>;
209
+ static atsLoad<K extends string, V>(slaveInstId: string | null, serviceType: ServiceTypeEnum, ctrlIndex: number, script: string): Promise<AtsLoadResponse<K, V>>;
209
210
  /**
210
211
  * 启动ats
211
212
  *
@@ -1,10 +1,12 @@
1
1
  import { ServiceTypeEnum } from "../domain/enums/ServiceTypeEnum";
2
+ import { AtsLoadResponse } from "../domain/AtsLoadResponse";
2
3
  export declare class MPlay {
3
4
  private readonly instId;
4
5
  private readonly serviceType;
5
6
  private readonly ctrlIndex;
6
7
  private dataGramCallBack;
7
8
  private atsHandleNameMap;
9
+ private atsStartedMark;
8
10
  /**
9
11
  * Connect to the MPlay server.
10
12
  *
@@ -34,9 +36,9 @@ export declare class MPlay {
34
36
  * Load ATS script to the MPlay server.
35
37
  *
36
38
  * @param atsScriptName The name of the ATS script to load.
37
- * @return atsHandle The handle of the ATS script.
39
+ * @return atsLoadResponse The response of the ATS load request.
38
40
  */
39
- load(atsScriptName: string): Promise<number>;
41
+ load<K extends string, V>(atsScriptName: string): Promise<AtsLoadResponse<K, V>>;
40
42
  /**
41
43
  * Start ATS script to the MPlay server by ATS handle.
42
44
  *
package/service/MPlay.js CHANGED
@@ -36,6 +36,7 @@ class MPlay {
36
36
  constructor(instId, serviceType, ctrlIndex) {
37
37
  this.ctrlIndex = 0;
38
38
  this.atsHandleNameMap = {};
39
+ this.atsStartedMark = {};
39
40
  if (instId) {
40
41
  this.instId = instId;
41
42
  }
@@ -112,16 +113,19 @@ class MPlay {
112
113
  * Load ATS script to the MPlay server.
113
114
  *
114
115
  * @param atsScriptName The name of the ATS script to load.
115
- * @return atsHandle The handle of the ATS script.
116
+ * @return atsLoadResponse The response of the ATS load request.
116
117
  */
117
118
  load(atsScriptName) {
118
119
  return __awaiter(this, void 0, void 0, function* () {
119
- const atsHandle = yield GtcClient_1.GtcClient.atsLoad(this.instId, this.serviceType, this.ctrlIndex, atsScriptName);
120
+ const atsLoadResponse = yield GtcClient_1.GtcClient.atsLoad(this.instId, this.serviceType, this.ctrlIndex, atsScriptName);
121
+ const atsHandle = atsLoadResponse.atsHandle;
120
122
  if (atsHandle === 0) {
121
123
  throw new Error("Failed to load ATS script");
122
124
  }
125
+ this.atsStartedMark[atsHandle] = false;
123
126
  this.atsHandleNameMap[atsHandle] = atsScriptName;
124
- return atsHandle;
127
+ // @ts-ignore
128
+ return atsLoadResponse;
125
129
  });
126
130
  }
127
131
  /**
@@ -137,6 +141,7 @@ class MPlay {
137
141
  yield GtcClient_1.GtcClient.atsStart(this.instId, this.serviceType, this.ctrlIndex, atsHandle, this.atsHandleNameMap[atsHandle]);
138
142
  yield atsStartSynchronizer.waitAll();
139
143
  PubSubUtil_1.PubSubUtil.unsubscribe(SubKeyEnum_1.SubKeyEnum.ATS_START_OK, atsHandle.toString());
144
+ this.atsStartedMark[atsHandle] = true;
140
145
  });
141
146
  }
142
147
  /**
@@ -150,6 +155,9 @@ class MPlay {
150
155
  if (!this.atsHandleNameMap[atsHandle]) {
151
156
  throw new Error("Please load ATS script first");
152
157
  }
158
+ if (!this.atsStartedMark[atsHandle]) {
159
+ yield this.start(atsHandle);
160
+ }
153
161
  yield GtcClient_1.GtcClient.atsPushButton(this.instId, this.serviceType, this.ctrlIndex, atsHandle, buttonName);
154
162
  });
155
163
  }