greeneye2.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. /******************************************************************************
  2. ** File Name: greeneye2.h *
  3. ** Author: *
  4. ** DATE: *
  5. ** Copyright: 2002 Spreatrum, Incoporated. All Rights Reserved. *
  6. ** Description: *
  7. ******************************************************************************
  8. ******************************************************************************
  9. ** Edit History *
  10. ** ------------------------------------------------------------------------- *
  11. ** DATE NAME DESCRIPTION *
  12. ** * *
  13. ******************************************************************************/
  14. #ifndef _GREENEYE2_H
  15. #define _GREENEYE2_H
  16. /**---------------------------------------------------------------------------*
  17. ** Dependencies *
  18. **---------------------------------------------------------------------------*/
  19. //#include "os_api.h"
  20. //#include "uart_drvapi.h"
  21. #include "gps_drv.h"
  22. /**---------------------------------------------------------------------------*
  23. ** Compiler Flag *
  24. **---------------------------------------------------------------------------*/
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**---------------------------------------------------------------------------*
  29. ** Constant Variables *
  30. **---------------------------------------------------------------------------*/
  31. extern uint32 g_libgps_log_id;
  32. #ifndef WIN32
  33. #define gps_log(fmt, ...) SCI_TRACE_LOW("[LIBGPS]" fmt, ##__VA_ARGS__)
  34. #define SPRD_LIBGPS_TRACE
  35. #ifdef SPRD_LIBGPS_TRACE
  36. #define LIBGPS_LOG(fmt, args...) \
  37. gps_log("[%d]%s: " fmt "\n", g_libgps_log_id++, __func__, ##args)
  38. #else
  39. #define LIBGPS_LOG(fmt, args...)
  40. #endif
  41. #else
  42. #define gps_log(fmt, _EXP)
  43. #define SPRD_LIBGPS_TRACE
  44. #define LIBGPS_LOG
  45. #endif
  46. /**---------------------------------------------------------------------------*
  47. ** Data Structures *
  48. **---------------------------------------------------------------------------*/
  49. #define __STRUCT_PACKED__
  50. #define NMEA_MAX_SIZE 1023
  51. #define GNSS_WAKE_LOCK_NAME OSI_MAKE_TAG('G', 'P', 'S', 'L') // gnss walelock name
  52. typedef enum _GPSDATACMD_TYPE
  53. {
  54. GPS_DATA_READ,
  55. GPS_DATA_WRITE,
  56. GPS_DATA_WATCHDOG,
  57. GPS_DATA_START,
  58. GPS_DATA_CMD_MAX
  59. } GPSDATACMD_TYPE;
  60. typedef enum _GPSNMEA_TYPE
  61. {
  62. GPS_MIN_TYPE,
  63. GPS_GGA_TYPE = 0x0,
  64. GPS_GLL_TYPE,
  65. GPS_GSA_TYPE,
  66. GPS_GSV_TYPE,
  67. GPS_RMC_TYPE,
  68. GPS_VTG_TYPE,
  69. GPS_LOG_TYPE,
  70. GPS_TCXO_TYPE,
  71. GPS_GNSSLOG_TYPE,
  72. GPS_TYPE_MAX
  73. } GPSNMEA_TYPE;
  74. typedef enum _GPSNMEA_MODE
  75. {
  76. GPS_GGA_MODE = 2,
  77. GPS_GLL_MODE = 4,
  78. GPS_GSA_MODE = 8,
  79. GPS_GSV_MODE = 16,
  80. GPS_RMC_MODE = 32,
  81. GPS_VTG_MODE = 64,
  82. GPS_MODE_NUM_MAX = 6
  83. } GPSNMEA_MODE;
  84. typedef enum
  85. {
  86. GNSS_TYPE_LOG_UNKOWN = 0,
  87. GNSS_TYPE_LOG_TRACE,
  88. GNSS_TYPE_LOG_NMEA,
  89. GNSS_TYPE_LOG_RF,
  90. GNSS_TYPE_MINILOG_TRACE,
  91. GNSS_TYPE_LOG_MAX,
  92. } GNSS_TYPE_LOG_E;
  93. typedef enum
  94. {
  95. GNSS_TCXO_CLOCK_TYPE = 0,
  96. GNSS_TSX_CLOCK_TYPE = 2
  97. } GNSS_CLOCK_TYPE;
  98. typedef struct _GPSNMEA_DATA
  99. {
  100. GPSNMEA_MODE mode;
  101. char data[NMEA_MAX_SIZE + 1];
  102. } GPSNMEA_DATA;
  103. #if 0
  104. struct tm {
  105. int tm_sec; /* seconds (0 - 59) */
  106. int tm_min; /* minutes (0 - 59) */
  107. int tm_hour; /* hours (0 - 23) */
  108. int tm_mday; /* day of month (1 - 31) */
  109. int tm_mon; /* month of year (0 - 11) */
  110. int tm_year; /* years since 1900 (from 0) */
  111. };
  112. #endif
  113. #ifdef GE2_ASSERT_DEBUG
  114. #define GE2_HANDER_TIME_MAX 64
  115. typedef enum GE2_RECORD_PROCESS_tag
  116. {
  117. GE2_PROCESS_SENDREAD, // Uart_CallbackHisr.
  118. GE2_PROCESS_READ, // thread start read.
  119. GE2_PROCESS_READEND, // thread read end.
  120. GE2_RECORD_PROCESS_MAX
  121. } GE2_RECORD_PROCESS;
  122. typedef struct GE2_HANDER_TIME
  123. {
  124. uint32 send_read_time[GE2_HANDER_TIME_MAX];
  125. uint32 thread_read_time[GE2_HANDER_TIME_MAX];
  126. uint32 thread_read_end_time[GE2_HANDER_TIME_MAX];
  127. uint32 curr_index[GE2_RECORD_PROCESS_MAX];
  128. uint32 read_time_max_ticket[GE2_RECORD_PROCESS_MAX];
  129. uint32 read_time_max_value;
  130. uint32 read_end_time_max_ticket[GE2_RECORD_PROCESS_MAX];
  131. uint32 read_end_time_max_value;
  132. uint32 read_timeout_count;
  133. uint32 read_end_timeout_count;
  134. //uint32 send_count;
  135. //uint32 read_count;
  136. //uint32 circle;
  137. } GE2_HANDER_TIME_T;
  138. #endif
  139. typedef long GpsUtcTime;
  140. /**
  141. * The id of this module
  142. */
  143. #define GPS_HARDWARE_MODULE_ID "gps"
  144. /** Milliseconds since January 1, 1970 */
  145. //typedef int64_t GpsUtcTime;
  146. /** Requested operational mode for GPS operation. */
  147. typedef uint32 GpsPositionMode;
  148. // IMPORTANT: Note that the following values must match
  149. // constants in GpsLocationProvider.java.
  150. /** Mode for running GPS standalone (no assistance). */
  151. #define GPS_POSITION_MODE_STANDALONE 0
  152. /** AGPS MS-Based mode. */
  153. #define GPS_POSITION_MODE_MS_BASED 1
  154. /** AGPS MS-Assisted mode. */
  155. #define GPS_POSITION_MODE_MS_ASSISTED 2
  156. /** Requested recurrence mode for GPS operation. */
  157. typedef uint32 GpsPositionRecurrence;
  158. // IMPORTANT: Note that the following values must match
  159. // constants in GpsLocationProvider.java.
  160. /** Receive GPS fixes on a recurring basis at a specified period. */
  161. #define GPS_POSITION_RECURRENCE_PERIODIC 0
  162. /** Request a single shot GPS fix. */
  163. #define GPS_POSITION_RECURRENCE_SINGLE 1
  164. /** GPS status event values. */
  165. typedef uint16 GpsStatusValue;
  166. // IMPORTANT: Note that the following values must match
  167. // constants in GpsLocationProvider.java.
  168. /** GPS status unknown. */
  169. #define GPS_STATUS_NONE 0
  170. /** GPS has begun navigating. */
  171. #define GPS_STATUS_SESSION_BEGIN 1
  172. /** GPS has stopped navigating. */
  173. #define GPS_STATUS_SESSION_END 2
  174. /** GPS has powered on but is not navigating. */
  175. #define GPS_STATUS_ENGINE_ON 3
  176. /** GPS is powered off. */
  177. #define GPS_STATUS_ENGINE_OFF 4
  178. /** Flags to indicate which values are valid in a GpsLocation. */
  179. typedef uint16 GpsLocationFlags;
  180. // IMPORTANT: Note that the following values must match
  181. // constants in GpsLocationProvider.java.
  182. /** GpsLocation has valid latitude and longitude. */
  183. #define GPS_LOCATION_HAS_LAT_LONG 0x0001
  184. /** GpsLocation has valid altitude. */
  185. #define GPS_LOCATION_HAS_ALTITUDE 0x0002
  186. /** GpsLocation has valid satellites. */
  187. #define GPS_LOCATION_HAS_SATELLITES 0x0003
  188. /** GpsLocation has valid speed. */
  189. #define GPS_LOCATION_HAS_SPEED 0x0004
  190. /** GpsLocation has valid bearing. */
  191. #define GPS_LOCATION_HAS_BEARING 0x0008
  192. /** GpsLocation has valid accuracy. */
  193. #define GPS_LOCATION_HAS_ACCURACY 0x0010
  194. /** Flags for the gps_set_capabilities callback. */
  195. /** GPS HAL schedules fixes for GPS_POSITION_RECURRENCE_PERIODIC mode.
  196. If this is not set, then the framework will use 1000ms for min_interval
  197. and will start and call start() and stop() to schedule the GPS.
  198. */
  199. #define GPS_CAPABILITY_SCHEDULING 0x0000001
  200. /** GPS supports MS-Based AGPS mode */
  201. #define GPS_CAPABILITY_MSB 0x0000002
  202. /** GPS supports MS-Assisted AGPS mode */
  203. #define GPS_CAPABILITY_MSA 0x0000004
  204. /** GPS supports single-shot fixes */
  205. #define GPS_CAPABILITY_SINGLE_SHOT 0x0000008
  206. /** GPS supports on demand time injection */
  207. #define GPS_CAPABILITY_ON_DEMAND_TIME 0x0000010
  208. /** GPS supports Geofencing */
  209. #define GPS_CAPABILITY_GEOFENCING 0x0000020
  210. /** Flags used to specify which aiding data to delete
  211. when calling delete_aiding_data(). */
  212. typedef uint16 GpsAidingData;
  213. // IMPORTANT: Note that the following values must match
  214. // constants in GpsLocationProvider.java.
  215. #define GPS_DELETE_EPHEMERIS 0x0001
  216. #define GPS_DELETE_ALMANAC 0x0002
  217. #define GPS_DELETE_POSITION 0x0004
  218. #define GPS_DELETE_TIME 0x0008
  219. #define GPS_DELETE_IONO 0x0010
  220. #define GPS_DELETE_UTC 0x0020
  221. #define GPS_DELETE_HEALTH 0x0040
  222. #define GPS_DELETE_SVDIR 0x0080
  223. #define GPS_DELETE_SVSTEER 0x0100
  224. #define GPS_DELETE_SADATA 0x0200
  225. #define GPS_DELETE_RTI 0x0400
  226. #define GPS_DELETE_CELLDB_INFO 0x8000
  227. #define GPS_DELETE_ALL 0xFFFF
  228. /** AGPS type */
  229. typedef uint16 AGpsType;
  230. #define AGPS_TYPE_SUPL 1
  231. #define AGPS_TYPE_C2K 2
  232. typedef uint16 AGpsSetIDType;
  233. #define AGPS_SETID_TYPE_NONE 0
  234. #define AGPS_SETID_TYPE_IMSI 1
  235. #define AGPS_SETID_TYPE_MSISDN 2
  236. /**
  237. * String length constants
  238. */
  239. #define GPS_NI_SHORT_STRING_MAXLEN 256
  240. #define GPS_NI_LONG_STRING_MAXLEN 2048
  241. /**
  242. * GpsNiType constants
  243. */
  244. typedef uint32 GpsNiType;
  245. #define GPS_NI_TYPE_VOICE 1
  246. #define GPS_NI_TYPE_UMTS_SUPL 2
  247. #define GPS_NI_TYPE_UMTS_CTRL_PLANE 3
  248. /**
  249. * GpsNiNotifyFlags constants
  250. */
  251. typedef uint32 GpsNiNotifyFlags;
  252. /** NI requires notification */
  253. #define GPS_NI_NEED_NOTIFY 0x0001
  254. /** NI requires verification */
  255. #define GPS_NI_NEED_VERIFY 0x0002
  256. /** NI requires privacy override, no notification/minimal trace */
  257. #define GPS_NI_PRIVACY_OVERRIDE 0x0004
  258. /**
  259. * GPS NI responses, used to define the response in
  260. * NI structures
  261. */
  262. typedef int GpsUserResponseType;
  263. #define GPS_NI_RESPONSE_ACCEPT 1
  264. #define GPS_NI_RESPONSE_DENY 2
  265. #define GPS_NI_RESPONSE_NORESP 3
  266. /**
  267. * NI data encoding scheme
  268. */
  269. typedef int GpsNiEncodingType;
  270. #define GPS_ENC_NONE 0
  271. #define GPS_ENC_SUPL_GSM_DEFAULT 1
  272. #define GPS_ENC_SUPL_UTF8 2
  273. #define GPS_ENC_SUPL_UCS2 3
  274. #define GPS_ENC_UNKNOWN -1
  275. /** AGPS status event values. */
  276. typedef uint16 AGpsStatusValue;
  277. /** GPS requests data connection for AGPS. */
  278. #define GPS_REQUEST_AGPS_DATA_CONN 1
  279. /** GPS releases the AGPS data connection. */
  280. #define GPS_RELEASE_AGPS_DATA_CONN 2
  281. /** AGPS data connection initiated */
  282. #define GPS_AGPS_DATA_CONNECTED 3
  283. /** AGPS data connection completed */
  284. #define GPS_AGPS_DATA_CONN_DONE 4
  285. /** AGPS data connection failed */
  286. #define GPS_AGPS_DATA_CONN_FAILED 5
  287. #define AGPS_REF_LOCATION_TYPE_GSM_CELLID 1
  288. #define AGPS_REF_LOCATION_TYPE_UMTS_CELLID 2
  289. #define AGPS_REG_LOCATION_TYPE_MAC 3
  290. /** Network types for update_network_state "type" parameter */
  291. #define AGPS_RIL_NETWORK_TYPE_MOBILE 0
  292. #define AGPS_RIL_NETWORK_TYPE_WIFI 1
  293. #define AGPS_RIL_NETWORK_TYPE_MOBILE_MMS 2
  294. #define AGPS_RIL_NETWORK_TYPE_MOBILE_SUPL 3
  295. #define AGPS_RIL_NETWORK_TTYPE_MOBILE_DUN 4
  296. #define AGPS_RIL_NETWORK_TTYPE_MOBILE_HIPRI 5
  297. #define AGPS_RIL_NETWORK_TTYPE_WIMAX 6
  298. /** Maximum number of SVs for gps_sv_status_callback(). */
  299. #define GNSS_MAX_SVS 64
  300. #define MAX_TSX_DATA_LENGTH (40)
  301. /**
  302. * Name for the GPS XTRA interface.
  303. */
  304. #define GPS_XTRA_INTERFACE "gps-xtra"
  305. /**
  306. * Name for the GPS DEBUG interface.
  307. */
  308. #define GPS_DEBUG_INTERFACE "gps-debug"
  309. /**
  310. * Name for the AGPS interface.
  311. */
  312. #define AGPS_INTERFACE "agps"
  313. /**
  314. * Name for NI interface
  315. */
  316. #define GPS_NI_INTERFACE "gps-ni"
  317. /**
  318. * Name for the AGPS-RIL interface.
  319. */
  320. #define AGPS_RIL_INTERFACE "agps_ril"
  321. /**
  322. * Name for the GPS_Geofencing interface.
  323. */
  324. #define GPS_GEOFENCING_INTERFACE "gps_geofencing"
  325. /** Represents a location. */
  326. typedef struct
  327. {
  328. /** set to sizeof(GpsLocation) */
  329. uint32 size;
  330. /** Contains GpsLocationFlags bits. */
  331. uint16 flags;
  332. /** Represents latitude in degrees. */
  333. double latitude;
  334. /** Represents longitude in degrees. */
  335. double longitude;
  336. /** Represents satellites in degrees. */
  337. uint8 satellites;
  338. /** Represents altitude in meters above the WGS 84 reference
  339. * ellipsoid. */
  340. double altitude;
  341. /** Represents speed in meters per second. */
  342. float speed;
  343. /** Represents heading in degrees. */
  344. float bearing;
  345. /** Represents expected accuracy in meters. */
  346. float accuracy;
  347. /** Timestamp for the location fix. */
  348. GpsUtcTime timestamp;
  349. /** Represents vertical accuracy in meters. */
  350. float veraccuracy;
  351. /** Represents speed accuracy in meters. */
  352. float speedaccuracy;
  353. /** Represents bearing accuracy in meters. */
  354. float bearaccuracy;
  355. } GpsLocation;
  356. /** Represents the status. */
  357. typedef struct
  358. {
  359. /** set to sizeof(GpsStatus) */
  360. uint32 size;
  361. GpsStatusValue status;
  362. } GpsStatus;
  363. #if 0
  364. /** Represents SV information. */
  365. typedef struct {
  366. /** set to sizeof(GpsSvInfo) */
  367. uint32 size;
  368. /** Pseudo-random number for the SV. */
  369. int prn;
  370. /** Signal to noise ratio. */
  371. float snr;
  372. /** Elevation of SV in degrees. */
  373. float elevation;
  374. /** Azimuth of SV in degrees. */
  375. float azimuth;
  376. } GpsSvInfo;
  377. /** Represents SV status. */
  378. typedef struct {
  379. /** set to sizeof(GpsSvStatus) */
  380. uint32 size;
  381. /** Number of SVs currently visible. */
  382. int num_svs;
  383. /** Contains an array of SV information. */
  384. GpsSvInfo sv_list[GPS_MAX_SVS];
  385. /** Represents a bit mask indicating which SVs
  386. * have ephemeris data.
  387. */
  388. uint32 ephemeris_mask[8];
  389. /** Represents a bit mask indicating which SVs
  390. * have almanac data.
  391. */
  392. uint32 almanac_mask[8];
  393. /**
  394. * Represents a bit mask indicating which SVs
  395. * were used for computing the most recent position fix.
  396. */
  397. uint32 used_in_fix_mask[8];
  398. } GpsSvStatus;
  399. #endif
  400. /** Callback with location information.
  401. * Can only be called from a thread created by create_thread_cb.
  402. */
  403. typedef void (*gps_location_callback)(GpsLocation *location);
  404. /** Callback with status information.
  405. * Can only be called from a thread created by create_thread_cb.
  406. */
  407. typedef void (*gps_status_callback)(GpsStatus *status);
  408. /** Callback with SV status information.
  409. * Can only be called from a thread created by create_thread_cb.
  410. */
  411. typedef void (*gps_sv_status_callback)(GpsSvStatus *sv_info);
  412. /** Callback for reporting NMEA sentences.
  413. * Can only be called from a thread created by create_thread_cb.
  414. */
  415. typedef void (*gps_nmea_callback)(GNSS_TYPE_LOG_E timestamp, const char *nmea, int length);
  416. /** Callback to inform framework of the GPS engine's capabilities.
  417. * Capability parameter is a bit field of GPS_CAPABILITY_* flags.
  418. */
  419. typedef void (*gps_set_capabilities)(uint32 capabilities);
  420. /** Callback for requesting NTP time */
  421. typedef void (*gps_request_utc_time)();
  422. /** Callback for gps err */
  423. typedef void (*gps_err_occurs)();
  424. /**
  425. * Provides information about how new the underlying GPS/GNSS hardware and
  426. * software is.
  427. *
  428. * This information will be available for Android Test Applications. If a GPS
  429. * HAL does not provide this information, it will be considered "2015 or
  430. * earlier".
  431. *
  432. * If a GPS HAL does provide this information, then newer years will need to
  433. * meet newer CTS standards. E.g. if the date are 2016 or above, then N+ level
  434. * GpsMeasurement support will be verified.
  435. */
  436. typedef struct
  437. {
  438. /** Set to sizeof(GnssSystemInfo) */
  439. size_t size;
  440. /* year in which the last update was made to the underlying hardware/firmware
  441. * used to capture GNSS signals, e.g. 2016 */
  442. uint16 year_of_hw;
  443. } GnssSystemInfo;
  444. /**
  445. * Constellation type of GnssSvInfo
  446. */
  447. typedef uint8 GnssConstellationType;
  448. #define GNSS_CONSTELLATION_UNKNOWN 0
  449. #define GNSS_CONSTELLATION_GPS 1
  450. #define GNSS_CONSTELLATION_SBAS 2
  451. #define GNSS_CONSTELLATION_GLONASS 3
  452. #define GNSS_CONSTELLATION_QZSS 4
  453. #define GNSS_CONSTELLATION_BEIDOU 5
  454. #define GNSS_CONSTELLATION_GALILEO 6
  455. /**
  456. * Flags that indicate information about the satellite
  457. */
  458. typedef uint8 GnssSvFlags;
  459. #define GNSS_SV_FLAGS_NONE 0
  460. #define GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA (1 << 0)
  461. #define GNSS_SV_FLAGS_HAS_ALMANAC_DATA (1 << 1)
  462. #define GNSS_SV_FLAGS_USED_IN_FIX (1 << 2)
  463. #define GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY (1 << 3)
  464. typedef struct
  465. {
  466. /** set to sizeof(GnssSvInfo) */
  467. size_t size;
  468. /**
  469. * Pseudo-random number for the SV, or FCN/OSN number for Glonass. The
  470. * distinction is made by looking at constellation field. Values should be
  471. * in the range of:
  472. *
  473. * - GPS: 1-32
  474. * - SBAS: 120-151, 183-192
  475. * - GLONASS: 1-24, the orbital slot number (OSN), if known. Or, if not:
  476. * 93-106, the frequency channel number (FCN) (-7 to +6) offset by + 100
  477. * i.e. report an FCN of -7 as 93, FCN of 0 as 100, and FCN of +6 as 106.
  478. * - QZSS: 193-200
  479. * - Galileo: 1-36
  480. * - Beidou: 1-37
  481. */
  482. int16 svid;
  483. /**
  484. * Defines the constellation of the given SV. Value should be one of those
  485. * GNSS_CONSTELLATION_* constants
  486. */
  487. GnssConstellationType constellation;
  488. /**
  489. * Carrier-to-noise density in dB-Hz, typically in the range [0, 63].
  490. * It contains the measured C/N0 value for the signal at the antenna port.
  491. *
  492. * This is a mandatory value.
  493. */
  494. float c_n0_dbhz;
  495. /** Elevation of SV in degrees. */
  496. float elevation;
  497. /** Azimuth of SV in degrees. */
  498. float azimuth;
  499. /**
  500. * Contains additional data about the given SV. Value should be one of those
  501. * GNSS_SV_FLAGS_* constants
  502. */
  503. GnssSvFlags flags;
  504. float carrier_freq;
  505. } GnssSvInfo;
  506. /**
  507. * Represents SV status.
  508. */
  509. typedef struct
  510. {
  511. /** set to sizeof(GnssSvStatus) */
  512. size_t size;
  513. /** Number of GPS SVs currently visible, refers to the SVs stored in sv_list */
  514. int num_svs;
  515. /**
  516. * Pointer to an array of SVs information for all GNSS constellations,
  517. * except GPS, which is reported using sv_list
  518. */
  519. GnssSvInfo gnss_sv_list[GNSS_MAX_SVS];
  520. } GnssSvStatus;
  521. #define NMEA_PACKET_DATA_LEN 3072
  522. typedef enum
  523. {
  524. GNSS_NMEA_DO_PACKET = 0,
  525. GNSS_NMEA_CLEAR_PACKET
  526. } GNSS_NMEA_PACKET_STATUS;
  527. typedef struct
  528. {
  529. uint16 nmea_types; // BIT0=1--GGA, BIT1=1--GLL, BIT2=1--GSA, BIT3=1--GSV, BIT4=1--RMC, BIT5=1--VTG
  530. uint32 cur_pos;
  531. uint8 nmea_packet_data[NMEA_PACKET_DATA_LEN]; // NMEA packet buffer
  532. } GNSS_NMEA_CONTAINER;
  533. extern GNSS_NMEA_CONTAINER NMEA_Container;
  534. /** Callback for creating a thread that can call into the Java framework code.
  535. * This must be used to create any threads that report events up to the framework.
  536. */
  537. //typedef pthread_t (* gps_create_thread)(const char* name, void (*start)(void *), void* arg);
  538. /** Callback for send NMEA sentences to test.
  539. * Can only be called from a thread created by create_thread_cb.
  540. */
  541. typedef void (*gps_send_nmea_callback)(GPSNMEA_TYPE type, const char *nmea, int length);
  542. #ifdef CONFIG_SOC_8850
  543. typedef void (*gps_send_nmea_packet_callback)();
  544. #endif
  545. /** GPS callback structure. */
  546. typedef struct
  547. {
  548. /** set to sizeof(GpsCallbacks) */
  549. uint32 size;
  550. gps_location_callback location_cb;
  551. gps_status_callback status_cb;
  552. gps_sv_status_callback sv_status_cb;
  553. gps_nmea_callback nmea_cb;
  554. gps_set_capabilities set_capabilities_cb;
  555. gps_request_utc_time request_utc_time_cb;
  556. gps_err_occurs err_occurs_cb;
  557. gps_send_nmea_callback send_nmea_cb;
  558. #ifdef CONFIG_SOC_8850
  559. gps_send_nmea_packet_callback send_nmea_packet_cb;
  560. #endif
  561. } GpsCallbacks;
  562. /** Represents the standard GPS interface. */
  563. typedef struct
  564. {
  565. /** set to sizeof(GpsInterface) */
  566. uint32 size;
  567. /**
  568. * Opens the interface and provides the callback routines
  569. * to the implemenation of this interface.
  570. */
  571. int (*init)(GpsCallbacks *callbacks);
  572. /** Starts navigating. */
  573. int (*start)(void);
  574. /** Starts idleoff. */
  575. int (*idleoff)(void);
  576. /** Stops navigating. */
  577. int (*stop)(void);
  578. /** Closes the interface. */
  579. void (*cleanup)(void);
  580. uint32 (*getposition)(char **pbuf);
  581. void (*setrestart)(uint32 mode);
  582. void (*settimerinterval)(uint32 timer_interval);
  583. void (*writeagpsdata)(char *agps_data, uint32 length);
  584. void (*testmodeenable)(uint8 status);
  585. void (*setrftestmode)(GPS_RF_TEST_MODE_E rf_mode);
  586. void (*sendephdata)(void);
  587. void (*clearephdata)(void);
  588. void (*sendwatchdog)(void);
  589. void (*clearalmdata)(void);
  590. void (*setassert)(uint8 assertmode);
  591. void (*entersleep)(void);
  592. #if 0
  593. /** Injects the current time. */
  594. int (*inject_time)(GpsUtcTime time, uint32 timeReference,
  595. int uncertainty);
  596. /** Injects current location from another location provider
  597. * (typically cell ID).
  598. * latitude and longitude are measured in degrees
  599. * expected accuracy is measured in meters
  600. */
  601. int (*inject_location)(double latitude, double longitude, float accuracy);
  602. /**
  603. * Specifies that the next call to start will not use the
  604. * information defined in the flags. GPS_DELETE_ALL is passed for
  605. * a cold start.
  606. */
  607. void (*delete_aiding_data)(GpsAidingData flags);
  608. /**
  609. * min_interval represents the time between fixes in milliseconds.
  610. * preferred_accuracy represents the requested fix accuracy in meters.
  611. * preferred_time represents the requested time to first fix in milliseconds.
  612. */
  613. int (*set_position_mode)(GpsPositionMode mode, GpsPositionRecurrence recurrence,
  614. uint32 min_interval, uint32 preferred_accuracy, uint32 preferred_time);
  615. /** Get a pointer to extension information. */
  616. const void* (*get_extension)(const char* name);
  617. #endif
  618. } GpsInterface;
  619. /** Extended interface for DEBUG support. */
  620. typedef struct
  621. {
  622. /** set to sizeof(GpsDebugInterface) */
  623. uint32 size;
  624. /**
  625. * This function should return any information that the native
  626. * implementation wishes to include in a bugreport.
  627. */
  628. uint32 (*get_internal_state)(char *buffer, uint32 bufferSize);
  629. } GpsDebugInterface;
  630. /** Represents an NI request */
  631. typedef struct
  632. {
  633. /** set to sizeof(GpsNiNotification) */
  634. uint32 size;
  635. /**
  636. * An ID generated by HAL to associate NI notifications and UI
  637. * responses
  638. */
  639. int notification_id;
  640. /**
  641. * An NI type used to distinguish different categories of NI
  642. * events, such as GPS_NI_TYPE_VOICE, GPS_NI_TYPE_UMTS_SUPL, ...
  643. */
  644. GpsNiType ni_type;
  645. /**
  646. * Notification/verification options, combinations of GpsNiNotifyFlags constants
  647. */
  648. GpsNiNotifyFlags notify_flags;
  649. /**
  650. * Timeout period to wait for user response.
  651. * Set to 0 for no time out limit.
  652. */
  653. int timeout;
  654. /**
  655. * Default response when time out.
  656. */
  657. GpsUserResponseType default_response;
  658. /**
  659. * Requestor ID
  660. */
  661. char requestor_id[GPS_NI_SHORT_STRING_MAXLEN];
  662. /**
  663. * Notification message. It can also be used to store client_id in some cases
  664. */
  665. char text[GPS_NI_LONG_STRING_MAXLEN];
  666. /**
  667. * Client name decoding scheme
  668. */
  669. GpsNiEncodingType requestor_id_encoding;
  670. /**
  671. * Client name decoding scheme
  672. */
  673. GpsNiEncodingType text_encoding;
  674. /**
  675. * A pointer to extra data. Format:
  676. * key_1 = value_1
  677. * key_2 = value_2
  678. */
  679. char extras[GPS_NI_LONG_STRING_MAXLEN];
  680. } GpsNiNotification;
  681. /** Callback with NI notification.
  682. * Can only be called from a thread created by create_thread_cb.
  683. */
  684. typedef void (*gps_ni_notify_callback)(GpsNiNotification *notification);
  685. /** GPS NI callback structure. */
  686. typedef struct
  687. {
  688. /**
  689. * Sends the notification request from HAL to GPSLocationProvider.
  690. */
  691. gps_ni_notify_callback notify_cb;
  692. // gps_create_thread create_thread_cb;
  693. } GpsNiCallbacks;
  694. /**
  695. * Extended interface for Network-initiated (NI) support.
  696. */
  697. typedef struct
  698. {
  699. /** set to sizeof(GpsNiInterface) */
  700. uint32 size;
  701. /** Registers the callbacks for HAL to use. */
  702. void (*init)(GpsNiCallbacks *callbacks);
  703. /** Sends a response to HAL. */
  704. void (*respond)(int notif_id, GpsUserResponseType user_response);
  705. } GpsNiInterface;
  706. struct gps_device_t
  707. {
  708. //struct hw_device_t common;
  709. /**
  710. * Set the provided lights to the provided values.
  711. *
  712. * Returns: 0 on succes, error code on failure.
  713. */
  714. const GpsInterface *(*get_gps_interface)(struct gps_device_t *dev);
  715. };
  716. /**
  717. * GPS Geofence.
  718. * There are 3 states associated with a Geofence: Inside, Outside, Unknown.
  719. * There are 3 transitions: ENTERED, EXITED, UNCERTAIN.
  720. *
  721. * An example state diagram with confidence level: 95% and Unknown time limit
  722. * set as 30 secs is shown below. (confidence level and Unknown time limit are
  723. * explained latter)
  724. * ____________________________
  725. * | Unknown (30 secs) |
  726. * """"""""""""""""""""""""""""
  727. * ^ | | ^
  728. * UNCERTAIN| |ENTERED EXITED| |UNCERTAIN
  729. * | v v |
  730. * ________ EXITED _________
  731. * | Inside | -----------> | Outside |
  732. * | | <----------- | |
  733. * """""""" ENTERED """""""""
  734. *
  735. * Inside state: We are 95% confident that the user is inside the geofence.
  736. * Outside state: We are 95% confident that the user is outside the geofence
  737. * Unknown state: Rest of the time.
  738. *
  739. * The Unknown state is better explained with an example:
  740. *
  741. * __________
  742. * | c|
  743. * | ___ | _______
  744. * | |a| | | b |
  745. * | """ | """""""
  746. * | |
  747. * """"""""""
  748. * In the diagram above, "a" and "b" are 2 geofences and "c" is the accuracy
  749. * circle reported by the GPS subsystem. Now with regard to "b", the system is
  750. * confident that the user is outside. But with regard to "a" is not confident
  751. * whether it is inside or outside the geofence. If the accuracy remains the
  752. * same for a sufficient period of time, the UNCERTAIN transition would be
  753. * triggered with the state set to Unknown. If the accuracy improves later, an
  754. * appropriate transition should be triggered. This "sufficient period of time"
  755. * is defined by the parameter in the add_geofence_area API.
  756. * In other words, Unknown state can be interpreted as a state in which the
  757. * GPS subsystem isn't confident enough that the user is either inside or
  758. * outside the Geofence. It moves to Unknown state only after the expiry of the
  759. * timeout.
  760. *
  761. * The geofence callback needs to be triggered for the ENTERED and EXITED
  762. * transitions, when the GPS system is confident that the user has entered
  763. * (Inside state) or exited (Outside state) the Geofence. An implementation
  764. * which uses a value of 95% as the confidence is recommended. The callback
  765. * should be triggered only for the transitions requested by the
  766. * add_geofence_area call.
  767. *
  768. * Even though the diagram and explanation talks about states and transitions,
  769. * the callee is only interested in the transistions. The states are mentioned
  770. * here for illustrative purposes.
  771. *
  772. * Startup Scenario: When the device boots up, if an application adds geofences,
  773. * and then we get an accurate GPS location fix, it needs to trigger the
  774. * appropriate (ENTERED or EXITED) transition for every Geofence it knows about.
  775. * By default, all the Geofences will be in the Unknown state.
  776. *
  777. * When the GPS system is unavailable, gps_geofence_status_callback should be
  778. * called to inform the upper layers of the same. Similarly, when it becomes
  779. * available the callback should be called. This is a global state while the
  780. * UNKNOWN transition described above is per geofence.
  781. *
  782. * An important aspect to note is that users of this API (framework), will use
  783. * other subsystems like wifi, sensors, cell to handle Unknown case and
  784. * hopefully provide a definitive state transition to the third party
  785. * application. GPS Geofence will just be a signal indicating what the GPS
  786. * subsystem knows about the Geofence.
  787. *
  788. */
  789. #define GPS_GEOFENCE_ENTERED (1 << 0L)
  790. #define GPS_GEOFENCE_EXITED (1 << 1L)
  791. #define GPS_GEOFENCE_UNCERTAIN (1 << 2L)
  792. #define GPS_GEOFENCE_UNAVAILABLE (1 << 0L)
  793. #define GPS_GEOFENCE_AVAILABLE (1 << 1L)
  794. #define GPS_GEOFENCE_OPERATION_SUCCESS 0
  795. #define GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES -100
  796. #define GPS_GEOFENCE_ERROR_ID_EXISTS -101
  797. #define GPS_GEOFENCE_ERROR_ID_UNKNOWN -102
  798. #define GPS_GEOFENCE_ERROR_INVALID_TRANSITION -103
  799. #define GPS_GEOFENCE_ERROR_GENERIC -149
  800. /**
  801. * The callback associated with the geofence.
  802. * Parameters:
  803. * geofence_id - The id associated with the add_geofence_area.
  804. * location - The current GPS location.
  805. * transition - Can be one of GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED,
  806. * GPS_GEOFENCE_UNCERTAIN.
  807. * timestamp - Timestamp when the transition was detected.
  808. *
  809. * The callback should only be called when the caller is interested in that
  810. * particular transition. For instance, if the caller is interested only in
  811. * ENTERED transition, then the callback should NOT be called with the EXITED
  812. * transition.
  813. *
  814. * IMPORTANT: If a transition is triggered resulting in this callback, the GPS
  815. * subsystem will wake up the application processor, if its in suspend state.
  816. */
  817. //typedef void (*gps_geofence_transition_callback) (int32 geofence_id, GpsLocation* location,
  818. // int32 transition, GpsUtcTime timestamp);
  819. /**
  820. * The callback associated with the availablity of the GPS system for geofencing
  821. * monitoring. If the GPS system determines that it cannot monitor geofences
  822. * because of lack of reliability or unavailability of the GPS signals, it will
  823. * call this callback with GPS_GEOFENCE_UNAVAILABLE parameter.
  824. *
  825. * Parameters:
  826. * status - GPS_GEOFENCE_UNAVAILABLE or GPS_GEOFENCE_AVAILABLE.
  827. * last_location - Last known location.
  828. */
  829. typedef void (*gps_geofence_status_callback)(int32 status, GpsLocation *last_location);
  830. /**
  831. * The callback associated with the add_geofence call.
  832. *
  833. * Parameter:
  834. * geofence_id - Id of the geofence.
  835. * status - GPS_GEOFENCE_OPERATION_SUCCESS
  836. * GPS_GEOFENCE_ERROR_TOO_MANY_GEOFENCES - geofence limit has been reached.
  837. * GPS_GEOFENCE_ERROR_ID_EXISTS - geofence with id already exists
  838. * GPS_GEOFENCE_ERROR_INVALID_TRANSITION - the monitorTransition contains an
  839. * invalid transition
  840. * GPS_GEOFENCE_ERROR_GENERIC - for other errors.
  841. */
  842. typedef void (*gps_geofence_add_callback)(int32 geofence_id, int32 status);
  843. /**
  844. * The callback associated with the remove_geofence call.
  845. *
  846. * Parameter:
  847. * geofence_id - Id of the geofence.
  848. * status - GPS_GEOFENCE_OPERATION_SUCCESS
  849. * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
  850. * GPS_GEOFENCE_ERROR_GENERIC for others.
  851. */
  852. typedef void (*gps_geofence_remove_callback)(int32 geofence_id, int32 status);
  853. /**
  854. * The callback associated with the pause_geofence call.
  855. *
  856. * Parameter:
  857. * geofence_id - Id of the geofence.
  858. * status - GPS_GEOFENCE_OPERATION_SUCCESS
  859. * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
  860. * GPS_GEOFENCE_ERROR_INVALID_TRANSITION -
  861. * when monitor_transitions is invalid
  862. * GPS_GEOFENCE_ERROR_GENERIC for others.
  863. */
  864. typedef void (*gps_geofence_pause_callback)(int32 geofence_id, int32 status);
  865. /**
  866. * The callback associated with the resume_geofence call.
  867. *
  868. * Parameter:
  869. * geofence_id - Id of the geofence.
  870. * status - GPS_GEOFENCE_OPERATION_SUCCESS
  871. * GPS_GEOFENCE_ERROR_ID_UNKNOWN - for invalid id
  872. * GPS_GEOFENCE_ERROR_GENERIC for others.
  873. */
  874. typedef void (*gps_geofence_resume_callback)(int32 geofence_id, int32 status);
  875. typedef struct
  876. {
  877. // gps_geofence_transition_callback geofence_transition_callback;
  878. gps_geofence_status_callback geofence_status_callback;
  879. gps_geofence_add_callback geofence_add_callback;
  880. gps_geofence_remove_callback geofence_remove_callback;
  881. gps_geofence_pause_callback geofence_pause_callback;
  882. gps_geofence_resume_callback geofence_resume_callback;
  883. } GpsGeofenceCallbacks;
  884. /** Extended interface for GPS_Geofencing support */
  885. typedef struct
  886. {
  887. /** set to sizeof(GpsGeofencingInterface) */
  888. uint32 size;
  889. /**
  890. * Opens the geofence interface and provides the callback routines
  891. * to the implemenation of this interface.
  892. */
  893. void (*init)(GpsGeofenceCallbacks *callbacks);
  894. /**
  895. * Add a geofence area. This api currently supports circular geofences.
  896. * Parameters:
  897. * geofence_id - The id for the geofence. If a geofence with this id
  898. * already exists, an error value (GPS_GEOFENCE_ERROR_ID_EXISTS)
  899. * should be returned.
  900. * latitude, longtitude, radius_meters - The lat, long and radius
  901. * (in meters) for the geofence
  902. * last_transition - The current state of the geofence. For example, if
  903. * the system already knows that the user is inside the geofence,
  904. * this will be set to GPS_GEOFENCE_ENTERED. In most cases, it
  905. * will be GPS_GEOFENCE_UNCERTAIN.
  906. * monitor_transition - Which transitions to monitor. Bitwise OR of
  907. * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
  908. * GPS_GEOFENCE_UNCERTAIN.
  909. * notification_responsiveness_ms - Defines the best-effort description
  910. * of how soon should the callback be called when the transition
  911. * associated with the Geofence is triggered. For instance, if set
  912. * to 1000 millseconds with GPS_GEOFENCE_ENTERED, the callback
  913. * should be called 1000 milliseconds within entering the geofence.
  914. * This parameter is defined in milliseconds.
  915. * NOTE: This is not to be confused with the rate that the GPS is
  916. * polled at. It is acceptable to dynamically vary the rate of
  917. * sampling the GPS for power-saving reasons; thus the rate of
  918. * sampling may be faster or slower than this.
  919. * unknown_timer_ms - The time limit after which the UNCERTAIN transition
  920. * should be triggered. This paramter is defined in milliseconds.
  921. * See above for a detailed explanation.
  922. */
  923. void (*add_geofence_area)(int32 geofence_id, double latitude,
  924. double longitude, double radius_meters,
  925. int last_transition, int monitor_transitions,
  926. int notification_responsiveness_ms,
  927. int unknown_timer_ms);
  928. /**
  929. * Pause monitoring a particular geofence.
  930. * Parameters:
  931. * geofence_id - The id for the geofence.
  932. */
  933. void (*pause_geofence)(int32 geofence_id);
  934. /**
  935. * Resume monitoring a particular geofence.
  936. * Parameters:
  937. * geofence_id - The id for the geofence.
  938. * monitor_transitions - Which transitions to monitor. Bitwise OR of
  939. * GPS_GEOFENCE_ENTERED, GPS_GEOFENCE_EXITED and
  940. * GPS_GEOFENCE_UNCERTAIN.
  941. * This supersedes the value associated provided in the
  942. * add_geofence_area call.
  943. */
  944. void (*resume_geofence)(int32 geofence_id, int monitor_transitions);
  945. /**
  946. * Remove a geofence area. After the function returns, no notifications
  947. * should be sent.
  948. * Parameter:
  949. * geofence_id - The id for the geofence.
  950. */
  951. void (*remove_geofence_area)(int32 geofence_id);
  952. } GpsGeofencingInterface;
  953. typedef struct _TGe2GpsPosition
  954. {
  955. float latitude; /** geographical latitude */
  956. float longitude; /** geographical longitude */
  957. uint8 satellites; /** geographical satellites */
  958. float altitude; /** geographical altitude */
  959. } __STRUCT_PACKED__ TGe2GpsPosition;
  960. typedef struct _TGe2Velocity
  961. {
  962. float horizontalSpeed; // kmh
  963. float bearing;
  964. float verticalSpeed; // kmh
  965. int verticalDirect; // 0: upward, 1:downward
  966. } __STRUCT_PACKED__ TGe2Velocity;
  967. typedef struct
  968. {
  969. unsigned short wYear;
  970. unsigned short wMonth;
  971. unsigned short wDay;
  972. unsigned short wHour;
  973. unsigned short wMinute;
  974. unsigned short wSecond;
  975. } TGe2TimeStamp;
  976. typedef struct __Ge2PositionParam_t
  977. {
  978. uint8 fix_mode;
  979. int ttff;
  980. TGe2GpsPosition pos;
  981. TGe2Velocity velocity;
  982. TGe2TimeStamp time;
  983. /** Represents expected accuracy in meters. */
  984. float accuracy;
  985. } Ge2PositionParam_t;
  986. typedef struct GPS_SIG_tag
  987. {
  988. SIGNAL_VARS
  989. uint32 sig_param;
  990. } GPS_SIG_T;
  991. /**---------------------------------------------------------------------------*
  992. ** Function Prototypes *
  993. **---------------------------------------------------------------------------*/
  994. int gps_open(struct gps_device_t **device);
  995. int gps_start(void);
  996. int gps_stop(void);
  997. BOOLEAN gps_get_testmode();
  998. GPS_RF_TEST_MODE_E gps_get_rftestmode();
  999. #ifdef GPS_TRANS_VIA_UART
  1000. int gps_com_close(int uart_port);
  1001. #endif
  1002. void watchdog(uint32 param);
  1003. /**---------------------------------------------------------------------------*
  1004. ** Compiler Flag *
  1005. **---------------------------------------------------------------------------*/
  1006. #ifdef __cplusplus
  1007. }
  1008. #endif /* __cplusplus */
  1009. #endif