Index: /trunk/FACT++/src/biasctrl.cc
===================================================================
--- /trunk/FACT++/src/biasctrl.cc	(revision 11774)
+++ /trunk/FACT++/src/biasctrl.cc	(revision 11775)
@@ -47,4 +47,5 @@
 #define RESISTOR float(1000)
 
+protected:
 
     vector<uint16_t> fVolt;        // Voltage in DAC units
@@ -58,4 +59,18 @@
 
     bool fResetHit;
+
+    virtual void UpdateA()
+    {
+        if (!fIsVerbose)
+            return;
+
+        for (int c=0; c<kNumChannels; c++)
+        {
+            Out() << setw(2) << c << ":";
+            for (int b=0; b<kNumBoards; b++)
+                Out() << " " << setprecision(2) << fixed << setw(5) << fCurrent[b+c*kNumBoards];
+            Out() << endl;
+        }
+    }
 
 private:
@@ -137,4 +152,6 @@
                 fOC[i] = false;
         }
+
+        UpdateA();
     }
 
@@ -218,19 +235,4 @@
 
         return data;
-    }
-
-    void ReadAllChannelsStatus()
-    {
-        vector<char> data;
-        data.reserve(kNumChannels*3);
-
-        // Prepare command to read all channels
-        for (int i=0; i<kNumChannels; i++)
-            {
-                const vector<char> cmd = GetCmd(i, kCmdRead);
-                data.insert(data.end(), cmd.begin(), cmd.end());
-            }
-
-        PostMessage(data);
     }
 
@@ -253,5 +255,4 @@
     }
 
-
     void SetChannels(const map<uint16_t, uint16_t> &vals)
     {
@@ -305,53 +306,4 @@
     }
     */
-
-    void SetReferenceCurrent()
-    {
-        fRefCurrent = fCurrent;
-    }
-
-    void GlobalSet(double voltage)
-    {
-        if (voltage>90)
-            return;
-
-        GlobalSetDac(voltage/90.0*0xfff);
-    }
-
-    // ***** Correct voltages according to current *****
-    void AdaptVoltages()
-    {
-        map<uint16_t, uint16_t> values;
-
-        for (int i=0; i<kNumChannels; i++)
-        {
-            if (fRefVolt[i]==0)
-                continue;
-
-            // Calculate difference and convert ADC units to Amps
-            const double diffcur = (fRefCurrent[i]-fCurrent[i])*1.22;
-
-            // Calculate voltage difference
-            const double diffvolt = diffcur*RESISTOR/1e6;
-
-            // Calculate new vlaue by onverting voltage difference to DAC units
-            const int32_t dac = fRefVolt[i] + diffvolt/90.0*0xfff;
-
-            if (dac<0 || dac>0xfff)
-                continue;
-
-            values[i] = fRefVolt[i] + dac;
-        }
-
-        SetChannels(values);
-
-        /*
-        static int LastUpdate = 0;
-        if (time(NULL)-LastUpdate > 5)
-        {
-            LastUpdate = time(NULL);
-            UpdateDIM();
-        }*/
-    }
 
 public:
@@ -368,4 +320,70 @@
     }
 
+    bool GlobalSet(double voltage)
+    {
+        if (voltage<0 || voltage>90)
+            return false;
+
+        GlobalSetDac(voltage/90.0*0xfff);
+
+        return true;
+    }
+
+    void ReadAllChannelsStatus()
+    {
+        vector<char> data;
+        data.reserve(kNumChannels*3);
+
+        // Prepare command to read all channels
+        for (int i=0; i<kNumChannels; i++)
+            {
+                const vector<char> cmd = GetCmd(i, kCmdRead);
+                data.insert(data.end(), cmd.begin(), cmd.end());
+            }
+
+        PostMessage(data);
+    }
+
+    // ***** Correct voltages according to current *****
+    void AdaptVoltages()
+    {
+        map<uint16_t, uint16_t> values;
+
+        for (int i=0; i<kNumChannels; i++)
+        {
+            if (fRefVolt[i]==0)
+                continue;
+
+            // Calculate difference and convert ADC units to Amps
+            const double diffcur = (fRefCurrent[i]-fCurrent[i])*1.22;
+
+            // Calculate voltage difference
+            const double diffvolt = diffcur*RESISTOR/1e6;
+
+            // Calculate new vlaue by onverting voltage difference to DAC units
+            const int32_t dac = fRefVolt[i] + diffvolt/90.0*0xfff;
+
+            if (dac<0 || dac>0xfff)
+                continue;
+
+            values[i] = fRefVolt[i] + dac;
+        }
+
+        SetChannels(values);
+
+        /*
+        static int LastUpdate = 0;
+        if (time(NULL)-LastUpdate > 5)
+        {
+            LastUpdate = time(NULL);
+            UpdateDIM();
+        }*/
+    }
+
+    void SetReferenceCurrent()
+    {
+        fRefCurrent = fCurrent;
+    }
+
     void SetVerbose(bool b)
     {
@@ -383,21 +401,23 @@
 
     DimDescribedService fDimCurrent;
-
-    void Update(DimDescribedService &svc, vector<float> data, float time) const
-    {
-        data.insert(data.begin(), time);
-        svc.setData(data.data(), data.size()*sizeof(float));
-        svc.updateService();
-    }
-
-    void UpdateCur(float time, const vector<float> &curr)
-    {
-        Update(fDimCurrent, curr, time);
-    }
+    DimDescribedService fDimVoltage;
+
+    void UpdateA()
+    {
+        fDimCurrent.Update(fCurrent);
+        ConnectionBias::UpdateA();
+    }
+
+    /*
+    void UpdateV()
+    {
+        fDimCurrent.Update(fRefVolt);
+    }*/
 
 public:
     ConnectionDimBias(ba::io_service& ioservice, MessageImp &imp) :
         ConnectionBias(ioservice, imp),
-        fDimCurrent("BIAS_CONTROL/CURRENT", "F:1;F:4", "")
+        fDimCurrent("BIAS_CONTROL/CURRENT", "F:416", ""),
+        fDimVoltage("BIAS_CONTROL/VOLTAGE", "F:416", "")
     {
     }
@@ -422,4 +442,15 @@
     }
 
+    bool CheckEventSize(size_t has, const char *name, size_t size)
+    {
+        if (has==size)
+            return true;
+
+        ostringstream msg;
+        msg << name << " - Received event has " << has << " bytes, but expected " << size << ".";
+        T::Fatal(msg);
+        return false;
+    }
+
 private:
     S fBias;
@@ -430,4 +461,16 @@
         kStateConnected    = 2,
     };
+
+    int SetGlobal(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetGlobal", 4))
+            return false;
+
+        if (!fBias.GlobalSet(evt.GetFloat()))
+            T::Error("Supplied voltage out of range (0-90)");
+
+        return T::GetCurrentState();
+    }
+
 
     int Disconnect()
@@ -475,15 +518,4 @@
     }
 
-    bool CheckEventSize(size_t has, const char *name, size_t size)
-    {
-        if (has==size)
-            return true;
-
-        ostringstream msg;
-        msg << name << " - Received event has " << has << " bytes, but expected " << size << ".";
-        T::Fatal(msg);
-        return false;
-    }
-
     int SetVerbosity(const EventImp &evt)
     {
@@ -530,4 +562,25 @@
             ("(Re)connect ethernet connection to FTM, a new address can be given"
              "|[host][string]:new ethernet address in the form <host:port>");
+
+
+        AddEvent("REQUEST_STATUS", kStateConnected)
+            (Wrap(bind(&ConnectionBias::ReadAllChannelsStatus, &fBias)))
+            ("");
+
+        AddEvent("SET_GLOBAL", "F:1", kStateConnected)
+            (bind(&StateMachineBias::SetGlobal, this, _1))
+            ("");
+
+        AddEvent("RESET", kStateConnected)
+            (Wrap(bind(&ConnectionBias::SystemReset, &fBias)))
+            ("");
+
+        AddEvent("SET_REFERENCE_CURRENT", kStateConnected)
+            (Wrap(bind(&ConnectionBias::SetReferenceCurrent, &fBias)))
+            ("");
+
+        AddEvent("ADAPT_VOLTAGES", kStateConnected)
+            (Wrap(bind(&ConnectionBias::AdaptVoltages, &fBias)))
+            ("");
     }
 
