| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | include("scripts/CheckFTU.js");
|
|---|
| 4 | include("scripts/CheckUnderflow.js");
|
|---|
| 5 | // To de done:
|
|---|
| 6 | // - CheckLID status (should be open or closed)
|
|---|
| 7 | // - Is it necessary to switch the bias-voltage off?
|
|---|
| 8 | // - Get reasonable timeouts for all steps (wait, get, run)
|
|---|
| 9 | // - Improve order to accelerate execution
|
|---|
| 10 | //
|
|---|
| 11 | // =================================================================
|
|---|
| 12 |
|
|---|
| 13 | /*
|
|---|
| 14 | var table =
|
|---|
| 15 | [
|
|---|
| 16 | [ "AGILENT_CONTROL" ],
|
|---|
| 17 | [ "BIAS_CONTROL" ],
|
|---|
| 18 | [ "CHAT" ],
|
|---|
| 19 | [ "DATA_LOGGER" ],
|
|---|
| 20 | [ "DRIVE_CONTROL" ],
|
|---|
| 21 | [ "FEEDBACK" ],
|
|---|
| 22 | [ "FAD_CONTROL" ],
|
|---|
| 23 | [ "FSC_CONTROL" ],
|
|---|
| 24 | [ "FTM_CONTROL" ],
|
|---|
| 25 | [ "LID_CONTROL" ],
|
|---|
| 26 | [ "MAGIC_WEATHER" ],
|
|---|
| 27 | [ "MCP" ],
|
|---|
| 28 | [ "PWR_CONTROL" ],
|
|---|
| 29 | [ "RATE_CONTROL" ],
|
|---|
| 30 | [ "RATE_SCAN" ],
|
|---|
| 31 | [ "SMART_FACT" ],
|
|---|
| 32 | [ "TIME_CHECK" ],
|
|---|
| 33 | [ "TNG_WEATHER" ],
|
|---|
| 34 | ];
|
|---|
| 35 |
|
|---|
| 36 | if (dim.state("DRIVE_CONTROL").name=="Locked")
|
|---|
| 37 | {
|
|---|
| 38 | throw new Error("Drivectrl still locked... needs UNLOCK first.");
|
|---|
| 39 | //while (!dim.send("DRIVE_CONTROL"))
|
|---|
| 40 | // v8.sleep();
|
|---|
| 41 | //dim.send("DRIVE_CONTROL/UNLOCK");
|
|---|
| 42 | //dim.wait("DRIVE_CONTROL", "Armed", 1000);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | */
|
|---|
| 46 |
|
|---|
| 47 | console.out("");
|
|---|
| 48 | dim.alarm();
|
|---|
| 49 |
|
|---|
| 50 | var loop;
|
|---|
| 51 | include("scripts/Handler.js");
|
|---|
| 52 | include("scripts/CheckStates.js");
|
|---|
| 53 |
|
|---|
| 54 | // -----------------------------------------------------------------
|
|---|
| 55 | // Make sure camera electronics is switched on and has power
|
|---|
| 56 | // -----------------------------------------------------------------
|
|---|
| 57 |
|
|---|
| 58 | include("scripts/handleAgilentPowerOn24V.js");
|
|---|
| 59 | include("scripts/handleAgilentPowerOn50V.js");
|
|---|
| 60 | include("scripts/handleAgilentPowerOn80V.js");
|
|---|
| 61 | include("scripts/handlePwrCameraOn.js");
|
|---|
| 62 |
|
|---|
| 63 | checkSend(["AGILENT_CONTROL_24V","AGILENT_CONTROL_50V","AGILENT_CONTROL_80V","PWR_CONTROL"]);
|
|---|
| 64 |
|
|---|
| 65 | loop = new Handler("PowerOn");
|
|---|
| 66 | //loop.add(handleAgilentPowerOn24V);
|
|---|
| 67 | //loop.add(handleAgilentPowerOn50V);
|
|---|
| 68 | //loop.add(handleAgilentPowerOn80V);
|
|---|
| 69 | loop.add(handlePwrCameraOn);
|
|---|
| 70 | loop.run();
|
|---|
| 71 | console.out("");
|
|---|
| 72 |
|
|---|
| 73 | // If power was switched on: wait for a few seconds
|
|---|
| 74 |
|
|---|
| 75 | // -----------------------------------------------------------------
|
|---|
| 76 | // Now take care that the bias control, the ftm and the fsc are
|
|---|
| 77 | // properly connected and are in a reasonable state (e.g. the
|
|---|
| 78 | // trigger is switched off)
|
|---|
| 79 | // -----------------------------------------------------------------
|
|---|
| 80 |
|
|---|
| 81 | include("scripts/handleBiasVoltageOff.js");
|
|---|
| 82 | include("scripts/handleFtmIdle.js");
|
|---|
| 83 | include("scripts/handleFscConnected.js");
|
|---|
| 84 | include("scripts/handleFeedbackConnected.js");
|
|---|
| 85 | include("scripts/handleRatectrlConnected.js");
|
|---|
| 86 | include("scripts/handleLidClosed.js");
|
|---|
| 87 | include("scripts/handleFadConnected.js");
|
|---|
| 88 |
|
|---|
| 89 | checkSend(["BIAS_CONTROL","FAD_CONTROL","FTM_CONTROL", "FSC_CONTROL", "FEEDBACK", "RATE_CONTROL", "MCP"]);
|
|---|
| 90 |
|
|---|
| 91 | dim.send("MCP/RESET");
|
|---|
| 92 |
|
|---|
| 93 | loop = new Handler("SystemSetup");
|
|---|
| 94 | loop.add(handleBiasVoltageOff);
|
|---|
| 95 | loop.add(handleFtmIdle);
|
|---|
| 96 | loop.add(handleFscConnected);
|
|---|
| 97 | loop.add(handleFadConnected);
|
|---|
| 98 | loop.add(handleFeedbackConnected); // Feedback needs FAD to be Connected
|
|---|
| 99 | loop.add(handleRatectrlConnected);
|
|---|
| 100 | loop.add(handleLidClosed);
|
|---|
| 101 | loop.run();
|
|---|
| 102 |
|
|---|
| 103 | console.out("biasctrl: "+dim.state("BIAS_CONTROL").name);
|
|---|
| 104 | console.out("ftmctrl: "+dim.state("FTM_CONTROL").name);
|
|---|
| 105 | console.out("fscctrl: "+dim.state("FSC_CONTROL").name);
|
|---|
| 106 | console.out("feedback: "+dim.state("FEEDBACK").name);
|
|---|
| 107 | console.out("ratecontrol: "+dim.state("RATE_CONTROL").name);
|
|---|
| 108 | console.out("fadctrl: "+dim.state("FAD_CONTROL").name);
|
|---|
| 109 | console.out("mcp: "+dim.state("MCP").name);
|
|---|
| 110 | console.out("");
|
|---|
| 111 |
|
|---|
| 112 | console.out("Enable all FTU");
|
|---|
| 113 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
|
|---|
| 114 |
|
|---|
| 115 | // -----------------------------------------------------------------
|
|---|
| 116 | // Now we check the FTU connection
|
|---|
| 117 | // -----------------------------------------------------------------
|
|---|
| 118 | CheckFTU.checkFTU();
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 | // -----------------------------------------------------------------
|
|---|
| 122 | // Now we check the clock conditioner
|
|---|
| 123 | // -----------------------------------------------------------------
|
|---|
| 124 |
|
|---|
| 125 | var sub_counter = new Subscription("FTM_CONTROL/COUNTER");
|
|---|
| 126 | var counter = sub_counter.get(3000, false).counter;
|
|---|
| 127 | dim.send("FTM_CONTROL/REQUEST_STATIC_DATA");
|
|---|
| 128 | v8.timeout(3000, function() { if (sub_counter.get(0, false).counter>counter) return true; });
|
|---|
| 129 | if (sub_counter.get(0, false).qos&0x100==0)
|
|---|
| 130 | throw new Error("Clock conditioner not locked.");
|
|---|
| 131 | sub_counter.close();
|
|---|
| 132 |
|
|---|
| 133 | // -----------------------------------------------------------------
|
|---|
| 134 | // Now we can safely try to connect the FAD boards.
|
|---|
| 135 | // -----------------------------------------------------------------
|
|---|
| 136 | /*
|
|---|
| 137 | include("scripts/handleFadConnected.js");
|
|---|
| 138 |
|
|---|
| 139 | // If FADs already connected
|
|---|
| 140 |
|
|---|
| 141 | checkSend(["FAD_CONTROL"]);
|
|---|
| 142 |
|
|---|
| 143 | loop = new Handler("ConnectFad");
|
|---|
| 144 | loop.add(handleFadConnected);
|
|---|
| 145 | loop.run();
|
|---|
| 146 |
|
|---|
| 147 | var failed = false;
|
|---|
| 148 | dim.onchange["FAD_CONTROL"] = function(arg)
|
|---|
| 149 | {
|
|---|
| 150 | if (this.rc && arg.name!="Connected")
|
|---|
| 151 | failed = true;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | console.out("FADs connected.");
|
|---|
| 155 | console.out("");
|
|---|
| 156 |
|
|---|
| 157 | console.out(dim.state("FAD_CONTROL").name);
|
|---|
| 158 | console.out(dim.state("MCP").name);
|
|---|
| 159 | */
|
|---|
| 160 |
|
|---|
| 161 | // ================================================================
|
|---|
| 162 | // Underflow check
|
|---|
| 163 | // ================================================================
|
|---|
| 164 | // Is it necessary to check for the so called 'underflow-problem'?
|
|---|
| 165 | // (This is necessary after each power cycle)
|
|---|
| 166 | // ----------------------------------------------------------------
|
|---|
| 167 | CheckUnderflow.checkUnderflow();
|
|---|
| 168 |
|
|---|
| 169 | // Now it is time to check the connection of the FADs
|
|---|
| 170 | // it might hav thrown an exception already anyway
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 | // ================================================================
|
|---|
| 174 | // Power on drive system if power is off (do it hre to make sure not
|
|---|
| 175 | // everything is switchd on at the same time)
|
|---|
| 176 | // ================================================================
|
|---|
| 177 |
|
|---|
| 178 | //console.out("PWR: "+(dim.state("PWR_CONTROL").index&16));
|
|---|
| 179 |
|
|---|
| 180 | if ((dim.state("PWR_CONTROL").index&16)==0)
|
|---|
| 181 | {
|
|---|
| 182 | console.out("Drive cabinet not powered... Switching on.");
|
|---|
| 183 | dim.send("PWR_CONTROL/TOGGLE_DRIVE");
|
|---|
| 184 | v8.timeout(5000, function() { if (dim.state("PWR_CONTROL").index&16) return true; });
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | include("scripts/handleDriveArmed.js");
|
|---|
| 188 |
|
|---|
| 189 | checkSend(["DRIVE_CONTROL"]);
|
|---|
| 190 |
|
|---|
| 191 | loop = new Handler("ArmDrive");
|
|---|
| 192 | loop.add(handleDriveArmed);
|
|---|
| 193 | loop.run();
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | // ================================================================
|
|---|
| 197 | // Bias crate calibration
|
|---|
| 198 | // ================================================================
|
|---|
| 199 | // Bias crate calibration if necessary (it is aftr 4pm (local tome)
|
|---|
| 200 | // and the last calibration was more than eight hours ago.
|
|---|
| 201 | // -----------------------------------------------------------------
|
|---|
| 202 |
|
|---|
| 203 | // At this point we know that:
|
|---|
| 204 | // 1) The lid is closed
|
|---|
| 205 | // 2) The feedback is stopped
|
|---|
| 206 | // 3) The voltage is off
|
|---|
| 207 | function makeCurrentCalibration()
|
|---|
| 208 | {
|
|---|
| 209 | dim.send("BIAS_CONTROL/SET_ZERO_VOLTAGE");
|
|---|
| 210 | dim.wait("BIAS_CONTROL", "VoltageOff", 30000); // waS: 15000
|
|---|
| 211 |
|
|---|
| 212 | var now = new Date();
|
|---|
| 213 | dim.send("FEEDBACK/CALIBRATE");
|
|---|
| 214 |
|
|---|
| 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", "Calibrated", 90000);
|
|---|
| 220 |
|
|---|
| 221 | console.out("Calibration finished ["+(new Date()-now)+"ms]");
|
|---|
| 222 |
|
|---|
| 223 | console.out("Wait for voltage to be off");
|
|---|
| 224 | dim.wait("BIAS_CONTROL", "VoltageOff", 30000); // was: 15000
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | // Check age of calibration
|
|---|
| 228 | var service_calibration = new Subscription("FEEDBACK/CALIBRATION");
|
|---|
| 229 |
|
|---|
| 230 | var data_calibration = service_calibration.get(3000, false);
|
|---|
| 231 |
|
|---|
| 232 | var age = data_calibration.time;
|
|---|
| 233 | var now = new Date();
|
|---|
| 234 |
|
|---|
| 235 | var diff = (now-age)/3600000;
|
|---|
| 236 |
|
|---|
| 237 | var fb_state = dim.state("FEEDBACK").index;
|
|---|
| 238 |
|
|---|
| 239 | // !data_calibration.data: FEEDBACK might just be freshly
|
|---|
| 240 | // started and will not yet serve this service.
|
|---|
| 241 | if (fb_state<5 || (diff>8 && now.getHours()>16))
|
|---|
| 242 | {
|
|---|
| 243 | if (fb_state<5)
|
|---|
| 244 | console.out("No BIAS crate calibration available: New calibration needed.");
|
|---|
| 245 | else
|
|---|
| 246 | console.out("Last BIAS crate calibration taken at "+age.toUTCString()+": New calibration needed.");
|
|---|
| 247 |
|
|---|
| 248 | makeCurrentCalibration();
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | service_calibration.close();
|
|---|
| 252 |
|
|---|
| 253 | // ================================================================
|
|---|
| 254 | // Setup GPS control and wait for the satellites to be locked
|
|---|
| 255 | // ================================================================
|
|---|
| 256 |
|
|---|
| 257 | checkSend(["GPS_CONTROL"]);
|
|---|
| 258 |
|
|---|
| 259 | if (dim.state("GPS_CONTROL").name=="Disconnected")
|
|---|
| 260 | dim.send("GPS_CONTROL/RECONNECT");
|
|---|
| 261 |
|
|---|
| 262 | // Wait for being connectes
|
|---|
| 263 | v8.timeout(5000, function() { if (dim.state("GPS_CONTROL").name!="Disconnected") return true; });
|
|---|
| 264 |
|
|---|
| 265 | // Wait for status available
|
|---|
| 266 | v8.timeout(5000, function() { if (dim.state("GPS_CONTROL").name!="Connected") return true; });
|
|---|
| 267 |
|
|---|
| 268 | if (dim.state("GPS_CONTROL").name=="Disabled")
|
|---|
| 269 | dim.send("GPS_CONTROL/ENABLE");
|
|---|
| 270 |
|
|---|
| 271 | // Wait for gps to be enabled and locked
|
|---|
| 272 | dim.wait("GPS_CONTROL", "Locked", 15000);
|
|---|
| 273 |
|
|---|
| 274 | // ================================================================
|
|---|
| 275 | // Crosscheck all states
|
|---|
| 276 | // ================================================================
|
|---|
| 277 |
|
|---|
| 278 | // FIXME: Check if there is a startup scheduled, if not do not force
|
|---|
| 279 | // drive to be switched on
|
|---|
| 280 |
|
|---|
| 281 | var table =
|
|---|
| 282 | [
|
|---|
| 283 | [ "TNG_WEATHER" ],
|
|---|
| 284 | [ "MAGIC_WEATHER" ],
|
|---|
| 285 | [ "CHAT" ],
|
|---|
| 286 | [ "SMART_FACT" ],
|
|---|
| 287 | [ "TEMPERATURE" ],
|
|---|
| 288 | [ "EVENT_SERVER", [ "Running", "Standby" ] ],
|
|---|
| 289 | [ "DATA_LOGGER", [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
|
|---|
| 290 | [ "FSC_CONTROL", [ "Connected" ] ],
|
|---|
| 291 | [ "MCP", [ "Idle" ] ],
|
|---|
| 292 | [ "TIME_CHECK", [ "Valid" ] ],
|
|---|
| 293 | [ "PWR_CONTROL", [ "SystemOn" ] ],
|
|---|
| 294 | [ "AGILENT_CONTROL_24V", [ "VoltageOn" ] ],
|
|---|
| 295 | [ "AGILENT_CONTROL_50V", [ "VoltageOn" ] ],
|
|---|
| 296 | [ "AGILENT_CONTROL_80V", [ "VoltageOn" ] ],
|
|---|
| 297 | [ "BIAS_CONTROL", [ "VoltageOff" ] ],
|
|---|
| 298 | [ "FEEDBACK", [ "Calibrated" ] ],
|
|---|
| 299 | [ "RATE_SCAN", [ "Connected" ] ],
|
|---|
| 300 | [ "RATE_CONTROL", [ "Connected" ] ],
|
|---|
| 301 | [ "DRIVE_CONTROL", [ "Armed", "Tracking", "OnTrack", "Locked" ] ],
|
|---|
| 302 | [ "LID_CONTROL", [ "Open", "Closed" ] ],
|
|---|
| 303 | [ "FTM_CONTROL", [ "Valid", "TriggerOn" ] ],
|
|---|
| 304 | [ "FAD_CONTROL", [ "Connected", "WritingData" ] ],
|
|---|
| 305 | [ "GPS_CONTROL", [ "Locked" ] ],
|
|---|
| 306 | [ "SQM_CONTROL", [ "Valid" ] ],
|
|---|
| 307 | [ "PFMINI_CONTROL", [ "Receiving" ] ],
|
|---|
| 308 | ];
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 | if (!checkStates(table))
|
|---|
| 313 | {
|
|---|
| 314 | throw new Error("Something unexpected has happened. Although the startup-"+
|
|---|
| 315 | "procedure has finished, not all servers are in the state "+
|
|---|
| 316 | "in which they ought to be. Please, try to find out what "+
|
|---|
| 317 | "happened...");
|
|---|
| 318 | }
|
|---|