Skip to content

Commit 670ef75

Browse files
committed
lib: modem_info: add data types
* Adds the `enum modem_info_data_type` type for representing the LTE link information data types. * Adds the `modem_info_data_type_get` function for requesting the data type of the current modem information type. Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
1 parent a577882 commit 670ef75

File tree

5 files changed

+78
-35
lines changed

5 files changed

+78
-35
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

+7
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ Modem libraries
650650

651651
* Fixed a bug where AT responses would erroneously be written to the logging UART instead of being written to the chosen ``ncs,at-host-uart`` UART device when the :kconfig:option:`CONFIG_LOG_BACKEND_UART` Kconfig option was set.
652652

653+
* :ref:`modem_info_readme` library:
654+
655+
* Added:
656+
657+
* The :c:enum:`modem_info_data_type` type for representing LTE link information data types.
658+
* The :c:func:`modem_info_data_type_get` function for requesting the data type of the current modem information type.
659+
653660
Multiprotocol Service Layer libraries
654661
-------------------------------------
655662

include/modem/modem_info.h

+19
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ enum modem_info {
151151
MODEM_INFO_COUNT, /**< Number of legal elements in the enum. */
152152
};
153153

154+
/** @brief LTE link information data types. */
155+
enum modem_info_data_type {
156+
/** Data of type invalid. */
157+
MODEM_INFO_DATA_TYPE_INVALID,
158+
/** Data of type integer. */
159+
MODEM_INFO_DATA_TYPE_NUM_INT,
160+
/** Data of type string. */
161+
MODEM_INFO_DATA_TYPE_STRING,
162+
};
163+
154164
/**@brief LTE parameter data. **/
155165
struct lte_param {
156166
uint16_t value; /**< The retrieved value. */
@@ -298,6 +308,15 @@ int modem_info_name_get(enum modem_info info, char *name);
298308
*/
299309
enum at_param_type modem_info_type_get(enum modem_info info);
300310

311+
/** @brief Request the data type of the current modem information
312+
* type.
313+
*
314+
* @param info The requested information type.
315+
*
316+
* @return The data type of the requested modem information data.
317+
*/
318+
enum modem_info_data_type modem_info_data_type_get(enum modem_info info);
319+
301320
/** @brief Obtain the modem parameters.
302321
*
303322
* The data is stored in the provided info structure.

lib/modem_info/modem_info.c

+44-27
Original file line numberDiff line numberDiff line change
@@ -154,183 +154,183 @@ struct modem_info_data {
154154
const char *data_name;
155155
uint8_t param_index;
156156
uint8_t param_count;
157-
enum at_param_type data_type;
157+
enum modem_info_data_type data_type;
158158
};
159159

160160
static const struct modem_info_data rsrp_data = {
161161
.cmd = AT_CMD_CESQ,
162162
.data_name = RSRP_DATA_NAME,
163163
.param_index = RSRP_PARAM_INDEX,
164164
.param_count = RSRP_PARAM_COUNT,
165-
.data_type = AT_PARAM_TYPE_NUM_INT,
165+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
166166
};
167167

168168
static const struct modem_info_data band_data = {
169169
.cmd = AT_CMD_CURRENT_BAND,
170170
.data_name = CUR_BAND_DATA_NAME,
171171
.param_index = BAND_PARAM_INDEX,
172172
.param_count = BAND_PARAM_COUNT,
173-
.data_type = AT_PARAM_TYPE_NUM_INT,
173+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
174174
};
175175

176176
static const struct modem_info_data band_sup_data = {
177177
.cmd = AT_CMD_SUPPORTED_BAND,
178178
.data_name = SUP_BAND_DATA_NAME,
179179
.param_index = BAND_PARAM_INDEX,
180180
.param_count = BAND_PARAM_COUNT,
181-
.data_type = AT_PARAM_TYPE_STRING,
181+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
182182
};
183183

184184
static const struct modem_info_data mode_data = {
185185
.cmd = AT_CMD_CURRENT_MODE,
186186
.data_name = UE_MODE_DATA_NAME,
187187
.param_index = MODE_PARAM_INDEX,
188188
.param_count = MODE_PARAM_COUNT,
189-
.data_type = AT_PARAM_TYPE_NUM_INT,
189+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
190190
};
191191

192192
static const struct modem_info_data operator_data = {
193193
.cmd = AT_CMD_CURRENT_OP,
194194
.data_name = OPERATOR_DATA_NAME,
195195
.param_index = OPERATOR_PARAM_INDEX,
196196
.param_count = OPERATOR_PARAM_COUNT,
197-
.data_type = AT_PARAM_TYPE_STRING,
197+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
198198
};
199199

200200
static const struct modem_info_data mcc_data = {
201201
.cmd = AT_CMD_CURRENT_OP,
202202
.data_name = MCC_DATA_NAME,
203203
.param_index = OPERATOR_PARAM_INDEX,
204204
.param_count = OPERATOR_PARAM_COUNT,
205-
.data_type = AT_PARAM_TYPE_NUM_INT,
205+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
206206
};
207207

208208
static const struct modem_info_data mnc_data = {
209209
.cmd = AT_CMD_CURRENT_OP,
210210
.data_name = MNC_DATA_NAME,
211211
.param_index = OPERATOR_PARAM_INDEX,
212212
.param_count = OPERATOR_PARAM_COUNT,
213-
.data_type = AT_PARAM_TYPE_NUM_INT,
213+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
214214
};
215215

216216
static const struct modem_info_data cellid_data = {
217217
.cmd = AT_CMD_NETWORK_STATUS,
218218
.data_name = CELLID_DATA_NAME,
219219
.param_index = CELLID_PARAM_INDEX,
220220
.param_count = CELLID_PARAM_COUNT,
221-
.data_type = AT_PARAM_TYPE_STRING,
221+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
222222
};
223223

224224
static const struct modem_info_data area_data = {
225225
.cmd = AT_CMD_NETWORK_STATUS,
226226
.data_name = AREA_CODE_DATA_NAME,
227227
.param_index = AREA_CODE_PARAM_INDEX,
228228
.param_count = AREA_CODE_PARAM_COUNT,
229-
.data_type = AT_PARAM_TYPE_STRING,
229+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
230230
};
231231

232232
static const struct modem_info_data ip_data = {
233233
.cmd = AT_CMD_PDP_CONTEXT,
234234
.data_name = IP_ADDRESS_DATA_NAME,
235235
.param_index = IP_ADDRESS_PARAM_INDEX,
236236
.param_count = IP_ADDRESS_PARAM_COUNT,
237-
.data_type = AT_PARAM_TYPE_STRING,
237+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
238238
};
239239

240240
static const struct modem_info_data uicc_data = {
241241
.cmd = AT_CMD_UICC_STATE,
242242
.data_name = UICC_DATA_NAME,
243243
.param_index = UICC_PARAM_INDEX,
244244
.param_count = UICC_PARAM_COUNT,
245-
.data_type = AT_PARAM_TYPE_NUM_INT,
245+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
246246
};
247247

248248
static const struct modem_info_data battery_data = {
249249
.cmd = AT_CMD_VBAT,
250250
.data_name = BATTERY_DATA_NAME,
251251
.param_index = VBAT_PARAM_INDEX,
252252
.param_count = VBAT_PARAM_COUNT,
253-
.data_type = AT_PARAM_TYPE_NUM_INT,
253+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
254254
};
255255

256256
static const struct modem_info_data temp_data = {
257257
.cmd = AT_CMD_TEMP,
258258
.data_name = TEMPERATURE_DATA_NAME,
259259
.param_index = TEMP_PARAM_INDEX,
260260
.param_count = TEMP_PARAM_COUNT,
261-
.data_type = AT_PARAM_TYPE_NUM_INT,
261+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
262262
};
263263

264264
static const struct modem_info_data fw_data = {
265265
.cmd = AT_CMD_FW_VERSION,
266266
.data_name = MODEM_FW_DATA_NAME,
267267
.param_index = MODEM_FW_PARAM_INDEX,
268268
.param_count = MODEM_FW_PARAM_COUNT,
269-
.data_type = AT_PARAM_TYPE_STRING,
269+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
270270
};
271271

272272
static const struct modem_info_data iccid_data = {
273273
.cmd = AT_CMD_ICCID,
274274
.data_name = ICCID_DATA_NAME,
275275
.param_index = ICCID_PARAM_INDEX,
276276
.param_count = ICCID_PARAM_COUNT,
277-
.data_type = AT_PARAM_TYPE_STRING,
277+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
278278
};
279279

280280
static const struct modem_info_data lte_mode_data = {
281281
.cmd = AT_CMD_SYSTEMMODE,
282282
.data_name = LTE_MODE_DATA_NAME,
283283
.param_index = LTE_MODE_PARAM_INDEX,
284284
.param_count = SYSTEMMODE_PARAM_COUNT,
285-
.data_type = AT_PARAM_TYPE_NUM_INT,
285+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
286286
};
287287

288288
static const struct modem_info_data nbiot_mode_data = {
289289
.cmd = AT_CMD_SYSTEMMODE,
290290
.data_name = NBIOT_MODE_DATA_NAME,
291291
.param_index = NBIOT_MODE_PARAM_INDEX,
292292
.param_count = SYSTEMMODE_PARAM_COUNT,
293-
.data_type = AT_PARAM_TYPE_NUM_INT,
293+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
294294
};
295295

296296
static const struct modem_info_data gps_mode_data = {
297297
.cmd = AT_CMD_SYSTEMMODE,
298298
.data_name = GPS_MODE_DATA_NAME,
299299
.param_index = GPS_MODE_PARAM_INDEX,
300300
.param_count = SYSTEMMODE_PARAM_COUNT,
301-
.data_type = AT_PARAM_TYPE_NUM_INT,
301+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
302302
};
303303

304304
static const struct modem_info_data imsi_data = {
305305
.cmd = AT_CMD_IMSI,
306306
.data_name = IMSI_DATA_NAME,
307307
.param_index = IMSI_PARAM_INDEX,
308308
.param_count = IMSI_PARAM_COUNT,
309-
.data_type = AT_PARAM_TYPE_STRING,
309+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
310310
};
311311

312312
static const struct modem_info_data imei_data = {
313313
.cmd = AT_CMD_IMEI,
314314
.data_name = MODEM_IMEI_DATA_NAME,
315315
.param_index = MODEM_IMEI_PARAM_INDEX,
316316
.param_count = MODEM_IMEI_PARAM_COUNT,
317-
.data_type = AT_PARAM_TYPE_STRING,
317+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
318318
};
319319

320320
static const struct modem_info_data date_time_data = {
321321
.cmd = AT_CMD_DATE_TIME,
322322
.data_name = DATE_TIME_DATA_NAME,
323323
.param_index = DATE_TIME_PARAM_INDEX,
324324
.param_count = DATE_TIME_PARAM_COUNT,
325-
.data_type = AT_PARAM_TYPE_STRING,
325+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
326326
};
327327

328328
static const struct modem_info_data apn_data = {
329329
.cmd = AT_CMD_PDP_CONTEXT,
330330
.data_name = APN_DATA_NAME,
331331
.param_index = APN_PARAM_INDEX,
332332
.param_count = APN_PARAM_COUNT,
333-
.data_type = AT_PARAM_TYPE_STRING,
333+
.data_type = MODEM_INFO_DATA_TYPE_STRING,
334334
};
335335

336336
static const struct modem_info_data *const modem_data[] = {
@@ -398,6 +398,23 @@ enum at_param_type modem_info_type_get(enum modem_info info_type)
398398
return -EINVAL;
399399
}
400400

401+
switch (modem_data[info_type]->data_type) {
402+
case MODEM_INFO_DATA_TYPE_NUM_INT:
403+
return AT_PARAM_TYPE_NUM_INT;
404+
case MODEM_INFO_DATA_TYPE_STRING:
405+
return AT_PARAM_TYPE_STRING;
406+
default:
407+
/* Unreachable. */
408+
return AT_PARAM_TYPE_INVALID;
409+
}
410+
}
411+
412+
enum modem_info_data_type modem_info_data_type_get(enum modem_info info_type)
413+
{
414+
if (info_type >= MODEM_INFO_COUNT) {
415+
return MODEM_INFO_DATA_TYPE_INVALID;
416+
}
417+
401418
return modem_data[info_type]->data_type;
402419
}
403420

@@ -433,7 +450,7 @@ int modem_info_short_get(enum modem_info info, uint16_t *buf)
433450
return -EINVAL;
434451
}
435452

436-
if (modem_data[info]->data_type == AT_PARAM_TYPE_STRING) {
453+
if (modem_data[info]->data_type == MODEM_INFO_DATA_TYPE_STRING) {
437454
return -EINVAL;
438455
}
439456

@@ -633,7 +650,7 @@ int modem_info_string_get(enum modem_info info, char *buf, const size_t buf_size
633650
err = at_parser_init(&parser, recv_buf);
634651
__ASSERT_NO_MSG(err == 0);
635652

636-
if (modem_data[info]->data_type == AT_PARAM_TYPE_NUM_INT) {
653+
if (modem_data[info]->data_type == MODEM_INFO_DATA_TYPE_NUM_INT) {
637654
err = at_parser_num_get(&parser,
638655
modem_data[info]->param_index,
639656
&param_value);
@@ -646,7 +663,7 @@ int modem_info_string_get(enum modem_info info, char *buf, const size_t buf_size
646663
if ((len <= 0) || (len > buf_size)) {
647664
return -EMSGSIZE;
648665
}
649-
} else if (modem_data[info]->data_type == AT_PARAM_TYPE_STRING) {
666+
} else if (modem_data[info]->data_type == MODEM_INFO_DATA_TYPE_STRING) {
650667
len = buf_size - out_buf_len;
651668
err = at_parser_string_get(&parser,
652669
modem_data[info]->param_index,
@@ -685,7 +702,7 @@ static void modem_info_rsrp_subscribe_handler(const char *notif)
685702
.data_name = RSRP_DATA_NAME,
686703
.param_index = RSRP_NOTIFY_PARAM_INDEX,
687704
.param_count = RSRP_NOTIFY_PARAM_COUNT,
688-
.data_type = AT_PARAM_TYPE_NUM_INT,
705+
.data_type = MODEM_INFO_DATA_TYPE_NUM_INT,
689706
};
690707

691708
err = at_parser_init(&parser, notif);

lib/modem_info/modem_info_params.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,24 @@ static int cellid_to_dec(struct lte_param *cellID, double *cellID_dec)
107107

108108
static int modem_data_get(struct lte_param *param)
109109
{
110-
enum at_param_type data_type;
110+
enum modem_info_data_type data_type;
111111
int ret;
112112

113-
data_type = modem_info_type_get(param->type);
113+
data_type = modem_info_data_type_get(param->type);
114114

115-
if (data_type < 0) {
115+
if (data_type == MODEM_INFO_DATA_TYPE_INVALID) {
116116
return -EINVAL;
117117
}
118118

119-
if (data_type == AT_PARAM_TYPE_STRING) {
119+
if (data_type == MODEM_INFO_DATA_TYPE_STRING) {
120120
ret = modem_info_string_get(param->type,
121121
param->value_string,
122122
sizeof(param->value_string));
123123
if (ret < 0) {
124124
LOG_ERR("Link data not obtained: %d %d", param->type, ret);
125125
return ret;
126126
}
127-
} else if (data_type == AT_PARAM_TYPE_NUM_INT) {
127+
} else if (data_type == MODEM_INFO_DATA_TYPE_NUM_INT) {
128128
ret = modem_info_short_get(param->type, &param->value);
129129
if (ret < 0) {
130130
LOG_ERR("Link data not obtained: %d", ret);

subsys/net/lib/nrf_cloud/src/nrf_cloud_codec_internal.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ int nrf_cloud_get_single_cell_modem_info(struct lte_lc_cell *const cell_inf)
12331233
static int add_modem_info_data(struct lte_param *param, cJSON *json_obj)
12341234
{
12351235
char data_name[MODEM_INFO_MAX_RESPONSE_SIZE];
1236-
enum at_param_type data_type;
1236+
enum modem_info_data_type data_type;
12371237
int ret;
12381238

12391239
__ASSERT_NO_MSG(param != NULL);
@@ -1246,12 +1246,12 @@ static int add_modem_info_data(struct lte_param *param, cJSON *json_obj)
12461246
return -EINVAL;
12471247
}
12481248

1249-
data_type = modem_info_type_get(param->type);
1249+
data_type = modem_info_data_type_get(param->type);
12501250
if (data_type < 0) {
12511251
return -EINVAL;
12521252
}
12531253

1254-
if (data_type == AT_PARAM_TYPE_STRING &&
1254+
if (data_type == MODEM_INFO_DATA_TYPE_STRING &&
12551255
param->type != MODEM_INFO_AREA_CODE) {
12561256
if (cJSON_AddStringToObject(json_obj, data_name, param->value_string) == NULL) {
12571257
return -ENOMEM;

0 commit comments

Comments
 (0)