Home | History | Annotate | Download | only in hardware_legacy
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _HARDWARE_GPS_H
     18 #define _HARDWARE_GPS_H
     19 
     20 #include <stdint.h>
     21 #include <stdlib.h>
     22 
     23 #if __cplusplus
     24 extern "C" {
     25 #endif
     26 
     27 /** Milliseconds since January 1, 1970 */
     28 typedef int64_t GpsUtcTime;
     29 
     30 /** Maximum number of SVs for gps_sv_status_callback(). */
     31 #define GPS_MAX_SVS 32
     32 
     33 /** Requested mode for GPS operation. */
     34 typedef uint16_t GpsPositionMode;
     35 // IMPORTANT: Note that the following values must match
     36 // constants in GpsLocationProvider.java.
     37 /** Mode for running GPS standalone (no assistance). */
     38 #define GPS_POSITION_MODE_STANDALONE    0
     39 /** AGPS MS-Based mode. */
     40 #define GPS_POSITION_MODE_MS_BASED      1
     41 /** AGPS MS-Assisted mode. */
     42 #define GPS_POSITION_MODE_MS_ASSISTED   2
     43 
     44 /** GPS status event values. */
     45 typedef uint16_t GpsStatusValue;
     46 // IMPORTANT: Note that the following values must match
     47 // constants in GpsLocationProvider.java.
     48 /** GPS status unknown. */
     49 #define GPS_STATUS_NONE             0
     50 /** GPS has begun navigating. */
     51 #define GPS_STATUS_SESSION_BEGIN    1
     52 /** GPS has stopped navigating. */
     53 #define GPS_STATUS_SESSION_END      2
     54 /** GPS has powered on but is not navigating. */
     55 #define GPS_STATUS_ENGINE_ON        3
     56 /** GPS is powered off. */
     57 #define GPS_STATUS_ENGINE_OFF       4
     58 
     59 /** Flags to indicate which values are valid in a GpsLocation. */
     60 typedef uint16_t GpsLocationFlags;
     61 // IMPORTANT: Note that the following values must match
     62 // constants in GpsLocationProvider.java.
     63 /** GpsLocation has valid latitude and longitude. */
     64 #define GPS_LOCATION_HAS_LAT_LONG   0x0001
     65 /** GpsLocation has valid altitude. */
     66 #define GPS_LOCATION_HAS_ALTITUDE   0x0002
     67 /** GpsLocation has valid speed. */
     68 #define GPS_LOCATION_HAS_SPEED      0x0004
     69 /** GpsLocation has valid bearing. */
     70 #define GPS_LOCATION_HAS_BEARING    0x0008
     71 /** GpsLocation has valid accuracy. */
     72 #define GPS_LOCATION_HAS_ACCURACY   0x0010
     73 
     74 /** Flags used to specify which aiding data to delete
     75     when calling delete_aiding_data(). */
     76 typedef uint16_t GpsAidingData;
     77 // IMPORTANT: Note that the following values must match
     78 // constants in GpsLocationProvider.java.
     79 #define GPS_DELETE_EPHEMERIS        0x0001
     80 #define GPS_DELETE_ALMANAC          0x0002
     81 #define GPS_DELETE_POSITION         0x0004
     82 #define GPS_DELETE_TIME             0x0008
     83 #define GPS_DELETE_IONO             0x0010
     84 #define GPS_DELETE_UTC              0x0020
     85 #define GPS_DELETE_HEALTH           0x0040
     86 #define GPS_DELETE_SVDIR            0x0080
     87 #define GPS_DELETE_SVSTEER          0x0100
     88 #define GPS_DELETE_SADATA           0x0200
     89 #define GPS_DELETE_RTI              0x0400
     90 #define GPS_DELETE_CELLDB_INFO      0x8000
     91 #define GPS_DELETE_ALL              0xFFFF
     92 
     93 /** AGPS type */
     94 typedef uint16_t AGpsType;
     95 #define AGPS_TYPE_SUPL          1
     96 #define AGPS_TYPE_C2K           2
     97 
     98 
     99 /** AGPS status event values. */
    100 typedef uint16_t AGpsStatusValue;
    101 /** GPS requests data connection for AGPS. */
    102 #define GPS_REQUEST_AGPS_DATA_CONN  1
    103 /** GPS releases the AGPS data connection. */
    104 #define GPS_RELEASE_AGPS_DATA_CONN  2
    105 /** AGPS data connection initiated */
    106 #define GPS_AGPS_DATA_CONNECTED     3
    107 /** AGPS data connection completed */
    108 #define GPS_AGPS_DATA_CONN_DONE     4
    109 /** AGPS data connection failed */
    110 #define GPS_AGPS_DATA_CONN_FAILED   5
    111 
    112 /**
    113  * Name for the GPS XTRA interface.
    114  */
    115 #define GPS_XTRA_INTERFACE      "gps-xtra"
    116 
    117 /**
    118  * Name for the GPS DEBUG interface.
    119  */
    120 #define GPS_DEBUG_INTERFACE      "gps-debug"
    121 
    122 /**
    123  * Name for the AGPS interface.
    124  */
    125 #define AGPS_INTERFACE      "agps"
    126 
    127 /**
    128  * Name for the GPS privacy interface.
    129  */
    130 #define GPS_PRIVACY_INTERFACE      "privacy"
    131 
    132 /** Represents a location. */
    133 typedef struct {
    134     /** Contains GpsLocationFlags bits. */
    135     uint16_t        flags;
    136     /** Represents latitude in degrees. */
    137     double          latitude;
    138     /** Represents longitude in degrees. */
    139     double          longitude;
    140     /** Represents altitude in meters above the WGS 84 reference
    141      * ellipsoid. */
    142     double          altitude;
    143     /** Represents speed in meters per second. */
    144     float           speed;
    145     /** Represents heading in degrees. */
    146     float           bearing;
    147     /** Represents expected accuracy in meters. */
    148     float           accuracy;
    149     /** Timestamp for the location fix. */
    150     GpsUtcTime      timestamp;
    151 } GpsLocation;
    152 
    153 /** Represents the status. */
    154 typedef struct {
    155     GpsStatusValue status;
    156 } GpsStatus;
    157 
    158 /** Represents SV information. */
    159 typedef struct {
    160     /** Pseudo-random number for the SV. */
    161     int     prn;
    162     /** Signal to noise ratio. */
    163     float   snr;
    164     /** Elevation of SV in degrees. */
    165     float   elevation;
    166     /** Azimuth of SV in degrees. */
    167     float   azimuth;
    168 } GpsSvInfo;
    169 
    170 /** Represents SV status. */
    171 typedef struct {
    172         /** Number of SVs currently visible. */
    173         int         num_svs;
    174 
    175         /** Contains an array of SV information. */
    176         GpsSvInfo   sv_list[GPS_MAX_SVS];
    177 
    178         /** Represents a bit mask indicating which SVs
    179          * have ephemeris data.
    180          */
    181         uint32_t    ephemeris_mask;
    182 
    183         /** Represents a bit mask indicating which SVs
    184          * have almanac data.
    185          */
    186         uint32_t    almanac_mask;
    187 
    188         /**
    189          * Represents a bit mask indicating which SVs
    190          * were used for computing the most recent position fix.
    191          */
    192         uint32_t    used_in_fix_mask;
    193 } GpsSvStatus;
    194 
    195 /** Callback with location information. */
    196 typedef void (* gps_location_callback)(GpsLocation* location);
    197 
    198 /** Callback with status information. */
    199 typedef void (* gps_status_callback)(GpsStatus* status);
    200 
    201 /** Callback with SV status information. */
    202 typedef void (* gps_sv_status_callback)(GpsSvStatus* sv_info);
    203 
    204 /** Callback for reporting NMEA sentences. */
    205 typedef void (* gps_nmea_callback)(GpsUtcTime timestamp, const char* nmea, int length);
    206 
    207 /** GPS callback structure. */
    208 typedef struct {
    209         gps_location_callback location_cb;
    210         gps_status_callback status_cb;
    211         gps_sv_status_callback sv_status_cb;
    212         gps_nmea_callback nmea_cb;
    213 } GpsCallbacks;
    214 
    215 
    216 /** Represents the standard GPS interface. */
    217 typedef struct {
    218     /**
    219      * Opens the interface and provides the callback routines
    220      * to the implemenation of this interface.
    221      */
    222     int   (*init)( GpsCallbacks* callbacks );
    223 
    224     /** Starts navigating. */
    225     int   (*start)( void );
    226 
    227     /** Stops navigating. */
    228     int   (*stop)( void );
    229 
    230     /** Closes the interface. */
    231     void  (*cleanup)( void );
    232 
    233     /** Injects the current time. */
    234     int   (*inject_time)(GpsUtcTime time, int64_t timeReference,
    235                          int uncertainty);
    236 
    237     /** Injects current location from another location provider
    238      *  (typically cell ID).
    239      *  latitude and longitude are measured in degrees
    240      *  expected accuracy is measured in meters
    241      */
    242     int  (*inject_location)(double latitude, double longitude, float accuracy);
    243 
    244     /**
    245      * Specifies that the next call to start will not use the
    246      * information defined in the flags. GPS_DELETE_ALL is passed for
    247      * a cold start.
    248      */
    249     void  (*delete_aiding_data)(GpsAidingData flags);
    250 
    251     /**
    252      * fix_frequency represents the time between fixes in seconds.
    253      * Set fix_frequency to zero for a single-shot fix.
    254      */
    255     int   (*set_position_mode)(GpsPositionMode mode, int fix_frequency);
    256 
    257     /** Get a pointer to extension information. */
    258     const void* (*get_extension)(const char* name);
    259 } GpsInterface;
    260 
    261 /** Callback to request the client to download XTRA data.
    262     The client should download XTRA data and inject it by calling
    263      inject_xtra_data(). */
    264 typedef void (* gps_xtra_download_request)();
    265 
    266 /** Callback structure for the XTRA interface. */
    267 typedef struct {
    268         gps_xtra_download_request download_request_cb;
    269 } GpsXtraCallbacks;
    270 
    271 /** Extended interface for XTRA support. */
    272 typedef struct {
    273     /**
    274      * Opens the XTRA interface and provides the callback routines
    275      * to the implemenation of this interface.
    276      */
    277     int  (*init)( GpsXtraCallbacks* callbacks );
    278     /** Injects XTRA data into the GPS. */
    279     int  (*inject_xtra_data)( char* data, int length );
    280 } GpsXtraInterface;
    281 
    282 /** Extended interface for DEBUG support. */
    283 typedef struct {
    284     /**
    285      * This function should return any information that the native
    286      * implementation wishes to include in a bugreport.
    287      */
    288     size_t (*get_internal_state)(char* buffer, size_t bufferSize);
    289 } GpsDebugInterface;
    290 
    291 /** Represents the status of AGPS. */
    292 typedef struct {
    293     AGpsType        type;
    294     AGpsStatusValue status;
    295 } AGpsStatus;
    296 
    297 /** Callback with AGPS status information. */
    298 typedef void (* agps_status_callback)(AGpsStatus* status);
    299 
    300 /** Callback structure for the AGPS interface. */
    301 typedef struct {
    302         agps_status_callback status_cb;
    303 } AGpsCallbacks;
    304 
    305 
    306 /** Extended interface for AGPS support. */
    307 typedef struct {
    308     /**
    309      * Opens the AGPS interface and provides the callback routines
    310      * to the implemenation of this interface.
    311      */
    312     void  (*init)( AGpsCallbacks* callbacks );
    313     /**
    314      * Notifies that a data connection is available and sets
    315      * the name of the APN to be used for SUPL.
    316      */
    317     int  (*data_conn_open)( const char* apn );
    318     /**
    319      * Notifies that the AGPS data connection has been closed.
    320      */
    321     int  (*data_conn_closed)();
    322     /**
    323      * Notifies that a data connection is not available for AGPS.
    324      */
    325     int  (*data_conn_failed)();
    326     /**
    327      * Sets the hostname and port for the AGPS server.
    328      */
    329     int  (*set_server)( AGpsType type, const char* hostname, int port );
    330 } AGpsInterface;
    331 
    332 /** Extended interface for GPS privacy support. */
    333 typedef struct {
    334     /**
    335      * Opens the AGPS interface and provides the callback routines
    336      * to the implemenation of this interface.
    337      */
    338     void  (*set_privacy_lock)( int enable_lock );
    339 } GpsPrivacyInterface;
    340 
    341 /** Returns the hardware GPS interface. */
    342 const GpsInterface* gps_get_hardware_interface();
    343 
    344 /**
    345  * Returns the qemu emulated GPS interface.
    346  */
    347 const GpsInterface* gps_get_qemu_interface();
    348 
    349 /**
    350  * Returns the default GPS interface.
    351  */
    352 const GpsInterface* gps_get_interface();
    353 
    354 #if __cplusplus
    355 }  // extern "C"
    356 #endif
    357 
    358 #endif  // _HARDWARE_GPS_H
    359