Example #1
0
static acq_status_t * choose_acq_sat(void)
{
  u32 total_score = 0;
  gps_time_t t = get_current_time();

  for (u32 i=0; i<PLATFORM_SIGNAL_COUNT; i++) {
    if ((acq_status[i].state != ACQ_PRN_ACQUIRING) ||
        acq_status[i].masked)
      continue;

    acq_status[i].score[ACQ_HINT_WARMSTART] =
      manage_warm_start(acq_status[i].sid, &t,
                        &acq_status[i].dopp_hint_low,
                        &acq_status[i].dopp_hint_high);

    for (enum acq_hint hint = 0; hint < ACQ_HINT_NUM; hint++) {
      total_score += acq_status[i].score[hint];
    }
  }

  if (total_score == 0) {
    log_error("Failed to pick a sat for acquisition!");
    return NULL;
  }

  u32 pick = rand() % total_score;

  for (u32 i=0; i<PLATFORM_SIGNAL_COUNT; i++) {
    if ((acq_status[i].state != ACQ_PRN_ACQUIRING) ||
        acq_status[i].masked)
      continue;

    u32 sat_score = 0;
    for (enum acq_hint hint = 0; hint < ACQ_HINT_NUM; hint++)
      sat_score += acq_status[i].score[hint];
    if (pick < sat_score) {
      return &acq_status[i];
    } else {
      pick -= sat_score;
    }
  }

  assert(!"Error picking a sat for acquisition");
  return NULL;
}
Example #2
0
static u8 choose_prn(void)
{
  u32 total_score = 0;
  gps_time_t t = get_current_time();

  for (u8 prn=0; prn<32; prn++) {
    if ((acq_prn_param[prn].state != ACQ_PRN_ACQUIRING) ||
         acq_prn_param[prn].masked)
      continue;

    acq_prn_param[prn].score[ACQ_HINT_WARMSTART] =
      manage_warm_start(prn, t,
                        &acq_prn_param[prn].dopp_hint_low,
                        &acq_prn_param[prn].dopp_hint_high);

    for (enum acq_hint hint = 0; hint < ACQ_HINT_NUM; hint++) {
      total_score += acq_prn_param[prn].score[hint];
    }
  }

  u32 pick = random_int() % total_score;

  for (u8 prn=0; prn<32; prn++) {
    if ((acq_prn_param[prn].state != ACQ_PRN_ACQUIRING) ||
         acq_prn_param[prn].masked)
      continue;

    u32 sat_score = 0;
    for (enum acq_hint hint = 0; hint < ACQ_HINT_NUM; hint++)
      sat_score += acq_prn_param[prn].score[hint];
    if (pick < sat_score) {
      return prn;
    } else {
      pick -= sat_score;
    }
  }

  log_error("Failed to pick a sat for acquisition!");

  return -1;
}