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