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(handleFeedbackConnected); // Feedback needs FAD to be Connected
|
---|
92 | loop.add(handleRatectrlConnected);
|
---|
93 | loop.add(handleFadConnected);
|
---|
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 can safely try to connect the FAD boards.
|
---|
132 | // -----------------------------------------------------------------
|
---|
133 | /*
|
---|
134 | include("scripts/handleFadConnected.js");
|
---|
135 |
|
---|
136 | // If FADs already connected
|
---|
137 |
|
---|
138 | checkSend(["FAD_CONTROL"]);
|
---|
139 |
|
---|
140 | loop = new Handler("ConnectFad");
|
---|
141 | loop.add(handleFadConnected);
|
---|
142 | loop.run();
|
---|
143 |
|
---|
144 | var failed = false;
|
---|
145 | dim.onchange["FAD_CONTROL"] = function(arg)
|
---|
146 | {
|
---|
147 | if (this.rc && arg.name!="Connected")
|
---|
148 | failed = true;
|
---|
149 | }
|
---|
150 |
|
---|
151 | console.out("FADs connected.");
|
---|
152 | console.out("");
|
---|
153 |
|
---|
154 | console.out(dim.state("FAD_CONTROL").name);
|
---|
155 | console.out(dim.state("MCP").name);
|
---|
156 | */
|
---|
157 |
|
---|
158 | // ================================================================
|
---|
159 | // Underflow check
|
---|
160 | // ================================================================
|
---|
161 | // Is it necessary to check for the so called 'underflow-problem'?
|
---|
162 | // (This is necessary after each power cycle)
|
---|
163 | // ----------------------------------------------------------------
|
---|
164 |
|
---|
165 | include('scripts/CheckUnderflow.js');
|
---|
166 |
|
---|
167 | // Now it is time to check the connection of the FADs
|
---|
168 | // it might hav thrown an exception already anyway
|
---|
169 |
|
---|
170 |
|
---|
171 | // ================================================================
|
---|
172 | // Power on drive system if power is off (do it hre to make sure not
|
---|
173 | // everything is switchd on at the same time)
|
---|
174 | // ================================================================
|
---|
175 |
|
---|
176 | //console.out("PWR: "+(dim.state("PWR_CONTROL").index&16));
|
---|
177 |
|
---|
178 | if ((dim.state("PWR_CONTROL").index&16)==0)
|
---|
179 | {
|
---|
180 | console.out("Drive on");
|
---|
181 | dim.send("PWR_CONTROL/TOGGLE_DRIVE");
|
---|
182 | }
|
---|
183 |
|
---|
184 | include("scripts/handleDriveArmed.js");
|
---|
185 |
|
---|
186 | checkSend(["DRIVE_CONTROL"]);
|
---|
187 |
|
---|
188 | loop = new Handler("ArmDrive");
|
---|
189 | loop.add(handleDriveArmed);
|
---|
190 | loop.run();
|
---|
191 |
|
---|
192 |
|
---|
193 | // ================================================================
|
---|
194 | // Bias crate calibration
|
---|
195 | // ================================================================
|
---|
196 | // Bias crate calibration if necessary (it is aftr 4pm (local tome)
|
---|
197 | // and the last calibration was more than eight hours ago.
|
---|
198 | // -----------------------------------------------------------------
|
---|
199 |
|
---|
200 | // At this point we know that:
|
---|
201 | // 1) The lid is closed
|
---|
202 | // 2) The feedback is stopped
|
---|
203 | // 3) The voltage is off
|
---|
204 | function makeCurrentCalibration()
|
---|
205 | {
|
---|
206 | dim.send("BIAS_CONTROL/SET_GLOBAL_DAC", 1);
|
---|
207 | dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
|
---|
208 |
|
---|
209 | var now = new Date();
|
---|
210 | dim.send("FEEDBACK/CALIBRATE_CURRENTS");
|
---|
211 |
|
---|
212 | // FIXME: Timeout!
|
---|
213 | console.out("Wait for calibration to start");
|
---|
214 | dim.wait("FEEDBACK", "Calibrating", 5000);
|
---|
215 |
|
---|
216 | console.out("Wait for calibration to end");
|
---|
217 | dim.wait("FEEDBACK", "Connected", 60000);
|
---|
218 |
|
---|
219 | console.out("Calibration took "+(new Date()-now)+"ms");
|
---|
220 |
|
---|
221 | console.out("Wait for voltage to be off");
|
---|
222 | dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
|
---|
223 | dim.wait("BIAS_CONTROL", "VoltageOff", 5000);
|
---|
224 | }
|
---|
225 |
|
---|
226 | // Check age of calibration
|
---|
227 | var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
|
---|
228 |
|
---|
229 | var data_calibration = service_calibration.get(3000, false);
|
---|
230 |
|
---|
231 | var age = data_calibration.time;
|
---|
232 | var now = new Date();
|
---|
233 |
|
---|
234 | var diff = (now-age)/3600000;
|
---|
235 |
|
---|
236 | // !data_calibration.data: FEEDBACK might just be freshly
|
---|
237 | // started and will not yet serve this service.
|
---|
238 | if (data_calibration.data==null || (diff>8 && now.getHours()>16))
|
---|
239 | {
|
---|
240 | if (data_calibration.data==null)
|
---|
241 | console.out("No BIAS crate calibration avaliable: New calibration needed.");
|
---|
242 | else
|
---|
243 | console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
|
---|
244 |
|
---|
245 | makeCurrentCalibration();
|
---|
246 | }
|
---|
247 |
|
---|
248 | service_calibration.close();
|
---|
249 |
|
---|
250 | // ================================================================
|
---|
251 | // Crosscheck all states
|
---|
252 | // ================================================================
|
---|
253 |
|
---|
254 | var table =
|
---|
255 | [
|
---|
256 | [ "TNG_WEATHER" ],
|
---|
257 | [ "MAGIC_WEATHER" ],
|
---|
258 | [ "CHAT" ],
|
---|
259 | [ "SMART_FACT" ],
|
---|
260 | [ "TEMPERATURE" ],
|
---|
261 | [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
|
---|
262 | [ "FSC_CONTROL", [ "Connected" ] ],
|
---|
263 | [ "MCP", [ "Idle" ] ],
|
---|
264 | [ "TIME_CHECK", [ "Valid" ] ],
|
---|
265 | [ "PWR_CONTROL", [ "SystemOn" ] ],
|
---|
266 | // [ "AGILENT_CONTROL", [ "VoltageOn" ] ],
|
---|
267 | [ "BIAS_CONTROL", [ "VoltageOn", "VoltageOff" ] ],
|
---|
268 | [ "FEEDBACK", [ "Connected" ] ],
|
---|
269 | [ "RATE_SCAN", [ "Connected" ] ],
|
---|
270 | [ "RATE_CONTROL", [ "Connected" ] ],
|
---|
271 | [ "LID_CONTROL", [ "Open", "Closed" ] ],
|
---|
272 | [ "DRIVE_CONTROL", [ "Armed", "Tracking", "OnTrack" ] ],
|
---|
273 | [ "FTM_CONTROL", [ "Idle", "TriggerOn" ] ],
|
---|
274 | [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
|
---|
275 | ];
|
---|
276 |
|
---|
277 | if (!checkStates(table))
|
---|
278 | {
|
---|
279 | throw new Error("Something unexpected has happened. Although the startup-"+
|
---|
280 | "procedure has finished, not all servers are in the state "+
|
---|
281 | "in which they ought to be. Please, try to find out what "+
|
---|
282 | "happened...");
|
---|
283 | }
|
---|
284 |
|
---|
285 |
|
---|