Skip to content

Commit a1d3f16

Browse files
ntn: Update NCS revision and adapt app to PDN and NTN libraries
NCS revision is updated, and adjustments made to the NTN module to adapt to - New NTN library for location requests - PDN library deprecation, now managing PDN via LTE LC Signed-off-by: Giacomo Dematteis <giacomo.dematteis@nordicsemi.no>
1 parent ce90523 commit a1d3f16

File tree

4 files changed

+98
-57
lines changed

4 files changed

+98
-57
lines changed

app/prj.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN=y
4747
CONFIG_NRF_MODEM_LIB_NET_IF_DOWN_DEFAULT_LTE_DISCONNECT=y
4848

4949
# Enable Link Controller modules
50+
CONFIG_LTE_LC_PDN_MODULE=y
51+
CONFIG_LTE_LC_CELLULAR_PROFILE_MODULE=y
5052
CONFIG_LTE_LC_EDRX_MODULE=y
5153
CONFIG_LTE_LC_CONN_EVAL_MODULE=y
5254
CONFIG_LTE_LC_WORKQUEUE_STACK_SIZE=768
@@ -57,6 +59,9 @@ CONFIG_LTE_EDRX_REQ=y
5759
CONFIG_LTE_EDRX_REQ_VALUE_LTE_M="0000"
5860
CONFIG_LTE_EDRX_REQ_VALUE_NBIOT="0000"
5961

62+
# NTN library
63+
CONFIG_NTN=y
64+
6065
# Modem library
6166
CONFIG_NRF_MODEM_LIB=y
6267

app/src/modules/ntn/ntn.c

Lines changed: 86 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <modem/pdn.h>
1313
#include <date_time.h>
1414
#include <modem/nrf_modem_lib.h>
15+
#include <modem/ntn.h>
1516
#include <nrf_modem_at.h>
1617
#include <modem/at_monitor.h>
1718
#include <nrf_modem_gnss.h>
@@ -29,7 +30,7 @@
2930
#include "ntn.h"
3031
#include "button.h"
3132

32-
LOG_MODULE_REGISTER(ntn, CONFIG_APP_NTN_LOG_LEVEL);
33+
LOG_MODULE_REGISTER(ntn_module, CONFIG_APP_NTN_LOG_LEVEL);
3334

3435
/* AT monitor for network notifications.
3536
* The monitor is needed to receive notification when in the case where the modem has been
@@ -99,7 +100,6 @@ static struct k_work gnss_location_work;
99100

100101
static void gnss_event_handler(int event);
101102
static void lte_lc_evt_handler(const struct lte_lc_evt *const evt);
102-
static void pdn_event_handler(uint8_t cid, enum pdn_event event, int reason);
103103
static void ntn_msg_publish(enum ntn_msg_type type);
104104

105105
static void state_running_entry(void *obj);
@@ -160,6 +160,27 @@ static void lte_lc_evt_handler(const struct lte_lc_evt *const evt)
160160
LOG_DBG("LTE_LC_NW_REG_REGISTERED_ROAMING");
161161
}
162162

163+
break;
164+
case LTE_LC_EVT_PDN:
165+
switch (evt->pdn.type) {
166+
case LTE_LC_EVT_PDN_ACTIVATED:
167+
LOG_DBG("PDN connection activated");
168+
ntn_msg_publish(NETWORK_CONNECTED);
169+
170+
break;
171+
case LTE_LC_EVT_PDN_DEACTIVATED:
172+
LOG_DBG("PDN connection deactivated");
173+
ntn_msg_publish(NETWORK_DISCONNECTED);
174+
175+
break;
176+
case LTE_LC_EVT_PDN_NETWORK_DETACH:
177+
LOG_DBG("PDN connection network detached");
178+
ntn_msg_publish(NETWORK_DISCONNECTED);
179+
180+
break;
181+
default:
182+
break;
183+
}
163184
break;
164185
case LTE_LC_EVT_MODEM_EVENT:
165186
if (evt->modem_evt.type == LTE_LC_MODEM_EVT_RESET_LOOP) {
@@ -183,48 +204,32 @@ static void lte_lc_evt_handler(const struct lte_lc_evt *const evt)
183204
}
184205
}
185206

186-
static void pdn_event_handler(uint8_t cid, enum pdn_event event, int reason)
207+
208+
static void gnss_event_handler(int event)
187209
{
188210
switch (event) {
189-
#if CONFIG_PDN_ESM_STRERROR
190-
case PDN_EVENT_CNEC_ESM:
191-
LOG_DBG("Event: PDP context %d, %s", cid, pdn_esm_strerror(reason));
192-
193-
break;
194-
#endif
195-
case PDN_EVENT_ACTIVATED:
196-
LOG_DBG("PDN_EVENT_ACTIVATED");
197-
ntn_msg_publish(NETWORK_CONNECTED);
198-
199-
break;
200-
case PDN_EVENT_NETWORK_DETACH:
201-
LOG_DBG("PDN_EVENT_NETWORK_DETACH");
202-
203-
break;
204-
case PDN_EVENT_DEACTIVATED:
205-
LOG_DBG("PDN_EVENT_DEACTIVATED");
206-
207-
break;
208-
case PDN_EVENT_CTX_DESTROYED:
209-
LOG_DBG("PDN_EVENT_CTX_DESTROYED");
211+
case NRF_MODEM_GNSS_EVT_PVT:
212+
/* Schedule work to handle PVT data in thread context */
213+
k_work_submit(&gnss_location_work);
210214

211215
break;
216+
/* TODO: add handling for GNSS_SEARCH_FAILED, see mosh gnss.c */
212217
default:
213-
LOG_ERR("Unexpected PDN event: %d", event);
214-
215218
break;
216219
}
217220
}
218221

219-
static void gnss_event_handler(int event)
222+
static void ntn_event_handler(const struct ntn_evt *evt)
220223
{
221-
switch (event) {
222-
case NRF_MODEM_GNSS_EVT_PVT:
223-
/* Schedule work to handle PVT data in thread context */
224-
k_work_submit(&gnss_location_work);
224+
switch (evt->type) {
225+
case NTN_EVT_LOCATION_REQUEST:
226+
LOG_DBG("NTN location requested: %s, accuracy: %d m",
227+
evt->location_request.requested ? "true" : "false",
228+
evt->location_request.accuracy);
229+
230+
ntn_msg_publish(NTN_LOCATION_REQUEST);
225231

226232
break;
227-
/* TODO: add handling for GNSS_SEARCH_FAILED, see mosh gnss.c */
228233
default:
229234
break;
230235
}
@@ -398,13 +403,11 @@ static int set_ntn_active_mode(struct ntn_state_object *state)
398403
return err;
399404
}
400405

401-
/* Configure location using latest GNSS data */
402-
err = nrf_modem_at_printf("AT%%LOCATION=2,\"%f\",\"%f\",\"%f\",0,0",
403-
(double)state->last_pvt.latitude,
406+
err = ntn_location_set((double)state->last_pvt.latitude,
404407
(double)state->last_pvt.longitude,
405-
(double)state->last_pvt.altitude);
408+
(float)state->last_pvt.altitude, 0);
406409
if (err) {
407-
LOG_ERR("Failed to set AT%%LOCATION, error: %d", err);
410+
LOG_ERR("Failed to set location, error: %d", err);
408411

409412
return err;
410413
}
@@ -591,41 +594,62 @@ static void state_running_entry(void *obj)
591594
lte_lc_register_handler(lte_lc_evt_handler);
592595

593596
/* Register handler for default PDP context 0. */
594-
err = pdn_default_ctx_cb_reg(pdn_event_handler);
597+
err = lte_lc_pdn_default_ctx_events_enable();
595598
if (err) {
596-
LOG_ERR("pdn_default_ctx_cb_reg, error: %d", err);
597-
SEND_FATAL_ERROR();
599+
LOG_ERR("lte_lc_pdn_default_ctx_events_enable, error: %d", err);
598600

599601
return;
600602
}
601603

604+
ntn_register_handler(ntn_event_handler);
605+
606+
/* Power off modem */
607+
err = lte_lc_power_off();
608+
if (err) {
609+
LOG_ERR("lte_lc_power_off, error: %d", err);
610+
611+
return err;
612+
}
613+
602614
/* Set NTN SIM profile.
603615
* 2: Configure cellular profile
604-
* 0: Cellular profile index
616+
* 1: Cellular profile index
605617
* 4: Access technology: Satellite E-UTRAN (NB-S1 mode)
606618
* 0: SIM slot, physical SIM
607619
*/
608-
err = nrf_modem_at_printf("AT%%CELLULARPRFL=2,1,4,0");
609-
if (err) {
610-
LOG_ERR("Failed to set modem NTN profile, error: %d", err);
611-
SEND_FATAL_ERROR();
620+
struct lte_lc_cellular_profile ntn_profile = {
621+
.id = 1,
622+
.act = LTE_LC_ACT_NTN,
623+
.uicc = LTE_LC_UICC_PHYSICAL,
624+
};
612625

613-
return;
614-
}
626+
/* Set NTN profile */
627+
err = lte_lc_cellular_profile_configure(&ntn_profile);
628+
if (err) {
629+
LOG_ERR("Failed to set NTN profile, error: %d", err);
630+
631+
return err;
632+
}
615633

616634
/* Set TN SIM profile for LTE-M
617635
* 2: Configure cellular profile
618-
* 1: Cellular profile index
636+
* 0: Cellular profile index
619637
* 1: Access technology: LE-UTRAN (WB-S1 mode), LTE-M
620638
* 0: SIM slot, physical SIM
621639
*/
622-
err = nrf_modem_at_printf("AT%%CELLULARPRFL=2,0,1,0");
623-
if (err) {
624-
LOG_ERR("Failed to set modem TN profile, error: %d", err);
625-
SEND_FATAL_ERROR();
640+
struct lte_lc_cellular_profile tn_profile = {
641+
.id = 0,
642+
.act = LTE_LC_ACT_LTEM || LTE_LC_ACT_NBIOT,
643+
.uicc = LTE_LC_UICC_PHYSICAL,
644+
};
626645

627-
return;
628-
}
646+
/* Set TN profile */
647+
err = lte_lc_cellular_profile_configure(&tn_profile);
648+
if (err) {
649+
LOG_ERR("Failed to set TN profile, error: %d", err);
650+
651+
return err;
652+
}
629653

630654
#if defined(CONFIG_APP_NTN_DISABLE_EPCO)
631655
/* Disable ePCO */
@@ -692,7 +716,7 @@ static void state_tn_entry(void *obj)
692716
case LTE_LC_FUNC_MODE_POWER_OFF:
693717
break;
694718
default:
695-
err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_OFFLINE_KEEP_REG);
719+
err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_POWER_OFF);
696720
if (err) {
697721
LOG_ERR("lte_lc_func_mode_set, error: %d", err);
698722

@@ -711,7 +735,8 @@ static void state_tn_entry(void *obj)
711735
}
712736
#endif
713737

714-
err = lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM_NBIOT, LTE_LC_SYSTEM_MODE_PREFER_LTEM);
738+
err = lte_lc_system_mode_set(LTE_LC_SYSTEM_MODE_LTEM_NBIOT,
739+
LTE_LC_SYSTEM_MODE_PREFER_LTEM);
715740
if (err) {
716741
LOG_ERR("lte_lc_system_mode_set, error: %d", err);
717742

@@ -836,7 +861,12 @@ static enum smf_state_result state_idle_run(void *obj)
836861
smf_set_state(SMF_CTX(state), &states[STATE_GNSS]);
837862

838863
return SMF_EVENT_HANDLED;
864+
} else if (msg->type == NTN_LOCATION_REQUEST) {
865+
LOG_DBG("NTN location requested");
866+
smf_set_state(SMF_CTX(state), &states[STATE_GNSS]);
839867
}
868+
869+
return SMF_EVENT_HANDLED;
840870
}
841871

842872
return SMF_EVENT_PROPAGATE;

app/src/modules/ntn/ntn.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ extern "C" {
1717

1818
/* NTN module message types */
1919
enum ntn_msg_type {
20+
/* NTN location request received */
21+
NTN_LOCATION_REQUEST,
22+
2023
/* Location search completed and GNSS location data is available */
2124
NTN_LOCATION_SEARCH_DONE,
2225

@@ -26,6 +29,9 @@ enum ntn_msg_type {
2629
/* Network connectivity established */
2730
NETWORK_CONNECTED,
2831

32+
/* Network connectivity lost */
33+
NETWORK_DISCONNECTED,
34+
2935
/* Network no suitable cell found */
3036
NETWORK_NO_SUITABLE_CELL,
3137

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ manifest:
1414
- name: nrf
1515
remote: ncs
1616
repo-path: sdk-nrf
17-
revision: 9c58ea4757b89e22902cbf7b5d785374a929c473
17+
revision: 002c75be46c98d55ae24652cdb1c2ebb5ff43d0e
1818
import: true

0 commit comments

Comments
 (0)