Index: trunk/FACT++/scripts/Main.js
===================================================================
--- trunk/FACT++/scripts/Main.js	(revision 17923)
+++ trunk/FACT++/scripts/Main.js	(revision 17924)
@@ -195,18 +195,4 @@
 
 // ================================================================
-//  Interrupt data taking in case of high currents
-// ================================================================
-dim.onchange['FEEDBACK'] = function(state)
-{
-    if ((state.name=="Critical" || state.name=="OnStandby") &&
-        (this.prev!="Critical"  && this.prev!="OnStandby"))
-    {
-        console.out("Feedback state changed from "+this.prev+" to "+state.name+" [Main.js]");
-        irq = "RESCHEDULE";
-    }
-    this.prev=state.name;
-}
-
-// ================================================================
 //  Code related to switching bias voltage on and off
 // ================================================================
@@ -217,7 +203,4 @@
 {
     if (!evt.data)
-        return;
-
-    if (this.ok==undefined)
         return;
 
@@ -240,4 +223,8 @@
     }
     avg /= 320;
+
+    if (this.ok==undefined)
+        return;
+
 
     this.ok = cnt<3;// || (this.last!=undefined && Math.abs(this.last-avg)<0.002);
@@ -319,5 +306,5 @@
         ov = 1.1;
 
-    if (this.ov!=ov && dim.state("FEEDBACK").name=="InProgress") // FIXME: Warning, OnStandby, Critical if (ov<this.ov)
+    if (this.ov!=ov && dim.state("FEEDBACK").name=="InProgress")
     {
         dim.log("Stoping feedback.");
@@ -341,7 +328,4 @@
 
         dim.send("FEEDBACK/START", ov);
-
-        // FIXME: We could miss "InProgress" if it immediately changes to "Warning"
-        //        Maybe a dim.timeout state>8 ?
         dim.wait("FEEDBACK", "InProgress", 45000);
 
@@ -381,5 +365,5 @@
 // ================================================================
 
-function Shutdown(singlepe)
+function Shutdown()
 {
     dim.log("Starting shutdown.");
@@ -435,16 +419,13 @@
     }*/
 
-    if (singlepe)
-    {
-        dim.log("Taking single-pe run.");
-
-        // The voltage must be on
-        service_feedback.voltageOn();
-        service_feedback.waitForVoltageOn();
-
-        // Before we can switch to 3000 we have to make the right DRS calibration
-        dim.log("Taking single p.e. run.");
-        while (!irq && !takeRun("single-pe", 10000));
-    }
+    dim.log("Taking single-pe run.");
+
+    // The voltage must be on
+    service_feedback.voltageOn();
+    service_feedback.waitForVoltageOn();
+
+    // Before we can switch to 3000 we have to make the right DRS calibration
+    dim.log("Taking single p.e. run.");
+    while (!irq && !takeRun("single-pe", 10000));
 
     // It is unclear what comes next, so we better switch off the voltage
@@ -547,5 +528,4 @@
          "FTM_CONTROL/TRIGGER_RATES",
          "GPS_CONTROL/NEMA",
-         "SQM_CONTROL/DATA",
          "LID_CONTROL/DATA",
          "MAGIC_LIDAR/DATA",
@@ -574,5 +554,5 @@
 
     var list = obj.data.split('\n').map(map);
-//     [A
+
     function check(name)
     {
@@ -633,4 +613,6 @@
 //console.out("Feedback init: start.");
 service_feedback.get(5000);
+
+//v8.timeout(3000, function() { var n = dim.state("FEEDBACK").name; if (n=="CurrentCtrlIdle" || n=="CurrentControl") return true; });
 
 // ----------------------------------------------------------------
@@ -726,8 +708,5 @@
 
     if (irq.toUpperCase()=="RESCHEDULE")
-    {
-        irq = undefined;
-        return false;
-    }
+        return true;
 
     if (irq.toUpperCase()=="OFF")
@@ -737,12 +716,4 @@
         return true;
     }
-
-    /*
-    if (irq.toUpperCase()=="STOP")
-    {
-        dim.send("FAD_CONTROL/CLOSE_OPEN_FILES");
-        dim.send("MCP/STOP");
-        return true;
-    }*/
 
     if (irq.toUpperCase()=="SHUTDOWN")
@@ -846,5 +817,5 @@
     }
 
-    // Check if sun is still up... only DATA and */
+    // Check if sun is still up... only DATA and RATESCAN must be suppressed
     if ((obs[sub].task=="DATA" || obs[sub].task=="RATESCAN") && sun.isUp)
     {
@@ -865,5 +836,5 @@
     // otherwise it is difficult to allow e.g. the STARTUP at the beginning of the night
     var power_states = sun.isUp || !system_on ? [ "DriveOff", "SystemOn" ] : [ "SystemOn" ];
-    var drive_states = sun.isUp || !system_on ? undefined : [ "Armed", "Tracking", "OnTrack" ];
+    var drive_states = sun.isUp || !system_on ?   undefined    : [ "Armed", "Tracking", "OnTrack" ];
 
     // A scheduled task was found, lets check if all servers are
@@ -887,5 +858,5 @@
          [ "AGILENT_CONTROL_80V", [ "VoltageOn"                ] ],
          [ "BIAS_CONTROL",        [ "VoltageOff", "VoltageOn", "Ramping" ] ],
-         [ "FEEDBACK",            [ "Calibrated", "InProgress", "OnStandby", "Warning", "Critical" ] ],
+         [ "FEEDBACK",            [ "Calibrated", "InProgress" ] ],
          [ "LID_CONTROL",         [ "Open", "Closed"           ] ],
          [ "DRIVE_CONTROL",       drive_states/*[ "Armed", "Tracking", "OnTrack" ]*/ ],
@@ -895,5 +866,4 @@
          [ "RATE_CONTROL",        [ "Connected", "GlobalThresholdSet", "InProgress"  ] ],
          [ "GPS_CONTROL",         [ "Locked"  ] ],
-         [ "SQM_CONTROL",         [ "Valid"  ] ],
         ];
 
@@ -902,23 +872,9 @@
     {
         throw new Error("Something unexpected has happened. One of the servers "+
-                        "is in a state in which it should not be. Please,"+ 
+                        "is in a state in which it should not be. Please,"+
                         "try to find out what happened...");
     }
 
-    datalogger_subscriptions.check();                                         
-                                                                                
-    // If this is an observation which needs the voltage to be swicthed on
-    // skip that if the voltage is not stable                                    
-    /*
-    if (obs[sub].task=="DATA" || obs[sub].task=="RATESCAN")
-    {
-        var state = dim.state("FEEDBACK").name;
-        if (state=="Warning" || state=="Critical" || state=="OnStandby")
-        {
-            v8.sleep(1000);
-            continue;
-        }
-    }*/
-
+    datalogger_subscriptions.check();
 
     // Check if obs.task is one of the one-time-tasks
@@ -953,5 +909,5 @@
 
     case "SHUTDOWN":
-        Shutdown(true);
+        Shutdown();
         system_on = false;
 
@@ -1081,31 +1037,23 @@
         service_feedback.waitForVoltageOn();
 
-        if (!irq)
-        {
-            var tm2 = new Date();
-
-            dim.log("Starting ratescan.");
-
-            // Start rate scan
-            dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
-
-            // Lets wait if the ratescan really starts... this might take a few
-            // seconds because RATE_SCAN configures the ftm and is waiting for
-            // it to be configured.
-            dim.wait("RATE_SCAN", "InProgress", 10000);
-            dim.wait("RATE_SCAN", "Connected", 2700000);
-
-            // Here one could implement a watchdog for the feedback as well, but what is the difference
-            // whether finally one has to find out if the feedback was in the correct state
-            // or the ratescan was interrupted?
-
-            // this line is actually some kind of hack.
-            // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
-            // So I decided to put this line here as a kind of patchwork....
-            //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
-
-            dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
-        }
-
+        var tm2 = new Date();
+
+        dim.log("Starting ratescan.");
+
+        // Start rate scan
+        dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
+
+        // Lets wait if the ratescan really starts... this might take a few
+        // seconds because RATE_SCAN configures the ftm and is waiting for
+        // it to be configured.
+        dim.wait("RATE_SCAN", "InProgress", 10000);
+        dim.wait("RATE_SCAN", "Connected", 2700000);
+
+        // this line is actually some kind of hack. 
+        // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
+        // So I decided to put this line here as a kind of patchwork....
+        //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 6);
+
+        dim.log("Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
         dim.log("Task finished [RATESCAN]");
         console.out("");
@@ -1124,5 +1072,4 @@
         }
     */
-
         // Calculate remaining time for this observation in minutes
         var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000;
@@ -1187,5 +1134,5 @@
 
         if (irq)
-            continue;
+            break;
 
         OpenLid();
@@ -1193,12 +1140,4 @@
         // This is now th right time to wait for th drive to be stable
         dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
-
-        // Now check the voltage... (do not start a lot of stuff just to do nothing)
-        var state = dim.state("FEEDBACK").name;
-        if (state=="Warning" || state=="Critical" || state=="OnStandby")
-        {
-            v8.sleep(60000);
-            continue;
-        }
 
         // Now we are 'OnTrack', so we can ramp to nominal voltage
@@ -1208,5 +1147,5 @@
 
         // If pointing had changed, do calibration
-        if (!irq && point)
+        if (point)
         {
             dim.log("Starting calibration.");
@@ -1238,5 +1177,5 @@
         {
             var len = 300;
-            while (!irq && len>15)
+            while (len>15)
             {
                 var time = new Date();
