gps.h 118 KB

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