source: trunk/FACT++/scripts/Startup.js@ 20084

Last change on this file since 20084 was 19930, checked in by tbretz, 5 years ago
Added GUDE_CONTROL as a requirement.
File size: 11.0 KB
Line 
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/*
12var 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
34if (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
45console.out("");
46dim.alarm();
47
48var loop;
49include("scripts/Handler.js");
50include("scripts/CheckStates.js");
51
52// -----------------------------------------------------------------
53// Make sure camera electronics is switched on and has power
54// -----------------------------------------------------------------
55
56include("scripts/handleAgilentPowerOn24V.js");
57include("scripts/handleAgilentPowerOn50V.js");
58include("scripts/handleAgilentPowerOn80V.js");
59include("scripts/handlePwrCameraOn.js");
60
61checkSend(["AGILENT_CONTROL_24V","AGILENT_CONTROL_50V","AGILENT_CONTROL_80V","PWR_CONTROL"]);
62
63loop = new Handler("PowerOn");
64//loop.add(handleAgilentPowerOn24V);
65//loop.add(handleAgilentPowerOn50V);
66//loop.add(handleAgilentPowerOn80V);
67loop.add(handlePwrCameraOn);
68loop.run(30000);
69console.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
79include("scripts/handleBiasVoltageOff.js");
80include("scripts/handleFtmIdle.js");
81include("scripts/handleFscConnected.js");
82include("scripts/handleFeedbackConnected.js");
83include("scripts/handleRatectrlConnected.js");
84include("scripts/handleLidClosed.js");
85include("scripts/handleFadConnected.js");
86include("scripts/handleScheduler.js");
87
88checkSend(["BIAS_CONTROL","FAD_CONTROL","FTM_CONTROL", "FSC_CONTROL", "FEEDBACK", "RATE_CONTROL", "MCP", "SCHEDULER"]);
89
90dim.send("MCP/RESET");
91
92loop = new Handler("SystemSetup");
93loop.add(handleBiasVoltageOff);
94loop.add(handleFtmIdle);
95loop.add(handleFscConnected);
96loop.add(handleFadConnected);
97loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
98loop.add(handleRatectrlConnected);
99loop.add(handleLidClosed);
100loop.add(handleScheduler);
101loop.run(60000);
102
103console.out("biasctrl: "+dim.state("BIAS_CONTROL").name);
104console.out("ftmctrl: "+dim.state("FTM_CONTROL").name);
105console.out("fscctrl: "+dim.state("FSC_CONTROL").name);
106console.out("feedback: "+dim.state("FEEDBACK").name);
107console.out("ratecontrol: "+dim.state("RATE_CONTROL").name);
108console.out("fadctrl: "+dim.state("FAD_CONTROL").name);
109console.out("mcp: "+dim.state("MCP").name);
110console.out("scheduler: "+dim.state("SCHEDULER").name);
111console.out("");
112
113console.out("Enable all FTU");
114dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
115
116// -----------------------------------------------------------------
117// Now we check the FTU connection
118// -----------------------------------------------------------------
119
120/*
121include("scripts/handleFtuCheck.js");
122
123loop = new Handler("FtuCheck");
124loop.ftuList = new Subscription("FTM_CONTROL/FTU_LIST");
125loop.add(handleFtuCheck);
126loop.run();
127loop.ftuList.close();
128
129dim.log("All FTUs are enabled and without error.");
130*/
131
132console.out("Checking FTU: start");
133include("scripts/CheckFTU.js");
134console.out("Checking FTU: done");
135console.out("");
136
137// -----------------------------------------------------------------
138// Now we check the clock conditioner
139// -----------------------------------------------------------------
140
141var sub_counter = new Subscription("FTM_CONTROL/COUNTER");
142var counter = sub_counter.get(3000, false).counter;
143dim.send("FTM_CONTROL/REQUEST_STATIC_DATA");
144v8.timeout(3000, function() { if (sub_counter.get(0, false).counter>counter) return true; });
145if (sub_counter.get(0, false).qos&0x100==0)
146 throw new Error("Clock conditioner not locked.");
147sub_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
157checkSend(["FAD_CONTROL"]);
158
159loop = new Handler("ConnectFad");
160loop.add(handleFadConnected);
161loop.run();
162
163var failed = false;
164dim.onchange["FAD_CONTROL"] = function(arg)
165{
166 if (this.rc && arg.name!="Connected")
167 failed = true;
168}
169
170console.out("FADs connected.");
171console.out("");
172
173console.out(dim.state("FAD_CONTROL").name);
174console.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
184include('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
197if ((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
204include("scripts/handleDriveArmed.js");
205
206checkSend(["DRIVE_CONTROL"]);
207
208loop = new Handler("ArmDrive");
209loop.add(handleDriveArmed);
210loop.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
224function 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
245var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
246
247var data_calibration = service_calibration.get(3000, false);
248
249var age = data_calibration.time;
250var now = new Date();
251
252var diff = (now-age)/3600000;
253
254var 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.
258if (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
268service_calibration.close();
269
270// ================================================================
271// Setup GPS control and wait for the satellites to be locked
272// ================================================================
273
274checkSend(["GPS_CONTROL"]);
275
276if (dim.state("GPS_CONTROL").name=="Disconnected")
277 dim.send("GPS_CONTROL/RECONNECT");
278
279// Wait for being connectes
280v8.timeout(5000, function() { if (dim.state("GPS_CONTROL").name!="Disconnected") return true; });
281
282// Wait for status available
283v8.timeout(5000, function() { if (dim.state("GPS_CONTROL").name!="Connected") return true; });
284
285if (dim.state("GPS_CONTROL").name=="Disabled")
286 dim.send("GPS_CONTROL/ENABLE");
287
288// Wait for gps to be enabled and locked
289dim.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
298var table =
299[
300 [ "GTC_DUST" ],
301 [ "TNG_WEATHER" ],
302 [ "MAGIC_WEATHER" ],
303 [ "RAIN_SENSOR" ],
304 [ "CHAT" ],
305 [ "SMART_FACT" ],
306 [ "TEMPERATURE" ],
307 [ "SCHEDULER", [ "Connected", "Armed" ] ],
308 [ "EVENT_SERVER", [ "Running", "Standby" ] ],
309 [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
310 [ "FSC_CONTROL", [ "Connected" ] ],
311 [ "MCP", [ "Idle" ] ],
312 [ "TIME_CHECK", [ "Valid" ] ],
313 [ "PWR_CONTROL", [ "SystemOn" ] ],
314 [ "AGILENT_CONTROL_24V", [ "VoltageOn" ] ],
315 [ "AGILENT_CONTROL_50V", [ "VoltageOn" ] ],
316 [ "AGILENT_CONTROL_80V", [ "VoltageOn", "Disconnected" ] ], //hack to allow for data taking while agilent not available
317 [ "BIAS_CONTROL", [ "VoltageOff" ] ],
318 [ "FEEDBACK", [ "Calibrated" ] ],
319 [ "RATE_SCAN", [ "Connected" ] ],
320 [ "RATE_CONTROL", [ "Connected" ] ],
321 [ "DRIVE_CONTROL", [ "Initialized", "Tracking", "OnTrack", "Locked" ] ],
322 [ "LID_CONTROL", [ "Open", "Closed" ] ],
323 [ "FTM_CONTROL", [ "Valid", "TriggerOn" ] ],
324 [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
325 [ "GPS_CONTROL", [ "Locked" ] ],
326// [ "SQM_CONTROL", [ "Valid" ] ],
327 [ "PFMINI_CONTROL", [ "Receiving" ] ],
328 [ "BIAS_TEMP", [ "Valid" ] ],
329 [ "GUDE_CONTROL", [ "Valid" ] ],
330];
331
332
333
334if (!checkStates(table))
335{
336 throw new Error("Something unexpected has happened. Although the startup-"+
337 "procedure has finished, not all servers are in the state "+
338 "in which they ought to be. Please, try to find out what "+
339 "happened...");
340}
Note: See TracBrowser for help on using the repository browser.