source: flair-src/trunk/tools/FlairGCS/src/ConnectionLayout.cpp@ 440

Last change on this file since 440 was 436, checked in by Sanahuja Guillaume, 3 years ago

gcs:sync graphs

File size: 3.6 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]5#include "ConnectionLayout.h"
6#include "UdtSocket.h"
7#include "DataRemote.h"
8#include <qendian.h>
9#include "communication.h"
10
[436]11ConnectionLayout::ConnectionLayout(UdtSocket *socket, QString name, QTime startTime)
[15]12 : Layout(NULL, name, "root") {
13 this->socket = socket;
[234]14 this->name = name;
[436]15 this->startTime = startTime;
[9]16}
17
[30]18ConnectionLayout::~ConnectionLayout() {
19}
[9]20
[436]21QTime ConnectionLayout::GetStartTime(void) {
22 return startTime;
23}
24
[260]25void ConnectionLayout::udtSocketDestroyed(QObject *obj){
26 socket=NULL;
27}
28
[15]29void ConnectionLayout::receive(char *buf, int size) {
[247]30 //fprintf(stderr,"trame %x\n",buf[0]);
[244]31 // for(int i=0; i<size;i++) fprintf(stderr,"%x ",buf[i]);
32 // fprintf(stderr,"\n");
[15]33 switch ((unsigned char)buf[0]) {
34 case XML_HEADER: {
35 QString xml;
36 QDomDocument doc;
37 xml = QString((char *)buf);
38 xml.resize(size);
[9]39
[244]40 // fprintf(stderr,"recu %i\n%s\n",size,xml.toLocal8Bit().constData());
[15]41 if (!doc.setContent(xml)) {
[244]42 fprintf(stderr,"prob setContent fichier\n");
[15]43 }
[9]44
[269]45 QDomElement dom=doc.firstChildElement("root").firstChildElement();
46 ParseXml(&dom);
[15]47 break;
48 }
[253]49 case DATA_BIG_ENDIAN: {
[244]50 // for(int i=0;i<size;i++) fprintf(stderr,"%x ",buf[i]);
51 // fprintf(stderr,"\n");
[15]52 uint16_t period;
53 memcpy(&period, &buf[1], sizeof(uint16_t));
54 period = qFromBigEndian(period);
55 drawDatas(&buf[3], size - 3, period, true);
56 break;
57 }
[253]58 case DATA_LITTLE_ENDIAN: {
[244]59 // for(int i=0;i<size;i++) fprintf(stderr,"%x ",buf[i]);
60 // fprintf(stderr,"\n");
[15]61 uint16_t period;
62 memcpy(&period, &buf[1], sizeof(uint16_t));
[244]63 // fprintf(stderr,"recu %i period %i\n",size,period);
[15]64 drawDatas(&buf[3], size - 3, period);
65 break;
66 }
[247]67 case CLOSING_CONNECTION: {
68 deleteLater();
69 break;
70 }
[15]71 default:
[244]72 fprintf(stderr,"trame non supportée %x\n", buf[0]);
[15]73 }
[9]74}
75
[234]76void ConnectionLayout::XmlToSend(QDomDocument doc) {
[258]77 //fprintf(stderr,"xml to send\n%s\n",doc.toString().toLocal8Bit().constData());
[260]78 if(!socket) return;
[234]79
80 // xml to send a mettre dans le manager
[258]81 if(doc.toString().toLocal8Bit().length()!=0) {
82 socket->write(doc.toString().toLocal8Bit().constData(),doc.toString().toLocal8Bit().length());
83 }
84 /*
[234]85 QMetaObject::invokeMethod(
86 socket, "write", Qt::BlockingQueuedConnection,
87 Q_ARG(const char *, doc.toString().toLocal8Bit().constData()),
88 Q_ARG(qint64, doc.toString().toLocal8Bit().length()));*/
89}
90
[269]91void ConnectionLayout::LoadXml(QDomDocument *to_parse) {
92 QDomElement tmp = to_parse->firstChildElement("root");
[234]93 while (tmp.attribute("name") != name && !tmp.isNull())
[269]94 tmp = to_parse->nextSiblingElement("root");
[234]95
96 if (!tmp.isNull()) {
[269]97 XmlWidget::LoadXml(&tmp);
[234]98 } else {
[244]99 fprintf(stderr,"%s not found in xml file \n", name.toLocal8Bit().constData());
[234]100 }
101}
102
[15]103void ConnectionLayout::removeDataRemote(DataRemote *data) {
104 dataremotes.removeOne(data);
[9]105}
106
[15]107void ConnectionLayout::addDataRemote(DataRemote *data) {
108 dataremotes.append(data);
[9]109}
110
[234]111QString ConnectionLayout::getName() { return name; }
[222]112
[15]113void ConnectionLayout::drawDatas(char *buf, int buf_size, uint16_t period,
114 bool big_endian) {
115 for (int i = 0; i < dataremotes.count(); i++) {
116 dataremotes.at(i)->BufEvent(&buf, &buf_size, period, big_endian);
117 }
[9]118}
119
[234]120QString ConnectionLayout::getDocRootName(char* buf, int size) {
121 QString xml;
122 QDomDocument doc;
123 xml = QString((char *)buf);
124 xml.resize(size);
[9]125
[234]126 if (!doc.setContent(xml)) {
[244]127 fprintf(stderr,"prob setContent fichier\n");
[15]128 }
[234]129
130 return doc.firstChildElement("root").attribute("name");
131}
Note: See TracBrowser for help on using the repository browser.