@operato/scene-mpi 8.0.0-beta.1 → 8.0.0-beta.2

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.
@@ -1,405 +0,0 @@
1
- import Gateway from './gateway'
2
- import Indicator from './indicator'
3
-
4
- export function consoleLogger(...args: any[]) {
5
- console.log(Date(), ...args)
6
- }
7
-
8
- export function onmessage(gateway: Gateway, message: any) {
9
- if (gateway.state.power_flag == 'false') {
10
- consoleLogger('got a message when power is off', message)
11
- return
12
- }
13
- if (!message.properties.is_reply) {
14
- consoleLogger('received ' + (message.body.action ? message.body.action : 'unknown action'), message)
15
-
16
- //
17
- gateway.replyPublisher!.data = gateway.generateReplyMessage(
18
- message.properties.id,
19
- message.properties.source_id,
20
- message.body.action,
21
- message.body
22
- )
23
- consoleLogger('sent reply: ', gateway.replyPublisher!.data)
24
-
25
- switch (message.body.action) {
26
- // 2.5 boot response
27
- case 'GW_INIT_RES':
28
- {
29
- if (gateway.state.boot_flag == 'true') {
30
- consoleLogger('Already booted')
31
- return
32
- }
33
-
34
- // 2.6 gateway initialize
35
- if (!gateway.version) gateway.version = message.body.gw_version
36
-
37
- gateway.setTimer(parseInt(message.body.svr_time) * 1000)
38
- gateway.timerOn()
39
- gateway.startBlinkingLed()
40
- gateway.startBlinkingLedBar()
41
-
42
- gateway.replyPublisher!.data = {
43
- properties: gateway.generateMessageProperties(),
44
- body: {
45
- action: 'GW_INIT_RPT',
46
- id: gateway.model.id,
47
- version: gateway.version
48
- }
49
- }
50
- consoleLogger('sent GW_INIT_RPT', gateway.replyPublisher!.data)
51
-
52
- gateway.setState('boot_flag', String('true')) // gw on
53
-
54
- // 2.7 indicator 초기화 요청
55
- let indConf = message && message.body && message.body.ind_conf
56
- let indIds =
57
- message &&
58
- message.body &&
59
- message.body.ind_list &&
60
- message.body.ind_list.map((ind: any) => {
61
- return ind.id
62
- })
63
- // 이전 프로토콜과 호환성 유지
64
- if (!indIds) {
65
- indIds = message && message.body && message.body.ind_id
66
- }
67
-
68
- let i = 0
69
- // ?? indicator 초기화 모두 완료 ??
70
- gateway.indicators.forEach(indicator => {
71
- // 2.8 indicator 초기화
72
- // 시뮬레이션 편의용: MPI 아이디 서버에서 부여 //
73
- if (!indicator.model.id && i < indIds.length && !gateway.findById(indIds[i])) {
74
- indicator.set('id', indIds[i])
75
- i++
76
- }
77
- ///////////////////////////////////////
78
-
79
- indicator.setState('boot_flag', String('true'))
80
-
81
- if (!indicator.version) indicator.version = message.body.ind_version
82
-
83
- Object.keys(indConf).forEach(key => {
84
- if (indicator.conf.hasOwnProperty(key)) {
85
- indicator.conf[key] = indConf[key]
86
- }
87
- })
88
-
89
- // 세그먼트 개수 맞춤
90
- indicator.setState('segments', new Array(indicator.getConf.seg_role.length).join(','))
91
-
92
- // 2.9 indicator 준비 완료
93
- gateway.replyPublisher!.data = {
94
- properties: gateway.generateMessageProperties(),
95
- body: {
96
- action: 'IND_INIT_RPT',
97
- id: indicator.model.id,
98
- version: indicator.version
99
- }
100
- }
101
- consoleLogger('sent IND_INIT_RPT', gateway.replyPublisher!.data)
102
-
103
- // 2.10 indicator ID 소등
104
- indicator.lightOff()
105
- })
106
- }
107
- // indicator 초기화 모두 완료
108
- break
109
- // 3.3 G/W에 indicator 점등 요청
110
- case 'IND_ON_REQ':
111
- {
112
- if (gateway.state.boot_flag == 'false') return
113
-
114
- // 3.4 indicator에 점등 요청
115
- let indicators = message && message.body && message.body.ind_on
116
-
117
- // 3.5 인디케이터 점등
118
- indicators &&
119
- indicators.forEach((indicator: any) => {
120
- let component = gateway.findById(indicator.id) as Indicator
121
-
122
- if (!component) return
123
- if (component.state.boot_flag == 'false') return
124
- // full 점등일 때 메시지 무시, 18.11.01 추가
125
-
126
- component.store = indicator
127
- component.store.biz_type = message.body.biz_type
128
- component.store.action_type = message.body.action_type
129
- component.store.ret_args = message.body.ret_args
130
-
131
- component.readOnly = message.body.read_only // readonly
132
-
133
- Object.keys(component.conf).forEach(opt => {
134
- if (indicator.hasOwnProperty(opt)) {
135
- switch (
136
- opt // 오버라이드 제외 목록
137
- ) {
138
- case 'seg_role':
139
- case '':
140
- return
141
- }
142
- component.conf[opt] = indicator[opt]
143
- }
144
- })
145
- let r = indicator.org_relay,
146
- b = indicator.org_box_qty == null ? 0 : indicator.org_box_qty,
147
- p = indicator.org_ea_qty == null ? 0 : indicator.org_ea_qty,
148
- c = indicator.color
149
-
150
- let cookedData: any = {}
151
-
152
- switch (message['body']['action_type']) {
153
- case component.tasks.PICK:
154
- component.currentTask = component.tasks.PICK
155
- break
156
- case component.tasks.STOCK:
157
- component.currentTask = component.tasks.STOCK
158
- break
159
- case component.tasks.FULL:
160
- component.currentTask = component.tasks.FULL
161
- cookedData = {}
162
- cookedData.viewStr = component.store.view_str
163
- cookedData.buttonColor = component.colors[c]
164
- component.lightOn(cookedData)
165
- component.displayMessage('-FULL-', c)
166
- return
167
- case component.tasks.FULL_MODIFY:
168
- component.currentTask = component.tasks.FULL_MODIFY
169
- component.displayMessage('FUL' + indicator.org_ea_qty, c)
170
- return
171
- case component.tasks.END:
172
- component.currentTask = component.tasks.END
173
- cookedData = {}
174
- cookedData.viewStr = component.store.view_str
175
- cookedData.buttonColor = component.colors[c]
176
- component.lightOn(cookedData)
177
- component.displayMessage('END', c)
178
- return
179
- case component.tasks.DISPLAY:
180
- component.currentTask = component.tasks.DISPLAY
181
- c = 'K'
182
- break
183
- case component.tasks.INSPECT:
184
- component.currentTask = component.tasks.INSPECT
185
- c = 'I'
186
- break
187
- case component.tasks.STRSHOW:
188
- component.currentTask = component.tasks.STRSHOW
189
- cookedData = {}
190
- cookedData.viewStr = component.store.view_str
191
- cookedData.buttonColor = component.colors[c]
192
- component.lightOn(cookedData)
193
- component.displayMessage(component.store.view_str, c)
194
- return
195
- }
196
-
197
- if (r || r >= 0) cookedData.org_relay = r
198
- if (b || b >= 0) cookedData.org_box_qty = b
199
- if (p || p >= 0) cookedData.org_ea_qty = p
200
- if (c) cookedData.buttonColor = component.colors[c]
201
- component.cookedData = cookedData
202
-
203
- if (component.lit && component.currentTask == component.tasks.FULL) return
204
-
205
- if (r || b || p || c) {
206
- component.jobLightOn(cookedData)
207
- }
208
- })
209
- }
210
- break
211
- case 'IND_ON_RES':
212
- {
213
- if (gateway.state.boot_flag == 'false') return
214
- gateway.indicators.forEach(indicator => {
215
- if (indicator.model.id === message.body.id) {
216
- var displayData: any = {}
217
- if (message.body.biz_flag == 'cancel') {
218
- displayData.org_ea_qty = message.body.res_ea_qty
219
- displayData.org_box_qty = message.body.org_box_qty
220
- } else {
221
- displayData.org_ea_qty = message.body.res_ea_qty
222
- displayData.org_box_qty = message.body.res_box_qty
223
- }
224
-
225
- displayData.buttonColor = ''
226
- indicator.cookedData = displayData
227
- indicator.jobLightOn(displayData)
228
- indicator.currentTask = indicator.tasks.END
229
- }
230
- })
231
- }
232
- break
233
- case 'IND_OFF_REQ':
234
- {
235
- if (gateway.state.boot_flag == 'false') return
236
-
237
- gateway.indicators.forEach(indicator => {
238
- // 인디케이터가 END 상태이면서 end_off_flag가 false이고, force_flag가 false이면 소등 안 함
239
- if (indicator.currentTask == indicator.tasks.END && !message.body.end_off_flag && !message.body.force_flag)
240
- return
241
-
242
- // 인디케이터의 불이 꺼져있고, 설정의 off_use_res가 false이면 소등 안 함
243
- if (!indicator.getConf.off_use_res && !indicator.lit) return
244
-
245
- let ind
246
- if (message.body.ind_off)
247
- ind = message.body.ind_off.find((element: any, index: number) => {
248
- return element === indicator.model.id
249
- })
250
- if (!ind) return
251
-
252
- indicator.lightOff()
253
-
254
- gateway.replyPublisher!.data = {
255
- properties: gateway.generateMessageProperties(),
256
- body: {
257
- action: 'IND_OFF_RES',
258
- id: indicator.model.id,
259
- result: true
260
- }
261
- }
262
- consoleLogger('sent IND_OFF_RES', gateway.replyPublisher!.data)
263
- })
264
- }
265
- break
266
- // 4.4 gateway에 배포 요청
267
- case 'GW_DEP_REQ': // 게이트웨이 펌웨어 업데이트
268
- {
269
- if (gateway.state.boot_flag == 'false') return
270
-
271
- // 4.5 firmware download
272
-
273
- // is G/W's firmware update?
274
- // - 인디케이터 펌웨어 업데이트 프로토콜은 따로임
275
-
276
- //firmware update//
277
- let isUpdated = false
278
- let random = Math.random()
279
- if (random > 0.5) {
280
- message.body.ind_url
281
- gateway.version = message.body.version
282
- isUpdated = true
283
- }
284
- ///////////////////
285
-
286
- ///완료 확인 로직?///
287
- ////////////////
288
-
289
- gateway.replyPublisher!.data = {
290
- properties: gateway.generateMessageProperties(),
291
- body: {
292
- action: 'GW_DEP_RES',
293
- id: gateway.model.id,
294
- result: isUpdated,
295
- version: gateway.version,
296
- time: Date.now()
297
- }
298
- }
299
- consoleLogger('sent GW_DEP_RES', gateway.replyPublisher!.data)
300
-
301
- gateway.off()
302
- gateway.boot()
303
- }
304
- //gateway.replyPublisher!.data = null;
305
- break
306
- // 4.4 gateway에 배포 요청
307
- case 'IND_DEP_REQ': // 인디케이터 펌웨어 업데이트
308
- {
309
- if (gateway.state.boot_flag == 'false') return
310
-
311
- // 4.5 firmware download//
312
- //////////////////////////
313
-
314
- // 4.6 indicator에 firmware 전송
315
- gateway.indicators.forEach(indicator => {
316
- if (indicator.state.boot_flag == false) return
317
-
318
- //4.7 firmware 파일 접수//
319
- ////////////////////////
320
-
321
- //4.8 firmware 업데이트//
322
- let result
323
- if (Math.random() > 0.5) {
324
- indicator.version = message.body.version
325
- result = true
326
- } else {
327
- result = false
328
- }
329
- ///////////////////////
330
-
331
- gateway.replyPublisher!.data = {
332
- properties: gateway.generateMessageProperties(),
333
- body: {
334
- action: 'IND_DEP_RES',
335
- id: indicator.model.id,
336
- result: result,
337
- version: indicator.version,
338
- time: Date.now()
339
- }
340
- }
341
- consoleLogger('sent IND_DEP_RES', gateway.replyPublisher!.data)
342
- })
343
- // boot
344
- gateway.off()
345
- gateway.boot()
346
- }
347
- break
348
- case 'TIMESYNC_RES': // 시간 동기화
349
- {
350
- if (gateway.state.boot_flag == 'false') return
351
- gateway.setTimer(parseInt(message.body.svr_time) * 1000)
352
- if (!gateway.time) gateway.timerOn()
353
- }
354
- break
355
- case 'MW_MOD_IP_REQ':
356
- {
357
- gateway.replyPublisher!.data = {
358
- properties: gateway.generateMessageProperties(),
359
- body: {
360
- action: 'MW_MOD_IP_RES',
361
- id: gateway.model.id,
362
- result: Math.random() > 0.5 ? true : false
363
- }
364
- }
365
- }
366
- break
367
- case 'LED_ON_REQ':
368
- {
369
- let ind = gateway.indicators.findIndex((indicator, index) => {
370
- return indicator.model.id === message.body.id
371
- })
372
- if (ind != -1) {
373
- Object.keys(gateway.indicators[ind].conf).forEach(opt => {
374
- if (message.body.hasOwnProperty(opt)) {
375
- gateway.indicators[ind].conf[opt] = message.body[opt]
376
- }
377
- })
378
- let color = '#f00'
379
-
380
- if (gateway.indicators[ind].getConf.led_bar_brtns > 10) gateway.indicators[ind].conf.led_bar_brtns = 10
381
- color = color + Math.round((gateway.indicators[ind].getConf.led_bar_brtns * 15) / 10).toString(16)
382
-
383
- gateway.indicators[ind].ledRect.strokeStyle = color
384
- gateway.indicators[ind].ledLit = true
385
- } else consoleLogger('Could not find indicator', message.body.id)
386
- }
387
- break
388
- case 'LED_OFF_REQ':
389
- {
390
- let ind = gateway.indicators.findIndex((indicator, index) => {
391
- return indicator.model.id === message.body.id
392
- })
393
- if (ind != -1) {
394
- gateway.indicators[ind].ledRect.strokeStyle = '#0000'
395
- gateway.indicators[ind].ledLit = false
396
- } else consoleLogger('Could not find indicator', message.body.id)
397
- }
398
- break
399
- default:
400
- consoleLogger('unknown message', message)
401
- }
402
- } else {
403
- consoleLogger('server reply: ', message)
404
- }
405
- }