Changeset 51 for drsdaq


Ignore:
Timestamp:
05/28/09 15:44:05 (15 years ago)
Author:
ogrimm
Message:
Added command line editing
Location:
drsdaq
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/DAQReadout.cc

    r49 r51  
    10191019  vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
    10201020 
    1021   // Print to console and generate new prompt
     1021  // Print to console
    10221022  if(Target & MsgToConsole) {
    1023     if(strlen(Textbuffer)>0 && Textbuffer[strlen(Textbuffer)-1]=='\n') printf("\r%s", Textbuffer);
     1023    if(strlen(Textbuffer)>0 && Textbuffer[strlen(Textbuffer)-1]=='\n') {
     1024      printf("\r%s%s", Textbuffer, Prompt);   // New prompt
     1025      fflush(stdout);
     1026    }
    10241027    else printf("%s", Textbuffer);
    1025 
    1026     // New prompt only after newline
    1027     if(Textbuffer[strlen(Textbuffer)-1]=='\n' || strlen(Textbuffer)==0) {
    1028       if (NumBoards == 0) printf("\rDAQ> ");
    1029       else if (FirstBoard == LastBoard) printf("\rDAQ|B%d> ",FirstBoard);
    1030       else printf("\rDAQ|B%d-%d> ",FirstBoard,LastBoard);
    1031       fflush(stdout);
    1032     }
    1033   }
    1034 
    1035   // Print to log file and socket only if length not zero (then only prompt)
    1036   if (strlen(Textbuffer)>0) {
    1037     if((Target & MsgToLog) && Logfile!=NULL) {
    1038       fprintf(Logfile, "%s", Textbuffer);
    1039       fflush(Logfile);
    1040     }
    1041     if((Target & MsgToSocket) && Socket!=-1) write(Socket, Textbuffer, strlen(Textbuffer));
    1042   }
     1028  }
     1029  // Print to log file
     1030  if((Target & MsgToLog) && Logfile!=NULL) {
     1031    fprintf(Logfile, "%s", Textbuffer);
     1032    fflush(Logfile);
     1033  }
     1034  // Print to socket
     1035  if((Target & MsgToSocket) && Socket!=-1) write(Socket, Textbuffer, strlen(Textbuffer));
    10431036}
    10441037
  • drsdaq/DAQReadout.h

    r49 r51  
    8181    unsigned int RunNumber, FileNumber;
    8282    char FileName[MAX_PATH];
    83 
     83    char Prompt[MAX_COM_SIZE];
    8484   
    8585    // Public functions
  • drsdaq/History.txt

    r49 r51  
    282819/5/2009   Subversion revision number included in run header. Added human readable
    2929            date and time to slow data.
    30 28/5/2009   Replaced NCMCBoards by NBoards for clarity.
     3028/5/2009   Replaced NCMCBoards by NBoards for clarity. Added line editing
     31            capability with the readline library.
  • drsdaq/Makefile

    r44 r51  
    2626
    2727CPPFLAGS = -DREVISION='"$(REVISION)"' -O3 -Wall $(VMECTRL)
    28 LIBS = -lstdc++ -lz -lpthread -lutil -lfl $(VMELIB)
     28LIBS = -lstdc++ -lz -lpthread -lutil -lfl -lreadline -ltermcap $(VMELIB)
    2929
    3030drsdaq: $(OBJECTS)
  • drsdaq/drsdaq.cpp

    r44 r51  
    1919#include <netdb.h>
    2020#include <arpa/inet.h>
     21#include <readline/readline.h>
     22#include <readline/history.h>
    2123
    2224#include "DAQReadout.h"
     
    116118  ConsoleCommand thread
    117119
    118   Handle console input
     120  Handle console input using readline library functions to allow
     121  line editing and history capability
    119122
    120123\********************************************************************/
     
    122125void ConsoleCommand(DAQReadout *m) {
    123126
    124   char Command[MAX_COM_SIZE], Buf[MAX_COM_SIZE];
    125127  time_t Time;
    126 
     128  char *Command, Buf[MAX_COM_SIZE];;
     129 
    127130  while (!m->Exit) {
    128     m->PrintMessage("");        // New prompt
    129     if (fgets(Command, MAX_COM_SIZE, stdin)==NULL)
     131    if (m->NumBoards == 0) snprintf(m->Prompt,sizeof(m->Prompt),"\rDAQ> ");
     132    else if (m->FirstBoard == m->LastBoard) snprintf(m->Prompt,sizeof(m->Prompt),"\rDAQ|B%d> ",m->FirstBoard);
     133    else snprintf(m->Prompt,sizeof(m->Prompt),"\rDAQ|B%d-%d> ",m->FirstBoard,m->LastBoard);
     134
     135    Command = readline(m->Prompt);
     136    if (Command==NULL) {
    130137      m->PrintMessage("Error reading command line input\n");
    131 
    132     strftime(Buf,MAX_COM_SIZE,"%d/%m/%y %X", localtime(&(Time=time(NULL))));
    133     m->PrintMessage(MsgToLog, "CONSOLE(%s)> %s",Buf, Command);
     138      continue;
     139    }
     140
     141    if(strlen(Command)>0) add_history(Command);
     142
     143    strftime(Buf,MAX_COM_SIZE, "%d/%m/%y %X", localtime(&(Time=time(NULL))));
     144    m->PrintMessage(MsgToLog, "CONSOLE(%s)> %s", Buf, Command);
    134145
    135146    pthread_mutex_lock(&m->control_mutex);
    136147    m->CommandControl(Command, false);
    137148    pthread_mutex_unlock(&m->control_mutex);
     149
     150    free(Command);
    138151  }
    139152}
     
    206219      memset(Command,0,sizeof(Command));
    207220      ReadResult = read(ConnectionSocket, Command, MAX_COM_SIZE);
    208       if (ReadResult==0) break;  // Client no exisiting anymore
     221      if (ReadResult==0) break;  // Client not exisiting anymore
    209222      if (ReadResult==-1) {
    210223        if (errno!=EINTR) m->PrintMessage("Error read from socket (%s)\n", strerror(errno));
     
    219232      m->CommandControl(Command, true); // Process CC command
    220233      pthread_mutex_unlock(&m->control_mutex);
    221       m->PrintMessage("");      // New prompt
    222234    }
    223235    m->Socket = -1;
Note: See TracChangeset for help on using the changeset viewer.