Changeset 10262 for fact/FADctrl
- Timestamp:
- 03/29/11 13:43:25 (14 years ago)
- Location:
- fact/FADctrl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/FADctrl/FAD.cc
r10261 r10262 612 612 if (i<R.Min || i > R.Max) continue; 613 613 614 PrintMessage(" BOARD #%d (%sactive) IP %s Communication %s\n", i, Boards[i]->Active ? "":"in", Boards[i]->Name, Boards[i]->CommOK ? "OK":"ERROR");614 PrintMessage("\nBOARD #%d (%sactive) IP %s Communication %s\n", i, Boards[i]->Active ? "":"in", Boards[i]->Name, Boards[i]->CommOK ? "OK":"ERROR"); 615 615 616 616 // Calibration information … … 620 620 // Status information 621 621 struct FADBoard::BoardStatus S = Boards[i]->GetStatus(); 622 623 PrintMessage("Status: %s\n", S.Message); 622 624 623 625 if (S.Update.tv_sec == -1) { … … 1018 1020 if (Mode != datarun) continue; 1019 1021 1020 // Check if all event numbers of active boards are the same 1021 bool Same = true; 1022 for (unsigned int i=0; i<Boards.size(); i++) { 1023 if (Boards[i]->Active && EventNumbers[i] != EventNumbers[0]) Same = false; 1024 } 1025 if (!Same) continue; 1022 // Check if event numbers of all active boards are the same 1023 unsigned long CommonEventNum = numeric_limits<unsigned long>::max(); 1024 1025 for (unsigned int i=0; i<Boards.size(); i++) if (Boards[i]->Active) { 1026 if (CommonEventNum == numeric_limits<unsigned long>::max()) CommonEventNum = EventNumbers[i]; 1027 if (CommonEventNum != EventNumbers[i]) { 1028 CommonEventNum = numeric_limits<unsigned long>::max(); 1029 break; 1030 } 1031 } 1032 if (CommonEventNum == numeric_limits<unsigned long>::max()) continue; 1026 1033 1027 1034 // Write also run header if this is the first event -
fact/FADctrl/FADBoard.cc
r10261 r10262 47 47 48 48 DIM_Name = new DimService((ID.str()+"Server").c_str(), Name); 49 DIM_Status = new DimService((ID.str()+"Status").c_str(), (char *) ""); 49 50 DIM_ID = new DimService((ID.str()+"BoardID").c_str(), (char *) "S", NULL, 0); 50 51 DIM_Temp = new DimService((ID.str()+"Temperature").c_str(), (char *) "F", NULL, 0); … … 53 54 54 55 // Create thread that connects and receives data 56 SetStatus("Trying to connect"); 57 55 58 if ((Ret = pthread_create(&Thread, NULL, (void * (*)(void *)) LaunchThread,(void *) this)) != 0) { 56 59 m->Message(m->FATAL, "pthread_create() failed in FADBoard() (%s)", strerror(Ret)); … … 77 80 78 81 delete DIM_Name; 82 delete DIM_Status; 79 83 delete DIM_ID; 80 84 delete DIM_Temp; … … 349 353 struct hostent *Host = gethostbyname(Name); 350 354 if (Host == 0) { 351 m->Message(m->WARN, "Could not resolve host name for %s", Name);355 SetStatus("Could not resolve host name '%s'", Name); 352 356 return; 353 357 } … … 365 369 // Connect to server 366 370 if (connect(Socket, (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1) { 367 m->PrintMessage("Could not connect to %s at port %d (%s)\n", Name, Port, strerror(errno));371 SetStatus("Could not connect to port %hu (%s)", Port, strerror(errno)); 368 372 } 369 373 else { 370 374 CommOK = true; 371 375 Active = true; 376 SetStatus("Connected"); 372 377 } 373 378 … … 381 386 // Check result of read 382 387 if (Result == -1) { 383 m-> PrintMessage("Error: Could not read from socket, exiting read loop (%s)\n", strerror(errno));388 m->Message(m->ERROR, "Could not read from socket for %s, exiting read loop (%s)\n", Name, strerror(errno)); 384 389 CommOK = false; 385 390 break; 386 391 } 387 392 else if (Result == 0) { 388 m->PrintMessage("Server not existing anymore, exiting read loop\n");393 SetStatus("Server not existing anymore, exiting read loop"); 389 394 CommOK = false; 390 395 break; … … 399 404 // Check if internal buffer full 400 405 if (Pos == sizeof(Buffer)) { 401 m->PrintMessage("Internal buffer full, deleting all data in buffer\n");406 SetStatus("Internal buffer full, deleting all data in buffer"); 402 407 Pos = 0; 403 408 continue; … … 410 415 memmove(Buffer, Buffer+Temp, Pos-Temp); 411 416 Pos -= Temp; 412 m->PrintMessage("Removed %d bytes because of start_package_flag not found for %s\n", Temp, Name);417 SetStatus("Removed %d bytes because of start_package_flag not found", Temp); 413 418 continue; 414 419 } … … 521 526 } 522 527 } 523 else m->PrintMessage("End package flag incorrect, removing corrupt event\n");528 else SetStatus("End package flag incorrect, removing corrupt event"); 524 529 525 530 // Remove event data from internal buffer … … 532 537 533 538 if (close(Socket) == -1) { 534 m->PrintMessage("Could not close socket descriptor for board %s (%s)", Name, strerror(errno)); 535 } 536 537 } 538 539 m->Message(m->ERROR, "Could not close socket descriptor for board %s (%s)", Name, strerror(errno)); 540 } 541 542 } 539 543 540 544 // … … 544 548 545 549 m->ReadLoop(); 550 } 551 552 553 // 554 // Set status message 555 // 556 void FADBoard::SetStatus(const char *Format, ...) { 557 558 int Ret; 559 560 // Assemble message 561 va_list ArgumentPointer; 562 va_start(ArgumentPointer, Format); 563 Lock(); 564 Ret = vsnprintf(Status.Message, sizeof(Status.Message), Format, ArgumentPointer); 565 Unlock(); 566 va_end(ArgumentPointer); 567 568 if (Ret == -1) m->Message(m->FATAL, "snprintf() in FADBoard::SetStatus() failed (%s)", strerror(errno)); 569 570 // Update status service 571 DIM_Status->updateService(Status.Message); 546 572 } 547 573 … … 571 597 // 572 598 // Open other sockets 599 // 600 // Error reporting is limited as this function is expected to be removed when firmware allows single socket 573 601 // 574 602 void FADBoard::threadHandler() { … … 581 609 // Resolve hostname 582 610 struct hostent *Host = gethostbyname(Name); 583 if (Host == 0) { 584 m->PrintMessage("OtherSockets: Could not resolve host name for %s\n", Name); 585 return; 586 } 611 if (Host == 0) return; 587 612 588 613 // Connect to server … … 594 619 // Open socket descriptor 595 620 if ((Socket[i] = socket(PF_INET, SOCK_STREAM, 0)) == -1) { 596 m-> PrintMessage("OtherSockets: Could not open socket for port %d (%s)\n", List[i], strerror(errno));621 m->Message(m->ERROR, "OtherSockets: Could not open socket for port %d (%s)\n", List[i], strerror(errno)); 597 622 return; 598 623 } … … 601 626 // Connect to server 602 627 SocketAddress.sin_port = htons((unsigned short) List[i]); 603 if (connect(Socket[i], (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1) { 604 m->PrintMessage("OtherSockets: Could not connect to port %d (%s)\n", List[i], strerror(errno)); 605 return; 606 } 628 if (connect(Socket[i], (struct sockaddr *) &SocketAddress, sizeof(SocketAddress)) == -1) return; 607 629 } 608 630 … … 612 634 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) FD_SET(Socket[i], &DescriptorList); 613 635 if (select(MaxSocketNum+1, &DescriptorList, NULL, NULL, NULL) == -1) { 614 m-> PrintMessage("OtherSockets: Error with select() (%s)\n", strerror(errno));636 m->Message(m->ERROR, "OtherSockets: Error with select() (%s)\n", strerror(errno)); 615 637 break; 616 638 } … … 619 641 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) if (FD_ISSET(Socket[i], &DescriptorList)) { 620 642 Ret = read(Socket[i], Buffer, sizeof(Buffer)); 621 if(Ret == 0) m->PrintMessage("OtherSockets: Connection to port %d not existing anymore\n", List[i]); 622 else if (Ret == -1) m->PrintMessage("OtherSockets: Error reading from port %d (%s)\n", List[i], strerror(errno)); 643 if (Ret == -1) m->Message(m->ERROR, "OtherSockets: Error reading from port %d (%s)\n", List[i], strerror(errno)); 623 644 } 624 645 } … … 627 648 for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) { 628 649 if ((Socket[i] != -1) && (close(Socket[i]) == -1)) { 629 m-> PrintMessage("OtherSockets: Could not close socket of port %d (%s)", List[i], strerror(errno));630 } 631 } 632 } 650 m->Message(m->ERROR, "OtherSockets: Could not close socket of port %d (%s)", List[i], strerror(errno)); 651 } 652 } 653 } -
fact/FADctrl/FADBoard.h
r10226 r10262 21 21 22 22 const unsigned int READ_BUFFER_SIZE = 1000000; 23 const unsigned int STATUS_SIZE = 200; 23 24 24 25 class FADBoard: public DimThread { … … 27 28 int Socket; 28 29 pthread_mutex_t Mutex; 29 DimService *DIM_Name, *DIM_ ID, *DIM_Temp, *DIM_ROI, *DIM_DAC;30 DimService *DIM_Name, *DIM_Status, *DIM_ID, *DIM_Temp, *DIM_ROI, *DIM_DAC; 30 31 31 32 void ReadLoop(); 32 33 static void LaunchThread(class FADBoard *); 33 34 void threadHandler(); 35 void SetStatus(const char *, ...); 34 36 35 37 public: … … 43 45 uint32_t BoardTime; 44 46 uint32_t EventCounter; 47 48 char Message[STATUS_SIZE]; 45 49 struct timeval Update; 46 50 … … 93 97 pthread_cond_t CondVar; 94 98 95 // Amplitude calibration99 // Amplitude calibration 96 100 int Count; 97 101 -
fact/FADctrl/History.txt
r10261 r10262 18 18 2/3/2011 Implemented new FAD data format 19 19 28/3/2011 Boards with communication error set themselves inactive 20 29/3/2011 Added Status message service for each board (removed several console messages in turn)
Note:
See TracChangeset
for help on using the changeset viewer.