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

Last change on this file since 276 was 269, checked in by Sanahuja Guillaume, 6 years ago

flairgcs:
speed up processing time when receiving datas from uav
triger watchdog while receiving datas from uav
(avoids connection lost in uav)

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