-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPCARSLV_SETTINGS.js
197 lines (154 loc) · 4.43 KB
/
PCARSLV_SETTINGS.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//import PCARSLV_BASIC from './PCARSLV_BASIC.js';
class PCARSLV_SETTINGS extends PCARSLV_BASIC {
// example function header
/*
* param {string}
* param {object}
* param {int}
*
* return {string} true if all is fine, false if something went wrong
*/
/* getAPIMODE()
*
* return {boolean} true if all is fine, false if something went wrong
*/
constructor() {
super(); // get functions from basic class
this.initFromConfigFile();
}
/* initFromConfigFile()
* initialize all relevant variables from config file.
*
* return {boolean} true if all is fine, false if something went wrong
*/
initFromConfigFile(){
this.version = SCRIPTVERSION;
this.curAPIMODE = APIMODE;
this.curDsServerURL = DsServerURL;
this.curDsPort = DsPort;
return true;
}
/* switchAPIMODE()
*
* return {boolean} true if all is fine, false if something went wrong
*/
switchAPIMODE(apimode){
switch (apimode) {
// validations
case "DS":
if (this.curDsServerURL && this.curDsPort !== undefined){
if (this._isApiModeValid(apimode)){
this.curAPIMODE = apimode; // set new API mode
this.displayMsg("INFO", "API Mode switched to: " + apimode);
} else {
this.displayMsg("WARN", "API Mode NOT switched. \nInvalid APIMODE: " + apimode);
}
}else{
this.displayErrorMsg("Switch canceled, not all variables defined. \nDSSERVERURL: "+ this.curDsServerURL +"\nDSPORT: "+ this.curDsPort +" !");
}
break;
case "DEMO":
if (this._isApiModeValid(apimode)){
this.curAPIMODE = apimode; // set new API mode
this.displayMsg("INFO", "API Mode switched to: " + apimode);
} else {
this.displayMsg("WARN", "API Mode NOT switched. \nInvalid APIMODE: " + apimode);
}
break;
default:
if (this._isApiModeValid(apimode)){
this.curAPIMODE = apimode; // set new API mode
this.displayMsg("INFO", "API Mode switched to: " + apimode);
} else {
this.displayMsg("ERROR", "API Mode NOT switched. \nInvalid APIMODE: " + apimode);
}
break;
}
if (this.curAPIMODE){
return this.curAPIMODE;
}else{
this.displayErrorMsg("APIMODE not defined"); // used from basic class
return false;
}
}
/* getAPIMODE()
*
* return {boolean} true if all is fine, false if something went wrong
*/
getAPIMODE(){
if (this.curAPIMODE){
return this.curAPIMODE;
}else{
this.displayErrorMsg("APIMODE not defined"); // used from basic class
return false;
}
}
/* getAPIMODE()
*
* param {string} string of the APIMODE
* return {boolean} true if all is fine, false if something went wrong
*/
_isApiModeValid(apimode){
var aVALIDAPIMODES = {
"DS" : 'active',
"DS2" : 'active',
"DS-AMS2" : 'active',
"CREST" : 'active',
"CREST2" : 'active',
"CREST2-AMS2" : 'active',
"DEMO" : 'active'
}
if (apimode in aVALIDAPIMODES){
return true;
}else{
return false;
}
}
/*
* Description: In case of APIMODE switch, copy specific variables to the common one
* Usage: setCurrentSettings("CREST2");
*
* param {string} string of APIMODE
* return {bolean} true if all is fine, false if something went wrong
*/
setCurrentSettings(sApiMode){
switch(sApiMode){
case "DS":
sCurUrl = DsServerURL;
sCurPort = DsPort;
sCurPath = DsPath;
break;
case "DS2":
sCurUrl = Ds2ServerURL;
sCurPort = Ds2Port;
sCurPath = Ds2Path;
break;
case "DS-AMS2":
sCurUrl = DsAMS2ServerURL;
sCurPort = DsAMS2Port;
sCurPath = DsAMS2Path;
break;
case "CREST":
sCurUrl = CRESTServerURL;
sCurPort = CRESTPort;
sCurPath = CRESTPath;
break;
case "CREST2":
sCurUrl = CREST2ServerURL;
sCurPort = CREST2Port;
sCurPath = CREST2Path;
break;
case "CREST2-AMS2":
sCurUrl = CREST2AMS2ServerURL;
sCurPort = CREST2AMS2Port;
sCurPath = CREST2AMS2Path;
break;
default: // fall back to DS1 settings
sCurUrl = DsServerURL;
sCurPort = DsPort;
sCurPath = DsPath;
}
if(log >= 3){console.log ("called setCurrentSettings() changed to: " +"|" + sCurUrl +' | '+ sCurPort);}
return 1;
}
}