Main Page | Alphabetical List | Data Structures | File List | Globals | Related Pages

gpsutil.c File Reference

Utilities for GPilotS. More...

#include <PalmOS.h>
#include <CharAttr.h>
#include <stdio.h>
#include "MathLib.h"
#include "Garmin.h"
#include "types.h"
#include "log.h"
#include "gpsutil.h"
#include <TxtGlue.h>

Defines

#define min(a, b)   (((a) < (b)) ? (a) : (b))
#define TxtGlueCharIsDigit(c)   (((c)<='9') && ((c)>='0'))

Functions

void DebugPrintf (char *formatStr,...)
 Internal use.

void SetMathLibRef (UInt16 ref)
void StrNCatSafe (char *dstp, char *srcp, UInt16 dstsize, UInt16 srcsize)
 Concatenation of a string and a char array.

char * StrNCopySafe (char *dstp, char *srcp, UInt16 dstsize)
 Copy at most dstsize-1 bytes from source to destination string.

void StrNToField (char *str, UInt16 length, UInt16 fieldid)
 copy a char array into a field, replacing the text handle of the field.

void DrawCharsInWidth (char *string, Int16 x, Int16 y, UInt16 w, Boolean RightAligned)
 Draws a string at given place and width.

void Canonicalize (char *p, UInt16 l)
 Canonization of a string (all upper case, no non-alphanum,...).

void * GetObjPtr (UInt16 ObjID)
 Get object form pointer from object ID.

void HideObject (UInt16 objID)
 Hides given object in current form.

void ShowObject (UInt16 objID)
 Show given object in current form.

void SetControlValue (UInt16 objID, short value)
 Set a control's values.

short GetControlValue (UInt16 objID)
 Get a control's (push button or check box) state.

void GetObjectBounds (UInt16 objID, RectanglePtr rp)
 Get an object's bounds.

Int16 RecIdToPosition (DmOpenRef DB, UInt16 category, UInt32 recid, UInt16 *indexp)
 Returns a record position in it's category and index given it's ID (avoids DmFindRecordByID pitfalls).

UInt32 GetRecordID (DmOpenRef DB, UInt16 index)
 Get unique ID of a record given it's index.

char * DToA (double x, UInt16 digits, UInt16 precision)
 Conversion of a double to a string (fixed precision) of the form [-]ddd.ffff.

double StrToD (char *p, char **endp)
 Conversion ascii floating point number ([+-]M[M...][.F[F...]][+-]eX[X]) to double.

double ReadCoord (char *string, Boolean *longitude)
 Converts ASCII coordinate to double.

char * DegreToChars (double coord, Boolean longitude, DisplayFormat DisplayMode)
 Converts coordinate to string in current format (specified in DisplayMode).

char * DegreToDM (double coord, Boolean longitude, Boolean nmea)
 Conversion of coordinate in degrees to ascii format [D]DD°MM.fff'L or [D]DDMM.fff,L if nmea.

char * DegreToDMS (double coord, Boolean longitude)
 degrees to string [D]DD°MM'SS.S"L

char * DegreToD (double coord, Boolean longitude)
 degrees to string [D]DD.DDDDD°L

void DegreToSemi (double latitude, double longitude, Semicircle_Type *p)
 conversion of degree coordinates to Semicircle_Type

void SemiToDegre (Semicircle_Type *p, double *latitude, double *longitude)
 Conversion of coordinates from Semicircle_Type to degree.

void DistBearToSemi (double dist, UInt16 bearing, Semicircle_Type *p)
 Computes Semicircle_Type coordinates from distance and bearing from a given point.

UInt16 Bearing (long slat1, long slon1, long slat2, long slon2)
 Bearing of point 2 from point 1.

Int16 DistComp (long lat1, long lon1, long lat2, long lon2, long reflat, long reflon)
 Distance comparison of two points against a reference point.

double Distance (long lat1, long lon1, long lat2, long lon2, DistanceUnit unit)
 Computes distance between two points given their coordinates.

double PDistance (long lat1, long lon1, long lat2, long lon2)
 Pseudo distance between 2 points.

void GpsutilSetDebugLevel (UInt16 debuglevel, LogProcPtr logprocp)
 Sets the debugging level (no effect if compiled without DEBUG).

Boolean WptHit (Custom_Wpt_Type *wptp, Semicircle_Type *position)
 Test if position is inside waypoint's proximity distance.


Variables

char rcsid [] = "$Id: gpsutil.c,v 1.11 2004/11/17 21:15:01 clavelei Exp $"
int DebugLevel
int DebugIndentLevel
LogProcPtr LogOutput


Detailed Description

Utilities for GPilotS.

Author:
C. Claveleira
Date:
1999-2004

Function Documentation

UInt16 Bearing long  slat1,
long  slon1,
long  slat2,
long  slon2
 

Bearing of point 2 from point 1.

Parameters:
slat1 latitude of point 1
slon1 longitude of point 1
slat2 latitude of point 2
slon2 longitude of point 2
Returns:
bearing in degrees

void Canonicalize char *  p,
UInt16  l
 

Canonization of a string (all upper case, no non-alphanum,...).

Parameters:
p string to canonicalise
l length of string
Returns:
nothing

void DebugPrintf char *  formatStr,
... 
 

Internal use.

Writes "printf" formatted messages to debug log

Parameters:
formatStr Pointer to the format specification string
... parameters
Returns:
nothing

char* DegreToChars double  coord,
Boolean  longitude,
DisplayFormat  DisplayMode
 

Converts coordinate to string in current format (specified in DisplayMode).

Parameters:
coord coordinate in degrees
longitude true indicates coordinate is a longitude
DisplayMode display format wanted
Returns:
converted string

char* DegreToD double  coord,
Boolean  longitude
 

degrees to string [D]DD.DDDDD°L

Parameters:
coord coordinate in degrees
longitude true indicates coord is a longitude
Returns:
result string

char* DegreToDM double  coord,
Boolean  longitude,
Boolean  nmea
 

Conversion of coordinate in degrees to ascii format [D]DD°MM.fff'L or [D]DDMM.fff,L if nmea.

Parameters:
coord coordinate in degrees
longitude true if longitude coordinate
nmea true if nmea format wanted
Returns:
pointer on resulting string

char* DegreToDMS double  coord,
Boolean  longitude
 

degrees to string [D]DD°MM'SS.S"L

Parameters:
coord coordinate in degrees
longitude true indicates coord is a longitude
Returns:
result string

void DegreToSemi double  latitude,
double  longitude,
Semicircle_Type *  p
 

conversion of degree coordinates to Semicircle_Type

Parameters:
latitude latitude in degrees
longitude longitude in degrees
p pointer to store the result
Returns:
nothing

double Distance long  lat1,
long  lon1,
long  lat2,
long  lon2,
DistanceUnit  unit
 

Computes distance between two points given their coordinates.

Parameters:
lat1 latitude WGS84 of point 1
lon1 longitude WGS84 of point 1
lat2 latitude WGS84 of point 2
lon2 longitude WGS84 of point 2
unit unit wanted
Returns:
distance in km, nm or mi

void DistBearToSemi double  dist,
UInt16  bearing,
Semicircle_Type *  p
 

Computes Semicircle_Type coordinates from distance and bearing from a given point.

Parameters:
dist distance in nm
bearing bearing in degrees
p address of origin then result coordinates
Returns:
nothing

Int16 DistComp long  lat1,
long  lon1,
long  lat2,
long  lon2,
long  reflat,
long  reflon
 

Distance comparison of two points against a reference point.

Parameters:
lat1 latitude of first point
lon1 longitude of first point
lat2 latitude of second point
lon2 longitude of second point
reflat latitude of reference point
reflon longitude of reference point
Returns:
-1, 0 or 1

void DrawCharsInWidth char *  string,
Int16  x,
Int16  y,
UInt16  w,
Boolean  RightAligned
 

Draws a string at given place and width.

If the string don't fit in given width an ellipsis is drawn (...) at the end.

Parameters:
string string to draw
x left coordinate to start
y top coordinate to start
w max width to draw into
RightAligned the string is right aligned if true, left aligned otherwise
Returns:
nothing

char* DToA double  x,
UInt16  digits,
UInt16  precision
 

Conversion of a double to a string (fixed precision) of the form [-]ddd.ffff.

Parameters:
x value to convert (we suppose x < 1e9)
digits number of digits of integer part (ddd), negative sign included. Must be <=9. Exemple : x=-34, digits=3 => "-34." If digits is 0 the necessary number of digits is returned.
precision number of digits of fractional part (ffff). Must be <=9
Returns:
the string containing value converted

short GetControlValue UInt16  objID  ) 
 

Get a control's (push button or check box) state.

Parameters:
objID id of the control
Returns:
the state of the control

void GetObjectBounds UInt16  objID,
RectanglePtr  rp
 

Get an object's bounds.

Parameters:
objID object's ID in the form
rp pointer on a RectangleType struct to store bounds into
Returns:
nothing

void* GetObjPtr UInt16  ObjID  ) 
 

Get object form pointer from object ID.

Parameters:
ObjID object id
Returns:
pointer on form object

UInt32 GetRecordID DmOpenRef  DB,
UInt16  index
 

Get unique ID of a record given it's index.

Parameters:
DB reference to data base to search
index index of the record
Returns:
UID of the record or 0 if record not found and OS not crashed

void GpsutilSetDebugLevel UInt16  debuglevel,
LogProcPtr  logprocp
 

Sets the debugging level (no effect if compiled without DEBUG).

Parameters:
debuglevel level of debugging (see values near top of nokialib.c)
logprocp procedure to call to log traces
Returns:
nothing

void HideObject UInt16  objID  ) 
 

Hides given object in current form.

Parameters:
objID object index to hide
Returns:
nothing

double PDistance long  lat1,
long  lon1,
long  lat2,
long  lon2
 

Pseudo distance between 2 points.

This is approximate but fast !

Parameters:
lat1 latitude of first point
lon1 longitute of first point
lat2 latitude of second point
lon2 longitute of second point
Returns:
pseudo-distance

double ReadCoord char *  string,
Boolean *  longitude
 

Converts ASCII coordinate to double.

Any format (D.DD, DM.MM, DMS) is accepted.

Parameters:
string pointer on coordinates
longitude pointer on boolean set to true if it's a longitude coordinate, false otherwise. If no indication in string, value passed is used.
Returns:
coordinate if conversion ok, BadCoordinate otherwise

Int16 RecIdToPosition DmOpenRef  DB,
UInt16  category,
UInt32  recid,
UInt16 *  indexp
 

Returns a record position in it's category and index given it's ID (avoids DmFindRecordByID pitfalls).

Parameters:
DB data base to search
category category to search into
recid id of record to search
indexp pointer on index to return if found, unchanged otherwise. May be null
Returns:
position value if found (and *indexp updated), -1 otherwise

void SemiToDegre Semicircle_Type *  p,
double *  latitude,
double *  longitude
 

Conversion of coordinates from Semicircle_Type to degree.

Parameters:
p address of source coordinate
latitude pointer to store latitude
longitude pointer to store longitude
Returns:
nothing

void SetControlValue UInt16  objID,
short  value
 

Set a control's values.

Parameters:
objID id of the control
value value to set
Returns:
nothing

void ShowObject UInt16  objID  ) 
 

Show given object in current form.

Parameters:
objID object index to show
Returns:
nothing

void StrNCatSafe char *  dstp,
char *  srcp,
UInt16  dstsize,
UInt16  srcsize
 

Concatenation of a string and a char array.

The array don't need to be null terminated and, in all cases, the resulting string is null terminated (contrary to StrNCat)

Parameters:
dstp null terminated destination string
srcp source string/array to catenate to dstp
dstsize allocated size of the destination string
srcsize number of chars to copy
Returns:
nothing

char* StrNCopySafe char *  dstp,
char *  srcp,
UInt16  dstsize
 

Copy at most dstsize-1 bytes from source to destination string.

Ensures that the destination string is null terminated (dstsize'th byte is 0) except if dstsize=0

Parameters:
dstp pointer on destination string
srcp pointer on source string
dstsize size to fill (including null)
Returns:
addr of next char after last char copied

void StrNToField char *  str,
UInt16  length,
UInt16  fieldid
 

copy a char array into a field, replacing the text handle of the field.

Parameters:
str string to put in the field (not necessarily terminated by 0)
length number of bytes to copy
fieldid id of the field
Returns:
nothing

double StrToD char *  p,
char **  endp
 

Conversion ascii floating point number ([+-]M[M...][.F[F...]][+-]eX[X]) to double.

Parameters:
p string to parse
endp si non null address of a pointer to store where the conversion has stopped
Returns:
result of conversion

Boolean WptHit Custom_Wpt_Type wptp,
Semicircle_Type *  position
 

Test if position is inside waypoint's proximity distance.

Parameters:
wptp pointer on a Custom_Wpt_Type waypoint
position pointer on a position
Returns:
true if position is inside proximity circle, flase otherwise


Generated on Sun Mar 13 09:36:01 2005 for GPilotS by doxygen 1.3.6