Exemple #1
0
bool
CAI302Device::ReadGeneralInfo(CAI302::GeneralInfo &data,
                              OperationEnvironment &env)
{
  if (!UploadMode(env))
    return false;

  return CAI302::UploadGeneralInfo(port, data, env);
}
Exemple #2
0
bool
CAI302Device::ReadActivePilot(CAI302::Pilot &pilot, OperationEnvironment &env)
{
  if (!UploadMode(env))
    return false;

  if (!CAI302::UploadPilot(port, 0, pilot, env)) {
    mode = Mode::UNKNOWN;
    return false;
  }

  return true;
}
Exemple #3
0
bool
CAI302Device::ReadNavpoint(unsigned index, CAI302::Navpoint &navpoint,
                           OperationEnvironment &env)
{
  if (!UploadMode(env))
    return false;

  if (!CAI302::UploadNavpoint(port, index, navpoint, env)) {
    mode = Mode::UNKNOWN;
    return false;
  }

  return true;
}
Exemple #4
0
int
CAI302Device::ReadNavpointCount(OperationEnvironment &env)
{
  if (!UploadMode(env))
    return false;

  CAI302::NavpointMeta meta;
  if (!CAI302::UploadNavpointMeta(port, meta, env)) {
    mode = Mode::UNKNOWN;
    return -1;
  }

  return FromBE16(meta.count);
}
Exemple #5
0
bool
CAI302Device::ReadPilotList(std::vector<CAI302::Pilot> &list,
                            unsigned &active_index,
                            OperationEnvironment &env)
{
  assert(list.empty());

  if (!UploadMode(env))
    return false;

  CAI302::PilotMetaActive meta;
  if (!CAI302::UploadPilotMetaActive(port, meta, env))
    return false;

  if (meta.record_size < sizeof(CAI302::Pilot))
    /* weird record size */
    return false;

  const unsigned count = meta.count;
  list.reserve(count);
  const unsigned record_size = meta.record_size;
  active_index = meta.active_index;

  const unsigned block_count = 8;

  uint8_t buffer[1024];

  for (unsigned i = 0; i < count; i += block_count) {
    unsigned this_block = std::min(count - i, block_count);
    unsigned n = CAI302::UploadPilotBlock(port, i, this_block,
                                          record_size, buffer, env);
    if (n != this_block)
      return false;

    const uint8_t *p = buffer;
    for (unsigned j = 0; j < n; ++j, p += record_size)
      list.push_back(*(const CAI302::Pilot *)p);
  }

  return true;
}
Exemple #6
0
bool
CAI302Device::ReadFlightList(RecordedFlightList &flight_list,
                             OperationEnvironment &env)
{
  if (!EnableBulkMode(env))
    return false;

  if (!UploadMode(env)) {
    DisableBulkMode(env);
    return false;
  }

  if (!ReadFlightListInner(port, flight_list, env)) {
    mode = Mode::UNKNOWN;
    DisableBulkMode(env);
    return false;
  }

  DisableBulkMode(env);
  return true;
}
Exemple #7
0
bool
CAI302Device::DownloadFlight(const RecordedFlightInfo &flight,
                             const TCHAR *path,
                             OperationEnvironment &env)
{
  assert(flight.internal.cai302 < 64);

  if (!EnableBulkMode(env))
    return false;

  if (!UploadMode(env)) {
    DisableBulkMode(env);
    return false;
  }

  if (!DownloadFlightInner(port, flight, path, env)) {
    mode = Mode::UNKNOWN;
    DisableBulkMode(env);
    return false;
  }

  DisableBulkMode(env);
  return true;
}