nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
cloud_codec.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef CLOUD_CODEC_H__
8#define CLOUD_CODEC_H__
9
10#include <zephyr/kernel.h>
11#include <stdbool.h>
12#include <stdint.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <cJSON_os.h>
16#include <zephyr/net/net_ip.h>
17#include <modem/lte_lc.h>
18#if defined(CONFIG_LOCATION)
19#include <modem/location.h>
20#endif
22#include <nrf_modem_gnss.h>
23
24#if defined(CONFIG_LWM2M)
25#include <zephyr/net/lwm2m.h>
26#else
27#include "lwm2m/lwm2m_dummy.h"
28#endif
29
37#ifdef __cplusplus
38extern "C" {
39#endif
40
44#define CLOUD_GNSS_HEADING_ACC_LIMIT (float)60.0
45
49 uint16_t bat;
51 int64_t bat_ts;
53 bool queued : 1;
54};
55
58 double lat;
60 double lon;
62 float acc;
64 float alt;
66 float alt_acc;
68 float spd;
70 float spd_acc;
72 float hdg;
74 float hdg_acc;
75};
76
80 int64_t gnss_ts;
81
84
86 bool queued : 1;
87};
88
94 bool gnss;
95
98
100 bool wifi;
101};
102
124};
125
129 int64_t ts;
131 double magnitude;
133 bool queued : 1;
134};
135
138 int64_t env_ts;
142 double humidity;
144 double pressure;
150 bool queued : 1;
151};
152
155 int64_t ts;
157 char iccid[23];
159 char appv[CONFIG_ASSET_TRACKER_V2_APP_VERSION_MAX_LEN];
161 char brdv[30];
163 char fw[40];
165 char imei[16];
167 bool queued : 1;
168};
169
172 int64_t ts;
174 uint8_t band;
178 uint16_t mcc;
180 uint16_t mnc;
182 uint16_t area;
184 uint32_t cell;
186 int16_t rsrp;
188 char ip[INET6_ADDRSTRLEN];
190 char apn[CONFIG_CLOUD_CODEC_APN_LEN_MAX];
192 char mccmnc[7];
194 bool queued : 1;
195};
196
199 int btn;
201 int64_t btn_ts;
203 bool queued : 1;
204};
205
208 char *buf;
210 size_t len;
212 struct lwm2m_obj_path paths[CONFIG_CLOUD_CODEC_LWM2M_PATH_LIST_ENTRIES_MAX];
215};
216
221 struct lte_lc_ncell neighbor_cells[CONFIG_LTE_NEIGHBOR_CELLS_MAX];
223 int64_t ts;
225 bool queued : 1;
226};
227
228#if defined(CONFIG_LOCATION_METHOD_WIFI)
231 struct wifi_scan_result ap_info[CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT];
233 uint16_t cnt;
235 int64_t ts;
237 bool queued : 1;
238};
239#endif
240
246#if defined(CONFIG_LOCATION_METHOD_WIFI)
251#endif
253 int64_t ts;
255 bool queued : 1;
256};
257
260 int mcc;
262 int mnc;
264 uint32_t cell;
266 uint32_t area;
268 struct nrf_modem_gnss_agnss_data_frame request;
270 bool queued : 1;
271};
274 uint16_t count;
276 uint16_t interval;
278 uint16_t day;
280 uint32_t time;
282 bool queued : 1;
283};
284
288};
289
295};
296
302typedef void (*cloud_codec_evt_handler_t)(const struct cloud_codec_evt *evt);
303
315
333 struct cloud_codec_data *output,
334 struct cloud_data_cloud_location *cloud_location);
335
336/* Foward declaration */
337struct location_data;
338
352int cloud_codec_decode_cloud_location(const char *input, size_t input_len,
353 struct location_data *location);
354
371 struct cloud_data_agnss_request *agnss_request);
372
389 struct cloud_data_pgps_request *pgps_request);
390
404int cloud_codec_decode_config(const char *input, size_t input_len,
405 struct cloud_data_cfg *cfg);
406
418 struct cloud_data_cfg *cfg);
419
439 struct cloud_data_gnss *gnss_buf,
440 struct cloud_data_sensors *sensor_buf,
441 struct cloud_data_modem_static *modem_stat_buf,
442 struct cloud_data_modem_dynamic *modem_dyn_buf,
443 struct cloud_data_ui *ui_buf,
444 struct cloud_data_impact *impact_buf,
445 struct cloud_data_battery *bat_buf);
446
459 struct cloud_data_ui *ui_buf);
460
473 struct cloud_data_impact *impact_buf);
474
501 struct cloud_data_gnss *gnss_buf,
502 struct cloud_data_sensors *sensor_buf,
503 struct cloud_data_modem_static *modem_stat_buf,
504 struct cloud_data_modem_dynamic *modem_dyn_buf,
505 struct cloud_data_ui *ui_buf,
506 struct cloud_data_impact *impact_buf,
507 struct cloud_data_battery *bat_buf,
508 size_t gnss_buf_count,
509 size_t sensor_buf_count,
510 size_t modem_stat_buf_count,
511 size_t modem_dyn_buf_count,
512 size_t ui_buf_count,
513 size_t impact_buf_count,
514 size_t bat_buf_count);
515
517 struct cloud_data_sensors *sensor_buffer,
518 struct cloud_data_sensors *new_sensor_data,
519 int *head_sensor_buf,
520 size_t buffer_count);
521
523 struct cloud_data_ui *new_ui_data,
524 int *head_ui_buf,
525 size_t buffer_count);
526
528 struct cloud_data_impact *impact_buf,
529 struct cloud_data_impact *new_impact_data,
530 int *head_impact_buf,
531 size_t buffer_count);
532
534 struct cloud_data_battery *new_bat_data,
535 int *head_bat_buf,
536 size_t buffer_count);
537
539 struct cloud_data_gnss *new_gnss_data,
540 int *head_gnss_buf,
541 size_t buffer_count);
542
544 struct cloud_data_modem_dynamic *modem_buffer,
545 struct cloud_data_modem_dynamic *new_modem_data,
546 int *head_modem_buf,
547 size_t buffer_count);
548
549#ifdef __cplusplus
550}
551#endif
555#endif
static const struct event_proxy_config cfg
Definition: event_proxy_def.h:28
int cloud_codec_init(struct cloud_data_cfg *cfg, cloud_codec_evt_handler_t event_handler)
Initialize cloud codec.
int cloud_codec_encode_cloud_location(struct cloud_codec_data *output, struct cloud_data_cloud_location *cloud_location)
Encode cloud codec cloud location data.
int cloud_codec_decode_config(const char *input, size_t input_len, struct cloud_data_cfg *cfg)
Decode received configuration.
cloud_codec_event_type
Definition: cloud_codec.h:285
@ CLOUD_CODEC_EVT_CONFIG_UPDATE
Definition: cloud_codec.h:287
int cloud_codec_encode_data(struct cloud_codec_data *output, struct cloud_data_gnss *gnss_buf, struct cloud_data_sensors *sensor_buf, struct cloud_data_modem_static *modem_stat_buf, struct cloud_data_modem_dynamic *modem_dyn_buf, struct cloud_data_ui *ui_buf, struct cloud_data_impact *impact_buf, struct cloud_data_battery *bat_buf)
Encode cloud buffer data.
int cloud_codec_encode_batch_data(struct cloud_codec_data *output, struct cloud_data_gnss *gnss_buf, struct cloud_data_sensors *sensor_buf, struct cloud_data_modem_static *modem_stat_buf, struct cloud_data_modem_dynamic *modem_dyn_buf, struct cloud_data_ui *ui_buf, struct cloud_data_impact *impact_buf, struct cloud_data_battery *bat_buf, size_t gnss_buf_count, size_t sensor_buf_count, size_t modem_stat_buf_count, size_t modem_dyn_buf_count, size_t ui_buf_count, size_t impact_buf_count, size_t bat_buf_count)
Encode a batch of cloud buffer data.
int cloud_codec_encode_ui_data(struct cloud_codec_data *output, struct cloud_data_ui *ui_buf)
Encode UI data.
void cloud_codec_populate_gnss_buffer(struct cloud_data_gnss *gnss_buffer, struct cloud_data_gnss *new_gnss_data, int *head_gnss_buf, size_t buffer_count)
void cloud_codec_populate_bat_buffer(struct cloud_data_battery *bat_buffer, struct cloud_data_battery *new_bat_data, int *head_bat_buf, size_t buffer_count)
void cloud_codec_populate_ui_buffer(struct cloud_data_ui *ui_buffer, struct cloud_data_ui *new_ui_data, int *head_ui_buf, size_t buffer_count)
int cloud_codec_encode_pgps_request(struct cloud_codec_data *output, struct cloud_data_pgps_request *pgps_request)
Encode cloud codec P-GPS request.
int cloud_codec_encode_config(struct cloud_codec_data *output, struct cloud_data_cfg *cfg)
Encode current configuration.
int cloud_codec_encode_impact_data(struct cloud_codec_data *output, struct cloud_data_impact *impact_buf)
Encode impact data.
void cloud_codec_populate_impact_buffer(struct cloud_data_impact *impact_buf, struct cloud_data_impact *new_impact_data, int *head_impact_buf, size_t buffer_count)
void cloud_codec_populate_modem_dynamic_buffer(struct cloud_data_modem_dynamic *modem_buffer, struct cloud_data_modem_dynamic *new_modem_data, int *head_modem_buf, size_t buffer_count)
void(* cloud_codec_evt_handler_t)(const struct cloud_codec_evt *evt)
Event handler prototype.
Definition: cloud_codec.h:302
int cloud_codec_decode_cloud_location(const char *input, size_t input_len, struct location_data *location)
Decode received cloud location data.
void cloud_codec_populate_sensor_buffer(struct cloud_data_sensors *sensor_buffer, struct cloud_data_sensors *new_sensor_data, int *head_sensor_buf, size_t buffer_count)
int cloud_codec_encode_agnss_request(struct cloud_codec_data *output, struct cloud_data_agnss_request *agnss_request)
Encode cloud codec A-GNSS request.
lte_lc_lte_mode
Definition: lte_lc.h:89
Public APIs for the Location library.
char * buf
Definition: cloud_codec.h:208
uint8_t valid_object_paths
Definition: cloud_codec.h:214
struct lwm2m_obj_path paths[CONFIG_CLOUD_CODEC_LWM2M_PATH_LIST_ENTRIES_MAX]
Definition: cloud_codec.h:212
size_t len
Definition: cloud_codec.h:210
Definition: cloud_codec.h:206
struct cloud_data_cfg config_update
Definition: cloud_codec.h:294
enum cloud_codec_event_type type
Definition: cloud_codec.h:292
Definition: cloud_codec.h:290
bool queued
Definition: cloud_codec.h:270
struct nrf_modem_gnss_agnss_data_frame request
Definition: cloud_codec.h:268
uint32_t area
Definition: cloud_codec.h:266
int mcc
Definition: cloud_codec.h:260
int mnc
Definition: cloud_codec.h:262
uint32_t cell
Definition: cloud_codec.h:264
Definition: cloud_codec.h:258
uint16_t bat
Definition: cloud_codec.h:49
bool queued
Definition: cloud_codec.h:53
int64_t bat_ts
Definition: cloud_codec.h:51
Structure containing battery data published to cloud.
Definition: cloud_codec.h:47
int movement_resolution
Definition: cloud_codec.h:111
int location_timeout
Definition: cloud_codec.h:107
double accelerometer_inactivity_timeout
Definition: cloud_codec.h:121
bool active_mode
Definition: cloud_codec.h:105
double accelerometer_activity_threshold
Definition: cloud_codec.h:117
double accelerometer_inactivity_threshold
Definition: cloud_codec.h:119
int active_wait_timeout
Definition: cloud_codec.h:109
struct cloud_data_no_data no_data
Definition: cloud_codec.h:123
int movement_timeout
Definition: cloud_codec.h:115
Definition: cloud_codec.h:103
bool neighbor_cells_valid
Definition: cloud_codec.h:243
bool queued
Definition: cloud_codec.h:255
struct cloud_data_wifi_access_points wifi_access_points
Definition: cloud_codec.h:250
bool wifi_access_points_valid
Definition: cloud_codec.h:248
struct cloud_data_neighbor_cells neighbor_cells
Definition: cloud_codec.h:245
int64_t ts
Definition: cloud_codec.h:253
Definition: cloud_codec.h:241
double lon
Definition: cloud_codec.h:60
float alt_acc
Definition: cloud_codec.h:66
float alt
Definition: cloud_codec.h:64
float hdg
Definition: cloud_codec.h:72
float hdg_acc
Definition: cloud_codec.h:74
float spd
Definition: cloud_codec.h:68
double lat
Definition: cloud_codec.h:58
float acc
Definition: cloud_codec.h:62
float spd_acc
Definition: cloud_codec.h:70
Definition: cloud_codec.h:56
bool queued
Definition: cloud_codec.h:86
struct cloud_data_gnss_pvt pvt
Definition: cloud_codec.h:83
int64_t gnss_ts
Definition: cloud_codec.h:80
Structure containing GNSS data published to cloud.
Definition: cloud_codec.h:78
bool queued
Definition: cloud_codec.h:133
double magnitude
Definition: cloud_codec.h:131
int64_t ts
Definition: cloud_codec.h:129
Definition: cloud_codec.h:127
uint32_t cell
Definition: cloud_codec.h:184
int16_t rsrp
Definition: cloud_codec.h:186
char mccmnc[7]
Definition: cloud_codec.h:192
uint8_t band
Definition: cloud_codec.h:174
int64_t ts
Definition: cloud_codec.h:172
uint16_t area
Definition: cloud_codec.h:182
uint16_t mcc
Definition: cloud_codec.h:178
enum lte_lc_lte_mode nw_mode
Definition: cloud_codec.h:176
char apn[CONFIG_CLOUD_CODEC_APN_LEN_MAX]
Definition: cloud_codec.h:190
uint16_t mnc
Definition: cloud_codec.h:180
bool queued
Definition: cloud_codec.h:194
char ip[INET6_ADDRSTRLEN]
Definition: cloud_codec.h:188
Definition: cloud_codec.h:170
bool queued
Definition: cloud_codec.h:167
char appv[CONFIG_ASSET_TRACKER_V2_APP_VERSION_MAX_LEN]
Definition: cloud_codec.h:159
char fw[40]
Definition: cloud_codec.h:163
char iccid[23]
Definition: cloud_codec.h:157
char brdv[30]
Definition: cloud_codec.h:161
int64_t ts
Definition: cloud_codec.h:155
char imei[16]
Definition: cloud_codec.h:165
Definition: cloud_codec.h:153
bool queued
Definition: cloud_codec.h:225
int64_t ts
Definition: cloud_codec.h:223
struct lte_lc_cells_info cell_data
Definition: cloud_codec.h:219
struct lte_lc_ncell neighbor_cells[CONFIG_LTE_NEIGHBOR_CELLS_MAX]
Definition: cloud_codec.h:221
Definition: cloud_codec.h:217
bool gnss
Definition: cloud_codec.h:94
bool wifi
Definition: cloud_codec.h:100
bool neighbor_cell
Definition: cloud_codec.h:97
Definition: cloud_codec.h:92
uint16_t interval
Definition: cloud_codec.h:276
uint16_t count
Definition: cloud_codec.h:274
bool queued
Definition: cloud_codec.h:282
uint16_t day
Definition: cloud_codec.h:278
uint32_t time
Definition: cloud_codec.h:280
Definition: cloud_codec.h:272
double temperature
Definition: cloud_codec.h:140
double pressure
Definition: cloud_codec.h:144
bool queued
Definition: cloud_codec.h:150
int bsec_air_quality
Definition: cloud_codec.h:148
int64_t env_ts
Definition: cloud_codec.h:138
double humidity
Definition: cloud_codec.h:142
Definition: cloud_codec.h:136
bool queued
Definition: cloud_codec.h:203
int64_t btn_ts
Definition: cloud_codec.h:201
int btn
Definition: cloud_codec.h:199
Definition: cloud_codec.h:197
bool queued
Definition: cloud_codec.h:237
struct wifi_scan_result ap_info[CONFIG_LOCATION_METHOD_WIFI_SCANNING_RESULTS_MAX_CNT]
Definition: cloud_codec.h:231
int64_t ts
Definition: cloud_codec.h:235
uint16_t cnt
Definition: cloud_codec.h:233
Definition: cloud_codec.h:229
Definition: location.h:249
Definition: lte_lc.h:513
Definition: lte_lc.h:385
Definition: lwm2m_dummy.h:10