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

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