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

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