nRF Connect SDK API 3.3.99
Loading...
Searching...
No Matches
nrf_cloud_codec.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef NRF_CLOUD_CODEC_H__
8#define NRF_CLOUD_CODEC_H__
9
10#include <net/nrf_cloud.h>
11#if defined(CONFIG_NRF_CLOUD_PGPS)
12#include <net/nrf_cloud_pgps.h>
13#endif
14#if defined(CONFIG_NRF_MODEM)
15#include <nrf_modem_gnss.h>
16#endif /* CONFIG_NRF_MODEM */
18#include <modem/lte_lc.h>
19
20#include <cJSON.h>
21#include <modem/lte_lc.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
45
55
68
71 char *app_id;
74 union {
75 char *str_val;
77 double double_val;
79 };
80 int64_t ts;
81};
82
97
100 /* A shadow delta, when there is a mismatch between "desired" and "reported" sections. */
102 /* The shadow data received in response to a JSONata transform request. */
105
116
120 int64_t ts;
122 int ver;
124 bool is_err;
125
126 union {
131 };
132};
133
142
154
166
178
185#define NRF_CLOUD_OBJ_JSON_DEFINE(_name) \
186 struct nrf_cloud_obj _name = { .type = NRF_CLOUD_OBJ_TYPE_JSON, .json = NULL, \
187 .enc_src = NRF_CLOUD_ENC_SRC_NONE, \
188 .encoded_data = { .len = 0, .ptr = NULL } }
189
190#define NRF_CLOUD_OBJ_COAP_CBOR_DEFINE(_name) \
191 struct nrf_cloud_obj _name = { .type = NRF_CLOUD_OBJ_TYPE_COAP_CBOR, \
192 .coap_cbor = NULL, \
193 .enc_src = NRF_CLOUD_ENC_SRC_NONE, \
194 .encoded_data = { .len = 0, .ptr = NULL } }
195
201#define NRF_CLOUD_OBJ_DEFINE(_name, _type) \
202 struct nrf_cloud_obj _name = { NRF_CLOUD_OBJ_TYPE__UNDEFINED }; \
203 _name.type = _type; \
204 _name.enc_src = NRF_CLOUD_ENC_SRC_NONE;
205
215#define NRF_CLOUD_OBJ_PRE_ENC_DEFINE(_name, _data, _len) \
216 struct nrf_cloud_obj _name = { .type = NRF_CLOUD_OBJ_TYPE__UNDEFINED, \
217 .enc_src = NRF_CLOUD_ENC_SRC_PRE_ENCODED, \
218 .encoded_data = { .len = _len, .ptr = _data } }
219
227#define NRF_CLOUD_OBJ_TYPE_VALID(_obj_ptr) \
228 (bool)((_obj_ptr != NULL) && \
229 (_obj_ptr->type > NRF_CLOUD_OBJ_TYPE__UNDEFINED) && \
230 (_obj_ptr->type < NRF_CLOUD_OBJ_TYPE__LAST))
231
250 const struct nrf_cloud_data *const input);
251
265int nrf_cloud_obj_msg_check(const struct nrf_cloud_obj *const obj, const char *const app_id,
266 const char *const msg_type);
267
282int nrf_cloud_obj_num_get(const struct nrf_cloud_obj *const obj, const char *const key,
283 double *num);
284
299int nrf_cloud_obj_str_get(const struct nrf_cloud_obj *const obj, const char *const key,
300 char **str);
301
316int nrf_cloud_obj_bool_get(const struct nrf_cloud_obj *const obj, const char *const key,
317 bool *val);
318
336int nrf_cloud_obj_object_detach(struct nrf_cloud_obj *const obj, const char *const key,
337 struct nrf_cloud_obj *const obj_out);
338
355int nrf_cloud_obj_msg_init(struct nrf_cloud_obj *const obj, const char *const app_id,
356 const char *const msg_type);
357
358
374
389int nrf_cloud_obj_init(struct nrf_cloud_obj *const obj);
390
400int nrf_cloud_obj_reset(struct nrf_cloud_obj *const obj);
401
415int nrf_cloud_obj_free(struct nrf_cloud_obj *const obj);
416
425
441int nrf_cloud_obj_bulk_add(struct nrf_cloud_obj *const bulk, struct nrf_cloud_obj *const obj);
442
455int nrf_cloud_obj_ts_add(struct nrf_cloud_obj *const obj, const int64_t time_ms);
456
474int nrf_cloud_obj_msg_ts_init(struct nrf_cloud_obj *const obj, const char *const app_id,
475 const char *const msg_type);
476
492int nrf_cloud_obj_num_add(struct nrf_cloud_obj *const obj, const char *const key,
493 const double val, const bool data_child);
494
510int nrf_cloud_obj_str_add(struct nrf_cloud_obj *const obj, const char *const key,
511 const char *const val, const bool data_child);
512
528int nrf_cloud_obj_bool_add(struct nrf_cloud_obj *const obj, const char *const key,
529 const bool val, const bool data_child);
530
545int nrf_cloud_obj_null_add(struct nrf_cloud_obj *const obj, const char *const key,
546 const bool data_child);
547
566int nrf_cloud_obj_object_add(struct nrf_cloud_obj *const obj, const char *const key,
567 struct nrf_cloud_obj *const obj_to_add, const bool data_child);
568
585int nrf_cloud_obj_int_array_add(struct nrf_cloud_obj *const obj, const char *const key,
586 const uint32_t ints[], const uint32_t ints_cnt,
587 const bool data_child);
588
605int nrf_cloud_obj_str_array_add(struct nrf_cloud_obj *const obj, const char *const key,
606 const char *const strs[], const uint32_t strs_cnt,
607 const bool data_child);
608
624
638
658 const struct nrf_cloud_gnss_data * const gnss);
659
680 struct nrf_cloud_obj *const obj,
681 const struct lte_lc_cells_info *const cells_inf,
682 const struct wifi_scan_info *const wifi_inf,
683 const struct nrf_cloud_location_config *const config,
684 int64_t timestamp
685);
686
706 const struct lte_lc_cells_info *const cells_inf,
707 const struct wifi_scan_info *const wifi_inf,
708 const struct nrf_cloud_location_config *const config);
709
724 const struct nrf_cloud_gnss_pvt * const pvt);
725
726#if defined(CONFIG_NRF_MODEM)
742 const struct nrf_modem_gnss_pvt_data_frame * const mdm_pvt);
743#endif /* CONFIG_NRF_MODEM */
744
745#if defined(CONFIG_NRF_CLOUD_PGPS)
763 const struct gps_pgps_request * const request);
764#endif
765
776 cJSON * const gnss_msg_obj);
777
788 cJSON * const svc_inf_obj);
789
802 cJSON * const mod_inf_obj);
803
821int nrf_cloud_error_msg_decode(const char * const buf,
822 const char * const app_id,
823 const char * const msg_type,
824 enum nrf_cloud_error * const err);
825
858 bool accept);
859
877 int (*process_cfg)(struct nrf_cloud_obj *cfg_obj),
878 int (*add_cfg_data)(struct nrf_cloud_obj *cfg_obj));
879
882#ifdef __cplusplus
883}
884#endif
885
886#endif /* NRF_CLOUD_CODEC_H__ */
int nrf_cloud_obj_msg_init(struct nrf_cloud_obj *const obj, const char *const app_id, const char *const msg_type)
Initialize an object as an nRF Cloud device message.
int nrf_cloud_obj_gnss_msg_create(struct nrf_cloud_obj *const obj, const struct nrf_cloud_gnss_data *const gnss)
Create an nRF Cloud GNSS message object.
int nrf_cloud_obj_bulk_init(struct nrf_cloud_obj *const bulk)
Initialize an object as an nRF Cloud bulk message.
int nrf_cloud_obj_str_get(const struct nrf_cloud_obj *const obj, const char *const key, char **str)
Get the string value associated with the provided key.
int nrf_cloud_obj_str_add(struct nrf_cloud_obj *const obj, const char *const key, const char *const val, const bool data_child)
Add a key string and string value to the provided object.
int nrf_cloud_obj_bool_get(const struct nrf_cloud_obj *const obj, const char *const key, bool *val)
Get the boolean value associated with the provided key.
int nrf_cloud_obj_null_add(struct nrf_cloud_obj *const obj, const char *const key, const bool data_child)
Add a key string and null value to the provided object.
int nrf_cloud_obj_cloud_encode(struct nrf_cloud_obj *const obj)
Encode the object's data for transport to nRF Cloud.
int nrf_cloud_obj_msg_check(const struct nrf_cloud_obj *const obj, const char *const app_id, const char *const msg_type)
Check if the object contains the specified app ID and message type.
int nrf_cloud_obj_num_get(const struct nrf_cloud_obj *const obj, const char *const key, double *num)
Get the number value associated with the provided key.
int nrf_cloud_obj_shadow_delta_response_encode(struct nrf_cloud_obj *const delta_state_obj, bool accept)
Encode the response to the shadow delta update.
int nrf_cloud_obj_bool_add(struct nrf_cloud_obj *const obj, const char *const key, const bool val, const bool data_child)
Add a key string and boolean value to the provided object.
int nrf_cloud_service_info_json_encode(const struct nrf_cloud_svc_info *const svc_inf, cJSON *const svc_inf_obj)
Add service info into the provided cJSON object.
int nrf_cloud_obj_msg_ts_init(struct nrf_cloud_obj *const obj, const char *const app_id, const char *const msg_type)
Initialize an nRF Cloud device message object with the current timestamp.
int nrf_cloud_obj_str_array_add(struct nrf_cloud_obj *const obj, const char *const key, const char *const strs[], const uint32_t strs_cnt, const bool data_child)
Add a key string and string array value to the provided object.
int nrf_cloud_obj_init(struct nrf_cloud_obj *const obj)
Initialize an empty object.
int nrf_cloud_obj_pvt_add(struct nrf_cloud_obj *const obj, const struct nrf_cloud_gnss_pvt *const pvt)
Add PVT data to the provided object.
int nrf_cloud_obj_location_request_create_timestamped(struct nrf_cloud_obj *const obj, const struct lte_lc_cells_info *const cells_inf, const struct wifi_scan_info *const wifi_inf, const struct nrf_cloud_location_config *const config, int64_t timestamp)
Create an nRF Cloud Location request message object with a timestamp.
nrf_cloud_obj_shadow_type
Types of shadow updates.
Definition nrf_cloud_codec.h:99
@ NRF_CLOUD_OBJ_SHADOW_TYPE_TF
Definition nrf_cloud_codec.h:103
@ NRF_CLOUD_OBJ_SHADOW_TYPE_DELTA
Definition nrf_cloud_codec.h:101
int nrf_cloud_obj_bulk_add(struct nrf_cloud_obj *const bulk, struct nrf_cloud_obj *const obj)
Add an object to a bulk message object.
int nrf_cloud_obj_location_request_create(struct nrf_cloud_obj *const obj, const struct lte_lc_cells_info *const cells_inf, const struct wifi_scan_info *const wifi_inf, const struct nrf_cloud_location_config *const config)
Create an nRF Cloud Location request message object.
int nrf_cloud_shadow_config_delta_process(struct nrf_cloud_obj *const delta_obj, int(*process_cfg)(struct nrf_cloud_obj *cfg_obj), int(*add_cfg_data)(struct nrf_cloud_obj *cfg_obj))
Process a shadow config delta using application-provided callbacks.
int nrf_cloud_obj_int_array_add(struct nrf_cloud_obj *const obj, const char *const key, const uint32_t ints[], const uint32_t ints_cnt, const bool data_child)
Add a key string and integer array value to the provided object.
int nrf_cloud_modem_info_json_encode(const struct nrf_cloud_modem_info *const mod_inf, cJSON *const mod_inf_obj)
Add modem info into the provided cJSON object.
int nrf_cloud_error_msg_decode(const char *const buf, const char *const app_id, const char *const msg_type, enum nrf_cloud_error *const err)
Check for a JSON error message in the data received from nRF Cloud over MQTT.
int nrf_cloud_obj_object_add(struct nrf_cloud_obj *const obj, const char *const key, struct nrf_cloud_obj *const obj_to_add, const bool data_child)
Add a key string and object to the provided object.
bool nrf_cloud_obj_bulk_check(struct nrf_cloud_obj *const obj)
Check if an object is a JSON array eligible for bulk transfer.
int nrf_cloud_obj_input_decode(struct nrf_cloud_obj *const obj, const struct nrf_cloud_data *const input)
Decode data received from nRF Cloud.
int nrf_cloud_obj_object_detach(struct nrf_cloud_obj *const obj, const char *const key, struct nrf_cloud_obj *const obj_out)
Get and detach the object associated with the provided key.
int nrf_cloud_obj_reset(struct nrf_cloud_obj *const obj)
Reset the state of an object; does not free memory.
nrf_cloud_obj_type
Object types for encoding and decoding.
Definition nrf_cloud_codec.h:34
@ NRF_CLOUD_OBJ_TYPE__LAST
Definition nrf_cloud_codec.h:43
@ NRF_CLOUD_OBJ_TYPE_JSON
Definition nrf_cloud_codec.h:37
@ NRF_CLOUD_OBJ_TYPE__UNDEFINED
Definition nrf_cloud_codec.h:35
@ NRF_CLOUD_OBJ_TYPE_COAP_CBOR
Definition nrf_cloud_codec.h:41
int nrf_cloud_obj_free(struct nrf_cloud_obj *const obj)
Free the memory of an initialized object.
int nrf_cloud_obj_ts_add(struct nrf_cloud_obj *const obj, const int64_t time_ms)
Add a timestamp to an object.
nrf_cloud_enc_src
Encoded data sources.
Definition nrf_cloud_codec.h:47
@ NRF_CLOUD_ENC_SRC_CLOUD_ENCODED
Definition nrf_cloud_codec.h:51
@ NRF_CLOUD_ENC_SRC_PRE_ENCODED
Definition nrf_cloud_codec.h:53
@ NRF_CLOUD_ENC_SRC_NONE
Definition nrf_cloud_codec.h:49
int nrf_cloud_obj_num_add(struct nrf_cloud_obj *const obj, const char *const key, const double val, const bool data_child)
Add a key string and number value to the provided object.
int nrf_cloud_obj_modem_pvt_add(struct nrf_cloud_obj *const obj, const struct nrf_modem_gnss_pvt_data_frame *const mdm_pvt)
Add modem PVT data to the provided object.
int nrf_cloud_obj_cloud_encoded_free(struct nrf_cloud_obj *const obj)
Free the memory of the encoded data in the object.
int nrf_cloud_gnss_msg_json_encode(const struct nrf_cloud_gnss_data *const gnss, cJSON *const gnss_msg_obj)
Create an nRF Cloud GNSS device message using the provided GNSS data.
nrf_cloud_data_type
Data types for nrf_cloud_sensor_data.
Definition nrf_cloud_codec.h:57
@ NRF_CLOUD_DATA_TYPE_STR
Definition nrf_cloud_codec.h:62
@ NRF_CLOUD_DATA_TYPE_INT
Definition nrf_cloud_codec.h:66
@ NRF_CLOUD_DATA_TYPE_NONE
Definition nrf_cloud_codec.h:58
@ NRF_CLOUD_DATA_TYPE_DOUBLE
Definition nrf_cloud_codec.h:64
@ NRF_CLOUD_DATA_TYPE_PVT
Definition nrf_cloud_codec.h:60
int nrf_cloud_obj_pgps_request_create(struct nrf_cloud_obj *const obj, const struct gps_pgps_request *const request)
Create an nRF Cloud P-GPS request device message object.
nrf_cloud_error
nRF Cloud error codes. See the Error Codes section of nRF Cloud API documentation for more informatio...
Definition nrf_cloud.h:210
Module to provide nRF Cloud location support to nRF9160 SiP.
Module to provide nRF Cloud Predicted GPS (P-GPS) support to nRF9160 SiP.
P-GPS request type.
Definition nrf_cloud_pgps.h:86
Results of neighbor cell measurements.
Definition lte_lc.h:673
Generic encapsulation for any data that is sent to the cloud.
Definition nrf_cloud.h:369
GNSS data to be sent to nRF Cloud as a device message.
Definition nrf_cloud.h:597
PVT data.
Definition nrf_cloud.h:546
Location request config.
Definition nrf_cloud_location.h:100
Modem info data and which sections should be encoded.
Definition nrf_cloud.h:492
enum nrf_cloud_data_type type
Definition nrf_cloud_codec.h:73
int int_val
Definition nrf_cloud_codec.h:78
double double_val
Definition nrf_cloud_codec.h:77
char * app_id
Definition nrf_cloud_codec.h:71
struct nrf_cloud_gnss_pvt * pvt
Definition nrf_cloud_codec.h:76
int64_t ts
Definition nrf_cloud_codec.h:80
char * str_val
Definition nrf_cloud_codec.h:75
Object to support nRF Cloud CoAP CBOR messages.
Definition nrf_cloud_codec.h:70
struct nrf_cloud_obj_shadow_delta * delta
Definition nrf_cloud_codec.h:173
enum nrf_cloud_obj_shadow_type type
Definition nrf_cloud_codec.h:170
struct nrf_cloud_obj_shadow_transform * transform
Definition nrf_cloud_codec.h:175
Object containing shadow update data.
Definition nrf_cloud_codec.h:168
struct nrf_cloud_obj err_obj
Definition nrf_cloud_codec.h:114
int code
Definition nrf_cloud_codec.h:109
char * msg
Definition nrf_cloud_codec.h:111
Object containing shadow delta error data.
Definition nrf_cloud_codec.h:107
int ver
Definition nrf_cloud_codec.h:122
struct nrf_cloud_obj_shadow_delta_err error
Definition nrf_cloud_codec.h:130
int64_t ts
Definition nrf_cloud_codec.h:120
bool is_err
Definition nrf_cloud_codec.h:124
struct nrf_cloud_obj state
Definition nrf_cloud_codec.h:128
Object containing shadow delta data.
Definition nrf_cloud_codec.h:118
int pos
Definition nrf_cloud_codec.h:147
struct nrf_cloud_obj err_obj
Definition nrf_cloud_codec.h:152
char * msg
Definition nrf_cloud_codec.h:149
int code
Definition nrf_cloud_codec.h:145
Definition nrf_cloud_codec.h:143
struct nrf_cloud_obj obj
Definition nrf_cloud_codec.h:140
Definition nrf_cloud_codec.h:134
struct nrf_cloud_obj_shadow_transform_error error
Definition nrf_cloud_codec.h:163
struct nrf_cloud_obj_shadow_transform_result result
Definition nrf_cloud_codec.h:161
bool is_err
Definition nrf_cloud_codec.h:157
Definition nrf_cloud_codec.h:155
cJSON * json
Definition nrf_cloud_codec.h:88
enum nrf_cloud_enc_src enc_src
Definition nrf_cloud_codec.h:93
enum nrf_cloud_obj_type type
Definition nrf_cloud_codec.h:86
struct nrf_cloud_obj_coap_cbor * coap_cbor
Definition nrf_cloud_codec.h:89
struct nrf_cloud_data encoded_data
Definition nrf_cloud_codec.h:95
Object used for building nRF Cloud messages.
Definition nrf_cloud_codec.h:84
Structure to specify which components are added to the encoded service info object.
Definition nrf_cloud.h:511
Access points found during a Wi-Fi scan.
Definition wifi_location_common.h:29