Changeset 161
- Timestamp:
- 02/05/10 09:01:28 (15 years ago)
- Location:
- hvcontrol
- Files:
-
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/History.txt
r126 r161 26 26 24/9/2009 Program is terminated if too many errors are encountered by the 27 27 monitor thread 28 8/12/2009 Implemented DIM servers (currently only needs DIM_DNS_NODE 29 environment variable) 28 8/12/2009 Implemented DIM servers 29 15/12/2009 Removed local log file and implemented logging via DColl 30 17/12/2009 Implemented DIM command handling and 'Textout' DIM service 31 8/1/2010 Removed locale slow data writing, now handled by Evidence 32 13/1/2010 Only important messages are written to log file 33 20/1/2010 Removed local configuration, now dependent on Evidence configuration 34 server 35 29/1/2010 DAC value 0 is now equivilant to calibrated voltage value 0 -
hvcontrol/Makefile
r135 r161 3 3 # 4 4 5 SOURCES = hvcontrol.cpp src/HV.cc src/HVC onfig.cc src/HVCalib.cc src/ProcessIO.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc ../drsdaq/SlowData.cc ../Evidence/Evidence.cc5 SOURCES = hvcontrol.cpp src/HV.cc src/HVCalib.cc src/ProcessIO.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc ../Evidence/Evidence.cc 6 6 OBJECTS = $(addsuffix .o, $(basename $(SOURCES))) 7 INCDIRS = -I. -I. /src -I../Evidence/DIM/7 INCDIRS = -I. -I../Evidence -I./src -I$(DIMDIR)/dim 8 8 9 CPPFLAGS = -O3 -Wall -DOS_LINUX$(INCDIRS)10 LDLIBS = -lstdc++ -lpthread -lfl -lreadline -ltermcap 9 CPPFLAGS = -O3 -Wall $(INCDIRS) 10 LDLIBS = -lstdc++ -lpthread -lfl -lreadline -ltermcap $(DIMDIR)/linux/libdim.a 11 11 12 hvcontrol: $(OBJECTS) ../Evidence/DIM/libdim.a12 hvcontrol: $(OBJECTS) 13 13 14 14 clean: -
hvcontrol/hvcontrol.cpp
r126 r161 93 93 signal(SIGQUIT, &CrashHandler); // CTRL-Backspace 94 94 signal(SIGINT, &CrashHandler); // CTRL-C 95 signal(SIGHUP, &CrashHandler); // CTRL-Backspace95 signal(SIGHUP, &CrashHandler); // Terminal closed 96 96 signal(SIGTERM, &CrashHandler); 97 97 … … 170 170 171 171 // Log command 172 m->PrintMessage( MsgToLog, "CONSOLE> %s\n", Command);172 m->PrintMessage(Log, "CONSOLE> %s\n", Command); 173 173 174 174 // Process command … … 208 208 // Set up server socket 209 209 if ((ServerSocket = socket(PF_INET, SOCK_STREAM, 0)) == -1) { 210 m->PrintMessage( "Could not open server socket, no remote connection possible (%s).\n", strerror(errno));210 m->PrintMessage(All, "Could not open server socket, no remote connection possible (%s).\n", strerror(errno)); 211 211 return; 212 212 } … … 215 215 int Value=1; 216 216 if (setsockopt(ServerSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &Value, sizeof (Value)) == -1) { 217 m->PrintMessage( "Warning: Could not set server socket option SO_REUSEADDR (%s)\n", strerror(errno));217 m->PrintMessage(All, "Warning: Could not set server socket option SO_REUSEADDR (%s)\n", strerror(errno)); 218 218 } 219 219 220 220 SocketAddress.sin_family = PF_INET; 221 SocketAddress.sin_port = htons((unsigned short) m-> config->fCCPort);221 SocketAddress.sin_port = htons((unsigned short) m->fCCPort); 222 222 SocketAddress.sin_addr.s_addr = INADDR_ANY; 223 223 224 224 if (bind(ServerSocket, (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1) { 225 m->PrintMessage( "Could not bind port to socket (%s)\n", strerror(errno));225 m->PrintMessage(All, "Could not bind port to socket (%s)\n", strerror(errno)); 226 226 close(ServerSocket); 227 227 return; 228 228 } 229 229 if (listen(ServerSocket, 0) == -1) { 230 m->PrintMessage( "Could not set socket to listening (%s)\n", strerror(errno));230 m->PrintMessage(All, "Could not set socket to listening (%s)\n", strerror(errno)); 231 231 close(ServerSocket); 232 232 return; … … 236 236 237 237 if ((ConnectionSocket = accept(ServerSocket, (struct sockaddr *) &ClientAddress, &SizeClientAddress)) == -1) { 238 if (errno!=EINTR) m->PrintMessage( "Failed to accept incoming connection (%s)\n", strerror(errno));238 if (errno!=EINTR) m->PrintMessage(All, "Failed to accept incoming connection (%s)\n", strerror(errno)); 239 239 close(ServerSocket); 240 240 return; … … 242 242 243 243 ClientName = gethostbyaddr((char *) &ClientAddress.sin_addr ,sizeof(struct sockaddr_in),AF_INET); 244 m->PrintMessage( "Connected to client at %s (%s).\n", inet_ntoa(ClientAddress.sin_addr), ClientName!=NULL ? ClientName->h_name:"name unknown");244 m->PrintMessage(All, "Connected to client at %s (%s).\n", inet_ntoa(ClientAddress.sin_addr), ClientName!=NULL ? ClientName->h_name:"name unknown"); 245 245 m->Socket = ConnectionSocket; 246 246 … … 253 253 if (ReadResult==0) break; // Client does not exist anymore 254 254 if (ReadResult==-1) { 255 if (errno!=EINTR) m->PrintMessage("Error read from socket (%s)\n", strerror(errno));256 break;255 if (errno!=EINTR) m->PrintMessage(All, "Error read from socket (%s)\n", strerror(errno)); 256 break; 257 257 } 258 258 if (Command[strlen(Command)-1]=='\n') Command[strlen(Command)-1]='\0'; // Remove trailing newline 259 259 260 260 // Log command 261 m->PrintMessage(MsgToConsole|MsgToLog, "SOCKET> %s\n", Command); 261 //m->PrintMessage(Console, "SOCKET> %s\n", Command); 262 //m->PrintMessage(Log, "SOCKET> %s\n", Command); 262 263 263 264 // Process command … … 270 271 271 272 m->Socket = -1; 272 m->PrintMessage( "Disconnected from client.\n");273 m->PrintMessage(All, "Disconnected from client.\n"); 273 274 close(ConnectionSocket); 274 275 } -
hvcontrol/src/HV.cc
r126 r161 22 22 m = PIO; 23 23 24 SetTimeOut(m-> config->fTimeOut);24 SetTimeOut(m->fTimeOut); 25 25 BoardNumber = DeviceNumber; 26 26 BoardName = DeviceName; … … 34 34 snprintf(Buffer, sizeof(Buffer), SERVER_NAME"/VOLT/ID%.2d/%.2d-%.3d", BoardNumber, i, j); 35 35 BiasVolt[i][j] = new DimService (Buffer, HVV[i][j]); 36 snprintf(Buffer, sizeof(Buffer), SERVER_NAME"/DAC/ID%.2d/%.2d-%.3d", BoardNumber, i, j);37 BiasDAC[i][j] = new DimService (Buffer, HV[i][j]);38 36 } 39 37 Overcurrent[i] = false; … … 43 41 LastWrapCount = -1; 44 42 ErrorCount = 0; 45 43 46 44 ClearVoltageArrays(); 47 45 … … 49 47 snprintf(Buffer, BUFFER_LENGTH, "/dev/%s",DeviceName); 50 48 if ((fDescriptor = open(Buffer, O_RDWR|O_NOCTTY|O_NDELAY)) == -1) { 51 if(errno != 2) m->PrintMessage( "Error: Could not open device %d/%s (%s)\n", DeviceNumber,DeviceName, strerror(errno));49 if(errno != 2) m->PrintMessage(All, "Error: Could not open device %d/%s (%s)\n", DeviceNumber,DeviceName, strerror(errno)); 52 50 return; 53 51 } … … 55 53 // Get current serial port settings 56 54 if (tcgetattr(fDescriptor, &tio) == -1) { 57 m->PrintMessage( "Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno));55 m->PrintMessage(All, "Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno)); 58 56 return; 59 57 } 60 58 61 59 // Set baudrate and raw mode 62 if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage( "Error: Could not set baud rate (%s)\n", strerror(errno));60 if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage(All, "Error: Could not set baud rate (%s)\n", strerror(errno)); 63 61 cfmakeraw(&tio); 64 if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage( "Error: tcsetattr() failed (%s)\n", strerror(errno));62 if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage(All, "Error: tcsetattr() failed (%s)\n", strerror(errno)); 65 63 66 64 // Synchronize HV board (if fails, closes device and sets fDescriptor to -2) … … 92 90 for (int j=0; j<NUM_CHANNELS; j++) { 93 91 delete BiasVolt[i][j]; 94 delete BiasDAC[i][j];95 92 } 96 93 } … … 109 106 // === Write data === 110 107 if ((ret=write(fDescriptor, wbuf, Bytes)) < Bytes) { 111 if (ret == -1) m->PrintMessage( "Could not write data to HV board (%s)\n", strerror(errno));112 else m->PrintMessage( "Could write only %d of %d bytes to HV board\n", ret, Bytes);108 if (ret == -1) m->PrintMessage(All, "Could not write data to HV board (%s)\n", strerror(errno)); 109 else m->PrintMessage(All, "Could write only %d of %d bytes to HV board\n", ret, Bytes); 113 110 ErrorCount++; 114 111 return 0; 115 }116 if (m->Verbose) {117 m->PrintMessage("%d bytes written:\n", Bytes);118 for (int i=0; i<Bytes; i++) m->PrintMessage(" Byte %d: %#.2x\n",i,wbuf[i]);119 112 } 120 113 … … 123 116 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)}; 124 117 if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) { 125 m->PrintMessage( "Error with select() (%s)\n", strerror(errno));118 m->PrintMessage(All, "Error with select() (%s)\n", strerror(errno)); 126 119 return 0; 127 120 } 128 121 // Time-out expired? 129 if (!FD_ISSET(fDescriptor, &SelectDescriptor)) { 130 if (m->Verbose) m->PrintMessage("Time-out of %.2f seconds expired while reading\n", fTimeOut); 131 return -1; 132 } 122 if (!FD_ISSET(fDescriptor, &SelectDescriptor)) return -1; 123 133 124 // Read error? 134 125 if ((ret = read(fDescriptor, &rbuf, 1)) == -1) { 135 m->PrintMessage( "Read error (%s)\n", strerror(errno));126 m->PrintMessage(All, "Read error (%s)\n", strerror(errno)); 136 127 ErrorCount++; 137 128 return 0; … … 147 138 ResetButton = (bool) (rbuf & 0X80); 148 139 149 if (m->Verbose && ret==1) m->PrintMessage(" 1 byte read: %#.2x\n", rbuf);150 151 140 return 1; 152 141 } … … 217 206 // Update DIM services 218 207 BiasVolt[j][k]->updateService(); 219 BiasDAC[j][k]->updateService();220 208 } 221 209 } -
hvcontrol/src/HV.h
r126 r161 9 9 #include <sys/ioctl.h> 10 10 11 #include "HVConfig.h"12 11 #include "dis.hxx" 12 #define NUM_CHAINS 4 13 #define NUM_CHANNELS 32 13 14 14 15 #define BAUDRATE B115200 … … 55 56 DimService *Name; 56 57 DimService *BiasVolt[NUM_CHAINS][NUM_CHANNELS]; 57 DimService *BiasDAC[NUM_CHAINS][NUM_CHANNELS];58 58 59 59 void ClearVoltageArrays(); -
hvcontrol/src/HVCalib.cc
r100 r161 19 19 #include "HVCalib.h" 20 20 21 #include "ProcessIO.h" // Must be not in HVCalib.h to avoid problem with declaring class ProcessIO 22 21 23 using namespace std; 22 24 23 25 24 HVCalib::HVCalib( HVConfig*hvConfig) {26 HVCalib::HVCalib(class ProcessIO *hvConfig) { 25 27 26 28 char calibfile[80], dLine[6000]; … … 31 33 32 34 Config = hvConfig; 33 35 34 36 iDACMin = Config->DACMin; 35 37 fHVCalibSlope = Config->fHVCalibSlope; … … 54 56 for(int i=0; i<Config->NumHVBoards; i++){ 55 57 for(int j=0; j<NUM_CHAINS; j++){ 56 sprintf(calibfile,"Calib/%s_%c%d.txt",hvConfig->f USBDevice[i],65+j,1);58 sprintf(calibfile,"Calib/%s_%c%d.txt",hvConfig->fHVBoard[i]->BoardName,65+j,1); 57 59 ifstream fin(calibfile); 58 60 … … 143 145 144 146 double HVCalib::DACToHV(int dac, int board, int chain, int channel) { 147 148 if (dac == 0) return 0; 149 145 150 if (dac < iDACMin){ 146 151 return HVArray[board][chain][channel][0] + (dac - iDACMin)*fHVCalibSlope; … … 153 158 154 159 int HVCalib::HVToDAC(double hv, int board, int chain, int channel) { 160 161 if (hv == 0) return 0; 155 162 if (hv < HVArray[board][chain][channel][0]){ 156 163 return iDACMin + (int)((hv - HVArray[board][chain][channel][0])/fHVCalibSlope); -
hvcontrol/src/HVCalib.h
r100 r161 4 4 #include <string.h> 5 5 6 #include "HVConfig.h"7 6 //#include "HVConfig.h" 7 class ProcessIO; 8 8 9 9 class HVCalib { … … 19 19 double fHVCalibSlope; 20 20 21 HVConfig*Config;21 class ProcessIO *Config; 22 22 23 23 public: 24 24 25 HVCalib( HVConfig*);25 HVCalib(class ProcessIO *); 26 26 ~HVCalib(); 27 27 -
hvcontrol/src/ProcessIO.cc
r126 r161 15 15 16 16 17 ProcessIO::ProcessIO(const char *ConfigFile): EvidenceServer(SERVER_NAME) { 17 ProcessIO::ProcessIO(const char *ConfigFile): 18 DimCommand((char *) SERVER_NAME"/Command", (char *) "C"), 19 EvidenceServer(SERVER_NAME) { 18 20 19 21 // Get program start time 20 22 time (&StartTime); 21 23 22 // Create instances 23 config = new HVConfig(ConfigFile); 24 calib = new HVCalib(config); 25 pm = new PixelMap(config->fPixMapTable); 24 // Create DIM text output service 25 Textout = new DimService (SERVER_NAME"/Textout", (char *) ""); 26 26 27 27 // Initialize status variables 28 28 state = active; 29 29 Exit = false; 30 Verbose = false;31 30 CmdFromSocket = false; 32 31 Socket = -1; … … 37 36 FirstChain = 0; 38 37 LastChain = NUM_CHAINS-1; 39 40 if (config->fStatusRefreshRate >= MIN_RATE && config->fStatusRefreshRate <= MAX_RATE) 41 fStatusRefreshRate = config->fStatusRefreshRate; 42 else fStatusRefreshRate = 1.; 43 38 39 // Get configuration data 40 char *Boards = GetConfig(SERVER_NAME " Boards"); 41 fPixMapTable = GetConfig(SERVER_NAME " PixMapTable"); 42 fTimeOut = atof(GetConfig(SERVER_NAME " TimeOut")); 43 fStatusRefreshRate = atof(GetConfig(SERVER_NAME " StatusRefreshRate")); 44 fCCPort = atoi(GetConfig(SERVER_NAME " CCPort")); 45 DACMin = atoi(GetConfig(SERVER_NAME " DACMin")); 46 DACMax = atoi(GetConfig(SERVER_NAME " DACMax")); 47 fHVCalibOffset = atof(GetConfig(SERVER_NAME " HVCalibOffset")); 48 fHVCalibSlope = atof(GetConfig(SERVER_NAME " HVCalibSlope")); 49 fHVMaxDiff = atoi(GetConfig(SERVER_NAME " HVMaxDiff")); 50 51 if (fStatusRefreshRate < MIN_RATE || fStatusRefreshRate > MAX_RATE) fStatusRefreshRate = 1; 52 44 53 // Open HV devices 45 fHVBoard = new HVBoard* [config->NumHVBoards]; 46 for (int i=0; i<config->NumHVBoards; i++) { 47 fHVBoard[NumHVBoards] = new HVBoard(i, config->fUSBDevice[i], this); 54 fHVBoard = new HVBoard* [strlen(Boards)]; 55 char *Token = strtok(Boards, " \t"); 56 while (Token != NULL) { 57 fHVBoard[NumHVBoards] = new HVBoard(NumHVBoards, Token, this); 48 58 if(fHVBoard[NumHVBoards]->fDescriptor >= 0) { 49 printf("Synchronized and reset HV board %d (%s)\n",i,config->fUSBDevice[i]);59 PrintMessage("Synchronized and reset board %d (%s)\n",NumHVBoards,fHVBoard[NumHVBoards]->BoardName); 50 60 NumHVBoards++; 51 61 } 52 62 else { 53 printf("Failed to synchronize to HV board %d (%s)\n",i,config->fUSBDevice[i]);63 PrintMessage(All, "Failed to synchronize board %d (%s)\n",NumHVBoards,fHVBoard[NumHVBoards]->BoardName); 54 64 delete fHVBoard[NumHVBoards]; 55 65 } 56 } 66 Token = strtok(NULL, " \t"); 67 } 57 68 LastBoard = NumHVBoards-1; 58 59 // Open log file 60 if ((Logfile = fopen(config->fLogFile, "a")) == NULL) printf("Warning: Could not open log file '%s'\n", config->fLogFile); 61 PrintMessage(MsgToLog,"********** Logging started **********\n"); 62 63 // Create instance of slow data class 64 SlowDataClass = new SlowData("HV", config->fSlowDir); 65 if (SlowDataClass->ErrorCode != 0) { 66 PrintMessage("Warning: Could not open slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode)); 67 } 68 SlowDataClass->NewEntry("Value-Info", "Issued if new HV value set successfull: Board-Num HV-Board-Name Chain Channel DAC-Target Converted-Value"); 69 SlowDataClass->NewEntry("Error-Info", "Issued if error occurs when trying to set new HV value: Board-Num HV-Board-Name Chain Channel Attempted-DAC-Target Converted-Value"); 69 70 // Create instances 71 calib = new HVCalib(this); 72 pm = new PixelMap(fPixMapTable); 70 73 } 71 74 … … 73 76 ProcessIO::~ProcessIO() { 74 77 75 delete SlowDataClass;76 77 78 for (int i=0; i<NumHVBoards; i++) delete fHVBoard[i]; 78 79 delete[] fHVBoard; 79 80 80 delete pm; delete calib; delete config; 81 82 if(Logfile != NULL) { 83 if(fclose(Logfile) != 0) perror("Error closing logfile"); 84 } 81 delete pm; delete calib; 82 delete Textout; 85 83 } 86 84 … … 97 95 98 96 for(int i=0; i<MAX_NUM_TOKEN; i++) Param[i] = ""; // All pointers point initially to empty string 99 100 101 // Adress HVboard97 NParam = ParseInput(Command, Param); 98 99 // Adress board 102 100 if (Match(Param[0], "board")) { 103 101 … … 158 156 // Print HV utility configuration 159 157 else if (Match(Param[0], "config")) { 160 PrintMessage( " Log file: %s\n" 161 " Pixel map table: %s\n" 162 " %d USB devices:\n", config->fLogFile, config->fPixMapTable, 163 config->NumHVBoards); 164 for (int i=0; i<config->NumHVBoards; i++) { 165 PrintMessage(" Board %d: %s\n", i, config->fUSBDevice[i]); 158 PrintMessage( " Pixel map table: %s\n" 159 " %d USB devices:\n", fPixMapTable, 160 NumHVBoards); 161 for (int i=0; i<NumHVBoards; i++) { 162 PrintMessage(" Board %d: %s\n", i, fHVBoard[i]->BoardName); 166 163 } 167 164 PrintMessage( " TimeOut: %.2f s\n" … … 172 169 " HVCalibOffset : %f\n" 173 170 " HVCalibSlope : %f\n" 174 " HVMaxDiff : %u\n", config->fTimeOut,175 config->fStatusRefreshRate, config->fCCPort, config->DACMin,176 config->DACMax, config->fHVCalibOffset, config->fHVCalibSlope,177 config->fHVMaxDiff);171 " HVMaxDiff : %u\n", fTimeOut, 172 fStatusRefreshRate, fCCPort, DACMin, 173 DACMax, fHVCalibOffset, fHVCalibSlope, 174 fHVMaxDiff); 178 175 179 176 return; … … 183 180 // Print help 184 181 if (Match(Param[0], "help")) { 185 puts(" board <i>|<i> <j>|<all> Address board i, boards i-j or all boards or list boards"); 186 puts(" chain <i>|<i> <j>|<all> Address chain i, chains i-j or all chains"); 187 puts(" hv <PXL id>|<ch>|<all> <v> Set HV of pixel ID, ch. or all ch. of active chain(s)/board(s)"); 188 puts(" hvdiff <PXL id>|<ch>|<all> <diff> Change HV by <diff>"); 189 puts(" status [dac] Show status information (DAC values if requested)"); 190 puts(" config Print configuration"); 191 puts(" load <file> Load HV settings from <file>"); 192 puts(" save <file> Save current HV settings to [file]"); 193 puts(" exit Exit program"); 194 puts(" rate <rate> Set status refresh rate to <rate> [Hz]"); 195 puts(" timeout <time> Set timeout to return from read to <time> [s]"); 196 puts(" reset Reset active HV board"); 197 puts(" start Start HV status monitor"); 198 puts(" stop Stop HV status monitor - not recommended!"); 199 puts(" uptime Get program uptime [h:m:s]"); 200 puts(" verbose <on|off>| Enable|disable verbosity"); 201 puts(" help Print help"); 202 puts(" .<cmd> Execute shell command <cmd>"); 182 PrintMessage(" board <i>|<i> <j>|<all> Address board i, boards i-j or all boards or list boards\n" 183 " chain <i>|<i> <j>|<all> Address chain i, chains i-j or all chains\n" 184 " hv <PXL id>|<ch>|<all> <v> Set bias of pixel ID, ch. or all ch. of active chain(s)/board(s)\n" 185 " hvdiff <PXL id>|<ch>|<all> <diff> Change bias by <diff>\n" 186 " status [dac] Show status information (DAC values if requested)\n" 187 " config Print configuration\n" 188 " load <file> Load and set bias settings from <file>\n" 189 " save <file> Save current bias settings to [file]\n" 190 " exit Exit program\n" 191 " rate <rate> Set status refresh rate to <rate> [Hz]\n" 192 " timeout <time> Set timeout to return from read to <time> [s]\n" 193 " reset Reset active bias board\n" 194 " start Start bias status monitor\n" 195 " stop Stop bias status monitor - not recommended!\n" 196 " uptime Get program uptime [h:m:s]\n" 197 " help Print help\n" 198 " .<cmd> Execute shell command <cmd>"); 203 199 204 200 return; … … 206 202 207 203 208 // Set new highvoltage (if no boards available, simply returns OK)204 // Set new bias voltage (if no boards available, simply returns OK) 209 205 // First reponse to socket should be 'OK' if no error occurred. 210 206 if (Match(Param[0], "hv") || Match(Param[0], "hvdiff")) { … … 249 245 for (int i=FirstBoard; i<=LastBoard; i++) { 250 246 if (i!=Board && Board!=-1) continue; 251 252 for (int j=FirstChain; j<=LastChain; j++) { 247 for (int j=FirstChain; j<=LastChain; j++) { 253 248 if (j!=Chain && Chain!=-1) continue; 254 255 249 for (int k=0; k<NUM_CHANNELS; k++) { 256 250 if (k!=Channel && Channel!=-1) continue; 257 251 258 // Convert from HV to DAC values 252 // hvdiff is ignored if DAC value is zero 253 if ((strlen(Param[0])>2 || isdigit(*Param[2])==0) && (fHVBoard[i]->HV[j][k] == 0)) continue; 254 255 // Determine new DAC values 259 256 if (!SetDac){ 260 if(strlen(Param[0]) > 2) fHVBoard[i]->HVV[j][k] += hvoltageV; // hvdiff257 if (strlen(Param[0])>2 || isdigit(*Param[2])==0) fHVBoard[i]->HVV[j][k] += hvoltageV; // hvdiff 261 258 else fHVBoard[i]->HVV[j][k] = hvoltageV; 262 259 DACValue = calib->HVToDAC(fHVBoard[i]->HVV[j][k], i, j, k); 263 260 } 264 261 else { 265 if(strlen(Param[0]) > 2) DACValue = fHVBoard[i]->HV[j][k] + hvoltage; // hvdiff262 if(strlen(Param[0])>2 || isdigit(*Param[2])==0) DACValue = fHVBoard[i]->HV[j][k] + hvoltage; // hvdiff 266 263 else DACValue = hvoltage; 267 264 } … … 271 268 if (SetDac) fHVBoard[i]->HVV[j][k] = calib->DACToHV(fHVBoard[i]->HV[j][k], i, j, k); 272 269 273 274 270 // Update DIM services 271 fHVBoard[i]->BiasVolt[j][k]->updateService(); 275 272 276 273 } // Channels 277 274 } // Chains 278 275 } // Boards 279 276 … … 306 303 for (int Board=0; Board<NumHVBoards; Board++) { 307 304 if (Match(fHVBoard[Board]->BoardName, Buffer)) { 308 PrintMessage("Found HVsettings for board %d (%s)\n\r",fHVBoard[Board]->GetBoardNumber(), fHVBoard[Board]->BoardName);305 PrintMessage("Found bias settings for board %d (%s)\n\r",fHVBoard[Board]->GetBoardNumber(), fHVBoard[Board]->BoardName); 309 306 310 307 Chain = 0; Channel = 0; … … 339 336 340 337 if (NBoards != NumHVBoards) { 341 PrintMessage("Warning: Could not load HVsettings for all connected HV boards\n");342 } 343 else if (Errors == 0) PrintMessage("Success: Read HVsettings for all connected HV boards\n");338 PrintMessage("Warning: Could not load bias settings for all connected HV boards\n"); 339 } 340 else if (Errors == 0) PrintMessage("Success: Read bias settings for all connected HV boards\n"); 344 341 if (Errors != 0) PrintMessage("Warning: Errors on %d channel(s) occurred\n", Errors); 345 342 … … 406 403 } 407 404 408 fprintf(File,"********** HVsettings, %04d %02d %02d, %02d:%02d:%02d **********\n\n",405 fprintf(File,"********** Bias settings, %04d %02d %02d, %02d:%02d:%02d **********\n\n", 409 406 1900 + Time->tm_year, 1 + Time->tm_mon, 410 407 Time->tm_mday, Time->tm_hour, Time->tm_min, Time->tm_sec); … … 433 430 state = active; 434 431 pthread_kill(HVMonitor, SIGUSR1); 435 PrintMessage( "Status monitoring activated\n");432 PrintMessage(All, "Status monitoring activated\n"); 436 433 return; 437 434 } … … 442 439 443 440 PrintMessage("\n Status monitor: %s\n", state_str[state]); 444 PrintMessage(" Verbose: %s\n", Verbose ? "on" : "off");445 441 PrintMessage(" Status refresh rate [Hz]: %.2f\n", fStatusRefreshRate); 446 442 PrintMessage(" Socket state: %s\n", Socket==-1 ? "disconnected":"connected"); 447 PrintMessage(" Total number of HVboards: %d\n", NumHVBoards);448 PrintMessage(" Active HVboards: %d\n\n", LastBoard - FirstBoard + 1);443 PrintMessage(" Total number of boards: %d\n", NumHVBoards); 444 PrintMessage(" Active boards: %d\n\n", LastBoard - FirstBoard + 1); 449 445 450 446 for (int i=FirstBoard; i<=LastBoard; i++) { … … 479 475 state = stopped; 480 476 pthread_kill(HVMonitor, SIGUSR1); 481 PrintMessage( "Status monitor stopped\n");477 PrintMessage(All, "Status monitor stopped\n"); 482 478 483 479 return; … … 520 516 521 517 522 // Enable/disable verbosity523 else if (Match(Param[0], "verbose")) {524 525 if (Match(Param[1], "on")) {526 Verbose = true;527 PrintMessage("Verbosity enabled\n");528 }529 else if (Match(Param[1], "off")) {530 Verbose = false;531 PrintMessage("Verbosity disabled\n");532 }533 else PrintMessage("Usage: verbose <on>|<off>\n");534 535 return;536 }537 538 539 518 // Exit program 540 519 else if(Match(Param[0], "exit")) { … … 559 538 560 539 // Print message to selected target 561 void ProcessIO::PrintMessage( int Target, const char *Format, ...) {540 void ProcessIO::PrintMessage(MsgTarget Target, const char *Format, ...) { 562 541 va_list ArgumentPointer; 563 542 va_start(ArgumentPointer, Format); … … 570 549 va_list ArgumentPointer; 571 550 va_start(ArgumentPointer, Format); 572 if (CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, MsgToSocket|MsgToLog);573 else DoPrintMessage(Format, ArgumentPointer, MsgToConsole|MsgToLog);551 if (CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, Client); 552 else DoPrintMessage(Format, ArgumentPointer, Console); 574 553 va_end(ArgumentPointer); 575 554 } … … 577 556 // Function doing the actual printing work 578 557 // Be careful with overloading variadic functions! 579 void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, int Target) {580 581 char Textbuffer[MAX_COM_SIZE];558 void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, MsgTarget Target) { 559 560 static char Textbuffer[MAX_COM_SIZE]; // static because of DIM service 582 561 583 562 memset(Textbuffer, 0, sizeof(Textbuffer)); … … 585 564 586 565 // Print to console 587 if(Target & MsgToConsole) {566 if(Target & Console) { 588 567 if(strlen(Textbuffer)>0 && Textbuffer[strlen(Textbuffer)-1]=='\n') { 589 568 printf("\r%s%s", Textbuffer, Prompt); // New prompt … … 592 571 fflush(stdout); 593 572 } 573 574 // Send to DIM service 575 Textout->updateService(Textbuffer); 576 594 577 // Print to socket 595 if((Target & MsgToSocket) && Socket!=-1) {578 if((Target & Client) && Socket!=-1) { 596 579 write(Socket, Textbuffer, strlen(Textbuffer)); 597 580 } 598 // Print to log file (replace carriage return by linefeed) 599 if((Target & MsgToLog) && Logfile!=NULL) {600 for (unsigned int i=0; i<strlen(Textbuffer); i++) {601 if(Textbuffer[i] == '\r') Textbuffer[i] = '\n';602 }603 time_t Time;604 strftime(Textbuffer+strlen(Textbuffer)+1,MAX_COM_SIZE-strlen(Textbuffer)-1, "%d/%m/%y %X", localtime(&(Time=time(NULL))));605 fprintf(Logfile, "%s: %s", Textbuffer+strlen(Textbuffer)+1, Textbuffer);606 fflush(Logfile);607 } 608 } 609 610 611 // Ramp to new voltage with maximum step size given in config->fHVMaxDiff581 582 // Send to log 583 if(Target & Log) { 584 char *Buf; 585 if (asprintf(&Buf, "%s %s", SERVER_NAME, Textbuffer) != -1) { 586 DimClient::sendCommand("DColl/Log", Buf); 587 free(Buf); 588 } 589 else DimClient::sendCommand("DColl/Log", SERVER_NAME" asprintf() failed"); 590 } 591 } 592 593 594 // Ramp to new voltage with maximum step size given in fHVMaxDiff 612 595 // No ramping when decreasing voltage 613 596 bool ProcessIO::RampVoltage(unsigned int Target, int Board, int Chain, int Channel) { … … 615 598 while (fHVBoard[Board]->HV[Chain][Channel] != (int) Target) { 616 599 int Diff = Target - fHVBoard[Board]->HV[Chain][Channel]; 617 if (Diff > (int) config->fHVMaxDiff) Diff = config->fHVMaxDiff; 618 619 if (fHVBoard[Board]->SetHV(Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff) == 1) { 620 if (Verbose) { 621 PrintMessage("Board %d: high voltage of chain %d channel %d set to %d | 0X%.4X | %f V\n",fHVBoard[Board]->GetBoardNumber(),Chain, Channel, Target, Target, calib->DACToHV(Target,fHVBoard[Board]->GetBoardNumber(),Chain,Channel)); 622 PrintBoardStatus(Board); 623 } 624 } 625 else { 626 PrintMessage("Error: Could not set HV of board %d, chain %d, channel %d. Skipping channel\n",fHVBoard[Board]->GetBoardNumber(),Chain,Channel); 627 SlowDataClass->NewEntry("Error"); 628 SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel)); 600 if (Diff > (int) fHVMaxDiff) Diff = fHVMaxDiff; 601 602 if (fHVBoard[Board]->SetHV(Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff) != 1) { 603 State(ERROR, "Could not set bias of board %d, chain %d, channel %d. Skipping channel\n",fHVBoard[Board]->GetBoardNumber(),Chain,Channel); 629 604 return false; 630 605 } 631 606 } 632 SlowDataClass->NewEntry("Value"); 633 SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel)); 634 635 // Update DIM service 636 fHVBoard[Board]->BiasDAC[Chain][Channel]->updateService(); 637 607 638 608 return true; 639 609 } … … 649 619 if (!Warned) { 650 620 Warned = true; 651 PrintMessage("Warning: Some board has many read/write errors, status monitor disabled\n"); 621 PrintMessage(All, "Warning: Some board has many read/write errors, status monitor disabled\n"); 622 State(WARN, "Warning: Some board has many read/write errors, status monitor disabled\n"); 652 623 } 653 624 continue; … … 655 626 656 627 if (fHVBoard[i]->GetStatus() != 1) { 657 PrintMessage("Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber()); 628 PrintMessage(All, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber()); 629 State(ERROR, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber()); 658 630 } 659 631 660 632 if (fHVBoard[i]->ResetButton) { 661 PrintMessage("Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber()); 633 PrintMessage(All, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber()); 634 State(INFO, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber()); 662 635 ResetBoard(i); 663 636 } 664 637 665 638 if (!fHVBoard[i]->WrapOK) { 666 PrintMessage("Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber()); 639 PrintMessage(All, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber()); 640 State(ERROR, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber()); 667 641 } 668 642 669 643 for (int j=0; j<NUM_CHAINS; j++) { 670 644 if (fHVBoard[i]->Overcurrent[j]) { 671 PrintMessage("Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber()); 672 ResetBoard(i); 645 PrintMessage(All, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber()); 646 State(WARN, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber()); 647 ResetBoard(i); 673 648 } 674 649 } … … 724 699 } 725 700 701 // 702 // Command handling (the only command is 'BIAS/Command') 703 // 704 void ProcessIO::commandHandler() { 705 706 // Log command 707 PrintMessage(Log, "DIM> %s\n", getString()); 708 709 // Process command 710 pthread_mutex_lock(&control_mutex); 711 CommandControl(getString()); 712 pthread_mutex_unlock(&control_mutex); 713 } 726 714 727 715 // Check if two strings match (min 1 character must match) -
hvcontrol/src/ProcessIO.h
r126 r161 8 8 #include <signal.h> 9 9 10 #define SERVER_NAME "B IAS" // Name to use in DIM11 #include " ../../Evidence/Evidence.h"10 #define SERVER_NAME "Bias" // Name to use in DIM 11 #include "Evidence.h" 12 12 13 #include "HVConfig.h"14 13 #include "HVCalib.h" 15 14 #include "HV.h" 16 15 #include "../pixelmap/PixelMap.h" 17 #include "../drsdaq/SlowData.h" 16 17 #define MAX_COM_SIZE 5000 18 #define NUM_CHAINS 4 19 #define NUM_CHANNELS 32 20 #define BUFFER_LENGTH 256 21 22 #define MIN_TIMEOUT 0.01 23 #define MAX_TIMEOUT 5.0 24 25 #define MIN_RATE 0.01 26 #define MAX_RATE 50.0 18 27 19 28 #define MAX_NUM_TOKEN 10 20 29 21 #define MsgToConsole 1 22 #define MsgToLog 2 23 #define MsgToSocket 4 30 enum MsgTarget {Console=1, Log=2, Client=4, All=7}; 31 typedef enum stateenum {active, stopped, na} state_enum; 24 32 25 typedef enum stateenum { active, stopped, na } state_enum; 26 27 class ProcessIO: public EvidenceServer { 33 class ProcessIO: public DimCommand, public EvidenceServer { 28 34 29 35 time_t StartTime; 30 FILE *Logfile;31 36 PixelMap *pm; 37 DimService *Textout; 38 39 void commandHandler(); 32 40 33 41 public: 34 42 35 HVConfig *config;43 //HVConfig *config; 36 44 HVCalib *calib; 37 45 HVBoard **fHVBoard; 38 SlowData *SlowDataClass;39 46 40 47 pthread_mutex_t control_mutex; … … 44 51 int NParam; 45 52 bool CmdFromSocket; 46 53 54 // Configuration data 55 char *fPixMapTable; 56 float fTimeOut; 57 float fStatusRefreshRate; 58 int fCCPort; 59 int DACMin; 60 int DACMax; 61 float fHVCalibOffset; 62 float fHVCalibSlope; 63 unsigned int fHVMaxDiff; 64 47 65 // Status variables 48 66 pthread_t HVMonitor; // exit function sends signal to these threads 49 67 pthread_t SocketThread; 50 68 51 bool Verbose;52 69 int Socket; // -1 if not connected 53 70 … … 58 75 int LastChain; 59 76 60 float fStatusRefreshRate;61 77 state_enum state; 62 78 bool Exit; … … 66 82 ~ProcessIO(); 67 83 68 void PrintMessage( int, const char *, ...);84 void PrintMessage(MsgTarget, const char *, ...); 69 85 void PrintMessage(const char *, ...); 70 void DoPrintMessage(const char *, va_list, int);86 void DoPrintMessage(const char *, va_list, MsgTarget); 71 87 void CommandControl(char*); 72 88 bool RampVoltage(unsigned int, int, int, int);
Note:
See TracChangeset
for help on using the changeset viewer.