Ignore:
Timestamp:
01/30/18 17:47:12 (5 years ago)
Author:
Sanahuja Guillaume
Message:

thread stack size rework
add Matrix class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/FrameworkManager_impl.cpp

    r186 r213  
    141141void FrameworkManager_impl::ConnectionLost(void) {
    142142  Err("connection lost\n");
    143   gcs_watchdog->SafeStop();
     143  if(gcs_watchdog!=NULL) gcs_watchdog->SafeStop();
    144144  connection_lost = true;
    145145}
     
    148148  // Printf("destruction FrameworkManager_impl\n");
    149149  int status;
    150         char errorMsg[256];
    151150       
    152151  SafeStop();
     
    162161    status = DeletePipe(&cmd_pipe);
    163162    if (status != 0) {
     163      char errorMsg[256];
    164164      Err("Error deleting pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    165165    }
    166166    status = DeletePipe(&data_pipe);
    167167    if (status != 0) {
     168      char errorMsg[256];
    168169      Err("Error deleting pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    169170    }
     
    172173    status = rt_heap_delete(&log_heap);
    173174    if (status != 0) {
     175      char errorMsg[256];
    174176      Err("rt_heap_delete error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    175177    }
     
    237239  // watchdog for connection with ground station
    238240  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);
    242242  gcs_watchdog->Start();
    243243}
     
    340340      }
    341341      case WATCHDOG_HEADER: {
    342         gcs_watchdog->Touch();
     342        if(gcs_watchdog!=NULL) gcs_watchdog->Touch();
    343343        break;
    344344      }
     
    411411  Printf("sending %s, size: %i\n", filename.c_str(), size);
    412412  // 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);
    415414
    416415  more_buf = (char *)realloc((void *)buf, size);
     
    464463  }
    465464
    466     //wait end ACK
    467     int nb_read = UDT::recvmsg(file_sock,&buf,1);
    468     if(nb_read<0) {
     465  //wait end ACK
     466  int nb_read = UDT::recvmsg(file_sock,&buf,1);
     467  if(nb_read<0) {
    469468    Err("UDT::recvmsg error (%s)\n",UDT::getlasterror().getErrorMessage());
    470     } else if (nb_read != 1)  {
     469  } else if (nb_read != 1)  {
    471470    Err("UDT::recvmsg error, sent %i/%i\n",nb_read,1);
    472     }
     471  }
    473472}
    474473
     
    567566#endif
    568567
    569 void FrameworkManager_impl::SetupLogger(string log_path) {
    570   char errorMsg[256];
     568void FrameworkManager_impl::SetupLogger(string log_path,uint32_t stackSize) {
    571569       
    572570        if (logger_defined == true) {
     
    579577  int status = CreatePipe(&cmd_pipe, "log_cmd");
    580578  if (status != 0) {
     579    char errorMsg[256];
    581580    Err("Error creating pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    582581    return;
     
    585584  status = CreatePipe(&data_pipe, "log_data");
    586585  if (status != 0) {
     586    char errorMsg[256];
    587587    Err("Error creating pipe (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    588588    return;
     
    592592  string tmp_name;
    593593  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);
    595595  if (status != 0) {
     596    char errorMsg[256];
    596597    Err("rt_heap_create error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    597598    return;
     
    601602  continuer = true;
    602603
    603 #ifdef NRT_STACK_SIZE
    604604  // Initialize thread creation attributes
    605605  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  }
    630633
    631634  logger_defined = true;
     
    781784  int cmd_pipe = -1;
    782785  int data_pipe = -1;
    783   string filename;
    784786  fd_set set;
    785787  struct timeval timeout;
     
    790792
    791793#ifdef __XENO__
    792         char errorMsg[256];
    793   filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_cmd";
    794794  while (cmd_pipe < 0) {
     795    string filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_cmd";
    795796    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];
    797799      caller->self->Err("open rt_pipe error: %s %s\n", filename.c_str(), strerror_r(errno, errorMsg, sizeof(errorMsg)));
     800    }
    798801    usleep(1000);
    799802  }
    800   filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_data";
    801803  while (data_pipe < 0) {
     804    string filename = NRT_PIPE_PATH + caller->self->ObjectName() + "-log_data";
    802805    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];
    804808      caller->self->Err("open rt_pipe error: %s %s\n", filename.c_str(), strerror_r(errno, errorMsg, sizeof(errorMsg)));
     809    }
    805810    usleep(1000);
    806811  }
     
    829834        read(cmd_pipe, &tmp, sizeof(log_desc_t));
    830835
    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";
    834838          printf("Creating log file %s (log size %i)\n", filename.c_str(), (int)tmp.size);
    835839          tmp.dbtFile = inithdFile((char *)filename.c_str(), UAV, tmp.size);
     
    840844            xmlSaveFile(filename.c_str(), caller->file_doc);
    841845          }
    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          }
    853856          for (size_t i = 0; i < logs.size(); i++) {
    854857            if (logs.at(i).dbtFile != NULL) {
    855858              close_hdfile(logs.at(i).dbtFile);
    856859
    857               filename = caller->FileName(logs.at(i).device) + ".dbt";
     860              string filename = caller->FileName(logs.at(i).device) + ".dbt";
    858861              caller->SendFile(caller->log_path, filename);
    859862
     
    875878
    876879          logs.clear();
    877             //enable watchdog again
    878             if(caller->gcs_watchdog!=NULL) {
    879                 caller->gcs_watchdog->Start();
    880             }
     880          //enable watchdog again
     881          if(caller->gcs_watchdog!=NULL) {
     882              caller->gcs_watchdog->Start();
     883          }
    881884        }
    882885      }
Note: See TracChangeset for help on using the changeset viewer.