Changeset 230 for hvcontrol/src
- Timestamp:
- 06/24/10 14:16:17 (14 years ago)
- Location:
- hvcontrol/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/src/HV.cc
r229 r230 27 27 strcpy(BoardName, Name.c_str()); 28 28 29 stringstream Buf;30 Buf << setw(2) << BoardNumber;31 string Result =Buf.str();32 33 29 // Create DIM services 34 NameService = new DimService ((SERVER_NAME"/NAME/ID"+Result).c_str(), BoardName); 35 BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+Result).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double)); 36 30 stringstream ID; 31 ID << setfill('0') << setw(2) << BoardNumber; 32 33 NameService = new DimService ((SERVER_NAME"/NAME/ID"+ID.str()).c_str(), BoardName); 34 BiasVolt = new DimService ((char *) (SERVER_NAME"/VOLT/ID"+ID.str()).c_str(), (char *) "D", HVV, NUM_CHAINS*NUM_CHANNELS*sizeof(double)); 35 36 // Initialise board variables 37 37 for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = false; 38 38 ResetButton = false; … … 43 43 ClearVoltageArrays(); 44 44 45 // Open device 45 46 if ((fDescriptor = open(("/dev/"+Name).c_str(), O_RDWR|O_NOCTTY|O_NDELAY)) == -1) { 46 if(errno != 2) m->PrintMessage( All,"Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno));47 if(errno != 2) m->PrintMessage("Error: Could not open device %d/%s (%s)\n", DeviceNumber, Name.c_str(), strerror(errno)); 47 48 return; 48 49 } … … 50 51 // Get current serial port settings 51 52 if (tcgetattr(fDescriptor, &tio) == -1) { 52 m->PrintMessage( All,"Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno));53 m->PrintMessage("Error: tcgetattr() failed (%d/%s)\n", errno, strerror(errno)); 53 54 return; 54 55 } 55 56 56 57 // Set baudrate and raw mode 57 if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage( All,"Error: Could not set baud rate (%s)\n", strerror(errno));58 if (cfsetspeed(&tio, BAUDRATE) == -1) m->PrintMessage("Error: Could not set baud rate (%s)\n", strerror(errno)); 58 59 cfmakeraw(&tio); 59 if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage( All,"Error: tcsetattr() failed (%s)\n", strerror(errno));60 if (tcsetattr(fDescriptor, TCSANOW, &tio ) == -1) m->PrintMessage("Error: tcsetattr() failed (%s)\n", strerror(errno)); 60 61 61 62 // Synchronize HV board (if fails, closes device and sets fDescriptor to -2) … … 100 101 // === Write data === 101 102 if ((ret=write(fDescriptor, wbuf, Bytes)) < Bytes) { 102 if (ret == -1) m-> PrintMessage(All, "Could not write data to HV board (%s)\n", strerror(errno));103 else m-> PrintMessage(All, "Could write only %d of %d bytes to HV board\n", ret, Bytes);103 if (ret == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno)); 104 else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", ret, Bytes); 104 105 ErrorCount++; 105 106 return 0; … … 110 111 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)}; 111 112 if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) { 112 m-> PrintMessage(All, "Error with select() (%s)\n", strerror(errno));113 m->Message(m->ERROR, "Error with select() (%s)", strerror(errno)); 113 114 return 0; 114 115 } … … 118 119 // Read error? 119 120 if ((ret = read(fDescriptor, &rbuf, 1)) == -1) { 120 m-> PrintMessage(All, "Read error (%s)\n", strerror(errno));121 m->Message(m->ERROR, "Read error (%s)", strerror(errno)); 121 122 ErrorCount++; 122 123 return 0; -
hvcontrol/src/ProcessIO.cc
r229 r230 64 64 // Get configuration data 65 65 vector<string> Boards = Tokenize(GetConfig("Boards"), " \t"); 66 fPixMapTable = GetConfig("PixMapTable");67 66 fTimeOut = atof(GetConfig("TimeOut").c_str()); 68 67 fStatusRefreshRate = atof(GetConfig("StatusRefreshRate").c_str()); … … 84 83 } 85 84 else { 86 PrintMessage(All, "Failed to synchronize board %d (%s)\n", NumHVBoards, fHVBoard[NumHVBoards]->BoardName);85 Message(WARN, "Failed to synchronize board %d (%s)", NumHVBoards, fHVBoard[NumHVBoards]->BoardName); 87 86 delete fHVBoard[NumHVBoards]; 88 87 } … … 92 91 // Create instances 93 92 calib = new HVCalib(this); 94 pm = new PixelMap( fPixMapTable);93 pm = new PixelMap(GetConfig("PixMapTable")); 95 94 96 95 // Install DIM command (after all initialized) … … 196 195 void ProcessIO::cmd_config() { 197 196 198 PrintMessage( " Pixel map table: %s\n" 199 " %d USB devices:\n", fPixMapTable.c_str(), NumHVBoards); 197 PrintMessage( " %d USB devices:\n", NumHVBoards); 200 198 201 199 for (int i=0; i<NumHVBoards; i++) PrintMessage(" Board %d: %s\n", i, fHVBoard[i]->BoardName); … … 414 412 state = active; 415 413 pthread_kill(HVMonitor, SIGUSR1); 416 PrintMessage(All, "Status monitoring activated\n");414 Message(INFO, "Status monitoring activated"); 417 415 } 418 416 … … 448 446 state = stopped; 449 447 pthread_kill(HVMonitor, SIGUSR1); 450 PrintMessage(All, "Status monitor stopped\n");448 Message(INFO, "Status monitor stopped"); 451 449 } 452 450 … … 481 479 482 480 483 // Print message to selected target 484 void ProcessIO::PrintMessage(MsgTarget Target, const char *Format, ...) { 485 486 va_list ArgumentPointer; 487 va_start(ArgumentPointer, Format); 488 DoPrintMessage(Format, ArgumentPointer, Target); 489 va_end(ArgumentPointer); 490 } 491 492 // Print message to log file, and screen or socket (depending on command origin) 481 // Print message to screen and to DIM text service 493 482 void ProcessIO::PrintMessage(const char *Format, ...) { 494 483 484 static char Error[] = "vasprintf() failed in PrintMessage()"; 485 char *Text; 486 487 // Evaluate arguments 495 488 va_list ArgumentPointer; 496 489 va_start(ArgumentPointer, Format); 497 DoPrintMessage(Format, ArgumentPointer, Console);490 if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error; 498 491 va_end(ArgumentPointer); 499 } 500 501 // Function doing the actual printing work 502 // Be careful with overloading variadic functions! 503 void ProcessIO::DoPrintMessage(const char *Format, va_list ArgumentPointer, MsgTarget Target) { 504 505 static char Error[] = "vasprintf() failed in DoPrintMessage()"; 506 char *Text; 507 508 // Evaluate arguments 509 if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error; 510 492 511 493 // Print to console 512 if(Target & Console) { 513 if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt 514 else printf("%s", Text); 515 fflush(stdout); 516 } 517 518 // Send to DIM console service and log 494 if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt 495 else printf("%s", Text); 496 fflush(stdout); 497 498 // Send to DIM text service 519 499 ConsoleOut->updateService(Text); 520 if(Target & Log) SendToLog("%s %s", SERVER_NAME, Text);521 500 522 501 // Free old text … … 524 503 ConsoleText = Text; 525 504 } 505 526 506 527 507 // Ramp to new voltage with maximum step size given in fHVMaxDiff … … 558 538 if (!Warned) { 559 539 Warned = true; 560 PrintMessage(All, "Warning: Some board has many read/write errors, status monitor disabled\n"); 561 Message(WARN, "Warning: Some board has many read/write errors, status monitor disabled\n"); 540 Message(WARN, "Warning: Board %d has many read/write errors, status monitor disabled", i); 562 541 } 563 542 continue; … … 565 544 566 545 if (fHVBoard[i]->GetStatus() != 1) { 567 PrintMessage(All, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber()); 568 Message(ERROR, "Error: Monitor could not read status of board %d\n", fHVBoard[i]->GetBoardNumber()); 546 Message(ERROR, "Error: Monitor could not read status of board %d", fHVBoard[i]->GetBoardNumber()); 569 547 } 570 548 571 549 if (fHVBoard[i]->ResetButton) { 572 PrintMessage(All, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber()); 573 Message(INFO, "Manual reset of board %d\n",fHVBoard[i]->GetBoardNumber()); 550 Message(INFO, "Manual reset of board %d", fHVBoard[i]->GetBoardNumber()); 574 551 ResetBoard(i); 575 552 } 576 553 577 554 if (!fHVBoard[i]->WrapOK) { 578 PrintMessage(All, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber()); 579 Message(ERROR, "Error: Wrap counter mismatch board %d\n",fHVBoard[i]->GetBoardNumber()); 555 Message(ERROR, "Error: Wrap counter mismatch board %d",fHVBoard[i]->GetBoardNumber()); 580 556 } 581 557 582 558 for (int j=0; j<NUM_CHAINS; j++) { 583 559 if (fHVBoard[i]->Overcurrent[j]) { 584 PrintMessage(All, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber()); 585 Message(WARN, "Warning: Overcurrent in chain %d of board %d\n",j,fHVBoard[i]->GetBoardNumber()); 560 Message(WARN, "Warning: Overcurrent in chain %d of board %d",j,fHVBoard[i]->GetBoardNumber()); 586 561 ResetBoard(i); 587 562 } … … 631 606 } 632 607 633 if (getCommand() == Command) CommandControl(getCommand()->getString()); 608 if ((getCommand()==Command) && (*(Command->getString()+Command->getSize()-1)=='\0')) { 609 SendToLog("Command '%s' from %s (ID %d)", Command->getString(), getClientName(), getClientId()); 610 CommandControl(Command->getString()); 611 } 634 612 635 613 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) { -
hvcontrol/src/ProcessIO.h
r229 r230 26 26 #define MAX_RATE 50.0 27 27 28 enum MsgTarget {Console=1, Log=2, All=7};29 28 typedef enum stateenum {active, stopped, na} state_enum; 30 29 … … 47 46 48 47 // Configuration data 49 std::string fPixMapTable;50 48 float fTimeOut; 51 49 float fStatusRefreshRate; … … 69 67 ~ProcessIO(); 70 68 71 void PrintMessage(MsgTarget, const char *, ...);72 69 void PrintMessage(const char *, ...); 73 void DoPrintMessage(const char *, va_list, MsgTarget);74 70 void CommandControl(char*); 75 71 bool RampVoltage(unsigned int, int, int, int);
Note:
See TracChangeset
for help on using the changeset viewer.