- Timestamp:
- 02/12/10 11:37:22 (15 years ago)
- Location:
- Evidence
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Edd/Edd.cc
r167 r168 20 20 Qt::gray, Qt::darkGray, Qt::lightGray}; 21 21 22 class GUI *Handler; 22 23 class Edd_DIM *Handler; 23 24 24 25 25 26 // History chooser function (opens plot for numeric data, TextHist for all other) 26 QWidget *OpenHistory(char *Service ) {27 QWidget *OpenHistory(char *Service, int Index) { 27 28 28 29 char *Name, *Format; 29 30 DimBrowser Browser; 30 31 //if (Browser.getServices(Service) == 0) return NULL; 31 32 32 Browser.getServices(Service); 33 33 if (Browser.getNextService(Name, Format) != DimSERVICE) return NULL; 34 34 35 if (strlen(Format) == 1 && *Format != 'C') return new Edd_Plot(Service );35 if (strlen(Format) == 1 && *Format != 'C') return new Edd_Plot(Service, Index); 36 36 else return new Edd_TextHist(Service); 37 37 } … … 43 43 44 44 // Constructor 45 Edd_Indicator::Edd_Indicator(QString DIMService, QWidget *P): QLineEdit(P) { 46 45 Edd_Indicator::Edd_Indicator(QString Name, int Index, QWidget *P): 46 QLineEdit(P), ServiceName(Name), Index(Index) { 47 47 48 // Widget properties 48 49 setReadOnly(true); … … 52 53 // Connect to DIM handler 53 54 if (connect(Handler, SIGNAL(YEP(DimInfo*, int, QByteArray, QString)), SLOT(Update(DimInfo*, int, QByteArray, QString))) == false) { 54 printf("Failed connection for %s\n", DIMService.toAscii().data());55 printf("Failed connection for %s\n", Name.toAscii().data()); 55 56 } 56 57 … … 61 62 Menu->addAction("Copy data", this, SLOT(MenuCopyData())); 62 63 63 // DIM client64 Data = new DimStampedInfo(DIMService.toAscii().data(), INT_MAX, NO_LINK, Handler);64 // Subscribe to service 65 Handler->Subscribe(Name); 65 66 } 66 67 67 68 // Destructor 68 69 Edd_Indicator::~Edd_Indicator() { 69 delete Data; 70 71 Handler->Unsubscribe(ServiceName); 70 72 } 71 73 … … 73 75 void Edd_Indicator::Update(DimInfo *Info, int Time, QByteArray Array, QString Text) { 74 76 75 if ( Info != Data) return;76 77 if (ServiceName != Info->getName()) return; 78 77 79 QPalette Pal = palette(); 78 80 … … 93 95 } 94 96 97 if (toupper(*(Info->getFormat()) != 'C')) Text = Text.section(' ', Index, Index); 98 95 99 if (!ShowAsTime) setText(Text); 96 100 else setText(QDateTime::fromTime_t(Text.toInt()).toString()); 97 101 setCursorPosition(0); 102 98 103 // Update status tip 99 setStatusTip(QString("%1: Last update %2 Format '%3'").arg(Info->getName(), QDateTime::fromTime_t(Time).toString()).arg(Info->getFormat()));104 setStatusTip(QString("%1: Last update %2 Format '%3' Index %4").arg(Info->getName()).arg( QDateTime::fromTime_t(Time).toString()).arg(Info->getFormat()).arg(Index)); 100 105 } 101 106 … … 135 140 QDrag *Drag = new QDrag(this); 136 141 QMimeData *MimeData = new QMimeData; 137 MimeData->setText( QString(Data->getName()));142 MimeData->setText(ServiceName); 138 143 Drag->setMimeData(MimeData); 139 144 Drag->exec(); … … 151 156 void Edd_Indicator::MenuOpenHistory() { 152 157 153 LastPlot = OpenHistory( Data->getName());158 LastPlot = OpenHistory(ServiceName.toAscii().data(), Index); 154 159 if (LastPlot != NULL) LastPlot->show(); 155 160 } … … 158 163 void Edd_Indicator::MenuCopyService() { 159 164 160 QApplication::clipboard()->setText( QString(Data->getName()));165 QApplication::clipboard()->setText(ServiceName); 161 166 } 162 167 … … 174 179 // Constructor 175 180 // 176 Edd_Plot::Edd_Plot(QString DIMService, QWidget *P): QwtPlot(P), EvidenceHistory() { 177 181 Edd_Plot::Edd_Plot(QString DIMService, int Index, QWidget *P): 182 QwtPlot(P), EvidenceHistory() { 183 184 Mutex = new QMutex(QMutex::Recursive); 185 186 // Widget properties 178 187 setAcceptDrops(true); 179 188 setAttribute(Qt::WA_DeleteOnClose); 180 181 // Graph properties182 189 setAutoReplot(false); 183 190 setCanvasBackground(QColor(Qt::yellow)); … … 220 227 221 228 // DIM client 222 if (!DIMService.isEmpty()) AddService(DIMService );229 if (!DIMService.isEmpty()) AddService(DIMService, Index); 223 230 } 224 231 … … 229 236 230 237 for (int i=0; i<Items.size(); i++) { 231 delete Items[i].LiveData;238 Handler->Unsubscribe(Items[i].Name); 232 239 delete Items[i].Signal; 233 240 } 234 241 delete Grid; 242 delete Mutex; 235 243 } 236 244 … … 238 246 // Add history service to plot 239 247 // 240 void Edd_Plot::AddService(QString Name ) {241 248 void Edd_Plot::AddService(QString Name, int Index) { 249 return; 242 250 // Lock before accessing Items list 243 QMutexLocker Locker( &Mutex);251 QMutexLocker Locker(Mutex); 244 252 245 253 // Check if already subscribed to service 246 254 for (int i=0; i<Items.size(); i++) { 247 if (Name == Items[i]. LiveData->getName()) {248 QMessageBox::warning(this, "Edd Message",Name+" .histalready present",QMessageBox::Ok);255 if (Name == Items[i].Name && Index == Items[i].Index) { 256 QMessageBox::warning(this, "Edd Message",Name+" (index "+QString::number(Index)+") already present",QMessageBox::Ok); 249 257 return; 250 258 } … … 253 261 // Generate new curve and subscribe to service 254 262 struct PlotItem New; 263 264 New.Name = Name; 255 265 New.Signal = new QwtPlotCurve; 256 266 New.Signal->attach(this); 257 New.Signal->setTitle(Name+" .hist");267 New.Signal->setTitle(Name+"("+QString::number(Index)+")"); 258 268 New.Signal->setPen(QColor(LineColors[Items.size() % (sizeof(LineColors)/sizeof(Qt::GlobalColor))])); 259 269 New.SizeLimit = 5000; 260 New. LiveData = new DimStampedInfo(Name.toAscii().data(), NO_LINK, Handler);270 New.Index = Index; 261 271 262 272 Items.append(New); 273 Handler->Subscribe(Name); 263 274 } 264 275 … … 269 280 if (Time == -1) { 270 281 setStatusTip(QString("%1: unavailable").arg(Info->getName())); 282 return; 271 283 } 272 284 273 285 // Lock before accessing Items list 274 QMutexLocker Locker( &Mutex);286 QMutexLocker Locker(Mutex); 275 287 276 288 // Determine which plot item this call belongs to 277 289 int ItemNo; 278 for (ItemNo=0; ItemNo<Items.size(); ItemNo++) if (I nfo == Items[ItemNo].LiveData) {290 for (ItemNo=0; ItemNo<Items.size(); ItemNo++) if (Items[ItemNo].Name == Info->getName()) { 279 291 280 292 // If size limit reached, clear buffer … … 289 301 void *Data; 290 302 291 if (GetHistory(Items[ItemNo]. LiveData->getName())) {303 if (GetHistory(Items[ItemNo].Name.toAscii().data())) { 292 304 double Smallest = DBL_MAX, Largest = DBL_MIN; 293 305 double Number=0; 294 306 while (Next(Time, Size, Data)) { 295 switch (*(Info->getFormat())) { 296 case 'I': Number = *(int *) Data; break; 297 case 'S': Number = *(short *) Data; break; 298 case 'F': Number = *(float *) Data; break; 299 case 'D': Number = *(double *) Data; break; 300 case 'X': Number = *(long long *) Data; break; 307 switch (toupper(*(Info->getFormat()))) { 308 case 'I': 309 case 'L': Number = *((int *) Data + Items[ItemNo].Index); break; 310 case 'S': Number = *((short *) Data + Items[ItemNo].Index); break; 311 case 'F': Number = *((float *) Data + Items[ItemNo].Index); break; 312 case 'D': Number = *((double *) Data + Items[ItemNo].Index); break; 313 case 'X': Number = *((long long *) Data + Items[ItemNo].Index); break; 301 314 default: break; 302 315 } … … 320 333 321 334 // Append data 335 Text = Text.section(' ', Items[ItemNo].Index, Items[ItemNo].Index); 336 322 337 Items[ItemNo].x.append(Time); 323 338 Items[ItemNo].y.append(atof(Text.toAscii().data())); … … 329 344 // Update status tip 330 345 QDateTime Timex = QDateTime::fromTime_t(Time); 331 StatusTip = QString("%1: Last update %2 Format '%3'").arg(Info->getName(), Timex.toString()).arg(Info->getFormat()); 332 } 333 334 Locker.unlock(); 346 setStatusTip(QString("%1: Last update %2 Format '%3'").arg(Info->getName(), Timex.toString()).arg(Info->getFormat())); 347 } 335 348 336 349 UpdatePlot(); … … 352 365 353 366 // Lock before accessing Items list 354 QMutexLocker Locker(&Mutex); 355 356 setStatusTip(StatusTip); 357 367 QMutexLocker Locker(Mutex); 368 358 369 for (int ItemNo=0; ItemNo<Items.size(); ItemNo++) { 359 370 … … 440 451 441 452 // Lock before accessing Items list 442 QMutexLocker Locker( &Mutex);453 QMutexLocker Locker(Mutex); 443 454 444 455 while (Items.size() > 1) { 445 delete Items.last().LiveData;456 Handler->Unsubscribe(Items.last().Name); 446 457 delete Items.last().Signal; 447 458 Items.takeLast(); 448 459 } 449 450 Locker.unlock();451 460 UpdatePlot(); 452 461 } … … 465 474 466 475 // Lock before accessing Items list 467 QMutexLocker Locker( &Mutex);476 QMutexLocker Locker(Mutex); 468 477 QTextStream Stream(&File); 469 478 470 479 // Write x and y data for all signals to file 471 480 for (int ItemNo=0; ItemNo<Items.size(); ItemNo++) { 472 Stream << QString("# ") +Items[ItemNo].LiveData->getName()+".hist" << endl;481 Stream << QString("# ") + Items[ItemNo].Name + ".hist" << endl; 473 482 for (int i=0; i<Items[ItemNo].Signal->dataSize(); i++) { 474 483 Stream << (int) Items[ItemNo].x.at(i) << " " << Items[ItemNo].Signal->y(i) << endl; … … 518 527 // Constructor 519 528 // 520 Edd_TextHist::Edd_TextHist(QString DIMService, QWidget *P): QTextEdit(P), EvidenceHistory() { 529 Edd_TextHist::Edd_TextHist(QString Name, QWidget *P): 530 QTextEdit(P), EvidenceHistory(), Name(Name) { 521 531 522 532 // Widget properties … … 528 538 // Connect to DIM handler 529 539 if (connect(Handler, SIGNAL(YEP(DimInfo*, int, QByteArray, QString)), SLOT(Update(DimInfo*, int, QByteArray, QString))) == false) { 530 printf("Failed connection for %s\n", DIMService.toAscii().data());540 printf("Failed connection for %s\n", Name.toAscii().data()); 531 541 } 532 542 … … 535 545 void *Data; 536 546 537 if (GetHistory( DIMService.toAscii().data())) {547 if (GetHistory(Name.toAscii().data())) { 538 548 while (Next(Time, Size, Data)) { 539 549 moveCursor (QTextCursor::Start); … … 544 554 545 555 // DIM client 546 Service = new DimStampedInfo(DIMService.toAscii().data(), INT_MAX, NO_LINK, Handler);556 Handler->Subscribe(Name); 547 557 } 548 558 … … 550 560 Edd_TextHist::~Edd_TextHist() { 551 561 552 delete Service;562 Handler->Unsubscribe(Name); 553 563 } 554 564 … … 557 567 void Edd_TextHist::Update(DimInfo *Info, int Time, QByteArray, QString Text) { 558 568 559 if ( Info != this->Service) return;569 if (Name != Info->getName()) return; 560 570 561 571 // Check if service available … … 572 582 573 583 // Update status tip 574 StatusTip = QString("%1: Last update %2 Format '%3'").arg(Info->getName(), Timex.toString()).arg(Info->getFormat());584 setStatusTip(QString("%1: Last update %2 Format '%3'").arg(Info->getName(), Timex.toString()).arg(Info->getFormat())); 575 585 } 576 586 … … 581 591 582 592 // Constructor 583 Edd_Textout::Edd_Textout(QString DIMService, QWidget *P): QTextEdit(P) {593 Edd_Textout::Edd_Textout(QString Name, QWidget *P): QTextEdit(P), Name(Name) { 584 594 585 595 // Widget properties … … 591 601 // Connect to DIM handler 592 602 if (connect(Handler, SIGNAL(YEP(DimInfo*, int, QByteArray, QString)), SLOT(Update(DimInfo*, int, QByteArray, QString))) == false) { 593 printf("Failed connection for %s\n", DIMService.toAscii().data());594 } 595 596 // DIM client597 Data = new DimStampedInfo(DIMService.toAscii().data(), INT_MAX, NO_LINK, Handler);603 printf("Failed connection for %s\n", Name.toAscii().data()); 604 } 605 606 // Subscribe to service 607 Handler->Subscribe(Name); 598 608 } 599 609 … … 601 611 Edd_Textout::~Edd_Textout() { 602 612 603 delete Data;613 Handler->Unsubscribe(Name); 604 614 } 605 615 … … 607 617 void Edd_Textout::Update(DimInfo *Info, int Time, QByteArray, QString Text) { 608 618 609 if ( Info != this->Data) return;619 if (Name != Info->getName()) return; 610 620 611 621 QPalette Pal = palette(); … … 622 632 if (Accumulate == false) clear(); 623 633 624 625 626 627 628 634 // Add if service contains only a string 635 if (strcmp(Info->getFormat(), "C") == 0) insertPlainText(Text); 636 637 // Update status tip 638 setStatusTip(QString("%1: Last update %2 Format '%3'").arg(Info->getName(), QDateTime::fromTime_t(Time).toString()).arg(Info->getFormat())); 629 639 } 630 640 setPalette(Pal); 641 } 642 643 644 ///////////////////////////// 645 // Interface to Dim system // 646 ///////////////////////////// 647 Edd_DIM::Edd_DIM() { 648 649 Mutex = new QMutex(QMutex::Recursive); 650 651 // Connect to DIM handler 652 if (connect(this, SIGNAL(YEP(DimInfo*, int, QByteArray, QString)), SLOT(Update(DimInfo*, int, QByteArray, QString))) == false) { 653 printf("Failed connection in Edd_DIM()\n"); 654 } 655 } 656 657 Edd_DIM::~Edd_DIM() { 658 659 delete Mutex; 660 } 661 662 // Subscribe to DIM service 663 void Edd_DIM::Subscribe(QString Name) { 664 665 // Lock before accessing list 666 QMutexLocker Locker(Mutex); 667 668 // Check if already subscribed to service, then increase usage count and emit last service data 669 for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Name) { 670 ServiceList[i].Count++; 671 YEP(ServiceList[i].DIMService, ServiceList[i].TimeStamp, ServiceList[i].ByteArray, ServiceList[i].Text); 672 return; 673 } 674 675 // Create new entry in service list 676 struct Item New; 677 New.Name = Name; 678 New.DIMService = new DimStampedInfo(Name.toAscii().data(), INT_MAX, NO_LINK, this); 679 New.Count = 1; 680 ServiceList.append(New); 681 682 return; 683 } 684 685 // Unsubsribe from DIM service 686 void Edd_DIM::Unsubscribe(QString Name) { 687 688 // Lock before accessing list 689 QMutexLocker Locker(Mutex); 690 691 for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Name) { 692 ServiceList[i].Count--; 693 if (ServiceList[i].Count == 0) { 694 delete ServiceList[i].DIMService; 695 ServiceList.removeAt(i); 696 return; 697 } 698 } 699 } 700 701 // Store service information for usage by Subscribe() 702 void Edd_DIM::Update(DimInfo *Info, int Time, QByteArray Data, QString Text) { 703 704 // Lock before accessing list 705 QMutexLocker Locker(Mutex); 706 707 for (int i=0; i<ServiceList.size(); i++) if (ServiceList[i].Name == Info->getName()) { 708 ServiceList[i].TimeStamp = Time; 709 ServiceList[i].ByteArray = Data; 710 ServiceList[i].Text = Text; 711 } 712 } 713 714 // Handling of DIM service update 715 void Edd_DIM::infoHandler() { 716 717 if (!EvidenceServer::ServiceOK(getInfo())) YEP(getInfo(), -1); 718 else { 719 char *Txt = EvidenceServer::ToString(getInfo()); 720 YEP(getInfo(), getInfo()->getTimestamp(), QByteArray((char *) getInfo()->getData(), getInfo()->getSize()), QString(Txt)); 721 free(Txt); 722 } 631 723 } 632 724 … … 637 729 GUI::GUI() { 638 730 639 Handler = this;731 Handler = new Edd_DIM(); 640 732 641 733 // Set features of main window … … 685 777 MainLayout->addWidget(Textout, 1, 0, 1, 2); 686 778 687 QFrame *Val = new QFrame();688 Val->setFrameStyle(QFrame::HLine);689 Val->setLineWidth(10);690 //Value->setMaximumWidth(200);691 MainLayout->addWidget(Val, 2, 0, 2, 1);692 693 779 Value = new Edd_Indicator("DColl/Status"); 694 780 Value->setMaximumWidth(200); … … 718 804 connect(Button, SIGNAL(released()), SLOT(StartDIMBrowser())); 719 805 MainLayout->addWidget(Button, 7, 1, 1, 1); 720 721 Edd_TextHist *Bla;722 Bla = new Edd_TextHist("DColl/CurrentFile");723 MainLayout->addWidget(Bla, 8, 0, 1, 1);724 806 725 807 // Layout of all widgets … … 737 819 Graph = new Edd_Plot(); 738 820 for (int i=0; i<36; i++) { 739 Text = Text.sprintf("Feedback/Average/ID%.2d/%.2d",i/8, i%8);740 Value = new Edd_Indicator(Text);741 821 //Text = Text.sprintf("Feedback/Average/ID%.2d/%.2d-%.3d",i/16, (i%16)/8, i%8); 822 Text = Text.sprintf("Feedback/AverageTest/ID%.2d",i/16); 823 Value = new Edd_Indicator(Text, i%16); 742 824 FeedbackLayout->addWidget(Value, i%9+1, 0+i/9, 1, 1); 743 825 //Graph->AddService(Text); 744 745 //Text = Text.sprintf("Bias/VOLT/ID00/01-%.3d",i); 746 //Value = new Edd_Indicator(Text); 747 //BiasLayout->addWidget(Value, i%9+1, 2+i/9, 1, 1); 826 } 827 FeedbackLayout->addWidget(Graph, 0, 4, 11, 3); 828 829 //Graph = new Edd_Plot(); 830 //for (int i=0; i<36; i++) { 831 //Text = Text.sprintf("Feedback/Sigma/ID%.2d/%.2d-%.3d",i/16, (i%16)/8, i%8); 748 832 //Graph->AddService(Text); 749 }750 751 FeedbackLayout->addWidget(Graph, 0, 4, 12, 3); 833 //} 834 //FeedbackLayout->addWidget(Graph, 10, 0, 10, 3); 835 752 836 Value = new Edd_Indicator("Feedback/Status"); 753 837 Value->setMaximumWidth(200); 754 838 FeedbackLayout->addWidget(Value, 0, 0, 1, 3); 839 Value = new Edd_Indicator("Feedback/Count"); 840 FeedbackLayout->addWidget(Value, 0, 3, 1, 1); 755 841 756 842 // Bias voltage page … … 759 845 Graph = new Edd_Plot(); 760 846 for (int i=0; i<18; i++) { 761 Text = Text.sprintf("Bias/VOLT/ID00/00-%.3d",i); 762 Value = new Edd_Indicator(Text); 763 847 Value = new Edd_Indicator("Bias/VOLT/ID00", i); 764 848 BiasLayout->addWidget(Value, i%9+1, 0+i/9, 1, 1); 765 Graph->AddService(Text); 766 767 Text = Text.sprintf("Bias/VOLT/ID00/01-%.3d",i); 768 Value = new Edd_Indicator(Text); 849 //Graph->AddService(Text, i); 850 851 Value = new Edd_Indicator("Bias/VOLT/ID00", i+32); 769 852 BiasLayout->addWidget(Value, i%9+1, 2+i/9, 1, 1); 770 Graph->AddService(Text);853 //Graph->AddService(Text,i+32); 771 854 } 772 855 … … 789 872 Graph = new Edd_Plot(); 790 873 for (int i=0; i<10; i++) { 791 Text = Text.sprintf("ARDUINO/VAL%.2d", i); 792 Value = new Edd_Indicator(Text); 874 Value = new Edd_Indicator("ARDUINO/Data", i); 793 875 EnvironmentLayout->addWidget(Value, i%5+1, i/5, 1, 1); 794 Graph->AddService( Text);876 Graph->AddService("ARDUINO/Data", i); 795 877 } 796 878 EnvironmentLayout->addWidget(Graph, 0, 3, 7, 4); … … 857 939 Result = Result.trimmed(); 858 940 if (Result.endsWith(".hist")) Result.chop(5); 859 QWidget *Hist = OpenHistory(Result.toAscii().data() );941 QWidget *Hist = OpenHistory(Result.toAscii().data(), 0); 860 942 if (Hist != NULL) Hist->show(); 861 }862 }863 864 // Handling of DIM service update865 void GUI::infoHandler() {866 867 // Check if service available868 if (!EvidenceServer::ServiceOK(getInfo())) YEP(getInfo(), -1);869 else {870 char *Txt = EvidenceServer::ToString(getInfo());871 872 YEP(getInfo(), getInfo()->getTimestamp(), QByteArray((char *) getInfo()->getData(), getInfo()->getSize()), QString(Txt));873 free(Txt);874 943 } 875 944 } -
Evidence/Edd/Edd.h
r167 r168 25 25 #define SVN_REVISION "$Revision$" 26 26 27 QWidget *OpenHistory(char * );27 QWidget *OpenHistory(char *, int); 28 28 29 29 // Time scale for axis … … 33 33 virtual QwtText label(double v) const { 34 34 QDateTime t = QDateTime::fromTime_t((int) v); 35 return t.toString("dMMM'\n'h :m:s");35 return t.toString("dMMM'\n'hh:mm:ss"); 36 36 } 37 37 }; … … 39 39 40 40 // General indicator for DIM service 41 class Edd_Indicator: public QLineEdit , public DimClient{41 class Edd_Indicator: public QLineEdit { 42 42 Q_OBJECT 43 43 44 44 QMenu *Menu; 45 45 QPoint dragStart; 46 //QwtPlot *LastPlot;47 46 QWidget *LastPlot; 48 47 49 DimStampedInfo *Data; 48 QString ServiceName; 49 int Index; 50 50 51 51 void mousePressEvent(QMouseEvent *); … … 54 54 55 55 public: 56 Edd_Indicator(QString, QWidget * = NULL);56 Edd_Indicator(QString, int=0, QWidget * = NULL); 57 57 ~Edd_Indicator(); 58 58 … … 72 72 73 73 struct PlotItem { 74 DimInfo *LiveData;74 QString Name; 75 75 QwtPlotCurve *Signal; 76 76 double Smallest; … … 78 78 int SizeLimit; 79 79 QVector<double> x; 80 QVector<double> y; 80 QVector<double> y; 81 int Index; 81 82 }; 82 83 83 84 QList<struct PlotItem> Items; 84 QMutex Mutex; 85 86 QString StatusTip; 87 85 QMutex *Mutex; 86 88 87 QMenu *Menu; 89 88 QAction *YLogAction; … … 100 99 101 100 public: 102 Edd_Plot(QString = QString(), QWidget * = NULL);101 Edd_Plot(QString = QString(), int = 0, QWidget * = NULL); 103 102 ~Edd_Plot(); 104 void AddService(QString );103 void AddService(QString, int = 0); 105 104 106 105 private slots: … … 123 122 Q_OBJECT 124 123 125 QString StatusTip; 126 DimStampedInfo *Service; 124 QString Name; 127 125 128 126 public: … … 138 136 Q_OBJECT 139 137 140 DimStampedInfo *Data;138 QString Name; 141 139 142 140 public: … … 150 148 }; 151 149 150 // Interface to DIM system 151 class Edd_DIM: public QObject, public DimInfo { 152 Q_OBJECT 153 154 struct Item { 155 QString Name; 156 DimStampedInfo *DIMService; 157 int Count; 158 int TimeStamp; 159 QByteArray ByteArray; 160 QString Text; 161 }; 162 QList<Item> ServiceList; 163 QMutex *Mutex; 164 165 void infoHandler(); 166 167 private slots: 168 void Update(DimInfo *, int, QByteArray, QString); 169 170 public: 171 Edd_DIM(); 172 ~Edd_DIM(); 173 174 void Subscribe(QString); 175 void Unsubscribe (QString); 176 177 signals: 178 void YEP(DimInfo *, int, QByteArray = QByteArray(), QString = QString()); 179 }; 180 181 152 182 // Main window class 153 class GUI: public QMainWindow, public DimBrowser , public DimInfo{183 class GUI: public QMainWindow, public DimBrowser { 154 184 Q_OBJECT 155 185 … … 162 192 163 193 void closeEvent(QCloseEvent *); 164 void infoHandler();165 194 166 195 public: … … 172 201 void MenuNewHistory(); 173 202 void StartDIMBrowser(); 174 175 signals:176 void YEP(DimInfo *, int, QByteArray = QByteArray(), QString = QString());177 203 }; 178 204 -
Evidence/Evidence.cc
r167 r168 227 227 228 228 // Translates DIMInfo to string (memory has to be freed by caller) 229 // DIM structures are converted to hexadecimal representation230 // For string conversion, a terminating \0 is enforced.231 229 char *EvidenceServer::ToString(DimInfo *Item) { 232 230 233 231 char *Text; 234 int R=0; 235 232 233 // Structure: print hex representation (3 characters per byte) 236 234 if (strlen(Item->getFormat()) != 1) { 237 235 if ((Text = (char *) malloc(3*Item->getSize()+1)) != NULL) { 238 236 for (int i=0; i<Item->getSize(); i++) sprintf(Text+3*i, "%02x", *((char *) Item->getData() + i)); 239 237 } 240 } 241 else { 242 switch (*(Item->getFormat())) { 243 case 'I': R = asprintf(&Text, "%d", Item->getInt()); break; 244 case 'S': R = asprintf(&Text, "%hd", Item->getShort()); break; 245 case 'F': R = asprintf(&Text, "%.5f", Item->getFloat()); break; 246 case 'D': R = asprintf(&Text, "%.5f", Item->getDouble()); break; 247 case 'X': R = asprintf(&Text, "%lld", Item->getLonglong()); break; 248 case 'C': *(Item->getString() + Item->getSize() - 1) = '\0'; 249 R = asprintf(&Text, "%s", Item->getString()); 250 break; 251 default: return NULL; 238 return Text; 239 } 240 241 // String: terminating \0 is enforced 242 if (toupper(*(Item->getFormat())) == 'C') { 243 *(Item->getString() + Item->getSize() - 1) = '\0'; 244 if (asprintf(&Text, "%s", Item->getString()) == -1) return NULL; 245 return Text; 246 } 247 248 // Number array 249 int Size; 250 switch (toupper(*(Item->getFormat()))) { 251 case 'I': 252 case 'L': Size = sizeof(int); break; 253 case 'S': Size = sizeof(short); break; 254 case 'F': Size = sizeof(float); break; 255 case 'D': Size = sizeof(double); break; 256 case 'X': Size = sizeof(long long); break; 257 default: return NULL; 258 } 259 260 int Max, Mem = Item->getSize()*Size*4+1; 261 char *Pos; 262 263 if ((Text = (char *) malloc(Mem)) == NULL) return NULL; 264 265 *Text = '\0'; 266 for (int i=0; i<Item->getSize()/Size; i++) { 267 Pos = Text+strlen(Text); 268 Max = Mem-strlen(Text); 269 270 switch (toupper(*(Item->getFormat()))) { 271 case 'I': 272 case 'L': snprintf(Pos, Max, "%d ", *((int *) Item->getData() + i)); 273 break; 274 case 'S': snprintf(Pos, Max, "%hd ", *((short *) Item->getData() + i)); 275 break; 276 case 'F': snprintf(Pos, Max, "%.5f ", *((float *) Item->getData() + i)); 277 break; 278 case 'D': snprintf(Pos, Max, "%.5f ", *((double *) Item->getData() + i)); 279 break; 280 case 'X': snprintf(Pos, Max, "%lld ", *((long long *) Item->getData() + i)); 281 break; 252 282 } 253 283 } 254 284 255 return (R == -1) ? NULL :Text;285 return Text; 256 286 } 257 287
Note:
See TracChangeset
for help on using the changeset viewer.