Changeset 93 for hvcontrol/src/ProcessIO.cc
- Timestamp:
- 07/28/09 09:15:18 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/src/ProcessIO.cc
r90 r93 14 14 static char* state_str[] = {"active", "stopped", "n.a."}; 15 15 16 ProcessIO::ProcessIO(char *ConfigFile) { 16 17 ProcessIO::ProcessIO(const char *ConfigFile) { 17 18 18 19 // Get program start time … … 20 21 21 22 // Create instances 22 config = new HVConfig( stdout,ConfigFile);23 config = new HVConfig(ConfigFile); 23 24 calib = new HVCalib(config); 24 25 pm = new PixelMap(config->fPixMapTable); … … 44 45 if(config->TestMode){ 45 46 fprintf(stdout,"Test mode: One HVBoard initialized as dummy.\n"); 46 fHVBoard[NumHVBoards] = new HVBoard(0, 0, config->TestMode, config->fTimeOut, Verbose);47 fHVBoard[NumHVBoards] = new HVBoard(0, 0, this); 47 48 NumHVBoards++; 48 49 } 49 50 else { 50 51 for (int i=0; i<config->NumHVBoards; i++) { 51 fHVBoard[NumHVBoards] = new HVBoard(config->USBDeviceNumber[i], config->fUSBDevice[i], config->TestMode, config->fTimeOut, Verbose);52 fHVBoard[NumHVBoards] = new HVBoard(config->USBDeviceNumber[i], config->fUSBDevice[i], this); 52 53 if(fHVBoard[NumHVBoards]->fDescriptor >= 0) { 53 54 printf("Synchronized and reset HV board %d (%s)\n",i,config->fUSBDevice[i]); … … 66 67 PrintMessage(MsgToLog,"********** Logging started **********\n"); 67 68 68 // Print configuration to log file 69 if(Logfile) config->PrintHVConfig(Logfile); 69 // Create instance of slow data class 70 SlowDataClass = new SlowData("HV", config->fSlowDir); 71 if (SlowDataClass->ErrorCode != 0) { 72 PrintMessage("Warning: Could not open slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode)); 73 } 74 SlowDataClass->NewEntry("Value-Info", "Issued if new HV value set successfull: Board-Num HV-Board-Name Chain Channel DAC-Target Converted-Value"); 75 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"); 70 76 } 71 77 … … 75 81 for (int i=0; i<NumHVBoards; i++) delete fHVBoard[i]; 76 82 77 delete config; delete pm;83 delete SlowDataClass; delete config; delete pm; 78 84 79 85 if(Logfile != NULL) { … … 156 162 // Print HV utility configuration 157 163 else if (Match(Param[0], "config")) { 158 159 config->PrintHVConfig(stdout); 160 164 PrintMessage( " Log file: %s\n" 165 " Pixel map table: %s\n" 166 " Test mode: %s\n" 167 " %d USB devices:\n", config->fLogFile, config->fPixMapTable, 168 config->TestMode ? "yes" : "no", config->NumHVBoards); 169 for (int i=0;i<NumHVBoards;i++) { 170 PrintMessage(" Board%d: %s\n ", config->USBDeviceNumber[i], config->fUSBDevice[i]); 171 } 172 PrintMessage( "\n TimeOut: %.2f s\n" 173 " StatusRefreshRate: %.2f Hz\n" 174 " CCPort: %d\n" 175 " DACMin value: %d\n" 176 " DACMax value: %d\n" 177 " HVCalibOffset : %f\n" 178 " HVCalibSlope : %f\n" 179 " HVMaxDiff : %u\n", config->fTimeOut, 180 config->fStatusRefreshRate, config->fCCPort, config->DACMin, 181 config->DACMax, config->fHVCalibOffset, config->fHVCalibSlope, 182 config->fHVMaxDiff); 183 161 184 return; 162 185 } … … 287 310 } 288 311 289 StopMonitor();290 291 312 while (fgets(Buffer, sizeof(Buffer), File) != NULL) { 292 313 for (int Board=0; Board<NumHVBoards; Board++) { … … 314 335 } // while() 315 336 316 StartMonitor();317 318 337 if (NBoards != NumHVBoards) { 319 338 PrintMessage("Warning: Could not load HV settings for all connected HV boards\n"); … … 333 352 double Rate; 334 353 335 if (!NumHVBoards) return;336 337 354 if (NParam != 2) { 338 355 PrintMessage("Usage: rate <Hz>\n"); … … 351 368 } 352 369 353 StopMonitor();354 370 fStatusRefreshRate = Rate; 355 371 PrintMessage("Refresh rate set to %.2f Hz\n", fStatusRefreshRate); 356 StartMonitor();357 372 358 373 return; … … 363 378 364 379 if (!NumHVBoards) return; 365 366 StopMonitor(); 367 ResetActiveBoards(); 368 StartMonitor(); 380 for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i); 369 381 return; 370 382 } … … 416 428 else if (Match(Param[0], "start")) { 417 429 418 if (!NumHVBoards) return; 419 420 StartMonitor(); 430 state = active; 431 pthread_kill(HVMonitor, SIGUSR1); 421 432 PrintMessage("OK - status monitoring activated\n"); 422 423 433 return; 424 434 } … … 463 473 else if (Match(Param[0], "stop")) { 464 474 465 if (!NumHVBoards) return; 466 467 StopMonitor(); 475 state = stopped; 476 pthread_kill(HVMonitor, SIGUSR1); 468 477 PrintMessage("Status monitor stopped\n"); 469 478 … … 594 603 bool ProcessIO::RampVoltage(unsigned int Target, int Board, int Chain, int Channel) { 595 604 596 int Diff;597 598 605 while (fHVBoard[Board]->HV[Chain][Channel] != (int) Target) { 599 Diff = Target - fHVBoard[Board]->HV[Chain][Channel];606 int Diff = Target - fHVBoard[Board]->HV[Chain][Channel]; 600 607 if (Diff > (int) config->fHVMaxDiff) Diff = config->fHVMaxDiff; 601 608 602 if (fHVBoard[Board]->SetHV( stdout, Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff, Verbose)==1) {609 if (fHVBoard[Board]->SetHV(Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff) == 1) { 603 610 fHVBoard[Board]->HV[Chain][Channel] += Diff; 604 611 … … 610 617 else { 611 618 PrintMessage("ERROR - Could not set HV of board %d, chain %d, channel %d. Skipping channel\n",fHVBoard[Board]->GetBoardNumber(),Chain,Channel); 619 SlowDataClass->NewEntry("Error"); 620 SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel)); 612 621 return false; 613 622 } 614 623 } 624 SlowDataClass->NewEntry("Value"); 625 SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel)); 615 626 return true; 616 627 } 617 628 618 void ProcessIO::StartMonitor() { 619 620 state = active; 621 pthread_kill(HVMonitor, SIGUSR1); 622 } 623 624 625 void ProcessIO::StopMonitor() { 626 627 state = stopped; 628 pthread_kill(HVMonitor, SIGUSR1); 629 } 630 631 629 630 // Check board status 632 631 void ProcessIO::Monitor() { 633 632 634 633 for (int i=0; i<NumHVBoards; i++) { 635 634 636 if (fHVBoard[i]->GetStatus( stdout,false)!=1) {635 if (fHVBoard[i]->GetStatus() != 1) { 637 636 PrintMessage("Error: Monitor, could not read status of board %d\n", fHVBoard[i]->GetBoardNumber()); 638 637 } … … 653 652 } 654 653 } 655 } 656 } 657 658 659 void ProcessIO::ResetActiveBoards() { 660 661 for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i); 662 } 663 664 654 655 } 656 } 657 658 659 // Send reset to board and clear voltage arrays 665 660 void ProcessIO::ResetBoard(int i) { 666 661 667 if (fHVBoard[i]->Reset( stdout,Verbose) == 1) {662 if (fHVBoard[i]->Reset() == 1) { 668 663 PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber()); 669 664 PrintBoardStatus(i); … … 673 668 674 669 670 // Get index of board with sequential number board 675 671 int ProcessIO::GetBoardIdx(int board) { 676 672 … … 681 677 } 682 678 683 679 // Print current board status 684 680 void ProcessIO::PrintBoardStatus(int i) { 685 681 … … 716 712 } 717 713 714 718 715 // Check if two strings match (min 1 character must match) 719 716 bool Match(const char *str, const char *cmd) { … … 721 718 } 722 719 720 723 721 // Convert string to double 724 722 // Returns false if conversion did not stop on whitespace or EOL character
Note:
See TracChangeset
for help on using the changeset viewer.