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

Last change on this file since 16857 was 16790, checked in by tbretz, 11 years ago
Added a chck for the clock conditioner; ftmctrl should now be in Valid not anymore in Idle.
File size: 9.2 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/handleAgilentPowerOn.js");
57include("scripts/handlePwrCameraOn.js");
58
59checkSend(["AGILENT_CONTROL","PWR_CONTROL"]);
60
61loop = new Handler("PowerOn");
62//loop.add(handleAgilentPowerOn);
63loop.add(handlePwrCameraOn);
64loop.run();
65console.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
75include("scripts/handleBiasVoltageOff.js");
76include("scripts/handleFtmIdle.js");
77include("scripts/handleFscConnected.js");
78include("scripts/handleFeedbackConnected.js");
79include("scripts/handleRatectrlConnected.js");
80include("scripts/handleLidClosed.js");
81include("scripts/handleFadConnected.js");
82
83checkSend(["BIAS_CONTROL","FAD_CONTROL","FTM_CONTROL", "FSC_CONTROL", "FEEDBACK", "RATE_CONTROL", "MCP"]);
84
85dim.send("MCP/RESET");
86
87loop = new Handler("SystemSetup");
88loop.add(handleBiasVoltageOff);
89loop.add(handleFtmIdle);
90loop.add(handleFscConnected);
91loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
92loop.add(handleRatectrlConnected);
93loop.add(handleFadConnected);
94//loop.add(handleLidClosed);
95loop.run();
96
97console.out("biasctrl: "+dim.state("BIAS_CONTROL").name);
98console.out("ftmctrl: "+dim.state("FTM_CONTROL").name);
99console.out("fscctrl: "+dim.state("FSC_CONTROL").name);
100console.out("feedback: "+dim.state("FEEDBACK").name);
101console.out("ratecontrol: "+dim.state("RATE_CONTROL").name);
102console.out("fadctrl: "+dim.state("FAD_CONTROL").name);
103console.out("mcp: "+dim.state("MCP").name);
104console.out("");
105
106console.out("Enable all FTU");
107dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
108
109// -----------------------------------------------------------------
110// Now we check the FTU connection
111// -----------------------------------------------------------------
112
113/*
114include("scripts/handleFtuCheck.js");
115
116loop = new Handler("FtuCheck");
117loop.ftuList = new Subscription("FTM_CONTROL/FTU_LIST");
118loop.add(handleFtuCheck);
119loop.run();
120loop.ftuList.close();
121
122dim.log("All FTUs are enabled and without error.");
123*/
124
125console.out("Checking FTU: start");
126include("scripts/CheckFTU.js");
127console.out("Checking FTU: done");
128console.out("");
129
130// -----------------------------------------------------------------
131// Now we check the clock conditioner
132// -----------------------------------------------------------------
133
134var sub_counter = new Subscription("FTM_CONTROL/COUNTER");
135var counter = sub_counter.get(3000, false).counter;
136dim.send("FTM_CONTROL/REQUEST_STATIC_DATA");
137v8.timeout(3000, function() { if (sub_counter.get(0, false).counter>counter) return true; });
138if (sub_counter.get(0, false).qos&0x100==0)
139 throw new Error("Clock conditioner not locked.");
140sub_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
150checkSend(["FAD_CONTROL"]);
151
152loop = new Handler("ConnectFad");
153loop.add(handleFadConnected);
154loop.run();
155
156var failed = false;
157dim.onchange["FAD_CONTROL"] = function(arg)
158{
159 if (this.rc && arg.name!="Connected")
160 failed = true;
161}
162
163console.out("FADs connected.");
164console.out("");
165
166console.out(dim.state("FAD_CONTROL").name);
167console.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
177include('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
190if ((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
197include("scripts/handleDriveArmed.js");
198
199checkSend(["DRIVE_CONTROL"]);
200
201loop = new Handler("ArmDrive");
202loop.add(handleDriveArmed);
203loop.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
217function makeCurrentCalibration()
218{
219 dim.send("BIAS_CONTROL/SET_GLOBAL_DAC", 1);
220 dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
221
222 var now = new Date();
223 dim.send("FEEDBACK/CALIBRATE_CURRENTS");
224
225 // FIXME: Timeout!
226 console.out("Wait for calibration to start");
227 dim.wait("FEEDBACK", "Calibrating", 5000);
228
229 console.out("Wait for calibration to end");
230 dim.wait("FEEDBACK", "Connected", 60000);
231
232 console.out("Calibration finished ["+(new Date()-now)+"ms]");
233
234 console.out("Wait for voltage to be off");
235 dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
236 dim.wait("BIAS_CONTROL", "VoltageOff", 5000);
237}
238
239// Check age of calibration
240var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
241
242var data_calibration = service_calibration.get(3000, false);
243
244var age = data_calibration.time;
245var now = new Date();
246
247var diff = (now-age)/3600000;
248
249// !data_calibration.data: FEEDBACK might just be freshly
250// started and will not yet serve this service.
251if (data_calibration.data==null || (diff>8 && now.getHours()>16))
252{
253 if (data_calibration.data==null)
254 console.out("No BIAS crate calibration avaliable: New calibration needed.");
255 else
256 console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
257
258 makeCurrentCalibration();
259}
260
261service_calibration.close();
262
263// ================================================================
264// Crosscheck all states
265// ================================================================
266
267var table =
268[
269 [ "TNG_WEATHER" ],
270 [ "MAGIC_WEATHER" ],
271 [ "CHAT" ],
272 [ "SMART_FACT" ],
273 [ "TEMPERATURE" ],
274 [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
275 [ "FSC_CONTROL", [ "Connected" ] ],
276 [ "MCP", [ "Idle" ] ],
277 [ "TIME_CHECK", [ "Valid" ] ],
278 [ "PWR_CONTROL", [ "SystemOn" ] ],
279 [ "AGILENT_CONTROL", [ "VoltageOn" ] ],
280 [ "BIAS_CONTROL", [ "VoltageOn", "VoltageOff" ] ],
281 [ "FEEDBACK", [ "Connected" ] ],
282 [ "RATE_SCAN", [ "Connected" ] ],
283 [ "RATE_CONTROL", [ "Connected" ] ],
284 [ "LID_CONTROL", [ "Open", "Closed" ] ],
285 [ "DRIVE_CONTROL", [ "Armed", "Tracking", "OnTrack", "Locked" ] ],
286 [ "FTM_CONTROL", [ "Valid", "TriggerOn" ] ],
287 [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
288];
289
290if (!checkStates(table))
291{
292 throw new Error("Something unexpected has happened. Although the startup-"+
293 "procedure has finished, not all servers are in the state "+
294 "in which they ought to be. Please, try to find out what "+
295 "happened...");
296}
Note: See TracBrowser for help on using the repository browser.