Changeset 12894


Ignore:
Timestamp:
Feb 16, 2012, 2:44:55 PM (8 years ago)
Author:
ogrimm
Message:
Updated Edd for history plotting of more complex arrays
Location:
fact
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fact/Evidence/Evidence.cc

    r12892 r12894  
    421421  }
    422422
    423   // Simplify format "?;1" to "?"
    424   if (strlen(Format)==3 && Format[2]=='1') Format[1] = '\0';
    425  
    426   // Structure: print hex representation
    427   if (strlen(Format) != 1) {
    428         for (int i=0; i<Size; i++) {
    429           Text << setw(2) << hex << *((char *) Data + i) << " ";
    430         }
    431         return Text.str();
    432   }
    433 
    434423  // String if format "C" and terminated with \0
    435424  if (strcmp(Format, "C") == 0 && Size > 0 && *((char *) Data+Size-1)=='\0') {
    436425        return string((char *) Data);
    437426  }
    438 
     427 
     428  // Check if format is made of identical component types
     429  vector<string> Components = Tokenize(Format, ";");
     430 
     431  for (unsigned int i=0; i<Components.size(); i++) {
     432        if (Components[i].empty()) return string();
     433
     434        // Print hex representation if format complex
     435        if (Components[i][0] != Components[0][0]) {
     436          for (int i=0; i<Size; i++) {
     437                Text << setw(2) << hex << *((char *) Data + i) << " ";
     438          }
     439          return Text.str();
     440        }
     441  }
     442 
    439443  // Number array
    440444  int ElementSize;
     445
    441446  switch (toupper(*Format)) {
    442447    case 'B':
  • fact/Evidence/GUI.cc

    r11360 r12894  
    88a DIM status service
    99
    10 April 2010, Oliver Grimm
     10April 2010, February 2012, Oliver Grimm
    1111
    1212============================================================ */
     
    1919// History chooser function (opens plot for numeric data, TextHist for all other)
    2020//
    21 void OpenHistory(char *Service, int Index) {
     21void OpenHistory(char *Service, int FromIndex, int ToIndex) {
    2222
    2323  QString Format;
     
    2929  if (strcmp(Service, "Edd/Rate_kBSec") == 0) Format = "F";
    3030  else if (Hist == NULL || Hist->GetFormat() == NULL) {
    31         QMessageBox::warning(NULL, "Edd Message", QString("Could not retrieve history for service ") + Service ,QMessageBox::Ok);
     31        //QMessageBox::warning(NULL, "Edd Message", QString("Could not retrieve history for service ") + Service ,QMessageBox::Ok);
     32        printf("Edd Message: Could not retrieve history for service %s\n", Service);
    3233  }
    3334  else Format = Hist->GetFormat();
     
    4445  M->setStatusBar(new QStatusBar(M));
    4546  M->setAttribute(Qt::WA_DeleteOnClose);
    46   M->setWindowTitle("Edd History - " + QString(Service));
    47  
    48   QWidget *W;
    49   if (Format.size() == 1 && Format[0] != 'C') W = new EddPlot(Service, Index);
    50   else W = new EddText(Service);
     47  M->setWindowTitle("Edd History");
    5148
    5249  QGridLayout *Layout = new QGridLayout(M->centralWidget());
    53   Layout->addWidget(W, 0, 0);
    54   Layout->addWidget(new EddLineDisplay(Service, Index), 1, 0);
    55   M->resize(300,350);
     50 
     51  if (Format.size() == 1 && Format[0] == 'C') Layout->addWidget(new EddText(Service), 0, 0);
     52  else  {
     53    EddPlot *W = new EddPlot(Service, FromIndex);
     54        for (int i=FromIndex+1; i<=ToIndex; i++) {
     55          W->AddService(Service,i);
     56      Layout->addWidget(new EddLineDisplay(Service, i), 1 + (i-FromIndex)/5, (i-FromIndex)%5);
     57        }
     58        Layout->addWidget(W, 0, 0, 1, 5);
     59  }
     60 
     61  Layout->addWidget(new EddLineDisplay(Service, FromIndex), 1, 0);
     62  M->resize(400,450);
    5663  M->show();
    5764}
     
    107114EddLineDisplay::~EddLineDisplay() {
    108115
    109   Handler->Unsubscribe(ServiceName, this);
     116  Handler->Unsubscribe(ServiceName, this, Index);
    110117}
    111118
     
    404411
    405412        // Append data if service available
    406         if (SetStatus(this, Name, Time, Format)) {
    407           //QString Txt = Text;
    408           //Txt = Txt.section(' ', List[ItemNo].Index, List[ItemNo].Index);
    409       //AddPoint(ItemNo, Time, atof(Txt.toAscii().data()));
    410       AddPoint(ItemNo, Time, atof(Text.toAscii().data()));
    411         }
    412 
     413        if (SetStatus(this, Name, Time, Format)) AddPoint(ItemNo, Time, atof(Text.toAscii().data()));
    413414        NewData = true;
    414415  }
     
    485486
    486487  for (int i=0; i<List.size(); i++) if (List[i].Signal == Curve) {
    487     Handler->Unsubscribe(List[i].Name, this);
     488    Handler->Unsubscribe(List[i].Name, this, List[i].Index);
    488489    List.removeAt(i);
    489490  }
     
    10071008  // Check if already subscribed to service
    10081009  if (ServiceList.contains(Name)) {
    1009         ServiceList[Name].Subscribers[Instance] = Index;
    1010         if (Index>=0 && Index<ServiceList[Name].Items.size()) Instance->Update(Name, ServiceList[Name].TimeStamp, ServiceList[Name].ByteArray, ServiceList[Name].Format, ServiceList[Name].Items[Index]);
     1010    ServiceList[Name].Subscribers.append(QPair<class EddWidget *, int>(Instance, Index));
     1011       
     1012        if (Index>=0 && Index<ServiceList[Name].Items.size()) {
     1013          Instance->Update(Name, ServiceList[Name].TimeStamp, ServiceList[Name].ByteArray, ServiceList[Name].Format, ServiceList[Name].Items[Index]);
     1014        }
    10111015        else Instance->Update(Name, ServiceList[Name].TimeStamp, ServiceList[Name].ByteArray, ServiceList[Name].Format, ServiceList[Name].Text);
    10121016
     
    10171021  ServiceList[Name].ByteArray = QByteArray();
    10181022  ServiceList[Name].TimeStamp = -1;
    1019   ServiceList[Name].Subscribers[Instance] = Index;
     1023  ServiceList[Name].Subscribers.append(QPair<class EddWidget *, int>(Instance, Index));
    10201024  ServiceList[Name].DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this);
    10211025}
     
    10231027
    10241028// Unsubscribe from DIM service
    1025 void EddDim::Unsubscribe(QString Name, class EddWidget *Instance) {
     1029void EddDim::Unsubscribe(QString Name, class EddWidget *Instance, int Index) {
    10261030
    10271031  // Lock before accessing list
     
    10291033
    10301034  if (!ServiceList.contains(Name)) return;
    1031  
    1032   if (ServiceList[Name].Subscribers.contains(Instance)) {
    1033         ServiceList[Name].Subscribers.remove(Instance);
    1034   }
    1035 
     1035
     1036  QPair<class EddWidget *, int> P(Instance, Index);
     1037 
     1038  if (ServiceList[Name].Subscribers.contains(P)) {
     1039        ServiceList[Name].Subscribers.removeAt(ServiceList[Name].Subscribers.indexOf(P));
     1040  }
     1041
     1042  // If no more needed, drop DIM subsription
    10361043  if (ServiceList[Name].Subscribers.isEmpty()) {
    10371044        delete ServiceList[Name].DIMService;
    10381045        ServiceList.remove(Name);
    1039         return;
    10401046  }
    10411047}
     
    11111117  Volume += Data.size();
    11121118
    1113   // Store service data
     1119  // Store service data and update all subscribers
    11141120  if (ServiceList.contains(Name)) {
    11151121        ServiceList[Name].TimeStamp = Time;
     
    11191125        ServiceList[Name].Items = ServiceList[Name].Text.split(" ");
    11201126
    1121         QMap<class EddWidget *, int>::const_iterator i = ServiceList[Name].Subscribers.constBegin();
    1122         while (i != ServiceList[Name].Subscribers.constEnd()) {
    1123           if (i.value() >=0 && i.value() < ServiceList[Name].Items.size()) i.key()->Update(Name, Time, Data, Format, ServiceList[Name].Items[i.value()], i.value());
    1124           else i.key()->Update(Name, Time, Data, Format, ServiceList[Name].Text, i.value());
    1125           i++;
     1127        for (int i=0; i<ServiceList[Name].Subscribers.size(); i++) {
     1128          QPair<class EddWidget *, int> P = ServiceList[Name].Subscribers[i];
     1129
     1130          if (P.second >=0 && P.second < ServiceList[Name].Items.size()) {
     1131            P.first->Update(Name, Time, Data, Format, ServiceList[Name].Items[P.second], P.second);
     1132          }
     1133          else P.first->Update(Name, Time, Data, Format, ServiceList[Name].Text, P.second);
    11261134        }
    11271135  } 
  • fact/Evidence/GUI.h

    r11360 r12894  
    3131const QColor EddPlotBackgroundColor(Qt::yellow);
    3232
    33 void OpenHistory(char *, int);
     33void OpenHistory(char *, int, int=-1);
    3434bool SetStatus(QWidget *, QString, int, QString, int = -1);
    3535
     
    231231        struct Item {
    232232          DimStampedInfo *DIMService;
    233           QMap<class EddWidget *, int> Subscribers;
     233          QList<QPair<class EddWidget *, int> > Subscribers;
    234234          int TimeStamp;
    235235          QByteArray ByteArray;
     
    263263
    264264        void Subscribe(QString, class EddWidget *, int = -1);
    265         void Unsubscribe (QString, class EddWidget *);
     265        void Unsubscribe (QString, class EddWidget *, int = -1);
    266266        void Ignore (QString, bool);
    267267        class EvidenceHistory *GetHistory(QString);
  • fact/tools/Edd/Edd.cc

    r11462 r12894  
    921921  QTimer *Timer = new QTimer(this);
    922922  connect(Timer, SIGNAL(timeout()), this, SLOT(CheckAlarm()));
    923   Timer->start(5000);
     923  if (QString(DimServer::getDnsNode()).contains("ethz.ch")) Timer->start(5000);
    924924
    925925   
     
    940940void GUI::MenuNewHistory() {
    941941
    942   QStringList List;
     942  QStringList List, Index;
    943943  char *Name, *Format;
    944944  int Type;
     
    954954  // Open dialog and open history window
    955955  QString Result = QInputDialog::getItem(this, "Edd Request",
    956     "Enter or choose DIM service name (add index separated by colon)", List, 0, true, &OK);
     956    "Enter or choose DIM service name (add index or index range a-b separated by colon)", List, 0, true, &OK);
    957957
    958958  // Check if cancelled or empty data
     
    960960  if (!OK || List.isEmpty()) return;
    961961
    962   if (List.size() == 1) OpenHistory(List[0].toAscii().data(), 0);
    963   else OpenHistory(List[0].toAscii().data(), atoi(List[1].toAscii().data()));
     962  // Check if index was given
     963  if (List.size() == 1) {
     964        OpenHistory(List[0].toAscii().data(), 0);
     965        return;
     966  }
     967
     968  // Single index or index range?
     969  Index = List[1].trimmed().split("-", QString::SkipEmptyParts);
     970  if (Index.isEmpty()) {
     971        QMessageBox::warning(NULL, "Edd Message", QString("Incorrect index range given") ,QMessageBox::Ok);
     972        return;
     973  }
     974
     975  if (Index.size() == 1) OpenHistory(List[0].toAscii().data(), atoi(Index[0].toAscii().data()));
     976  else OpenHistory(List[0].toAscii().data(), atoi(Index[0].toAscii().data()), atoi(Index[1].toAscii().data()));
    964977}
    965978
Note: See TracChangeset for help on using the changeset viewer.