Changeset 230 for hvcontrol/src


Ignore:
Timestamp:
06/24/10 14:16:17 (14 years ago)
Author:
ogrimm
Message:
Command reception logged by drsdaq and hvcontrol
Location:
hvcontrol/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/HV.cc

    r229 r230  
    2727  strcpy(BoardName, Name.c_str());
    2828 
    29   stringstream Buf;
    30   Buf << setw(2) << BoardNumber;
    31   string Result =Buf.str();
    32 
    3329  // Create DIM services
    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));
    36 
     30  stringstream ID;
     31  ID << setfill('0') << setw(2) << BoardNumber;
     32
     33  NameService = new DimService ((SERVER_NAME"/NAME/ID"+ID.str()).c_str(), BoardName);
     34  BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+ID.str()).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double));
     35
     36  // Initialise board variables
    3737  for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = false;
    3838  ResetButton = false;
     
    4343  ClearVoltageArrays();
    4444
     45  // Open device
    4546  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));
     47    if(errno != 2) m->PrintMessage("Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno));
    4748    return;
    4849  }
     
    5051  // Get current serial port settings
    5152  if (tcgetattr(fDescriptor, &tio) == -1) {
    52     m->PrintMessage(All, "Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno));
     53    m->PrintMessage("Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno));
    5354    return;   
    5455  }
    5556
    5657  // Set baudrate and raw mode
    57   if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage(All, "Error: Could not set baud rate (%s)\n", strerror(errno));
     58  if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage("Error: Could not set baud rate (%s)\n", strerror(errno));
    5859  cfmakeraw(&tio);
    59   if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage(All, "Error: tcsetattr() failed (%s)\n", strerror(errno));
     60  if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage("Error: tcsetattr() failed (%s)\n", strerror(errno));
    6061
    6162  //  Synchronize HV board (if fails, closes device and sets fDescriptor to -2)
     
    100101  // === Write data ===
    101102  if ((ret=write(fDescriptor, wbuf, Bytes)) < Bytes) {
    102     if (ret == -1) m->PrintMessage(All, "Could not write data to HV board (%s)\n", strerror(errno));
    103     else m->PrintMessage(All, "Could write only %d of %d bytes to HV board\n", ret, Bytes);
     103    if (ret == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno));
     104    else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", ret, Bytes);
    104105    ErrorCount++;
    105106    return 0;
     
    110111  struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};
    111112  if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
    112     m->PrintMessage(All, "Error with select() (%s)\n", strerror(errno));
     113    m->Message(m->ERROR, "Error with select() (%s)", strerror(errno));
    113114    return 0;
    114115  }
     
    118119  // Read error?   
    119120  if ((ret = read(fDescriptor, &rbuf, 1)) == -1) {
    120     m->PrintMessage(All, "Read error (%s)\n", strerror(errno));
     121    m->Message(m->ERROR, "Read error (%s)", strerror(errno));
    121122    ErrorCount++;
    122123    return 0;
  • hvcontrol/src/ProcessIO.cc

    r229 r230  
    6464  // Get configuration data
    6565  vector<string> Boards = Tokenize(GetConfig("Boards"), " \t");
    66   fPixMapTable = GetConfig("PixMapTable");
    6766  fTimeOut = atof(GetConfig("TimeOut").c_str());
    6867  fStatusRefreshRate = atof(GetConfig("StatusRefreshRate").c_str());
     
    8483    }
    8584    else {
    86       PrintMessage(All, "Failed to synchronize board %d (%s)\n", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);
     85      Message(WARN, "Failed to synchronize board %d (%s)", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);
    8786      delete fHVBoard[NumHVBoards];
    8887    }
     
    9291  // Create instances
    9392  calib  = new HVCalib(this);
    94   pm     = new PixelMap(fPixMapTable);
     93  pm     = new PixelMap(GetConfig("PixMapTable"));
    9594 
    9695  // Install DIM command (after all initialized)
     
    196195void ProcessIO::cmd_config() {
    197196
    198   PrintMessage( " Pixel map table:   %s\n"
    199                 " %d USB devices:\n", fPixMapTable.c_str(), NumHVBoards); 
     197  PrintMessage( " %d USB devices:\n", NumHVBoards); 
    200198
    201199  for (int i=0; i<NumHVBoards; i++) PrintMessage(" Board %d: %s\n", i, fHVBoard[i]->BoardName);
     
    414412  state = active;
    415413  pthread_kill(HVMonitor, SIGUSR1);
    416   PrintMessage(All, "Status monitoring activated\n");
     414  Message(INFO, "Status monitoring activated");
    417415}
    418416
     
    448446  state = stopped;
    449447  pthread_kill(HVMonitor, SIGUSR1);
    450   PrintMessage(All, "Status monitor stopped\n");
     448  Message(INFO, "Status monitor stopped");
    451449}
    452450
     
    481479 
    482480
    483 // Print message to selected target
    484 void ProcessIO::PrintMessage(MsgTarget Target, const char *Format, ...) {
    485 
    486   va_list ArgumentPointer;
    487   va_start(ArgumentPointer, Format);
    488   DoPrintMessage(Format, ArgumentPointer, Target);
    489   va_end(ArgumentPointer);
    490 }
    491 
    492 // Print message to log file, and screen or socket (depending on command origin)
     481// Print message to screen and to DIM text service
    493482void ProcessIO::PrintMessage(const char *Format, ...) {
    494483
     484  static char Error[] = "vasprintf() failed in PrintMessage()";
     485  char *Text;
     486
     487  // Evaluate arguments   
    495488  va_list ArgumentPointer;
    496489  va_start(ArgumentPointer, Format);
    497   DoPrintMessage(Format, ArgumentPointer, Console);
     490  if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error;
    498491  va_end(ArgumentPointer);
    499 }
    500 
    501 // Function doing the actual printing work
    502 // Be careful with overloading variadic functions!
    503 void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, MsgTarget Target) {
    504 
    505   static char Error[] = "vasprintf() failed in DoPrintMessage()";
    506   char *Text;
    507 
    508   // Evaluate arguments   
    509   if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error;
    510  
     492 
    511493  // Print to console
    512   if(Target & Console) {
    513     if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt
    514     else printf("%s", Text);
    515     fflush(stdout);
    516   }
    517 
    518   // Send to DIM console service and log
     494  if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt
     495  else printf("%s", Text);
     496  fflush(stdout);
     497
     498  // Send to DIM text service
    519499  ConsoleOut->updateService(Text);
    520   if(Target & Log) SendToLog("%s %s", SERVER_NAME, Text);
    521500
    522501  // Free old text
     
    524503  ConsoleText = Text;
    525504}
     505
    526506
    527507// Ramp to new voltage with maximum step size given in fHVMaxDiff
     
    558538      if (!Warned) {
    559539        Warned = true;
    560         PrintMessage(All, "Warning: Some board has many read/write errors, status monitor disabled\n");
    561         Message(WARN, "Warning: Some board has many read/write errors, status monitor disabled\n");
     540        Message(WARN, "Warning: Board %d has many read/write errors, status monitor disabled", i);
    562541      }
    563542      continue;
     
    565544
    566545    if (fHVBoard[i]->GetStatus() != 1) {
    567       PrintMessage(All, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber());
    568       Message(ERROR, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber());
     546      Message(ERROR, "Error: Monitor could not read status of board %d", fHVBoard[i]->GetBoardNumber());
    569547    }
    570548   
    571549    if (fHVBoard[i]->ResetButton) {
    572       PrintMessage(All, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber());
    573       Message(INFO, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber());
     550      Message(INFO, "Manual reset of board %d", fHVBoard[i]->GetBoardNumber());
    574551      ResetBoard(i);
    575552    }
    576553   
    577554    if (!fHVBoard[i]->WrapOK) {
    578       PrintMessage(All, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber());
    579       Message(ERROR, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber());
     555      Message(ERROR, "Error: Wrap counter mismatch board %d",fHVBoard[i]->GetBoardNumber());
    580556    }
    581557
    582558    for (int j=0; j<NUM_CHAINS; j++) {
    583559      if (fHVBoard[i]->Overcurrent[j]) {
    584                 PrintMessage(All, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber());
    585                 Message(WARN, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber());
     560                Message(WARN, "Warning: Overcurrent in chain %d of board %d",j,fHVBoard[i]->GetBoardNumber());
    586561                ResetBoard(i);
    587562      }
     
    631606  }
    632607
    633   if (getCommand() == Command) CommandControl(getCommand()->getString());
     608  if ((getCommand()==Command) && (*(Command->getString()+Command->getSize()-1)=='\0')) {
     609        SendToLog("Command '%s' from %s (ID %d)", Command->getString(), getClientName(), getClientId());
     610        CommandControl(Command->getString());
     611  }
    634612
    635613  if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
  • hvcontrol/src/ProcessIO.h

    r229 r230  
    2626#define MAX_RATE 50.0
    2727
    28 enum MsgTarget {Console=1, Log=2, All=7};
    2928typedef enum stateenum {active, stopped, na} state_enum;
    3029
     
    4746
    4847        // Configuration data
    49         std::string fPixMapTable;
    5048        float fTimeOut;
    5149        float fStatusRefreshRate;
     
    6967        ~ProcessIO();
    7068
    71         void PrintMessage(MsgTarget, const char *, ...);
    7269        void PrintMessage(const char *, ...);
    73         void DoPrintMessage(const char *, va_list, MsgTarget);
    7470        void CommandControl(char*);
    7571        bool RampVoltage(unsigned int, int, int, int);
Note: See TracChangeset for help on using the changeset viewer.