1 | 'use strict';
|
---|
2 |
|
---|
3 | // To de done:
|
---|
4 | // - CheckLID status (should be open or closed)
|
---|
5 | // - Is it necessary to switch the bias-voltage off?
|
---|
6 | // - Get reasonable timeouts for all steps (wait, get, run)
|
---|
7 | // - Improve order to accelerate execution
|
---|
8 | //
|
---|
9 | // =================================================================
|
---|
10 |
|
---|
11 | /*
|
---|
12 | var table =
|
---|
13 | [
|
---|
14 | [ "AGILENT_CONTROL" ],
|
---|
15 | [ "BIAS_CONTROL" ],
|
---|
16 | [ "CHAT" ],
|
---|
17 | [ "DATA_LOGGER" ],
|
---|
18 | [ "DRIVE_CONTROL" ],
|
---|
19 | [ "FEEDBACK" ],
|
---|
20 | [ "FAD_CONTROL" ],
|
---|
21 | [ "FSC_CONTROL" ],
|
---|
22 | [ "FTM_CONTROL" ],
|
---|
23 | [ "LID_CONTROL" ],
|
---|
24 | [ "MAGIC_WEATHER" ],
|
---|
25 | [ "MCP" ],
|
---|
26 | [ "PWR_CONTROL" ],
|
---|
27 | [ "RATE_CONTROL" ],
|
---|
28 | [ "RATE_SCAN" ],
|
---|
29 | [ "SMART_FACT" ],
|
---|
30 | [ "TIME_CHECK" ],
|
---|
31 | [ "TNG_WEATHER" ],
|
---|
32 | ];
|
---|
33 |
|
---|
34 | if (dim.state("DRIVE_CONTROL").name=="Locked")
|
---|
35 | {
|
---|
36 | throw new Error("Drivectrl still locked... needs UNLOCK first.");
|
---|
37 | //while (!dim.send("DRIVE_CONTROL"))
|
---|
38 | // v8.sleep();
|
---|
39 | //dim.send("DRIVE_CONTROL/UNLOCK");
|
---|
40 | //dim.wait("DRIVE_CONTROL", "Armed", 1000);
|
---|
41 | }
|
---|
42 |
|
---|
43 | */
|
---|
44 |
|
---|
45 | console.out("");
|
---|
46 | dim.alarm();
|
---|
47 |
|
---|
48 | var loop;
|
---|
49 | include("scripts/Handler.js");
|
---|
50 | include("scripts/CheckStates.js");
|
---|
51 |
|
---|
52 | // -----------------------------------------------------------------
|
---|
53 | // Make sure camera electronics is switched on and has power
|
---|
54 | // -----------------------------------------------------------------
|
---|
55 |
|
---|
56 | include("scripts/handleAgilentPowerOn24V.js");
|
---|
57 | include("scripts/handleAgilentPowerOn50V.js");
|
---|
58 | include("scripts/handleAgilentPowerOn80V.js");
|
---|
59 | include("scripts/handlePwrCameraOn.js");
|
---|
60 |
|
---|
61 | checkSend(["AGILENT_CONTROL_24V","AGILENT_CONTROL_50V","AGILENT_CONTROL_80V","PWR_CONTROL"]);
|
---|
62 |
|
---|
63 | loop = new Handler("PowerOn");
|
---|
64 | //loop.add(handleAgilentPowerOn24V);
|
---|
65 | //loop.add(handleAgilentPowerOn50V);
|
---|
66 | //loop.add(handleAgilentPowerOn80V);
|
---|
67 | loop.add(handlePwrCameraOn);
|
---|
68 | loop.run(30000);
|
---|
69 | console.out("");
|
---|
70 |
|
---|
71 | // If power was switched on: wait for a few seconds
|
---|
72 |
|
---|
73 | // -----------------------------------------------------------------
|
---|
74 | // Now take care that the bias control, the ftm and the fsc are
|
---|
75 | // properly connected and are in a reasonable state (e.g. the
|
---|
76 | // trigger is switched off)
|
---|
77 | // -----------------------------------------------------------------
|
---|
78 |
|
---|
79 | include("scripts/handleBiasVoltageOff.js");
|
---|
80 | include("scripts/handleFtmIdle.js");
|
---|
81 | include("scripts/handleFscConnected.js");
|
---|
82 | include("scripts/handleFeedbackConnected.js");
|
---|
83 | include("scripts/handleRatectrlConnected.js");
|
---|
84 | include("scripts/handleLidClosed.js");
|
---|
85 | include("scripts/handleFadConnected.js");
|
---|
86 | include("scripts/handleScheduler.js");
|
---|
87 |
|
---|
88 | checkSend(["BIAS_CONTROL","FAD_CONTROL","FTM_CONTROL", "FSC_CONTROL", "FEEDBACK", "RATE_CONTROL", "MCP", "SCHEDULER"]);
|
---|
89 |
|
---|
90 | dim.send("MCP/RESET");
|
---|
91 |
|
---|
92 | loop = new Handler("SystemSetup");
|
---|
93 | loop.add(handleBiasVoltageOff);
|
---|
94 | loop.add(handleFtmIdle);
|
---|
95 | loop.add(handleFscConnected);
|
---|
96 | loop.add(handleFadConnected);
|
---|
97 | loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
|
---|
98 | loop.add(handleRatectrlConnected);
|
---|
99 | loop.add(handleLidClosed);
|
---|
100 | loop.add(handleScheduler);
|
---|
101 | loop.run(60000);
|
---|
102 |
|
---|
103 | console.out("biasctrl: "+dim.state("BIAS_CONTROL").name);
|
---|
104 | console.out("ftmctrl: "+dim.state("FTM_CONTROL").name);
|
---|
105 | console.out("fscctrl: "+dim.state("FSC_CONTROL").name);
|
---|
106 | console.out("feedback: "+dim.state("FEEDBACK").name);
|
---|
107 | console.out("ratecontrol: "+dim.state("RATE_CONTROL").name);
|
---|
108 | console.out("fadctrl: "+dim.state("FAD_CONTROL").name);
|
---|
109 | console.out("mcp: "+dim.state("MCP").name);
|
---|
110 | console.out("scheduler: "+dim.state("SCHEDULER").name);
|
---|
111 | console.out("");
|
---|
112 |
|
---|
113 | console.out("Enable all FTU");
|
---|
114 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
|
---|
115 |
|
---|
116 | // -----------------------------------------------------------------
|
---|
117 | // Now we check the FTU connection
|
---|
118 | // -----------------------------------------------------------------
|
---|
119 |
|
---|
120 | /*
|
---|
121 | include("scripts/handleFtuCheck.js");
|
---|
122 |
|
---|
123 | loop = new Handler("FtuCheck");
|
---|
124 | loop.ftuList = new Subscription("FTM_CONTROL/FTU_LIST");
|
---|
125 | loop.add(handleFtuCheck);
|
---|
126 | loop.run();
|
---|
127 | loop.ftuList.close();
|
---|
128 |
|
---|
129 | dim.log("All FTUs are enabled and without error.");
|
---|
130 | */
|
---|
131 |
|
---|
132 | console.out("Checking FTU: start");
|
---|
133 | include("scripts/CheckFTU.js");
|
---|
134 | console.out("Checking FTU: done");
|
---|
135 | console.out("");
|
---|
136 |
|
---|
137 | // -----------------------------------------------------------------
|
---|
138 | // Now we check the clock conditioner
|
---|
139 | // -----------------------------------------------------------------
|
---|
140 |
|
---|
141 | var sub_counter = new Subscription("FTM_CONTROL/COUNTER");
|
---|
142 | var counter = sub_counter.get(3000, false).counter;
|
---|
143 | dim.send("FTM_CONTROL/REQUEST_STATIC_DATA");
|
---|
144 | v8.timeout(3000, function() { if (sub_counter.get(0, false).counter>counter) return true; });
|
---|
145 | if (sub_counter.get(0, false).qos&0x100==0)
|
---|
146 | throw new Error("Clock conditioner not locked.");
|
---|
147 | sub_counter.close();
|
---|
148 |
|
---|
149 | // -----------------------------------------------------------------
|
---|
150 | // Now we can safely try to connect the FAD boards.
|
---|
151 | // -----------------------------------------------------------------
|
---|
152 | /*
|
---|
153 | include("scripts/handleFadConnected.js");
|
---|
154 |
|
---|
155 | // If FADs already connected
|
---|
156 |
|
---|
157 | checkSend(["FAD_CONTROL"]);
|
---|
158 |
|
---|
159 | loop = new Handler("ConnectFad");
|
---|
160 | loop.add(handleFadConnected);
|
---|
161 | loop.run();
|
---|
162 |
|
---|
163 | var failed = false;
|
---|
164 | dim.onchange["FAD_CONTROL"] = function(arg)
|
---|
165 | {
|
---|
166 | if (this.rc && arg.name!="Connected")
|
---|
167 | failed = true;
|
---|
168 | }
|
---|
169 |
|
---|
170 | console.out("FADs connected.");
|
---|
171 | console.out("");
|
---|
172 |
|
---|
173 | console.out(dim.state("FAD_CONTROL").name);
|
---|
174 | console.out(dim.state("MCP").name);
|
---|
175 | */
|
---|
176 |
|
---|
177 | // ================================================================
|
---|
178 | // Underflow check
|
---|
179 | // ================================================================
|
---|
180 | // Is it necessary to check for the so called 'underflow-problem'?
|
---|
181 | // (This is necessary after each power cycle)
|
---|
182 | // ----------------------------------------------------------------
|
---|
183 |
|
---|
184 | include('scripts/CheckUnderflow.js');
|
---|
185 |
|
---|
186 | // Now it is time to check the connection of the FADs
|
---|
187 | // it might hav thrown an exception already anyway
|
---|
188 |
|
---|
189 |
|
---|
190 | // ================================================================
|
---|
191 | // Power on drive system if power is off (do it hre to make sure not
|
---|
192 | // everything is switchd on at the same time)
|
---|
193 | // ================================================================
|
---|
194 |
|
---|
195 | //console.out("PWR: "+(dim.state("PWR_CONTROL").index&16));
|
---|
196 |
|
---|
197 | if ((dim.state("PWR_CONTROL").index&16)==0)
|
---|
198 | {
|
---|
199 | console.out("Drive cabinet not powered... Switching on.");
|
---|
200 | dim.send("PWR_CONTROL/TOGGLE_DRIVE");
|
---|
201 | v8.timeout(5000, function() { if (dim.state("PWR_CONTROL").index&16) return true; });
|
---|
202 | }
|
---|
203 |
|
---|
204 | include("scripts/handleDriveArmed.js");
|
---|
205 |
|
---|
206 | checkSend(["DRIVE_CONTROL"]);
|
---|
207 |
|
---|
208 | loop = new Handler("ArmDrive");
|
---|
209 | loop.add(handleDriveArmed);
|
---|
210 | loop.run(30000);
|
---|
211 |
|
---|
212 |
|
---|
213 | // ================================================================
|
---|
214 | // Bias crate calibration
|
---|
215 | // ================================================================
|
---|
216 | // Bias crate calibration if necessary (it is aftr 4pm (local tome)
|
---|
217 | // and the last calibration was more than eight hours ago.
|
---|
218 | // -----------------------------------------------------------------
|
---|
219 |
|
---|
220 | // At this point we know that:
|
---|
221 | // 1) The lid is closed
|
---|
222 | // 2) The feedback is stopped
|
---|
223 | // 3) The voltage is off
|
---|
224 | function makeCurrentCalibration()
|
---|
225 | {
|
---|
226 | dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
|
---|
227 | dim.wait("BIAS_CONTROL", "VoltageOff", 30000); // waS: 15000
|
---|
228 |
|
---|
229 | var now = new Date();
|
---|
230 | dim.send("FEEDBACK/CALIBRATE");
|
---|
231 |
|
---|
232 | console.out("Wait for calibration to start");
|
---|
233 | dim.wait("FEEDBACK", "Calibrating", 5000);
|
---|
234 |
|
---|
235 | console.out("Wait for calibration to end");
|
---|
236 | dim.wait("FEEDBACK", "Calibrated", 90000);
|
---|
237 |
|
---|
238 | console.out("Calibration finished ["+(new Date()-now)+"ms]");
|
---|
239 |
|
---|
240 | console.out("Wait for voltage to be off");
|
---|
241 | dim.wait("BIAS_CONTROL", "VoltageOff", 30000); // was: 15000
|
---|
242 | }
|
---|
243 |
|
---|
244 | // Check age of calibration
|
---|
245 | var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
|
---|
246 |
|
---|
247 | var data_calibration = service_calibration.get(3000, false);
|
---|
248 |
|
---|
249 | var age = data_calibration.time;
|
---|
250 | var now = new Date();
|
---|
251 |
|
---|
252 | var diff = (now-age)/3600000;
|
---|
253 |
|
---|
254 | var fb_state = dim.state("FEEDBACK").index;
|
---|
255 |
|
---|
256 | // !data_calibration.data: FEEDBACK might just be freshly
|
---|
257 | // started and will not yet serve this service.
|
---|
258 | if (fb_state<5 || (diff>8 && now.getHours()>16))
|
---|
259 | {
|
---|
260 | if (fb_state<5)
|
---|
261 | console.out("No BIAS crate calibration available: New calibration needed.");
|
---|
262 | else
|
---|
263 | console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
|
---|
264 |
|
---|
265 | makeCurrentCalibration();
|
---|
266 | }
|
---|
267 |
|
---|
268 | service_calibration.close();
|
---|
269 |
|
---|
270 | // ================================================================
|
---|
271 | // Setup GPS control and wait for the satellites to be locked
|
---|
272 | // ================================================================
|
---|
273 |
|
---|
274 | checkSend(["GPS_CONTROL"]);
|
---|
275 |
|
---|
276 | if (dim.state("GPS_CONTROL").name=="Disconnected")
|
---|
277 | dim.send("GPS_CONTROL/RECONNECT");
|
---|
278 |
|
---|
279 | // Wait for being connectes
|
---|
280 | v8.timeout(5000, function() { if (dim.state("GPS_CONTROL").name!="Disconnected") return true; });
|
---|
281 |
|
---|
282 | // Wait for status available
|
---|
283 | v8.timeout(5000, function() { if (dim.state("GPS_CONTROL").name!="Connected") return true; });
|
---|
284 |
|
---|
285 | if (dim.state("GPS_CONTROL").name=="Disabled")
|
---|
286 | dim.send("GPS_CONTROL/ENABLE");
|
---|
287 |
|
---|
288 | // Wait for gps to be enabled and locked
|
---|
289 | dim.wait("GPS_CONTROL", "Locked", 15000);
|
---|
290 |
|
---|
291 | // ================================================================
|
---|
292 | // Crosscheck all states
|
---|
293 | // ================================================================
|
---|
294 |
|
---|
295 | // FIXME: Check if there is a startup scheduled, if not do not force
|
---|
296 | // drive to be switched on
|
---|
297 |
|
---|
298 | var table =
|
---|
299 | [
|
---|
300 | [ "TNG_WEATHER" ],
|
---|
301 | [ "MAGIC_WEATHER" ],
|
---|
302 | [ "RAIN_SENSOR" ],
|
---|
303 | [ "CHAT" ],
|
---|
304 | [ "SMART_FACT" ],
|
---|
305 | [ "TEMPERATURE" ],
|
---|
306 | [ "SCHEDULER", [ "Connected", "Armed" ] ],
|
---|
307 | [ "EVENT_SERVER", [ "Running", "Standby" ] ],
|
---|
308 | [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
|
---|
309 | [ "FSC_CONTROL", [ "Connected" ] ],
|
---|
310 | [ "MCP", [ "Idle" ] ],
|
---|
311 | [ "TIME_CHECK", [ "Valid" ] ],
|
---|
312 | [ "PWR_CONTROL", [ "SystemOn" ] ],
|
---|
313 | [ "AGILENT_CONTROL_24V", [ "VoltageOn" ] ],
|
---|
314 | [ "AGILENT_CONTROL_50V", [ "VoltageOn" ] ],
|
---|
315 | [ "AGILENT_CONTROL_80V", [ "VoltageOn", "Disconnected" ] ], //hack to allow for data taking while agilent not available
|
---|
316 | [ "BIAS_CONTROL", [ "VoltageOff" ] ],
|
---|
317 | [ "FEEDBACK", [ "Calibrated" ] ],
|
---|
318 | [ "RATE_SCAN", [ "Connected" ] ],
|
---|
319 | [ "RATE_CONTROL", [ "Connected" ] ],
|
---|
320 | [ "DRIVE_CONTROL", [ "Initialized", "Tracking", "OnTrack", "Locked" ] ],
|
---|
321 | [ "LID_CONTROL", [ "Open", "Closed" ] ],
|
---|
322 | [ "FTM_CONTROL", [ "Valid", "TriggerOn" ] ],
|
---|
323 | [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
|
---|
324 | [ "GPS_CONTROL", [ "Locked" ] ],
|
---|
325 | // [ "SQM_CONTROL", [ "Valid" ] ],
|
---|
326 | [ "PFMINI_CONTROL", [ "Receiving" ] ],
|
---|
327 | [ "BIAS_TEMP", [ "Valid" ] ],
|
---|
328 | ];
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 | if (!checkStates(table))
|
---|
333 | {
|
---|
334 | throw new Error("Something unexpected has happened. Although the startup-"+
|
---|
335 | "procedure has finished, not all servers are in the state "+
|
---|
336 | "in which they ought to be. Please, try to find out what "+
|
---|
337 | "happened...");
|
---|
338 | }
|
---|