-
Notifications
You must be signed in to change notification settings - Fork 0
/
soarGraph.c
399 lines (347 loc) · 16.7 KB
/
soarGraph.c
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#include <PalmOS.h>
#include "soaring.h"
#include "soarDB.h"
#include "soarUtil.h"
#include "soarGraph.h"
#include "soarUGraph.h"
#include "soarWind.h"
#include "soarMem.h"
void DrawAltTimeGraph(Int16 fltindex, UInt8 graphtype)
{
Graph_t *appgr;
Graph_t *appgr2;
DateTimeType strtdt, stopdt;
UInt32 startsecs, stopsecs, lengthsecs;
UInt32 prevsecs=0;
UInt32 graphsecs=0;
UInt32 maxscalevalue=0;
UInt32 minscalevalue=0;
double prevalt=0.0;
double prevterelev=0.0;
MemHandle output_hand;
MemPtr output_ptr;
FlightData *fltdata;
Int32 recindex;
LoggerData *logdata;
Boolean firsttime=true;
Char tempchar[10];
Coord ulX, ulY, widthX, heightY;
Boolean altlabeldrawn = false;
Int16 prevtaskleg = -1;
Int16 prevhour = -1;
Int16 prevtasklegsecs = -1;
if(graphtype == 0) {
ulX = 5;
ulY = 25;
widthX = 150;
heightY = 100;
AllocMem((void *)&fltdata, sizeof(FlightData));
AllocMem((void *)&logdata, sizeof(LoggerData));
AllocMem((void *)&appgr, sizeof(Graph_t));
AllocMem((void *)&appgr2, sizeof(Graph_t));
//must call this. This initializes the variables in the graph and ensures
//there are no spurious values. The values of initialization can be changed
//by changing respective values in the grlib.h header files
grLibInitializeGraphStruct(appgr);
grLibInitializeGraphStruct(appgr2);
OpenDBQueryRecord(flight_db, fltindex, &output_hand, &output_ptr);
MemMove(fltdata,output_ptr,sizeof(FlightData));
MemHandleUnlock(output_hand);
// Copy the flight start and stop DTG(MMDDYY) into the Start & Stop DateTime Structure
// Copy the flight start and stop UTC(HHMMSS) into the Start & Stop DateTime Structure
StringToDateAndTime(fltdata->startdtg, fltdata->startutc, &strtdt);
StringToDateAndTime(fltdata->stopdtg, fltdata->stoputc, &stopdt);
// Get the start and stop times converted into seconds
startsecs = TimDateTimeToSeconds(&strtdt);
stopsecs = TimDateTimeToSeconds(&stopdt);
// Calculate flt length
if (startsecs > stopsecs) lengthsecs = 0; else lengthsecs=stopsecs-startsecs;
//set the graph perimeters and the Type (LINE or LINE_FILL) and specify if draw in
//color or not
grLibSetGraphParams(appgr, ulX, ulY, widthX, heightY, LINE, device.colorCapable);
grLibSetGraphParams(appgr2, ulX, ulY, widthX, heightY, LINE_FILL_HASH, device.colorCapable);
// grLibSetGraphParams(appgr2, ulX, ulY, widthX, heightY, LINE, device.colorCapable);
maxscalevalue = (UInt32)(pround(fltdata->maxalt*data.input.altconst, 0));
if (maxscalevalue < 10) {
maxscalevalue = 10;
} else if (maxscalevalue < 100) {
maxscalevalue = 100;
} else if (maxscalevalue < 1000) {
maxscalevalue = ((maxscalevalue / 100) + 1) * 100;
} else if (maxscalevalue < 10000) {
maxscalevalue = ((maxscalevalue / 1000) + 1) * 1000;
} else if (maxscalevalue < 100000) {
maxscalevalue = ((maxscalevalue / 10000) + 1) * 10000;
}
minscalevalue = (UInt32)(pround(fltdata->minalt*data.input.altconst, 0));
//specify the scales (max and min X and Y) - these are the data ranges
grLibSetMaxMinScales(appgr, 0, 0, lengthsecs, maxscalevalue);
grLibSetMaxMinScales(appgr2, 0, 0, lengthsecs, maxscalevalue);
// grLibSetMaxMinScales(&appgr, 0, minscalevalue, lengthsecs, maxscalevalue);
//draw an outer frame for the graph. This routine will use the frame
//parameters set in grLibSetGraphParams
grLibDrawGraphFrame(appgr,FRAME);
grLibDrawGraphGrids(appgr,YGRID,YTEXT,5);
for (recindex = fltdata->startidx; recindex < fltdata->stopidx; recindex++) {
OpenDBQueryRecord(logger_db, recindex, &output_hand, &output_ptr);
MemMove(logdata, output_ptr, sizeof(LoggerData));
MemHandleUnlock(output_hand);
// Copy the current data points DTG(MMDDYY) into the Start & Stop DateTime Structure
// Copy the Stop time UTC (HHMMSS) into the Stop DateTime Structure
StringToDateAndTime(logdata->gpsdtg, logdata->gpsutc, &stopdt);
graphsecs=TimDateTimeToSeconds(&stopdt) - startsecs;
if (firsttime) {
// Output the start time with seconds
SecondsToDateOrTimeString(startsecs, tempchar, 1, (Int32)data.config.timezone);
grLibDrawGraphText(appgr, graphsecs, 12, 0, -2, "|");
grLibDrawGraphText(appgr, graphsecs, 12, 0, 7, "|");
grLibDrawGraphText(appgr, graphsecs, 0, -4, 15, tempchar);
prevtaskleg = logdata->taskleg;
prevhour = (Int16)((graphsecs+startsecs)/3600);
prevtasklegsecs = graphsecs;
} else {
appgr->numDataPts = 0;
appgr2->numDataPts = 0;
if ((Int16)((graphsecs+startsecs)/3600) > prevhour) {
// draw tick marks at hourly intervals
grLibDrawGraphText(appgr, graphsecs, 12, 0, -2, "|");
prevhour = (Int16)((graphsecs+startsecs)/3600);
}
if (logdata->taskleg != prevtaskleg) {
// draw line for task leg change
grLibInputGraphData(appgr, prevsecs, minscalevalue, 0, NULL);
grLibInputGraphData(appgr, graphsecs, maxscalevalue, 0, NULL);
if (prevtaskleg >= 0) {
// label task leg
grLibDrawGraphText(appgr, (graphsecs+prevtasklegsecs)/2, 12, -2, -10, DblToStr(prevtaskleg,0));
}
prevtaskleg = logdata->taskleg;
prevtasklegsecs = graphsecs;
} else {
// draw normal altitude
grLibInputGraphData(appgr, prevsecs,(UInt32)(pround(prevalt*data.input.altconst, 0)), 0, NULL);
grLibInputGraphData(appgr, graphsecs, (UInt32)(pround(logdata->gpsalt*data.input.altconst, 0)), 0, NULL);
// grLibInputGraphData(appgr, graphsecs, (UInt32)(pround(logdata->pressalt*data.input.altconst, 0)), 0, NULL);
}
// draw ground
grLibInputGraphData(appgr2, prevsecs, (UInt32)(pround(prevterelev*data.input.altconst, 0)), 0, NULL);
grLibInputGraphData(appgr2, graphsecs, (UInt32)(pround(logdata->terelev*data.input.altconst, 0)), 0, NULL);
if (logdata->gpsalt >= fltdata->maxalt && altlabeldrawn == false) {
// Output the max altitude when it is reached
grLibDrawGraphText(appgr, graphsecs, (UInt32)(pround(logdata->gpsalt*data.input.altconst, 0)), 5, -10, print_altitude(fltdata->maxalt));
// grLibDrawGraphText(appgr, graphsecs, (UInt32)(pround(logdata->pressalt*data.input.altconst, 0)), 5, -10, print_altitude(fltdata->maxalt));
altlabeldrawn = true;
}
// draw the graphs
grLibDrawGraph(appgr,0);
// grLibDrawGraph(appgr,1);
grLibDrawGraph(appgr2,0);
}
firsttime = false;
prevsecs = graphsecs;
prevalt = logdata->gpsalt;
prevterelev = logdata->terelev;
}
// Output the end time
SecondsToDateOrTimeString(stopsecs, tempchar, 1, (Int32)data.config.timezone);
grLibDrawGraphText(appgr, graphsecs, 12, 0, -2, "|");
grLibDrawGraphText(appgr, graphsecs, 12, 0, 7, "|");
grLibDrawGraphText(appgr, graphsecs, 0, -30, 15, tempchar);
FreeMem((void *)&fltdata);
FreeMem((void *)&logdata);
grLibDrawGraphTitle(appgr,"Altitude vs. Time");
grLibReleaseResources(appgr);
grLibReleaseResources(appgr2);
FreeMem((void *)&appgr);
FreeMem((void *)&appgr2);
}
}
void DrawPctThermalGraph(Int16 fltindex, UInt8 graphtype)
{
Graph_t *appgr;
DateTimeType strtdt, stopdt;
UInt32 startsecs, stopsecs, lengthsecs;
UInt32 graphsecs=0;
UInt32 prevcursecs=0;
UInt32 intervalsecs = 0;
UInt32 plotsecs = 0;
UInt32 maxscalevalue=0;
UInt32 minscalevalue=0;
MemHandle output_hand;
MemPtr output_ptr;
FlightData *fltdata;
Int32 recindex;
LoggerData *logdata;
Boolean firsttime=true;
Char tempchar[10];
Coord ulX, ulY, widthX, heightY;
UInt16 thermalcount=0;
UInt32 pctthermal;
UInt16 x=1;
UInt16 plotcount=1;
UInt16 maxplotcount;
Int16 prevtaskleg=0;
Boolean taskstarted = false;
//must call this. This initializes the variables in the graph and ensures
//there are no spurious values. The values of initialization can be changed
//by changing respective values in the grlib.h header files
AllocMem((void *)&appgr, sizeof(Graph_t));
grLibInitializeGraphStruct(appgr);
ulX = 5;
ulY = 25;
widthX = 150;
heightY = 100;
AllocMem((void *)&fltdata, sizeof(FlightData));
AllocMem((void *)&logdata, sizeof(LoggerData));
OpenDBQueryRecord(flight_db, fltindex, &output_hand, &output_ptr);
MemMove(fltdata, output_ptr, sizeof(FlightData));
MemHandleUnlock(output_hand);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-fltdata->flttask.numwaypts-|%hu|", fltdata->flttask.numwaypts);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-fltdata->tskstartutc-|%s|", fltdata->tskstartutc);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-fltdata->tskstoputc-|%s|", fltdata->tskstoputc);
if (StrCompare(fltdata->tskstoputc, "NT")==0 || fltdata->flttask.numwaypts <= 0) {
// no task started so plot by time
maxplotcount = 7;
// Copy the flight start and stop DTG(MMDDYY) into the Start & Stop DateTime Structure
// Copy the flight start and stop UTC(HHMMSS) into the Start & Stop DateTime Structure
StringToDateAndTime(fltdata->startdtg, fltdata->startutc, &strtdt);
StringToDateAndTime(fltdata->stopdtg, fltdata->stoputc, &stopdt);
// Get the start and stop times converted into seconds
startsecs = TimDateTimeToSeconds(&strtdt);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-startsecs-|%lu|", startsecs);
stopsecs = TimDateTimeToSeconds(&stopdt);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-stopsecs-|%lu|", stopsecs);
// Calculate flt length
if (startsecs > stopsecs) lengthsecs = 0; else lengthsecs=stopsecs-startsecs; lengthsecs=stopsecs-startsecs;
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-lengthsecs-|%lu|", lengthsecs);
intervalsecs = lengthsecs / (UInt32)(maxplotcount - 1);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-intervalsecs-|%lu|", intervalsecs);
//set the graph perimeters and the Type (BAR, LINE, LINE_FILL, STACK) and specify if draw in
//color or not
grLibSetGraphParams(appgr,ulX, ulY, widthX, heightY, BAR, device.colorCapable);
maxscalevalue = 125;
minscalevalue = 0;
//specify the scales (max and min X and Y) - these are the data ranges
grLibSetMaxMinScales(appgr, 0, 0, (UInt32)maxplotcount, maxscalevalue);
//draw an outer frame for the graph. This routine will use the frame
//parameters set in grLibSetGraphParams
grLibDrawGraphFrame(appgr,FRAME);
grLibDrawGraphGrids(appgr,YGRID,YTEXT,5);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-startidx-|%hd|", fltdata->startidx);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-stopidx-|%hd|", fltdata->stopidx);
for (recindex = fltdata->startidx; recindex < fltdata->stopidx; recindex++) {
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-recindex-|%hd|", recindex);
OpenDBQueryRecord(logger_db, recindex, &output_hand, &output_ptr);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-OpenDBQueryRecord-|%hd|", recindex);
MemMove(logdata, output_ptr, sizeof(LoggerData));
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-MemMove");
MemHandleUnlock(output_hand);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-MemHandleUnlock");
// Copy the current data points DTG(MMDDYY) into the Start & Stop DateTime Structure
// Copy the Stop time UTC (HHMMSS) into the Stop DateTime Structure
StringToDateAndTime(logdata->gpsdtg, logdata->gpsutc, &stopdt);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-StringToDateAndTime");
graphsecs=TimDateTimeToSeconds(&stopdt) - startsecs;
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-graphsecs-|%lu|", graphsecs);
if (firsttime) {
firsttime = false;
// Output the start time with seconds
SecondsToDateOrTimeString(startsecs, tempchar, 1, (Int32)data.config.timezone);
grLibDrawGraphText(appgr, (UInt32)plotcount, 0, -10, 3, tempchar);
prevcursecs = graphsecs;
}
// If in THERMAL mode, increment the thermal posit count to allow for determining
// the thermal vs. cruise percentage
if (logdata->thermal == THERMAL) {
thermalcount++;
}
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-plotsecs-|%lu|", plotsecs);
if ((prevcursecs != graphsecs) && ((graphsecs >= plotsecs+intervalsecs) || (recindex == (fltdata->stopidx-1)))) {
plotsecs += intervalsecs;
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-x-|%hu|", x);
pctthermal = (UInt32)pround(((double)thermalcount / (double)x * 100.0), 0);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-pctthermal-|%lu|", pctthermal);
grLibInputGraphData(appgr, (UInt32)plotcount, pctthermal, 1, NULL);
if (pctthermal >= 0) {
grLibDrawGraphText(appgr, (UInt32)plotcount, pctthermal, -4, -12, StrIToA(tempchar, pctthermal));
}
thermalcount = 0;
x = 0; // x is the number of logger records being used to find the percentage
plotcount++;
// HostTraceOutputTL(appErrorClass, "=======================================");
}
x++;
prevcursecs = graphsecs;
// HostTraceOutputTL(appErrorClass, "---------------------------------------");
}
grLibDrawGraph(appgr,1);
// Output the end time
SecondsToDateOrTimeString(stopsecs, tempchar, 1, (Int32)data.config.timezone);
grLibDrawGraphText(appgr, (UInt32)plotcount, 0, -30, 3, tempchar);
grLibDrawGraphTitle(appgr,"%Thermal vs. Time");
} else {
// plot % thermal by task leg
taskstarted = false;
maxplotcount = fltdata->flttask.numwaypts;
if (fltdata->flttask.hastakeoff) maxplotcount--;
if (fltdata->flttask.haslanding) maxplotcount--;
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-taskleg-maxplotcount-|%hu|", maxplotcount);
//set the graph perimeters and the Type (BAR, LINE, LINE_FILL, STACK) and specify if draw in
//color or not
grLibSetGraphParams(appgr,ulX, ulY, widthX, heightY, BAR, device.colorCapable);
maxscalevalue = 125;
minscalevalue = 0;
//specify the scales (max and min X and Y) - these are the data ranges
grLibSetMaxMinScales(appgr, 0, 0, (UInt32)maxplotcount, maxscalevalue);
//draw an outer frame for the graph. This routine will use the frame
//parameters set in grLibSetGraphParams
grLibDrawGraphFrame(appgr,FRAME);
grLibDrawGraphGrids(appgr,YGRID,YTEXT,5);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-startidx-|%lu|", fltdata->startidx);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-stopidx-|%lu|", fltdata->stopidx);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-records-|%lu|", fltdata->stopidx-fltdata->startidx+1);
// HostTraceOutputTL(appErrorClass, "-----");
for (recindex = fltdata->startidx; recindex < fltdata->stopidx; recindex++) {
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-recindex-|%ld|", recindex);
OpenDBQueryRecord(logger_db, recindex, &output_hand, &output_ptr);
MemMove(logdata, output_ptr, sizeof(LoggerData));
MemHandleUnlock(output_hand);
if ((logdata->taskleg != -1) || (taskstarted)) {
taskstarted = true;
// If in THERMAL mode, increment the thermal posit count to allow for determining
// the thermal vs. cruise percentage
if (logdata->thermal == THERMAL) {
// if (logdata->thermal == CRUISE) {
thermalcount++;
}
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-logdata->taskleg-|%hd|", logdata->taskleg);
if (((prevtaskleg > 0) && (prevtaskleg != logdata->taskleg)) || (recindex == (fltdata->stopidx-1))) {
// HostTraceOutputTL(appErrorClass, "-");
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-prevleg -|%hu|", prevtaskleg);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-x -|%hu|", x);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-th-|%hu|", thermalcount);
pctthermal = (UInt32)pround(((double)thermalcount / (double)x * 100.0), 0);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-pctthermal-|%ld|", pctthermal);
// HostTraceOutputTL(appErrorClass, "DrawPctThermalGraph-recindex-|%ld|", recindex-fltdata->startidx);
// HostTraceOutputTL(appErrorClass, "-");
grLibInputGraphData(appgr, (UInt32)prevtaskleg, pctthermal, 0, NULL);
if (pctthermal >= 0) {
grLibDrawGraphText(appgr, (UInt32)prevtaskleg, pctthermal, -4, -12, StrIToA(tempchar, pctthermal));
grLibDrawGraphText(appgr, (UInt32)prevtaskleg, 0, 0, 3, StrIToA(tempchar, prevtaskleg));
}
thermalcount = 0;
x = 0; // x is the number of logger records being used to find the percentage
}
x++;
prevtaskleg = logdata->taskleg;
if (prevtaskleg == -1) taskstarted = false;
}
}
grLibDrawGraph(appgr,0);
grLibDrawGraphTitle(appgr,"%Thermal vs. Task Leg");
}
grLibReleaseResources(appgr);
FreeMem((void *)&fltdata);
FreeMem((void *)&logdata);
FreeMem((void *)&appgr);
}