Changeset 264
- Timestamp:
- 07/27/10 07:27:04 (14 years ago)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r263 r264 32 32 33 33 // Constructor: Subscribe to be informed on configuration file change 34 EvidenceServer::Config::Config(): Dim RpcInfo("ConfigRequest", NO_LINK),35 Dim Command((This->Name+"/ResetMessage").c_str(), (char *) "") {34 EvidenceServer::Config::Config(): DimCommand((This->Name+"/ResetMessage").c_str(), (char *) ""), 35 DimRpcInfo("ConfigRequest", NO_LINK) { 36 36 37 37 CurrentItem = string(); -
hvcontrol/History.txt
r230 r264 38 38 removed 'chain' command. 39 39 24/6/2010 Removed 'Target' from PrintMessage (can now use SendToLog() if needed) 40 20/7/2010 Removed all mutex locking. Communicate() uses now lockf() to serialize access. -
hvcontrol/hvcontrol.cpp
r226 r264 117 117 void HVMonitor(ProcessIO *m) { 118 118 119 120 119 while (!m->ExitRequest) { 121 120 if (m->state == active) m->Monitor(); … … 133 132 // Remove lock file before running default signal code 134 133 void CrashHandler(int Signal) { 134 135 135 remove(LOCKFILE); 136 136 printf("Caught signal number %d. Removing lockfile and performing standard signal action. Good luck.\n",Signal); -
hvcontrol/src/HV.cc
r230 r264 96 96 97 97 unsigned char rbuf; 98 int ret;98 int N, Ret = 0; 99 99 fd_set SelectDescriptor; 100 100 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)}; 101 102 // === Lock file descriptor === 103 if (lockf(fDescriptor, F_LOCK, 0) == -1) { 104 m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno)); 105 return 0; 106 } 107 101 108 // === Write data === 102 if (( ret=write(fDescriptor, wbuf, Bytes)) < 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);109 if ((N = write(fDescriptor, wbuf, Bytes)) < Bytes) { 110 if (N == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno)); 111 else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", N, Bytes); 105 112 ErrorCount++; 106 return 0;113 goto ExitCommunicate; 107 114 } 108 115 109 116 // === Try to read until time-out === 110 117 FD_ZERO(&SelectDescriptor); FD_SET(fDescriptor, &SelectDescriptor); 111 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};112 118 if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) { 113 119 m->Message(m->ERROR, "Error with select() (%s)", strerror(errno)); 114 return 0;120 goto ExitCommunicate; 115 121 } 116 122 // Time-out expired? 117 if (!FD_ISSET(fDescriptor, &SelectDescriptor)) return -1; 123 if (!FD_ISSET(fDescriptor, &SelectDescriptor)) { 124 Ret = -1; 125 goto ExitCommunicate; 126 } 118 127 119 128 // Read error? 120 if ( (ret = read(fDescriptor, &rbuf, 1)) == -1) {129 if (read(fDescriptor, &rbuf, 1) == -1) { 121 130 m->Message(m->ERROR, "Read error (%s)", strerror(errno)); 122 131 ErrorCount++; 123 return 0;132 goto ExitCommunicate; 124 133 } 125 134 … … 132 141 for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = (rbuf & (0X08 << i)); 133 142 ResetButton = (bool) (rbuf & 0X80); 134 135 return 1; 136 } 137 138 139 /* Reset HV board - uses TRead() and has same return values */ 143 Ret = 1; 144 145 // === UnLock file descriptor === 146 ExitCommunicate: 147 if (lockf(fDescriptor, F_LOCK, 0) == -1) { 148 m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno)); 149 return 0; 150 } 151 152 return Ret; 153 } 154 155 156 // Reset HV board 140 157 int HVBoard::Reset() { 141 158 … … 151 168 152 169 153 / * Read status register - uses TRead() and has same return values */170 // Read status register 154 171 int HVBoard::GetStatus() { 155 172 … … 160 177 161 178 162 / * Set high voltage - uses TRead() and has same return values */179 // Set high voltage 163 180 int HVBoard::SetHV(int chain, unsigned int channel, int hv) { 164 181 -
hvcontrol/src/ProcessIO.cc
r230 r264 30 30 {"rate", &ProcessIO::cmd_rate, 1, "<rate>", "Set status refresh rate in Hz"}, 31 31 {"timeout", &ProcessIO::cmd_timeout, 1, "<time>", "Set timeout to return from read in seconds"}, 32 {"reset", &ProcessIO::cmd_reset, 0, "", "Reset active bias board "},32 {"reset", &ProcessIO::cmd_reset, 0, "", "Reset active bias boards"}, 33 33 {"start", &ProcessIO::cmd_start, 0, "", "Start bias status monitor"}, 34 34 {"stop", &ProcessIO::cmd_stop, 0, "", "Stop bias status monitor"}, … … 53 53 FirstBoard = 0; 54 54 LastBoard = -1; 55 56 // Initialize mutex for thread synchronisation57 if (pthread_mutex_init(&Mutex, NULL) != 0) {58 Message(FATAL, "pthread_mutex_init() failed");59 }60 55 61 56 // DIM console service used in PrintMessage() … … 109 104 delete calib; 110 105 delete ConsoleOut; 111 free(ConsoleText); 112 113 // Destroy mutex 114 if (pthread_mutex_destroy(&Mutex) != 0) Message(ERROR, "pthread_mutex_destroy() failed"); 106 free(ConsoleText); 115 107 } 116 108 … … 370 362 void ProcessIO::cmd_reset() { 371 363 372 for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i); 364 for (int i=FirstBoard; i<=LastBoard; i++) { 365 if (fHVBoard[i]->Reset() == 1) { 366 PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber()); 367 PrintBoardStatus(i); 368 } 369 else PrintMessage("Error: Could not reset board %d\n",fHVBoard[i]->GetBoardNumber()); 370 } 373 371 } 374 372 … … 527 525 528 526 static bool Warned = false; 529 int Ret;530 531 // Lock because command execution runs in different thread532 if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {533 Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));534 }535 527 536 528 for (int i=0; i<NumHVBoards; i++) { … … 549 541 if (fHVBoard[i]->ResetButton) { 550 542 Message(INFO, "Manual reset of board %d", fHVBoard[i]->GetBoardNumber()); 551 ResetBoard(i);543 fHVBoard[i]->Reset(); 552 544 } 553 545 … … 558 550 for (int j=0; j<NUM_CHAINS; j++) { 559 551 if (fHVBoard[i]->Overcurrent[j]) { 560 Message(WARN, "Warning: Overcurrent in chain %d of board %d ",j,fHVBoard[i]->GetBoardNumber());561 ResetBoard(i);552 Message(WARN, "Warning: Overcurrent in chain %d of board %d, resetting board",j,fHVBoard[i]->GetBoardNumber()); 553 fHVBoard[i]->Reset(); 562 554 } 563 555 } 564 } 565 566 // Unlock 567 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) { 568 Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret)); 569 } 570 571 } 572 573 574 // Send reset to board and clear voltage arrays 575 void ProcessIO::ResetBoard(int i) { 576 577 if (fHVBoard[i]->Reset() == 1) { 578 PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber()); 579 PrintBoardStatus(i); 580 } 581 else PrintMessage("Error: Could not reset board %d\n",fHVBoard[i]->GetBoardNumber()); 582 } 556 } 557 } 558 583 559 584 560 … … 597 573 598 574 599 // Command handling (mutex needed because of monitor thread)575 // Command handling 600 576 void ProcessIO::commandHandler() { 601 577 602 int Ret;603 604 if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {605 Message(FATAL, "pthread_mutex_lock() failed in commandHandler() (%s)", strerror(Ret));606 }607 608 578 if ((getCommand()==Command) && (*(Command->getString()+Command->getSize()-1)=='\0')) { 609 SendToLog("Command '%s' from %s (ID %d)", Command->getString(), getClientName(), getClientId());610 579 CommandControl(Command->getString()); 611 }612 613 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {614 Message(FATAL, "pthread_mutex_unlock() failed in commandHandler() (%s)", strerror(Ret));615 580 } 616 581 } -
hvcontrol/src/ProcessIO.h
r230 r264 54 54 unsigned int fHVMaxDiff; 55 55 56 // Status variables57 56 pthread_t HVMonitor; // exit function sends signal to these threads 58 pthread_mutex_t Mutex;59 60 57 int NumHVBoards; 61 58 int FirstBoard; … … 71 68 bool RampVoltage(unsigned int, int, int, int); 72 69 void Monitor(); 73 void ResetBoard(int);74 70 void PrintBoardStatus(int); 75 71
Note:
See TracChangeset
for help on using the changeset viewer.