Ignore:
Timestamp:
04/23/10 08:24:35 (14 years ago)
Author:
ogrimm
Message:
Improved test command
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/vchvtest/vchvtest.cc

    r201 r202  
    88
    99#include <stdio.h>
     10#include <termios.h>
     11#include <unistd.h>
     12
    1013#include <ctype.h>
    1114#include <sys/time.h>
     
    2730int LastCrate;
    2831bool Repeat = false;
    29 bool Verbose = true;
     32bool Verbose;
    3033
    3134// Function prototypes
     
    7376
    7477  char Prompt[MAX_COM_SIZE], *Command = NULL;
     78  struct termios Termios, Termios_orig;
    7579
    7680  printf("\n*** vchvtest (built %s, %s; O. Grimm) ***\n\n",__DATE__,__TIME__);
    77   if (argc == 1) printf("Note: Use FTDI serial numbers as arguments to connect\n");
     81  if (argc == 1) {
     82    printf("Note: Use FTDI serial numbers as arguments to connect\n");
     83  }
     84       
    7885
    7986  // Initialize status variables
     
    9097  }
    9198  LastCrate = NumCrates-1;
     99
     100  // Set terminal to read single chars
     101  if (tcgetattr (1, &Termios_orig) == -1) {
     102    printf("Error with tcgetattr() (%s)\n", strerror(errno));
     103    exit(EXIT_FAILURE);
     104  }
     105  Termios = Termios_orig;
     106  Termios.c_lflag &= ~(ICANON | ECHO);
    92107
    93108  // Command loop
     
    109124    else continue;
    110125   
    111     // Process command     
     126        // Set terminal to return single chars
     127        if (tcsetattr (1, 0, &Termios) == -1) {
     128      printf("Error with tcsetattr() (%s)\n", strerror(errno));
     129      exit(EXIT_FAILURE);
     130    }
     131
     132        // Defualt is verbose response
     133        Verbose = true;
     134
     135    // Process command
    112136    for(int i=0; i<MAX_NUM_TOKEN; i++) Param[i] = "";  // All pointers point initially to empty string
    113137    NParam = ParseInput(Command, Param);
     
    115139    bool Found=false;
    116140    int N;
    117     for(unsigned int CmdNumber=0; CmdNumber<sizeof(CommandList)/sizeof(CL_Struct); CmdNumber++)
     141    for(unsigned int CmdNumber=0; CmdNumber<sizeof(CommandList)/sizeof(CL_Struct); CmdNumber++) {
    118142      if (Match(Param[0], CommandList[CmdNumber].Name)) {
    119143        if(NParam-1 < CommandList[CmdNumber].MinNumParameter) {
    120144          printf("Usage: %s %s\n", CommandList[CmdNumber].Name, CommandList[CmdNumber].Parameters);
    121         }
    122         else do {
    123           (*CommandList[CmdNumber].CommandPointer)();
    124           ioctl(STDIN_FILENO, FIONREAD, &N);
    125         } while(CommandList[CmdNumber].Repeatable && Repeat && N==0);
     145            }
     146                else do {
     147                  (*CommandList[CmdNumber].CommandPointer)();
     148                  ioctl(STDIN_FILENO, FIONREAD, &N);
     149                } while(CommandList[CmdNumber].Repeatable && Repeat && N==0);
    126150        Found = true;
    127         break;
     151                break;
    128152      }
     153        } // for()
     154       
    129155    if (!Found) printf("Unknown command '%s'\n",Param[0]);
    130   } // while{}
     156       
     157        // Set terminal back to line buffering
     158        if (tcsetattr (1, 0, &Termios_orig) == -1) {
     159      printf("Error with tcsetattr() (%s)\n", strerror(errno));
     160      exit(EXIT_FAILURE);
     161    }
     162  } // while()
    131163}
    132164
     
    226258void cmd_test() {
    227259
    228   for (int i=FirstCrate; i<=LastCrate; i++) {
    229     printf("Testing board %d  (Enter to continue, any key plus enter to stop)\n", fHVBoard[i]->BoardNumber);
     260  Verbose = false;
     261
     262  // Loop over crates
     263  for (int i=FirstCrate; i<=LastCrate; i++) {
     264    printf("Testing board %d  (q to stop, any other key to continue)\n", fHVBoard[i]->BoardNumber);
    230265    if (fHVBoard[i]->GlobalSet(0) != 1) {
    231266      printf("Error: Could not global set board to zero\n");
     
    234269
    235270        for (int k=0; k<MAX_NUM_BOARDS; k++) for (int j=0; j<NUM_CHANNELS; j++) {
    236           printf("\rBoard %d, channel %d", k, j);
    237           fflush(stdout);
    238           Verbose = false;
     271          printf("Board %d, channel %d\n", k, j);
     272
    239273          if (fHVBoard[i]->ChannelSet(k, j, atoi(Param[1])) != 1) {
    240         printf("Error setting voltage\n");
     274        printf("  Error setting voltage\n");
    241275                return;
    242276          }
    243           Verbose = true;
    244           if (getchar() != '\n') return;
     277         
     278          if (getchar() == 'q') return;
    245279        }
    246280  }
     
    270304
    271305  if (N < 1) return;
     306  Verbose = false;
    272307
    273308  gettimeofday(&Start, NULL);
    274   Verbose = false;
    275309  for (int i=0; i<=N; i++) fHVBoard[0]->ReadChannel(0, 0);
    276   Verbose = true;
    277310  gettimeofday(&End, NULL);
    278311
     
    286319  if (Match(Param[1],"on")) Repeat = true;
    287320  else Repeat = false;
    288   printf("Auto command repeat is %s\n", Repeat ? "on (CTRL-c to switch off)" : "off");
     321  printf("Auto command repeat is %s\n", Repeat ? "on (Hit return while repeating to stop)" : "off");
    289322}
    290323
     
    294327  int Board;
    295328
     329  Verbose = false;
     330
    296331  if (NParam==2 && ConvertToInt(Param[1], &Board)) {
    297332        for (int i=FirstCrate; i<=LastCrate; i++) {
    298           Verbose = false;
    299333          for (int j=0; j<NUM_CHANNELS; j++) {
    300334                if (j%4 == 0) printf("\nChannel %2d  ", j);
     
    304338      }   
    305339        printf("\n"); 
    306         Verbose = true;
    307340        }
    308341  } else {
     
    332365    }   
    333366  }
    334  
    335   Verbose = true;
    336367}
    337368
Note: See TracChangeset for help on using the changeset viewer.