-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflightplan.h
274 lines (239 loc) · 6.02 KB
/
flightplan.h
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#ifndef LIBFLIGHTPLAN_H_GUARD
#define LIBFLIGHTPLAN_H_GUARD
#ifdef __cplusplus
extern "C" {
#endif
/*
* NAME fpl_cleanup()
*
* DESCRIPTION
*
* This should be called when the process is done using this library
* to perform any global level memory cleanup (really just any errors).
* This is safe to call multiple times.
* */
void fpl_cleanup();
// A flightplan represents the primary flightplan data structure.
typedef void flightplan;
/*
* NAME fpl_new()
*
* DESCRIPTION
*
* Create a new empty flight plan.
*/
flightplan *fpl_new();
/*
* NAME fpl_free()
*
* DESCRIPTION
*
* Free resources associated with a flight plan. The flight plan can no longer
* be used after this is called. This must be called for any flight plan that
* is returned.
*/
void fpl_free(flightplan *);
/*
* NAME fpl_created()
*
* DESCRIPTION
*
* Returns the timestamp when the flight plan was created.
*
* NOTE(mitchellh): This raw string is not what I want long term. I want to
* convert this to a UTC unix timestamp, so this function will probably change
* to a time_t result at some point.
*/
char *fpl_created(flightplan *);
/**************************************************************************
* Errors
*************************************************************************/
typedef void flightplan_error;
/*
* NAME fpl_last_error()
*
* DESCRIPTION
*
* Returns the last error (if any). An error can be set in any situation
* where a function returns NULL or otherwise noted by the documentation.
* The error doesn't need to be freed; any memory associated with error storage
* is freed when fpl_cleanup is called.
*
* This error is only valid until another error occurs.
* */
flightplan_error *fpl_last_error();
/*
* NAME fpl_error_message()
*
* DESCRIPTION
*
* Returns a human-friendly error message for this error.
* */
char *fpl_error_message(flightplan_error *);
/**************************************************************************
* Import/Export
*************************************************************************/
/*
* NAME fpl_garmin_parse_file()
*
* DESCRIPTION
*
* Parse a Garmin FPL file. This is also compatible with ForeFlight.
*/
flightplan *fpl_garmin_parse_file(char *);
/*
* NAME fpl_garmin_write_to_file()
*
* DESCRIPTION
*
* Write a flight plan in Garmin FPL format to the given file.
*/
int fpl_garmin_write_to_file(flightplan *, char *);
/*
* NAME fpl_xplane11_write_to_file()
*
* DESCRIPTION
*
* Write a flight plan in X-Plane 11 FMS format to the given file.
*/
int fpl_xplane11_write_to_file(flightplan *, char *);
/**************************************************************************
* Waypoints
*************************************************************************/
// A waypoint that the flight plan may or may not use but knows about.
typedef void flightplan_waypoint;
typedef void flightplan_waypoint_iter;
// Types of waypoints.
typedef enum {
FLIGHTPLAN_INVALID,
FLIGHTPLAN_USER_WAYPOINT,
FLIGHTPLAN_AIRPORT,
FLIGHTPLAN_NDB,
FLIGHTPLAN_VOR,
FLIGHTPLAN_INT,
FLIGHTPLAN_INT_VRP,
} flightplan_waypoint_type;
/*
* NAME fpl_waypoints_count()
*
* DESCRIPTION
*
* Returns the total number of waypoints that are in this flight plan.
*/
int fpl_waypoints_count(flightplan *);
/*
* NAME fpl_waypoint_iter()
*
* DESCRIPTION
*
* Returns an iterator that can be used to read each of the waypoints.
* The iterator is only valid so long as zero modifications are made
* to the waypoint list.
*
* The iterator must be freed with fpl_waypoint_iter_free.
*/
flightplan_waypoint_iter *fpl_waypoints_iter(flightplan *);
/*
* NAME fpl_waypoint_iter_free()
*
* DESCRIPTION
*
* Free resources associated with an iterator.
*/
void fpl_waypoint_iter_free(flightplan_waypoint_iter *);
/*
* NAME fpl_waypoints_next()
*
* DESCRIPTION
*
* Get the next waypoint for the iterator. This returns NULL when there are
* no more waypoints available. The values returned should NOT be manually
* freed, they are owned by the flight plan.
*/
flightplan_waypoint *fpl_waypoints_next(flightplan_waypoint_iter *);
// TODO
flightplan_waypoint *fpl_waypoint_new();
void fpl_waypoint_free(flightplan_waypoint *);
/*
* NAME fpl_waypoint_identifier()
*
* DESCRIPTION
*
* Return the unique identifier for this waypoint.
*/
char *fpl_waypoint_identifier(flightplan_waypoint *);
/*
* NAME fpl_waypoint_lat()
*
* DESCRIPTION
*
* Return the latitude for this waypoint as a decimal value.
*/
float fpl_waypoint_lat(flightplan_waypoint *);
/*
* NAME fpl_waypoint_lon()
*
* DESCRIPTION
*
* Return the longitude for this waypoint as a decimal value.
*/
float fpl_waypoint_lon(flightplan_waypoint *);
/*
* NAME fpl_waypoint_type()
*
* DESCRIPTION
*
* Returns the type of this waypoint.
*/
flightplan_waypoint_type fpl_waypoint_type(flightplan_waypoint *);
/*
* NAME fpl_waypoint_type_str()
*
* DESCRIPTION
*
* Convert a waypoint type to a string value.
*/
char *fpl_waypoint_type_str(flightplan_waypoint_type);
/**************************************************************************
* Route
*************************************************************************/
typedef void flightplan_route_point;
typedef void flightplan_route_point_iter;
/*
* NAME fpl_route_name()
*
* DESCRIPTION
*
* The name of the route.
*/
char *fpl_route_name(flightplan *);
/*
* NAME fpl_route_points_count()
*
* DESCRIPTION
*
* Returns the total number of route points that are in this flight plan.
*/
int fpl_route_points_count(flightplan *);
/*
* NAME fpl_route_points_get()
*
* DESCRIPTION
*
* Returns the route point at the given index in the route. index must be
* greater than 0 and less than fpl_route_points_count().
*/
flightplan_route_point *fpl_route_points_get(flightplan *, int);
/*
* NAME fpl_route_point_identifier()
*
* DESCRIPTION
*
* Returns the identifier of this route point. This should match a waypoint
* in the flight plan if it is validly formed.
*/
char *fpl_route_point_identifier(flightplan_route_point *);
#ifdef __cplusplus
}
#endif
#endif