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/handleAgilentPowerOn.js");
|
---|
57 | include("scripts/handlePwrCameraOn.js");
|
---|
58 |
|
---|
59 | checkSend(["AGILENT_CONTROL","PWR_CONTROL"]);
|
---|
60 |
|
---|
61 | loop = new Handler("PowerOn");
|
---|
62 | //loop.add(handleAgilentPowerOn);
|
---|
63 | loop.add(handlePwrCameraOn);
|
---|
64 | loop.run();
|
---|
65 | console.out("");
|
---|
66 |
|
---|
67 | // If power was switched on: wait for a few seconds
|
---|
68 |
|
---|
69 | // -----------------------------------------------------------------
|
---|
70 | // Now take care that the bias control, the ftm and the fsc are
|
---|
71 | // properly connected and are in a reasonable state (e.g. the
|
---|
72 | // trigger is switched off)
|
---|
73 | // -----------------------------------------------------------------
|
---|
74 |
|
---|
75 | include("scripts/handleBiasVoltageOff.js");
|
---|
76 | include("scripts/handleFtmIdle.js");
|
---|
77 | include("scripts/handleFscConnected.js");
|
---|
78 | include("scripts/handleFeedbackConnected.js");
|
---|
79 | include("scripts/handleRatectrlConnected.js");
|
---|
80 | include("scripts/handleLidClosed.js");
|
---|
81 | include("scripts/handleFadConnected.js");
|
---|
82 |
|
---|
83 | checkSend(["BIAS_CONTROL","FAD_CONTROL","FTM_CONTROL", "FSC_CONTROL", "FEEDBACK", "RATE_CONTROL", "MCP"]);
|
---|
84 |
|
---|
85 | dim.send("MCP/RESET");
|
---|
86 |
|
---|
87 | loop = new Handler("SystemSetup");
|
---|
88 | loop.add(handleBiasVoltageOff);
|
---|
89 | loop.add(handleFtmIdle);
|
---|
90 | loop.add(handleFscConnected);
|
---|
91 | loop.add(handleFadConnected);
|
---|
92 | loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
|
---|
93 | loop.add(handleRatectrlConnected);
|
---|
94 | //loop.add(handleLidClosed);
|
---|
95 | loop.run();
|
---|
96 |
|
---|
97 | console.out("biasctrl: "+dim.state("BIAS_CONTROL").name);
|
---|
98 | console.out("ftmctrl: "+dim.state("FTM_CONTROL").name);
|
---|
99 | console.out("fscctrl: "+dim.state("FSC_CONTROL").name);
|
---|
100 | console.out("feedback: "+dim.state("FEEDBACK").name);
|
---|
101 | console.out("ratecontrol: "+dim.state("RATE_CONTROL").name);
|
---|
102 | console.out("fadctrl: "+dim.state("FAD_CONTROL").name);
|
---|
103 | console.out("mcp: "+dim.state("MCP").name);
|
---|
104 | console.out("");
|
---|
105 |
|
---|
106 | console.out("Enable all FTU");
|
---|
107 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
|
---|
108 |
|
---|
109 | // -----------------------------------------------------------------
|
---|
110 | // Now we check the FTU connection
|
---|
111 | // -----------------------------------------------------------------
|
---|
112 |
|
---|
113 | /*
|
---|
114 | include("scripts/handleFtuCheck.js");
|
---|
115 |
|
---|
116 | loop = new Handler("FtuCheck");
|
---|
117 | loop.ftuList = new Subscription("FTM_CONTROL/FTU_LIST");
|
---|
118 | loop.add(handleFtuCheck);
|
---|
119 | loop.run();
|
---|
120 | loop.ftuList.close();
|
---|
121 |
|
---|
122 | dim.log("All FTUs are enabled and without error.");
|
---|
123 | */
|
---|
124 |
|
---|
125 | console.out("Checking FTU: start");
|
---|
126 | include("scripts/CheckFTU.js");
|
---|
127 | console.out("Checking FTU: done");
|
---|
128 | console.out("");
|
---|
129 |
|
---|
130 | // -----------------------------------------------------------------
|
---|
131 | // Now we check the clock conditioner
|
---|
132 | // -----------------------------------------------------------------
|
---|
133 |
|
---|
134 | var sub_counter = new Subscription("FTM_CONTROL/COUNTER");
|
---|
135 | var counter = sub_counter.get(3000, false).counter;
|
---|
136 | dim.send("FTM_CONTROL/REQUEST_STATIC_DATA");
|
---|
137 | v8.timeout(3000, function() { if (sub_counter.get(0, false).counter>counter) return true; });
|
---|
138 | if (sub_counter.get(0, false).qos&0x100==0)
|
---|
139 | throw new Error("Clock conditioner not locked.");
|
---|
140 | sub_counter.close();
|
---|
141 |
|
---|
142 | // -----------------------------------------------------------------
|
---|
143 | // Now we can safely try to connect the FAD boards.
|
---|
144 | // -----------------------------------------------------------------
|
---|
145 | /*
|
---|
146 | include("scripts/handleFadConnected.js");
|
---|
147 |
|
---|
148 | // If FADs already connected
|
---|
149 |
|
---|
150 | checkSend(["FAD_CONTROL"]);
|
---|
151 |
|
---|
152 | loop = new Handler("ConnectFad");
|
---|
153 | loop.add(handleFadConnected);
|
---|
154 | loop.run();
|
---|
155 |
|
---|
156 | var failed = false;
|
---|
157 | dim.onchange["FAD_CONTROL"] = function(arg)
|
---|
158 | {
|
---|
159 | if (this.rc && arg.name!="Connected")
|
---|
160 | failed = true;
|
---|
161 | }
|
---|
162 |
|
---|
163 | console.out("FADs connected.");
|
---|
164 | console.out("");
|
---|
165 |
|
---|
166 | console.out(dim.state("FAD_CONTROL").name);
|
---|
167 | console.out(dim.state("MCP").name);
|
---|
168 | */
|
---|
169 |
|
---|
170 | // ================================================================
|
---|
171 | // Underflow check
|
---|
172 | // ================================================================
|
---|
173 | // Is it necessary to check for the so called 'underflow-problem'?
|
---|
174 | // (This is necessary after each power cycle)
|
---|
175 | // ----------------------------------------------------------------
|
---|
176 |
|
---|
177 | include('scripts/CheckUnderflow.js');
|
---|
178 |
|
---|
179 | // Now it is time to check the connection of the FADs
|
---|
180 | // it might hav thrown an exception already anyway
|
---|
181 |
|
---|
182 |
|
---|
183 | // ================================================================
|
---|
184 | // Power on drive system if power is off (do it hre to make sure not
|
---|
185 | // everything is switchd on at the same time)
|
---|
186 | // ================================================================
|
---|
187 |
|
---|
188 | //console.out("PWR: "+(dim.state("PWR_CONTROL").index&16));
|
---|
189 |
|
---|
190 | if ((dim.state("PWR_CONTROL").index&16)==0)
|
---|
191 | {
|
---|
192 | console.out("Drive cabinet not power... Switching on.");
|
---|
193 | dim.send("PWR_CONTROL/TOGGLE_DRIVE");
|
---|
194 | v8.timeout(5000, function() { if (dim.state("PWR_CONTROL").index&16) return true; });
|
---|
195 | }
|
---|
196 |
|
---|
197 | include("scripts/handleDriveArmed.js");
|
---|
198 |
|
---|
199 | checkSend(["DRIVE_CONTROL"]);
|
---|
200 |
|
---|
201 | loop = new Handler("ArmDrive");
|
---|
202 | loop.add(handleDriveArmed);
|
---|
203 | loop.run();
|
---|
204 |
|
---|
205 |
|
---|
206 | // ================================================================
|
---|
207 | // Bias crate calibration
|
---|
208 | // ================================================================
|
---|
209 | // Bias crate calibration if necessary (it is aftr 4pm (local tome)
|
---|
210 | // and the last calibration was more than eight hours ago.
|
---|
211 | // -----------------------------------------------------------------
|
---|
212 |
|
---|
213 | // At this point we know that:
|
---|
214 | // 1) The lid is closed
|
---|
215 | // 2) The feedback is stopped
|
---|
216 | // 3) The voltage is off
|
---|
217 | function makeCurrentCalibration()
|
---|
218 | {
|
---|
219 | dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
|
---|
220 | dim.wait("BIAS_CONTROL", "VoltageOff", 30000); // waS: 15000
|
---|
221 |
|
---|
222 | var now = new Date();
|
---|
223 | dim.send("FEEDBACK/CALIBRATE");
|
---|
224 |
|
---|
225 | console.out("Wait for calibration to start");
|
---|
226 | dim.wait("FEEDBACK", "Calibrating", 5000);
|
---|
227 |
|
---|
228 | console.out("Wait for calibration to end");
|
---|
229 | dim.wait("FEEDBACK", "Calibrated", 90000);
|
---|
230 |
|
---|
231 | console.out("Calibration finished ["+(new Date()-now)+"ms]");
|
---|
232 |
|
---|
233 | console.out("Wait for voltage to be off");
|
---|
234 | dim.wait("BIAS_CONTROL", "VoltageOff", 30000); // was: 15000
|
---|
235 | }
|
---|
236 |
|
---|
237 | // Check age of calibration
|
---|
238 | var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
|
---|
239 |
|
---|
240 | var data_calibration = service_calibration.get(3000, false);
|
---|
241 |
|
---|
242 | var age = data_calibration.time;
|
---|
243 | var now = new Date();
|
---|
244 |
|
---|
245 | var diff = (now-age)/3600000;
|
---|
246 |
|
---|
247 | var fb_state = dim.state("FEEDBACK").index;
|
---|
248 |
|
---|
249 | // !data_calibration.data: FEEDBACK might just be freshly
|
---|
250 | // started and will not yet serve this service.
|
---|
251 | if (fb_state<5 || (diff>8 && now.getHours()>16))
|
---|
252 | {
|
---|
253 | if (fb_state<5)
|
---|
254 | console.out("No BIAS crate calibration available: New calibration needed.");
|
---|
255 | else
|
---|
256 | console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
|
---|
257 |
|
---|
258 | makeCurrentCalibration();
|
---|
259 | }
|
---|
260 |
|
---|
261 | service_calibration.close();
|
---|
262 |
|
---|
263 | // ================================================================
|
---|
264 | // Crosscheck all states
|
---|
265 | // ================================================================
|
---|
266 |
|
---|
267 | // FIXME: Check if there is a startup shceduled, if not do not force
|
---|
268 | // drive to be switched on
|
---|
269 |
|
---|
270 | var table =
|
---|
271 | [
|
---|
272 | [ "TNG_WEATHER" ],
|
---|
273 | [ "MAGIC_WEATHER" ],
|
---|
274 | [ "CHAT" ],
|
---|
275 | [ "SMART_FACT" ],
|
---|
276 | [ "TEMPERATURE" ],
|
---|
277 | [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
|
---|
278 | [ "FSC_CONTROL", [ "Connected" ] ],
|
---|
279 | [ "MCP", [ "Idle" ] ],
|
---|
280 | [ "TIME_CHECK", [ "Valid" ] ],
|
---|
281 | [ "PWR_CONTROL", [ "SystemOn" ] ],
|
---|
282 | [ "AGILENT_CONTROL", [ "VoltageOn" ] ],
|
---|
283 | [ "BIAS_CONTROL", [ "VoltageOff" ] ],
|
---|
284 | [ "FEEDBACK", [ "Calibrated" ] ],
|
---|
285 | [ "RATE_SCAN", [ "Connected" ] ],
|
---|
286 | [ "RATE_CONTROL", [ "Connected" ] ],
|
---|
287 | [ "LID_CONTROL", [ "Open", "Closed" ] ],
|
---|
288 | [ "DRIVE_CONTROL", [ "Armed", "Tracking", "OnTrack", "Locked" ] ],
|
---|
289 | [ "FTM_CONTROL", [ "Valid", "TriggerOn" ] ],
|
---|
290 | [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
|
---|
291 | ];
|
---|
292 |
|
---|
293 | if (!checkStates(table))
|
---|
294 | {
|
---|
295 | throw new Error("Something unexpected has happened. Although the startup-"+
|
---|
296 | "procedure has finished, not all servers are in the state "+
|
---|
297 | "in which they ought to be. Please, try to find out what "+
|
---|
298 | "happened...");
|
---|
299 | }
|
---|