gps.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 The Android Open Source Project
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef _HARDWARE_GPS_H
00018 #define _HARDWARE_GPS_H
00019 
00020 #include <stdint.h>
00021 
00022 #if __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 /** Milliseconds since January 1, 1970 */
00027 typedef int64_t GpsUtcTime;
00028 
00029 /** Maximum number of SVs for gps_sv_status_callback(). */
00030 #define GPS_MAX_SVS 32
00031 
00032 /** Requested mode for GPS operation. */
00033 typedef uint16_t GpsPositionMode;
00034 // IMPORTANT: Note that the following values must match
00035 // constants in GpsLocationProvider.java.
00036 /** Mode for running GPS standalone (no assistance). */
00037 #define GPS_POSITION_MODE_STANDALONE    0
00038 /** SUPL MS-Based mode. */
00039 #define GPS_POSITION_MODE_MS_BASED      1
00040 /** SUPL MS-Assisted mode. */
00041 #define GPS_POSITION_MODE_MS_ASSISTED   2
00042 
00043 /** GPS status event values. */
00044 typedef uint16_t GpsStatusValue;
00045 // IMPORTANT: Note that the following values must match
00046 // constants in GpsLocationProvider.java.
00047 /** GPS status unknown. */
00048 #define GPS_STATUS_NONE             0
00049 /** GPS has begun navigating. */
00050 #define GPS_STATUS_SESSION_BEGIN    1
00051 /** GPS has stopped navigating. */
00052 #define GPS_STATUS_SESSION_END      2
00053 /** GPS has powered on but is not navigating. */
00054 #define GPS_STATUS_ENGINE_ON        3
00055 /** GPS is powered off. */
00056 #define GPS_STATUS_ENGINE_OFF       4
00057 
00058 /** Flags to indicate which values are valid in a GpsLocation. */
00059 typedef uint16_t GpsLocationFlags;
00060 // IMPORTANT: Note that the following values must match
00061 // constants in GpsLocationProvider.java.
00062 /** GpsLocation has valid latitude and longitude. */
00063 #define GPS_LOCATION_HAS_LAT_LONG   0x0001
00064 /** GpsLocation has valid altitude. */
00065 #define GPS_LOCATION_HAS_ALTITUDE   0x0002
00066 /** GpsLocation has valid speed. */
00067 #define GPS_LOCATION_HAS_SPEED      0x0004
00068 /** GpsLocation has valid bearing. */
00069 #define GPS_LOCATION_HAS_BEARING    0x0008
00070 /** GpsLocation has valid accuracy. */
00071 #define GPS_LOCATION_HAS_ACCURACY   0x0010
00072 
00073 /** Flags used to specify which aiding data to delete
00074     when calling delete_aiding_data(). */
00075 typedef uint16_t GpsAidingData;
00076 // IMPORTANT: Note that the following values must match
00077 // constants in GpsLocationProvider.java.
00078 #define GPS_DELETE_EPHEMERIS        0x0001
00079 #define GPS_DELETE_ALMANAC          0x0002
00080 #define GPS_DELETE_POSITION         0x0004
00081 #define GPS_DELETE_TIME             0x0008
00082 #define GPS_DELETE_IONO             0x0010
00083 #define GPS_DELETE_UTC              0x0020
00084 #define GPS_DELETE_HEALTH           0x0040
00085 #define GPS_DELETE_SVDIR            0x0080
00086 #define GPS_DELETE_SVSTEER          0x0100
00087 #define GPS_DELETE_SADATA           0x0200
00088 #define GPS_DELETE_RTI              0x0400
00089 #define GPS_DELETE_CELLDB_INFO      0x8000
00090 #define GPS_DELETE_ALL              0xFFFF
00091 
00092 /**
00093  * Name for the GPS XTRA interface.
00094  */
00095 #define GPS_XTRA_INTERFACE      "gps-xtra"
00096 
00097 /**
00098  * Name for the GPS SUPL interface.
00099  */
00100 #define GPS_SUPL_INTERFACE      "gps-supl"
00101 
00102 /** Represents a location. */
00103 typedef struct {
00104     /** Contains GpsLocationFlags bits. */
00105     uint16_t        flags;
00106     /** Represents latitude in degrees. */
00107     double          latitude;
00108     /** Represents longitude in degrees. */
00109     double          longitude;
00110     /** Represents altitude in meters above the WGS 84 reference
00111      * ellipsoid. */
00112     double          altitude;
00113     /** Represents speed in meters per second. */
00114     float           speed;
00115     /** Represents heading in degrees. */
00116     float           bearing;
00117     /** Represents expected accuracy in meters. */
00118     float           accuracy;
00119     /** Timestamp for the location fix. */
00120     GpsUtcTime      timestamp;
00121 } GpsLocation;
00122 
00123 /** Represents the status. */
00124 typedef struct {
00125     GpsStatusValue status;
00126 } GpsStatus;
00127 
00128 /** Represents SV information. */
00129 typedef struct {
00130     /** Pseudo-random number for the SV. */
00131     int     prn;
00132     /** Signal to noise ratio. */
00133     float   snr;
00134     /** Elevation of SV in degrees. */
00135     float   elevation;
00136     /** Azimuth of SV in degrees. */
00137     float   azimuth;
00138 } GpsSvInfo;
00139 
00140 /** Represents SV status. */
00141 typedef struct {
00142         /** Number of SVs currently visible. */
00143         int         num_svs;
00144 
00145         /** Contains an array of SV information. */
00146         GpsSvInfo   sv_list[GPS_MAX_SVS];
00147 
00148         /** Represents a bit mask indicating which SVs
00149          * have ephemeris data.
00150          */
00151         uint32_t    ephemeris_mask;
00152 
00153         /** Represents a bit mask indicating which SVs
00154          * have almanac data.
00155          */
00156         uint32_t    almanac_mask;
00157 
00158         /**
00159          * Represents a bit mask indicating which SVs
00160          * were used for computing the most recent position fix.
00161          */
00162         uint32_t    used_in_fix_mask;
00163 } GpsSvStatus;
00164 
00165 /** Callback with location information. */
00166 typedef void (* gps_location_callback)(GpsLocation* location);
00167 
00168 /** Callback with status information. */
00169 typedef void (* gps_status_callback)(GpsStatus* status);
00170 
00171 /** Callback with SV status information. */
00172 typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
00173 
00174 /** GPS callback structure. */
00175 typedef struct {
00176         gps_location_callback location_cb;
00177         gps_status_callback status_cb;
00178         gps_sv_status_callback sv_status_cb;
00179 } GpsCallbacks;
00180 
00181 
00182 /** Represents the standard GPS interface. */
00183 typedef struct {
00184     /**
00185      * Opens the interface and provides the callback routines
00186      * to the implemenation of this interface.
00187      */
00188     int   (*init)( GpsCallbacks* callbacks );
00189 
00190     /** Starts navigating. */
00191     int   (*start)( void );
00192 
00193     /** Stops navigating. */
00194     int   (*stop)( void );
00195 
00196     /** Sets requested frequency of fixes in seconds. */
00197     void  (*set_fix_frequency)( int frequency );
00198 
00199     /** Closes the interface. */
00200     void  (*cleanup)( void );
00201 
00202     /** Injects the current time. */
00203     int   (*inject_time)(GpsUtcTime time, int64_t timeReference,
00204                          int uncertainty);
00205 
00206     /**
00207      * Specifies that the next call to start will not use the
00208      * information defined in the flags. GPS_DELETE_ALL is passed for
00209      * a cold start.
00210      */
00211     void  (*delete_aiding_data)(GpsAidingData flags);
00212 
00213     /**
00214      * fix_frequency represents the time between fixes in seconds.
00215      * Set fix_frequency to zero for a single-shot fix.
00216      */
00217     int   (*set_position_mode)(GpsPositionMode mode, int fix_frequency);
00218 
00219     /** Get a pointer to extension information. */
00220     const void* (*get_extension)(const char* name);
00221 } GpsInterface;
00222 
00223 /** Callback to request the client to download XTRA data.
00224     The client should download XTRA data and inject it by calling
00225      inject_xtra_data(). */
00226 typedef void (* gps_xtra_download_request)();
00227 
00228 /** Callback structure for the XTRA interface. */
00229 typedef struct {
00230         gps_xtra_download_request download_request_cb;
00231 } GpsXtraCallbacks;
00232 
00233 /** Extended interface for XTRA support. */
00234 typedef struct {
00235     /**
00236      * Opens the XTRA interface and provides the callback routines
00237      * to the implemenation of this interface.
00238      */
00239     int  (*init)( GpsXtraCallbacks* callbacks );
00240     /** Injects XTRA data into the GPS. */
00241     int  (*inject_xtra_data)( char* data, int length );
00242 } GpsXtraInterface;
00243 
00244 /** Extended interface for SUPL support. */
00245 typedef struct {
00246     /**
00247      * Sets the name of the APN to be used for SUPL.
00248      */
00249     int  (*set_apn)( const char* apn );
00250 } GpsSuplInterface;
00251 
00252 /** Returns the hardware GPS interface. */
00253 const GpsInterface* gps_get_hardware_interface();
00254 
00255 /**
00256  * Returns the qemu emulated GPS interface.
00257  */
00258 const GpsInterface* gps_get_qemu_interface();
00259 
00260 /**
00261  * Returns the default GPS interface.
00262  */
00263 const GpsInterface* gps_get_interface();
00264 
00265 #if __cplusplus
00266 }  // extern "C"
00267 #endif
00268 
00269 #endif  // _HARDWARE_GPS_H