Esempio n. 1
0
/** Initialize a decoder channel to process telemetry for sid from the
 * specified tracking channel.
 *
 * \param tracking_channel  Tracking channel to use.
 * \param sid               Signal to be decoded.
 *
 * \return true if a decoder channel was initialized, false otherwise.
 */
bool decoder_channel_init(u8 tracking_channel, gnss_signal_t sid)
{
  decoder_channel_t *d = decoder_channel_get(tracking_channel);
  if (decoder_channel_state_get(d) != DECODER_CHANNEL_STATE_DISABLED)
    return false;

  const decoder_interface_t *interface = decoder_interface_get(sid);
  decoder_t *decoder;
  if (!available_decoder_get(interface, &decoder))
    return false;

  /* Set up channel */
  d->info.tracking_channel = tracking_channel;
  d->info.sid = sid;
  d->decoder = decoder;

  /* Empty the nav bit FIFO */
  s8 soft_bit;
  while (tracking_channel_nav_bit_get(d->info.tracking_channel, &soft_bit)) {
    ;
  }

  interface_function(d, interface->init);
  event(d, EVENT_ENABLE);
  return true;
}
Esempio n. 2
0
static void decoder_gps_l1ca_process(const decoder_channel_info_t *channel_info,
                                     decoder_data_t *decoder_data)
{
  gps_l1ca_decoder_data_t *data = decoder_data;

  /* Process incoming nav bits */
  s8 soft_bit;
  while (tracking_channel_nav_bit_get(channel_info->tracking_channel,
                                      &soft_bit)) {
    /* Update TOW */
    bool bit_val = soft_bit >= 0;
    s32 TOW_ms = nav_msg_update(&data->nav_msg, bit_val);
    s8 bit_polarity = data->nav_msg.bit_polarity;
    if ((TOW_ms >= 0) && (bit_polarity != BIT_POLARITY_UNKNOWN)) {
      if (!tracking_channel_time_sync(channel_info->tracking_channel, TOW_ms,
                                      bit_polarity)) {
        log_warn_sid(channel_info->sid, "TOW set failed");
      }
    }
  }

  /* Check if there is a new nav msg subframe to process. */
  if (!subframe_ready(&data->nav_msg))
    return;

  /* Decode ephemeris to temporary struct */
  ephemeris_t e = {.sid = channel_info->sid};
  s8 ret = process_subframe(&data->nav_msg, &e);;

  if (ret <= 0)
    return;

  /* Decoded a new ephemeris. */
  ephemeris_new(&e);

  ephemeris_t *eph = ephemeris_get(channel_info->sid);
  if (!eph->valid) {
    log_info_sid(channel_info->sid, "ephemeris is invalid");
  }
}