Changeset 10984


Ignore:
Timestamp:
06/10/11 15:02:24 (13 years ago)
Author:
ogrimm
Message:
Edd allows to set plot update rate
Location:
fact
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • fact/Evidence/GUI.cc

    r10928 r10984  
    4646  if (Format.size() == 1 && Format[0] != 'C') return new EddPlot(Service, Index);
    4747  else return new EddText(Service);
     48 
     49 
    4850}
    4951
     
    235237  setAcceptDrops(true);
    236238  setAxisScaleDraw(QwtPlot::xBottom, new EddTimeScale);
    237        
     239
    238240  // Update time range on plot when axis change (update() results in paintEvent())
    239241  connect(axisWidget(QwtPlot::xBottom), SIGNAL(scaleDivChanged()), SLOT(update()));
     
    252254  Menu->insertAction(Menu->actions().value(1), Action);
    253255 
    254   // Maximum number if points in curve (will be increased in Update())
    255   SizeLimit = 0;
     256  // Set timer to regularly update plot if new data available
     257  SingleShot = new QTimer(this);
     258  connect(SingleShot, SIGNAL(timeout()), this, SLOT(UpdatePlot()));
     259  SingleShot->setSingleShot(true);
    256260
    257261  // DIM client
     
    284288  List.append(N);
    285289
     290  // Request new history buffer
     291  const struct EvidenceHistory::Item *R;
     292  class EvidenceHistory *Hist;
     293
     294  if ((Hist = Handler->GetHistory(Name)) != NULL) {
     295        double Number=0;
     296        while ((R=Hist->Next()) != NULL) {
     297          switch (*(Hist->GetFormat())) {
     298        case 'I':
     299                case 'L':  Number = *((int *) R->Data + N.Index);   break;
     300        case 'S':  Number = *((short *) R->Data + N.Index);   break;
     301        case 'F':  Number = *((float *) R->Data + N.Index);   break;
     302        case 'D':  Number = *((double *) R->Data + N.Index);   break;
     303        case 'X':  Number = *((long long *) R->Data + N.Index);   break;
     304        default: break;
     305          }
     306          AddPoint(List.size()-1, R->Time, Number);
     307        }
     308  }
     309  Handler->DropHistory(Name);
    286310  Handler->Subscribe(Name);
     311 
     312  SingleShot->start(100);
    287313}
    288314
     
    290316void EddPlot::Update(QString Name, int Time, QByteArray, QString Format, QString Text) {
    291317
    292   bool DoUpdate = false;
    293 
    294   // Determine which plot item this call belongs to
    295   int ItemNo;
    296   for (ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) {
    297 
    298         DoUpdate = true;
    299 
    300         // If size limit reached, clear buffer
    301     if (List[ItemNo].Signal->dataSize() > SizeLimit) List[ItemNo].Signal->setData(QPolygonF());
    302 
    303         // If buffer empty, request new history buffer
    304     if (List[ItemNo].Signal->dataSize() == 0) {
    305           int Count=0;
    306           const struct EvidenceHistory::Item *R;
    307           class EvidenceHistory *Hist;
    308 
    309           if ((Hist = Handler->GetHistory(List[ItemNo].Name)) != NULL) {
    310                 double Number=0;
    311                 while ((R=Hist->Next()) != NULL) {
    312                   switch (*(Hist->GetFormat())) {
    313                 case 'I':
    314                         case 'L':  Number = *((int *) R->Data + List[ItemNo].Index);   break;
    315                 case 'S':  Number = *((short *) R->Data + List[ItemNo].Index);   break;
    316                 case 'F':  Number = *((float *) R->Data + List[ItemNo].Index);   break;
    317                 case 'D':  Number = *((double *) R->Data + List[ItemNo].Index);   break;
    318                 case 'X':  Number = *((long long *) R->Data + List[ItemNo].Index);   break;
    319                 default: break;
    320                   }
    321                   AddPoint(ItemNo, R->Time, Number);
    322                   Count++;
    323                 }
    324 
    325                 // Local buffer at least twice as large as longest history
    326                 if (SizeLimit < 2*Count) SizeLimit = 2*Count;
    327           }
    328           Handler->DropHistory(List[ItemNo].Name);
    329         }
    330 
    331         // Append data only if service available
     318  for (int ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) {
     319
     320        // Append data if service available
    332321        if (SetStatus(this, Name, Time, Format)) {
    333322          QString Txt = Text;
     
    335324      AddPoint(ItemNo, Time, atof(Txt.toAscii().data()));
    336325        }
    337   }
    338 
    339   if (DoUpdate) UpdatePlot();
     326
     327        NewData = true;
     328  }
    340329}
    341330
     
    412401  setCanvasBackground(EddPlotBackgroundColor);
    413402  setMargin(15);
     403  NewData = false;
    414404
    415405  // Plot navigation
     
    460450  Menu->addAction("Single trace", this, SLOT(MenuSingleTrace()));
    461451  Menu->addSeparator();
     452  Menu->addAction("Set update rate", this, SLOT(MenuSetUpdateRate())); 
     453  Menu->addSeparator();
    462454  Menu->addAction("Save as ASCII", this, SLOT(MenuSaveASCII()));
    463455  Menu->addAction("Save plot", this, SLOT(MenuSave()));
    464456  Menu->addAction("Print plot", this, SLOT(MenuPrint()));
    465457  Menu->addAction("Plot help", this, SLOT(MenuPlotHelp()));
     458 
     459  // Set timer to regularly update plot if new data available
     460  Timer = new QTimer(this);
     461  connect(Timer, SIGNAL(timeout()), this, SLOT(UpdatePlot()));
     462  Timer->start(2000);
    466463}
    467464
     
    527524  Symbol.setStyle(QwtSymbol::Ellipse);
    528525  Symbol.setSize(4);
     526
     527  // Only update if called by timer if new data is available
     528  if (sender() == Timer && !NewData) return;
     529  NewData = false;
    529530
    530531  // Select engine for linear or logarithmic scale
     
    560561      } 
    561562    }
    562  
     563
    563564    // Plot data
    564565    Items[ItemNo].Signal->setData(Items[ItemNo].x.data(), y, DataPoints);
     
    716717  }
    717718  UpdatePlot();
     719}
     720
     721// Set maximum update rate of plot
     722void EddBasePlot::MenuSetUpdateRate() {
     723
     724  bool OK;
     725  double Rate;
     726 
     727  Rate = QInputDialog::getDouble(this, "Edd Request",
     728    "Minimum period between plot updates (sec)", (double) Timer->interval()/1000, 0, std::numeric_limits<double>::max(), 2, &OK);
     729  if (OK) Timer->setInterval(Rate*1000);
    718730}
    719731
  • fact/Evidence/GUI.h

    r10928 r10984  
    2222#include <qwt_color_map.h>
    2323
    24 #include <limits.h>
     24#include <limits>
    2525#include <float.h>
     26#include <limits>
    2627
    2728#include "dic.hxx"
     
    7273    ~EddBasePlot();
    7374
     75        QTimer *Timer;
     76        bool NewData;
    7477        QwtPlotCurve *NewCurve(QwtText);
    7578        void ClearCurve(unsigned int);
     
    8689        void contextMenuEvent(QContextMenuEvent *);
    8790    void MenuSingleTrace();       
     91    void MenuSetUpdateRate();       
    8892    void MenuZoomOut();
    8993    void MenuSaveASCII();
     
    172176  private:
    173177        QwtLegend *Legend;
    174         int SizeLimit;
     178        QTimer *SingleShot;
    175179
    176180    void dragEnterEvent(QDragEnterEvent *);
  • fact/tools/Edd/Edd.cc

    r10928 r10984  
    77EddLineDisplay changes its background colour in case it display
    88a DIM status service
     9
     10Note: Currently no limit to number of points in plot, can result in out of memory condition.
    911
    1012============================================================ */
     
    5557  AddTrace(0,0,0);
    5658
     59  // Update interval
     60  Timer->setInterval(100);
    5761  SetActive(true);
    5862}
     
    334338
    335339//
    336 // Environment page
     340// Environment page (For M0, server was called ARDUINO)
    337341//
    338342TP_Environment::TP_Environment() {
     
    342346
    343347  // Status display
    344   EddLineDisplay *Line = new EddLineDisplay("ARDUINO/Message");
    345   Line->setMaximumWidth(200);
    346   Layout->addWidget(Line, 0, 0, 1, 2);     
    347 
    348   // Generate plot and data displays
     348  EddLineDisplay *Line = new EddLineDisplay("FSCctrl/Message");
     349  Line->setMaximumWidth(300);
     350  Layout->addWidget(Line, 0, 0, 1, 4);     
     351
     352  Line = new EddLineDisplay("FSCctrl/Time");
     353  Layout->addWidget(Line, 0, 5, 1, 2);     
     354
     355  // Temperatures
    349356  EddPlot *Plot = new EddPlot();
    350   for (int i=0; i<10; i++) {
    351     Line = new EddLineDisplay("ARDUINO/Data", i);
    352     Layout->addWidget(Line, i%5+1, i/5, 1, 1);
    353     Plot->AddService("ARDUINO/Data", i);
    354   }
    355   Layout->addWidget(Plot, 0, 2, 9, 7);     
     357  for (int i=0; i<64; i++) {
     358    Line = new EddLineDisplay("FSCctrl/Temperature", i);
     359    Line->setMaximumWidth(50);
     360    Layout->addWidget(Line, i/8+1, i%8);
     361    Plot->AddService("FSCctrl/Temperature", i);
     362  }
     363  Layout->addWidget(Plot, 0, 10, 22, 15);     
     364
     365  // Voltages and currents
     366  for (int i=0; i<40; i++) {
     367    Line = new EddLineDisplay("FSCctrl/Voltage", i);
     368    Line->setMaximumWidth(50);
     369    Layout->addWidget(Line, i/8+10, i%8);
     370
     371    Line = new EddLineDisplay("FSCctrl/Current", i);
     372    Line->setMaximumWidth(50);
     373    Layout->addWidget(Line, i/8+16, i%8);
     374  }
    356375
    357376  // Night sky monitor
    358377  Line = new EddLineDisplay("SQM/Message");
    359   Line->setMaximumWidth(200);
    360   Layout->addWidget(Line, 6, 0, 1, 2);     
     378  Line->setMaximumWidth(300);
     379  Layout->addWidget(Line, 22, 0, 1, 4);     
    361380
    362381  Line = new EddLineDisplay("SQM/NSB");
    363   Layout->addWidget(Line, 7, 0, 1, 1);         
     382  Layout->addWidget(Line, 22, 5, 1, 2);         
    364383}
    365384
     
    872891  TabWidget->addTab(new TP_Bias, "Bias");
    873892  TabWidget->addTab(new TP_Feedback, "Feedback");
    874   TabWidget->addTab(new TP_Environment, "Environment");
     893  TabWidget->addTab(new TP_Environment, "FSC/SQM");
    875894  TabWidget->addTab(new TP_Evidence, "Evidence");
    876895
Note: See TracChangeset for help on using the changeset viewer.