示例#1
0
int __exapp_connectivity_destroy(uint32_t delay_s)
{
  struct timespec ts;

  if (g_connid == UINT32_MAX)
    {
      return OK;
    }

  if (delay_s >= 0)
    {
      if (g_contimer_id >= 0)
        {
          ts_core_timer_stop(g_contimer_id);
        }

      clock_gettime(CLOCK_MONOTONIC, &ts);
      ts.tv_sec += delay_s;
      g_contimer_id = ts_core_timer_setup_date(&ts, con_timer_cb, NULL);
    }
  else
    {
      con_timer_cb(-1, &ts, NULL);
    }

  return OK;
}
示例#2
0
/****************************************************************************
 * Name: ubgps_psm_timer_cb
 *
 * Description:
 *   timeout handler for PSM callback
 *
 * Input Parameters:
 *
 * Returned Values:
 *   Status
 *
 ****************************************************************************/
int ubgps_psm_timer_cb(const int timer_id, const struct timespec *date,
                       void * const priv)
{
  struct ubgps_s * const gps = (struct ubgps_s *)priv;

  /* Off-time expired, acquire fix */

  if (timer_id == gps->state.psm_timer_id)
    {
      struct sm_event_psm_event_s psm;

      psm.super.id = SM_EVENT_PSM_STATE;
      psm.enable = false;
      ubgps_sm_process(gps, (struct sm_event_s *)&psm);

      ts_core_timer_stop(gps->state.psm_timer_id);
      gps->state.psm_timer_id = -1;
    }
  else
    {
      dbg("invalid timer id\n");
    }

  return OK;
}
示例#3
0
static void initial_connectivity_wait_handler(void)
{
  struct conman_status_s status;
  int ret;

  ret = conman_client_get_connection_status(&g_conman_client, &status);
  if (ret < 0)
    {
      exapp_dbg("conman_client_get_connection_status failed\n");
      return;
    }

  exapp_dbg("status: %d\n", status.status);

  if (status.status == CONMAN_STATUS_ESTABLISHED)
    {
      g_conn_request_waiting = false;

      __exapp_main_initial_connectivity_reached();

      return;
    }

  if (status.status == CONMAN_STATUS_OFF)
    {
      if (conman_client_destroy_connection(&g_conman_client, g_connid) < 0)
        {
          exapp_dbg("conman_client_destroy_connection failed\n");
        }

      ret = conman_client_request_connection(&g_conman_client, CONMAN_DATA, &g_connid);
      if (ret < 0)
        {
          exapp_dbg("conman_client_request_connection failed\n");
          return;
        }
    }
  else if (g_retry_id >= 0)
    {
      /* If g_retry_id is not -1, then connection failed. Poke connection. */

      __exapp_connectivity_poke_connection();
    }

  if (g_retry_id >= 0)
    {
      ts_core_timer_stop(g_retry_id);
      g_retry_id = -1;
    }

  exapp_dbg("wait conman event\n");
}
示例#4
0
static int ts_gps_core_reconfigure(void)
{
  struct pollfd pfd = {};
  int timeout_ms;
  int ret;

  /* Get new poll setup. */

  ret = ubgps_poll_setup(ts_gps, &pfd, &timeout_ms);
  if (ret < 0)
    {
      return ret;
    }

  /* Reconfigure poll events. */

  if (ts_core_gps.fd >= 0)
    ts_core_fd_unregister(ts_core_gps.fd);
  if (pfd.fd >= 0)
    {
      ret = ts_core_fd_register(pfd.fd, pfd.events, ts_gps_poll_callback,
                                NULL);
      DEBUGASSERT(ret >= 0);
    }

  ts_core_gps.fd = pfd.fd;

  /* Reconfigure timers. */

  if (ts_core_gps.timerid >= 0)
    ts_core_timer_stop(ts_core_gps.timerid);
  if (timeout_ms >= 0)
    {
      ret = ts_core_timer_setup(TS_TIMER_TYPE_TIMEOUT, timeout_ms,
                                ts_gps_timer_callback, NULL);
      DEBUGASSERT(ret >= 0);
      ts_core_gps.timerid = ret;
    }
  else
    {
      ts_core_gps.timerid = -1;
    }

  return OK;
}
示例#5
0
int __exapp_connectivity_request(void)
{
  int ret;

  if (g_connid != UINT32_MAX)
    {
      if (g_contimer_id >= 0)
        {
          ts_core_timer_stop(g_contimer_id);
          g_contimer_id = -1;
        }
      return OK;
    }

  ret = conman_client_request_connection(&g_conman_client, CONMAN_DATA, &g_connid);
  if (ret < 0)
    {
      exapp_dbg("conman_client_request_connection failed\n");
    }

  return ret;
}
示例#6
0
/****************************************************************************
 * Name: ubgps_sm_poweroff
 *
 * Description:
 *   State machine for GPS power off
 *
 ****************************************************************************/
static int ubgps_sm_poweroff(struct ubgps_s * const gps, struct sm_event_s const * const event)
{
  DEBUGASSERT(gps && event);

  /* Check event */

  switch (event->id)
    {
      case SM_EVENT_ENTRY:
        {
          dbg_sm("SM_EVENT_ENTRY\n");
          if (gps->state.powered)
            {
              /* Power down GPS chip */

              board_gps_power(false);

              /* Mark GPS power down */

              gps->state.powered = false;

              /* Reset UBX receiver */

              ubx_reset(gps);
            }

          /* Report target reached status */

          ubgps_report_target_state(gps, false);

          /* Reset PSM accuracy filter */

          gps->filt_location.horizontal_accuracy = 0;

          /* Make sure that timers are not running */

          if (gps->state.location_timer_id >= 0)
            {
              __ubgps_remove_timer(gps, gps->state.location_timer_id);
              gps->state.location_timer_id = -1;
            }

#ifdef CONFIG_UBGPS_ASSIST_UPDATER
          /* Stop aiding updater and timers */

          if (gps->state.aid_timer_id >= 0)
            {
              __ubgps_remove_timer(gps, gps->state.aid_timer_id);
              gps->state.aid_timer_id = -1;
            }

          if (gps->assist)
            {
              if (ubgps_aid_updater_stop(gps->assist))
                {
                  dbg("Aiding updater stop failed\n");
                }
            }
#endif
          /* Free GPS assistance data if PSM is not active */

          if (gps->assist && gps->state.psm_timer_id < 0)
            {
              if (gps->assist->alp_file)
                free(gps->assist->alp_file);

              free(gps->assist);
              gps->assist = NULL;
            }

          return OK;
        }

      case SM_EVENT_TARGET_STATE:
        {
          struct sm_event_target_state_s * const target =
              (struct sm_event_target_state_s *)event;

          dbg_sm("SM_EVENT_TARGET_STATE -> %u\n", target->target_state);

          /* Stop PSM timer */

          if (gps->state.psm_timer_id > 0)
            {
              ts_core_timer_stop(gps->state.psm_timer_id);
              gps->state.psm_timer_id = -1;
            }

          if (target->target_state != GPS_STATE_POWER_OFF)
            {
              /* Setup target state transition timeout */

              ubgps_setup_timeout(gps, target->timeout);

              /* Set GPS target state */

              gps->state.target_state = target->target_state;

              /* Set next GPS state */

              ubgps_set_new_state(gps, GPS_STATE_INITIALIZATION);
            }
          else
            {
              /* Make current state the target state */

              /* Free GPS assistance data */

              if (gps->assist)
                {
                  if (gps->assist->alp_file)
                    free(gps->assist->alp_file);

                  free(gps->assist);
                  gps->assist = NULL;
                }

              gps->state.target_state = gps->state.current_state;

              /* Report target reached */

              ubgps_report_target_state(gps, false);
            }

          return OK;
        }

      case SM_EVENT_PSM_STATE:
        {
          struct sm_event_psm_event_s const * const psm_event =
              (struct sm_event_psm_event_s *)event;
          dbg_sm("SM_EVENT_PSM_STATE -> %u\n", psm_event->enable);

          if (!psm_event->enable)
            {
              gps->state.target_state = GPS_STATE_FIX_ACQUIRED;
              ubgps_set_new_state(gps, GPS_STATE_INITIALIZATION);
            }

          return OK;
        }

      case SM_EVENT_EXIT:
        {
          dbg_sm("SM_EVENT_EXIT\n");

          if (!gps->state.powered)
            {
              struct termios uart;
              int ret;

              /* Configure initial baud rate to GPS UART */

              ret = ioctl(gps->fd, TCGETS, (unsigned long)&uart);
              DEBUGASSERT(ret == OK);

              uart.c_cflag = CS8;
              uart.c_speed = GPS_INITIAL_BAUD_RATE;

              ret = ioctl(gps->fd, TCSETS, (unsigned long)&uart);
              DEBUGASSERT(ret == OK);

              /* Power up GPS chip */

              board_gps_power(true);

              /* Mark GPS power up */

              gps->state.powered = true;
            }

          return OK;
        }

      default:
        break;
    }

  return OK;
}