Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2412 lines
90 KiB

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