Changeset 35
- Timestamp:
- 04/24/09 14:06:49 (16 years ago)
- Location:
- hvcontrol
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/HV.conf
r14 r35 1 # Main configuration file for the HV control program V1.0, 2009 0 3 17, 18:46:081 # Main configuration file for the HV control program V1.0, 2009 04 23, 17:13:36 2 2 # Note: this file will be updated at program exit 3 3 … … 13 13 IsDAC FALSE # Define here if user input is interpreted as DAC value or voltage 14 14 15 HVCalibOffset -0.800000 # Calibration of DAC to voltage values 15 DACMin 11008 # Starting point for calibration of DAC to voltage values 16 DACMax 12496 # End point for calibration of DAC to voltage values 17 HVMin 67.000000 # Starting point for calibration of voltage to DAC values 18 HVMax 76.000000 # End point for calibration of voltage to DAC values 19 HVCalibOffset 67.000000 # Calibration of DAC to voltage values 16 20 HVCalibSlope 0.006400 # Calibration of DAC to voltage values 17 21 -
hvcontrol/Makefile
r14 r35 1 1 # 2 # Makefile for the CTX HV utility2 # Makefile example 3 3 # 4 4 5 include Makefile.general 5 SOURCES = hvcontrol.cpp src/CCCommand.cc src/ConsoleCommand.cc src/HV.cc src/HVConfig.cc src/HVCalib.cc src/HVMonitor.cc src/HVStatus.cc src/Log.cc src/ProcessIO.cc src/ReadCard.cc src/Utilities.cc ../../fact_repos.svn/pixelmap/Pixel.cc ../../fact_repos.svn/pixelmap/PixelMap.cc 6 6 7 PROGRAMS = hvcontrol remotecontrol 7 OBJECTS = $(addsuffix .o, $(basename $(SOURCES))) 8 8 9 SUBDIRS = src 9 #INCDIRS = -I. -IDRS -I../pixelmap 10 INCDIRS = -I. -I../pixelmap -I./src 10 11 12 CFLAGS = -pipe -fthread-jumps -funroll-all-loops -O3 -Wall -DOS_LINUX 13 CPPFLAGS = -pipe -fPIC -fthread-jumps -funroll-all-loops -O3 -Wall -DOS_LINUX $(VMECTRL) 14 LIBS = -lstdc++ -lz -lpthread -lutil -lfl -lusb -lftdi -L/usr/lib -L/sw/lib 11 15 12 all: $(PROGRAMS) 16 hvcontrol: $(OBJECTS) 17 $(CC) $(CPPFLAGS) -o $@ $(OBJECTS) $(LIBS) 13 18 19 clean: 20 @rm -f $(OBJECTS) $(SOBJECTS).so 21 @rm -f *.d 22 @rm -f *~ 14 23 15 OBJECTS = $(SUBDIRS:=/*.o) 24 -include Dep.d 16 25 17 INCDIRS = -I. $(SUBDIRS:%=-I%) 26 # Implicit rules 18 27 19 MRPROPERS = $(SUBDIRS:=.mrproper) 28 %.o : %.c 29 $(CC) $(CFLAGS) $(INCDIRS) -c -o $@ $< 30 %.o : %.cc 31 $(CC) $(CPPFLAGS) $(INCDIRS) -c -o $@ $< 32 %.o : %.cpp 33 $(CC) $(CPPFLAGS) $(INCDIRS) -c -o $@ $< 34 %.d : 35 @echo "Generating dependencies" $@ 36 @$(CC) -MM $(SOURCES) $(INCDIRS) \ 37 | sed 's/^\(.*\).o:/$@ \1.o:/' > $@ 20 38 21 CLEANERS = $(SUBDIRS:=.cleaner)22 23 LIBRARIES = $(SUBDIRS:=.all)24 25 26 $(PROGRAMS) : % : %.o $(LIBRARIES)27 $(G++) $(CFLAGS) -o $@ $@.o $(OBJECTS) $(LIBS)28 29 include Makefile.rules30 31 $(LIBRARIES):32 @echo " Calling make in $(@:.all=)"33 @(cd $(@:.all=); $(MAKE) -f Makefile all)34 35 $(MRPROPERS):36 @echo " Doing Mr.Proper in $(@:.mrproper=)"37 @(cd $(@:.mrproper=); $(MAKE) -f Makefile mrproper)38 39 $(CLEANERS):40 @echo " Doing clean in $(@:.cleaner=)"41 @(cd $(@:.cleaner=); $(MAKE) -f Makefile clean)42 43 mrproper: $(MRPROPERS) rmobj rmbak rmdep44 @rm -f $(PROGRAMS)45 @echo " Done."46 47 clean: $(CLEANERS) rmobj48 @echo " Done."49 -
hvcontrol/hvcontrol.cpp
r14 r35 31 31 #define LOCKFILE "/tmp/CTX_HV_LOCK" 32 32 33 void CrashHandler(int Signal); 34 33 35 34 36 int main(int argc, char *argv[]) { … … 46 48 // The flag O_EXCL together with O_CREAT assure that the lock 47 49 // file cannot be opened by another instance, i.e. there are no parallel write accesses 48 if ((LockDescriptor = open(LOCKFILE,O_RDONLY|O_CREAT|O_EXCL)) == -1) {50 /* if ((LockDescriptor = open(LOCKFILE,O_RDONLY|O_CREAT|O_EXCL)) == -1) { 49 51 sprintf(str, "Could not create lock file %s", LOCKFILE); 50 52 perror(str); … … 52 54 } 53 55 close(LockDescriptor); 56 */ 57 if((LockDescriptor = open(LOCKFILE,O_WRONLY|O_CREAT|O_EXCL,S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)) == -1) { 58 if(errno==EEXIST) { 59 printf("Error: Lock file already existing\n"); 60 sprintf(str,"paste %s -s -d ' '",LOCKFILE); 61 system(str); 62 } 63 else { 64 sprintf(str, "Could not create lock file %s", LOCKFILE); 65 perror(str); 66 } 67 exit(EXIT_FAILURE); 68 } 69 close(LockDescriptor); 70 sprintf(str,"echo Created >%s; date >>%s; echo by $USER@$HOSTNAME>>%s",LOCKFILE,LOCKFILE,LOCKFILE); 71 system(str); 54 72 55 73 … … 81 99 signal(SIGUSR1, &SignalHandler); 82 100 siginterrupt (SIGUSR1, true); 101 102 // Install signals to assure that the lock file is deleted in case of a program crash 103 signal(SIGQUIT, &CrashHandler); 104 signal(SIGILL, &CrashHandler); 105 signal(SIGABRT, &CrashHandler); 106 signal(SIGFPE, &CrashHandler); 107 signal(SIGSEGV, &CrashHandler); 108 signal(SIGBUS, &CrashHandler); 109 signal(SIGTERM, &CrashHandler); 110 signal(SIGINT, &CrashHandler); 111 signal(SIGHUP, &CrashHandler); 112 83 113 84 114 // Create threads … … 116 146 return 0; 117 147 } 148 149 // Remove lock file before running default signal code 150 void CrashHandler(int Signal) { 151 remove(LOCKFILE); 152 printf("Caught signal number %d. Removing lockfile and performing standard signal action. Good luck.\n",Signal); 153 signal(Signal, SIG_DFL); 154 raise(Signal); 155 } -
hvcontrol/src/CCCommand.cc
r14 r35 79 79 m->status->Pc = comline; 80 80 81 sprintf(str,"Test in CCComand: %s",m->status->Pc);82 printf(str);83 81 84 82 ParseInput(m->status->Pc,&(m->status->NParam),m->status->Param); -
hvcontrol/src/HV.cc
r14 r35 334 334 335 335 unsigned char wbuf[] = {0,0,0}; 336 336 337 337 if (!(hv>=0.0 && hv<=0X3FFF)) { 338 338 fprintf(fptr," Error: HV beyond limits [0 - 0x3FFF]\n"); 339 339 return 0; 340 340 } 341 341 342 342 343 switch (chain) { -
hvcontrol/src/HVConfig.cc
r14 r35 36 36 fTimeOut = 1.; 37 37 IsDAC = true; 38 DACMin = 11008; 39 DACMax = 12496; 40 HVMin = 67.0; 41 HVMax = 76.0; 38 42 fHVCalibOffset = -.8; 39 43 fHVCalibSlope = 0.0064; … … 91 95 ReadCard("CCClient", fCCClient, 's', f); 92 96 ReadCard("IsDAC", &str, 's', f); 97 ReadCard("DACMin", &DACMin, 'I', f); 98 ReadCard("DACMax", &DACMax, 'I', f); 99 ReadCard("HVMin", &HVMin, 'f', f); 100 ReadCard("HVMax", &HVMax, 'f', f); 93 101 ReadCard("HVCalibOffset", &fHVCalibOffset, 'f', f); 94 102 ReadCard("HVCalibSlope", &fHVCalibSlope, 'f', f); … … 121 129 fprintf(fptr," CCClient: %s\n\n", fCCClient); 122 130 fprintf(fptr," Set DAC values: %s\n\n", IsDAC ? "yes" : "no"); 131 fprintf(fptr," DACMin value: %d\n\n", DACMin); 132 fprintf(fptr," DACMax value: %d\n\n", DACMax); 133 fprintf(fptr," HVMin value: %f\n\n", HVMin); 134 fprintf(fptr," HVMax value: %f\n\n", HVMax); 123 135 fprintf(fptr," HVCalibOffset : %f\n\n", fHVCalibOffset); 124 136 fprintf(fptr," HVCalibSlope : %f\n\n", fHVCalibSlope); … … 166 178 fprintf(f,"CCClient %s # Central Control client name\n\n",fCCClient); 167 179 fprintf(f,"IsDAC %s # Define here if user input is interpreted as DAC value or voltage\n\n",((IsDAC) ? "TRUE" : "FALSE")); 180 fprintf(f,"DACMin %d # Starting point for calibration of DAC to voltage values\n",DACMin); 181 fprintf(f,"DACMax %d # End point for calibration of DAC to voltage values\n",DACMax); 182 fprintf(f,"HVMin %f # Starting point for calibration of voltage to DAC values\n",HVMin); 183 fprintf(f,"HVMax %f # End point for calibration of voltage to DAC values\n",HVMax); 168 184 fprintf(f,"HVCalibOffset %f # Calibration of DAC to voltage values\n",fHVCalibOffset); 169 185 fprintf(f,"HVCalibSlope %f # Calibration of DAC to voltage values\n\n",fHVCalibSlope); -
hvcontrol/src/HVConfig.h
r14 r35 36 36 float fStatusRefreshRate; 37 37 38 int DACMin; 39 int DACMax; 40 float HVMin; 41 float HVMax; 42 38 43 float fHVCalibOffset; 39 44 float fHVCalibSlope; -
hvcontrol/src/HVStatus.cc
r14 r35 162 162 163 163 if (status->Socket != -1) // Print status string to socket if open 164 write(status->Socket,str,strlen(str) );164 write(status->Socket,str,strlen(str)+1); 165 165 166 166 } -
hvcontrol/src/ProcessIO.cc
r14 r35 22 22 status = new Status; 23 23 config = new HVConfig(stdout,ConfigFile); 24 calib = new HVCalib(config); 24 25 log = new Log(config->fLogPath); 25 26 hv = new HV(config->fUSBDevice,config->USBDeviceNumber,stdout); 27 28 pm = new PixelMap("../fact_repos.svn/config/PixelMap.txt"); 26 29 27 30 // Initialize status structure (HVStatus.cc/h) … … 85 88 config->WriteHVConfig(stdout,config->FileName); 86 89 87 if (hv) delete hv; 88 if (status) delete status; 89 if (config) delete config; 90 if (log) delete log; 90 delete hv; 91 delete status; 92 delete config; 93 delete log; 94 delete pm; 91 95 92 96 } … … 104 108 puts(" help Print help"); 105 109 puts(" hv <ch>|<all> [b][x]<v> Set chan. <ch>|<all> chan. of active chain(s)/board(s) to <v>"); 106 puts(" hvdiff <ch>|<all> [b][x]<diff> Set chan. <ch>|<all> chan. of active chain(s)/board(s) to <diff>"); 110 // puts(" hvdiff <ch>|<all> [b][x]<diff> Set chan. <ch>|<all> chan. of active chain(s)/board(s) to <diff>"); 111 puts(" hvdiff <PXL id> <diff> Set HV difference of pixel PXL id to <diff>"); 107 112 puts(" list List all HV boards"); 108 113 puts(" load <file> Load HV settings from <file>"); … … 128 133 int ProcessIO::CommandControl() { 129 134 130 // bool IsDAC;131 // float fHVCalibOffset;132 // float fHVCalibSlope;133 // float fHVMaxDiff;134 135 135 136 136 // Adress HV board … … 340 340 } 341 341 342 if (!(config->IsDAC))343 hvoltage=(unsigned int)((hvoltageV-config->fHVCalibOffset)/config->fHVCalibSlope);344 342 345 343 StopMonitor(); … … 350 348 for (int j=status->FirstChain;j<=status->LastChain;j++) { 351 349 if (!allchannels) { 352 if ((hv->GetHVBoard(i))->SetHV(stdout,j,channel,hvoltage,rbuf,status->Verbose)==1) { 353 350 // Convert from HV to DAC values 351 if (!(config->IsDAC)) 352 hvoltage = calib->HVToDAC(hvoltageV,i,j,channel); 353 if ((hv->GetHVBoard(i))->SetHV(stdout,j,channel,hvoltage,rbuf,status->Verbose)==1){ 354 354 status->HV[i][j][channel]=hvoltage; 355 sprintf(str, "Test1 status->HV = %d\n",hvoltage);356 DoPrompt(str);357 355 UpdateStatus(i,rbuf); 358 356 … … 370 368 errors++; 371 369 } 372 373 370 } 371 374 372 else { 375 376 373 sprintf(str,"updating board %d chain %d\n",hv->GetHVBoard(i)->GetBoardNumber(),j); 377 374 DoPrompt(str); 378 375 379 380 376 for (int k=0;k<MAX_NUM_CHANNELS;k++) { 377 // Convert from HV to DAC values 378 if (!(config->IsDAC)) 379 hvoltage = calib->HVToDAC(hvoltageV,i,j,k); 381 380 if ((hv->GetHVBoard(i))->SetHV(stdout,j,k,hvoltage,rbuf,status->Verbose)==1) { 382 383 381 status->HV[i][j][k]=hvoltage; 384 382 UpdateStatus(i,rbuf); … … 436 434 int hvdiff = 0; 437 435 unsigned int hvoltage = 0; 436 float hvoltageV = 0.0; 438 437 float hvdiffV = 0.0; 439 int channel = 0; 440 bool allchannels = FALSE; 438 std::string pixelname(status->Param[1]); 439 unsigned int board = 0; 440 unsigned int chain = 0; 441 unsigned int channel = 0; 442 441 443 442 444 if (status->Param[1][0]>0 && status->Param[2][0]>0) { 443 445 446 447 // Set board 448 board = pm->Pixel_to_HVboard(pixelname); 449 // std::cout << "Board: " << board << std::endl; 450 // Set chain 451 chain = pm->Pixel_to_HVchain(status->Param[1]); 452 // std::cout << "Chain: " << chain << std::endl; 444 453 // Set channel 445 if (IsNoDigit(status->Param[1])) 446 channel = atoi(status->Param[1]); 447 else if(status->Param[1][0] == 'a') 448 allchannels = TRUE; 449 else { 450 DoPrompt("error: wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n"); 451 return 0; 452 } 454 channel = pm->Pixel_to_HVchannel(status->Param[1]); 455 // std::cout << "Channel: " << channel << std::endl; 456 457 /* if (IsNoDigit(status->Param[1])) 458 channel = atoi(status->Param[1]); 459 else if(status->Param[1][0] == 'a') 460 allchannels = TRUE; 461 else { 462 DoPrompt("error: wrong input format - usage: hvdiff <channel>|<all> <hv difference>\n"); 463 return 0; 464 }*/ 453 465 454 466 // Binary input … … 481 493 return 0; 482 494 } 483 else if (hvdiff>0X3FFF) { 484 DoPrompt("difference of high voltage out of range (Vmin: -16383, Vmax: 16383)!\n"); 485 return 0; 486 } 487 else if (hvdiffV>78.0 && (-78.0<hvdiffV)) { 488 DoPrompt("difference of high voltage out of range (Vmin: -78.0, Vmax: 78.0)!\n"); 489 return 0; 490 } 491 495 else if (hvdiff>config->DACMax || hvdiff <(-(config->DACMax))) { 496 sprintf(str,"difference of high voltage [hvdiff:%d] out of range (Vmin: 0.0, Vmax: %d)!\n", hvdiff,config->DACMax); 497 DoPrompt(str); 498 return 0; 499 } 500 else if (hvdiffV>(calib->DACToHV(config->DACMax,0,0,0))|| hvdiffV<-(calib->DACToHV(config->DACMax,0,0,0))) { 501 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)); 502 DoPrompt(str); 503 return 0; 504 } 505 506 //Convert from HV to DAC values 492 507 if (!(config->IsDAC)){ 493 hvdiff=(int)(hvdiffV/config->fHVCalibSlope); 508 hvoltage = status->HV[board][chain][channel]; 509 hvoltageV = calib->DACToHV(hvoltage,board,chain,channel); 510 hvoltageV = hvoltageV + hvdiffV; 511 hvdiff = calib->HVToDAC(hvoltageV,board,chain,channel) - hvoltage; 494 512 } 495 513 StopMonitor(); 496 514 497 498 for (int i=status->FirstBoard;i<=status->LastBoard;i++) { 499 500 for (int j=status->FirstChain;j<=status->LastChain;j++) { 501 if (!allchannels) { 502 hvoltage = status->HV[i][j][channel]; 503 for (int k=0;k<=abs((int)(hvdiff/config->fHVMaxDiff));k++){ 504 if (k<abs((int)(hvdiff/config->fHVMaxDiff))){ 505 hvoltage=(unsigned int)(hvoltage + config->fHVMaxDiff*hvdiff/abs(hvdiff)); 506 } 507 if (k==(int)(abs((int)(hvdiff/config->fHVMaxDiff)))){ 508 hvoltage=(unsigned int)(hvoltage + (hvdiff%(int)config->fHVMaxDiff)); 509 } 510 511 512 status->HV[i][j][channel]=hvoltage; 513 if ((hv->GetHVBoard(i))->SetHV(stdout,j,channel,hvoltage,rbuf,status->Verbose)==1) { 514 UpdateStatus(i,rbuf); 515 sprintf(str,"board %d: high voltage of chain %d channel %d set to %d | 0X%.4X\n",hv->GetHVBoard(i)->GetBoardNumber(),j,channel,hvoltage,hvoltage); 516 DoPrompt(str); 517 if (status->Verbose) { 518 sPrintStatus(status,str,i); 519 DoPrompt(str); 520 } 521 sPrintStatus(status,str,i); // Print status only to socket 522 } 523 else { 524 sprintf(str,"board %d error: could not set hv - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber()); 525 DoPrompt(str); 526 errors++; 527 } 528 // Sleep(1); 529 } 515 516 517 hvoltage = status->HV[board][chain][channel]; 518 for (int k=0;k<=abs((int)(hvdiff/config->fHVMaxDiff));k++){ 519 if (k<abs((int)(hvdiff/config->fHVMaxDiff))){ 520 hvoltage=(unsigned int)(hvoltage + config->fHVMaxDiff*hvdiff/abs(hvdiff)); 521 } 522 if (k==(int)(abs((int)(hvdiff/config->fHVMaxDiff)))){ 523 hvoltage=(unsigned int)(hvoltage + (hvdiff%(int)config->fHVMaxDiff)); 524 } 525 526 527 status->HV[board][chain][channel]=hvoltage; 528 if ((hv->GetHVBoard(board))->SetHV(stdout,chain,channel,hvoltage,rbuf,status->Verbose)==1) { 529 UpdateStatus(board,rbuf); 530 if (k==(int)(abs((int)(hvdiff/config->fHVMaxDiff)))){ 531 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); 532 DoPrompt(str); 533 sPrintStatus(status,str,board); // Print status only to socket 530 534 } 531 else { 532 533 sprintf(str,"updating board %d chain %d\n",hv->GetHVBoard(i)->GetBoardNumber(),j); 534 DoPrompt(str); 535 536 537 for (int k=0;k<MAX_NUM_CHANNELS;k++) { 538 int hvoltage = status->HV[i][j][k]; 539 for (int l=0;l<=abs((int)(hvdiff/config->fHVMaxDiff));l++){ 540 if (l<abs((int)(hvdiff/config->fHVMaxDiff))) 541 hvoltage=(unsigned int)(hvoltage + config->fHVMaxDiff*hvdiff/abs(hvdiff)); 542 if (l==(int)(abs((int)(hvdiff/config->fHVMaxDiff)))) 543 hvoltage=(unsigned int)(hvoltage + (hvdiff%(int)config->fHVMaxDiff)); 544 status->HV[i][j][k]=hvoltage; 545 if ((hv->GetHVBoard(i))->SetHV(stdout,j,k,hvoltage,rbuf,status->Verbose)==1) { 546 547 UpdateStatus(i,rbuf); 548 549 if (status->Verbose) { 550 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); 551 DoPrompt(str); 552 sPrintStatus(status,str,i); 553 DoPrompt(str); 554 } 555 sPrintStatus(status,str,i); // Print status only to socket 556 557 } 558 else { 559 sprintf(str,"board %d error: could not set HV - check timeout and try again\n",hv->GetHVBoard(i)->GetBoardNumber()); 560 DoPrompt(str); 561 errors++; 562 } 563 // Sleep(0.001); 564 } 565 } 566 } 567 } 568 } 535 } 536 else { 537 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); 538 DoPrompt(str); 539 errors++; 540 } 541 } // for loop over k 542 // Sleep(1); 543 if (status->Verbose) { 544 sPrintStatus(status,str,board); 545 DoPrompt(str); 546 } 547 548 569 549 StartMonitor(); 570 550 571 551 if (errors) { 572 sprintf(str,"warning %d error(s) => check timeout and try again\n",errors);552 sprintf(str,"warning %d error(s)\n",errors); 573 553 DoPrompt(str); 574 554 } … … 579 559 } 580 560 else { 581 sprintf(str,"usage: hvdiff < channel>|<all> <hv difference>\n");561 sprintf(str,"usage: hvdiff <PXL id> <hv difference>\n"); 582 562 DoPrompt(str); 583 563 } 584 564 return 0; 585 565 586 566 } 587 567 588 568 // End: Write difference of high voltage -------------------------------------------------------------------- -
hvcontrol/src/ProcessIO.h
r14 r35 28 28 #include "Log.h" 29 29 #include "HVConfig.h" 30 #include "HVCalib.h" 30 31 #include "Utilities.h" 31 32 #include "HV.h" 33 34 #include <iostream> 35 #include "../../fact_repos.svn/pixelmap/PixelMap.h" 32 36 33 37 … … 45 49 char bdata[16]; 46 50 51 PixelMap *pm; 52 47 53 public: 48 54 49 55 HVConfig* config; 56 HVCalib* calib; 50 57 Status* status; 51 58 Log* log;
Note:
See TracChangeset
for help on using the changeset viewer.