Changeset 80


Ignore:
Timestamp:
07/01/09 20:47:49 (15 years ago)
Author:
lstark
Message:
feedback through socket and test mode implemented
Location:
hvcontrol
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/HV.conf

    r75 r80  
    66PixMapTable        ../config/PixelMap.txt
    77
    8 TimeOut            0.10 s   # Timeout to return from read (0.01,...5.00) s
     8TestMode           TRUE       #Test Mode: if no HV boards are connected, the test mode can be used.TimeOut            1.00 s   # Timeout to return from read (0.01,...5.00) s
    99
    1010StatusRefreshRate  50.00 Hz   # Status update rate (0.01,...50.00) Hz
  • hvcontrol/src/CCCommand.cc

    r39 r80  
    8686      m->status->Pc = comline;     
    8787                 
    88 
    8988      ParseInput(m->status->Pc,&(m->status->NParam),m->status->Param);
    9089     
  • hvcontrol/src/HV.cc

    r35 r80  
    2626
    2727
    28 HV::HV(char** usbdevice, int* usbdevicenumber, FILE* f): fNumberOfBoards(0) {
    29  
     28HV::HV(char** usbdevice, int* usbdevicenumber, FILE* f,bool TestMode): fNumberOfBoards(0) {
     29 
     30  fTestMode = TestMode;
     31
    3032  int i = 0, j = 0, ret = 0;
    3133
     
    5052  i = 0;
    5153 
     54  if(fTestMode){
     55    fprintf(stdout,"Test mode: One HVBoard initialized as dummy.\n");
     56    fHVBoard[fNumberOfBoards] = new HVBoard("dummy", 0, &ftdic[fNumberOfBoards],fTestMode);
     57    fNumberOfBoards++;
     58    return;
     59  }
    5260  // Obtain information on FTDI devices
    5361  for (curdev = devlist; (curdev != NULL && i<MAX_NUM_HVBOARDS); i++) {
     
    8896        ftdi_set_latency_timer(&ftdic[fNumberOfBoards], USB_LATENCY_TIMER);
    8997       
    90         fHVBoard[fNumberOfBoards] = new HVBoard(serial, usbdevicenumber[j], &ftdic[fNumberOfBoards]);
     98        fHVBoard[fNumberOfBoards] = new HVBoard(serial, usbdevicenumber[j], &ftdic[fNumberOfBoards],fTestMode);
    9199        fNumberOfBoards++;
    92100        /*
     
    113121
    114122
    115 /* Bubble-sort HV boards according to board number */
     123// Bubble-sort HV boards according to board number
    116124void HV::ArrangeHVBoards(HVBoard** fHVBoard, int size) {
     125
     126  if(fTestMode){
     127    return;
     128  }
    117129
    118130  HVBoard* tmp;
     
    130142
    131143HV::~HV() {
     144
     145  if(fTestMode){
     146    fprintf(stdout,"Test mode: No FTDI device has to be closed.\n");
     147    return;
     148  }
    132149 
    133150  int i, ret = 0;
     
    157174
    158175
    159 HVBoard::HVBoard(char* serial, int number, struct ftdi_context* ftdic) : fTimeOut(.5)
     176HVBoard::HVBoard(char* serial, int number, struct ftdi_context* ftdic,bool TestMode) : fTimeOut(.5)
    160177{
    161178 
     179  fTestMode = TestMode;
     180  fTestModeWrap = 0;
    162181  FTDI_C = ftdic;
    163182  sprintf(Serial,"%s",serial);
     
    209228
    210229int HVBoard::Write(unsigned char* data, int size) {
     230  if (fTestMode)
     231    return 3;  // implying that 3 bytes are written
     232
    211233#ifdef DO_CAST
    212234  return ftdi_write_data(FTDI_C, (char*)data, size);
     
    217239
    218240int HVBoard::Read(unsigned char* data, int size) {
     241  if (fTestMode) {
     242    data[0] = fTestModeWrap;
     243    //    fprintf(stdout," Read Data 0X%.2X\n",data[0]);
     244    fTestModeWrap++;
     245    fTestModeWrap = fTestModeWrap%8;
     246    return 1;  // one byte read
     247  }
    219248#ifdef DO_CAST
    220249  return ftdi_read_data(FTDI_C, (char*)data, size);
     
    233262*/
    234263int HVBoard::TRead(FILE* fptr, unsigned char* rbuf, bool verbose) {
    235  
     264
     265  if (fTestMode) {
     266    Read(rbuf,BUFFER_LENGTH);
     267    return 1;  // rbuf read
     268  }
     269
    236270  char str[STR_LENGTH];
    237271
     
    278312int HVBoard::Reset(FILE* fptr, unsigned char* rbuf, bool verbose) {
    279313
     314  if (fTestMode)
     315    return 1;
     316
    280317  char str[STR_LENGTH];
    281318
     
    303340/* Read status register - uses TRead() and has same return values */
    304341int HVBoard::GetStatus(FILE* fptr, unsigned char* rbuf, bool verbose) {
     342  if (fTestMode){
     343    //    printf("Test mode. (Get Status) \n");
     344    return TRead(fptr,rbuf,verbose);
     345    return 1;
     346  }
    305347
    306348  char str[STR_LENGTH];
     
    330372/* Set high voltage - uses TRead() and has same return values */
    331373int HVBoard::SetHV(FILE* fptr, int chain, unsigned int channel, unsigned int hv, unsigned char* rbuf, bool verbose) {
     374
     375  if (fTestMode){
     376    printf("Test mode: Nothing to be done. \n");
     377    return 1;
     378  }
     379
    332380 
    333381  char str[STR_LENGTH];
     
    380428/* Set reference voltage - uses TRead() and has same return values */
    381429int HVBoard::SetVRef(FILE* fptr, int chain, unsigned int vref, unsigned char* rbuf, bool verbose) {
    382  
     430
     431    if (fTestMode){
     432    printf("Test mode. Nothing to be done.\n");
     433    return 1;
     434  }
     435
    383436  char str[STR_LENGTH];
    384437
     
    463516*/
    464517int HVBoard::Init(bool verbose) {
     518
    465519
    466520  unsigned char wbuf = REG_STATUS;
  • hvcontrol/src/HV.h

    r14 r80  
     1#ifndef HV_H_SEEN
     2#define HV_H_SEEN
    13
    24#include "Types.h"
     
    1416#endif
    1517#endif
    16 
    17 
    18 #ifndef HV_H_SEEN
    19 #define HV_H_SEEN
    2018
    2119
     
    6260 public:
    6361 
    64   HVBoard(char* serial, int number, struct ftdi_context* ftdic);
     62  HVBoard(char* serial, int number, struct ftdi_context* ftdic, bool TestMode);
    6563  ~HVBoard();
     64
     65  bool fTestMode;
    6666
    6767  int Init(bool verbose);
     
    8787  int  BoardNumber;
    8888  float fTimeOut;      // [s] timeout to return from read
     89  int fTestModeWrap;
    8990 
    9091};
     
    9697 public:
    9798 
    98   HV(char** usbdevice, int* usbdevicenumber, FILE* f);
     99  HV(char** usbdevice, int* usbdevicenumber, FILE* f,bool TestMode);
    99100  ~HV();
    100101
    101102  int fNumberOfBoards;
    102103  int fMaxNumberOfBoards;
     104
     105  bool fTestMode;
    103106
    104107  HVBoard* fHVBoard[MAX_NUM_HVBOARDS];
  • hvcontrol/src/HVConfig.cc

    r46 r80  
    3333  }
    3434
     35  TestMode           = false;
    3536  NumHVBoards        = 0;
    3637  FileName           = configfile;
     
    8182  }
    8283 
    83   ReadCard("LogPath",    fLogPath,'s',f);
     84  ReadCard("LogPath",    fLogPath,    's',f);
    8485
    8586  ReadCard("PixMapTable",fPixMapTable,'s',f);
     87
     88  ReadCard("TestMode",   &str,        's',f);
     89  if (!strcmp(str,"TRUE"))
     90    TestMode = true;
     91
    8692
    8793  for (int i=0;i<MAX_NUM_HVBOARDS;i++) {
     
    124130  fprintf(fptr," Log path:          %s\n\n", fLogPath);
    125131  fprintf(fptr," Pixel map table:   %s\n\n", fPixMapTable);
     132  fprintf(fptr," Test mode:         %s\n\n", TestMode ? "yes" : "no");
    126133  fprintf(fptr," %.2d USB devices:\n\n", NumHVBoards);
    127134 
     
    178185  fprintf(f,"PixMapTable        %s\n\n",   fPixMapTable);
    179186
     187  fprintf(f,"TestMode           %s       #Test Mode: if no HV boards are connected, the test mode can be used.",((TestMode) ? "TRUE" : "FALSE"));
     188
    180189  fprintf(f,"TimeOut            %.2f s   # Timeout to return from read (%.2f,...%.2f) s\n\n",fTimeOut,MIN_TIMEOUT,MAX_TIMEOUT);
    181190
  • hvcontrol/src/HVConfig.h

    r46 r80  
    2626  char *fCCClient;
    2727
     28  bool TestMode;
     29
    2830  bool IsDAC;
    2931  float Coef[MAX_NUM_HVBOARDS][MAX_NUM_CHAINS][2];
  • hvcontrol/src/HVStatus.cc

    r39 r80  
    163163          status->WC[1][i]);
    164164 
    165   if (status->Socket != -1) // Print status string to socket if open
    166     write(status->Socket,str,strlen(str)+1);
     165  //  if (status->Socket != -1) // Print status string to socket if open
     166  //    write(status->Socket,str,strlen(str)+1);
    167167
    168168}
  • hvcontrol/src/ProcessIO.cc

    r72 r80  
    2424  calib  = new HVCalib(config);
    2525  log     = new Log(config->fLogPath);
    26   hv      = new HV(config->fUSBDevice,config->USBDeviceNumber,stdout);
     26  hv      = new HV(config->fUSBDevice,config->USBDeviceNumber,stdout,config->TestMode);
    2727 
    2828  pm = new PixelMap(config->fPixMapTable);
     
    7575  pthread_mutex_init (&control_mutex, NULL);
    7676  pthread_cond_init  (&control_cond,  NULL);
    77    
     77 
     78  sprintf(str,"**************** End of constructor ProcessIO ************\n");
     79  DoPrompt(str);
     80 
    7881}
    7982
     
    150153      // Wrong type of argument
    151154      else if (!IsNoDigit(status->Param[1]) || !IsNoDigit(status->Param[2]) || status->Param[3][0] || !status->Param[1][0]) {
    152         sprintf(str,"usage: <board> <i>|<i> <j>|<all>\n");
     155        sprintf(str,"ERROR - usage: <board> <i>|<i> <j>|<all>\n");
    153156        DoPrompt(str); 
    154157        return 0;
     
    158161
    159162        if (!IsBoard(atoi(status->Param[1]))) {
    160           sprintf(str,"board #%d does not exist\n", atoi(status->Param[1]));
     163          sprintf(str,"ERROR -board #%d does not exist\n", atoi(status->Param[1]));
    161164          DoPrompt(str);
    162165          return 0;
     
    165168        if (status->Param[2][0])
    166169          if (!IsBoard(atoi(status->Param[2]))) {
    167             sprintf(str,"board #%d does not exist\n", atoi(status->Param[2]));
     170            sprintf(str,"ERROR -board #%d does not exist\n", atoi(status->Param[2]));
    168171            DoPrompt(str);
    169172            return 0;
     
    206209      }
    207210      else if (!IsNoDigit(status->Param[1]) || !status->Param[1][0]) {
    208         sprintf(str,"usage: <chain> <i>|<i> <j>|<all>\n");
     211        sprintf(str,"ERROR -usage: <chain> <i>|<i> <j>|<all>\n");
    209212        DoPrompt(str); 
    210213        return 0;
     
    226229       
    227230        if (atoi(status->Param[1]) < 0 || atoi(status->Param[1]) > 3) {
    228           sprintf(str,"chain #%d does not exist\n", atoi(status->Param[1]));
     231          sprintf(str,"ERROR -chain #%d does not exist\n", atoi(status->Param[1]));
    229232          DoPrompt(str);
    230233        }
     
    232235       
    233236        if ((atoi(status->Param[2]) < 0 || atoi(status->Param[2]) > 3) && (atoi(status->Param[1]) != atoi(status->Param[2]))) {
    234           sprintf(str,"chain #%d does not exist\n", atoi(status->Param[2]));
     237          sprintf(str,"ERROR -chain #%d does not exist\n", atoi(status->Param[2]));
    235238          DoPrompt(str);
    236239        }
     
    297300        allchannels = TRUE;
    298301      else {
    299         DoPrompt("error: wrong input format - usage: hv <channel>|<all> <voltage>\n");
     302        DoPrompt("ERROR - wrong input format - usage: hv <channel>|<all> <voltage>\n");
    300303        return 0;
    301304      }
     
    304307      if (tolower(status->Param[2][0])=='x' && strlen(status->Param[2])>2) {
    305308        if (sPrintHex2Dec(Chop(status->Param[2]+1),&hvoltage)!=0) {
    306           DoPrompt("error: wrong input format - usage: hv <channel>|<all> <voltage>\n");
     309          DoPrompt("ERROR - wrong input format - usage: hv <channel>|<all> <voltage>\n");
    307310          return 0;
    308311        }
     
    311314      else if (tolower(status->Param[2][0])=='b' && strlen(status->Param[2])>2) {
    312315        if (sPrintBin2Dec(Chop(status->Param[2]+1),&hvoltage)!=0) {
    313           DoPrompt("wrong input format - usage: hv <channel>|<all> <voltage>\n");
     316          DoPrompt("ERROR - wrong input format - usage: hv <channel>|<all> <voltage>\n");
    314317          return 0;
    315318        }
     
    322325      // Wrong input format
    323326      else {
    324         DoPrompt("wrong input format - usage: hv <channel>|<all> <voltage>\n");
     327        DoPrompt("ERROR - wrong input format - usage: hv <channel>|<all> <voltage>\n");
    325328        return 0;
    326329      }
     
    328331      // Check limits
    329332      if (channel>31 || channel <0) {
    330         DoPrompt("channel out of range (0...31)!\n");
     333        DoPrompt("ERROR - channel out of range (0...31)!\n");
    331334        return 0;
    332335      }
    333336      else if ((hvoltage>0X3FFF || hvoltage <0)&&config->IsDAC) {
    334         DoPrompt("high voltage out of range (Vmin: 0, Vmax: 16383)!\n");
     337        DoPrompt("ERROR - high voltage out of range (Vmin: 0, Vmax: 16383)!\n");
    335338        return 0;
    336339      }
    337340      else if ((hvoltage>78.0 || hvoltage <0)&&(!(config->IsDAC))) {
    338         DoPrompt("high voltage out of range (Vmin: 0, Vmax: 78.)!\n");
     341        DoPrompt("ERROR - high voltage out of range (Vmin: 0, Vmax: 78.)!\n");
    339342        return 0;
    340343      }
     
    365368                UpdateStatus(i,rbuf);
    366369               
    367                 sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",hv->GetHVBoard(i)->GetBoardNumber(),j,channel,hvoltage,hvoltage,calib->DACToHV(hvoltage,hv->GetHVBoard(i)->GetBoardNumber(),j,channel));
     370                sprintf(str,"OK - board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",hv->GetHVBoard(i)->GetBoardNumber(),j,channel,hvoltage,hvoltage,calib->DACToHV(hvoltage,hv->GetHVBoard(i)->GetBoardNumber(),j,channel));
    368371                //              DoPrompt(str);
    369372                if (status->Verbose) {
     
    374377              }
    375378              else {
    376                 sprintf(str,"board %d error: could not set hv - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
     379                sprintf(str,"ERROR - board %d error: could not set hv - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
    377380                DoPrompt(str);
    378381                errors++;
     
    381384          }
    382385          else {
    383             sprintf(str,"updating board %d chain %d\n",hv->GetHVBoard(i)->GetBoardNumber(),j);
     386            sprintf(str,"OK - updating board %d chain %d\n",hv->GetHVBoard(i)->GetBoardNumber(),j);
    384387            DoPrompt(str);
    385388         
     
    404407                 
    405408                  if (status->Verbose) {
    406                     sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",hv->GetHVBoard(i)->GetBoardNumber(),j,channel,hvoltage,hvoltage,calib->DACToHV(hvoltage,hv->GetHVBoard(i)->GetBoardNumber(),j,channel));
     409                    sprintf(str,"OK - board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",hv->GetHVBoard(i)->GetBoardNumber(),j,channel,hvoltage,hvoltage,calib->DACToHV(hvoltage,hv->GetHVBoard(i)->GetBoardNumber(),j,channel));
    407410                    //sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X\n",hv->GetHVBoard(i)->GetBoardNumber(),j,k,hvoltage,hvoltage);
    408411                    //   DoPrompt(str);
     
    414417               
    415418                else {
    416                   sprintf(str,"board %d error: could not set HV - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
     419                  sprintf(str,"ERROR - board %d error: could not set HV - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
    417420                  DoPrompt(str);
    418421                  errors++;
     
    429432
    430433      if (errors) {
    431         sprintf(str,"warning %d error(s) => check timeout and try again\n",errors);
     434        sprintf(str,"ERROR - warning %d error(s) => check timeout and try again\n",errors);
    432435        DoPrompt(str);
    433436      }
    434437      else {
    435         sprintf(str,"no error(s)... success!\n");
     438        sprintf(str,"OK - no error(s)... success!\n");
    436439        DoPrompt(str);
    437440      }
     
    439442    }
    440443    else {
    441       sprintf(str,"usage: hv <channel>|<all> <voltage>\n");
     444      sprintf(str,"ERROR - usage: hv <channel>|<all> <voltage>\n");
    442445      DoPrompt(str);
    443446    }
     
    481484      if (tolower(status->Param[2][0])=='x' && strlen(status->Param[2])>2) {
    482485        if (sPrintHex2Dec(Chop(status->Param[2]+1),(unsigned int *)hvdiff)!=0) {
    483           DoPrompt("error: wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n");
     486          DoPrompt("ERROR - wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n");
    484487          return 0;
    485488        }
     
    488491      else if (tolower(status->Param[2][0])=='b' && strlen(status->Param[2])>2) {
    489492        if (sPrintBin2Dec(Chop(status->Param[2]+1),(unsigned int *)hvdiff)!=0) {
    490           DoPrompt("wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n");
     493          DoPrompt("ERROR - wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n");
    491494          return 0;
    492495        }
     
    499502      // Wrong input format
    500503      else {
    501         DoPrompt("wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n");
     504        DoPrompt("ERROR - wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n");
    502505        return 0;
    503506      }
    504507      // Check limits
    505508      if (channel>31 || channel <0) {
    506         DoPrompt("channel out of range (0...31)!\n");
     509        sprintf(str,"ERROR - channel out of range (0...31)!\n");
     510        DoPrompt(str);
    507511        return 0;
    508512      }
    509513      else if (hvdiff>config->DACMax || hvdiff <(-(config->DACMax))) {
    510         sprintf(str,"difference of high voltage [hvdiff:%d] out of range (Vmin: 0.0, Vmax: %d)!\n", hvdiff,config->DACMax);
     514        sprintf(str,"ERROR - difference of high voltage [hvdiff:%d] out of range (Vmin: 0.0, Vmax: %d)!\n", hvdiff,config->DACMax);
    511515        DoPrompt(str);
    512516        return 0;
    513517      }
    514518      else if (hvdiffV>(calib->DACToHV(config->DACMax,0,0,0))|| hvdiffV<-(calib->DACToHV(config->DACMax,0,0,0))) {
    515         sprintf(str,"difference of high voltage [hvdiff:%f] out of range (Vmin: 0.0, Vmax: %f)!\n",hvdiffV,calib->DACToHV(config->DACMax,0,0,0));
    516         DoPrompt(str);
    517         return 0;
    518       }
    519 
    520       sprintf(str,"Error - Test \n");
    521       DoPrompt(str);
    522       if (status->Socket != -1) // Print status string to socket if open
    523         write(status->Socket,str,strlen(str)+1);
    524       sPrintStatus(status,str,0); // Print status only to socket
    525      
    526 
     519        sprintf(str,"ERROR - difference of high voltage [hvdiff:%f] out of range (Vmin: 0.0, Vmax: %f)!\n",hvdiffV,calib->DACToHV(config->DACMax,0,0,0));
     520        DoPrompt(str);
     521        return 0;
     522      }
     523     
    527524
    528525
     
    556553          UpdateStatus(board,rbuf);
    557554          if (k==(abs((int)(hvdiff/config->fHVMaxDiff)))){
    558             sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",hv->GetHVBoard(board)->GetBoardNumber(),chain,channel,hvoltage,hvoltage,calib->DACToHV(hvoltage,hv->GetHVBoard(board)->GetBoardNumber(),chain,channel));
     555            sprintf(str,"OK - board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",hv->GetHVBoard(board)->GetBoardNumber(),chain,channel,hvoltage,hvoltage,calib->DACToHV(hvoltage,hv->GetHVBoard(board)->GetBoardNumber(),chain,channel));
    559556            //sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X\n",hv->GetHVBoard(board)->GetBoardNumber(),chain,channel,hvoltage,hvoltage);
    560557            DoPrompt(str);
     
    563560        }
    564561        else {
    565           sprintf(str,"board %d chain %d channel %d error: could not set hv - check timeout and try again\n",hv->GetHVBoard(board)->GetBoardNumber(), chain, channel);
     562          sprintf(str,"ERROR - board %d chain %d channel %d error: could not set hv - check timeout and try again\n",hv->GetHVBoard(board)->GetBoardNumber(), chain, channel);
    566563          DoPrompt(str);
    567564          errors++;
     
    577574
    578575      if (errors) {
    579         sprintf(str,"warning %d error(s)\n",errors);
     576        sprintf(str,"ERROR - warning %d error(s)\n",errors);
    580577        DoPrompt(str);
    581578      }
    582579      else {
    583         sprintf(str,"no error(s)... success!\n");
     580        sprintf(str,"OK - no error(s)... success!\n");
    584581        DoPrompt(str);
    585582      }
    586583    }
    587584    else {
    588       sprintf(str,"usage: hvdiff <PXL id> <hv difference>\n");
     585      sprintf(str,"ERROR - usage: hvdiff <PXL id> <hv difference>\n");
    589586      DoPrompt(str);
    590587    }
     
    600597  else if (Match(status->Param[0], "list")) {
    601598   
    602     sprintf(str,"%d HV board(s) active:\n",hv->GetNumberOfBoards());
     599    sprintf(str,"OK - %d HV board(s) active:\n",hv->GetNumberOfBoards());
    603600    DoPrompt(str);
    604601
    605602    for (int i=0;i<hv->GetNumberOfBoards();i++) {
    606       sprintf(str,"board %d (%s)\n",(hv->GetHVBoard(i))->GetBoardNumber(),(hv->GetHVBoard(i))->GetSerial());
     603      sprintf(str,"OK - board %d (%s)\n",(hv->GetHVBoard(i))->GetBoardNumber(),(hv->GetHVBoard(i))->GetSerial());
    607604      DoPrompt(str);
    608605    }
     
    634631       
    635632        if (status->Verbose) {
    636           sprintf(str,"file \"%s\" opened\n",Chop(status->Param[1]));
     633          sprintf(str,"OK - file \"%s\" opened\n",Chop(status->Param[1]));
    637634          DoPrompt(str);
    638635        }
     
    651648                board = j;
    652649               
    653                 sprintf(str,"found HV settings for board %d (%s)\n",hv->GetHVBoard(board)->GetBoardNumber(),Chop(param[1]));
     650                sprintf(str,"OK - found HV settings for board %d (%s)\n",hv->GetHVBoard(board)->GetBoardNumber(),Chop(param[1]));
    654651                DoPrompt(str);
    655652               
     
    666663
    667664                    if (!((nrows)%4)) {
    668                       sprintf(str,"updating board %d chain %d\n",hv->GetHVBoard(board)->GetBoardNumber(),chain);
     665                      sprintf(str,"OK - updating board %d chain %d\n",hv->GetHVBoard(board)->GetBoardNumber(),chain);
    669666                      DoPrompt(str);
    670667                    }
     
    683680                       
    684681                        if (status->Verbose) {
    685                           sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X\n",
     682                          sprintf(str,"OK - board %d: high voltage of chain %d channel %d set to %d | 0X%.4X\n",
    686683                                  hv->GetHVBoard(board)->GetBoardNumber(),chain,channel,hvoltage,hvoltage);
    687684                          DoPrompt(str);
     
    691688                      }
    692689                      else {
    693                         sprintf(str,"board %d error: could not set HV - check timeout and try again\n",hv->GetHVBoard(board)->GetBoardNumber());
     690                        sprintf(str,"ERROR - board %d error: could not set HV - check timeout and try again\n",hv->GetHVBoard(board)->GetBoardNumber());
    694691                        DoPrompt(str);
    695692                        errors++;
     
    709706       
    710707        if (fclose (file)) {
    711           sprintf(str,"error: could not close file \"%s\"\n",Chop(status->Param[1]));
     708          sprintf(str,"ERROR - could not close file \"%s\"\n",Chop(status->Param[1]));
    712709          DoPrompt(str);
    713710        }
    714711        else {
    715712          if (status->Verbose) {
    716             sprintf(str,"file \"%s\" closed\n",Chop(status->Param[1]));
     713            sprintf(str,"OK - file \"%s\" closed\n",Chop(status->Param[1]));
    717714            DoPrompt(str);
    718715          }
     
    720717
    721718        if (nboards!=hv->GetNumberOfBoards()) {
    722           sprintf(str,"warning: could not load HV settings for all connected HV boards\n");
     719          sprintf(str,"ERROR - warning: could not load HV settings for all connected HV boards\n");
    723720          DoPrompt(str);
    724721        }
    725722        else {
    726           sprintf(str,"success: read HV settings for all connected HV boards\n");
     723          sprintf(str,"OK - success: read HV settings for all connected HV boards\n");
    727724          DoPrompt(str);
    728725        }
    729726
    730727        if (errors) {
    731           sprintf(str,"warning %d error(s) => check timeout and try again\n",errors);
     728          sprintf(str,"ERROR - warning %d error(s) => check timeout and try again\n",errors);
    732729          DoPrompt(str);
    733730        }
    734731        else {
    735           sprintf(str,"no error(s)... success!\n");
     732          sprintf(str,"OK - no error(s)... success!\n");
    736733          DoPrompt(str);
    737734        }
     
    739736      }
    740737      else {
    741         sprintf(str,"error: could not open file \"%s\"\n",Chop(status->Param[1]));
     738        sprintf(str,"ERROR - could not open file \"%s\"\n",Chop(status->Param[1]));
    742739        DoPrompt(str);
    743740      }
     
    745742    }
    746743    else
    747       DoPrompt("usage: load <file>\n");
     744      DoPrompt("ERROR - usage: load <file>\n");
    748745
    749746    StartMonitor();
     
    759756    if (Match(status->Param[1], "on") && status->Param[1][0]) {
    760757      status->Log = TRUE;
    761       sprintf(str,"logging enabled\n");
     758      sprintf(str,"OK - logging enabled\n");
    762759      DoPrompt(str);
    763760    }
     
    765762    else if (Match(status->Param[1], "off") && status->Param[1][0]) {
    766763      status->Log = FALSE;
    767       sprintf(str,"logging disabled\n");
     764      sprintf(str,"OK -logging disabled\n");
    768765      DoPrompt(str);
    769766    }
    770767   
    771768    else
    772       DoPrompt("usage: log <on>|<off>\n");
     769      DoPrompt("ERROR - usage: log <on>|<off>\n");
    773770 
    774771    return 0;
     
    785782
    786783      if (!IsNoDigit(status->Param[1])) {
    787         DoPrompt("wrong input format - usage: rate <rate>\n");
     784        DoPrompt("ERROR - wrong input format - usage: rate <rate>\n");
    788785        return 0;
    789786      }
    790787      // Check limits
    791788      else if (atof(status->Param[1]) < MIN_RATE || atof(status->Param[1]) > MAX_RATE) {
    792         sprintf(str,"refresh rate out of range (min: %.2f Hz, max: %.2f Hz)!\n",MIN_RATE,MAX_RATE);
     789        sprintf(str,"ERROR - refresh rate out of range (min: %.2f Hz, max: %.2f Hz)!\n",MIN_RATE,MAX_RATE);
    793790        DoPrompt(str);
    794791        return 0;
     
    797794        StopMonitor();
    798795        status->fStatusRefreshRate=atof(status->Param[1]);
    799         sprintf(str,"status refresh rate set to %.2f Hz\n",status->fStatusRefreshRate);
     796        sprintf(str,"OK - status refresh rate set to %.2f Hz\n",status->fStatusRefreshRate);
    800797        DoPrompt(str);
    801798      }
     
    805802    }
    806803    else {
    807       sprintf(str,"usage: rate <rate>\n");
     804      sprintf(str,"ERROR - usage: rate <rate>\n");
    808805      DoPrompt(str);
    809806    }
     
    859856  else if (Match(status->Param[0], "root")) {
    860857   
    861     sprintf(str,"starting ROOT... type '.q' to return\n");
     858    sprintf(str,"OK - starting ROOT... type '.q' to return\n");
    862859    DoPrompt(str);
    863860    system ("root");
     
    874871     
    875872      if (SaveHVSettings(Chop(status->Param[1]))) {
    876         sprintf(str,"HV settings written to \"%s\"\n",Chop(status->Param[1]));
     873        sprintf(str,"OK - HV settings written to \"%s\"\n",Chop(status->Param[1]));
    877874        DoPrompt(str);
    878875      }
     
    889886      time_now = localtime(&time_now_secs);
    890887     
    891       sprintf(buffer,"hvsettings/HV_%04d-%02d-%02d_%02d-%02d-%02d.txt",
     888      sprintf(buffer,"OK - hvsettings/HV_%04d-%02d-%02d_%02d-%02d-%02d.txt",
    892889              1900 + time_now->tm_year,
    893890              1 + time_now->tm_mon,
     
    901898     
    902899      if (SaveHVSettings(buffer)) {
    903         sprintf(str,"HV settings successfully written to \"%s\"\n",buffer);
     900        sprintf(str,"OK - HV settings successfully written to \"%s\"\n",buffer);
    904901        DoPrompt(str);
    905902      }
     
    918915   
    919916    if (status->state==active) {
    920       sprintf(str,"status monitoring is already active\n");
     917      sprintf(str,"OK - status monitoring is already active\n");
    921918      DoPrompt(str);
    922919      return 0;
     
    925922    StartMonitor();
    926923
    927     sprintf(str,"status monitoring activated\n");
     924    sprintf(str,"OK - status monitoring activated\n");
    928925    DoPrompt(str);
    929926
     
    953950   
    954951    if (status->state!=active) {
    955       sprintf(str,"status monitoring is already deactivated\n");
     952      sprintf(str,"OK - status monitoring is already deactivated\n");
    956953      DoPrompt(str);
    957954      return 0;
     
    960957    StopMonitor();
    961958   
    962     sprintf(str,"warning: status monitoring deactivated\n");
     959    sprintf(str,"ERROR - warning: status monitoring deactivated\n");
    963960    DoPrompt(str);
    964961
     
    11371134
    11381135      if (!IsNoDigit(status->Param[1])) {
    1139         DoPrompt("wrong input format - usage: timeout <time>\n");
     1136        DoPrompt("ERROR - wrong input format - usage: timeout <time>\n");
    11401137        return 0;
    11411138      }
    11421139      // Check limits
    11431140      else if (atof(status->Param[1]) < MIN_TIMEOUT || atof(status->Param[1]) > MAX_TIMEOUT) {
    1144         sprintf(str,"timeout out of range (min: %.2f s, max: %.2f s)!\n",MIN_TIMEOUT,MAX_TIMEOUT);
     1141        sprintf(str,"ERROR -timeout out of range (min: %.2f s, max: %.2f s)!\n",MIN_TIMEOUT,MAX_TIMEOUT);
    11451142        DoPrompt(str);
    11461143        return 0;
     
    11511148          (hv->GetHVBoard(i))->SetTimeOut((float)atof(status->Param[1]));
    11521149        status->fTimeOut = atof(status->Param[1]);     
    1153         sprintf(str,"timeout set to %.2f s\n",status->fTimeOut);
     1150        sprintf(str,"OK - timeout set to %.2f s\n",status->fTimeOut);
    11541151
    11551152        DoPrompt(str);
     
    11601157    }
    11611158    else {
    1162       sprintf(str,"usage: timeout <time>\n");
     1159      sprintf(str,"ERROR - usage: timeout <time>\n");
    11631160      DoPrompt(str);
    11641161    }
     
    11731170    double difftime = GetDiffTime(&StartTime);
    11741171
    1175     sprintf(str,"%d:%02d:%02d\n",(int)difftime/SECONDS_HOUR,((int)difftime/SECONDS_MINUTE)%SECONDS_MINUTE,(int)difftime%SECONDS_MINUTE);
     1172    sprintf(str,"OK - %d:%02d:%02d\n",(int)difftime/SECONDS_HOUR,((int)difftime/SECONDS_MINUTE)%SECONDS_MINUTE,(int)difftime%SECONDS_MINUTE);
    11761173    DoPrompt(str);
    11771174
     
    11851182    if (Match(status->Param[1], "on") && status->Param[1][0]) {
    11861183      if (status->Verbose == TRUE) {
    1187         sprintf(str,"verbosity is already enabled\n");
     1184        sprintf(str,"OK - verbosity is already enabled\n");
    11881185        DoPrompt(str);
    11891186      }
    11901187      else {
    11911188        status->Verbose = TRUE;
    1192         sprintf(str,"verbosity enabled\n");
     1189        sprintf(str,"OK - verbosity enabled\n");
    11931190        DoPrompt(str);
    11941191      }
     
    11971194    else if (Match(status->Param[1], "off") && status->Param[1][0]) {
    11981195      if (status->Verbose == FALSE) {
    1199         sprintf(str,"verbosity is already disabled\n");
     1196        sprintf(str,"OK - verbosity is already disabled\n");
    12001197        DoPrompt(str);
    12011198      }
    12021199      else {
    12031200        status->Verbose = FALSE;
    1204         sprintf(str,"verbosity disabled\n");
     1201        sprintf(str,"OK - verbosity disabled\n");
    12051202        DoPrompt(str);
    12061203      }
     
    12081205   
    12091206    else
    1210       DoPrompt("usage: verbose <on>|<off>\n");
     1207      DoPrompt("ERROR - usage: verbose <on>|<off>\n");
    12111208 
    12121209    return 0;
     
    12271224      if (tolower(status->Param[1][0])=='x' && strlen(status->Param[1])>2) {
    12281225        if (sPrintHex2Dec(Chop(status->Param[1]+1),&voltage)!=0) {
    1229             DoPrompt("error: wrong input format - usage: vref <voltage>\n");
     1226            DoPrompt("ERROR - wrong input format - usage: vref <voltage>\n");
    12301227            return 0;
    12311228        }
     
    12341231      else if (tolower(status->Param[1][0])=='b' && strlen(status->Param[1])>2) {
    12351232        if (sPrintBin2Dec(Chop(status->Param[1]+1),&voltage)!=0) {
    1236           DoPrompt("wrong input format - usage: vref <voltage>\n");
     1233          DoPrompt("ERROR - wrong input format - usage: vref <voltage>\n");
    12371234          return 0;
    12381235        }
     
    12431240      // Wrong input format
    12441241      else {
    1245         DoPrompt("wrong input format - usage: vref <voltage>\n");
     1242        DoPrompt("ERROR - wrong input format - usage: vref <voltage>\n");
    12461243        return 0;
    12471244      }
     
    12491246      // Check limits
    12501247      if (voltage>0X3FFF || voltage <0) {
    1251         DoPrompt("reference voltage out of range (Vmin: 0, Vmax: 16383)!\n");
     1248        DoPrompt("ERROR - reference voltage out of range (Vmin: 0, Vmax: 16383)!\n");
    12521249        return 0;
    12531250      }
     
    12591256        for (int j=status->FirstChain;j<=status->LastChain;j++) {
    12601257          if (((hv->GetHVBoard(i))->SetVRef(stdout,j,voltage,rbuf,status->Verbose)==1)) {
    1261             sprintf(str,"board %d: reference voltage of chain %d set to %d | 0X%.4X\n",hv->GetHVBoard(i)->GetBoardNumber(),j,voltage,voltage);
     1258            sprintf(str,"OK - board %d: reference voltage of chain %d set to %d | 0X%.4X\n",hv->GetHVBoard(i)->GetBoardNumber(),j,voltage,voltage);
    12621259            status->VRef[i][j]=voltage;
    12631260            DoPrompt(str);
     
    12661263            DoPrompt(str);
    12671264          } else {
    1268             sprintf(str,"board %d error: could not set vref - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
     1265            sprintf(str,"ERROR - board %d error: could not set vref - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
    12691266            DoPrompt(str);
    12701267          }
     
    12741271    }
    12751272    else {
    1276       sprintf(str,"usage: vref <voltage>\n");
     1273      sprintf(str,"ERROR - usage: vref <voltage>\n");
    12771274      DoPrompt(str);
    12781275    }
     
    13611358   
    13621359    if (strchr(status->Param[0],'\n') == 0)
    1363       sprintf(str,"unknown command: %s\n",status->Param[0]);
     1360      sprintf(str,"ERROR - unknown command: %s\n",status->Param[0]);
    13641361    else
    1365       sprintf(str,"unknown command: %s",status->Param[0]);
     1362      sprintf(str,"ERROR - unknown command: %s",status->Param[0]);
    13661363   
    13671364    DoPrompt(str);
     
    13851382  timeinfo = localtime(&rawtime); // Get local time
    13861383  fflush(stdout);
    1387   sprintf(str,"current date/time is: %s",asctime(timeinfo));
     1384  sprintf(str,"OK - current date/time is: %s",asctime(timeinfo));
    13881385  DoPrompt(str);
    13891386
     
    13911388
    13921389void ProcessIO::DoPrompt(char* str) {
    1393  
     1390  if (str!=NULL) {
     1391    if (status->Socket != -1) // Print status string to socket if open
     1392      write(status->Socket,str,strlen(str)+1);
     1393  }
     1394  else {
     1395    if (status->Socket != -1) // Print status string to socket if open
     1396      write(status->Socket,"OK\n",3);
     1397  }
    13941398  if (str!=NULL) {
    13951399    if (status->NumHVBoards == 0) {
     
    14701474     }
    14711475  }
    1472 
    1473  
    14741476}
    14751477
     
    15921594
    15931595  if (status->NumHVBoards==0)
    1594     DoPrompt("no HV boards available!\n");
     1596    DoPrompt("ERROR - no HV boards available!\n");
    15951597
    15961598  return status->NumHVBoards;
     
    16031605
    16041606  if (hv->GetNumberOfBoards())
    1605     printf("Initialization:\n");
     1607    printf("OK - Initialization:\n");
    16061608
    16071609  for (int i=0;i<hv->GetNumberOfBoards();i++) {
    1608     printf(" HV board %d (%s):\n",hv->GetHVBoard(i)->GetBoardNumber(),hv->GetHVBoard(i)->GetSerial());
     1610    printf("OK - HV board %d (%s):\n",hv->GetHVBoard(i)->GetBoardNumber(),hv->GetHVBoard(i)->GetSerial());
    16091611    nb+=hv->GetHVBoard(i)->Init(status->Verbose);
    16101612  }
     
    16621664
    16631665    if ((hv->GetHVBoard(i))->GetStatus(stdout,rbuf,FALSE)!=1) {
    1664       sprintf(str,"board %d error: could not read status - check timeout and status refresh rate...",hv->GetHVBoard(i)->GetBoardNumber());
     1666      sprintf(str,"ERROR - board %d error: could not read status - check timeout and status refresh rate...",hv->GetHVBoard(i)->GetBoardNumber());
    16651667      PrintMessage(str);     
    16661668    }
     
    16691671   
    16701672    if (status->MR[i]) {
    1671       sprintf(str,"warning: manual reset of board %d!",hv->GetHVBoard(i)->GetBoardNumber());
     1673      sprintf(str,"ERROR - warning: manual reset of board %d!",hv->GetHVBoard(i)->GetBoardNumber());
    16721674      PrintMessage(str);     
    16731675      StopMonitor();
     
    16781680   
    16791681    if (!status->isok[i]) {
    1680       sprintf(str,"error: wrap counter mismatch board %d (%d,%d)!",hv->GetHVBoard(i)->GetBoardNumber(),status->WC[0][i],status->WC[1][i]);
     1682      sprintf(str,"ERROR - wrap counter mismatch board %d (%d,%d)!",hv->GetHVBoard(i)->GetBoardNumber(),status->WC[0][i],status->WC[1][i]);
    16811683      PrintMessage(str);     
    16821684    }
     
    16841686    for (int j=0;j<MAX_NUM_CHAINS;j++)
    16851687      if (status->OC[i][j]) {
    1686         sprintf(str,"warning: overcurrent in chain %d of board %d!",j,hv->GetHVBoard(i)->GetBoardNumber());
     1688        sprintf(str,"ERROR - warning: overcurrent in chain %d of board %d!",j,hv->GetHVBoard(i)->GetBoardNumber());
    16871689        PrintMessage(str);     
    16881690        ResetBoard(i);
     
    16971699  for (int i=status->FirstBoard;i<=status->LastBoard;i++) {
    16981700    if ((hv->GetHVBoard(i))->Reset(stdout,rbuf,status->Verbose)==1) {
    1699       sprintf(str,"software reset done board %d\n",hv->GetHVBoard(i)->GetBoardNumber());
     1701      sprintf(str,"OK - software reset done board %d\n",hv->GetHVBoard(i)->GetBoardNumber());
    17001702      DoPrompt(str);
    17011703      UpdateStatus(i,rbuf);
     
    17041706    }
    17051707    else {
    1706       sprintf(str,"board %d error: could not reset - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
     1708      sprintf(str,"ERROR - board %d error: could not reset - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
    17071709        DoPrompt(str);
    17081710    }   
     
    17161718  for (int i=0;i<hv->GetNumberOfBoards();i++) {
    17171719    if ((hv->GetHVBoard(i))->Reset(stdout,rbuf,status->Verbose)==1) {
    1718       sprintf(str,"software reset done board %d\n",hv->GetHVBoard(i)->GetBoardNumber());
     1720      sprintf(str,"OK - software reset done board %d\n",hv->GetHVBoard(i)->GetBoardNumber());
    17191721      DoPrompt(str);
    17201722      UpdateStatus(i,rbuf);
     
    17231725    }
    17241726    else {
    1725       sprintf(str,"board %d error: could not reset - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
     1727      sprintf(str,"ERROR - board %d error: could not reset - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber());
    17261728      DoPrompt(str);
    17271729    }   
     
    17341736   
    17351737  if ((hv->GetHVBoard(i))->Reset(stdout,rbuf,status->Verbose)==1) {
    1736     sprintf(str,"software reset done board %d",hv->GetHVBoard(i)->GetBoardNumber());
     1738    sprintf(str,"OK - software reset done board %d",hv->GetHVBoard(i)->GetBoardNumber());
    17371739    PrintMessage(str);
    17381740    UpdateStatus(i,rbuf);
     
    17411743  }
    17421744  else {
    1743     sprintf(str,"board %d error: could not reset - check timeout and try again",hv->GetHVBoard(i)->GetBoardNumber());
     1745    sprintf(str,"ERROR - board %d error: could not reset - check timeout and try again",hv->GetHVBoard(i)->GetBoardNumber());
    17441746    PrintMessage(str);
    17451747  }   
     
    17611763
    17621764  if ((fptr = fopen(filename,"w")) == NULL) {
    1763     sprintf(str,"error: could not open file \"%s\"\n", filename);
     1765    sprintf(str,"ERROR - could not open file \"%s\"\n", filename);
    17641766    return 0;
    17651767  }
Note: See TracChangeset for help on using the changeset viewer.