-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbpWorker.js
84 lines (80 loc) · 2.24 KB
/
bpWorker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
self.addEventListener(
"message",
(e) => {
let bpTmp = e.data[1];
console.log(`【W→BPW受】自弁指令:${e.data[0]}現在BP:${e.data[1]}`);
//BP圧力指定 後で変更
let bpTarget;
switch (e.data[0]) {
case 0:
bpTarget = 490;
break;
case 1:
bpTarget = 470;
break;
case 2:
bpTarget = 450;
break;
case 3:
bpTarget = 430;
break;
case 4:
bpTarget = 410;
break;
case 5:
bpTarget = 390;
break;
case 6:
bpTarget = 370;
break;
case 7:
bpTarget = 350;
break;
case 8:
bpTarget = 340;
break;
case 9:
bpTarget = 0;
break;
}
//非常
if(bpTarget == 0){
var timer = setInterval(function() {
console.log(`【bpW】非常制動 元bp:${bpTmp}`);
bpTmp = bpTmp-1;
if(bpTmp<0){bpTmp=0;}
console.log(`【bpW→W送】計算bpP:${bpTmp}kPa`);
self.postMessage(bpTmp);
if (bpTmp==0) {
clearInterval(timer);
}
}, 10);
}
//減圧すべき場合
else if(bpTmp > bpTarget){
var timer = setInterval(function() {
console.log(`【bpW】計算開始 元bp:${bpTmp}`);
bpTmp = Math.floor(bpTmp-2.5);
console.log(`【bpW→W送】計算bpP:${bpTmp}kPa`);
self.postMessage(bpTmp);
if (bpTmp <= bpTarget) {
clearInterval(timer);
}
}, 75);
}
//増圧すべき場合
else if(bpTmp < bpTarget){
var timer = setInterval(function() {
console.log(`【bpW】計算開始 元bp:${bpTmp}`);
bpTmp = Math.floor(bpTmp+2.5);
if(bpTmp>490){bpTmp=490;}
console.log(`【bpW→W送】計算bpP:${bpTmp}kPa`);
self.postMessage(bpTmp);
if (bpTmp >= bpTarget) {
clearInterval(timer);
}
}, 125);
}
},
false
);