gps.h 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410
  1. /* gps.h -- interface of the libgps library */
  2. /*
  3. * This file is Copyright (c) 2010 by the GPSD project
  4. * SPDX-License-Identifier: BSD-2-clause
  5. */
  6. #ifndef _GPSD_GPS_H_
  7. #define _GPSD_GPS_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include <inttypes.h> /* stdint.h would be smaller but not all have it */
  12. #include <limits.h>
  13. #include <pthread.h> /* pacifies OpenBSD's compiler */
  14. #include <signal.h>
  15. #include <stdbool.h>
  16. #include <stdio.h>
  17. #include <sys/time.h> // for struct timespec
  18. #include <sys/types.h>
  19. #include <time.h>
  20. /*
  21. * 4.1 - Base version for initial JSON protocol (Dec 2009, release 2.90)
  22. * 4.2 - AIS application IDs split into DAC and FID (July 2010, release 2.95)
  23. * 5.0 - MAXCHANNELS bumped from 20 to 32 for GLONASS (Mar 2011, release 2.96)
  24. * gps_open() becomes reentrant, what gps_open_r() used to be.
  25. * gps_poll() removed in favor of gps_read(). The raw hook is gone.
  26. * (Aug 2011, release 3.0)
  27. * 5.1 - GPS_PATH_MAX uses system PATH_MAX; split24 flag added. New
  28. * model and serial members in part B of AIS type 24, conforming
  29. * with ITU-R 1371-4. New timedrift structure (Nov 2013, release 3.10).
  30. * 6.0 - AIS type 6 and 8 get 'structured' flag; GPS_PATH_MAX
  31. * shortened because devices has moved out of the tail union. Sentence
  32. * tag fields dropped from emitted JSON. The shape of the skyview
  33. * structure has changed to make working with the satellites-used
  34. * bits less confusing. (January 2015, release 3.12).
  35. * 6.1 - Add navdata_t for more (nmea2000) info.
  36. * 7.0 - add gps_fix_t.ecef (February 2018)
  37. * changed prototype of gps_read() to add buffer parameters
  38. * increased length of devconfig_t.subtype
  39. * add gnssid:svid:sigid to satellite_t
  40. * add mtime to attitude_t
  41. * changed MAXCHANNELS
  42. * 8.0 - Change shape of rawdata_t.
  43. * Added values for gps_data_t->status
  44. * Remove epe from gps_data_t, it duplicates gps_fix_t eph
  45. * Added sep (estimated spherical error, 3D)
  46. * Note: Some GPS call eph as epe, others call sep as epe
  47. * Add gps_fix_t datum string, and qErr
  48. * enlarge subtype to hold ZED-F9 string
  49. * MAXCHANNELS bumped from 120 to 140
  50. * Try to make PRN be NMEA 2.x-4.0 compliant, not 4.10 or u-blox
  51. * 9.0 add NED and geoid_sep variables to gps_fix_t
  52. * add health variable to satellite_t
  53. * change satellite_t elevation and azimuth to double
  54. * satellite_t elevation, azimuth, and ss use NAN for unknown value.
  55. * add altMSL, and depth, to gps_fix_t
  56. * change altitude to altHAE to gps_fix_t
  57. * Move mag_var from gps_device_t to magnetic_var gps_data_t.
  58. * add dgps_age and dgps_station, to gps_fix_t
  59. * Change gps_fix_t.time from timestamp_t to timespec_t
  60. * Change gps_data_t.skyview_time from timestamp_t to timespec_t
  61. * Change gps_data_t.online from timestamp_t to timespec_t
  62. * Change gpst_t.utctime from double to timespec_t
  63. * Change devices.time from timestamp_t to timespec_t
  64. * Change sub4_18.d_tot from timestamp_t to time_t t_tot
  65. * Change devconfig_t.activated, cycle & mincycle to timespec_t
  66. * Remove unused timestamp() and unix_to_iso8601().
  67. * Remove unused iso8601_to_unix().
  68. * Remove unused struct timestamp_t entirely
  69. * Add DEG_NORM()
  70. * Move toff and pps out of gps_data_t.union.
  71. * Move gps_fix_t.qErr to gps_data_t.
  72. * Split devconfig_t.subtype into subtype and subtype1
  73. */
  74. #define GPSD_API_MAJOR_VERSION 9 /* bump on incompatible changes */
  75. #define GPSD_API_MINOR_VERSION 0 /* bump on compatible changes */
  76. #define MAXCHANNELS 140 /* u-blox 9 tracks 140 signals */
  77. #define MAXUSERDEVS 4 /* max devices per user */
  78. #define GPS_PATH_MAX 128 /* for names like /dev/serial/by-id/... */
  79. // normalize degrees to 0 to 359
  80. #define DEG_NORM(deg) \
  81. if (0 > (deg)) {(deg) += 360;} else if (360 <= (deg)) {(deg) -= 360;};
  82. /*
  83. * The structure describing an uncertainty volume in kinematic space.
  84. * This is what GPSes are meant to produce; all the other info is
  85. * technical impedimenta.
  86. *
  87. * All double values use NAN to indicate data not available.
  88. *
  89. * All the information in this structure was considered valid
  90. * by the GPS at the time of update.
  91. *
  92. * Error estimates are at 95% confidence.
  93. */
  94. /* WARNING! loss of precision telling timme as a double.
  95. * A double is 53 significant bits.
  96. * UNIX time to nanoSec precision is 62 significant bits
  97. * UNIX time to nanoSec precision after 2038 is 63 bits
  98. * UNIX time as a double is only microSec precision
  99. * UNIX time as a double and PPS do not play well together
  100. */
  101. /* we want cm accuracy and 0.0000001 degrees is 1.11 cm at the equator
  102. * the equator is best case for longitude. At 45lat cut that in half.
  103. * at 85lat make it 0.00000001
  104. *
  105. * this easily fits in a C double which has 15.95 digits of precision
  106. * printf() format %f defaults to %.6f, which will truncate the result.
  107. * so print with %.7f if you have a survey grade GPS.
  108. *
  109. * ref: https://en.wikipedia.org/wiki/Decimal_degrees
  110. */
  111. typedef struct timespec timespec_t; /* Unix time as sec, nsec */
  112. /* GPS error estimates are all over the map, and often unspecified.
  113. * try for 1-sigma if we can... */
  114. struct gps_fix_t {
  115. timespec_t time; /* Time of update */
  116. int mode; /* Mode of fix */
  117. #define MODE_NOT_SEEN 0 /* mode update not seen yet */
  118. #define MODE_NO_FIX 1 /* none */
  119. #define MODE_2D 2 /* good for latitude/longitude */
  120. #define MODE_3D 3 /* good for altitude/climb too */
  121. double ept; /* Expected time uncertainty, seconds */
  122. double latitude; /* Latitude in degrees (valid if mode >= 2) */
  123. double epy; /* Latitude position uncertainty, meters */
  124. double longitude; /* Longitude in degrees (valid if mode >= 2) */
  125. double epx; /* Longitude position uncertainty, meters */
  126. double altHAE; /* Altitude, height above allipsoid.
  127. * in meters and probably WGS84
  128. * (valid if mode == 3)
  129. * MSL = altHAE - geoid_sep */
  130. double altMSL; /* Altitude MSL (maybe EGM2008) */
  131. double epv; /* Vertical position uncertainty, meters */
  132. double track; /* Course made good (relative to true north) */
  133. double epd; /* Track uncertainty, degrees */
  134. double speed; /* Speed over ground, meters/sec */
  135. double eps; /* Speed uncertainty, meters/sec */
  136. double climb; /* Vertical speed, meters/sec */
  137. double epc; /* Vertical speed uncertainty */
  138. /* estimated postion error horizontal (2D) . meters, maybe 50%, maybe 95% */
  139. /* aka estimated position error (epe) */
  140. double eph; /* estimated postion error horizontal (2D) */
  141. /* sperical error probability, 3D. meters, maybe 50%, maybe 95% */
  142. /* Garmin, not gpsd, calls this estimated position error (epe) */
  143. double sep;
  144. /* Geoid separation (ellipsoid separation)
  145. * Height of MSL ellipsoid (geoid) above WGS84 ellipsoid.
  146. * Postive is MSL above WGS84. In meters */
  147. double geoid_sep;
  148. double magnetic_track; /* Course (relative to Magnetic North) */
  149. double magnetic_var; /* magnetic variation in degrees */
  150. double depth; /* depth in meters, probably depth of water
  151. * under the keel */
  152. /* ECEF data, all data in meters, and meters/second, or NaN */
  153. struct {
  154. double x, y, z; /* ECEF x, y, z */
  155. double pAcc; /* 3D Position Accuracy Estimate, likely SEP */
  156. double vx, vy, vz; /* ECEF x, y, z velocity */
  157. double vAcc; /* Velocity Accuracy Estimate, probably SEP */
  158. } ecef;
  159. /* NED data, all data in meters, and meters/second, or NaN */
  160. struct {
  161. double relPosN, relPosE, relPosD; /* NED relative positions */
  162. double velN, velE, velD; /* NED velocities */
  163. } NED;
  164. char datum[40]; /* map datum */
  165. /* DGPS stuff, often from xxGGA, or xxGNS */
  166. double dgps_age; /* age of DGPS data in tenths of seconds,
  167. * -1 invalid */
  168. /* DGPS Station used, max size is a guess
  169. * NMEA 2 says 0000-1023
  170. * RTCM 3, station ID is 0 to 4095.
  171. * u-blox UBX-NAV-DGPS is 16 bit integer */
  172. int dgps_station; /* DGPS station ID, -1 invalid */
  173. };
  174. /*
  175. * Other GNSS birds reuse GPS PRNs.
  176. * It is an NMEA0183 convention to map them to pseudo-PRNs 65..437.
  177. * Very dependent on NMEA version.
  178. * (some other GPS receivers push them to 33 and above).
  179. */
  180. #define GLONASS_PRN_OFFSET 64
  181. /*
  182. * The structure describing the pseudorange errors (GPGST)
  183. */
  184. struct gst_t {
  185. timespec_t utctime;
  186. double rms_deviation;
  187. double smajor_deviation;
  188. double sminor_deviation;
  189. double smajor_orientation;
  190. double lat_err_deviation;
  191. double lon_err_deviation;
  192. double alt_err_deviation;
  193. };
  194. /*
  195. * From the RCTM104 2.x standard:
  196. *
  197. * "The 30 bit words (as opposed to 32 bit words) coupled with a 50 Hz
  198. * transmission rate provides a convenient timing capability where the
  199. * times of word boundaries are a rational multiple of 0.6 seconds."
  200. *
  201. * "Each frame is N+2 words long, where N is the number of message data
  202. * words. For example, a filler message (type 6 or 34) with no message
  203. * data will have N=0, and will consist only of two header words. The
  204. * maximum number of data words allowed by the format is 31, so that
  205. * the longest possible message will have a total of 33 words."
  206. */
  207. #define RTCM2_WORDS_MAX 33
  208. #define MAXCORRECTIONS 18 /* max correction count in type 1 or 9 */
  209. #define MAXSTATIONS 10 /* maximum stations in almanac, type 5 */
  210. /* RTCM104 doesn't specify this, so give it the largest reasonable value */
  211. #define MAXHEALTH (RTCM2_WORDS_MAX-2)
  212. /*
  213. * A nominally 30-bit word (24 bits of data, 6 bits of parity)
  214. * used both in the GPS downlink protocol described in IS-GPS-200
  215. * and in the format for DGPS corrections used in RTCM-104v2.
  216. */
  217. typedef uint32_t isgps30bits_t;
  218. /*
  219. * Values for "system" fields. Note, the encoding logic is senstive to the
  220. * actual values of these; it's not sufficient that they're distinct.
  221. */
  222. #define NAVSYSTEM_GPS 0
  223. #define NAVSYSTEM_GLONASS 1
  224. #define NAVSYSTEM_GALILEO 2
  225. #define NAVSYSTEM_UNKNOWN 3
  226. struct rtcm2_t {
  227. /* header contents */
  228. unsigned type; /* RTCM message type */
  229. unsigned length; /* length (words) */
  230. double zcount; /* time within hour: GPS time, no leap secs */
  231. unsigned refstaid; /* reference station ID */
  232. unsigned seqnum; /* message sequence number (modulo 8) */
  233. unsigned stathlth; /* station health */
  234. /* message data in decoded form */
  235. union {
  236. struct {
  237. unsigned int nentries;
  238. struct gps_rangesat_t { /* data from messages 1 & 9 */
  239. unsigned ident; /* satellite ID */
  240. unsigned udre; /* user diff. range error */
  241. unsigned iod; /* issue of data */
  242. double prc; /* range error */
  243. double rrc; /* range error rate */
  244. } sat[MAXCORRECTIONS];
  245. } gps_ranges;
  246. struct { /* data for type 3 messages */
  247. bool valid; /* is message well-formed? */
  248. double x, y, z;
  249. } ecef;
  250. struct { /* data from type 4 messages */
  251. bool valid; /* is message well-formed? */
  252. int system;
  253. int sense;
  254. #define SENSE_INVALID 0
  255. #define SENSE_GLOBAL 1
  256. #define SENSE_LOCAL 2
  257. char datum[6];
  258. double dx, dy, dz;
  259. } reference;
  260. struct { /* data from type 5 messages */
  261. unsigned int nentries;
  262. struct consat_t {
  263. unsigned ident; /* satellite ID */
  264. bool iodl; /* issue of data */
  265. unsigned int health; /* is satellite healthy? */
  266. #define HEALTH_NORMAL (0) /* Radiobeacon operation normal */
  267. #define HEALTH_UNMONITORED (1) /* No integrity monitor operating */
  268. #define HEALTH_NOINFO (2) /* No information available */
  269. #define HEALTH_DONOTUSE (3) /* Do not use this radiobeacon */
  270. int snr; /* signal-to-noise ratio, dB */
  271. #define SNR_BAD -1 /* not reported */
  272. bool health_en; /* health enabled */
  273. bool new_data; /* new data? */
  274. bool los_warning; /* line-of-sight warning */
  275. unsigned int tou; /* time to unhealth, seconds */
  276. } sat[MAXHEALTH];
  277. } conhealth;
  278. struct { /* data from type 7 messages */
  279. unsigned int nentries;
  280. struct station_t {
  281. double latitude, longitude; /* location */
  282. unsigned int range; /* range in km */
  283. double frequency; /* broadcast freq */
  284. unsigned int health; /* station health */
  285. unsigned int station_id; /* of the transmitter */
  286. unsigned int bitrate; /* of station transmissions */
  287. } station[MAXSTATIONS];
  288. } almanac;
  289. struct { /* data for type 13 messages */
  290. bool status; /* expect a text message */
  291. bool rangeflag; /* station range altered? */
  292. double lat, lon; /* station longitude/latitude */
  293. unsigned int range; /* transmission range in km */
  294. } xmitter;
  295. struct { /* data from type 14 messages */
  296. unsigned int week; /* GPS week (0-1023) */
  297. unsigned int hour; /* Hour in week (0-167) */
  298. unsigned int leapsecs; /* Leap seconds (0-63) */
  299. } gpstime;
  300. struct {
  301. unsigned int nentries;
  302. struct glonass_rangesat_t { /* data from message type 31 */
  303. unsigned ident; /* satellite ID */
  304. unsigned udre; /* user diff. range error */
  305. unsigned tod; /* issue of data */
  306. bool change; /* ephemeris change bit */
  307. double prc; /* range error */
  308. double rrc; /* range error rate */
  309. } sat[MAXCORRECTIONS];
  310. } glonass_ranges;
  311. /* data from type 16 messages */
  312. char message[(RTCM2_WORDS_MAX-2) * sizeof(isgps30bits_t)];
  313. /* data from messages of unknown type */
  314. isgps30bits_t words[RTCM2_WORDS_MAX-2];
  315. };
  316. };
  317. /* RTCM3 report structures begin here */
  318. #define RTCM3_MAX_SATELLITES 64
  319. #define RTCM3_MAX_DESCRIPTOR 31
  320. #define RTCM3_MAX_ANNOUNCEMENTS 32
  321. struct rtcm3_rtk_hdr { /* header data from 1001, 1002, 1003, 1004 */
  322. /* Used for both GPS and GLONASS, but their timebases differ */
  323. unsigned int station_id; /* Reference Station ID */
  324. time_t tow; /* GPS Epoch Time (TOW) in ms,
  325. or GLONASS Epoch Time in ms */
  326. bool sync; /* Synchronous GNSS Message Flag */
  327. unsigned short satcount; /* # Satellite Signals Processed */
  328. bool smoothing; /* Divergence-free Smoothing Indicator */
  329. unsigned int interval; /* Smoothing Interval */
  330. };
  331. struct rtcm3_basic_rtk {
  332. unsigned char indicator; /* Indicator */
  333. unsigned int channel; /* Satellite Frequency Channel Number
  334. (GLONASS only) */
  335. double pseudorange; /* Pseudorange */
  336. double rangediff; /* PhaseRange - Pseudorange in meters */
  337. unsigned char locktime; /* Lock time Indicator */
  338. };
  339. struct rtcm3_extended_rtk {
  340. unsigned char indicator; /* Indicator */
  341. unsigned int channel; /* Satellite Frequency Channel Number
  342. (GLONASS only) */
  343. double pseudorange; /* Pseudorange */
  344. double rangediff; /* PhaseRange - L1 Pseudorange */
  345. unsigned char locktime; /* Lock time Indicator */
  346. unsigned char ambiguity; /* Integer Pseudorange
  347. Modulus Ambiguity */
  348. double CNR; /* Carrier-to-Noise Ratio */
  349. };
  350. struct rtcm3_network_rtk_header {
  351. unsigned int network_id; /* Network ID */
  352. unsigned int subnetwork_id; /* Subnetwork ID */
  353. time_t time; /* GPS Epoch Time (TOW) in ms */
  354. bool multimesg; /* GPS Multiple Message Indicator */
  355. unsigned master_id; /* Master Reference Station ID */
  356. unsigned aux_id; /* Auxilary Reference Station ID */
  357. unsigned char satcount; /* count of GPS satellites */
  358. };
  359. struct rtcm3_correction_diff {
  360. unsigned char ident; /* satellite ID */
  361. enum {reserved, correct, widelane, uncertain} ambiguity;
  362. unsigned char nonsync;
  363. double geometric_diff; /* Geometric Carrier Phase
  364. Correction Difference (1016, 1017) */
  365. unsigned char iode; /* GPS IODE (1016, 1017) */
  366. double ionospheric_diff; /* Ionospheric Carrier Phase
  367. Correction Difference (1015, 1017) */
  368. };
  369. struct rtcm3_t {
  370. /* header contents */
  371. unsigned type; /* RTCM 3.x message type */
  372. unsigned length; /* payload length, inclusive of checksum */
  373. union {
  374. /* 1001-1013 were present in the 3.0 version */
  375. struct {
  376. struct rtcm3_rtk_hdr header;
  377. struct rtcm3_1001_t {
  378. unsigned ident; /* Satellite ID */
  379. struct rtcm3_basic_rtk L1;
  380. } rtk_data[RTCM3_MAX_SATELLITES];
  381. } rtcm3_1001;
  382. struct {
  383. struct rtcm3_rtk_hdr header;
  384. struct rtcm3_1002_t {
  385. unsigned ident; /* Satellite ID */
  386. struct rtcm3_extended_rtk L1;
  387. } rtk_data[RTCM3_MAX_SATELLITES];
  388. } rtcm3_1002;
  389. struct rtcm3_1003_t {
  390. struct rtcm3_rtk_hdr header;
  391. struct {
  392. unsigned ident; /* Satellite ID */
  393. struct rtcm3_basic_rtk L1;
  394. struct rtcm3_basic_rtk L2;
  395. } rtk_data[RTCM3_MAX_SATELLITES];
  396. } rtcm3_1003;
  397. struct rtcm3_1004_t {
  398. struct rtcm3_rtk_hdr header;
  399. struct {
  400. unsigned ident; /* Satellite ID */
  401. struct rtcm3_extended_rtk L1;
  402. struct rtcm3_extended_rtk L2;
  403. } rtk_data[RTCM3_MAX_SATELLITES];
  404. } rtcm3_1004;
  405. struct rtcm3_1005_t {
  406. unsigned int station_id; /* Reference Station ID */
  407. int system; /* Which system is it? */
  408. bool reference_station; /* Reference-station indicator */
  409. bool single_receiver; /* Single Receiver Oscillator */
  410. double ecef_x, ecef_y, ecef_z; /* ECEF antenna location */
  411. } rtcm3_1005;
  412. struct rtcm3_1006_t {
  413. unsigned int station_id; /* Reference Station ID */
  414. int system; /* Which system is it? */
  415. bool reference_station; /* Reference-station indicator */
  416. bool single_receiver; /* Single Receiver Oscillator */
  417. double ecef_x, ecef_y, ecef_z; /* ECEF antenna location */
  418. double height; /* Antenna height */
  419. } rtcm3_1006;
  420. struct {
  421. unsigned int station_id; /* Reference Station ID */
  422. char descriptor[RTCM3_MAX_DESCRIPTOR+1]; /* Description string */
  423. unsigned int setup_id;
  424. } rtcm3_1007;
  425. struct {
  426. unsigned int station_id; /* Reference Station ID */
  427. char descriptor[RTCM3_MAX_DESCRIPTOR+1]; /* Description string */
  428. unsigned int setup_id;
  429. char serial[RTCM3_MAX_DESCRIPTOR+1]; /* Serial # string */
  430. } rtcm3_1008;
  431. struct {
  432. struct rtcm3_rtk_hdr header;
  433. struct rtcm3_1009_t {
  434. unsigned ident; /* Satellite ID */
  435. struct rtcm3_basic_rtk L1;
  436. } rtk_data[RTCM3_MAX_SATELLITES];
  437. } rtcm3_1009;
  438. struct {
  439. struct rtcm3_rtk_hdr header;
  440. struct rtcm3_1010_t {
  441. unsigned ident; /* Satellite ID */
  442. struct rtcm3_extended_rtk L1;
  443. } rtk_data[RTCM3_MAX_SATELLITES];
  444. } rtcm3_1010;
  445. struct {
  446. struct rtcm3_rtk_hdr header;
  447. struct rtcm3_1011_t {
  448. unsigned ident; /* Satellite ID */
  449. struct rtcm3_extended_rtk L1;
  450. struct rtcm3_extended_rtk L2;
  451. } rtk_data[RTCM3_MAX_SATELLITES];
  452. } rtcm3_1011;
  453. struct {
  454. struct rtcm3_rtk_hdr header;
  455. struct rtcm3_1012_t {
  456. unsigned ident; /* Satellite ID */
  457. struct rtcm3_extended_rtk L1;
  458. struct rtcm3_extended_rtk L2;
  459. } rtk_data[RTCM3_MAX_SATELLITES];
  460. } rtcm3_1012;
  461. struct {
  462. unsigned int station_id; /* Reference Station ID */
  463. unsigned short mjd; /* Modified Julian Day (MJD) Number */
  464. unsigned int sod; /* Seconds of Day (UTC) */
  465. unsigned char leapsecs; /* Leap Seconds, GPS-UTC */
  466. unsigned char ncount; /* Count of announcements to follow */
  467. struct rtcm3_1013_t {
  468. unsigned short id; /* message type ID */
  469. bool sync;
  470. unsigned short interval; /* interval in 0.1sec units */
  471. } announcements[RTCM3_MAX_ANNOUNCEMENTS];
  472. } rtcm3_1013;
  473. /* 1014-1017 were added in the 3.1 version */
  474. struct rtcm3_1014_t {
  475. unsigned int network_id; /* Network ID */
  476. unsigned int subnetwork_id; /* Subnetwork ID */
  477. unsigned int stationcount; /* # auxiliary stations transmitted */
  478. unsigned int master_id; /* Master Reference Station ID */
  479. unsigned int aux_id; /* Auxilary Reference Station ID */
  480. double d_lat, d_lon, d_alt; /* Aux-master location delta */
  481. } rtcm3_1014;
  482. struct rtcm3_1015_t {
  483. struct rtcm3_network_rtk_header header;
  484. struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
  485. } rtcm3_1015;
  486. struct rtcm3_1016_t {
  487. struct rtcm3_network_rtk_header header;
  488. struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
  489. } rtcm3_1016;
  490. struct rtcm3_1017_t {
  491. struct rtcm3_network_rtk_header header;
  492. struct rtcm3_correction_diff corrections[RTCM3_MAX_SATELLITES];
  493. } rtcm3_1017;
  494. /* 1018-1029 were in the 3.0 version */
  495. struct rtcm3_1019_t {
  496. unsigned int ident; /* Satellite ID */
  497. unsigned int week; /* GPS Week Number */
  498. unsigned char sv_accuracy; /* GPS SV ACCURACY */
  499. enum {reserved_code, p, ca, l2c} code;
  500. double idot;
  501. unsigned char iode;
  502. /* ephemeris fields, not scaled */
  503. unsigned int t_sub_oc;
  504. signed int a_sub_f2;
  505. signed int a_sub_f1;
  506. signed int a_sub_f0;
  507. unsigned int iodc;
  508. signed int C_sub_rs;
  509. signed int delta_sub_n;
  510. signed int M_sub_0;
  511. signed int C_sub_uc;
  512. unsigned int e;
  513. signed int C_sub_us;
  514. unsigned int sqrt_sub_A;
  515. unsigned int t_sub_oe;
  516. signed int C_sub_ic;
  517. signed int OMEGA_sub_0;
  518. signed int C_sub_is;
  519. signed int i_sub_0;
  520. signed int C_sub_rc;
  521. signed int argument_of_perigee;
  522. signed int omegadot;
  523. signed int t_sub_GD;
  524. unsigned char sv_health;
  525. bool p_data;
  526. bool fit_interval;
  527. } rtcm3_1019;
  528. struct rtcm3_1020_t {
  529. unsigned int ident; /* Satellite ID */
  530. unsigned short channel; /* Satellite Frequency Channel Number */
  531. /* ephemeris fields, not scaled */
  532. bool C_sub_n;
  533. bool health_avAilability_indicator;
  534. unsigned char P1;
  535. unsigned short t_sub_k;
  536. bool msb_of_B_sub_n;
  537. bool P2;
  538. bool t_sub_b;
  539. signed int x_sub_n_t_of_t_sub_b_prime;
  540. signed int x_sub_n_t_of_t_sub_b;
  541. signed int x_sub_n_t_of_t_sub_b_prime_prime;
  542. signed int y_sub_n_t_of_t_sub_b_prime;
  543. signed int y_sub_n_t_of_t_sub_b;
  544. signed int y_sub_n_t_of_t_sub_b_prime_prime;
  545. signed int z_sub_n_t_of_t_sub_b_prime;
  546. signed int z_sub_n_t_of_t_sub_b;
  547. signed int z_sub_n_t_of_t_sub_b_prime_prime;
  548. bool P3;
  549. signed int gamma_sub_n_of_t_sub_b;
  550. unsigned char MP;
  551. bool Ml_n;
  552. signed int tau_n_of_t_sub_b;
  553. signed int M_delta_tau_sub_n;
  554. unsigned int E_sub_n;
  555. bool MP4;
  556. unsigned char MF_sub_T;
  557. unsigned char MN_sub_T;
  558. unsigned char MM;
  559. bool additioinal_data_availability;
  560. unsigned int N_sup_A;
  561. unsigned int tau_sub_c;
  562. unsigned int M_N_sub_4;
  563. signed int M_tau_sub_GPS;
  564. bool M_l_sub_n;
  565. } rtcm3_1020;
  566. struct rtcm3_1029_t {
  567. unsigned int station_id; /* Reference Station ID */
  568. unsigned short mjd; /* Modified Julian Day (MJD) Number */
  569. unsigned int sod; /* Seconds of Day (UTC) */
  570. size_t len; /* # chars to follow */
  571. size_t unicode_units; /* # Unicode units in text */
  572. unsigned char text[128];
  573. } rtcm3_1029;
  574. struct rtcm3_1033_t {
  575. unsigned int station_id; /* Reference Station ID */
  576. char descriptor[RTCM3_MAX_DESCRIPTOR+1]; /* Description string */
  577. unsigned int setup_id;
  578. char serial[RTCM3_MAX_DESCRIPTOR+1]; /* Serial # string */
  579. char receiver[RTCM3_MAX_DESCRIPTOR+1]; /* Receiver string */
  580. char firmware[RTCM3_MAX_DESCRIPTOR+1]; /* Firmware string */
  581. } rtcm3_1033;
  582. unsigned char data[1024]; /* Max RTCM3 msg length is 1023 bytes */
  583. } rtcmtypes;
  584. };
  585. /* RTCM3 scaling constants */
  586. #define GPS_AMBIGUITY_MODULUS 299792.458 /* 1004, DF014*/
  587. #define GLONASS_AMBIGUITY_MODULUS 599584.916 /* 1012, DF044 */
  588. #define MESSAGE_INTERVAL_UNITS 0.1 /* 1013, DF047 */
  589. /*
  590. * Raw IS_GPS subframe data
  591. */
  592. /* The almanac is a subset of the clock and ephemeris data, with reduced
  593. * precision. See IS-GPS-200E, Table 20-VI */
  594. struct almanac_t
  595. {
  596. uint8_t sv; /* The satellite this refers to */
  597. /* toa, almanac reference time, 8 bits unsigned, seconds */
  598. uint8_t toa;
  599. long l_toa;
  600. /* SV health data, 8 bit unsigned bit map */
  601. uint8_t svh;
  602. /* deltai, correction to inclination, 16 bits signed, semi-circles */
  603. int16_t deltai;
  604. double d_deltai;
  605. /* M0, Mean Anomaly at Reference Time, 24 bits signed, semi-circles */
  606. int32_t M0;
  607. double d_M0;
  608. /* Omega0, Longitude of Ascending Node of Orbit Plane at Weekly Epoch,
  609. * 24 bits signed, semi-circles */
  610. int32_t Omega0;
  611. double d_Omega0;
  612. /* omega, Argument of Perigee, 24 bits signed, semi-circles */
  613. int32_t omega;
  614. double d_omega;
  615. /* af0, SV clock correction constant term
  616. * 11 bits signed, seconds */
  617. int16_t af0;
  618. double d_af0;
  619. /* af1, SV clock correction first order term
  620. * 11 bits signed, seconds/second */
  621. int16_t af1;
  622. double d_af1;
  623. /* eccentricity, 16 bits, unsigned, dimensionless */
  624. uint16_t e;
  625. double d_eccentricity;
  626. /* sqrt A, Square Root of the Semi-Major Axis
  627. * 24 bits unsigned, square_root(meters) */
  628. uint32_t sqrtA;
  629. double d_sqrtA;
  630. /* Omega dot, Rate of Right Ascension, 16 bits signed, semi-circles/sec */
  631. int16_t Omegad;
  632. double d_Omegad;
  633. };
  634. struct subframe_t {
  635. /* subframe number, 3 bits, unsigned, 1 to 5 */
  636. uint8_t subframe_num;
  637. /* data_id, denotes the NAV data structure of D(t), 2 bits, in
  638. * IS-GPS-200E always == 0x1 */
  639. uint8_t data_id;
  640. /* SV/page id used for subframes 4 & 5, 6 bits */
  641. uint8_t pageid;
  642. /* tSVID, SV ID of the sat that transmitted this frame, 6 bits unsigned */
  643. uint8_t tSVID;
  644. /* TOW, Time of Week of NEXT message, 17 bits unsigned, scale 6, seconds */
  645. uint32_t TOW17;
  646. long l_TOW17;
  647. /* integrity, URA bounds flag, 1 bit */
  648. bool integrity;
  649. /* alert, alert flag, SV URA and/or the SV User Differential Range
  650. * Accuracy (UDRA) may be worse than indicated, 1 bit */
  651. bool alert;
  652. /* antispoof, A-S mode is ON in that SV, 1 bit */
  653. bool antispoof;
  654. int is_almanac;
  655. union {
  656. /* subframe 1, part of ephemeris, see IS-GPS-200E, Table 20-II
  657. * and Table 20-I */
  658. struct {
  659. /* WN, Week Number, 10 bits unsigned, scale 1, weeks */
  660. uint16_t WN;
  661. /* IODC, Issue of Data, Clock, 10 bits, unsigned,
  662. * issued in 8 data ranges at the same time */
  663. uint16_t IODC;
  664. /* toc, clock data reference time, 16 bits, unsigned, seconds
  665. * scale 2**4, issued in 8 data ranges at the same time */
  666. uint16_t toc;
  667. long l_toc;
  668. /* l2, code on L2, 2 bits, bit map */
  669. uint8_t l2;
  670. /* l2p, L2 P data flag, 1 bit */
  671. uint8_t l2p;
  672. /* ura, SV accuracy, 4 bits unsigned index */
  673. unsigned int ura;
  674. /* hlth, SV health, 6 bits unsigned bitmap */
  675. unsigned int hlth;
  676. /* af0, SV clock correction constant term
  677. * 22 bits signed, scale 2**-31, seconds */
  678. int32_t af0;
  679. double d_af0;
  680. /* af1, SV clock correction first order term
  681. * 22 bits signed, scale 2**-43, seconds/second */
  682. int16_t af1;
  683. double d_af1;
  684. /* af2, SV clock correction second order term
  685. * 8 bits signed, scale 2**-55, seconds/second**2 */
  686. int8_t af2;
  687. double d_af2;
  688. /* Tgd, L1-L2 correction term, 8 bits signed, scale 2**-31,
  689. * seconds */
  690. int8_t Tgd;
  691. double d_Tgd;
  692. } sub1;
  693. /* subframe 2, part of ephemeris, see IS-GPS-200E, Table 20-II
  694. * and Table 20-III */
  695. struct {
  696. /* Issue of Data (Ephemeris),
  697. * equal to the 8 LSBs of the 10 bit IODC of the same data set */
  698. uint8_t IODE;
  699. /* Age of Data Offset for the NMCT, 6 bits, scale 900,
  700. * ignore if all ones, seconds */
  701. uint8_t AODO;
  702. uint16_t u_AODO;
  703. /* fit, FIT interval flag, indicates a fit interval greater than
  704. * 4 hour, 1 bit */
  705. uint8_t fit;
  706. /* toe, Reference Time Ephemeris, 16 bits unsigned, scale 2**4,
  707. * seconds */
  708. uint16_t toe;
  709. long l_toe;
  710. /* Crs, Amplitude of the Sine Harmonic Correction Term to the
  711. * Orbit Radius, 16 bits, scale 2**-5, signed, meters */
  712. int16_t Crs;
  713. double d_Crs;
  714. /* Cus, Amplitude of the Sine Harmonic Correction Term to the
  715. * Argument of Latitude, 16 bits, signed, scale 2**-29, radians */
  716. int16_t Cus;
  717. double d_Cus;
  718. /* Cuc, Amplitude of the Cosine Harmonic Correction Term to the
  719. * Argument of Latitude, 16 bits, signed, scale 2**-29, radians */
  720. int16_t Cuc;
  721. double d_Cuc;
  722. /* deltan, Mean Motion Difference From Computed Value
  723. * Mean Motion Difference From Computed Value
  724. * 16 bits, signed, scale 2**-43, semi-circles/sec */
  725. int16_t deltan;
  726. double d_deltan;
  727. /* M0, Mean Anomaly at Reference Time, 32 bits signed,
  728. * scale 2**-31, semi-circles */
  729. int32_t M0;
  730. double d_M0;
  731. /* eccentricity, 32 bits, unsigned, scale 2**-33, dimensionless */
  732. uint32_t e;
  733. double d_eccentricity;
  734. /* sqrt A, Square Root of the Semi-Major Axis
  735. * 32 bits unsigned, scale 2**-19, square_root(meters) */
  736. uint32_t sqrtA;
  737. double d_sqrtA;
  738. } sub2;
  739. /* subframe 3, part of ephemeris, see IS-GPS-200E, Table 20-II,
  740. * Table 20-III */
  741. struct {
  742. /* Issue of Data (Ephemeris), 8 bits, unsigned
  743. * equal to the 8 LSBs of the 10 bit IODC of the same data set */
  744. uint8_t IODE;
  745. /* Rate of Inclination Angle, 14 bits signed, scale2**-43,
  746. * semi-circles/sec */
  747. int16_t IDOT;
  748. double d_IDOT;
  749. /* Cic, Amplitude of the Cosine Harmonic Correction Term to the
  750. * Angle of Inclination, 16 bits signed, scale 2**-29, radians*/
  751. int16_t Cic;
  752. double d_Cic;
  753. /* Cis, Amplitude of the Sine Harmonic Correction Term to the
  754. * Angle of Inclination, 16 bits, unsigned, scale 2**-29, radians */
  755. int16_t Cis;
  756. double d_Cis;
  757. /* Crc, Amplitude of the Cosine Harmonic Correction Term to the
  758. * Orbit Radius, 16 bits signed, scale 2**-5, meters */
  759. int16_t Crc;
  760. double d_Crc;
  761. /* i0, Inclination Angle at Reference Time, 32 bits, signed,
  762. * scale 2**-31, semi-circles */
  763. int32_t i0;
  764. double d_i0;
  765. /* Omega0, Longitude of Ascending Node of Orbit Plane at Weekly
  766. * Epoch, 32 bits signed, semi-circles */
  767. int32_t Omega0;
  768. double d_Omega0;
  769. /* omega, Argument of Perigee, 32 bits signed, scale 2**-31,
  770. * semi-circles */
  771. int32_t omega;
  772. double d_omega;
  773. /* Omega dot, Rate of Right Ascension, 24 bits signed,
  774. * scale 2**-43, semi-circles/sec */
  775. int32_t Omegad;
  776. double d_Omegad;
  777. } sub3;
  778. struct {
  779. struct almanac_t almanac;
  780. } sub4;
  781. /* subframe 4, page 13 */
  782. struct {
  783. /* mapping ord ERD# to SV # is non trivial
  784. * leave it alone. See IS-GPS-200E Section 20.3.3.5.1.9 */
  785. /* Estimated Range Deviation, 6 bits signed, meters */
  786. char ERD[33];
  787. /* ai, Availability Indicator, 2bits, bit map */
  788. unsigned char ai;
  789. } sub4_13;
  790. /* subframe 4, page 17, system message, 23 chars, plus nul */
  791. struct {
  792. char str[24];
  793. } sub4_17;
  794. /* subframe 4, page 18 */
  795. struct {
  796. /* ionospheric and UTC data */
  797. /* A0, Bias coefficient of GPS time scale relative to UTC time
  798. * scale, 32 bits signed, scale 2**-30, seconds */
  799. int32_t A0;
  800. double d_A0;
  801. /* A1, Drift coefficient of GPS time scale relative to UTC time
  802. * scale, 24 bits signed, scale 2**-50, seconds/second */
  803. int32_t A1;
  804. double d_A1;
  805. /* alphaX, the four coefficients of a cubic equation representing
  806. * the amplitude of the vertical delay */
  807. /* alpha0, 8 bits signed, scale w**-30, seconds */
  808. int8_t alpha0;
  809. double d_alpha0;
  810. /* alpha1, 8 bits signed, scale w**-27, seconds/semi-circle */
  811. int8_t alpha1;
  812. double d_alpha1;
  813. /* alpha2, 8 bits signed, scale w**-24, seconds/semi-circle**2 */
  814. int8_t alpha2;
  815. double d_alpha2;
  816. /* alpha3, 8 bits signed, scale w**-24, seconds/semi-circle**3 */
  817. int8_t alpha3;
  818. double d_alpha3;
  819. /* betaX, the four coefficients of a cubic equation representing
  820. * the period of the model */
  821. /* beta0, 8 bits signed, scale w**11, seconds */
  822. int8_t beta0;
  823. double d_beta0;
  824. /* beta1, 8 bits signed, scale w**14, seconds/semi-circle */
  825. int8_t beta1;
  826. double d_beta1;
  827. /* beta2, 8 bits signed, scale w**16, seconds/semi-circle**2 */
  828. int8_t beta2;
  829. double d_beta2;
  830. /* beta3, 8 bits signed, scale w**16, seconds/semi-circle**3 */
  831. int8_t beta3;
  832. double d_beta3;
  833. /* leap (delta t ls), current leap second, 8 bits signed,
  834. * scale 1, seconds */
  835. int8_t leap;
  836. /* lsf (delta t lsf), future leap second, 8 bits signed,
  837. * scale 1, seconds */
  838. int8_t lsf;
  839. /* tot, reference time for UTC data,
  840. * 8 bits unsigned, scale 2**12, seconds */
  841. uint8_t tot;
  842. time_t t_tot;
  843. /* WNt, UTC reference week number, 8 bits unsigned, scale 1,
  844. * weeks */
  845. uint8_t WNt;
  846. /* WNlsf, Leap second reference Week Number,
  847. * 8 bits unsigned, scale 1, weeks */
  848. uint8_t WNlsf;
  849. /* DN, Leap second reference Day Number , 8 bits unsigned,
  850. * scale 1, days */
  851. uint8_t DN;
  852. } sub4_18;
  853. /* subframe 4, page 25 */
  854. struct {
  855. /* svf, A-S status and the configuration code of each SV
  856. * 4 bits unsigned, bitmap */
  857. unsigned char svf[33];
  858. /* svh, SV health data for SV 25 through 32
  859. * 6 bits unsigned bitmap */
  860. uint8_t svhx[8];
  861. } sub4_25;
  862. struct {
  863. struct almanac_t almanac;
  864. } sub5;
  865. struct {
  866. /* toa, Almanac reference Time, 8 bits unsigned, scale 2**12,
  867. * seconds */
  868. uint8_t toa;
  869. long l_toa;
  870. /* WNa, Week Number almanac, 8 bits, scale 2, GPS Week
  871. * Number % 256 */
  872. uint8_t WNa;
  873. /* sv, SV health status, 6 bits, bitmap */
  874. uint8_t sv[25];
  875. } sub5_25;
  876. };
  877. };
  878. typedef uint64_t gps_mask_t;
  879. /*
  880. * Is an MMSI number that of an auxiliary associated with a mother ship?
  881. * We need to be able to test this for decoding AIS Type 24 messages.
  882. * According to <http://www.navcen.uscg.gov/marcomms/gmdss/mmsi.htm#format>,
  883. * auxiliary-craft MMSIs have the form 98MIDXXXX, where MID is a country
  884. * code and XXXX the vessel ID.
  885. */
  886. #define AIS_AUXILIARY_MMSI(n) ((n) / 10000000 == 98)
  887. /* N/A values and scaling constant for 25/24 bit lon/lat pairs */
  888. #define AIS_LON3_NOT_AVAILABLE 181000
  889. #define AIS_LAT3_NOT_AVAILABLE 91000
  890. #define AIS_LATLON3_DIV 60000.0
  891. /* N/A values and scaling constant for 28/27 bit lon/lat pairs */
  892. #define AIS_LON4_NOT_AVAILABLE 1810000
  893. #define AIS_LAT4_NOT_AVAILABLE 910000
  894. #define AIS_LATLON4_DIV 600000.0
  895. struct route_info {
  896. unsigned int linkage; /* Message Linkage ID */
  897. unsigned int sender; /* Sender Class */
  898. unsigned int rtype; /* Route Type */
  899. unsigned int month; /* Start month */
  900. unsigned int day; /* Start day */
  901. unsigned int hour; /* Start hour */
  902. unsigned int minute; /* Start minute */
  903. unsigned int duration; /* Duration */
  904. int waycount; /* Waypoint count */
  905. struct waypoint_t {
  906. signed int lon; /* Longitude */
  907. signed int lat; /* Latitude */
  908. } waypoints[16];
  909. };
  910. struct ais_t
  911. {
  912. unsigned int type; /* message type */
  913. unsigned int repeat; /* Repeat indicator */
  914. unsigned int mmsi; /* MMSI */
  915. union {
  916. /* Types 1-3 Common navigation info */
  917. struct {
  918. unsigned int status; /* navigation status */
  919. signed turn; /* rate of turn */
  920. #define AIS_TURN_HARD_LEFT -127
  921. #define AIS_TURN_HARD_RIGHT 127
  922. #define AIS_TURN_NOT_AVAILABLE 128
  923. unsigned int speed; /* speed over ground in deciknots */
  924. #define AIS_SPEED_NOT_AVAILABLE 1023
  925. #define AIS_SPEED_FAST_MOVER 1022 /* >= 102.2 knots */
  926. bool accuracy; /* position accuracy */
  927. #define AIS_LATLON_DIV 600000.0
  928. int lon; /* longitude */
  929. #define AIS_LON_NOT_AVAILABLE 0x6791AC0
  930. int lat; /* latitude */
  931. #define AIS_LAT_NOT_AVAILABLE 0x3412140
  932. unsigned int course; /* course over ground */
  933. #define AIS_COURSE_NOT_AVAILABLE 3600
  934. unsigned int heading; /* true heading */
  935. #define AIS_HEADING_NOT_AVAILABLE 511
  936. /* seconds of UTC time, 0 to 59.
  937. * 60 == N/A, 61 == manual, 62 == dead reckoning,
  938. * 63 == inoperative */
  939. unsigned int second;
  940. #define AIS_SEC_NOT_AVAILABLE 60
  941. #define AIS_SEC_MANUAL 61
  942. #define AIS_SEC_ESTIMATED 62
  943. #define AIS_SEC_INOPERATIVE 63
  944. unsigned int maneuver; /* maneuver indicator */
  945. //unsigned int spare; spare bits */
  946. bool raim; /* RAIM flag */
  947. unsigned int radio; /* radio status bits */
  948. } type1;
  949. /* Type 4 - Base Station Report & Type 11 - UTC and Date Response */
  950. struct {
  951. unsigned int year; /* UTC year */
  952. #define AIS_YEAR_NOT_AVAILABLE 0
  953. unsigned int month; /* UTC month */
  954. #define AIS_MONTH_NOT_AVAILABLE 0
  955. unsigned int day; /* UTC day */
  956. #define AIS_DAY_NOT_AVAILABLE 0
  957. unsigned int hour; /* UTC hour */
  958. #define AIS_HOUR_NOT_AVAILABLE 24
  959. unsigned int minute; /* UTC minute */
  960. #define AIS_MINUTE_NOT_AVAILABLE 60
  961. unsigned int second; /* UTC second */
  962. #define AIS_SECOND_NOT_AVAILABLE 60
  963. bool accuracy; /* fix quality */
  964. int lon; /* longitude */
  965. int lat; /* latitude */
  966. unsigned int epfd; /* type of position fix device */
  967. //unsigned int spare; spare bits */
  968. bool raim; /* RAIM flag */
  969. unsigned int radio; /* radio status bits */
  970. } type4;
  971. /* Type 5 - Ship static and voyage related data */
  972. struct {
  973. unsigned int ais_version; /* AIS version level */
  974. unsigned int imo; /* IMO identification */
  975. // cppcheck-suppress arrayIndexOutOfBounds
  976. char callsign[7+1]; /* callsign */
  977. #define AIS_SHIPNAME_MAXLEN 20
  978. // cppcheck-suppress arrayIndexOutOfBounds
  979. char shipname[AIS_SHIPNAME_MAXLEN+1]; /* vessel name */
  980. unsigned int shiptype; /* ship type code */
  981. unsigned int to_bow; /* dimension to bow */
  982. unsigned int to_stern; /* dimension to stern */
  983. unsigned int to_port; /* dimension to port */
  984. unsigned int to_starboard; /* dimension to starboard */
  985. unsigned int epfd; /* type of position fix deviuce */
  986. unsigned int month; /* UTC month */
  987. unsigned int day; /* UTC day */
  988. unsigned int hour; /* UTC hour */
  989. unsigned int minute; /* UTC minute */
  990. unsigned int draught; /* draft in meters */
  991. char destination[20+1]; /* ship destination */
  992. unsigned int dte; /* data terminal enable */
  993. //unsigned int spare; spare bits */
  994. } type5;
  995. /* Type 6 - Addressed Binary Message */
  996. struct {
  997. unsigned int seqno; /* sequence number */
  998. unsigned int dest_mmsi; /* destination MMSI */
  999. bool retransmit; /* retransmit flag */
  1000. //unsigned int spare; spare bit(s) */
  1001. unsigned int dac; /* Application ID */
  1002. unsigned int fid; /* Functional ID */
  1003. bool structured; /* True match for DAC/FID? */
  1004. #define AIS_TYPE6_BINARY_MAX 920 /* 920 bits */
  1005. size_t bitcount; /* bit count of the data */
  1006. union {
  1007. // cppcheck-suppress arrayIndexOutOfBounds
  1008. char bitdata[(AIS_TYPE6_BINARY_MAX + 7) / 8];
  1009. /* Inland AIS - ETA at lock/bridge/terminal */
  1010. struct {
  1011. char country[2+1]; /* UN Country Code */
  1012. char locode[3+1]; /* UN/LOCODE */
  1013. char section[5+1]; /* Fairway section */
  1014. char terminal[5+1]; /* Terminal code */
  1015. char hectometre[5+1]; /* Fairway hectometre */
  1016. unsigned int month; /* ETA month */
  1017. unsigned int day; /* ETA day */
  1018. unsigned int hour; /* ETA hour */
  1019. unsigned int minute; /* ETA minute */
  1020. unsigned int tugs; /* Assisting Tugs */
  1021. unsigned int airdraught; /* Air Draught */
  1022. } dac200fid21;
  1023. /* Inland AIS - ETA at lock/bridge/terminal */
  1024. struct {
  1025. char country[2+1]; /* UN Country Code */
  1026. char locode[3+1]; /* UN/LOCODE */
  1027. char section[5+1]; /* Fairway section */
  1028. char terminal[5+1]; /* Terminal code */
  1029. char hectometre[5+1]; /* Fairway hectometre */
  1030. unsigned int month; /* RTA month */
  1031. unsigned int day; /* RTA day */
  1032. unsigned int hour; /* RTA hour */
  1033. unsigned int minute; /* RTA minute */
  1034. unsigned int status; /* Status */
  1035. #define DAC200FID22_STATUS_OPERATIONAL 0
  1036. #define DAC200FID22_STATUS_LIMITED 1
  1037. #define DAC200FID22_STATUS_OUT_OF_ORDER 2
  1038. #define DAC200FID22_STATUS_NOT_AVAILABLE 0
  1039. } dac200fid22;
  1040. /* Inland AIS - Number of persons on board */
  1041. struct {
  1042. unsigned int crew; /* # crew on board */
  1043. unsigned int passengers; /* # passengers on board */
  1044. unsigned int personnel; /* # personnel on board */
  1045. #define DAC200FID55_COUNT_NOT_AVAILABLE 255
  1046. } dac200fid55;
  1047. /* GLA - AtoN monitoring data (UK/ROI) */
  1048. struct {
  1049. unsigned int ana_int; /* Analogue (internal) */
  1050. unsigned int ana_ext1; /* Analogue (external #1) */
  1051. unsigned int ana_ext2; /* Analogue (external #2) */
  1052. unsigned int racon; /* RACON status */
  1053. unsigned int light; /* Light status */
  1054. bool alarm; /* Health alarm*/
  1055. unsigned int stat_ext; /* Status bits (external) */
  1056. bool off_pos; /* Off position status */
  1057. } dac235fid10;
  1058. /* IMO236 - Dangerous Cargo Indication */
  1059. struct {
  1060. char lastport[5+1]; /* Last Port Of Call */
  1061. unsigned int lmonth; /* ETA month */
  1062. unsigned int lday; /* ETA day */
  1063. unsigned int lhour; /* ETA hour */
  1064. unsigned int lminute; /* ETA minute */
  1065. char nextport[5+1]; /* Next Port Of Call */
  1066. unsigned int nmonth; /* ETA month */
  1067. unsigned int nday; /* ETA day */
  1068. unsigned int nhour; /* ETA hour */
  1069. unsigned int nminute; /* ETA minute */
  1070. char dangerous[20+1]; /* Main Dangerous Good */
  1071. char imdcat[4+1]; /* IMD Category */
  1072. unsigned int unid; /* UN Number */
  1073. unsigned int amount; /* Amount of Cargo */
  1074. unsigned int unit; /* Unit of Quantity */
  1075. } dac1fid12;
  1076. /* IMO236 - Extended Ship Static and Voyage Related Data */
  1077. struct {
  1078. unsigned int airdraught; /* Air Draught */
  1079. } dac1fid15;
  1080. /* IMO236 - Number of Persons on board */
  1081. struct {
  1082. unsigned persons; /* number of persons */
  1083. } dac1fid16;
  1084. /* IMO289 - Clearance Time To Enter Port */
  1085. struct {
  1086. unsigned int linkage; /* Message Linkage ID */
  1087. unsigned int month; /* Month (UTC) */
  1088. unsigned int day; /* Day (UTC) */
  1089. unsigned int hour; /* Hour (UTC) */
  1090. unsigned int minute; /* Minute (UTC) */
  1091. char portname[20+1]; /* Name of Port & Berth */
  1092. char destination[5+1]; /* Destination */
  1093. signed int lon; /* Longitude */
  1094. signed int lat; /* Latitude */
  1095. } dac1fid18;
  1096. /* IMO289 - Berthing Data (addressed) */
  1097. struct {
  1098. unsigned int linkage; /* Message Linkage ID */
  1099. unsigned int berth_length; /* Berth length */
  1100. unsigned int berth_depth; /* Berth Water Depth */
  1101. unsigned int position; /* Mooring Position */
  1102. unsigned int month; /* Month (UTC) */
  1103. unsigned int day; /* Day (UTC) */
  1104. unsigned int hour; /* Hour (UTC) */
  1105. unsigned int minute; /* Minute (UTC) */
  1106. unsigned int availability; /* Services Availability */
  1107. unsigned int agent; /* Agent */
  1108. unsigned int fuel; /* Bunker/fuel */
  1109. unsigned int chandler; /* Chandler */
  1110. unsigned int stevedore; /* Stevedore */
  1111. unsigned int electrical; /* Electrical */
  1112. unsigned int water; /* Potable water */
  1113. unsigned int customs; /* Customs house */
  1114. unsigned int cartage; /* Cartage */
  1115. unsigned int crane; /* Crane(s) */
  1116. unsigned int lift; /* Lift(s) */
  1117. unsigned int medical; /* Medical facilities */
  1118. unsigned int navrepair; /* Navigation repair */
  1119. unsigned int provisions; /* Provisions */
  1120. unsigned int shiprepair; /* Ship repair */
  1121. unsigned int surveyor; /* Surveyor */
  1122. unsigned int steam; /* Steam */
  1123. unsigned int tugs; /* Tugs */
  1124. unsigned int solidwaste; /* Waste disposal (solid) */
  1125. unsigned int liquidwaste; /* Waste disposal (liquid) */
  1126. unsigned int hazardouswaste; /* Waste disposal (hazardous) */
  1127. unsigned int ballast; /* Reserved ballast exchange */
  1128. unsigned int additional; /* Additional services */
  1129. unsigned int regional1; /* Regional reserved 1 */
  1130. unsigned int regional2; /* Regional reserved 2 */
  1131. unsigned int future1; /* Reserved for future */
  1132. unsigned int future2; /* Reserved for future */
  1133. char berth_name[20+1]; /* Name of Berth */
  1134. signed int berth_lon; /* Longitude */
  1135. signed int berth_lat; /* Latitude */
  1136. } dac1fid20;
  1137. /* IMO289 - Weather observation report from ship */
  1138. /*** WORK IN PROGRESS - NOT YET DECODED ***/
  1139. struct {
  1140. bool wmo; /* true if WMO variant */
  1141. union {
  1142. struct {
  1143. char location[20+1]; /* Location */
  1144. signed int lon; /* Longitude */
  1145. signed int lat; /* Latitude */
  1146. unsigned int day; /* Report day */
  1147. unsigned int hour; /* Report hour */
  1148. unsigned int minute; /* Report minute */
  1149. bool vislimit; /* Max range? */
  1150. unsigned int visibility; /* Units of 0.1 nm */
  1151. #define DAC1FID21_VISIBILITY_NOT_AVAILABLE 127
  1152. #define DAC1FID21_VISIBILITY_SCALE 10.0
  1153. unsigned humidity; /* units of 1% */
  1154. unsigned int wspeed; /* average wind speed */
  1155. unsigned int wgust; /* wind gust */
  1156. #define DAC1FID21_WSPEED_NOT_AVAILABLE 127
  1157. unsigned int wdir; /* wind direction */
  1158. #define DAC1FID21_WDIR_NOT_AVAILABLE 360
  1159. unsigned int pressure; /* air pressure, hpa */
  1160. #define DAC1FID21_NONWMO_PRESSURE_NOT_AVAILABLE 403
  1161. #define DAC1FID21_NONWMO_PRESSURE_HIGH 402 /* > 1200hPa */
  1162. #define DAC1FID21_NONWMO_PRESSURE_OFFSET 400 /* N/A */
  1163. unsigned int pressuretend; /* tendency */
  1164. int airtemp; /* temp, units 0.1C */
  1165. #define DAC1FID21_AIRTEMP_NOT_AVAILABLE -1024
  1166. #define DAC1FID21_AIRTEMP_SCALE 10.0
  1167. unsigned int watertemp; /* units 0.1degC */
  1168. #define DAC1FID21_WATERTEMP_NOT_AVAILABLE 501
  1169. #define DAC1FID21_WATERTEMP_SCALE 10.0
  1170. unsigned int waveperiod; /* in seconds */
  1171. #define DAC1FID21_WAVEPERIOD_NOT_AVAILABLE 63
  1172. unsigned int wavedir; /* direction in deg */
  1173. #define DAC1FID21_WAVEDIR_NOT_AVAILABLE 360
  1174. unsigned int swellheight; /* in decimeters */
  1175. unsigned int swellperiod; /* in seconds */
  1176. unsigned int swelldir; /* direction in deg */
  1177. } nonwmo_obs;
  1178. struct {
  1179. signed int lon; /* Longitude */
  1180. signed int lat; /* Latitude */
  1181. unsigned int month; /* UTC month */
  1182. unsigned int day; /* Report day */
  1183. unsigned int hour; /* Report hour */
  1184. unsigned int minute; /* Report minute */
  1185. unsigned int course; /* course over ground */
  1186. unsigned int speed; /* speed, m/s */
  1187. #define DAC1FID21_SOG_NOT_AVAILABLE 31
  1188. #define DAC1FID21_SOG_HIGH_SPEED 30
  1189. #define DAC1FID21_SOG_SCALE 2.0
  1190. unsigned int heading; /* true heading */
  1191. #define DAC1FID21_HDG_NOT_AVAILABLE 127
  1192. #define DAC1FID21_HDG_SCALE 5.0
  1193. unsigned int pressure; /* units of hPa * 0.1 */
  1194. #define DAC1FID21_WMO_PRESSURE_SCALE 10
  1195. #define DAC1FID21_WMO_PRESSURE_OFFSET 90.0
  1196. unsigned int pdelta; /* units of hPa * 0.1 */
  1197. #define DAC1FID21_PDELTA_SCALE 10
  1198. #define DAC1FID21_PDELTA_OFFSET 50.0
  1199. unsigned int ptend; /* enumerated */
  1200. unsigned int twinddir; /* in 5 degree steps */
  1201. #define DAC1FID21_TWINDDIR_NOT_AVAILABLE 127
  1202. unsigned int twindspeed; /* meters per second */
  1203. #define DAC1FID21_TWINDSPEED_SCALE 2
  1204. #define DAC1FID21_RWINDSPEED_NOT_AVAILABLE 255
  1205. unsigned int rwinddir; /* in 5 degree steps */
  1206. #define DAC1FID21_RWINDDIR_NOT_AVAILABLE 127
  1207. unsigned int rwindspeed; /* meters per second */
  1208. #define DAC1FID21_RWINDSPEED_SCALE 2
  1209. #define DAC1FID21_RWINDSPEED_NOT_AVAILABLE 255
  1210. unsigned int mgustspeed; /* meters per second */
  1211. #define DAC1FID21_MGUSTSPEED_SCALE 2
  1212. #define DAC1FID21_MGUSTSPEED_NOT_AVAILABLE 255
  1213. unsigned int mgustdir; /* in 5 degree steps */
  1214. #define DAC1FID21_MGUSTDIR_NOT_AVAILABLE 127
  1215. unsigned int airtemp; /* degress K */
  1216. #define DAC1FID21_AIRTEMP_OFFSET 223
  1217. unsigned humidity; /* units of 1% */
  1218. #define DAC1FID21_HUMIDITY_NOT_VAILABLE 127
  1219. /* some trailing fields are missing */
  1220. } wmo_obs;
  1221. };
  1222. } dac1fid21;
  1223. /*** WORK IN PROGRESS ENDS HERE ***/
  1224. /* IMO289 - Dangerous Cargo Indication */
  1225. struct {
  1226. unsigned int unit; /* Unit of Quantity */
  1227. unsigned int amount; /* Amount of Cargo */
  1228. int ncargos;
  1229. struct cargo_t {
  1230. unsigned int code; /* Cargo code */
  1231. unsigned int subtype; /* Cargo subtype */
  1232. } cargos[28];
  1233. } dac1fid25;
  1234. /* IMO289 - Route info (addressed) */
  1235. struct route_info dac1fid28;
  1236. /* IMO289 - Text message (addressed) */
  1237. struct {
  1238. unsigned int linkage;
  1239. #define AIS_DAC1FID30_TEXT_MAX 154 /* 920 bits of six-bit, plus NUL */
  1240. char text[AIS_DAC1FID30_TEXT_MAX];
  1241. } dac1fid30;
  1242. /* IMO289 & IMO236 - Tidal Window */
  1243. struct {
  1244. unsigned int month; /* Month */
  1245. unsigned int day; /* Day */
  1246. signed int ntidals;
  1247. struct tidal_t {
  1248. signed int lon; /* Longitude */
  1249. signed int lat; /* Latitude */
  1250. unsigned int from_hour; /* From UTC Hour */
  1251. unsigned int from_min; /* From UTC Minute */
  1252. unsigned int to_hour; /* To UTC Hour */
  1253. unsigned int to_min; /* To UTC Minute */
  1254. #define DAC1FID32_CDIR_NOT_AVAILABLE 360
  1255. unsigned int cdir; /* Current Dir. Predicted */
  1256. #define DAC1FID32_CSPEED_NOT_AVAILABLE 127
  1257. unsigned int cspeed; /* Current Speed Predicted */
  1258. } tidals[3];
  1259. } dac1fid32;
  1260. };
  1261. } type6;
  1262. /* Type 7 - Binary Acknowledge */
  1263. struct {
  1264. unsigned int mmsi1;
  1265. unsigned int seqno1;
  1266. unsigned int mmsi2;
  1267. unsigned int seqno2;
  1268. unsigned int mmsi3;
  1269. unsigned int seqno3;
  1270. unsigned int mmsi4;
  1271. unsigned int seqno4;
  1272. /* spares ignored, they're only padding here */
  1273. } type7;
  1274. /* Type 8 - Broadcast Binary Message */
  1275. struct {
  1276. unsigned int dac; /* Designated Area Code */
  1277. unsigned int fid; /* Functional ID */
  1278. #define AIS_TYPE8_BINARY_MAX 952 /* 952 bits */
  1279. size_t bitcount; /* bit count of the data */
  1280. bool structured; /* True match for DAC/FID? */
  1281. union {
  1282. // cppcheck-suppress arrayIndexOutOfBounds
  1283. char bitdata[(AIS_TYPE8_BINARY_MAX + 7) / 8];
  1284. /* Inland static ship and voyage-related data */
  1285. struct {
  1286. char vin[8+1]; /* European Vessel ID */
  1287. unsigned int length; /* Length of ship */
  1288. unsigned int beam; /* Beam of ship */
  1289. unsigned int shiptype; /* Ship/combination type */
  1290. unsigned int hazard; /* Hazardous cargo */
  1291. #define DAC200FID10_HAZARD_MAX 5
  1292. unsigned int draught; /* Draught */
  1293. unsigned int loaded; /* Loaded/Unloaded */
  1294. bool speed_q; /* Speed inf. quality */
  1295. bool course_q; /* Course inf. quality */
  1296. bool heading_q; /* Heading inf. quality */
  1297. } dac200fid10;
  1298. /* Inland AIS EMMA Warning */
  1299. struct {
  1300. unsigned int start_year; /* Start Year */
  1301. unsigned int start_month; /* Start Month */
  1302. unsigned int start_day; /* Start Day */
  1303. unsigned int end_year; /* End Year */
  1304. unsigned int end_month; /* End Month */
  1305. unsigned int end_day; /* End Day */
  1306. unsigned int start_hour; /* Start Hour */
  1307. unsigned int start_minute; /* Start Minute */
  1308. unsigned int end_hour; /* End Hour */
  1309. unsigned int end_minute; /* End Minute */
  1310. signed int start_lon; /* Start Longitude */
  1311. signed int start_lat; /* Start Latitude */
  1312. signed int end_lon; /* End Longitude */
  1313. signed int end_lat; /* End Latitude */
  1314. unsigned int type; /* Type */
  1315. #define DAC200FID23_TYPE_UNKNOWN 0
  1316. signed int min; /* Min value */
  1317. #define DAC200FID23_MIN_UNKNOWN 255
  1318. signed int max; /* Max value */
  1319. #define DAC200FID23_MAX_UNKNOWN 255
  1320. unsigned int intensity; /* Classification */
  1321. #define DAC200FID23_CLASS_UNKNOWN 0
  1322. unsigned int wind; /* Wind Direction */
  1323. #define DAC200FID23_WIND_UNKNOWN 0
  1324. } dac200fid23;
  1325. struct {
  1326. char country[2+1]; /* UN Country Code */
  1327. signed int ngauges;
  1328. struct gauge_t {
  1329. unsigned int id; /* Gauge ID */
  1330. #define DAC200FID24_GAUGE_ID_UNKNOWN 0
  1331. signed int level; /* Water Level */
  1332. #define DAC200FID24_GAUGE_LEVEL_UNKNOWN 0
  1333. } gauges[4];
  1334. } dac200fid24;
  1335. struct {
  1336. signed int lon; /* Signal Longitude */
  1337. signed int lat; /* Signal Latitude */
  1338. unsigned int form; /* Signal form */
  1339. #define DAC200FID40_FORM_UNKNOWN 0
  1340. unsigned int facing; /* Signal orientation */
  1341. #define DAC200FID40_FACING_UNKNOWN 0
  1342. unsigned int direction; /* Direction of impact */
  1343. #define DAC200FID40_DIRECTION_UNKNOWN 0
  1344. unsigned int status; /* Light Status */
  1345. #define DAC200FID40_STATUS_UNKNOWN 0
  1346. } dac200fid40;
  1347. /* IMO236 - Meteorological-Hydrological data
  1348. * Trial message, not to be used after January 2013
  1349. * Replaced by IMO289 (DAC 1, FID 31)
  1350. */
  1351. struct {
  1352. #define DAC1FID11_LATLON_SCALE 1000
  1353. int lon; /* longitude in minutes * .001 */
  1354. #define DAC1FID11_LON_NOT_AVAILABLE 0xFFFFFF
  1355. int lat; /* latitude in minutes * .001 */
  1356. #define DAC1FID11_LAT_NOT_AVAILABLE 0x7FFFFF
  1357. unsigned int day; /* UTC day */
  1358. unsigned int hour; /* UTC hour */
  1359. unsigned int minute; /* UTC minute */
  1360. unsigned int wspeed; /* average wind speed */
  1361. unsigned int wgust; /* wind gust */
  1362. #define DAC1FID11_WSPEED_NOT_AVAILABLE 127
  1363. unsigned int wdir; /* wind direction */
  1364. unsigned int wgustdir; /* wind gust direction */
  1365. #define DAC1FID11_WDIR_NOT_AVAILABLE 511
  1366. unsigned int airtemp; /* temperature, units 0.1C */
  1367. #define DAC1FID11_AIRTEMP_NOT_AVAILABLE 2047
  1368. #define DAC1FID11_AIRTEMP_OFFSET 600
  1369. #define DAC1FID11_AIRTEMP_DIV 10.0
  1370. unsigned int humidity; /* relative humidity, % */
  1371. #define DAC1FID11_HUMIDITY_NOT_AVAILABLE 127
  1372. unsigned int dewpoint; /* dew point, units 0.1C */
  1373. #define DAC1FID11_DEWPOINT_NOT_AVAILABLE 1023
  1374. #define DAC1FID11_DEWPOINT_OFFSET 200
  1375. #define DAC1FID11_DEWPOINT_DIV 10.0
  1376. unsigned int pressure; /* air pressure, hpa */
  1377. #define DAC1FID11_PRESSURE_NOT_AVAILABLE 511
  1378. #define DAC1FID11_PRESSURE_OFFSET -800
  1379. unsigned int pressuretend; /* tendency */
  1380. #define DAC1FID11_PRESSURETREND_NOT_AVAILABLE 3
  1381. unsigned int visibility; /* units 0.1 nautical miles */
  1382. #define DAC1FID11_VISIBILITY_NOT_AVAILABLE 255
  1383. #define DAC1FID11_VISIBILITY_DIV 10.0
  1384. int waterlevel; /* decimeters */
  1385. #define DAC1FID11_WATERLEVEL_NOT_AVAILABLE 511
  1386. #define DAC1FID11_WATERLEVEL_OFFSET 100
  1387. #define DAC1FID11_WATERLEVEL_DIV 10.0
  1388. unsigned int leveltrend; /* water level trend code */
  1389. #define DAC1FID11_WATERLEVELTREND_NOT_AVAILABLE 3
  1390. unsigned int cspeed; /* surface current speed in deciknots */
  1391. #define DAC1FID11_CSPEED_NOT_AVAILABLE 255
  1392. #define DAC1FID11_CSPEED_DIV 10.0
  1393. unsigned int cdir; /* surface current dir., degrees */
  1394. #define DAC1FID11_CDIR_NOT_AVAILABLE 511
  1395. unsigned int cspeed2; /* current speed in deciknots */
  1396. unsigned int cdir2; /* current dir., degrees */
  1397. unsigned int cdepth2; /* measurement depth, m */
  1398. #define DAC1FID11_CDEPTH_NOT_AVAILABLE 31
  1399. unsigned int cspeed3; /* current speed in deciknots */
  1400. unsigned int cdir3; /* current dir., degrees */
  1401. unsigned int cdepth3; /* measurement depth, m */
  1402. unsigned int waveheight; /* in decimeters */
  1403. #define DAC1FID11_WAVEHEIGHT_NOT_AVAILABLE 255
  1404. #define DAC1FID11_WAVEHEIGHT_DIV 10.0
  1405. unsigned int waveperiod; /* in seconds */
  1406. #define DAC1FID11_WAVEPERIOD_NOT_AVAILABLE 63
  1407. unsigned int wavedir; /* direction in degrees */
  1408. #define DAC1FID11_WAVEDIR_NOT_AVAILABLE 511
  1409. unsigned int swellheight; /* in decimeters */
  1410. unsigned int swellperiod; /* in seconds */
  1411. unsigned int swelldir; /* direction in degrees */
  1412. unsigned int seastate; /* Beaufort scale, 0-12 */
  1413. #define DAC1FID11_SEASTATE_NOT_AVAILABLE 15
  1414. unsigned int watertemp; /* units 0.1deg Celsius */
  1415. #define DAC1FID11_WATERTEMP_NOT_AVAILABLE 1023
  1416. #define DAC1FID11_WATERTEMP_OFFSET 100
  1417. #define DAC1FID11_WATERTEMP_DIV 10.0
  1418. unsigned int preciptype; /* 0-7, enumerated */
  1419. #define DAC1FID11_PRECIPTYPE_NOT_AVAILABLE 7
  1420. unsigned int salinity; /* units of 0.1ppt */
  1421. #define DAC1FID11_SALINITY_NOT_AVAILABLE 511
  1422. #define DAC1FID11_SALINITY_DIV 10.0
  1423. unsigned int ice; /* is there sea ice? */
  1424. #define DAC1FID11_ICE_NOT_AVAILABLE 3
  1425. } dac1fid11;
  1426. /* IMO236 - Fairway Closed */
  1427. struct {
  1428. char reason[20+1]; /* Reason For Closing */
  1429. char closefrom[20+1]; /* Location Of Closing From */
  1430. char closeto[20+1]; /* Location of Closing To */
  1431. unsigned int radius; /* Radius extension */
  1432. #define AIS_DAC1FID13_RADIUS_NOT_AVAILABLE 10001
  1433. unsigned int extunit; /* Unit of extension */
  1434. #define AIS_DAC1FID13_EXTUNIT_NOT_AVAILABLE 0
  1435. unsigned int fday; /* From day (UTC) */
  1436. unsigned int fmonth; /* From month (UTC) */
  1437. unsigned int fhour; /* From hour (UTC) */
  1438. unsigned int fminute; /* From minute (UTC) */
  1439. unsigned int tday; /* To day (UTC) */
  1440. unsigned int tmonth; /* To month (UTC) */
  1441. unsigned int thour; /* To hour (UTC) */
  1442. unsigned int tminute; /* To minute (UTC) */
  1443. } dac1fid13;
  1444. /* IMO236 - Extended ship and voyage data */
  1445. struct {
  1446. unsigned int airdraught; /* Air Draught */
  1447. } dac1fid15;
  1448. /* IMO286 - Number of Persons on board */
  1449. struct {
  1450. unsigned persons; /* number of persons */
  1451. } dac1fid16;
  1452. /* IMO289 - VTS-generated/Synthetic Targets */
  1453. struct {
  1454. signed int ntargets;
  1455. struct target_t {
  1456. #define DAC1FID17_IDTYPE_MMSI 0
  1457. #define DAC1FID17_IDTYPE_IMO 1
  1458. #define DAC1FID17_IDTYPE_CALLSIGN 2
  1459. #define DAC1FID17_IDTYPE_OTHER 3
  1460. unsigned int idtype; /* Identifier type */
  1461. union target_id { /* Target identifier */
  1462. unsigned int mmsi;
  1463. unsigned int imo;
  1464. #define DAC1FID17_ID_LENGTH 7
  1465. // cppcheck-suppress arrayIndexOutOfBounds
  1466. char callsign[DAC1FID17_ID_LENGTH+1];
  1467. char other[DAC1FID17_ID_LENGTH+1];
  1468. } id;
  1469. signed int lat; /* Latitude */
  1470. signed int lon; /* Longitude */
  1471. #define DAC1FID17_COURSE_NOT_AVAILABLE 360
  1472. unsigned int course; /* Course Over Ground */
  1473. unsigned int second; /* Time Stamp */
  1474. #define DAC1FID17_SPEED_NOT_AVAILABLE 255
  1475. unsigned int speed; /* Speed Over Ground */
  1476. } targets[4];
  1477. } dac1fid17;
  1478. /* IMO 289 - Marine Traffic Signal */
  1479. struct {
  1480. unsigned int linkage; /* Message Linkage ID */
  1481. char station[20+1]; /* Name of Signal Station */
  1482. signed int lon; /* Longitude */
  1483. signed int lat; /* Latitude */
  1484. unsigned int status; /* Status of Signal */
  1485. unsigned int signal; /* Signal In Service */
  1486. unsigned int hour; /* UTC hour */
  1487. unsigned int minute; /* UTC minute */
  1488. unsigned int nextsignal; /* Expected Next Signal */
  1489. } dac1fid19;
  1490. /* IMO289 - Route info (broadcast) */
  1491. struct route_info dac1fid27;
  1492. /* IMO289 - Text message (broadcast) */
  1493. struct {
  1494. unsigned int linkage;
  1495. #define AIS_DAC1FID29_TEXT_MAX 162 /* 920 bits of six-bit, plus NUL */
  1496. char text[AIS_DAC1FID29_TEXT_MAX];
  1497. } dac1fid29;
  1498. /* IMO289 - Meteorological-Hydrological data */
  1499. struct {
  1500. bool accuracy; /* position accuracy, <10m if true */
  1501. #define DAC1FID31_LATLON_SCALE 1000
  1502. int lon; /* longitude in minutes * .001 */
  1503. #define DAC1FID31_LON_NOT_AVAILABLE (181*60*DAC1FID31_LATLON_SCALE)
  1504. int lat; /* longitude in minutes * .001 */
  1505. #define DAC1FID31_LAT_NOT_AVAILABLE (91*60*DAC1FID31_LATLON_SCALE)
  1506. unsigned int day; /* UTC day */
  1507. unsigned int hour; /* UTC hour */
  1508. unsigned int minute; /* UTC minute */
  1509. unsigned int wspeed; /* average wind speed */
  1510. unsigned int wgust; /* wind gust */
  1511. #define DAC1FID31_WIND_HIGH 126
  1512. #define DAC1FID31_WIND_NOT_AVAILABLE 127
  1513. unsigned int wdir; /* wind direction */
  1514. unsigned int wgustdir; /* wind gust direction */
  1515. #define DAC1FID31_DIR_NOT_AVAILABLE 360
  1516. int airtemp; /* temperature, units 0.1C */
  1517. #define DAC1FID31_AIRTEMP_NOT_AVAILABLE -1024
  1518. #define DAC1FID31_AIRTEMP_DIV 10.0
  1519. unsigned int humidity; /* relative humidity, % */
  1520. #define DAC1FID31_HUMIDITY_NOT_AVAILABLE 101
  1521. int dewpoint; /* dew point, units 0.1C */
  1522. #define DAC1FID31_DEWPOINT_NOT_AVAILABLE 501
  1523. #define DAC1FID31_DEWPOINT_DIV 10.0
  1524. unsigned int pressure; /* air pressure, hpa */
  1525. #define DAC1FID31_PRESSURE_NOT_AVAILABLE 511
  1526. #define DAC1FID31_PRESSURE_HIGH 402
  1527. #define DAC1FID31_PRESSURE_OFFSET -799
  1528. unsigned int pressuretend; /* tendency */
  1529. #define DAC1FID31_PRESSURETEND_NOT_AVAILABLE 3
  1530. bool visgreater; /* visibility greater than */
  1531. unsigned int visibility; /* units 0.1 nautical miles */
  1532. #define DAC1FID31_VISIBILITY_NOT_AVAILABLE 127
  1533. #define DAC1FID31_VISIBILITY_DIV 10.0
  1534. int waterlevel; /* cm */
  1535. #define DAC1FID31_WATERLEVEL_NOT_AVAILABLE 4001
  1536. #define DAC1FID31_WATERLEVEL_OFFSET 1000
  1537. #define DAC1FID31_WATERLEVEL_DIV 100.0
  1538. unsigned int leveltrend; /* water level trend code */
  1539. #define DAC1FID31_WATERLEVELTREND_NOT_AVAILABLE 3
  1540. unsigned int cspeed; /* current speed in deciknots */
  1541. #define DAC1FID31_CSPEED_NOT_AVAILABLE 255
  1542. #define DAC1FID31_CSPEED_DIV 10.0
  1543. unsigned int cdir; /* current dir., degrees */
  1544. unsigned int cspeed2; /* current speed in deciknots */
  1545. unsigned int cdir2; /* current dir., degrees */
  1546. unsigned int cdepth2; /* measurement depth, 0.1m */
  1547. #define DAC1FID31_CDEPTH_NOT_AVAILABLE 301
  1548. #define DAC1FID31_CDEPTH_SCALE 10.0
  1549. unsigned int cspeed3; /* current speed in deciknots */
  1550. unsigned int cdir3; /* current dir., degrees */
  1551. unsigned int cdepth3; /* measurement depth, 0.1m */
  1552. unsigned int waveheight; /* in decimeters */
  1553. #define DAC1FID31_HEIGHT_NOT_AVAILABLE 31
  1554. #define DAC1FID31_HEIGHT_DIV 10.0
  1555. unsigned int waveperiod; /* in seconds */
  1556. #define DAC1FID31_PERIOD_NOT_AVAILABLE 63
  1557. unsigned int wavedir; /* direction in degrees */
  1558. unsigned int swellheight; /* in decimeters */
  1559. unsigned int swellperiod; /* in seconds */
  1560. unsigned int swelldir; /* direction in degrees */
  1561. unsigned int seastate; /* Beaufort scale, 0-12 */
  1562. #define DAC1FID31_SEASTATE_NOT_AVAILABLE 15
  1563. int watertemp; /* units 0.1deg Celsius */
  1564. #define DAC1FID31_WATERTEMP_NOT_AVAILABLE 601
  1565. #define DAC1FID31_WATERTEMP_DIV 10.0
  1566. unsigned int preciptype; /* 0-7, enumerated */
  1567. #define DAC1FID31_PRECIPTYPE_NOT_AVAILABLE 7
  1568. unsigned int salinity; /* units of 0.1 permil (ca. PSU) */
  1569. #define DAC1FID31_SALINITY_NOT_AVAILABLE 510
  1570. #define DAC1FID31_SALINITY_DIV 10.0
  1571. unsigned int ice; /* is there sea ice? */
  1572. #define DAC1FID31_ICE_NOT_AVAILABLE 3
  1573. } dac1fid31;
  1574. };
  1575. } type8;
  1576. /* Type 9 - Standard SAR Aircraft Position Report */
  1577. struct {
  1578. unsigned int alt; /* altitude in meters */
  1579. #define AIS_ALT_NOT_AVAILABLE 4095
  1580. #define AIS_ALT_HIGH 4094 /* 4094 meters or higher */
  1581. unsigned int speed; /* speed over ground in deciknots */
  1582. #define AIS_SAR_SPEED_NOT_AVAILABLE 1023
  1583. #define AIS_SAR_FAST_MOVER 1022
  1584. bool accuracy; /* position accuracy */
  1585. int lon; /* longitude */
  1586. int lat; /* latitude */
  1587. unsigned int course; /* course over ground */
  1588. /* seconds of UTC time, 0 to 59.
  1589. * 60 == N/A, 61 == manual, 62 == dead reckoning,
  1590. * 63 == inoperative */
  1591. unsigned int second; /* seconds of UTC time */
  1592. unsigned int regional; /* regional reserved */
  1593. unsigned int dte; /* data terminal enable */
  1594. //unsigned int spare; spare bits */
  1595. bool assigned; /* assigned-mode flag */
  1596. bool raim; /* RAIM flag */
  1597. unsigned int radio; /* radio status bits */
  1598. } type9;
  1599. /* Type 10 - UTC/Date Inquiry */
  1600. struct {
  1601. //unsigned int spare;
  1602. unsigned int dest_mmsi; /* destination MMSI */
  1603. //unsigned int spare2;
  1604. } type10;
  1605. /* Type 12 - Safety-Related Message */
  1606. struct {
  1607. unsigned int seqno; /* sequence number */
  1608. unsigned int dest_mmsi; /* destination MMSI */
  1609. bool retransmit; /* retransmit flag */
  1610. //unsigned int spare; spare bit(s) */
  1611. #define AIS_TYPE12_TEXT_MAX 157 /* 936 bits of six-bit, plus NUL */
  1612. char text[AIS_TYPE12_TEXT_MAX];
  1613. } type12;
  1614. /* Type 14 - Safety-Related Broadcast Message */
  1615. struct {
  1616. //unsigned int spare; spare bit(s) */
  1617. #define AIS_TYPE14_TEXT_MAX 161 /* 952 bits of six-bit, plus NUL */
  1618. char text[AIS_TYPE14_TEXT_MAX];
  1619. } type14;
  1620. /* Type 15 - Interrogation */
  1621. struct {
  1622. //unsigned int spare; spare bit(s) */
  1623. unsigned int mmsi1;
  1624. unsigned int type1_1;
  1625. unsigned int offset1_1;
  1626. //unsigned int spare2; spare bit(s) */
  1627. unsigned int type1_2;
  1628. unsigned int offset1_2;
  1629. //unsigned int spare3; spare bit(s) */
  1630. unsigned int mmsi2;
  1631. unsigned int type2_1;
  1632. unsigned int offset2_1;
  1633. //unsigned int spare4; spare bit(s) */
  1634. } type15;
  1635. /* Type 16 - Assigned Mode Command */
  1636. struct {
  1637. //unsigned int spare; spare bit(s) */
  1638. unsigned int mmsi1;
  1639. unsigned int offset1;
  1640. unsigned int increment1;
  1641. unsigned int mmsi2;
  1642. unsigned int offset2;
  1643. unsigned int increment2;
  1644. } type16;
  1645. /* Type 17 - GNSS Broadcast Binary Message */
  1646. struct {
  1647. //unsigned int spare; spare bit(s) */
  1648. #define AIS_GNSS_LATLON_DIV 600.0
  1649. int lon; /* longitude */
  1650. int lat; /* latitude */
  1651. //unsigned int spare2; spare bit(s) */
  1652. #define AIS_TYPE17_BINARY_MAX 736 /* 920 bits */
  1653. size_t bitcount; /* bit count of the data */
  1654. char bitdata[(AIS_TYPE17_BINARY_MAX + 7) / 8];
  1655. } type17;
  1656. /* Type 18 - Standard Class B CS Position Report */
  1657. struct {
  1658. unsigned int reserved; /* altitude in meters */
  1659. unsigned int speed; /* speed over ground in deciknots */
  1660. bool accuracy; /* position accuracy */
  1661. int lon; /* longitude */
  1662. #define AIS_GNS_LON_NOT_AVAILABLE 0x1a838
  1663. int lat; /* latitude */
  1664. #define AIS_GNS_LAT_NOT_AVAILABLE 0xd548
  1665. unsigned int course; /* course over ground */
  1666. unsigned int heading; /* true heading */
  1667. /* seconds of UTC time, 0 to 59.
  1668. * 60 == N/A, 61 == manual, 62 == dead reckoning,
  1669. * 63 == inoperative */
  1670. unsigned int second;
  1671. unsigned int regional; /* regional reserved */
  1672. bool cs; /* carrier sense unit flag */
  1673. bool display; /* unit has attached display? */
  1674. bool dsc; /* unit attached to radio with DSC? */
  1675. bool band; /* unit can switch frequency bands? */
  1676. bool msg22; /* can accept Message 22 management? */
  1677. bool assigned; /* assigned-mode flag */
  1678. bool raim; /* RAIM flag */
  1679. unsigned int radio; /* radio status bits */
  1680. } type18;
  1681. /* Type 19 - Extended Class B CS Position Report */
  1682. struct {
  1683. unsigned int reserved; /* altitude in meters */
  1684. unsigned int speed; /* speed over ground in deciknots */
  1685. bool accuracy; /* position accuracy */
  1686. int lon; /* longitude */
  1687. int lat; /* latitude */
  1688. unsigned int course; /* course over ground */
  1689. unsigned int heading; /* true heading */
  1690. /* seconds of UTC time, 0 to 59.
  1691. * 60 == N/A, 61 == manual, 62 == dead reckoning,
  1692. * 63 == inoperative */
  1693. unsigned int second;
  1694. unsigned int regional; /* regional reserved */
  1695. // cppcheck-suppress arrayIndexOutOfBounds
  1696. char shipname[AIS_SHIPNAME_MAXLEN+1]; /* ship name */
  1697. unsigned int shiptype; /* ship type code */
  1698. unsigned int to_bow; /* dimension to bow */
  1699. unsigned int to_stern; /* dimension to stern */
  1700. unsigned int to_port; /* dimension to port */
  1701. unsigned int to_starboard; /* dimension to starboard */
  1702. unsigned int epfd; /* type of position fix deviuce */
  1703. bool raim; /* RAIM flag */
  1704. unsigned int dte; /* date terminal enable */
  1705. bool assigned; /* assigned-mode flag */
  1706. //unsigned int spare; spare bits */
  1707. } type19;
  1708. /* Type 20 - Data Link Management Message */
  1709. struct {
  1710. //unsigned int spare; spare bit(s) */
  1711. unsigned int offset1; /* TDMA slot offset */
  1712. unsigned int number1; /* number of xlots to allocate */
  1713. unsigned int timeout1; /* allocation timeout */
  1714. unsigned int increment1; /* repeat increment */
  1715. unsigned int offset2; /* TDMA slot offset */
  1716. unsigned int number2; /* number of xlots to allocate */
  1717. unsigned int timeout2; /* allocation timeout */
  1718. unsigned int increment2; /* repeat increment */
  1719. unsigned int offset3; /* TDMA slot offset */
  1720. unsigned int number3; /* number of xlots to allocate */
  1721. unsigned int timeout3; /* allocation timeout */
  1722. unsigned int increment3; /* repeat increment */
  1723. unsigned int offset4; /* TDMA slot offset */
  1724. unsigned int number4; /* number of xlots to allocate */
  1725. unsigned int timeout4; /* allocation timeout */
  1726. unsigned int increment4; /* repeat increment */
  1727. } type20;
  1728. /* Type 21 - Aids to Navigation Report */
  1729. struct {
  1730. unsigned int aid_type; /* aid type */
  1731. char name[35]; /* name of aid to navigation */
  1732. bool accuracy; /* position accuracy */
  1733. int lon; /* longitude */
  1734. int lat; /* latitude */
  1735. unsigned int to_bow; /* dimension to bow */
  1736. unsigned int to_stern; /* dimension to stern */
  1737. unsigned int to_port; /* dimension to port */
  1738. unsigned int to_starboard; /* dimension to starboard */
  1739. unsigned int epfd; /* type of EPFD */
  1740. /* seconds of UTC time, 0 to 59.
  1741. * 60 == N/A, 61 == manual, 62 == dead reckoning,
  1742. * 63 == inoperative */
  1743. unsigned int second;
  1744. bool off_position; /* off-position indicator */
  1745. unsigned int regional; /* regional reserved field */
  1746. bool raim; /* RAIM flag */
  1747. bool virtual_aid; /* is virtual station? */
  1748. bool assigned; /* assigned-mode flag */
  1749. //unsigned int spare; unused */
  1750. } type21;
  1751. /* Type 22 - Channel Management */
  1752. struct {
  1753. //unsigned int spare; spare bit(s) */
  1754. unsigned int channel_a; /* Channel A number */
  1755. unsigned int channel_b; /* Channel B number */
  1756. unsigned int txrx; /* transmit/receive mode */
  1757. bool power; /* high-power flag */
  1758. #define AIS_CHANNEL_LATLON_DIV 600.0
  1759. union {
  1760. struct {
  1761. int ne_lon; /* NE corner longitude */
  1762. int ne_lat; /* NE corner latitude */
  1763. int sw_lon; /* SW corner longitude */
  1764. int sw_lat; /* SW corner latitude */
  1765. } area;
  1766. struct {
  1767. unsigned int dest1; /* addressed station MMSI 1 */
  1768. unsigned int dest2; /* addressed station MMSI 2 */
  1769. } mmsi;
  1770. };
  1771. bool addressed; /* addressed vs. broadast flag */
  1772. bool band_a; /* fix 1.5kHz band for channel A */
  1773. bool band_b; /* fix 1.5kHz band for channel B */
  1774. unsigned int zonesize; /* size of transitional zone */
  1775. } type22;
  1776. /* Type 23 - Group Assignment Command */
  1777. struct {
  1778. int ne_lon; /* NE corner longitude */
  1779. int ne_lat; /* NE corner latitude */
  1780. int sw_lon; /* SW corner longitude */
  1781. int sw_lat; /* SW corner latitude */
  1782. //unsigned int spare; spare bit(s) */
  1783. unsigned int stationtype; /* station type code */
  1784. unsigned int shiptype; /* ship type code */
  1785. //unsigned int spare2; spare bit(s) */
  1786. unsigned int txrx; /* transmit-enable code */
  1787. unsigned int interval; /* report interval */
  1788. unsigned int quiet; /* quiet time */
  1789. //unsigned int spare3; spare bit(s) */
  1790. } type23;
  1791. /* Type 24 - Class B CS Static Data Report */
  1792. struct {
  1793. char shipname[AIS_SHIPNAME_MAXLEN+1]; /* vessel name */
  1794. enum {
  1795. both,
  1796. part_a,
  1797. part_b,
  1798. } part;
  1799. unsigned int shiptype; /* ship type code */
  1800. char vendorid[8]; /* vendor ID */
  1801. unsigned int model; /* unit model code */
  1802. unsigned int serial; /* serial number */
  1803. char callsign[8]; /* callsign */
  1804. union {
  1805. unsigned int mothership_mmsi; /* MMSI of main vessel */
  1806. struct {
  1807. unsigned int to_bow; /* dimension to bow */
  1808. unsigned int to_stern; /* dimension to stern */
  1809. unsigned int to_port; /* dimension to port */
  1810. unsigned int to_starboard; /* dimension to starboard */
  1811. } dim;
  1812. };
  1813. } type24;
  1814. /* Type 25 - Addressed Binary Message */
  1815. struct {
  1816. bool addressed; /* addressed-vs.broadcast flag */
  1817. bool structured; /* structured-binary flag */
  1818. unsigned int dest_mmsi; /* destination MMSI */
  1819. unsigned int app_id; /* Application ID */
  1820. #define AIS_TYPE25_BINARY_MAX 128 /* Up to 128 bits */
  1821. size_t bitcount; /* bit count of the data */
  1822. char bitdata[(AIS_TYPE25_BINARY_MAX + 7) / 8];
  1823. } type25;
  1824. /* Type 26 - Addressed Binary Message */
  1825. struct {
  1826. bool addressed; /* addressed-vs.broadcast flag */
  1827. bool structured; /* structured-binary flag */
  1828. unsigned int dest_mmsi; /* destination MMSI */
  1829. unsigned int app_id; /* Application ID */
  1830. #define AIS_TYPE26_BINARY_MAX 1004 /* Up to 128 bits */
  1831. size_t bitcount; /* bit count of the data */
  1832. char bitdata[(AIS_TYPE26_BINARY_MAX + 7) / 8];
  1833. unsigned int radio; /* radio status bits */
  1834. } type26;
  1835. /* Type 27 - Long Range AIS Broadcast message */
  1836. struct {
  1837. bool accuracy; /* position accuracy */
  1838. bool raim; /* RAIM flag */
  1839. unsigned int status; /* navigation status */
  1840. #define AIS_LONGRANGE_LATLON_DIV 600.0
  1841. int lon; /* longitude */
  1842. #define AIS_LONGRANGE_LON_NOT_AVAILABLE 0x1a838
  1843. int lat; /* latitude */
  1844. #define AIS_LONGRANGE_LAT_NOT_AVAILABLE 0xd548
  1845. unsigned int speed; /* speed over ground in deciknots */
  1846. #define AIS_LONGRANGE_SPEED_NOT_AVAILABLE 63
  1847. unsigned int course; /* course over ground */
  1848. #define AIS_LONGRANGE_COURSE_NOT_AVAILABLE 511
  1849. bool gnss; /* are we reporting GNSS position? */
  1850. } type27;
  1851. };
  1852. };
  1853. /* basic data, per PRN, from GPGSA and GPGSV, or GPS binary messages */
  1854. /* FIXME: u-blox 9 no longer uses PRN */
  1855. struct satellite_t {
  1856. /* SNR. signal-to-noise ratio, 0 to 254 dB, u-blox can be 0 to 63.
  1857. * -1 for n/a */
  1858. double ss;
  1859. bool used; /* this satellite used in solution */
  1860. /* PRN of this satellite, 1 to 437, 0 for n/a
  1861. * sadly there is no standard, but many different implementations of
  1862. * how to code PRN
  1863. */
  1864. short PRN; /* PRN numbering per NMEA 2.x to 4.0, not 4.10 */
  1865. double elevation; /* elevation of satellite, -90 to 90 deg, NAN for n/a */
  1866. double azimuth; /* azimuth, 0 to 359 deg, NAN1 for n/a */
  1867. /* gnssid:svid:sigid, as defined by u-blox 8/9:
  1868. * gnssid svid (native PRN)
  1869. * 0 = GPS 1-32
  1870. * 1 = SBAS 120-158
  1871. * 2 = Galileo 1-36
  1872. * 3 - BeiDou 1-37
  1873. * 4 = IMES 1-10
  1874. * 5 = QZSS 1-5 Undocumented u-blox goes to 7
  1875. * 6 = GLONASS 1-32, 255
  1876. * x = IRNSS 1-11 Not defined by u-blox:
  1877. *
  1878. * gnssid:svid:sigid, as defined by NMEA 4.10, NOT USED HERE!
  1879. * 1 = GPS 1-32
  1880. * 1 = SBAS 33-64, 152-158
  1881. * 1 = QZSS 193-197 Undocuemtned u-blox goes to 199
  1882. * 2 = GLONASS 1-32, nul
  1883. * 3 = Galileo 1-36
  1884. * 4 - BeiDou 1-37
  1885. * x = IMES Not defined by NMEA 4.10
  1886. *
  1887. * Note: other GNSS receivers use different mappings!
  1888. */
  1889. unsigned char gnssid;
  1890. /* defines for u-blox gnssId, as used in satellite_t */
  1891. #define GNSSID_GPS 0
  1892. #define GNSSID_SBAS 1
  1893. #define GNSSID_GAL 2
  1894. #define GNSSID_BD 3
  1895. #define GNSSID_IMES 4
  1896. #define GNSSID_QZSS 5
  1897. #define GNSSID_GLO 6
  1898. #define GNSSID_IRNSS 7 /* Not defined by u-blox */
  1899. #define GNSSID_CNT 8 /* count for array size */
  1900. /* ignore gnssid and sigid if svid is zero */
  1901. unsigned char svid;
  1902. /* sigid as defined by u-blox 9, and used here
  1903. * GPS: 0 = L1C/A, 3 = L2 CL, 4 = L2 CM
  1904. * SBAS: 0 = L1C/A, ? = L5I
  1905. * Galileo: 0 = E1 C, 1 = E1 B, 5 = E5 bl, 6 = E5 bQ
  1906. * BeiDou: 0 = B1I D1, 1 = B1I D2, 2 = B2I D1, 3 = B2I D2
  1907. * QZSS: 0 = L1C/A, 4 = L2 CM, 5 = L2 CL
  1908. * GLONASS: 0 = L1 OF, 2 = L2 OF
  1909. *
  1910. * sigid as defined by NMEA 4.10, NOT used here
  1911. * GPS: 1 = L1C/A, 6 = L2 CL, 5 = L2 CM
  1912. * Galileo: 7 = E1 C, 7 = E1 B, 2 = E5 bl, 2 = E5 bQ
  1913. * BeiDou: 1 = B1|D1, 1 = B1|D2, 3 = B2|D1, 3 = B2|D2
  1914. * QZSS: not defined
  1915. * GLONASS: 1 = L1 OF, 3 = L2 OF
  1916. */
  1917. unsigned char sigid;
  1918. signed char freqid; /* The GLONASS (Only) frequency, 0 - 13 */
  1919. unsigned char health; /* 0 = unknown, 1 = helthy, 2 = unhealthy */
  1920. #define SAT_HEALTH_UNK 0
  1921. #define SAT_HEALTH_OK 1
  1922. #define SAT_HEALTH_BAD 2
  1923. };
  1924. struct attitude_t {
  1925. timespec_t mtime; /* time of measurement */
  1926. double acc_len; /* unitvector sqrt(x^2 + y^2 +z^2) */
  1927. double acc_x;
  1928. double acc_y;
  1929. double acc_z;
  1930. double depth;
  1931. double dip;
  1932. double gyro_x;
  1933. double gyro_y;
  1934. double heading;
  1935. double mag_len; /* unitvector sqrt(x^2 + y^2 +z^2) */
  1936. double mag_x;
  1937. double mag_y;
  1938. double mag_z;
  1939. double pitch;
  1940. double roll;
  1941. double temp;
  1942. double yaw;
  1943. /* compass status -- TrueNorth (and any similar) devices only */
  1944. char mag_st;
  1945. char pitch_st;
  1946. char roll_st;
  1947. char yaw_st;
  1948. };
  1949. struct navdata_t {
  1950. unsigned int version;
  1951. double compass_heading;
  1952. double compass_deviation;
  1953. double compass_variation;
  1954. double air_temp;
  1955. double air_pressure;
  1956. double water_temp;
  1957. double depth;
  1958. double depth_offset;
  1959. double wind_speed;
  1960. double wind_dir;
  1961. double crosstrack_error;
  1962. unsigned int compass_status;
  1963. unsigned int log_cumulative;
  1964. unsigned int log_trip;
  1965. unsigned int crosstrack_status;
  1966. };
  1967. struct dop_t {
  1968. /* Dilution of precision factors */
  1969. double xdop, ydop, pdop, hdop, vdop, tdop, gdop;
  1970. };
  1971. struct rawdata_t {
  1972. /* raw measurement data, suitable for RINEX 3 */
  1973. timespec_t mtime; /* time of measurement: sec, nsec
  1974. * Note: GPS time, not UTC time */
  1975. struct meas_t {
  1976. /* gnssid see satellite_t for decode */
  1977. unsigned char gnssid;
  1978. /* svid see RINEX 3 for decode, not satellite_t */
  1979. unsigned char svid;
  1980. /* sigid see satellite_t for decode */
  1981. unsigned char sigid;
  1982. /* SNR. 0 to 100 dB-Hz. u-blox can be 0 to 63. */
  1983. unsigned char snr;
  1984. unsigned char freqid; /* The GLONASS (Only) frequency, 0 - 13 */
  1985. unsigned char lli; /* RINEX Loss of Lock Indicator
  1986. * bit 0 - Lost Lock
  1987. * bit 1 - half-cycle ambiguity/slip possible
  1988. * bit 2 - GALILEO BOC-tracking of MBOC signal
  1989. */
  1990. char obs_code[4]; /* 3 char RINEX observation code */
  1991. /* see RINEX documenetation
  1992. * GPS: L1: L1C, L1S, L1L, L1X, L1P, L1W, L1N
  1993. * L2: L2C, L2D, L2S, L2L, L2X, L2P, L2W, L2N
  1994. * L5: L5I, L5Q
  1995. * GLONASS: G1: L1C, L1P
  1996. * G2: L2C, L2P
  1997. * G3: L3I, L3Q, L3X
  1998. * GALILEO: E1: L1B, L1C, L1X
  1999. * E5A: L5I, L5Ql L5X
  2000. * E5B: L7I, L7Q, L7X
  2001. * E5(A+B): L8I, L8Q, L8X
  2002. * E6: L6B, L6C, L6X
  2003. * QZSS: L1: L1C, L1S, L1L, L1X, L1Z
  2004. * L2: L2S, L2L, L2X
  2005. * L5: L5I, L5Q, L5X
  2006. * LEX(6): L6S, L6L, L6X
  2007. * BeiDou: B1: L2I, L2Q, L2X
  2008. * B2: L7I, L7Q, L7X
  2009. * B3: L6I, L6Q, L6X
  2010. * IRNSS: L5: L5A, L5B, L5C, L5X
  2011. * S: L9A, L9B, L9C, L9X
  2012. */
  2013. double codephase; /* meters */
  2014. double carrierphase; /* L1 C/A meters, RINEX L1C */
  2015. double pseudorange; /* L1 C/A meters, RINEX C1C */
  2016. double deltarange; /* L1 C/A meters/sec, RINEX D1C */
  2017. double doppler; /* Hz */
  2018. #define LOCKMAX 64500 /* locktime capped at 64500 */
  2019. unsigned locktime; /* Carrier Phase Locktime in ms.
  2020. * max 64,500 ms */
  2021. double l2c; /* L2 C/A carrier phase meters, RINEX L2C */
  2022. double c2c; /* L2 C/A pseudo-range meters, RINEX C2C */
  2023. unsigned satstat; /* tracking status */
  2024. #define SAT_ACQUIRED 0x01 /* satellite acquired */
  2025. #define SAT_CODE_TRACK 0x02 /* code-tracking loop acquired */
  2026. #define SAT_CARR_TRACK 0x04 /* carrier-tracking loop acquired */
  2027. #define SAT_DATA_SYNC 0x08 /* data-bit synchronization done */
  2028. #define SAT_FRAME_SYNC 0x10 /* frame synchronization done */
  2029. #define SAT_EPHEMERIS 0x20 /* ephemeris collected */
  2030. #define SAT_FIX_USED 0x40 /* used for position fix */
  2031. } meas[MAXCHANNELS];
  2032. };
  2033. struct version_t {
  2034. char release[64]; /* external version */
  2035. char rev[64]; /* internal revision ID */
  2036. int proto_major, proto_minor; /* API major and minor versions */
  2037. char remote[GPS_PATH_MAX]; /* could be from a remote device */
  2038. };
  2039. #define HEXDATA_MAX 512 /* hex encoded command buffer, max */
  2040. struct devconfig_t {
  2041. char path[GPS_PATH_MAX];
  2042. int flags;
  2043. #define SEEN_GPS 0x01
  2044. #define SEEN_RTCM2 0x02
  2045. #define SEEN_RTCM3 0x04
  2046. #define SEEN_AIS 0x08
  2047. char driver[64];
  2048. /* 96 too small for ZED-F9 */
  2049. char subtype[128]; // maybe hardware version
  2050. char subtype1[128]; // maybe software version
  2051. /* a buffer to hold data to output to GPS */
  2052. char hexdata[HEXDATA_MAX];
  2053. timespec_t activated;
  2054. unsigned int baudrate, stopbits; /* RS232 link parameters */
  2055. char parity; /* 'N', 'O', or 'E' */
  2056. timespec_t cycle, mincycle; /* refresh cycle time in seconds */
  2057. int driver_mode; /* is driver in native mode or not? */
  2058. };
  2059. struct gps_policy_t {
  2060. bool watcher; /* is watcher mode on? */
  2061. bool json; /* requesting JSON? */
  2062. bool nmea; /* requesting dumping as NMEA? */
  2063. int raw; /* requesting raw data? */
  2064. bool scaled; /* requesting report scaling? */
  2065. bool timing; /* requesting timing info */
  2066. bool split24; /* requesting split AIS Type 24s */
  2067. bool pps; /* requesting PPS in NMEA/raw modes */
  2068. int loglevel; /* requested log level of messages */
  2069. char devpath[GPS_PATH_MAX]; /* specific device to watch */
  2070. char remote[GPS_PATH_MAX]; /* ...if this was passthrough */
  2071. };
  2072. #ifndef TIMEDELTA_DEFINED
  2073. #define TIMEDELTA_DEFINED
  2074. struct timedelta_t {
  2075. timespec_t real;
  2076. timespec_t clock;
  2077. };
  2078. #endif /* TIMEDELTA_DEFINED */
  2079. struct oscillator_t {
  2080. bool running; /* oscillator is running */
  2081. bool reference; /* PPS reference is available */
  2082. bool disciplined; /* oscillator is GPS-disciplined */
  2083. int delta; /* last observed PPS delta */
  2084. };
  2085. /*
  2086. * Someday we may support Windows, under which socket_t is a separate type.
  2087. * In the meantime, having a typedef for this semantic kind is no bad thing,
  2088. * as it makes clearer what some declarations are doing without breaking
  2089. * binary compatibility.
  2090. */
  2091. typedef int socket_t;
  2092. #define BAD_SOCKET(s) ((s) == -1)
  2093. #define INVALIDATE_SOCKET(s) do { s = -1; } while (0)
  2094. /* mode flags for setting streaming policy */
  2095. #define WATCH_ENABLE 0x000001u /* enable streaming */
  2096. #define WATCH_DISABLE 0x000002u /* disable watching */
  2097. #define WATCH_JSON 0x000010u /* JSON output */
  2098. #define WATCH_NMEA 0x000020u /* output in NMEA */
  2099. #define WATCH_RARE 0x000040u /* output of packets in hex */
  2100. #define WATCH_RAW 0x000080u /* output of raw packets */
  2101. #define WATCH_SCALED 0x000100u /* scale output to floats */
  2102. #define WATCH_TIMING 0x000200u /* timing information */
  2103. #define WATCH_DEVICE 0x000800u /* watch specific device */
  2104. #define WATCH_SPLIT24 0x001000u /* split AIS Type 24s */
  2105. #define WATCH_PPS 0x002000u /* enable PPS JSON */
  2106. #define WATCH_NEWSTYLE 0x010000u /* force JSON streaming */
  2107. /*
  2108. * Main structure that includes all previous substructures
  2109. */
  2110. struct gps_data_t {
  2111. gps_mask_t set; /* has field been set since this was last cleared? */
  2112. #define ONLINE_SET (1llu<<1)
  2113. #define TIME_SET (1llu<<2)
  2114. #define TIMERR_SET (1llu<<3)
  2115. #define LATLON_SET (1llu<<4)
  2116. #define ALTITUDE_SET (1llu<<5)
  2117. #define SPEED_SET (1llu<<6)
  2118. #define TRACK_SET (1llu<<7)
  2119. #define CLIMB_SET (1llu<<8)
  2120. #define STATUS_SET (1llu<<9)
  2121. #define MODE_SET (1llu<<10)
  2122. #define DOP_SET (1llu<<11)
  2123. #define HERR_SET (1llu<<12)
  2124. #define VERR_SET (1llu<<13)
  2125. #define ATTITUDE_SET (1llu<<14)
  2126. #define SATELLITE_SET (1llu<<15)
  2127. #define SPEEDERR_SET (1llu<<16)
  2128. #define TRACKERR_SET (1llu<<17)
  2129. #define CLIMBERR_SET (1llu<<18)
  2130. #define DEVICE_SET (1llu<<19)
  2131. #define DEVICELIST_SET (1llu<<20)
  2132. #define DEVICEID_SET (1llu<<21)
  2133. #define RTCM2_SET (1llu<<22)
  2134. #define RTCM3_SET (1llu<<23)
  2135. #define AIS_SET (1llu<<24)
  2136. #define PACKET_SET (1llu<<25)
  2137. #define SUBFRAME_SET (1llu<<26)
  2138. #define GST_SET (1llu<<27)
  2139. #define VERSION_SET (1llu<<28)
  2140. #define POLICY_SET (1llu<<29)
  2141. #define LOGMESSAGE_SET (1llu<<30)
  2142. #define ERROR_SET (1llu<<31)
  2143. #define TOFF_SET (1llu<<32) /* not yet used */
  2144. #define PPS_SET (1llu<<33)
  2145. #define NAVDATA_SET (1llu<<34)
  2146. #define OSCILLATOR_SET (1llu<<35)
  2147. #define ECEF_SET (1llu<<36)
  2148. #define VECEF_SET (1llu<<37)
  2149. #define MAGNETIC_TRACK_SET (1llu<<38)
  2150. #define RAW_SET (1llu<<39)
  2151. #define NED_SET (1llu<<40)
  2152. #define VNED_SET (1llu<<41)
  2153. #define SET_HIGH_BIT 42
  2154. timespec_t online; /* NZ if GPS is on line, 0 if not.
  2155. *
  2156. * Note: gpsd clears this time when sentences
  2157. * fail to show up within the GPS's normal
  2158. * send cycle time. If the host-to-GPS
  2159. * link is lossy enough to drop entire
  2160. * sentences, this field will be
  2161. * prone to false zero values.
  2162. */
  2163. #ifndef USE_QT
  2164. socket_t gps_fd; /* socket or file descriptor to GPS */
  2165. #else
  2166. void* gps_fd;
  2167. #endif
  2168. struct gps_fix_t fix; /* accumulated PVT data */
  2169. /* GPS status -- always valid */
  2170. int status; /* Do we have a fix? */
  2171. #define STATUS_NO_FIX 0 /* no */
  2172. /* yes, plain GPS (SPS Mode), without DGPS, PPS, RTK, DR, etc. */
  2173. #define STATUS_FIX 1
  2174. #define STATUS_DGPS_FIX 2 /* yes, with DGPS */
  2175. #define STATUS_RTK_FIX 3 /* yes, with RTK Fixed */
  2176. #define STATUS_RTK_FLT 4 /* yes, with RTK Float */
  2177. #define STATUS_DR 5 /* yes, with dead reckoning */
  2178. #define STATUS_GNSSDR 6 /* yes, with GNSS + dead reckoning */
  2179. #define STATUS_TIME 7 /* yes, time only (surveyed in, manual) */
  2180. #define STATUS_SIM 8 /* yes, simulated */
  2181. /* yes, Precise Positioning Service (PPS)
  2182. * Not to be confused with Pulse per Second (PPS)
  2183. * PPS is the encrypted military P(Y)-code */
  2184. #define STATUS_PPS_FIX 9
  2185. /* precision of fix -- valid if satellites_used > 0 */
  2186. int satellites_used; /* Number of satellites used in solution */
  2187. struct dop_t dop;
  2188. /* satellite status -- valid when satellites_visible > 0 */
  2189. timespec_t skyview_time; /* skyview time */
  2190. int satellites_visible; /* # of satellites in view */
  2191. struct satellite_t skyview[MAXCHANNELS];
  2192. struct devconfig_t dev; /* device that shipped last update */
  2193. struct gps_policy_t policy; /* our listening policy */
  2194. struct {
  2195. timespec_t time;
  2196. int ndevices;
  2197. struct devconfig_t list[MAXUSERDEVS];
  2198. } devices;
  2199. /* pack things never reported together to reduce structure size */
  2200. #define UNION_SET (AIS_SET|ATTITUDE_SET|ERROR_SET|GST_SET| \
  2201. LOGMESSAGE_SET|OSCILLATOR_SET|PPS_SET|RAW_SET| \
  2202. RTCM2_SET|RTCM3_SET|SUBFRAME_SET|TOFF_SET|VERSION_SET)
  2203. union {
  2204. /* unusual forms of sensor data that might come up the pipe */
  2205. struct rtcm2_t rtcm2;
  2206. struct rtcm3_t rtcm3;
  2207. struct subframe_t subframe;
  2208. struct ais_t ais;
  2209. struct attitude_t attitude;
  2210. struct navdata_t navdata;
  2211. struct rawdata_t raw;
  2212. struct gst_t gst;
  2213. struct oscillator_t osc;
  2214. /* "artificial" structures for various protocol responses */
  2215. struct version_t version;
  2216. char error[256];
  2217. };
  2218. /* time stuff */
  2219. /* FIXME! next lib rev need to add a place to put PPS precision */
  2220. struct timedelta_t toff;
  2221. struct timedelta_t pps;
  2222. /* quantization error adjustment to PPS. aka "sawtooth" correction */
  2223. long qErr; /* offset in picoseconds (ps) */
  2224. /* time of PPS pulse that qErr applies to */
  2225. timespec_t qErr_time;
  2226. /* Private data - client code must not set this */
  2227. void *privdata;
  2228. };
  2229. extern int gps_open(const char *, const char *,
  2230. struct gps_data_t *);
  2231. extern int gps_close(struct gps_data_t *);
  2232. extern int gps_send(struct gps_data_t *, const char *, ... );
  2233. extern int gps_read(struct gps_data_t *, char *message, int message_len);
  2234. extern int gps_unpack(char *, struct gps_data_t *);
  2235. extern bool gps_waiting(const struct gps_data_t *, int);
  2236. extern int gps_stream(struct gps_data_t *, unsigned int, void *);
  2237. extern int gps_mainloop(struct gps_data_t *, int,
  2238. void (*)(struct gps_data_t *));
  2239. extern const char *gps_data(const struct gps_data_t *);
  2240. extern const char *gps_errstr(const int);
  2241. int json_toff_read(const char *buf, struct gps_data_t *,
  2242. const char **);
  2243. int json_pps_read(const char *buf, struct gps_data_t *,
  2244. const char **);
  2245. int json_oscillator_read(const char *buf, struct gps_data_t *,
  2246. const char **);
  2247. /* dependencies on struct gpsdata_t end here */
  2248. extern void libgps_trace(int errlevel, const char *, ...);
  2249. extern void gps_clear_att(struct attitude_t *);
  2250. extern void gps_clear_dop( struct dop_t *);
  2251. extern void gps_clear_fix(struct gps_fix_t *);
  2252. extern void gps_merge_fix(struct gps_fix_t *, gps_mask_t, struct gps_fix_t *);
  2253. extern void gps_enable_debug(int, FILE *);
  2254. extern const char *gps_maskdump(gps_mask_t);
  2255. extern double safe_atof(const char *);
  2256. extern time_t mkgmtime(struct tm *);
  2257. extern timespec_t iso8601_to_timespec(char *);
  2258. extern char *now_to_iso8601(char[], size_t len);
  2259. extern char *timespec_to_iso8601(timespec_t t, char[], size_t len);
  2260. extern double earth_distance(double, double, double, double);
  2261. extern double earth_distance_and_bearings(double, double, double, double,
  2262. double *,
  2263. double *);
  2264. extern double wgs84_separation(double, double);
  2265. extern double mag_var(double, double);
  2266. extern void datum_code_string(int code, char *buffer, size_t len);
  2267. /* some multipliers for interpreting GPS output */
  2268. #define METERS_TO_FEET (1 / 0.3048) /* Meters to International Foot */
  2269. /* Note: not the same as the USA Survey Foot: (3937 / 1200)
  2270. * Some states use the International Foot, not the USA Survey Foot */
  2271. #define METERS_TO_MILES 0.00062137119 /* Meters to miles */
  2272. #define METERS_TO_FATHOMS 0.54680665 /* Meters to fathoms */
  2273. #define KNOTS_TO_MPH 1.1507794 /* Knots to miles per hour */
  2274. #define KNOTS_TO_KPH 1.852 /* Knots to kilometers per hour */
  2275. #define KNOTS_TO_MPS 0.51444444 /* Knots to meters per second */
  2276. #define MPS_TO_KPH 3.6 /* Meters per second to klicks/hr */
  2277. #define MPS_TO_MPH 2.2369363 /* Meters/second to miles per hour */
  2278. #define MPS_TO_KNOTS 1.9438445 /* Meters per second to knots */
  2279. /* miles and knots are both the international standard versions of the units */
  2280. /* angle conversion multipliers */
  2281. #define GPS_PI 3.1415926535897932384626433832795029
  2282. #define RAD_2_DEG 57.2957795130823208767981548141051703
  2283. #define DEG_2_RAD 0.0174532925199432957692369076848861271
  2284. /* other mathematical constants */
  2285. #define GPS_LN2 0.693147180559945309417232121458176568
  2286. /* WGS84(G1674) degining parameters */
  2287. /* https://en.wikipedia.org/wiki/Geodetic_datum
  2288. * Section #World_Geodetic_System_1984_(WGS_84)
  2289. *
  2290. * http://www.unoosa.org/pdf/icg/2012/template/WGS_84.pdf
  2291. */
  2292. #define WGS84A 6378137.0 /* equatorial radius (semi-major axis) */
  2293. #define WGS84F 298.257223563 /* flattening */
  2294. #define WGS84B 6356752.314245 /* polar radius (semi-minor axis) */
  2295. /* 1st eccentricity squared = (WGS84A ^ 2 + WGS84B ^ 2) / (WGS84A ^ 2)
  2296. * precomputed so C does not recompute every time */
  2297. #define WGS84E 0.006694379990197585 /* 1st eccentricity squared */
  2298. /* 2nd eccentricity squared = ((WGS84A ^ 2 - WGS84B ^ 2) / (WGS84B ^ 2)
  2299. * precomputed so C does not recompute every time */
  2300. #define WGS84E2 0.006739496742333464 /* 2nd eccentricy squared */
  2301. #define CLIGHT 299792458.0 /* speed of light (m/s) */
  2302. /* netlib_connectsock() errno return values */
  2303. #define NL_NOSERVICE -1 /* can't get service entry */
  2304. #define NL_NOHOST -2 /* can't get host entry */
  2305. #define NL_NOPROTO -3 /* can't get protocol entry */
  2306. #define NL_NOSOCK -4 /* can't create socket */
  2307. #define NL_NOSOCKOPT -5 /* error SETSOCKOPT SO_REUSEADDR */
  2308. #define NL_NOCONNECT -6 /* can't connect to host/socket pair */
  2309. #define SHM_NOSHARED -7 /* shared-memory segment not available */
  2310. #define SHM_NOATTACH -8 /* shared-memory attach failed */
  2311. #define DBUS_FAILURE -9 /* DBUS initialization failure */
  2312. #define DEFAULT_GPSD_PORT "2947" /* IANA assignment */
  2313. #define DEFAULT_RTCM_PORT "2101" /* IANA assignment */
  2314. /* special host values for non-socket exports */
  2315. #define GPSD_SHARED_MEMORY "shared memory"
  2316. #define GPSD_DBUS_EXPORT "DBUS export"
  2317. #ifdef __cplusplus
  2318. } /* End of the 'extern "C"' block */
  2319. #endif
  2320. #endif /* _GPSD_GPS_H_ */
  2321. /* gps.h ends here */