Changeset 247 in flair-src
- Timestamp:
- May 28, 2018, 6:23:35 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/ui_com.cpp
r243 r247 105 105 if (UDT::setsockopt(socket_fd, 0, UDT_RCVTIMEO, &timeout, sizeof(int)) != 0) 106 106 Err("UDT::setsockopt error (UDT_RCVTIMEO)\n"); 107 107 /* 108 timeout=-1; 109 if (UDT::setsockopt(socket_fd, 0, UDT_SNDTIMEO, &timeout, sizeof(int)) != 0) 110 Err("UDT::setsockopt error (UDT_SNDTIMEO)\n"); 111 */ 108 112 bool blocking = true; 109 113 if (UDT::setsockopt(socket_fd, 0, UDT_SNDSYN, &blocking, sizeof(bool)) != 0) … … 138 142 139 143 Join(); 140 144 145 char buf=CLOSING_CONNECTION; 146 Send(&buf,1); 147 141 148 if (send_buffer != NULL) 142 149 free(send_buffer); … … 196 203 nb_write = UDT::sendmsg(socket_fd, tosend, size, -1, true); 197 204 #endif // COMPRESS_FRAMES 198 //Printf("write %i %i\n",nb_write,size);205 //Printf("write %i %i\n",nb_write,size); 199 206 if (nb_write < 0) { 200 207 Err("UDT::sendmsg error (%s)\n", UDT::getlasterror().getErrorMessage()); -
trunk/lib/FlairCore/src/unexported/communication.h
r234 r247 12 12 #define DATAS_LITTLE_ENDIAN 0x02 13 13 #define DATAS_BIG_ENDIAN 0x03 14 #define CLOSING_CONNECTION 0x04 14 15 16 //messages file socket 15 17 #define START_SENDING_FILES 0x10 16 18 #define FILE_INFO_LITTLE_ENDIAN 0x11 -
trunk/lib/FlairFilter/src/Pid.cpp
r214 r247 47 47 } 48 48 49 float Pid::GetIntegral(void) const { return pimpl_->i; } 50 49 51 void Pid::UpdateFrom(const io_data *data) { 50 52 pimpl_->UpdateFrom(data); -
trunk/lib/FlairFilter/src/Pid.h
r15 r247 58 58 */ 59 59 void Reset(void); 60 61 /*! 62 * \brief Get intergral part 63 * 64 * \return current integral part 65 */ 66 float GetIntegral(void) const; 67 60 68 61 69 /*! -
trunk/tools/FlairGCS/src/ConnectionLayout.cpp
r244 r247 18 18 } 19 19 20 QString ConnectionLayout::getUDTStats() {21 return socket->getUDTStats();22 }23 24 20 void ConnectionLayout::receive(char *buf, int size) { 25 //fprintf(stderr,"trame %x\n",buf[0]);21 //fprintf(stderr,"trame %x\n",buf[0]); 26 22 // for(int i=0; i<size;i++) fprintf(stderr,"%x ",buf[i]); 27 23 // fprintf(stderr,"\n"); … … 57 53 // fprintf(stderr,"recu %i period %i\n",size,period); 58 54 drawDatas(&buf[3], size - 3, period); 55 break; 56 } 57 case CLOSING_CONNECTION: { 58 deleteLater(); 59 59 break; 60 60 } -
trunk/tools/FlairGCS/src/ConnectionLayout.h
r234 r247 22 22 void LoadXml(QDomDocument to_parse); 23 23 QString getName(); 24 QString getUDTStats();25 24 static QString getDocRootName(char* buf, int size); 26 25 -
trunk/tools/FlairGCS/src/Manager.cpp
r244 r247 46 46 // tab bar for multiple connections 47 47 tabBar = new QTabBar(); 48 //tabBar->setTabsClosable(true); 48 49 managerLayout->addWidget(tabBar); 49 50 connect(tabBar, SIGNAL(currentChanged(int)), this, … … 95 96 } 96 97 98 99 icon_ok = QIcon(":green.png"); 100 icon_ko = QIcon(":red.png"); 101 102 97 103 QTimer *timer = new QTimer(this); 98 104 connect(timer, SIGNAL(timeout()), this, SLOT(acceptConnections())); … … 101 107 102 108 Manager::~Manager() { 103 for (int i = 0; i < udtSockets.count(); i++) {104 udtSockets.at(i)->kill();105 udtSockets.at(i)->thread()->wait();109 for (int i = 0; i < connections.count(); i++) { 110 connections.at(i).socket->kill(); 111 connections.at(i).socket->thread()->wait(); 106 112 } 107 113 … … 127 133 UdtSocket *udtSocket = new UdtSocket(socket,name); 128 134 udtSocket->moveToThread(thread); 129 udtSockets.append(udtSocket); 130 135 131 136 connect(udtSocket, SIGNAL(newFileUI(UDTSOCKET)), this, SLOT(newFileUI(UDTSOCKET))); 132 137 connect(udtSocket, SIGNAL(newConnectionLayout(QString)), this, SLOT(newConnectionLayout(QString)),Qt::BlockingQueuedConnection); … … 141 146 142 147 ConnectionLayout *newLayout = new ConnectionLayout(udtSocket, name); 143 connectionsLayout.append(newLayout);144 148 connect(udtSocket, SIGNAL(UDTStats(QString)), newLayout, SIGNAL(UDTStats(QString)));//connection in 2 steps to get udtsocket as sender 145 149 connect(newLayout, SIGNAL(UDTStats(QString)), this, SLOT(printUDTStats(QString))); … … 147 151 connect(newLayout, SIGNAL(destroyed(QObject *)), this, SLOT(layoutDestroyed(QObject *))); 148 152 connect(udtSocket, SIGNAL(destroyed(QObject *)), this, SLOT(udtSocketDestroyed(QObject *))); 149 connect(udtSocket, SIGNAL(destroyed()), newLayout, SLOT(deleteLater())); 150 151 // widget 153 154 // widget 152 155 QWidget *newWidget = new QWidget(); 153 connectionsWidget.append(newWidget);154 156 newWidget->setLayout(newLayout->getQGridLayout()); 155 157 managerLayout->insertWidget(1, newWidget); 156 158 newWidget->hide(); 157 159 160 connections_t connection; 161 connection.layout=newLayout; 162 connection.widget=newWidget; 163 connection.socket=udtSocket; 164 connections.append(connection); 165 158 166 //tab: avoid having only 1 tab (0, 2 or more) 159 if (connections Layout.count() == 1) { // first connection160 connectionsWidget.at(0)->show();167 if (connections.count() == 1) { // first connection 168 newWidget->show(); 161 169 hiddenTabName = name; 162 170 } 163 if (connections Layout.count() == 2) {164 tabBar->addTab( hiddenTabName);171 if (connections.count() == 2) { 172 tabBar->addTab(icon_ok,hiddenTabName); 165 173 currentTab = 0; 166 174 } 167 if (connections Layout.count() > 1) {168 tabBar->addTab( name);175 if (connections.count() > 1) { 176 tabBar->addTab(icon_ok,name); 169 177 } 170 178 } 171 179 172 180 void Manager::udtSocketDestroyed(QObject *obj) { 173 udtSockets.removeOne((UdtSocket *)obj); 181 fprintf(stderr,"sockets -1\n"); 182 //mark socket as not valid, it can be a connection lost 183 //in this case we keep the layout for reading, and mark it as problematic 184 fprintf(stderr,"change icon\n"); 185 for(int i=0;i<connections.count();i++) { 186 if(connections.at(i).socket==(UdtSocket *)obj) { 187 connections[i].socket=NULL; 188 break; 189 } 190 } 174 191 } 175 192 176 193 void Manager::layoutDestroyed(QObject *obj) { 177 int index = connectionsLayout.indexOf((ConnectionLayout *)obj); 178 179 delete connectionsWidget.at(index); 180 connectionsWidget.removeAt(index); 181 connectionsLayout.removeOne((ConnectionLayout *)obj); 182 183 //tab: avoid having only 1 tab (0, 2 or more) 194 fprintf(stderr,"layout -1\n"); 195 //remove the connection, it comes from a proper close 196 int index=-1; 197 for(int i=0;i<connections.count();i++) { 198 if(connections.at(i).layout==(ConnectionLayout *)obj) { 199 delete connections.at(i).widget; 200 //connections[i].widget=NULL; 201 //connections[i].layout=NULL; 202 connections.removeAt(i); 203 index=i; 204 break; 205 } 206 } 207 208 if(index==-1) { 209 fprintf(stderr,"layoutDestroyed: error, layout not found!\n"); 210 return; 211 } 212 213 //tab: avoid having only 1 tab (only 0, 2 or more) 184 214 if (tabBar->count() > 1) { 185 215 tabBar->removeTab(index); 186 216 } 187 217 188 if (connections Layout.count() == 1) {218 if (connections.count() == 1) { 189 219 hiddenTabName = tabBar->tabText(0); 190 220 tabBar->removeTab(0); 191 221 } 192 222 193 if (connections Layout.count() == 0) {223 if (connections.count() == 0) { 194 224 status->showMessage(""); 195 225 } 196 197 198 226 } 199 227 200 228 void Manager::newFileUI(UDTSOCKET socket) { 201 //remove udtsocket as it will be automatically destroyed202 udtSockets.removeOne((UdtSocket *)sender());203 204 229 QThread *thread = new QThread(this); 205 230 file_ui* fileUi = new file_ui(socket,name); … … 216 241 217 242 void Manager::printUDTStats(QString stats) { 218 int index = connectionsLayout.indexOf((ConnectionLayout *)sender()); 243 int index = -1; 244 for(int i=0;i<connections.count();i++) { 245 if(connections.at(i).layout==(ConnectionLayout *)sender()) { 246 index=i; 247 break; 248 } 249 } 250 219 251 if(index==-1) return; 220 252 … … 230 262 if (index >= 0) { 231 263 //if we are coming from layout destroyed 232 if(currentTab<connections Layout.count()) connectionsWidget.at(currentTab)->hide();233 connections Widget.at(index)->show();264 if(currentTab<connections.count()) connections.at(currentTab).widget->hide(); 265 connections.at(index).widget->show(); 234 266 currentTab = index; 235 267 } else { 236 268 currentTab = 0; 237 connectionsWidget.at(0)->show(); 238 } 269 connections.at(0).widget->show(); 270 } 271 QString msg="not connected"; 239 272 if (tabBar->count() == 0) { 240 status->showMessage(connectionsLayout.at(0)->getUDTStats()); 273 if(connections.at(0).socket!=NULL) msg=connections.at(0).socket->getUDTStats(); 274 241 275 } else { 242 status->showMessage(QString("%1: %2").arg(tabBar->tabText(index)).arg(connectionsLayout.at(index)->getUDTStats())); 243 } 276 if(connections.at(index).socket!=NULL) msg=QString("%1: %2").arg(tabBar->tabText(index)).arg(connections.at(index).socket->getUDTStats()); 277 } 278 status->showMessage(msg); 244 279 } 245 280 … … 249 284 250 285 if (dir_name != "") { 251 for (int i = 0; i < connections Layout.count(); i++) {286 for (int i = 0; i < connections.count(); i++) { 252 287 QFile *file; 253 288 file = new QFile(dir_name + "/" + 254 connections Layout.at(i)->getName() + ".xml");289 connections.at(i).layout->getName() + ".xml"); 255 290 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { 256 291 QMessageBox::warning(this, "Warning", 257 292 "Enable to load " + 258 connections Layout.at(i)->getName() +293 connections.at(i).layout->getName() + 259 294 ".xml"); 260 295 continue; … … 268 303 QMessageBox::critical( 269 304 this, "Error", 270 "unable to read " + connections Layout.at(i)->getName() +305 "unable to read " + connections.at(i).layout->getName() + 271 306 ".xml" + " (" + errorMsg + " at " + QString::number(errorLine) + 272 307 "," + QString::number(errorColumn) + ")"); 273 308 } else { 274 connections Layout.at(i)->LoadXml(doc);309 connections.at(i).layout->LoadXml(doc); 275 310 } 276 311 delete file; … … 282 317 bool isUptodate = true; 283 318 284 for (int i = 0; i < connections Layout.count(); i++) {285 if (!connections Layout.at(i)->IsUptodate()) {319 for (int i = 0; i < connections.count(); i++) { 320 if (!connections.at(i).layout->IsUptodate()) { 286 321 isUptodate = false; 287 322 break; … … 319 354 QDir().mkdir(dir_name); 320 355 321 for (int i = 0; i < connections Layout.count(); i++) {356 for (int i = 0; i < connections.count(); i++) { 322 357 QDomDocument *xml = new QDomDocument("remote_ui_xml"); 323 358 324 connections Layout.at(i)->GetFullXml((QDomElement *)xml);325 326 QFile fichier(dir_name + "/" + connections Layout.at(i)->getName() +359 connections.at(i).layout->GetFullXml((QDomElement *)xml); 360 361 QFile fichier(dir_name + "/" + connections.at(i).layout->getName() + 327 362 ".xml"); 328 363 QString write_doc = (xml->ownerDocument()).toString(); … … 344 379 345 380 void Manager::send(void) { 346 for (int i = 0; i < connections Layout.count(); i++) {381 for (int i = 0; i < connections.count(); i++) { 347 382 QDomDocument doc("remote_ui_xml"); 348 connections Layout.at(i)->GetUpdateXml((QDomElement *)&doc);383 connections.at(i).layout->GetUpdateXml((QDomElement *)&doc); 349 384 // fprintf(stderr,"merge\n%s\n",doc.toString().toLocal8Bit().constData()); 350 385 351 connections Layout.at(i)->XmlToSend(doc);386 connections.at(i).layout->XmlToSend(doc); 352 387 } 353 388 } 354 389 355 390 void Manager::reset() { 356 for (int i = 0; i < connections Layout.count(); i++)357 connections Layout.at(i)->ResetAllChilds();358 } 391 for (int i = 0; i < connections.count(); i++) 392 connections.at(i).layout->ResetAllChilds(); 393 } -
trunk/tools/FlairGCS/src/Manager.h
r244 r247 7 7 8 8 #include <QWidget> 9 #include <QIcon> 9 10 #include <udt.h> 10 11 #include <qdom.h> … … 28 29 UDTSOCKET serv; 29 30 QVBoxLayout *managerLayout; 30 QList<ConnectionLayout *> connectionsLayout; 31 QList<QWidget *> connectionsWidget; 32 QList<UdtSocket *> udtSockets; 31 typedef struct { 32 ConnectionLayout *layout; 33 QWidget *widget; 34 UdtSocket *socket; 35 } connections_t; 36 QList<connections_t> connections; 37 //QList<ConnectionLayout *> connectionsLayout; 38 //QList<UdtSocket *> udtSockets; 33 39 QTabBar *tabBar; 34 40 QString name, hiddenTabName; … … 41 47 QGridLayout *button_layout; 42 48 QStatusBar *status; 49 QIcon icon_ok,icon_ko; 43 50 44 51 private slots: -
trunk/tools/FlairGCS/src/UdtSocket.cpp
r244 r247 53 53 heartbeat_timer->stop(); 54 54 udtstats_timer->stop(); 55 if(destroySocket) UDT::close(socket); 55 if(destroySocket) UDT::close(socket); 56 fprintf(stderr,"fin udt\n"); 56 57 } 57 58 … … 151 152 int num = 1; 152 153 UDTSOCKET readfds; 154 153 155 int rv = UDT::epoll_wait2(eid, &readfds, &num,NULL, NULL,100); 154 155 156 if (rv == -1) { 156 157 if (UDT::getlasterror().getErrorCode() != 6003) … … 158 159 } else if(readfds==socket && num==1 && rv==1) { 159 160 160 int size=UDT::recvmsg(socket, buf, buf_size); 161 if (size > 0) { 162 total_received+=size; 163 164 switch ((unsigned char)buf[0]) { 165 case ZLIB_HEADER: { 166 ssize_t out_size; 167 uncompressBuffer(buf, size, uncompressbuf, &out_size); 168 if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) { 169 socketType=gui; 170 QString remoteName=ConnectionLayout::getDocRootName(uncompressbuf, out_size); 171 setName(remoteName); 172 emit newConnectionLayout(remoteName);//connection is Qt::BlockingQueuedConnection 161 int size; 162 do { 163 size=UDT::recvmsg(socket, buf, buf_size); 164 165 //fprintf(stderr,"recu %i\n",size); 166 if (size > 0) { 167 total_received+=size; 168 169 switch ((unsigned char)buf[0]) { 170 case ZLIB_HEADER: { 171 ssize_t out_size; 172 uncompressBuffer(buf, size, uncompressbuf, &out_size); 173 if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) { 174 socketType=gui; 175 QString remoteName=ConnectionLayout::getDocRootName(uncompressbuf, out_size); 176 setName(remoteName); 177 emit newConnectionLayout(remoteName);//connection is Qt::BlockingQueuedConnection 178 } 179 emit dataReady(uncompressbuf, out_size);//connection is Qt::BlockingQueuedConnection, as we have only one buffer 180 break; 173 181 } 174 emit dataReady(uncompressbuf, out_size);//connection is Qt::BlockingQueuedConnection, as we have only one buffer 175 break; 182 case START_SENDING_FILES: { 183 if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) { 184 socketType=log; 185 } 186 setName("log files"); 187 heartbeat_timer->stop(); 188 emit newFileUI(socket); 189 deleteLater(); 190 stop=true; 191 destroySocket=false; 192 break; 193 } 194 case XML_HEADER: 195 if(socketType==unknown) { 196 socketType=gui; 197 QString remoteName=ConnectionLayout::getDocRootName(buf, size ); 198 setName(remoteName); 199 emit newConnectionLayout(remoteName); 200 } 201 case DATAS_BIG_ENDIAN: 202 case DATAS_LITTLE_ENDIAN: 203 emit dataReady(buf, size ); 204 break; 205 case CLOSING_CONNECTION: 206 fprintf(stderr,"%s, connection closed\n",name.toLocal8Bit().constData()); 207 emit dataReady(buf, size ); 208 stop = true; 209 heartbeat_timer->stop(); 210 deleteLater(); 211 break; 212 default: 213 fprintf(stderr,"trame non supportée %x\n", buf[0]); 176 214 } 177 case START_SENDING_FILES: { 178 if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) { 179 socketType=log; 180 } 181 setName("log files"); 182 heartbeat_timer->stop(); 183 emit newFileUI(socket); 184 deleteLater(); 185 stop=true; 186 destroySocket=false; 187 break; 188 } 189 case XML_HEADER: 190 if(socketType==unknown) { 191 socketType=gui; 192 QString remoteName=ConnectionLayout::getDocRootName(buf, size ); 193 setName(remoteName); 194 emit newConnectionLayout(remoteName); 195 } 196 case DATAS_BIG_ENDIAN: 197 case DATAS_LITTLE_ENDIAN: 198 emit dataReady(buf, size ); 199 break; 215 } else { 216 //not necessary to check, watchdog (heartbeat_timer) can do it 217 //if(UDT::getlasterror().getErrorCode()!=6002 && !stop) 218 //fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage()); 219 //UDT::close(socket);//si deconnecté 220 //free(buf); 221 //break; 200 222 } 201 } else { 202 if(UDT::getlasterror().getErrorCode()!=6002) 203 fprintf(stderr,"udt socket: %s %i\n",UDT::getlasterror().getErrorMessage(),size); 204 //UDT::close(socket);//si deconnecté 205 //free(buf); 206 //break; 207 } 223 } while(size>0); 208 224 } else { 209 fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage()); 225 //not necessary to check, watchdog (heartbeat_timer) can do it 226 //fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage()); 210 227 } 211 228 UDT::epoll_remove_usock(eid, socket); 212 229 UDT::epoll_release(eid); 213 230 } 231 214 232 free(uncompressbuf); 215 233 free(buf); -
trunk/tools/FlairGCS/src/ressources.qrc
r9 r247 5 5 <file>landmark.png</file> 6 6 <file>cross.png</file> 7 <file>green.png</file> 8 <file>red.png</file> 7 9 </qresource> 8 10 </RCC>
Note:
See TracChangeset
for help on using the changeset viewer.