// GlobalMapperInterface_GPS.h - interface for Global Mapper DLL GPS-related exports
//
// Developed by: Mike Childs
//      Started: 6/4/05

#ifndef _GLOBALMAPPERINTERFACE_GPS_H_
#define _GLOBALMAPPERINTERFACE_GPS_H_

/*--------------------------------------------------------------------
                            GENERAL INCLUDES
--------------------------------------------------------------------*/

#include "GlobalMapperInterface.h"

// Make sure the whole thing is packed to 8 byte structure alignment
// like the SDK expects
#pragma pack( push, 8 )

/*--------------------------------------------------------------------
                            LITERAL CONSTANTS
--------------------------------------------------------------------*/

/*--------------------------------------------------------------------
                                 TYPES
--------------------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif

// GPS fix type
typedef uint8 GM_gps_fix_t8; enum
    {
    GM_GPS_FIX_NO_SOLN,             // No GPS solution is available
    GM_GPS_FIX_2D,                  // a 2-dimensional fix is available
    GM_GPS_FIX_3D,                  // a 3-dimensional fix is available
    GM_GPS_FIX_2D_DIFF,             // a 2-dimensional differential or WAAS fix is available
    GM_GPS_FIX_3D_DIFF,             // a 3-dimensional differential or WAAS fix is available

    GM_GPS_NUM_FIX_TYPES
    };

// Format for GPS connection
typedef uint8 GM_gps_format_t8; enum
	{
	GM_GPS_FORMAT_AUTODETECT,
	GM_GPS_FORMAT_NMEA,
	GM_GPS_FORMAT_GARMIN,

    GM_GPS_NUM_FORMAT_TYPES
	};

// GPS event notification enumeration
typedef uint32 GM_gps_event_t32; enum
    {
    GM_GPS_EVENT_NEW_POS,       // a new location is available (event data is GM_Point_t* with current lat/lon)
    GM_GPS_EVENT_STATE_CHANGED, // the GPS state has changed

    GM_GPS_NUM_EVENTS
    };

// Callback for being notified of GPS status changes.
typedef void (_stdcall *GM_GPSCallbackFunc)
    ( 
    GM_gps_event_t32    aEvent,
    void*               aEventData
    );

/*--------------------------------------------------------------------
                        GPS RENDERING FUNCTIONS
--------------------------------------------------------------------*/

// Renders a GPS vessel of the given size to the provided device context
// at the current GPS location.
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSRenderVessel
    (
    HDC                     aDC,            // Device context to draw to
    const GM_Rectangle_t*   aWorldBounds,   // IN: World bounds to convert from or NULL for last drawn
    const GM_PixelRect_t*   aPixelRect,     // IN: Pixel bounds to convert from or NULL for last drawn 
    uint32                  aVesselHeight,  // IN: The vessel height in pixels
    uint32                  aVesselWidth,   // IN: The vessel width in pixels
    COLORREF                aVesselColor    // IN: The color to render the vessel in
    );

/*--------------------------------------------------------------------
                          GPS SETUP FUNCTIONS
--------------------------------------------------------------------*/

// Starts tracking a GPS device connected to a serial port
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSStartTrackingSerial
    ( 
    GM_gps_format_t8        aFormat,        // format (NMEA or Garmin)
    uint8                   aPort,          // COM port for serial connections
    uint32                  aBaud,          // baud rate for serial port
    GM_GPSCallbackFunc      aCallbackFunc,  // optional callback function
    uint32                  aReserved       // 32-bit reserved value (must be 0)
    );

// Starts tracking a GPS device connected to a USB port
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSStartTrackingUSB
    ( 
    GM_GPSCallbackFunc      aCallbackFunc,  // optional callback function
    uint32                  aReserved       // 32-bit reserved value (must be 0)
    );

// Stops tracking any connected GPS device
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSStopTracking
    (
    void
    );

/*--------------------------------------------------------------------
                       GPS STATE QUERY FUNCTIONS
--------------------------------------------------------------------*/

// Retrieves the current GPS altitude, if valid
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSGetAltitude
    (
    float*                  aAltitude       // out: current GPS altitude in meters
    );

// Retrieves the current GPS bearing, if valid
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSGetBearing
    (
    float*                  aBearing        // out: current GPS bearing in radians from due north
    );

// Retrieves the current GPS fix accuracy statistics
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSGetFixInfo
    (
    float*                  aHorzPosError,  // out: current horizontal position error in meters (0.0 if unknown)
    float*                  aVertPosError,  // out: current vertical position error in meters (0.0 if unknown)
    float*                  aPDOP,          // out: current position DOP in meters (0.0 if unknown)
    uint32*                 aNumSats        // out: number of satellites used in fix (0 if unknown)
    );

// Retrieves the current GPS fix type
GM_DLL_EXPORTED GM_gps_fix_t8 __stdcall GM_GPSGetFixType
    (
    void
    );

// Retrieves the current GPS location
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSGetLocation
    (
    GM_Point_t*             aCurPos,        // out: current GPS location
    boolean                 aGetLatLon      // in: retrieve coordinates in lat/lon/WGS84 rather than global coords
    );

// Retrieves the current GPS velocity, if valid
GM_DLL_EXPORTED GM_Error_t32 __stdcall GM_GPSGetVelocity
    (
    float*                  aVelocity       // out: current GPS velocity in m/s
    );

// Restore structure alignment to its old value
#pragma pack( pop )

#ifdef __cplusplus
}
#endif

#endif // end of file GlobalMapperInterface_GPS.h