Changeset 213 in flair-src for trunk/lib/FlairCore/src/FrameworkManager_impl.cpp
- Timestamp:
- 01/30/18 17:47:12 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/FrameworkManager_impl.cpp
r186 r213 141 141 void FrameworkManager_impl::ConnectionLost(void) { 142 142 Err("connection lost\n"); 143 gcs_watchdog->SafeStop();143 if(gcs_watchdog!=NULL) gcs_watchdog->SafeStop(); 144 144 connection_lost = true; 145 145 } … … 148 148 // Printf("destruction FrameworkManager_impl\n"); 149 149 int status; 150 char errorMsg[256];151 150 152 151 SafeStop(); … … 162 161 status = DeletePipe(&cmd_pipe); 163 162 if (status != 0) { 163 char errorMsg[256]; 164 164 Err("Error deleting pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 165 165 } 166 166 status = DeletePipe(&data_pipe); 167 167 if (status != 0) { 168 char errorMsg[256]; 168 169 Err("Error deleting pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 169 170 } … … 172 173 status = rt_heap_delete(&log_heap); 173 174 if (status != 0) { 175 char errorMsg[256]; 174 176 Err("rt_heap_delete error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 175 177 } … … 237 239 // watchdog for connection with ground station 238 240 connection_lost = false; 239 gcs_watchdog = new Watchdog( 240 this, std::bind(&FrameworkManager_impl::ConnectionLost, this), 241 watchdogTimeout); 241 gcs_watchdog = new Watchdog(this, std::bind(&FrameworkManager_impl::ConnectionLost, this),watchdogTimeout); 242 242 gcs_watchdog->Start(); 243 243 } … … 340 340 } 341 341 case WATCHDOG_HEADER: { 342 gcs_watchdog->Touch();342 if(gcs_watchdog!=NULL) gcs_watchdog->Touch(); 343 343 break; 344 344 } … … 411 411 Printf("sending %s, size: %i\n", filename.c_str(), size); 412 412 // send file information 413 UDT::sendmsg(file_sock, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1, 414 true); 413 UDT::sendmsg(file_sock, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1,true); 415 414 416 415 more_buf = (char *)realloc((void *)buf, size); … … 464 463 } 465 464 466 467 468 465 //wait end ACK 466 int nb_read = UDT::recvmsg(file_sock,&buf,1); 467 if(nb_read<0) { 469 468 Err("UDT::recvmsg error (%s)\n",UDT::getlasterror().getErrorMessage()); 470 469 } else if (nb_read != 1) { 471 470 Err("UDT::recvmsg error, sent %i/%i\n",nb_read,1); 472 471 } 473 472 } 474 473 … … 567 566 #endif 568 567 569 void FrameworkManager_impl::SetupLogger(string log_path) { 570 char errorMsg[256]; 568 void FrameworkManager_impl::SetupLogger(string log_path,uint32_t stackSize) { 571 569 572 570 if (logger_defined == true) { … … 579 577 int status = CreatePipe(&cmd_pipe, "log_cmd"); 580 578 if (status != 0) { 579 char errorMsg[256]; 581 580 Err("Error creating pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 582 581 return; … … 585 584 status = CreatePipe(&data_pipe, "log_data"); 586 585 if (status != 0) { 586 char errorMsg[256]; 587 587 Err("Error creating pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 588 588 return; … … 592 592 string tmp_name; 593 593 tmp_name = self->ObjectName() + "-log_heap"; 594 status = rt_heap_create(&log_heap, tmp_name.c_str(), LOG_HEAP, H_FIFO);594 status = rt_heap_create(&log_heap, tmp_name.c_str(), RT_LOG_HEAP, H_FIFO); 595 595 if (status != 0) { 596 char errorMsg[256]; 596 597 Err("rt_heap_create error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 597 598 return; … … 601 602 continuer = true; 602 603 603 #ifdef NRT_STACK_SIZE604 604 // Initialize thread creation attributes 605 605 pthread_attr_t attr; 606 if (pthread_attr_init(&attr) != 0) { 607 Err("pthread_attr_init error\n"); 608 return; 609 } 610 611 if (pthread_attr_setstacksize(&attr, NRT_STACK_SIZE) != 0) { 612 Err("pthread_attr_setstacksize error\n"); 613 return; 614 } 615 616 if (pthread_create(&log_th, &attr, write_log_user, (void *)this) < 0) 617 #else 618 if (pthread_create(&log_th, NULL, write_log_user, (void *)this) < 0) 619 #endif 620 { 621 Err("pthread_create error\n"); 622 return; 623 } 624 #ifdef NRT_STACK_SIZE 625 if (pthread_attr_destroy(&attr) != 0) { 626 Err("pthread_attr_destroy error\n"); 627 return; 628 } 629 #endif 606 status=pthread_attr_init(&attr); 607 if (status != 0) { 608 char errorMsg[256]; 609 Err("pthread_attr_init error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 610 return; 611 } 612 613 status=pthread_attr_setstacksize(&attr, stackSize); 614 if (status != 0) { 615 char errorMsg[256]; 616 Err("pthread_attr_setstacksize error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 617 return; 618 } 619 620 status=pthread_create(&log_th, &attr, write_log_user, (void *)this); 621 if (status < 0) { 622 char errorMsg[256]; 623 Err("pthread_create error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 624 return; 625 } 626 627 status=pthread_attr_destroy(&attr); 628 if (status != 0) { 629 char errorMsg[256]; 630 Err("pthread_attr_destroy error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg))); 631 return; 632 } 630 633 631 634 logger_defined = true; … … 781 784 int cmd_pipe = -1; 782 785 int data_pipe = -1; 783 string filename;784 786 fd_set set; 785 787 struct timeval timeout; … … 790 792 791 793 #ifdef __XENO__ 792 char errorMsg[256];793 filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_cmd";794 794 while (cmd_pipe < 0) { 795 string filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_cmd"; 795 796 cmd_pipe = open(filename.c_str(), O_RDWR); 796 if (cmd_pipe < 0 && errno != ENOENT) 797 if (cmd_pipe < 0 && errno != ENOENT) { 798 char errorMsg[256]; 797 799 caller->self->Err("open rt_pipe error: %s %s\n", filename.c_str(), strerror_r(errno, errorMsg, sizeof(errorMsg))); 800 } 798 801 usleep(1000); 799 802 } 800 filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_data";801 803 while (data_pipe < 0) { 804 string filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_data"; 802 805 data_pipe = open(filename.c_str(), O_RDWR); 803 if (data_pipe < 0 && errno != ENOENT) 806 if (data_pipe < 0 && errno != ENOENT) { 807 char errorMsg[256]; 804 808 caller->self->Err("open rt_pipe error: %s %s\n", filename.c_str(), strerror_r(errno, errorMsg, sizeof(errorMsg))); 809 } 805 810 usleep(1000); 806 811 } … … 829 834 read(cmd_pipe, &tmp, sizeof(log_desc_t)); 830 835 831 if (tmp.running == true) // start logging 832 { 833 filename = caller->log_path + "/" + caller->FileName(tmp.device) + ".dbt"; 836 if (tmp.running == true) {// start logging 837 string filename = caller->log_path + "/" + caller->FileName(tmp.device) + ".dbt"; 834 838 printf("Creating log file %s (log size %i)\n", filename.c_str(), (int)tmp.size); 835 839 tmp.dbtFile = inithdFile((char *)filename.c_str(), UAV, tmp.size); … … 840 844 xmlSaveFile(filename.c_str(), caller->file_doc); 841 845 } 842 } else // stop logging 843 { 844 //disable watchdog temporarly 845 //this is necessary because GCS is no longer sending the heartbeat when receiving files... 846 //TODO: add a thread in GCS for receiving file 847 //but be careful that with a xbee modem for exemple, sending files can saturate communication and 848 //avoid the heartbeat to be received... so disabling watchdog is not a so bad option... 849 if(caller->gcs_watchdog!=NULL) { 850 caller->gcs_watchdog->SafeStop(); 851 caller->gcs_watchdog->Join(); 852 } 846 } else {// stop logging 847 //disable watchdog temporarly 848 //this is necessary because GCS is no longer sending the heartbeat when receiving files... 849 //TODO: add a thread in GCS for receiving file 850 //but be careful that with a xbee modem for exemple, sending files can saturate communication and 851 //avoid the heartbeat to be received... so disabling watchdog is not a so bad option... 852 if(caller->gcs_watchdog!=NULL) { 853 caller->gcs_watchdog->SafeStop(); 854 caller->gcs_watchdog->Join(); 855 } 853 856 for (size_t i = 0; i < logs.size(); i++) { 854 857 if (logs.at(i).dbtFile != NULL) { 855 858 close_hdfile(logs.at(i).dbtFile); 856 859 857 filename = caller->FileName(logs.at(i).device) + ".dbt";860 string filename = caller->FileName(logs.at(i).device) + ".dbt"; 858 861 caller->SendFile(caller->log_path, filename); 859 862 … … 875 878 876 879 logs.clear(); 877 878 879 880 880 //enable watchdog again 881 if(caller->gcs_watchdog!=NULL) { 882 caller->gcs_watchdog->Start(); 883 } 881 884 } 882 885 }
Note:
See TracChangeset
for help on using the changeset viewer.