aboutsummaryrefslogtreecommitdiff
path: root/chpp/include/chpp/common/gnss_types.h
blob: 1f5f65347fc24473bf999c53c0a64432dfa1be57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef CHPP_GNSS_TYPES_H_
#define CHPP_GNSS_TYPES_H_

// This file was automatically generated by chre_api_to_chpp.py
// Date: 2021-05-24 15:46:26 UTC
// Source: chre_api/include/chre_api/chre/gnss.h @ commit 833a6241

// DO NOT modify this file directly, as those changes will be lost the next
// time the script is executed

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include "chpp/app.h"
#include "chpp/common/common_types.h"
#include "chpp/macros.h"
#include "chre_api/chre/gnss.h"
#include "chre_api/chre/version.h"

#ifdef __cplusplus
extern "C" {
#endif

CHPP_PACKED_START

//! See {@link chreGnssClock} for details
struct ChppGnssClock {
  int64_t time_ns;
  int64_t full_bias_ns;
  float bias_ns;
  float drift_nsps;
  float bias_uncertainty_ns;
  float drift_uncertainty_nsps;
  uint32_t hw_clock_discontinuity_count;
  uint16_t flags;
  uint8_t reserved[2];  // Input ignored; always set to 0
} CHPP_PACKED_ATTR;

//! See {@link chreGnssMeasurement} for details
struct ChppGnssMeasurement {
  int64_t time_offset_ns;
  int64_t accumulated_delta_range_um;
  int64_t received_sv_time_in_ns;
  int64_t received_sv_time_uncertainty_in_ns;
  float pseudorange_rate_mps;
  float pseudorange_rate_uncertainty_mps;
  float accumulated_delta_range_uncertainty_m;
  float c_n0_dbhz;
  float snr_db;
  uint16_t state;
  uint16_t accumulated_delta_range_state;
  int16_t svid;
  uint8_t constellation;
  uint8_t multipath_indicator;
  float carrier_frequency_hz;
} CHPP_PACKED_ATTR;

//! See {@link chreGnssDataEvent} for details
struct ChppGnssDataEvent {
  uint8_t version;  // Input ignored; always set to CHRE_GNSS_DATA_EVENT_VERSION
  uint8_t measurement_count;
  uint8_t reserved[6];  // Input ignored; always set to 0
  struct ChppGnssClock clock;
  struct ChppOffset measurements;  // References measurement_count instances of
                                   // struct ChppOffset
} CHPP_PACKED_ATTR;

//! See {@link chreGnssLocationEvent} for details
struct ChppGnssLocationEvent {
  uint64_t timestamp;
  int32_t latitude_deg_e7;
  int32_t longitude_deg_e7;
  float altitude;
  float speed;
  float bearing;
  float accuracy;
  uint16_t flags;
  uint8_t reserved[2];  // Input ignored; always set to 0
  float altitude_accuracy;
  float speed_accuracy;
  float bearing_accuracy;
} CHPP_PACKED_ATTR;

//! CHPP app header plus struct ChppGnssDataEventWithHeader
struct ChppGnssDataEventWithHeader {
  struct ChppAppHeader header;
  struct ChppGnssDataEvent payload;
} CHPP_PACKED_ATTR;

//! CHPP app header plus struct ChppGnssLocationEventWithHeader
struct ChppGnssLocationEventWithHeader {
  struct ChppAppHeader header;
  struct ChppGnssLocationEvent payload;
} CHPP_PACKED_ATTR;

CHPP_PACKED_END

// Encoding functions (CHRE --> CHPP)

/**
 * Converts from given CHRE structure to serialized CHPP type.
 *
 * @param in Fully-formed CHRE structure.
 * @param out Upon success, will point to a buffer allocated with chppMalloc().
 * It is the responsibility of the caller to set the values of the CHPP app
 * layer header, and to free the buffer when it is no longer needed via
 * chppFree() or CHPP_FREE_AND_NULLIFY().
 * @param outSize Upon success, will be set to the size of the output buffer, in
 * bytes.
 *
 * @return true on success, false if memory allocation failed.
 */
bool chppGnssDataEventFromChre(const struct chreGnssDataEvent *in,
                               struct ChppGnssDataEventWithHeader **out,
                               size_t *outSize);

/**
 * Converts from given CHRE structure to serialized CHPP type.
 *
 * @param in Fully-formed CHRE structure.
 * @param out Upon success, will point to a buffer allocated with chppMalloc().
 * It is the responsibility of the caller to set the values of the CHPP app
 * layer header, and to free the buffer when it is no longer needed via
 * chppFree() or CHPP_FREE_AND_NULLIFY().
 * @param outSize Upon success, will be set to the size of the output buffer, in
 * bytes.
 *
 * @return true on success, false if memory allocation failed.
 */
bool chppGnssLocationEventFromChre(const struct chreGnssLocationEvent *in,
                                   struct ChppGnssLocationEventWithHeader **out,
                                   size_t *outSize);

// Decoding functions (CHPP --> CHRE)

/**
 * Converts from serialized CHPP structure to a CHRE type.
 *
 * @param in Fully-formed CHPP structure.
 * @param in Size of the CHPP structure in bytes.
 *
 * @return If successful, a pointer to a CHRE structure allocated with
 * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
 * to free the buffer when it is no longer needed via chppFree() or
 * CHPP_FREE_AND_NULLIFY().
 */
struct chreGnssDataEvent *chppGnssDataEventToChre(
    const struct ChppGnssDataEvent *in, size_t inSize);

/**
 * Converts from serialized CHPP structure to a CHRE type.
 *
 * @param in Fully-formed CHPP structure.
 * @param in Size of the CHPP structure in bytes.
 *
 * @return If successful, a pointer to a CHRE structure allocated with
 * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
 * to free the buffer when it is no longer needed via chppFree() or
 * CHPP_FREE_AND_NULLIFY().
 */
struct chreGnssLocationEvent *chppGnssLocationEventToChre(
    const struct ChppGnssLocationEvent *in, size_t inSize);

#ifdef __cplusplus
}
#endif

#endif  // CHPP_GNSS_TYPES_H_