Changeset 229 for hvcontrol/src


Ignore:
Timestamp:
06/24/10 07:51:15 (14 years ago)
Author:
ogrimm
Message:
Config requests non-blocking if not made from main thread, adapted all servers to GetConfig() returning std::string, workaround for erroneous SERVICE_LIST
Location:
hvcontrol/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/HV.cc

    r220 r229  
    1414#include "ProcessIO.h" // Must be not in HV.h to avoid problem with declaring class ProcessIO
    1515
     16using namespace std;
     17
    1618// Constructor
    17 HVBoard::HVBoard(int DeviceNumber, char *DeviceName, class ProcessIO *PIO) {
     19HVBoard::HVBoard(int DeviceNumber, string Name, class ProcessIO *PIO) {
    1820   
    19   char *Buffer;
    2021  struct termios tio;
    2122 
    2223  m = PIO;
    23 
    2424  SetTimeOut(m->fTimeOut);
    2525  BoardNumber = DeviceNumber;
    26   BoardName = DeviceName;
    27  
     26  BoardName = new char [Name.size()+1];
     27  strcpy(BoardName, Name.c_str());
     28 
     29  stringstream Buf;
     30  Buf << setw(2) << BoardNumber;
     31  string Result =Buf.str();
     32
    2833  // Create DIM services
    29   if (asprintf(&Buffer, SERVER_NAME"/NAME/ID%.2d", BoardNumber) == -1) {
    30     m->PrintMessage(All, "asprintf() failed for DIM service name creation\n");
    31         return;
    32   }
    33   Name = new DimService (Buffer, BoardName);
    34   free(Buffer);
    35  
    36   if (asprintf(&Buffer, SERVER_NAME"/VOLT/ID%.2d", BoardNumber) == -1) {
    37     m->PrintMessage(All, "asprintf() failed for DIM service name creation\n");
    38         return;
    39   }
    40   BiasVolt = new DimService (Buffer, "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
    41   free(Buffer);
     34  NameService = new DimService ((SERVER_NAME"/NAME/ID"+Result).c_str(), BoardName);
     35  BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+Result).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
    4236
    4337  for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = false;
     
    4943  ClearVoltageArrays();
    5044
    51   // Open device (do not warn on non-existing device)
    52   if (asprintf(&Buffer, "/dev/%s",DeviceName) == -1) {
    53     m->PrintMessage(All, "asprintf() failed for device name creation\n");
    54         return;
    55   }
    56   if ((fDescriptor = open(Buffer, O_RDWR|O_NOCTTY|O_NDELAY)) == -1) {
    57     if(errno != 2) m->PrintMessage(All, "Error: Could not open device %d/%s (%s)\n", DeviceNumber,DeviceName, strerror(errno));
    58         free(Buffer);
     45  if ((fDescriptor = open(("/dev/"+Name).c_str(), O_RDWR|O_NOCTTY|O_NDELAY)) == -1) {
     46    if(errno != 2) m->PrintMessage(All, "Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno));
    5947    return;
    6048  }
    61   free(Buffer);
    6249
    6350  // Get current serial port settings
     
    9683  }
    9784
    98   delete Name;
     85  delete NameService;
    9986  delete BiasVolt;
     87  delete[] BoardName;
    10088}
    10189
  • hvcontrol/src/HV.h

    r183 r229  
    88#include <unistd.h>
    99#include <sys/ioctl.h>
     10#include <string>
    1011
    1112#include "dis.hxx"
     
    3940 public:
    4041 
    41    HVBoard(int, char *, class ProcessIO *);
     42   HVBoard(int, std::string, class ProcessIO *);
    4243   ~HVBoard();
    4344
     
    5455   double HVV[NUM_CHAINS][NUM_CHANNELS];  // HV value in volts
    5556
    56    DimService *Name;
     57   DimService *NameService;
    5758   DimService *BiasVolt;
    5859
  • hvcontrol/src/ProcessIO.cc

    r226 r229  
    1212#include "ProcessIO.h"
    1313
    14 static char* state_str[]    = {"active", "stopped", "n.a."};
     14static const char* state_str[]    = {"active", "stopped", "n.a."};
    1515
    1616// Branch table for command evaluation
     
    6363
    6464  // Get configuration data
    65   char *Boards = GetConfig("Boards");
     65  vector<string> Boards = Tokenize(GetConfig("Boards"), " \t");
    6666  fPixMapTable = GetConfig("PixMapTable");
    67   fTimeOut = atof(GetConfig("TimeOut"));
    68   fStatusRefreshRate = atof(GetConfig("StatusRefreshRate"));
    69   DACMin = atoi(GetConfig("DACMin"));
    70   DACMax = atoi(GetConfig("DACMax"));
    71   fHVCalibOffset = atof(GetConfig("HVCalibOffset"));
    72   fHVCalibSlope = atof(GetConfig("HVCalibSlope"));
    73   fHVMaxDiff = atoi(GetConfig("HVMaxDiff"));
     67  fTimeOut = atof(GetConfig("TimeOut").c_str());
     68  fStatusRefreshRate = atof(GetConfig("StatusRefreshRate").c_str());
     69  DACMin = atoi(GetConfig("DACMin").c_str());
     70  DACMax = atoi(GetConfig("DACMax").c_str());
     71  fHVCalibOffset = atof(GetConfig("HVCalibOffset").c_str());
     72  fHVCalibSlope = atof(GetConfig("HVCalibSlope").c_str());
     73  fHVMaxDiff = atoi(GetConfig("HVMaxDiff").c_str());
    7474
    7575  if (fStatusRefreshRate < MIN_RATE || fStatusRefreshRate > MAX_RATE)  fStatusRefreshRate = 1;
    7676
    7777  // Open HV devices
    78   fHVBoard = new HVBoard* [strlen(Boards)];
    79   char *Token = strtok(Boards, " \t");
    80   while (Token != NULL) {
    81     fHVBoard[NumHVBoards] = new HVBoard(NumHVBoards, Token, this);
     78  fHVBoard = new HVBoard* [Boards.size()];
     79  for (unsigned int i=0; i<Boards.size(); i++) {
     80    fHVBoard[NumHVBoards] = new HVBoard(NumHVBoards, Boards[i], this);
    8281    if(fHVBoard[NumHVBoards]->fDescriptor >= 0) {
    83        PrintMessage("Synchronized and reset board %d (%s)\n",NumHVBoards,fHVBoard[NumHVBoards]->BoardName);
     82       PrintMessage("Synchronized and reset board %d (%s)\n", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);
    8483       NumHVBoards++;
    8584    }
    8685    else {
    87       PrintMessage(All, "Failed to synchronize board %d (%s)\n",NumHVBoards,fHVBoard[NumHVBoards]->BoardName);
     86      PrintMessage(All, "Failed to synchronize board %d (%s)\n", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);
    8887      delete fHVBoard[NumHVBoards];
    8988    }
    90         Token = strtok(NULL, " \t");
    9189  }
    9290  LastBoard = NumHVBoards-1;
     
    199197
    200198  PrintMessage( " Pixel map table:   %s\n"
    201                 " %d USB devices:\n", fPixMapTable, NumHVBoards); 
     199                " %d USB devices:\n", fPixMapTable.c_str(), NumHVBoards); 
    202200
    203201  for (int i=0; i<NumHVBoards; i++) PrintMessage(" Board %d: %s\n", i, fHVBoard[i]->BoardName);
  • hvcontrol/src/ProcessIO.h

    r226 r229  
    77#include <math.h>
    88#include <signal.h>
     9#include <string>
    910
    1011#define SERVER_NAME "Bias"       // Name to use in DIM
     
    4647
    4748        // Configuration data
    48         char *fPixMapTable;
     49        std::string fPixMapTable;
    4950        float fTimeOut;
    5051        float fStatusRefreshRate;
Note: See TracChangeset for help on using the changeset viewer.