Skip to content

Commit

Permalink
application: serial_lte_modem: Automation of LwM2M requests
Browse files Browse the repository at this point in the history
Add CONFIG_SLM_CARRIER_AUTO_CONTROL to control automatical handling
of below requests from LwM2M in SLM, instead of by host MCU:
- Link down/up
- Power off modem
- Reboot

By default this CONFIG is enabled.

JIRA-ticket: NCSDK-28267
JIRA-ticket: NCSDK-28431

Signed-off-by: Jun Qing Zou <jun.qing.zou@nordicsemi.no>
  • Loading branch information
junqingzou authored and rlubos committed Jul 30, 2024
1 parent 2b9ba89 commit 6298c41
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
24 changes: 12 additions & 12 deletions applications/serial_lte_modem/doc/CARRIER_AT_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ These may be the following:

* ``#XCARRIEREVT: 1,<status>``

Request to set the modem to full functional mode.
Request to use the ``AT+CFUN=1`` AT command to set the modem to full functional mode.
``<status>`` returns two possible values:

* ``0`` - Request handled successfully.
* ``-1`` - Request handling was deferred and must be performed by the application at its earliest convenience.
* ``0`` - Request handling is fulfilled automatically.
* ``-1`` - Request handling is deferred and must be fulfilled by the application at its earliest convenience.

* ``#XCARRIEREVT: 2,<status>``

Request to set the modem to flight functional mode.
Request to use the ``AT+CFUN=4`` AT command to set the modem to flight functional mode.
``<status>`` returns two possible values:

* ``0`` - Request handled successfully.
* ``-1`` - Request handling was deferred and must be performed by the application at its earliest convenience.
* ``0`` - Request handling is fulfilled automatically.
* ``-1`` - Request handling is deferred and must be fulfilled by the application at its earliest convenience.

* ``#XCARRIEREVT: 3,<status>``

Request to set the modem to minimum functional mode.
Request to use the ``AT+CFUN=0`` AT command to set the modem to minimum functional mode.
``<status>`` returns two possible values:

* ``0`` - Request handled successfully.
* ``-1`` - Request handling was deferred and must be performed by the application at its earliest convenience.
* ``0`` - Request handling is fulfilled automatically.
* ``-1`` - Request handling is deferred and must be fulfilled by the application at its earliest convenience.

* ``#XCARRIEREVT: 4,0``

Expand Down Expand Up @@ -94,12 +94,12 @@ These may be the following:

* ``#XCARRIEREVT: 10,<status>``

Request to perform an application reboot.
Request to perform an application reboot, for example using the ``AT#XRESET`` AT command.

``<status>`` returns two possible values:

* ``0`` - Request handled successfully.
* ``-1`` - Request handling was deferred and must be performed by the application at its earliest convenience.
* ``0`` - Request handling is fulfilled automatically.
* ``-1`` - Request handling is deferred and must be fulfilled by the application at its earliest convenience.

* ``#XCARRIEREVT: 11,0``

Expand Down
9 changes: 9 additions & 0 deletions applications/serial_lte_modem/src/lwm2m_carrier/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ config SLM_CARRIER_AUTO_STARTUP
Enable automatic startup of the library on device boot. If this configuration is
disabled, automatic startup is controlled through a dedicated AT command.

config SLM_CARRIER_AUTO_CONTROL
bool "Automatic handling of LwM2M requests"
depends on SLM_AUTO_CONNECT
default y
help
Enable automatic power off, reboot, link up or link down when requested by the LwM2M
stack. If this is disabled, the host MCU must perform these operations via AT commands
when requested.

endif # SLM_CARRIER
53 changes: 39 additions & 14 deletions applications/serial_lte_modem/src/lwm2m_carrier/slm_at_carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,53 @@ static void reconnect_wk(struct k_work *work)
int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *event)
{
int err = 0;
static bool fota_started;

switch (event->type) {
#if defined(CONFIG_SLM_CARRIER_AUTO_CONTROL)
case LWM2M_CARRIER_EVENT_LTE_LINK_UP:
LOG_DBG("LWM2M_CARRIER_EVENT_LTE_LINK_UP");
if (fota_started) {
fota_started = false;
k_work_reschedule(&reconnect_work, K_MSEC(100));
} else {
/* AT+CFUN=1 to be issued. */
k_work_reschedule(&reconnect_work, SLM_UART_RESPONSE_DELAY);
break;
case LWM2M_CARRIER_EVENT_LTE_LINK_DOWN:
LOG_DBG("LWM2M_CARRIER_EVENT_LTE_LINK_DOWN");
err = slm_util_at_printf("AT+CFUN=4");
if (err) {
err = -1;
}
break;
case LWM2M_CARRIER_EVENT_LTE_POWER_OFF:
LOG_DBG("LWM2M_CARRIER_EVENT_LTE_POWER_OFF");
err = slm_util_at_printf("AT+CFUN=0");
if (err) {
err = -1;
}
break;
case LWM2M_CARRIER_EVENT_REBOOT:
LOG_DBG("LWM2M_CARRIER_EVENT_REBOOT");
/* Return 0 to reboot right after a URC. */
break;
#else
case LWM2M_CARRIER_EVENT_LTE_LINK_UP:
LOG_DBG("LWM2M_CARRIER_EVENT_LTE_LINK_UP");
/* AT+CFUN=1 to be issued. */
err = -1;
break;
case LWM2M_CARRIER_EVENT_LTE_LINK_DOWN:
LOG_DBG("LWM2M_CARRIER_EVENT_LTE_LINK_DOWN");
/* AT+CFUN=4 to be issued. */
err = -1;
break;
case LWM2M_CARRIER_EVENT_LTE_POWER_OFF:
LOG_DBG("LWM2M_CARRIER_EVENT_LTE_POWER_OFF");
/* TODO: defer setting the modem to minimum funtional mode. */
err = slm_util_at_printf("AT+CFUN=0");
/* AT+CFUN=0 to be issued. */
err = -1;
break;
case LWM2M_CARRIER_EVENT_REBOOT:
LOG_DBG("LWM2M_CARRIER_EVENT_REBOOT");
/* Return -1 to defer the reboot until the application decides to do so. */
err = -1;
break;
#endif /* CONFIG_SLM_CARRIER_AUTO_CONTROL */
case LWM2M_CARRIER_EVENT_BOOTSTRAPPED:
LOG_DBG("LWM2M_CARRIER_EVENT_BOOTSTRAPPED");
break;
Expand All @@ -185,16 +209,10 @@ int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *event)
return 0;
case LWM2M_CARRIER_EVENT_FOTA_START:
LOG_DBG("LWM2M_CARRIER_EVENT_FOTA_START");
fota_started = true;
break;
case LWM2M_CARRIER_EVENT_FOTA_SUCCESS:
LOG_DBG("LWM2M_CARRIER_EVENT_FOTA_SUCCESS");
break;
case LWM2M_CARRIER_EVENT_REBOOT:
LOG_DBG("LWM2M_CARRIER_EVENT_REBOOT");
/* Return -1 to defer the reboot until the application decides to do so. */
err = -1;
break;
case LWM2M_CARRIER_EVENT_MODEM_DOMAIN:
LOG_DBG("LWM2M_CARRIER_EVENT_MODEM_DOMAIN");
break;
Expand All @@ -220,6 +238,13 @@ int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *event)

rsp_send("\r\n#XCARRIEREVT: %d,%d\r\n", event->type, err);

#if defined(CONFIG_SLM_CARRIER_AUTO_CONTROL)
/* Allow time for the URC be flushed before reboot */
if (event->type == LWM2M_CARRIER_EVENT_REBOOT && err == 0) {
k_sleep(SLM_UART_RESPONSE_DELAY);
}
#endif

return err;
}

Expand Down

0 comments on commit 6298c41

Please sign in to comment.