Changeset 234 in flair-src for trunk/lib/FlairCore
- Timestamp:
- Apr 10, 2018, 5:05:27 PM (7 years ago)
- Location:
- trunk/lib/FlairCore/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/FrameworkManager_impl.cpp
r214 r234 193 193 Printf("Error udt::close %s", UDT::getlasterror().getErrorMessage()); 194 194 195 status = UDT::close(file_sock);196 if (status != 0)197 Printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());198 199 195 SleepMS(200); // a revoir, sinon UDT::cleanup bloque en RT 200 196 UDT::cleanup(); … … 210 206 return; 211 207 } 208 this->address=address; 209 this->port=port; 212 210 213 211 UDT::startup(1024*256,1024*256,1024*256); … … 216 214 // socket file_socket, doit être créé en premier, cf station sol 217 215 Printf("Connecting to %s:%i\n", address.c_str(), port); 218 file_sock = GetSocket(address, port);219 com_sock = GetSocket( address, port);216 //file_sock = GetSocket(address, port); 217 com_sock = GetSocket(); 220 218 221 219 // receive buffer allocation … … 226 224 227 225 com = new ui_com(this, com_sock); 228 229 // file managment230 bool blocking = true;231 UDT::setsockopt(file_sock, 0, UDT_SNDSYN, &blocking, sizeof(bool));232 UDT::setsockopt(file_sock, 0, UDT_RCVSYN, &blocking, sizeof(bool));233 234 int timeout = 100; // ms235 UDT::setsockopt(com_sock, 0, UDT_RCVTIMEO, &timeout, sizeof(int));236 226 237 227 Start(); … … 292 282 while (!ToBeStopped()) { 293 283 ssize_t bytesRead; 294 295 284 bytesRead = com->Receive(rcv_buf, rcv_buf_size); 296 285 com->CheckConnection(); 286 //printf("%i\n",bytesRead); 297 287 if (bytesRead == (ssize_t)rcv_buf_size) 298 288 Err("FrameworkManager max receive size, augmenter le buffer size!\n"); 299 289 300 290 if (bytesRead > 0) { 301 // printf("recu %ld, trame %x\n",bytesRead,(uint8_t)rcv_buf[0]);302 //rcv_buf[bytesRead-1]=0;//pour affichage303 //printf("%s\n",rcv_buf);291 //printf("recu %ld, trame %x %lld\n",bytesRead,(uint8_t)rcv_buf[0],GetTime()/(1000000)); 292 //rcv_buf[bytesRead-1]=0;//pour affichage 293 //printf("%s\n",rcv_buf); 304 294 305 295 switch ((uint8_t)rcv_buf[0]) { … … 376 366 } 377 367 378 void FrameworkManager_impl::SendFile( string path, string name) {368 void FrameworkManager_impl::SendFile(UDTSOCKET socket,string path, string name) { 379 369 char *buf, *more_buf; 380 370 int size; … … 411 401 Printf("sending %s, size: %i\n", filename.c_str(), size); 412 402 // send file information 413 UDT::sendmsg( file_sock, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1,true);403 UDT::sendmsg(socket, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1,true); 414 404 415 405 more_buf = (char *)realloc((void *)buf, size); … … 424 414 pbuf->sgetn(buf, size); 425 415 // send the file 426 nb_write = UDT::sendmsg( file_sock, buf, size, -1, true);416 nb_write = UDT::sendmsg(socket, buf, size, -1, true); 427 417 428 418 if (nb_write < 0) { … … 436 426 } 437 427 438 void FrameworkManager_impl::FinishSending( ) {428 void FrameworkManager_impl::FinishSending(UDTSOCKET socket) { 439 429 char rm_cmd[256]; 440 430 441 431 // send orignal xml 442 SendFile( log_path, "setup.xml");432 SendFile(socket,log_path, "setup.xml"); 443 433 sprintf(rm_cmd, "rm %s/setup.xml", log_path.c_str()); 444 434 system(rm_cmd); … … 447 437 for (size_t i = 0; i < xml_changes.size(); i++) { 448 438 // Printf("%s\n",xml_changes.at(i).c_str()); 449 SendFile( log_path, xml_changes.at(i).c_str());439 SendFile(socket,log_path, xml_changes.at(i).c_str()); 450 440 sprintf(rm_cmd, "rm %s/%s", log_path.c_str(), xml_changes.at(i).c_str()); 451 441 system(rm_cmd); … … 454 444 455 445 // end notify 456 char buf = END ;457 int nb_write = UDT::sendmsg( file_sock, &buf, 1, -1, true);446 char buf = END_SENDING_FILES; 447 int nb_write = UDT::sendmsg(socket, &buf, 1, -1, true); 458 448 459 449 if (nb_write < 0) { … … 464 454 465 455 //wait end ACK 466 int nb_read = UDT::recvmsg( file_sock,&buf,1);456 int nb_read = UDT::recvmsg(socket,&buf,1); 467 457 if(nb_read<0) { 468 458 Err("UDT::recvmsg error (%s)\n",UDT::getlasterror().getErrorMessage()); … … 472 462 } 473 463 474 UDTSOCKET FrameworkManager_impl::GetSocket( string address, uint16_t port) {464 UDTSOCKET FrameworkManager_impl::GetSocket(void) { 475 465 while (1) { 476 466 UDTSOCKET new_fd; … … 854 844 caller->gcs_watchdog->Join(); 855 845 } 846 //create a socket for files 847 UDTSOCKET file_sock = caller->GetSocket(); 848 char data=START_SENDING_FILES; 849 ssize_t nb_write = UDT::sendmsg(file_sock, &data, 1, -1, true); 850 if (nb_write < 0) { 851 caller->Err("UDT::sendmsg error (%s)\n", UDT::getlasterror().getErrorMessage()); 852 if (UDT::getlasterror().getErrorCode() == CUDTException::ECONNLOST || 853 UDT::getlasterror().getErrorCode() == CUDTException::EINVSOCK) { 854 } 855 } else if (nb_write != 1) { 856 caller->Err("%s, code %i (%ld/%ld)\n", UDT::getlasterror().getErrorMessage(), 857 UDT::getlasterror().getErrorCode(), nb_write, 1); 858 } 856 859 for (size_t i = 0; i < logs.size(); i++) { 857 860 if (logs.at(i).dbtFile != NULL) { … … 859 862 860 863 string filename = caller->FileName(logs.at(i).device) + ".dbt"; 861 caller->SendFile( caller->log_path, filename);864 caller->SendFile(file_sock,caller->log_path, filename); 862 865 863 866 fstream txt_file; … … 870 873 txt_file.close(); 871 874 872 caller->SendFile( caller->log_path, filename);875 caller->SendFile(file_sock,caller->log_path, filename); 873 876 } 874 877 } 875 878 // a revoir celui ci est le xml enregistré et pas forcement l'actuel 876 879 // if(caller->xml_file!="") caller->SendFile(caller->xml_file); 877 caller->FinishSending(); 880 caller->FinishSending(file_sock); 881 882 int status = UDT::close(file_sock); 883 if (status != 0) 884 caller->Err("Error udt::close %s", UDT::getlasterror().getErrorMessage()); 878 885 879 886 logs.clear(); -
trunk/lib/FlairCore/src/ui_com.cpp
r213 r234 223 223 } 224 224 225 void ui_com::CheckConnection(void) { 226 int32_t val,len; 227 228 int result=UDT::getsockopt(socket_fd,0,UDT_STATE,&val,&len); 229 if (result < 0) { 230 Printf("UDT::getsockopt error (%s)\n", UDT::getlasterror().getErrorMessage()); 231 } 232 // printf("opt: %i %i %i\n",result,val,len); 233 } 234 225 235 void ui_com::Run(void) { 226 236 // check endianness -
trunk/lib/FlairCore/src/unexported/FrameworkManager_impl.h
r213 r234 82 82 private: 83 83 flair::core::FrameworkManager *self; 84 UDTSOCKET file_sock,com_sock;85 UDTSOCKET GetSocket( std::string address, uint16_t port);84 UDTSOCKET com_sock; 85 UDTSOCKET GetSocket(void); 86 86 void Run(); 87 void SendFile( std::string path, std::string name);88 void FinishSending( void);87 void SendFile(UDTSOCKET socket,std::string path, std::string name); 88 void FinishSending(UDTSOCKET socket); 89 89 std::string FileName(flair::core::IODevice *device); 90 90 void SaveXmlChange(char *buf); … … 92 92 size_t rcv_buf_size; 93 93 char *rcv_buf; 94 std::string address; 95 uint16_t port; 94 96 #ifdef __XENO__ 95 97 int CreatePipe(RT_PIPE *fd, std::string name); -
trunk/lib/FlairCore/src/unexported/communication.h
r15 r234 6 6 #define COMMUNICATION_H 7 7 8 // messages file socket 9 #define FILE_INFO_LITTLE_ENDIAN 0x01 10 #define FILE_INFO_BIG_ENDIAN 0x02 11 #define END 0x03 12 8 // messages data socket 13 9 #define XML_HEADER 0x3c 14 10 #define ZLIB_HEADER 0x78 15 11 #define WATCHDOG_HEADER 0x01 12 #define DATAS_LITTLE_ENDIAN 0x02 13 #define DATAS_BIG_ENDIAN 0x03 16 14 17 #define DATAS_LITTLE_ENDIAN 0xfd 18 #define DATAS_BIG_ENDIAN 0xfe 15 #define START_SENDING_FILES 0x10 16 #define FILE_INFO_LITTLE_ENDIAN 0x11 17 #define FILE_INFO_BIG_ENDIAN 0x12 18 #define END_SENDING_FILES 0x13 19 19 20 20 #endif // COMMUNICATION_H -
trunk/lib/FlairCore/src/unexported/ui_com.h
r15 r234 48 48 void UnBlock(void); 49 49 bool ConnectionLost(void); 50 50 void CheckConnection(void); 51 51 private: 52 52 ssize_t send_size;
Note:
See TracChangeset
for help on using the changeset viewer.