Index: /trunk/FACT++/src/biasctrl.cc
===================================================================
--- /trunk/FACT++/src/biasctrl.cc	(revision 11939)
+++ /trunk/FACT++/src/biasctrl.cc	(revision 11940)
@@ -15,4 +15,5 @@
 
 #include "LocalControl.h"
+#include "HeadersBIAS.h"
 
 namespace ba    = boost::asio;
@@ -22,4 +23,5 @@
 using namespace std::placeholders;
 using namespace std;
+using namespace BIAS;
 
 // ------------------------------------------------------------------------
@@ -27,32 +29,4 @@
 class ConnectionBias : public ConnectionUSB
 {
-    enum
-    {
-        kNumBoards           = 13,
-        kNumChannelsPerBoard = 32,
-        kNumChannels = kNumBoards*kNumChannelsPerBoard
-    };
-
-    enum Command_t
-    {
-        // Communication commands
-        kCmdReset         =  0,
-        kCmdRead          =  1,
-        kCmdGlobalSet     =  2,
-        kCmdChannelSet    =  3,
-
-        // Internal command names
-        kResetChannels    = 0x10|kCmdChannelSet,
-        kUpdate           = 0x10|kCmdRead,
-        kExpertChannelSet = 0x14|kCmdChannelSet,
-        kSynchronize      = 0x1e,
-        //kOverCurReset     = 20,
-    };
-
-    enum
-    {
-        kMaxDac = 0xfff
-    };
-
     boost::asio::deadline_timer fSyncTimer;
     boost::asio::deadline_timer fRampTimer;
@@ -60,4 +34,6 @@
 
     vector<uint8_t> fBuffer;
+    vector<uint8_t> fBufferRamp;
+    vector<uint8_t> fBufferUpdate;
 
     bool fIsVerbose;
@@ -82,5 +58,5 @@
     bool fIsInitializing;
     bool fIsRamping;
-//    bool fWaitingForAnswer;
+    bool fWaitingForAnswer;
 
 protected:
@@ -164,5 +140,5 @@
     }
 
-    bool EvalAnswer(uint8_t *answer, uint16_t id, int command)
+    bool EvalAnswer(const uint8_t *answer, uint16_t id, int command)
     {
         answer += id*3;
@@ -215,4 +191,8 @@
             fSendCounter = wrap;
 
+            msg.str("");
+            msg << "Setting fSendCounter to " << wrap;
+            Info(msg);
+
             return true;
         }
@@ -288,4 +268,96 @@
 
 private:
+    void HandleReceivedData(const vector<uint8_t> &buf, size_t bytes_received, int command, int send_counter)
+    {
+        // Now print the received message if requested by the user
+        if (fIsVerbose/* && command!=kUpdate*/)
+        {
+            Out() << endl << kBold << dec << "Data received (size=" << bytes_received << "):" << endl;
+            Out() << " Command=" << command << " fWrapCounter=" << fWrapCounter << " fSendCounter=" << fSendCounter << " fIsInitializing=" << fIsInitializing << " fIsRamping=" << fIsRamping;
+            Out() << hex << setfill('0');
+
+            for (size_t i=0; i<bytes_received/3; i++)
+            {
+                if (i%8==0)
+                    Out() << '\n' << setw(2) << bytes_received/24 << "| ";
+
+                Out() << setw(2) << uint16_t(buf[i*3+2]);
+                Out() << setw(2) << uint16_t(buf[i*3+1]);
+                Out() << setw(2) << uint16_t(buf[i*3+0]) << " ";
+            }
+            Out() << endl;
+        }
+
+        const int cmd = command&0xf;
+
+        // Check the number of received_byted according to the answer expected
+        if ((cmd==kSynchronize      && !CheckMessageLength(bytes_received, 3,                "Synchronization")) ||
+            (cmd==kCmdReset         && !CheckMessageLength(bytes_received, 3,                "CmdReset"))        ||
+            (cmd==kCmdRead          && !CheckMessageLength(bytes_received, 3*kNumChannels,   "CmdRead"))         ||
+            (cmd==kCmdChannelSet    && !CheckMessageLength(bytes_received, 3*kNumChannels,   "CmdChannelSet"))   ||
+            (cmd==kExpertChannelSet && !CheckMessageLength(bytes_received, 3,                "CmdExpertChannelSet")))
+            return;
+
+        // Now evaluate the whole bunch of messages
+        for (size_t i=0; i<bytes_received/3; i++)
+        {
+            if (!EvalAnswer(buf.data(), i, command))
+            {
+                PostClose(false);
+                return;
+            }
+        }
+
+        if (command==kSynchronize)
+        {
+            Message("Stream successfully synchronized.");
+            fIsInitializing = false;
+
+            // Cancel sending of the next 0
+            fSyncTimer.cancel();
+
+            // Start continous reading of all channels
+            ScheduleUpdate(100);
+            return;
+        }
+
+        if (send_counter%8 != fWrapCounter)
+        {
+            ostringstream msg;
+            msg << "Corrupted answer: received wrap counter " << fWrapCounter  << " is not send counter " << send_counter << "%8.";
+            Error(msg);
+            PostClose(false);
+        }
+
+
+        // Take action depending on what is going on
+        if (command==kCmdReset)
+            Message("Reset command successfully answered.");
+
+        if (cmd==kCmdRead || cmd==kCmdChannelSet || cmd==kExpertChannelSet)
+        {
+            UpdateV();
+            UpdateA();
+        }
+
+        if (cmd==kCmdReset || command==kResetChannels)
+        {
+            // Re-start cyclic reading of values after a short time
+            // to allow the currents to become stable
+            fUpdateTimer.cancel();
+            ScheduleUpdate(100);
+        }
+
+        if (command==kUpdate)
+            ScheduleUpdate(fUpdateTime);
+
+        // If we are ramping, schedule a new ramp step
+        if (command==kCmdChannelSet && fIsRamping)
+        {
+            ScheduleRampStep();
+            return;
+        }
+    }
+
     void HandleReceivedData(const bs::error_code& err, size_t bytes_received, int command, int send_counter)
     {
@@ -319,98 +391,43 @@
         }
 
-        // Now print the received message if requested by the user
-        if (fIsVerbose/* && command!=kUpdate*/)
-        {
-            Out() << endl << kBold << dec << "Data received (size=" << bytes_received << "):" << endl;
-            Out() << " Command=" << command << " fWrapCounter=" << fWrapCounter << " fSendCounter=" << fSendCounter << " fIsInitializing=" << fIsInitializing << " fIsRamping=" << fIsRamping << endl;
-            Out() << hex << setfill('0');
-
-            vector<uint32_t> vout((bytes_received/3)*4);
-
-            for (size_t i=0; i<bytes_received/3; i++)
-            {
-                vout[i] =
-                    (uint32_t(fBuffer[i*3+2])<<16) |
-                    (uint32_t(fBuffer[i*3+1])<< 8) |
-                    (uint32_t(fBuffer[i*3+0])<< 0);
-
-                Out() << setw(6) << vout[i] << " ";
-                if (i%8==7)
-                    Out() << endl;
-            }
-
-            //Out() << Converter::GetHex<uint32_t>(vout, 16) << endl;
-        }
-
-        const int cmd = command&0xf;
-
-        // Check the number of received_byted according to the answer expected
-        if ((cmd==kSynchronize      && !CheckMessageLength(bytes_received, 3,                "Synchronization")) ||
-            (cmd==kCmdReset         && !CheckMessageLength(bytes_received, 3,                "CmdReset"))        ||
-            (cmd==kCmdRead          && !CheckMessageLength(bytes_received, 3*kNumChannels,   "CmdRead"))         ||
-            (cmd==kCmdChannelSet    && !CheckMessageLength(bytes_received, 3*kNumChannels,   "CmdChannelSet"))   ||
-            (cmd==kExpertChannelSet && !CheckMessageLength(bytes_received, 3,                "CmdExpertChannelSet")))
-            return;
-
-        // Now evaluate the whole bunch of messages
-        for (size_t i=0; i<bytes_received/3; i++)
-        {
-            if (!EvalAnswer(fBuffer.data(), i, command))
-            {
-                PostClose(false);
-                return;
-            }
-        }
-
-        // Now we are ready to send a new message
-//        fWaitingForAnswer = false;
-
-        if (command==kSynchronize)
-        {
-            Message("Stream successfully synchronized.");
-            fIsInitializing = false;
-
-            // Cancel sending of the next 0
-            fSyncTimer.cancel();
-
-            // Start continous reading of all channels
-            ScheduleUpdate(100);
-            return;
-        }
-
-        if (send_counter%8 != fWrapCounter)
-        {
-            ostringstream msg;
-            msg << "Corrupted answer: received wrap counter " << fWrapCounter  << " is not send counter " << send_counter << "%8.";
-            Error(msg);
-            PostClose(false);
-        }
-
-
-        // Take action depending on what is going on
-        if (command==kCmdReset)
-            Message("Reset command successfully answered.");
-
-        if (cmd==kCmdRead || cmd==kCmdChannelSet || cmd==kExpertChannelSet)
-        {
-            UpdateV();
-            UpdateA();
-        }
-
-        if (cmd==kCmdReset || command==kResetChannels)
-        {
-            // Re-start cyclic reading of values after a short time
-            // to allow the currents to become stable
-            fUpdateTimer.cancel();
-            ScheduleUpdate(100);
-        }
-
-        if (command==kUpdate)
-            ScheduleUpdate(fUpdateTime);
-
-        // If we are ramping, schedule a new ramp step
-        if (command==kCmdChannelSet && fIsRamping)
-        {
-            ScheduleRampStep();
+        // We have three different parallel streams:
+        //  1) The setting of voltages due to ramping
+        //  2) The cynclic request of the currents
+        //  3) Answers to commands
+        // For each of these three streams an own buffer is needed, otherwise
+        // a buffer which is filled in the background might overwrite
+        // a buffer which is currently evaluated. In all other programs
+        // this is no problem because the boards don't answer and if
+        // they do the answer identifies itself. Consequently,
+        // there is always only one async_read in progress. Here we have
+        // three streams which need to be connected somehow to the
+        // commands.
+
+        // Maybe a better possibility would be to setup a command
+        // queue (each command will be queued in a buffer)
+        // and whenever an answer has been received, a new async_read is
+        // scheduled.
+        // Build a command queue<pair<command, vector<char>>>
+        ///  This replaces the send counter and the command argument
+        //   in handleReceivedData
+
+        switch (command&0xff)
+        {
+        case kSynchronize:
+        case kCmdReset:
+        case kExpertChannelSet:
+        case kCmdGlobalSet:
+        case kResetChannels:
+        case kCmdRead:
+            HandleReceivedData(fBuffer, bytes_received, command, send_counter);
+            fWaitingForAnswer = false;
+            return;
+
+        case kCmdChannelSet:
+            HandleReceivedData(fBufferRamp, bytes_received, command, send_counter);
+            return;
+
+        case kUpdate:
+            HandleReceivedData(fBufferUpdate, bytes_received, command, send_counter);
             return;
         }
@@ -491,5 +508,5 @@
         PostMessage("\0", 1);
         AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, 0);//++fSendCounter);
-//        fWaitingForAnswer = true;
+        fWaitingForAnswer = true;
 
         // Wait for some time before sending the next 0
@@ -551,7 +568,9 @@
 
         PostMessage(data);
-        AsyncRead(ba::buffer(fBuffer, kNumChannels*3),
+        AsyncRead(ba::buffer(special ? fBuffer : fBufferRamp, kNumChannels*3),
                   special ? kResetChannels : kCmdChannelSet, fSendCounter);
-//        fWaitingForAnswer = true;
+
+        if (special)
+            fWaitingForAnswer = true;
     }
 
@@ -651,4 +670,6 @@
         fUpdateTimer(ioservice),
         fBuffer(3*kNumChannels),
+        fBufferRamp(3*kNumChannels),
+        fBufferUpdate(3*kNumChannels),
         fIsVerbose(false),
         fVoltCmd(kNumChannels),
@@ -658,7 +679,8 @@
         fRampStep(-1),
         fRampTime(-1),
+        fUpdateTime(3000),
         fSyncTime(333),
-        fUpdateTime(3000),
         fIsRamping(false),
+        fWaitingForAnswer(false),
         fVolt(kNumChannels),
         fVoltRef(kNumChannels),
@@ -670,4 +692,10 @@
     void OverCurrentReset()
     {
+        if (fWaitingForAnswer)
+        {
+            Error("Answer on last command not yet received.");
+            return;
+        }
+
         if (fIsRamping)
         {
@@ -686,4 +714,10 @@
     void ReadAllChannels(bool special = false)
     {
+        if (!special && fWaitingForAnswer)
+        {
+            Error("Answer on last command not yet received.");
+            return;
+        }
+
         vector<char> data;
         data.reserve(kNumChannels*3);
@@ -698,7 +732,9 @@
 
         PostMessage(data);
-        AsyncRead(ba::buffer(fBuffer, kNumChannels*3),
+        AsyncRead(ba::buffer(special ? fBufferUpdate : fBuffer, kNumChannels*3),
                   special ? kUpdate : kCmdRead, fSendCounter);
-//        fWaitingForAnswer = true;
+
+        if (!special)
+            fWaitingForAnswer = true;
     }
 
@@ -824,8 +860,14 @@
     void ExpertReset()
     {
+        if (fWaitingForAnswer)
+        {
+            Error("Answer on last command not yet received.");
+            return;
+        }
+
         Warn("EXPERT MODE: Sending reset.");
         PostMessage(GetCmd(kCmdReset));
-        AsyncRead(ba::buffer(fBuffer, 3), kCmdReset);
-//        fWaitingForAnswer = true;
+        AsyncRead(ba::buffer(fBuffer, 3), kCmdReset, ++fSendCounter);
+        fWaitingForAnswer = true;
     }
 
@@ -833,4 +875,10 @@
     bool ExpertChannelSetDac(uint16_t ch, uint16_t dac)
     {
+        if (fWaitingForAnswer)
+        {
+            Error("Answer on last command not yet received.");
+            return false;
+        }
+
         if (!CheckChDac("ExpertChannelSetDac", dac, ch))
             return false;
@@ -844,5 +892,5 @@
         PostMessage(GetCmd(kCmdChannelSet, ch, dac));
         AsyncRead(ba::buffer(fBuffer, 3), kExpertChannelSet|(ch<<8), ++fSendCounter);
-//        fWaitingForAnswer = true;
+        fWaitingForAnswer = true;
 
         return true;
@@ -856,4 +904,10 @@
     bool ExpertGlobalSetDac(uint16_t dac)
     {
+        if (fWaitingForAnswer)
+        {
+            Error("Answer on last command not yet received.");
+            return false;
+        }
+
         if (!CheckChDac("ExpertGlobalSetDac", dac))
             return false;
@@ -873,5 +927,5 @@
         PostMessage(GetCmd(kCmdGlobalSet, 0, dac));
         AsyncRead(ba::buffer(fBuffer, 3), kCmdGlobalSet, ++fSendCounter);
-//        fWaitingForAnswer = true;
+        fWaitingForAnswer = true;
 
         return true;
@@ -1042,39 +1096,27 @@
     */
 
-    enum States_t
-    {
-        kDisconnected = StateMachineImp::kSM_UserMode,
-        kConnecting,
-        kInitializing,
-        kConnected,
-        kRamping,
-        kOverCurrent,
-        kAtReference,
-        kExpertMode // 'forward' declaration to be used in StateMachineBias
-    };
-
-    int GetStatus()
+    States_t GetStatus()
     {
         if (!IsConnected())
-            return kDisconnected;
+            return BIAS::kDisconnected;
 
         if (IsConnecting())
-            return kConnecting;
+            return BIAS::kConnecting;
 
         if (fIsInitializing)
-            return kInitializing;
+            return BIAS::kInitializing;
 
         if (fIsRamping)
-            return kRamping;
+            return BIAS::kRamping;
 
         for (int ch=0; ch<kNumChannels; ch++)
             if (fPresent[ch/kNumChannelsPerBoard] && fCurrent[ch]<0)
-                return kOverCurrent;
+                return BIAS::kOverCurrent;
 
         for (int ch=0; ch<kNumChannels; ch++)
             if (fPresent[ch/kNumChannelsPerBoard] && fVolt[ch]!=fVoltRef[ch])
-                return kConnected;
-
-        return kAtReference;
+                return BIAS::kConnected;
+
+        return BIAS::kAtReference;
     }
 };
@@ -1306,6 +1348,6 @@
         poll_one();
 
-        return fExpertMode && fBias.GetStatus()==ConnectionBias::kConnected ?
-            ConnectionBias::kExpertMode : fBias.GetStatus();
+        return fExpertMode && fBias.GetStatus()>=kConnected ?
+            kExpertMode : fBias.GetStatus();
     }
 
@@ -1323,26 +1365,26 @@
 
         // State names
-        T::AddStateName(ConnectionBias::kDisconnected, "Disconnected",
+        T::AddStateName(kDisconnected, "Disconnected",
                         "Bias-power supply not connected via USB.");
 
-        T::AddStateName(ConnectionBias::kConnecting, "Connecting",
+        T::AddStateName(kConnecting, "Connecting",
                         "Trying to establish USB connection to bias-power supply.");
 
-        T::AddStateName(ConnectionBias::kInitializing, "Initializing",
+        T::AddStateName(kInitializing, "Initializing",
                         "USB connection to bias-power supply established, synchronizing USB stream.");
 
-        T::AddStateName(ConnectionBias::kConnected, "Connected",
+        T::AddStateName(kConnected, "Connected",
                         "USB connection to bias-power supply established.");
 
-        T::AddStateName(ConnectionBias::kAtReference, "Referenced",
+        T::AddStateName(kAtReference, "Referenced",
                         "Internal reference voltage matches last sent voltage.");
 
-        T::AddStateName(ConnectionBias::kOverCurrent, "OverCurrent",
+        T::AddStateName(kOverCurrent, "OverCurrent",
                         "At least one channel is in over current state.");
 
-        T::AddStateName(ConnectionBias::kExpertMode, "ExpertMode",
+        T::AddStateName(kExpertMode, "ExpertMode",
                         "Special (risky!) mode to directly send command to the bias-power supply.");
 
-        T::AddStateName(ConnectionBias::kRamping, "Ramping",
+        T::AddStateName(kRamping, "Ramping",
                         "Voltage ramping in progress.");
 
@@ -1354,9 +1396,9 @@
 
         // Conenction commands
-        T::AddEvent("DISCONNECT", ConnectionBias::kConnected, ConnectionBias::kAtReference)
+        T::AddEvent("DISCONNECT", kConnected, kAtReference)
             (bind(&StateMachineBias::Disconnect, this))
             ("disconnect from ethernet");
 
-        T::AddEvent("RECONNECT", "O", ConnectionBias::kDisconnected, ConnectionBias::kConnected, ConnectionBias::kAtReference)
+        T::AddEvent("RECONNECT", "O", kDisconnected, kConnected, kAtReference)
             (bind(&StateMachineBias::Reconnect, this, placeholders::_1))
             ("(Re)connect ethernet connection to FTM, a new address can be given"
@@ -1365,9 +1407,9 @@
 
 
-        T::AddEvent("REQUEST_STATUS", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("REQUEST_STATUS", kConnected, kAtReference, kOverCurrent)
             (Wrapper(bind(&ConnectionBias::ReadAllChannels, &fBias, false)))
             ("Asynchronously request the status (current) of all channels.");
 
-        T::AddEvent("RESET_OVER_CURRENT_STATUS", ConnectionBias::kOverCurrent)
+        T::AddEvent("RESET_OVER_CURRENT_STATUS", kOverCurrent)
             (Wrapper(bind(&ConnectionBias::OverCurrentReset, &fBias)))
             ("NOT YET TESTED");
@@ -1375,25 +1417,25 @@
 
 
-        T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1", kConnected, kAtReference, kOverCurrent)
             (bind(&StateMachineBias::SetGlobalVolt, this, placeholders::_1))
             ("Set all channels to a new reference voltage. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)");
 
-        T::AddEvent("SET_GLOBAL_DAC", "S:1", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("SET_GLOBAL_DAC", "S:1", kConnected, kAtReference, kOverCurrent)
             (bind(&StateMachineBias::SetGlobalDac, this, placeholders::_1))
             ("Set all channels to a new DAC reference. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)");
 
-        T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", kConnected, kAtReference, kOverCurrent)
             (bind(&StateMachineBias::SetChannelVolt, this, placeholders::_1))
             ("Set a single channel a new reference voltage. Starts ramping if necessary.");
 
-        T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", kConnected, kAtReference, kOverCurrent)
             (bind(&StateMachineBias::SetChannelDac, this, placeholders::_1))
             ("Set a single channel a new DAC reference value. Starts ramping if necessary.");
 
-        T::AddEvent("SET_GAPD_REFERENCE_VOLTAGE", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("SET_GAPD_REFERENCE_VOLTAGE", kConnected, kAtReference, kOverCurrent)
             (Wrapper(bind(&ConnectionBias::SetGapdVoltage, &fBias)))
             ("Set all channels to their G-APD reference voltage. Starts ramping if necessary.");
 
-        T::AddEvent("SET_ZERO_VOLTAGE", ConnectionBias::kConnected, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("SET_ZERO_VOLTAGE", kConnected, kAtReference, kOverCurrent)
             (Wrapper(bind(&ConnectionBias::SetZero, &fBias)))
             ("Set all channels to a zero reference voltage. Starts ramping if necessary.");
@@ -1401,9 +1443,9 @@
 
 
-        T::AddEvent("STOP", ConnectionBias::kConnected, ConnectionBias::kRamping, ConnectionBias::kAtReference, ConnectionBias::kOverCurrent)
+        T::AddEvent("STOP", kConnected, kRamping, kAtReference, kOverCurrent)
             (Wrapper(bind(&ConnectionBias::RampStop, &fBias)))
             ("");
 
-        T::AddEvent("START", ConnectionBias::kConnected, ConnectionBias::kOverCurrent)
+        T::AddEvent("START", kConnected, kOverCurrent)
             (Wrapper(bind(&ConnectionBias::RampStart, &fBias)))
             ("");
@@ -1426,21 +1468,21 @@
             ("Enable usage of expert commands (note that for safty reasons the are exclusive with the standard commands)");
 
-        T::AddEvent("EXPERT_RESET", ConnectionBias::kExpertMode)
+        T::AddEvent("EXPERT_RESET", kExpertMode)
             (Wrapper(bind(&ConnectionBias::ExpertReset, &fBias)))
             ("Send the RESET command (note that this is possibly harmfull command)");
 
-        T::AddEvent("EXPERT_SET_GLOBAL_VOLTAGE", "F:1", ConnectionBias::kExpertMode)
+        T::AddEvent("EXPERT_SET_GLOBAL_VOLTAGE", "F:1", kExpertMode)
             (bind(&StateMachineBias::ExpertSetGlobalVolt, this, placeholders::_1))
             ("Send the global set command. The given voltage is converted to DAC counts.");
 
-        T::AddEvent("EXPERT_SET_GLOBAL_DAC", "S:1", ConnectionBias::kExpertMode)
+        T::AddEvent("EXPERT_SET_GLOBAL_DAC", "S:1", kExpertMode)
             (bind(&StateMachineBias::ExpertSetGlobalDac, this, placeholders::_1))
             ("Send the global set command.");
 
-        T::AddEvent("EXPERT_SET_CHANNEL_VOLTAGE", "S:1;F:1", ConnectionBias::kExpertMode)
+        T::AddEvent("EXPERT_SET_CHANNEL_VOLTAGE", "S:1;F:1", kExpertMode)
             (bind(&StateMachineBias::ExpertSetChannelVolt, this, placeholders::_1))
             ("Send a single channel set command. The given voltage is converted to DAC commands.");
 
-        T::AddEvent("EXPERT_SET_CHANNEL_DAC", "S:1;S:1", ConnectionBias::kExpertMode)
+        T::AddEvent("EXPERT_SET_CHANNEL_DAC", "S:1;S:1", kExpertMode)
             (bind(&StateMachineBias::ExpertSetChannelDac, this, placeholders::_1))
             ("Send a single channel set command.");
@@ -1494,5 +1536,5 @@
         int l = 0;
 
-        vector<float> vec(ConnectionBias::kNumChannels);
+        vector<float> vec(kNumChannels);
 
         string buf;
@@ -1517,5 +1559,5 @@
             str >> fdummy >> fdummy >> fdummy;
 
-            if (channel+32*board>=ConnectionBias::kNumChannels)
+            if (channel+32*board>=kNumChannels)
             {
                 T::Error("Invalid board/channel read from FACTmapV5.txt.");
