Changeset 10052


Ignore:
Timestamp:
11/17/10 15:30:16 (14 years ago)
Author:
ogrimm
Message:
Added bulk command transfer
Location:
fact/BIASctrl
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • fact/BIASctrl/BIASctrl.cc

    r10049 r10052  
    7272 
    7373  // Install signal handler and set signal SIGUSR1 to interrupt blocking system calls
    74   signal(SIGUSR1, &DummyHandler);
    75   siginterrupt (SIGUSR1, true);
     74  //signal(SIGUSR1, &DummyHandler);
     75  //siginterrupt (SIGUSR1, true);
    7676
    7777  // Assure lock file is deleted in case of a program crash or call to exit()
  • fact/BIASctrl/Crate.cc

    r10049 r10052  
    1919  // Initialize
    2020  InitOK = false;
     21  File = NULL;
    2122  m = PIO;
    2223  Name = new char [CrateName.size()+1];
     
    5051    return;
    5152  }
     53 
     54  // Generate FILE pointer
     55  if ((File = fdopen(fDescriptor, "rb+")) == NULL) {
     56    m->PrintMessage("Error: fdopen() failed on device %d/%s (%s)\n", CrateNumber, Name, strerror(errno));
     57    return;
     58  }
    5259
    5360  // Get current serial port settings
     
    7784
    7885  if(fDescriptor != -1) {
     86    GlobalSet(0);
     87
    7988    SystemReset();
    80     if (close(fDescriptor) == -1) m->PrintMessage("Error closing device %s (%s)\n", Name, strerror(errno));;
     89    if (File == NULL) {
     90          if (close(fDescriptor) == -1) m->PrintMessage("Error closing device %s (%s)\n", Name, strerror(errno));
     91        }
     92    else if (fclose(File) != 0) m->PrintMessage("Error closing device %s\n", Name);
    8193  }
    8294
     
    90102//
    91103// Returns: 0 error, 1 success, -1 time-out exceeded
    92 int Crate::Communicate(unsigned char* wbuf, int Bytes) {
    93 
    94   int N, Ret = 0;
     104vector<char> Crate::Communicate(unsigned char* wbuf, int Bytes) {
     105
     106  int N;
    95107  fd_set SelectDescriptor;
    96108  struct timeval WaitTime = {(long) m->fTimeOut, (long) ((m->fTimeOut-(long) m->fTimeOut)*1e6)};
    97  
    98   // === Lock file descriptor ===
    99   if (lockf(fDescriptor, F_LOCK, 0) == -1) {
    100         m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno));
    101         return 0;
    102   }
    103 
     109  char Buffer[10000];
     110  vector<char> Data;
     111 
     112  // === Lock device ===
     113  flockfile(File);
     114 
    104115  // === Write data ===
    105116  if ((N = write(fDescriptor, wbuf, Bytes)) < Bytes) {
     
    110121  }
    111122
    112   // === Try to read until time-out ===
    113   FD_ZERO(&SelectDescriptor);   FD_SET(fDescriptor, &SelectDescriptor);
    114   if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
    115     m->Message(m->ERROR, "Error with select() (%s)", strerror(errno));
     123  // === Try to read back data with time-out ===
     124  do {
     125        FD_ZERO(&SelectDescriptor);   FD_SET(fDescriptor, &SelectDescriptor);
     126        if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) {
     127      m->Message(m->ERROR, "Error with select() (%s)", strerror(errno));
     128          goto ExitCommunicate;
     129        }
     130
     131        // Time-out expired?
     132        if (!FD_ISSET(fDescriptor, &SelectDescriptor)) {
     133          Data.push_back(-1);
     134          goto ExitCommunicate;
     135        }
     136
     137        // Read data   
     138        if ((N = read(fDescriptor, Buffer, sizeof(Buffer))) == -1) {
     139      m->Message(m->ERROR, "Read error (%s)", strerror(errno));
     140      ErrorCount++;
     141          goto ExitCommunicate;
     142        }
     143
     144        // Add data to buffer
     145        for (int i=0; i<N; i++) Data.push_back(Buffer[i]);
     146  } while(Data.size() < (unsigned int) Bytes);
     147 
     148  // === Check if multiple of three bytes were returned ===
     149  if (Data.size() % 3 != 0) {
     150    Data.clear();
    116151        goto ExitCommunicate;
    117152  }
    118153
    119   // Time-out expired?
    120   if (!FD_ISSET(fDescriptor, &SelectDescriptor)) {
    121         Ret = -1;
    122         goto ExitCommunicate;
    123   }
    124 
    125   // Read data   
    126   if ((N = read(fDescriptor, ReadBuffer, sizeof(ReadBuffer))) == -1) {
    127     m->Message(m->ERROR, "Read error (%s)", strerror(errno));
    128     ErrorCount++;
    129         goto ExitCommunicate;
    130   }
    131 
    132   // === Check wrap counter if three bytes were returned ===
    133   if (N == 3) {
     154  // === Check/update all wrap counter === 
     155  for (unsigned int i=0; i<Data.size(); i+=3) {
    134156        if (WrapCount != -1) {
    135           if ((WrapCount+1)%8 == ((ReadBuffer[0]>>4) & 7)) WrapOK = true;
     157          if ((WrapCount+1)%8 == ((Data[i]>>4) & 7)) WrapOK = true;
    136158          else WrapOK = false;
    137159        }
    138         WrapCount = (ReadBuffer[0]>>4) & 7;
    139         Ret = 1;
    140   }
    141  
     160        WrapCount = (Data[i]>>4) & 7;
     161  }
     162 
    142163  // === UnLock file descriptor ===
    143164  ExitCommunicate:
    144   if (lockf(fDescriptor, F_ULOCK, 0) == -1) {
    145         m->Message(m->ERROR, "Failed to unlock file descriptor (%s)", strerror(errno));
    146         return 0;
    147   }
    148  
    149   return Ret;
     165  funlockfile(File);
     166
     167  if (Data.empty()) Data.push_back(0);
     168
     169  return Data;
    150170}
    151171
     
    156176 
    157177  unsigned char wbuf[] = {0,0,0};
    158   int ret;
    159  
    160   if((ret = Communicate(wbuf, 3)) == 1) {
     178  vector<char> Data = Communicate(wbuf, 3);
     179 
     180  if (Data.size() == 3) {
    161181    ClearVoltageArrays();
    162182    ErrorCount = 0;
    163   }
    164   return ret;
     183        return 1;
     184  }
     185  return Data[0];
    165186}
    166187
     
    181202
    182203  // Execute command
    183   unsigned char wbuf[] = {1<<5 | Board<<1 | (Channel&16)>>4, Channel<<4, 0};
    184   int ret; 
     204  unsigned char wbuf[] = {1<<5 | Board<<1 | (Channel&16)>>4, Channel<<4, 0};
     205  vector<char> Data = Communicate(wbuf, 3);
     206
     207  if (Data.size() == 3) {
     208        Current[Board][Channel] = Data[1] + (Data[0]&15)*256;
     209        OC[Board][Channel] = Data[0] & 128;
     210        ResetHit = Data[2] & 128;
     211        if (Board==2 && Channel==19) OC[Board][Channel] = false;
     212        return 1;
     213  }
     214  return Data[0];
     215}
     216
     217
     218//
     219// Read all channels status
     220//
     221int Crate::ReadAll() {
     222
     223  unsigned char wbuf[3*MAX_NUM_BOARDS*NUM_CHANNELS];
     224  int Count = 0;
     225
     226  // Prepare command to read all channels
     227  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     228        wbuf[Count++] = 1<<5 | i<<1 | (j&16)>>4;
     229        wbuf[Count++] = j<<4;
     230        wbuf[Count++] = 0;
     231  }
     232 
     233  // Execute command
     234  vector<char> Data = Communicate(wbuf, 3*MAX_NUM_BOARDS*NUM_CHANNELS);
    185235   
    186   if ((ret = Communicate(wbuf, 3)) == 1) {
    187         Current[Board][Channel] = ReadBuffer[1] + (ReadBuffer[0]&15)*256;
    188         OC[Board][Channel] = ReadBuffer[0] & 128;
    189         ResetHit = ReadBuffer[2] & 128;
    190   }
    191   return ret;
     236  if (Data.size() != 3*MAX_NUM_BOARDS*NUM_CHANNELS) return Data[0];
     237
     238  //Evaluate returned data
     239  Count = 0;
     240  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     241        Current[i][j] = Data[Count+1] + (Data[Count]&15)*256;
     242        OC[i][j] = Data[Count] & 128;
     243        ResetHit = Data[Count+2] & 128;
     244        Count += 3;
     245        if (i==2 && j==19) OC[i][j] = false;
     246  }
     247  return 1;
    192248}
    193249
     
    204260  // Execute command
    205261  unsigned char wbuf[] = {1<<6 , SetPoint>>8, SetPoint};
    206   int ret; 
    207 
    208   if ((ret = Communicate(wbuf, 3)) == 1) {
    209         for (int i=0; i<MAX_NUM_BOARDS; i++) {
    210       for (int j=0; j<NUM_CHANNELS; j++) {
    211             DAC[i][j] = SetPoint;
    212                 Volt[i][j] = (double) SetPoint / 0xfff * 90;
    213           }
    214         }
    215   }
    216   return ret;
     262  vector<char> Data = Communicate(wbuf, 3);
     263
     264  if (Data.size() == 3) {
     265        for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     266          DAC[i][j] = SetPoint;
     267          Volt[i][j] = (double) SetPoint / 0xfff * 90;
     268        }
     269        return 1;
     270  }
     271  return Data[0];
    217272}
    218273
     
    237292  // Execute command
    238293  unsigned char wbuf[] = {3<<5 |  Board<<1 | (Channel&16)>>4, Channel<<4 | SetPoint>>8, SetPoint};
    239   int ret; 
     294  vector<char> Data = Communicate(wbuf, 3);
    240295   
    241   if ((ret = Communicate(wbuf, 3)) == 1) {
     296  if (Data.size() == 3) {
    242297    DAC[Board][Channel] = SetPoint;
    243298        Volt[Board][Channel] = (double) SetPoint / 0xfff * 90;
    244   }
    245   return ret;
     299        return 1;
     300  }
     301  return Data[0];
     302}
     303
     304
     305// ***** Channel set *****
     306int Crate::SetAll() {
     307 
     308  unsigned char wbuf[3*MAX_NUM_BOARDS*NUM_CHANNELS];
     309  double Volt = 10;
     310  int Count=0;
     311  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     312        wbuf[Count++] = 3<<5 |  i<<1 | (j&16)>>4;
     313        wbuf[Count++] = j<<4 | ((int) (Volt/90*0x0fff))>>8;
     314        wbuf[Count++] = (int) (Volt/90*0x0fff);
     315        Volt += 0.2;
     316  }
     317 
     318  // Execute command
     319  vector<char> Data = Communicate(wbuf, 3*MAX_NUM_BOARDS*NUM_CHANNELS);
     320   
     321  if (Data.size() == 3*MAX_NUM_BOARDS*NUM_CHANNELS) {
     322    //DAC[Board][Channel] = SetPoint;
     323        //Volt[Board][Channel] = (double) SetPoint / 0xfff * 90;
     324        return 1;
     325  }
     326  return Data[0];
    246327}
    247328
     
    251332 
    252333  unsigned char wbuf = 0;
    253   int Trial = 0, ret;
    254  
     334  int Trial = 0;
     335  vector<char> Data;
     336
    255337  while(++Trial <= 3) {
    256     if((ret = Communicate(&wbuf, 1)) == 1) return true;
    257     if (ret == 0) break;
     338    Data = Communicate(&wbuf, 1);
     339    if (Data.size() == 3) return true;
     340    if (Data[0] == 0) break;
    258341  }
    259342  return false;
     343}
     344
     345
     346// ***** Determine offset for current measurement *****
     347bool Crate::CurrentCalib(double Voltage) {
     348
     349  // Set voltage of all channels and wait for current to settle
     350  if (GlobalSet((int) (Voltage/90*0xfff)) != 1) return false;
     351  sleep(1);
     352 
     353  // Measure current of all channels
     354  if (ReadAll() != 1) return false;
     355
     356  for (int i=0; i<MAX_NUM_BOARDS; i++) for (int j=0; j<NUM_CHANNELS; j++) {
     357        CurrentOffset[i][j] = Current[i][j];
     358  }
     359  return true;
    260360}
    261361
  • fact/BIASctrl/Crate.h

    r10049 r10052  
    99#include <sys/ioctl.h>
    1010#include <string>
     11#include <vector>
    1112
    1213#include "dis.hxx"
     
    2223    class User *m;
    2324        int CrateNumber;
    24         int fDescriptor;
     25        int fDescriptor;
     26        FILE *File;
    2527        DimService *NameService;
    26         char ReadBuffer[3];
    2728
    28         int Communicate(unsigned char*, int);
     29        std::vector<char> Communicate(unsigned char*, int);
    2930        void ClearVoltageArrays();
    3031   
     
    4546        int DAC[MAX_NUM_BOARDS][NUM_CHANNELS];      // Voltage in DAC units
    4647        double Volt[MAX_NUM_BOARDS][NUM_CHANNELS];  // Voltage in Volt
     48        int CurrentOffset[MAX_NUM_BOARDS][NUM_CHANNELS]; // Offset for current measurement
    4749
    4850        bool InitOK;
    4951
     52        int SetAll();
     53        int ReadAll();
    5054        int SystemReset();
    5155        int ReadChannel(unsigned int, unsigned int);
     
    5357        int ChannelSet(int, int, unsigned int);
    5458        bool Synch();
     59        bool CurrentCalib(double);
    5560};
    5661
  • fact/BIASctrl/History.txt

    r9917 r10052  
    22                        program 'hvcontrol' (revision 9852).
    3320/8/2010       Removed the possibility to set DAC values.
     417/11/2010      Added possibility for bulk transfers (ReadAll(), SetAll())
  • fact/BIASctrl/User.cc

    r10049 r10052  
    44
    55#include "User.h"
     6#include <readline/readline.h>
    67
    78using namespace std;
     
    1718    {"hv", &User::cmd_hv, 2, "<id>|<ch>|<all> <v>", "Change bias of pixel or (all) chan. of active boards"},
    1819    {"gs", &User::cmd_gs, 1, "[crate] <volt>", "Global voltage set"},
    19         {"status", &User::cmd_status, 0, "[dac]", "Show status information (DAC values if requested)"},
     20        {"status", &User::cmd_status, 0, "[dac|current]", "Show status information (DAC values if requested)"},
     21        {"ccal", &User::cmd_ccal, 1, "<volt>", "Calibrate current measurement at given voltage"},
    2022        {"load", &User::cmd_load, 1, "<file>", "Load and set bias settings from file"},
    2123        {"save", &User::cmd_save, 1, "<file>", "Save current bias settings to file"},
    22         {"exit", &User::cmd_exit, 0, "", "Exit program"},
    2324        {"rate", &User::cmd_rate, 1, "<rate>", "Set refresh rate in Hz"},
    2425        {"timeout", &User::cmd_timeout, 1, "<time>", "Set timeout to return from read in seconds"},
    2526        {"reset", &User::cmd_reset, 1, "<crates>", "Reset crates"},
    26         {"help", &User::cmd_help, 0, "", "Print help"}};
     27        {"help", &User::cmd_help, 0, "", "Print help"},
     28        {"exit", &User::cmd_exit, 0, "", "Exit program"}};
    2729
    2830
     
    7779//
    7880User::~User() {
    79  
     81
    8082  // Wait for thread to quit
    8183  if (pthread_join(Thread, NULL) != 0) {
     
    170172        else {
    171173      vector<string> T = Tokenize(Parameter[n], "/");
     174          Crt.Min = 0;
     175          Crt.Max = Crates.size()-1;
     176          Chan.Min = 0;
     177          Chan.Max = MAX_NUM_BOARDS*NUM_CHANNELS-1;
     178         
    172179          if (T.size() == 2) {
    173                 Crt = ConvertToRange(T[0]);
    174                 Chan = ConvertToRange(T[1]);
     180                if(!ConvertToRange(T[0], Crt) || !ConvertToRange(T[1], Chan)) {
     181                  PrintMessage("Numeric conversion or out-of-range error for parameter %d, skipping channel\n", n);
     182                  continue;
     183                }
    175184          }
    176185          else {
    177186                Crt.Min = Crt.Max = 0;
    178                 Chan = ConvertToRange(T[0]);
     187                if (!ConvertToRange(T[0], Chan)) {
     188                  PrintMessage("Numeric conversion or out-of-range error for parameter %d, skipping channel\n", n);
     189                  continue;
     190                }
    179191          }
    180192        }
    181193 
    182         // Check validity of ranges
    183     if (Crt.Min < 0 || Chan.Min < 0 || Crt.Max >= (int) Crates.size() || Chan.Max >= MAX_NUM_BOARDS*NUM_CHANNELS) {
    184           PrintMessage("Numeric conversion or out-of-range error for parameter %d, skipping channel\n", n);
    185           continue;
    186         }
    187 
    188194        // Convert voltage value and check format
    189195        if (!ConvertToDouble(Parameter[n+1], &Double)) {
     
    304310void User::cmd_reset() {
    305311
    306   struct Range R = ConvertToRange(Parameter[1]);
    307  
    308   for (int i=0; i<(int) Crates.size(); i++) if (i>= R.Min && i<=R.Max) {
     312  struct Range R = {0, Crates.size()-1};
     313
     314  // Check ranges 
     315  if(!ConvertToRange(Parameter[1], R)) {
     316        PrintMessage("Error, crate number out of range\n");
     317        return;
     318  }
     319 
     320  for (int i=R.Min; i<=R.Max; i++) {
    309321        if (Crates[i]->SystemReset() == 1) PrintMessage("System reset of crate %s (#%d)\n", Crates[i]->Name, i);
    310322        else PrintMessage("Error: Could not reset board %s (#%d)\n", Crates[i]->Name, i);
     
    322334
    323335  if (Crates[0]->GlobalSet((int) (Voltage/90*0xfff)) != 1) {
    324     printf("Error: Could not global set board %d\n", 0);
     336    PrintMessage("Error: Could not global set board %d\n", 0);
    325337  }   
     338}
     339
     340//
     341// Determine current measurement offset
     342//
     343void User::cmd_ccal() {
     344
     345  double Voltage;
     346   
     347  if (!ConvertToDouble(Parameter[1], &Voltage)) {
     348    PrintMessage("Error with format of voltage parameter\n"); 
     349        return;
     350  }
     351
     352  // Execute current offset determination
     353  if (!Crates[0]->CurrentCalib(Voltage)) {
     354    PrintMessage("Error with current calibration of board %d\n", 0);
     355        return;
     356  }
     357 
     358  PrintMessage("Current calibration of board %d done\n", 0); 
    326359}
    327360
     
    370403                Crates[i]->ResetHit ? "yes" : "no", Crates[i]->ErrorCount);
    371404
     405        if (Parameter.size() == 1) PrintMessage("Channel voltages (in V)");
     406    else if (Match(Parameter[1], "dac")) PrintMessage("Channel voltages (in DAC values)");
     407        else PrintMessage("Channel currents (in uA)");
     408
    372409    for (int j=0; j<MAX_NUM_BOARDS*NUM_CHANNELS; j++) {
    373410          if (j%12 == 0) PrintMessage("\n%3.1d:  ", j);
    374           if (Parameter.size() == 2) PrintMessage("%5d ", Crates[i]->DAC[j/NUM_CHANNELS][j%NUM_CHANNELS]);
    375       else PrintMessage("%#5.2f ",Crates[i]->Volt[j/NUM_CHANNELS][j%NUM_CHANNELS]);
    376           //PrintMessage(" (%#5.2f %s)  ", Crates[i]->Current[j/NUM_CHANNELS][j%NUM_CHANNELS], Crates[i]->OC[j/NUM_CHANNELS][j%NUM_CHANNELS] ? "OC":"");
     411      if (Parameter.size() == 1) PrintMessage("%#5.2f ",Crates[i]->Volt[j/NUM_CHANNELS][j%NUM_CHANNELS]);
     412          else if (Match(Parameter[1], "dac")) PrintMessage("%5d ", Crates[i]->DAC[j/NUM_CHANNELS][j%NUM_CHANNELS]);
     413          else PrintMessage("%#5.2f %s ", (Crates[i]->Current[j/NUM_CHANNELS][j%NUM_CHANNELS]-Crates[i]->CurrentOffset[j/NUM_CHANNELS][j%NUM_CHANNELS])*1.2, Crates[i]->OC[j/NUM_CHANNELS][j%NUM_CHANNELS] ? "OC":"");
    377414    }
    378415        PrintMessage("\n");
     
    402439
    403440  ExitRequest = true;
    404   pthread_kill(Thread, SIGUSR1);
     441  //pthread_kill(Thread, SIGUSR1);
     442  //pthread_cancel(Thread);
    405443}
    406444 
     
    421459 
    422460  // Print to console
    423   if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, "\rBias> "); // New prompt
    424   else printf("%s", Text);
     461  printf("%s", Text); // New prompt
    425462  fflush(stdout);
     463  if (strlen(Text)>0 && Text[strlen(Text)-1]=='\n') rl_on_new_line(); // New prompt
    426464
    427465  // Send to DIM text service
     
    458496
    459497  static bool Warned = false;
    460 return;
     498
    461499  while (!ExitRequest) {
    462500        for (unsigned int i=0; i<Crates.size(); i++) {
     
    470508
    471509      if (Crates[i]->ResetHit) {
    472         Message(INFO, "Manual reset of board %d", i);
     510        Message(INFO, "Manual reset of board %d, setting voltages to zero and issuing system reset", i);
     511                Crates[i]->GlobalSet(0);
    473512                Crates[i]->SystemReset();
    474513      }
     
    478517      }
    479518
     519      if (Crates[i]->ReadAll() != 1) {
     520        Message(ERROR, "Monitor could not read status from crate %d", i);
     521                continue;
     522      }
     523
    480524      for (int j=0; j<MAX_NUM_BOARDS*NUM_CHANNELS; j++) {
    481         if (Crates[i]->ReadChannel(j/NUM_CHANNELS, j%NUM_CHANNELS) != 1) {
    482           Message(ERROR, "Monitor could not read status of crate %d, board %d, channel %d", i, j/NUM_CHANNELS, j%NUM_CHANNELS);
    483                   continue;
    484         }
    485525        if (Crates[i]->OC[j/NUM_CHANNELS][j%NUM_CHANNELS]) {
    486                   Message(WARN, "Overcurrent on crate %d, board %d, channel %d, resetting board", i, j/NUM_CHANNELS, j%NUM_CHANNELS);
     526                  Message(WARN, "Overcurrent on crate %d, board %d, channel %d, setting voltage to zero", i, j/NUM_CHANNELS, j%NUM_CHANNELS);
     527                  Crates[i]->ChannelSet(j/NUM_CHANNELS, j%NUM_CHANNELS, 0);
    487528                  Crates[i]->SystemReset();
    488529        }
     
    505546// Check if two strings match (min 1 character must match)
    506547//
    507 bool Match(string str, const char *cmd) {
     548bool User::Match(string str, const char *cmd) {
    508549
    509550  return strncasecmp(str.c_str(),cmd,strlen(str.c_str())==0 ? 1:strlen(str.c_str())) ? false:true;
     
    514555//
    515556// Return false if conversion did not stop on whitespace or EOL character
    516 bool ConvertToDouble(string String, double *Result) {
     557bool User::ConvertToDouble(string String, double *Result) {
    517558
    518559  char *EndPointer;
     
    523564}
    524565
    525 bool ConvertToInt(string String, int *Result) {
     566bool User::ConvertToInt(string String, int *Result) {
    526567
    527568  char *EndPointer;
     
    535576// Interprets a range
    536577//
    537 struct Range ConvertToRange(string String) {
    538 
    539   struct Range R;
     578bool User::ConvertToRange(string String, struct User::Range &R) {
     579
     580  int N, M;
    540581
    541582  // Full range
    542   if (Match(String, "all")) {
    543     R.Min = 0;
    544         R.Max = std::numeric_limits<int>::max();
    545         return R;
    546   }
     583  if (Match(String, "all")) return true;
    547584
    548585  // Single number
    549   if (ConvertToInt(String, &R.Min)) {
    550         R.Max = R.Min;
    551         return R;
     586  if (ConvertToInt(String, &N)) {
     587        if (N>= R.Min && N<=R.Max) {
     588          R.Max = R.Min = N;
     589          return true;
     590        }
     591        return false;
    552592  }
    553593 
    554594  // Range a-b
    555595  vector<string> V = EvidenceServer::Tokenize(String, "-");
    556   if (V.size() == 2 && ConvertToInt(V[0], &R.Min) && ConvertToInt(V[1], &R.Max)) return R;
    557  
    558   R.Min = R.Max = -1; 
    559   return R;
    560 }
     596  if (V.size()==2 && ConvertToInt(V[0], &N) && ConvertToInt(V[1], &M) && N>=R.Min && M<=R.Max) {
     597        R.Min = N;
     598        R.Max = M;
     599        return true;
     600  }
     601 
     602  return false;
     603}
  • fact/BIASctrl/User.h

    r10049 r10052  
    3535        void commandHandler();
    3636
     37        struct Range {
     38          int Min;
     39          int Max;
     40        };
     41
     42        bool Match(std::string, const char *);
     43        bool ConvertToDouble(std::string, double *);
     44        bool ConvertToInt(std::string, int *);
     45        bool ConvertToRange(std::string, struct Range &);
     46
    3747 public:
    3848        double fTimeOut;
     
    5363        void cmd_exit();        void cmd_rate();
    5464        void cmd_timeout();     void cmd_reset();
    55         void cmd_help();
     65        void cmd_help();        void cmd_ccal();
    5666};
    5767
    58 struct Range {
    59   int Min;
    60   int Max;
    61 };
    62 
    63 bool Match(std::string, const char *);
    64 bool ConvertToDouble(std::string, double *);
    65 bool ConvertToInt(std::string, int *);
    66 struct Range ConvertToRange(std::string);
    67 
    6868#endif
Note: See TracChangeset for help on using the changeset viewer.