Index: /trunk/FACT++/src/ratecontrol.cc
===================================================================
--- /trunk/FACT++/src/ratecontrol.cc	(revision 12456)
+++ /trunk/FACT++/src/ratecontrol.cc	(revision 12457)
@@ -268,5 +268,5 @@
         for (int i=0; i<40; i++)
         {
-            if ( fabs(sdata.fBoardRate[i]-mb)<3*db)
+            if ( fabs(sdata.fBoardRate[i]-mb)<2.5*db)
             {
                 avg += sdata.fBoardRate[i];
@@ -275,5 +275,5 @@
         }
 
-        fTriggerRate = avg / num * 40;
+        fTriggerRate = avg/num * 40;
 
         if (fVerbose)
@@ -284,11 +284,22 @@
         }
 
+        if (sdata.fTriggerRate<0)
+            fTriggerRate = sdata.fTriggerRate;
+
         // ----------------------
 
-        if (fTriggerRate>0 && fTriggerRate<fTargetRate)
+        /*
+        if (avg>0 && avg<fTargetRate)
         {
             // I am assuming here (and at other places) the the answer from the FTM when setting
             // the new threshold always arrives faster than the next rate update.
             fThresholdMin = fThresholds[0];
+            Out() << "Setting fThresholdMin to " << fThresholds[0] << endl;
+        }
+        */
+
+        if (fTriggerRate>0 && fTriggerRate<fTargetRate)
+        {
+            fThresholds.assign(160, fThresholdMin);
             return;
         }
@@ -298,9 +309,6 @@
         const float step = (log10(fTriggerRate)-log10(fTargetRate))/0.039 + 1;
 
-        const uint16_t diff = fThresholds[0]+int16_t(truncf(step));
-
-        cout << diff << endl;
-
-        if (diff==fThresholds[0])
+        const uint16_t diff = fThresholdMin+int16_t(truncf(step));
+        if (diff<=fThresholdMin)
             return;
 
@@ -308,5 +316,5 @@
         {
             //Out() << idx/40 << "|" << (idx/4)%10 << "|" << idx%4;
-            Out() << fThresholds[0];
+            Out() << fThresholdMin;
             Out() << (step>0 ? " += " : " -= ");
             Out() << step << " (" << diff << ")" << endl;
@@ -315,4 +323,6 @@
         const uint32_t val[2] = { -1,  diff };
         DimClient::sendCommandNB("FTM_CONTROL/SET_THRESHOLD", (void*)val, 8);
+
+        fThresholdMin = diff;
     }
 
@@ -580,5 +590,5 @@
 
         fThresholdReference = 300;
-        fTargetRate         =  70;
+        fTargetRate         =  75;
 
         return -1;
