1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef CHPP_GNSS_TYPES_H_
17 #define CHPP_GNSS_TYPES_H_
18 
19 // This file was automatically generated by chre_api_to_chpp.py
20 // Date: 2021-05-24 15:46:26 UTC
21 // Source: chre_api/include/chre_api/chre/gnss.h @ commit 833a6241
22 
23 // DO NOT modify this file directly, as those changes will be lost the next
24 // time the script is executed
25 
26 #include <stdbool.h>
27 #include <stddef.h>
28 #include <stdint.h>
29 
30 #include "chpp/app.h"
31 #include "chpp/common/common_types.h"
32 #include "chpp/macros.h"
33 #include "chre_api/chre/gnss.h"
34 #include "chre_api/chre/version.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 CHPP_PACKED_START
41 
42 //! See {@link chreGnssClock} for details
43 struct ChppGnssClock {
44   int64_t time_ns;
45   int64_t full_bias_ns;
46   float bias_ns;
47   float drift_nsps;
48   float bias_uncertainty_ns;
49   float drift_uncertainty_nsps;
50   uint32_t hw_clock_discontinuity_count;
51   uint16_t flags;
52   uint8_t reserved[2];  // Input ignored; always set to 0
53 } CHPP_PACKED_ATTR;
54 
55 //! See {@link chreGnssMeasurement} for details
56 struct ChppGnssMeasurement {
57   int64_t time_offset_ns;
58   int64_t accumulated_delta_range_um;
59   int64_t received_sv_time_in_ns;
60   int64_t received_sv_time_uncertainty_in_ns;
61   float pseudorange_rate_mps;
62   float pseudorange_rate_uncertainty_mps;
63   float accumulated_delta_range_uncertainty_m;
64   float c_n0_dbhz;
65   float snr_db;
66   uint16_t state;
67   uint16_t accumulated_delta_range_state;
68   int16_t svid;
69   uint8_t constellation;
70   uint8_t multipath_indicator;
71   float carrier_frequency_hz;
72 } CHPP_PACKED_ATTR;
73 
74 //! See {@link chreGnssDataEvent} for details
75 struct ChppGnssDataEvent {
76   uint8_t version;  // Input ignored; always set to CHRE_GNSS_DATA_EVENT_VERSION
77   uint8_t measurement_count;
78   uint8_t reserved[6];  // Input ignored; always set to 0
79   struct ChppGnssClock clock;
80   struct ChppOffset measurements;  // References measurement_count instances of
81                                    // struct ChppOffset
82 } CHPP_PACKED_ATTR;
83 
84 //! See {@link chreGnssLocationEvent} for details
85 struct ChppGnssLocationEvent {
86   uint64_t timestamp;
87   int32_t latitude_deg_e7;
88   int32_t longitude_deg_e7;
89   float altitude;
90   float speed;
91   float bearing;
92   float accuracy;
93   uint16_t flags;
94   uint8_t reserved[2];  // Input ignored; always set to 0
95   float altitude_accuracy;
96   float speed_accuracy;
97   float bearing_accuracy;
98 } CHPP_PACKED_ATTR;
99 
100 //! CHPP app header plus struct ChppGnssDataEventWithHeader
101 struct ChppGnssDataEventWithHeader {
102   struct ChppAppHeader header;
103   struct ChppGnssDataEvent payload;
104 } CHPP_PACKED_ATTR;
105 
106 //! CHPP app header plus struct ChppGnssLocationEventWithHeader
107 struct ChppGnssLocationEventWithHeader {
108   struct ChppAppHeader header;
109   struct ChppGnssLocationEvent payload;
110 } CHPP_PACKED_ATTR;
111 
112 CHPP_PACKED_END
113 
114 // Encoding functions (CHRE --> CHPP)
115 
116 /**
117  * Converts from given CHRE structure to serialized CHPP type.
118  *
119  * @param in Fully-formed CHRE structure.
120  * @param out Upon success, will point to a buffer allocated with chppMalloc().
121  * It is the responsibility of the caller to set the values of the CHPP app
122  * layer header, and to free the buffer when it is no longer needed via
123  * chppFree() or CHPP_FREE_AND_NULLIFY().
124  * @param outSize Upon success, will be set to the size of the output buffer, in
125  * bytes.
126  *
127  * @return true on success, false if memory allocation failed.
128  */
129 bool chppGnssDataEventFromChre(const struct chreGnssDataEvent *in,
130                                struct ChppGnssDataEventWithHeader **out,
131                                size_t *outSize);
132 
133 /**
134  * Converts from given CHRE structure to serialized CHPP type.
135  *
136  * @param in Fully-formed CHRE structure.
137  * @param out Upon success, will point to a buffer allocated with chppMalloc().
138  * It is the responsibility of the caller to set the values of the CHPP app
139  * layer header, and to free the buffer when it is no longer needed via
140  * chppFree() or CHPP_FREE_AND_NULLIFY().
141  * @param outSize Upon success, will be set to the size of the output buffer, in
142  * bytes.
143  *
144  * @return true on success, false if memory allocation failed.
145  */
146 bool chppGnssLocationEventFromChre(const struct chreGnssLocationEvent *in,
147                                    struct ChppGnssLocationEventWithHeader **out,
148                                    size_t *outSize);
149 
150 // Decoding functions (CHPP --> CHRE)
151 
152 /**
153  * Converts from serialized CHPP structure to a CHRE type.
154  *
155  * @param in Fully-formed CHPP structure.
156  * @param in Size of the CHPP structure in bytes.
157  *
158  * @return If successful, a pointer to a CHRE structure allocated with
159  * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
160  * to free the buffer when it is no longer needed via chppFree() or
161  * CHPP_FREE_AND_NULLIFY().
162  */
163 struct chreGnssDataEvent *chppGnssDataEventToChre(
164     const struct ChppGnssDataEvent *in, size_t inSize);
165 
166 /**
167  * Converts from serialized CHPP structure to a CHRE type.
168  *
169  * @param in Fully-formed CHPP structure.
170  * @param in Size of the CHPP structure in bytes.
171  *
172  * @return If successful, a pointer to a CHRE structure allocated with
173  * chppMalloc(). If unsuccessful, null. It is the responsibility of the caller
174  * to free the buffer when it is no longer needed via chppFree() or
175  * CHPP_FREE_AND_NULLIFY().
176  */
177 struct chreGnssLocationEvent *chppGnssLocationEventToChre(
178     const struct ChppGnssLocationEvent *in, size_t inSize);
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif  // CHPP_GNSS_TYPES_H_
185