Changeset 10262


Ignore:
Timestamp:
Mar 29, 2011, 1:43:25 PM (10 years ago)
Author:
neise
Message:
Added status message for each board
Location:
fact/FADctrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fact/FADctrl/FAD.cc

    r10261 r10262  
    612612        if (i<R.Min || i > R.Max) continue;
    613613
    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");
    615615
    616616        // Calibration information
     
    620620        // Status information
    621621        struct FADBoard::BoardStatus S = Boards[i]->GetStatus();
     622
     623        PrintMessage("Status: %s\n", S.Message);
    622624
    623625        if (S.Update.tv_sec == -1) {
     
    10181020        if (Mode != datarun) continue;
    10191021       
    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;
    10261033
    10271034        // Write also run header if this is the first event
  • fact/FADctrl/FADBoard.cc

    r10261 r10262  
    4747
    4848  DIM_Name = new DimService((ID.str()+"Server").c_str(), Name);
     49  DIM_Status = new DimService((ID.str()+"Status").c_str(), (char *) "");
    4950  DIM_ID = new DimService((ID.str()+"BoardID").c_str(), (char *) "S", NULL, 0);
    5051  DIM_Temp = new DimService((ID.str()+"Temperature").c_str(), (char *) "F", NULL, 0);
     
    5354
    5455  // Create thread that connects and receives data
     56  SetStatus("Trying to connect");
     57
    5558  if ((Ret = pthread_create(&Thread, NULL, (void * (*)(void *)) LaunchThread,(void *) this)) != 0) {
    5659    m->Message(m->FATAL, "pthread_create() failed in FADBoard() (%s)", strerror(Ret));
     
    7780
    7881  delete DIM_Name;
     82  delete DIM_Status;
    7983  delete DIM_ID;
    8084  delete DIM_Temp;
     
    349353  struct hostent *Host = gethostbyname(Name);
    350354  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);
    352356    return;
    353357  }
     
    365369  // Connect to server
    366370  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));
    368372  }
    369373  else {
    370374        CommOK = true;
    371375        Active = true;
     376    SetStatus("Connected");
    372377  }
    373378
     
    381386        // Check result of read
    382387        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));
    384389          CommOK = false;
    385390          break;
    386391        }
    387392        else if (Result == 0) {
    388           m->PrintMessage("Server not existing anymore, exiting read loop\n");
     393          SetStatus("Server not existing anymore, exiting read loop");
    389394          CommOK = false;
    390395          break;
     
    399404        // Check if internal buffer full
    400405        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");
    402407          Pos = 0;
    403408          continue;
     
    410415          memmove(Buffer, Buffer+Temp, Pos-Temp);
    411416          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);
    413418          continue;
    414419        }
     
    521526          }         
    522527        }
    523         else m->PrintMessage("End package flag incorrect, removing corrupt event\n");
     528        else SetStatus("End package flag incorrect, removing corrupt event");
    524529
    525530        // Remove event data from internal buffer
     
    532537
    533538  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}
    539543
    540544//
     
    544548
    545549  m->ReadLoop();
     550}
     551
     552
     553//
     554// Set status message
     555//
     556void 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);
    546572}
    547573
     
    571597//
    572598// Open other sockets
     599//
     600//  Error reporting is limited as this function is expected to be removed when firmware allows single socket
    573601//
    574602void FADBoard::threadHandler() {
     
    581609  // Resolve hostname
    582610  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;
    587612
    588613  // Connect to server
     
    594619        // Open socket descriptor
    595620        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));
    597622      return;
    598623        }
     
    601626        // Connect to server
    602627    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;
    607629  }
    608630 
     
    612634    for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) FD_SET(Socket[i], &DescriptorList);
    613635    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));
    615637      break;
    616638    }
     
    619641        for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) if (FD_ISSET(Socket[i], &DescriptorList)) {
    620642          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));
    623644    }
    624645  }
     
    627648  for (unsigned int i=0; i<sizeof(List)/sizeof(int); i++) {
    628649        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  
    2121
    2222const unsigned int READ_BUFFER_SIZE = 1000000;
     23const unsigned int STATUS_SIZE = 200;
    2324
    2425class FADBoard: public DimThread {
     
    2728        int Socket;
    2829        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;
    3031
    3132        void ReadLoop();
    3233        static void LaunchThread(class FADBoard *);
    3334        void threadHandler();
     35        void SetStatus(const char *, ...);
    3436
    3537  public:
     
    4345          uint32_t BoardTime;
    4446          uint32_t EventCounter;
     47
     48          char Message[STATUS_SIZE];
    4549          struct timeval Update;
    4650
     
    9397        pthread_cond_t CondVar;
    9498       
    95   // Amplitude calibration
     99    // Amplitude calibration
    96100        int Count; 
    97101
  • fact/FADctrl/History.txt

    r10261 r10262  
    18182/3/2011        Implemented new FAD data format
    191928/3/2011       Boards with communication error set themselves inactive
     2029/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.