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

Last change on this file since 15353 was 15353, checked in by tbretz, 12 years ago
Added TEMPERATURE to the required servers, removed AGILENT_CONTROL temporarily
File size: 8.6 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 can safely try to connect the FAD boards.
132// -----------------------------------------------------------------
133/*
134 include("scripts/handleFadConnected.js");
135
136// If FADs already connected
137
138checkSend(["FAD_CONTROL"]);
139
140loop = new Handler("ConnectFad");
141loop.add(handleFadConnected);
142loop.run();
143
144var failed = false;
145dim.onchange["FAD_CONTROL"] = function(arg)
146{
147 if (this.rc && arg.name!="Connected")
148 failed = true;
149}
150
151console.out("FADs connected.");
152console.out("");
153
154console.out(dim.state("FAD_CONTROL").name);
155console.out(dim.state("MCP").name);
156*/
157
158// ================================================================
159// Underflow check
160// ================================================================
161// Is it necessary to check for the so called 'underflow-problem'?
162// (This is necessary after each power cycle)
163// ----------------------------------------------------------------
164
165include('scripts/CheckUnderflow.js');
166
167// Now it is time to check the connection of the FADs
168// it might hav thrown an exception already anyway
169
170
171// ================================================================
172// Power on drive system if power is off (do it hre to make sure not
173// everything is switchd on at the same time)
174// ================================================================
175
176//console.out("PWR: "+(dim.state("PWR_CONTROL").index&16));
177
178if ((dim.state("PWR_CONTROL").index&16)==0)
179{
180 console.out("Drive on");
181 dim.send("PWR_CONTROL/TOGGLE_DRIVE");
182}
183
184include("scripts/handleDriveArmed.js");
185
186checkSend(["DRIVE_CONTROL"]);
187
188loop = new Handler("ArmDrive");
189loop.add(handleDriveArmed);
190loop.run();
191
192
193// ================================================================
194// Bias crate calibration
195// ================================================================
196// Bias crate calibration if necessary (it is aftr 4pm (local tome)
197// and the last calibration was more than eight hours ago.
198// -----------------------------------------------------------------
199
200// At this point we know that:
201// 1) The lid is closed
202// 2) The feedback is stopped
203// 3) The voltage is off
204function makeCurrentCalibration()
205{
206 dim.send("BIAS_CONTROL/SET_GLOBAL_DAC", 1);
207 dim.wait("BIAS_CONTROL", "VoltageOn", 3000);
208
209 var now = new Date();
210 dim.send("FEEDBACK/CALIBRATE_CURRENTS");
211
212 // FIXME: Timeout!
213 console.out("Wait for calibration to start");
214 dim.wait("FEEDBACK", "Calibrating", 5000);
215
216 console.out("Wait for calibration to end");
217 dim.wait("FEEDBACK", "Connected", 60000);
218
219 console.out("Calibration took "+(new Date()-now)+"ms");
220
221 console.out("Wait for voltage to be off");
222 dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
223 dim.wait("BIAS_CONTROL", "VoltageOff", 5000);
224}
225
226// Check age of calibration
227var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
228
229var data_calibration = service_calibration.get(3000, false);
230
231var age = data_calibration.time;
232var now = new Date();
233
234var diff = (now-age)/3600000;
235
236// !data_calibration.data: FEEDBACK might just be freshly
237// started and will not yet serve this service.
238if (data_calibration.data==null || (diff>8 && now.getHours()>16))
239{
240 if (data_calibration.data==null)
241 console.out("No BIAS crate calibration avaliable: New calibration needed.");
242 else
243 console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
244
245 makeCurrentCalibration();
246}
247
248service_calibration.close();
249
250// ================================================================
251// Crosscheck all states
252// ================================================================
253
254var table =
255[
256 [ "TNG_WEATHER" ],
257 [ "MAGIC_WEATHER" ],
258 [ "CHAT" ],
259 [ "SMART_FACT" ],
260 [ "TEMPERATURE" ],
261 [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
262 [ "FSC_CONTROL", [ "Connected" ] ],
263 [ "MCP", [ "Idle" ] ],
264 [ "TIME_CHECK", [ "Valid" ] ],
265 [ "PWR_CONTROL", [ "SystemOn" ] ],
266// [ "AGILENT_CONTROL", [ "VoltageOn" ] ],
267 [ "BIAS_CONTROL", [ "VoltageOn", "VoltageOff" ] ],
268 [ "FEEDBACK", [ "Connected" ] ],
269 [ "RATE_SCAN", [ "Connected" ] ],
270 [ "RATE_CONTROL", [ "Connected" ] ],
271 [ "LID_CONTROL", [ "Open", "Closed" ] ],
272 [ "DRIVE_CONTROL", [ "Armed", "Tracking", "OnTrack" ] ],
273 [ "FTM_CONTROL", [ "Idle", "TriggerOn" ] ],
274 [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
275];
276
277if (!checkStates(table))
278{
279 throw new Error("Something unexpected has happened. Although the startup-"+
280 "procedure has finished, not all servers are in the state "+
281 "in which they ought to be. Please, try to find out what "+
282 "happened...");
283}
284
285
Note: See TracBrowser for help on using the repository browser.