Exemplo n.º 1
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Fills out decl->Task data.
///
/// @param lkDecl      LK task declaration data
/// @param decl        task declaration data for device
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  declaration successfully filled out
/// @retval false error (description in @p errBuf)
///
//static
bool DevLXNano::FillTask(const Declaration_t& lkDecl, Decl& decl, unsigned errBufSize, TCHAR errBuf[])
{
  // to declared Start, TPs, and Finish we will add Takeoff and Landing,
  // so maximum NB of declared TPs is Decl::max_wp_count - 2
  if (!CheckWPCount(lkDecl,
      Decl::min_wp_count - 2, Decl::max_wp_count - 2, errBufSize, errBuf))
    return(false);

  int wpCount = lkDecl.num_waypoints;

  Decl::Task& task = decl.task;

  if (!GPS_INFO.NAVWarning && GPS_INFO.SatellitesUsed > 0 &&
    GPS_INFO.Day >= 1 && GPS_INFO.Day <= 31 && GPS_INFO.Month >= 1 && GPS_INFO.Month <= 12)
  {
    task.di = GPS_INFO.Day;
    task.mi = GPS_INFO.Month;
    task.yi = GPS_INFO.Year % 100;
  }
  else
  { // use system time
    time_t sysTime = time(NULL);
    tm tm_temp = {0};
    struct tm* utc = gmtime_r(&sysTime, &tm_temp);

    task.di = utc->tm_mday;
    task.mi = utc->tm_mon + 1;
    task.yi = utc->tm_year % 100;
  }

  task.input_time = 0;

  task.fd = task.di;
  task.fm = task.mi;
  task.fy = task.yi;

  task.taskid = 1; // unused, so default is 1

  task.num_of_tp = (char) wpCount - 2; // minus Start and Finish

  // add Start, TPs, and Finish
  for (int i = 0; i < wpCount; i++)
    decl.SetWaypoint(lkDecl.waypoint[i], Decl::tp_regular, i + 1);

  // add Home as Takeoff and Landing
  if (HomeWaypoint >= 0 && ValidWayPoint(HomeWaypoint))
  {
    decl.SetWaypoint(&WayPointList[HomeWaypoint], Decl::tp_takeoff, 0);
    decl.SetWaypoint(&WayPointList[HomeWaypoint], Decl::tp_landing, wpCount + 1);
  }
  else
  {
    decl.SetWaypoint(NULL, Decl::tp_takeoff, 0);
    decl.SetWaypoint(NULL, Decl::tp_landing, wpCount + 1);
  }

  return(true);
} // FillTask()
Exemplo n.º 2
0
BOOL CDevIMI::DeclareTask(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufSize, TCHAR errBuf[])
{
  // verify WP number
  if(!CheckWPCount(*decl, 2, 13, errBufSize, errBuf))
    return false;
  
  // stop Rx thread
  if(!StopRxThread(d, errBufSize, errBuf))
    return false;
  
  // set new Rx timeout
  int orgRxTimeout;
  bool status = SetRxTimeout(d, 2000, orgRxTimeout, errBufSize, errBuf);
  if(status) {
    // connect to the device
    ShowProgress(decl_enable);
    status = Connect(d, errBufSize, errBuf);
    if(status) {
      // task declaration
      ShowProgress(decl_send);
      status = status && DeclarationWrite(d, *decl, errBufSize, errBuf);
    }
    
    // disconnect
    ShowProgress(decl_disable);
    status = Disconnect(d, status ? errBufSize : 0, errBuf) && status;
    
    // restore Rx timeout (we must try that always; don't overwrite error descr)
    status = SetRxTimeout(d, orgRxTimeout, orgRxTimeout, status ? errBufSize : 0, errBuf) && status;
  }
  
  // restart Rx thread
  status = StartRxThread(d, status ? errBufSize : 0, errBuf) && status;
  
  return status;
}
Exemplo n.º 3
0
BOOL CDevCAIGpsNav::DeclareTask(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufSize, TCHAR errBuf[])
{
  // check requirements
  if(!CheckWPCount(*decl, 1, 9, errBufSize, errBuf))  /// @todo: check min number
    return false;

  // create a unique set of task waypoints
  CTaskWPSet wps;
  for(int i=0; i<decl->num_waypoints; i++)
    wps.insert(decl->waypoint[i]);

  // create a list of waypoint indexes in a task
  CTaskWPIdxArray task;
  for(int i=0; i<decl->num_waypoints; i++) {
    int j=0;
    for(CTaskWPSet::const_iterator it=wps.begin(), end=wps.end(); it!=end; ++it, j++)
      if(decl->waypoint[i] == *it)
        task.push_back(j);
  }

  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];
  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1404_ = "Opening connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1404));
  CreateProgressDialog(buffer);

  // prepare communication
  if(!StopRxThread(d, errBufSize, errBuf))
    return false;
  int timeout;
  bool status = SetRxTimeout(d, 500, timeout, errBufSize, errBuf);

  if(status) {
    EmptyRXBuffer(d);
    status = CAICommandMode(d, errBufSize, errBuf);
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1403_ = "Sending declaration"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403));
  CreateProgressDialog(buffer);

  if(status) {
    int temptimeout;
    status = SetRxTimeout(d, 5000, temptimeout, errBufSize, errBuf);
  }

  if(status)
    status = WaypointsClear(d, errBufSize, errBuf);

  if(status)
    // enter CAI download mode
    status = CAIDownloadMode(d, errBufSize, errBuf);

  if(status)
    // upload waypoints
    status = WaypointsUpload(d, wps, errBufSize, errBuf);

  if(status)
    // upload task
    status = TaskUpload(d, task, errBufSize, errBuf);

  if(status)
    // upload pilot and glider data
    status = PilotAndGliderUpload(d, *decl, errBufSize, errBuf);

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1406_ = "Closing connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1406));
  CreateProgressDialog(buffer);

  // restore NMEA mode
  status &= CAINMEAMode(d, errBufSize, errBuf);

  // restore regular communication
  status &= SetRxTimeout(d, timeout, timeout, errBufSize, errBuf);
  status &= StartRxThread(d, errBufSize, errBuf);

  return status;
}