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