//--------------------------------------------------------------------------------------------------
static void StopCellularNetwork
(
    void
)
{
    le_onoff_t  radioState;
    le_result_t result;

    result=le_mrc_GetRadioPower(&radioState);
    if ((result == LE_OK) && (radioState == LE_OFF))
    {
        return;
    }
    else
    {
        // Try to shutdown the radio anyway
        le_mrc_SetRadioPower(LE_OFF);

        // Set a timer that gets the current position.
        le_timer_Ref_t stopCellNetTimer = le_timer_Create("StopCellNetTimer");
        le_clk_Time_t interval = {5, 0}; // 5 seconds

        if ( (le_timer_SetHandler(stopCellNetTimer, StopCellNetTimerHandler) != LE_OK) ||
             (le_timer_SetRepeat(stopCellNetTimer, 0) != LE_OK) ||
             (le_timer_SetInterval(stopCellNetTimer, interval) != LE_OK) ||
             (le_timer_Start(stopCellNetTimer) != LE_OK) )
        {
            LE_ERROR("Could not start the StopCellNet timer!");
        }
    }
}
//--------------------------------------------------------------------------------------------------
static void StartCellularNetwork
(
    void
)
{
    le_onoff_t  radioState;
    le_result_t result;

    result=le_mrc_GetRadioPower(&radioState);
    if ((result == LE_OK) && (radioState == LE_ON))
    {
        // Load SIM configuration from secure storage
        le_sim_Id_t simSelected = le_sim_GetSelectedCard();

        if (le_sim_IsPresent(simSelected))
        {
            LoadSimFromSecStore(simSelected);
        }

        // Notify the applications even if the SIM is absent
        GetAndSendCellNetStateEvent();
    }
    else
    {
        // Try to power ON the radio anyway
        le_mrc_SetRadioPower(LE_ON);

        // Set a timer that gets the current position.
        le_timer_Ref_t startCellNetTimer = le_timer_Create("StartCellNetTimer");
        le_clk_Time_t interval = {15, 0}; // 15 seconds

        if ( (le_timer_SetHandler(startCellNetTimer, StartCellNetTimerHandler) != LE_OK) ||
             (le_timer_SetRepeat(startCellNetTimer, 0) != LE_OK) ||
             (le_timer_SetInterval(startCellNetTimer, interval) != LE_OK) ||
             (le_timer_Start(startCellNetTimer) != LE_OK) )
        {
            LE_ERROR("Could not start the StartCellNet timer!");
        }
    }
}
Exemple #3
0
static int mqttClient_startSession(mqttClient_t* clientData)
{
  int rc = LE_OK;

  LE_ASSERT(clientData);

  memcpy(&clientData->session.config, &clientData->config, sizeof(clientData->config));

  clientData->session.connTimer = le_timer_Create(MQTT_CLIENT_CONNECT_TIMER);
  if (!clientData->session.connTimer)
  {
    LE_ERROR("le_timer_Create() failed");
    rc = LE_BAD_PARAMETER;
    goto cleanup;
  }

  rc = le_timer_SetHandler(clientData->session.connTimer, mqttClient_connExpiryHndlr);
  if (rc)
  {
    LE_ERROR("le_timer_SetHandler() failed(%d)", rc);
    goto cleanup;
  }

  rc = le_timer_SetMsInterval(clientData->session.connTimer, MQTT_CLIENT_CONNECT_TIMEOUT_MS);
  if (rc)
  {
    LE_ERROR("le_timer_SetMsInterval() failed(%d)", rc);
    goto cleanup;
  }  

  rc = le_timer_SetContextPtr(clientData->session.connTimer, clientData);
  if (rc)
  {
    LE_ERROR("le_timer_SetContextPtr() failed(%d)", rc);
    goto cleanup;
  } 

  clientData->session.cmdTimer = le_timer_Create(MQTT_CLIENT_COMMAND_TIMER);
  if (!clientData->session.cmdTimer)
  {
    LE_ERROR("le_timer_Create() failed");
    rc = LE_BAD_PARAMETER;
    goto cleanup;
  }

  rc = le_timer_SetHandler(clientData->session.cmdTimer, mqttClient_cmdExpiryHndlr);
  if (rc)
  {
    LE_ERROR("le_timer_SetHandler() failed(%d)", rc);
    goto cleanup;
  }

  rc = le_timer_SetMsInterval(clientData->session.cmdTimer, MQTT_CLIENT_CMD_TIMEOUT_MS);
  if (rc)
  {
    LE_ERROR("le_timer_SetMsInterval() failed(%d)", rc);
    goto cleanup;
  }  

  rc = le_timer_SetContextPtr(clientData->session.cmdTimer, clientData);
  if (rc)
  {
    LE_ERROR("le_timer_SetContextPtr() failed(%d)", rc);
    goto cleanup;
  } 

  clientData->session.pingTimer = le_timer_Create(MQTT_CLIENT_PING_TIMER);
  if (!clientData->session.pingTimer)
  {
    LE_ERROR("le_timer_Create() failed");
    rc = LE_BAD_PARAMETER;
    goto cleanup;
  }

  rc = le_timer_SetHandler(clientData->session.pingTimer, mqttClient_pingExpiryHndlr);
  if (rc)
  {
    LE_ERROR("le_timer_SetHandler() failed(%d)", rc);
    goto cleanup;
  }

  rc = le_timer_SetMsInterval(clientData->session.pingTimer, clientData->session.config.keepAlive * 1000);
  if (rc)
  {
    LE_ERROR("le_timer_SetMsInterval() failed(%d)", rc);
    goto cleanup;
  }  

  rc = le_timer_SetRepeat(clientData->session.pingTimer, 0);
  if (rc)
  {
    LE_ERROR("le_timer_SetRepeat() failed(%d)", rc);
    goto cleanup;
  }  

  rc = le_timer_SetContextPtr(clientData->session.pingTimer, clientData);
  if (rc)
  {
    LE_ERROR("le_timer_SetContextPtr() failed(%d)", rc);
    goto cleanup;
  } 

  LE_INFO("connect(%s:%d)", clientData->session.config.brokerUrl, clientData->session.config.portNumber);
  rc = mqttClient_connect(clientData); 
  if (rc)
  {
    LE_ERROR("mqttClient_connect() failed(%d)", rc);
    goto cleanup;
  }

cleanup:
  if (rc)
  {
    LE_INFO("start session failed");
    mqttClient_SendConnStateEvent(false, rc, -1);
  }

  return rc;
}