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

Last change on this file since 17028 was 17028, checked in by tbretz, 11 years ago
Updated to the recent changes in the feedback (still untested)
File size: 9.5 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(handleFadConnected);
92loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
93loop.add(handleRatectrlConnected);
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_ZERO_VOLTAGE");
220 dim.wait("BIAS_CONTROL", "VoltageOff", 15000);
221
222 var now = new Date();
223 dim.send("FEEDBACK/CALIBRATE");
224
225 console.out("Wait for calibration to start");
226 dim.wait("FEEDBACK", "Calibrating", 5000);
227
228 console.out("Wait for calibration to end");
229 dim.wait("FEEDBACK", "Calibrated", 60000);
230
231 console.out("Calibration finished ["+(new Date()-now)+"ms]");
232
233 console.out("Wait for voltage to be off");
234 dim.wait("BIAS_CONTROL", "VoltageOff", 5000);
235}
236
237// Check age of calibration
238var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
239
240var data_calibration = service_calibration.get(3000, false);
241
242var age = data_calibration.time;
243var now = new Date();
244
245var diff = (now-age)/3600000;
246
247// !data_calibration.data: FEEDBACK might just be freshly
248// started and will not yet serve this service.
249if (data_calibration.data==null || (diff>8 && now.getHours()>16))
250{
251 if (data_calibration.data==null)
252 console.out("No BIAS crate calibration avaliable: New calibration needed.");
253 else
254 console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
255
256 makeCurrentCalibration();
257}
258
259service_calibration.close();
260
261// ================================================================
262
263dim.send("BIAS_CONTROL/SET_EXPERT_MODE", true);
264dim.send("BIAS_CONTROL/EXPERT_LOAD_MAP_FILE", "/home/fact/operation/GAPDmap_with_spare_module-new.txt");
265dim.send("BIAS_CONTROL/SET_EXPERT_MODE", false);
266dim.send("FEEDBACK/ENABLE_OLD_ALGORITHM", false);
267
268// ================================================================
269// Crosscheck all states
270// ================================================================
271
272var table =
273[
274 [ "TNG_WEATHER" ],
275 [ "MAGIC_WEATHER" ],
276 [ "CHAT" ],
277 [ "SMART_FACT" ],
278 [ "TEMPERATURE" ],
279 [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
280 [ "FSC_CONTROL", [ "Connected" ] ],
281 [ "MCP", [ "Idle" ] ],
282 [ "TIME_CHECK", [ "Valid" ] ],
283 [ "PWR_CONTROL", [ "SystemOn" ] ],
284 [ "AGILENT_CONTROL", [ "VoltageOn" ] ],
285 [ "BIAS_CONTROL", [ "VoltageOn", "VoltageOff" ] ],
286 [ "FEEDBACK", [ "Calibrated" ] ],
287 [ "RATE_SCAN", [ "Connected" ] ],
288 [ "RATE_CONTROL", [ "Connected" ] ],
289 [ "LID_CONTROL", [ "Open", "Closed" ] ],
290 [ "DRIVE_CONTROL", [ "Armed", "Tracking", "OnTrack", "Locked" ] ],
291 [ "FTM_CONTROL", [ "Valid", "TriggerOn" ] ],
292 [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
293];
294
295if (!checkStates(table))
296{
297 throw new Error("Something unexpected has happened. Although the startup-"+
298 "procedure has finished, not all servers are in the state "+
299 "in which they ought to be. Please, try to find out what "+
300 "happened...");
301}
Note: See TracBrowser for help on using the repository browser.