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

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