driver_rtcm3.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*****************************************************************************
  2. This is a decoder for RTCM-104 3.x, a serial protocol used for
  3. broadcasting pseudorange corrections from differential-GPS reference
  4. stations. The applicable specification is RTCM 10403.1: RTCM Paper
  5. 177-2006-SC104-STD. This obsolesces the earlier RTCM-104 2.x
  6. specifications. The specification document is proprietary; ordering
  7. instructions are accessible from <http://www.rtcm.org/>
  8. under "Publications".
  9. Unike the RTCM 2.x protocol, RTCM3.x does not use the strange
  10. sliding-bit-window IS-GPS-200 protocol as a transport layer, but is a
  11. self-contained byte-oriented packet protocol. Packet recognition is
  12. handled in the GPSD packet-getter state machine; this code is
  13. concerned with unpacking the packets into well-behaved C structures,
  14. coping with odd field lengths and fields that may overlap byte
  15. boudaries. These report structures live in gps.h.
  16. Note that the unpacking this module does is probably useful only for
  17. RTCM reporting and diagnostic tools. It is not necessary when
  18. passing RTCM corrections to a GPS, which normally should just be
  19. passed an entire correction packet for processing by their internal
  20. firmware.
  21. Decodes of the following types have been verified: 1004, 1005, 1006,
  22. 1008, 1012, 1013, 1029. There is good reason to believe the 1007 code
  23. is correct, as it's identical to 1008 up to where it ends.
  24. The 1033 decode was arrived at by looking at an rtcminspect dump and noting
  25. that it carries an information superset of the 1008. There are additional
  26. Receiver and Firmware fields we're not certain to decode without access
  27. to an RTCM3 standard at revision 4 or later, but the guess in the code
  28. has been observed to correctly analyze a message with a nonempty Receiver
  29. field.
  30. This file is Copyright (c) 2010-2018 by the GPSD project
  31. SPDX-License-Identifier: BSD-2-clause
  32. *****************************************************************************/
  33. #include "gpsd_config.h" /* must be before all includes */
  34. #include <string.h>
  35. #include "gpsd.h"
  36. #include "bits.h"
  37. #ifdef RTCM104V3_ENABLE
  38. /* scaling constants for RTCM3 real number types */
  39. #define GPS_PSEUDORANGE_RESOLUTION 0.02 /* DF011 */
  40. #define PSEUDORANGE_DIFF_RESOLUTION 0.0005 /* DF012,DF042 */
  41. #define CARRIER_NOISE_RATIO_UNITS 0.25 /* DF015, DF045, DF50 */
  42. #define ANTENNA_POSITION_RESOLUTION 0.0001 /* DF025-027 */
  43. #define GLONASS_PSEUDORANGE_RESOLUTION 0.02 /* DF041 */
  44. #define ANTENNA_DEGREE_RESOLUTION 25e-6 /* DF062 */
  45. #define GPS_EPOCH_TIME_RESOLUTION 0.1 /* DF065 */
  46. #define PHASE_CORRECTION_RESOLUTION 0.5 /* DF069-070 */
  47. /* Other magic values */
  48. #define GPS_INVALID_PSEUDORANGE 0x80000 /* DF012, DF018 */
  49. #define GLONASS_INVALID_RANGEINCR 0x2000 /* DF047 */
  50. #define GLONASS_CHANNEL_BASE 7 /* DF040 */
  51. /* Large case statements make GNU indent very confused */
  52. /* *INDENT-OFF* */
  53. /* good source on message types:
  54. * https://software.rtcm-ntrip.org/export/HEAD/ntrip/trunk/BNC/src/bnchelp.html
  55. * Also look in the BNC source
  56. * and look at the tklib source: http://www.rtklib.com/
  57. */
  58. void rtcm3_unpack(const struct gps_context_t *context,
  59. struct rtcm3_t *rtcm, char *buf)
  60. /* break out the raw bits into the scaled report-structure fields */
  61. {
  62. unsigned int n, n2, n3, n4;
  63. int bitcount = 0;
  64. unsigned int i;
  65. signed long temp;
  66. bool unknown = true;;
  67. #define ugrab(width) (bitcount += width, ubits((unsigned char *)buf, bitcount-width, width, false))
  68. #define sgrab(width) (bitcount += width, sbits((signed char *)buf, bitcount-width, width, false))
  69. #define GPS_PSEUDORANGE(fld, len) \
  70. {temp = (unsigned long)ugrab(len); \
  71. if (temp == GPS_INVALID_PSEUDORANGE) \
  72. fld.pseudorange = 0; \
  73. else \
  74. fld.pseudorange = temp * GPS_PSEUDORANGE_RESOLUTION;}
  75. #define RANGEDIFF(fld, len) \
  76. temp = (long)sgrab(len); \
  77. if (temp == GPS_INVALID_PSEUDORANGE) \
  78. fld.rangediff = 0; \
  79. else \
  80. fld.rangediff = temp * PSEUDORANGE_DIFF_RESOLUTION;
  81. memset(rtcm, 0, sizeof(struct rtcm3_t));
  82. //assert(ugrab(8) == 0xD3);
  83. //assert(ugrab(6) == 0x00);
  84. ugrab(14);
  85. rtcm->length = (unsigned int)ugrab(10);
  86. rtcm->type = (unsigned int)ugrab(12);
  87. GPSD_LOG(LOG_RAW, &context->errout, "RTCM3: type %d payload length %d\n",
  88. rtcm->type, rtcm->length);
  89. switch (rtcm->type) {
  90. case 63:
  91. /* RTCM - 63
  92. * BDS/BeiDou Ephemeris
  93. * length 64
  94. */
  95. break;
  96. case 1001:
  97. /* GPS Basic RTK, L1 Only */
  98. rtcm->rtcmtypes.rtcm3_1001.header.station_id = (unsigned int)ugrab(12);
  99. rtcm->rtcmtypes.rtcm3_1001.header.tow = (time_t)ugrab(30);
  100. rtcm->rtcmtypes.rtcm3_1001.header.sync = (bool)ugrab(1);
  101. rtcm->rtcmtypes.rtcm3_1001.header.satcount = (unsigned short)ugrab(5);
  102. rtcm->rtcmtypes.rtcm3_1001.header.smoothing = (bool)ugrab(1);
  103. rtcm->rtcmtypes.rtcm3_1001.header.interval = (unsigned short)ugrab(3);
  104. #define R1001 rtcm->rtcmtypes.rtcm3_1001.rtk_data[i]
  105. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1001.header.satcount; i++) {
  106. R1001.ident = (unsigned short)ugrab(6);
  107. R1001.L1.indicator = (unsigned char)ugrab(1);
  108. GPS_PSEUDORANGE(R1001.L1, 24);
  109. RANGEDIFF(R1001.L1, 20);
  110. R1001.L1.locktime = (unsigned char)sgrab(7);
  111. }
  112. #undef R1001
  113. unknown = false;
  114. break;
  115. case 1002:
  116. /* GPS Extended RTK, L1 Only */
  117. rtcm->rtcmtypes.rtcm3_1002.header.station_id = (unsigned int)ugrab(12);
  118. rtcm->rtcmtypes.rtcm3_1002.header.tow = (time_t)ugrab(30);
  119. rtcm->rtcmtypes.rtcm3_1002.header.sync = (bool)ugrab(1);
  120. rtcm->rtcmtypes.rtcm3_1002.header.satcount = (unsigned short)ugrab(5);
  121. rtcm->rtcmtypes.rtcm3_1002.header.smoothing = (bool)ugrab(1);
  122. rtcm->rtcmtypes.rtcm3_1002.header.interval = (unsigned short)ugrab(3);
  123. #define R1002 rtcm->rtcmtypes.rtcm3_1002.rtk_data[i]
  124. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1002.header.satcount; i++) {
  125. R1002.ident = (unsigned short)ugrab(6);
  126. R1002.L1.indicator = (unsigned char)ugrab(1);
  127. GPS_PSEUDORANGE(R1002.L1, 24);
  128. RANGEDIFF(R1002.L1, 20);
  129. R1002.L1.locktime = (unsigned char)sgrab(7);
  130. R1002.L1.ambiguity = (unsigned char)ugrab(8);
  131. R1002.L1.CNR = (ugrab(8)) * CARRIER_NOISE_RATIO_UNITS;
  132. }
  133. #undef R1002
  134. unknown = false;
  135. break;
  136. case 1003:
  137. /* GPS Basic RTK, L1 & L2 */
  138. rtcm->rtcmtypes.rtcm3_1003.header.station_id = (unsigned int)ugrab(12);
  139. rtcm->rtcmtypes.rtcm3_1003.header.tow = (time_t)ugrab(30);
  140. rtcm->rtcmtypes.rtcm3_1003.header.sync = (bool)ugrab(1);
  141. rtcm->rtcmtypes.rtcm3_1003.header.satcount = (unsigned short)ugrab(5);
  142. rtcm->rtcmtypes.rtcm3_1003.header.smoothing = (bool)ugrab(1);
  143. rtcm->rtcmtypes.rtcm3_1003.header.interval = (unsigned short)ugrab(3);
  144. #define R1003 rtcm->rtcmtypes.rtcm3_1003.rtk_data[i]
  145. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1003.header.satcount; i++) {
  146. R1003.ident = (unsigned short)ugrab(6);
  147. R1003.L1.indicator =
  148. (unsigned char)ugrab(1);
  149. GPS_PSEUDORANGE(R1003.L1, 24);
  150. RANGEDIFF(R1003.L1, 20);
  151. R1003.L1.locktime = (unsigned char)sgrab(7);
  152. R1003.L2.indicator = (unsigned char)ugrab(2);
  153. GPS_PSEUDORANGE(R1003.L2, 24);
  154. temp = (long)sgrab(20);
  155. if (temp == GPS_INVALID_PSEUDORANGE)
  156. R1003.L2.rangediff = 0;
  157. else
  158. R1003.L2.rangediff = temp * PSEUDORANGE_DIFF_RESOLUTION;
  159. R1003.L2.locktime = (unsigned char)sgrab(7);
  160. }
  161. #undef R1003
  162. unknown = false;
  163. break;
  164. case 1004:
  165. /* GPS Extended RTK, L1 & L2 */
  166. rtcm->rtcmtypes.rtcm3_1004.header.station_id = (unsigned int)ugrab(12);
  167. rtcm->rtcmtypes.rtcm3_1004.header.tow = (time_t)ugrab(30);
  168. rtcm->rtcmtypes.rtcm3_1004.header.sync = (bool)ugrab(1);
  169. rtcm->rtcmtypes.rtcm3_1004.header.satcount = (unsigned short)ugrab(5);
  170. rtcm->rtcmtypes.rtcm3_1004.header.smoothing = (bool)ugrab(1);
  171. rtcm->rtcmtypes.rtcm3_1004.header.interval = (unsigned short)ugrab(3);
  172. #define R1004 rtcm->rtcmtypes.rtcm3_1004.rtk_data[i]
  173. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1004.header.satcount; i++) {
  174. R1004.ident = (unsigned short)ugrab(6);
  175. R1004.L1.indicator = (bool)ugrab(1);
  176. GPS_PSEUDORANGE(R1004.L1, 24);
  177. RANGEDIFF(R1004.L1, 20);
  178. R1004.L1.locktime = (unsigned char)sgrab(7);
  179. R1004.L1.ambiguity = (unsigned char)ugrab(8);
  180. R1004.L1.CNR = ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  181. R1004.L2.indicator = (unsigned char)ugrab(2);
  182. GPS_PSEUDORANGE(R1004.L2, 14);
  183. RANGEDIFF(R1004.L2, 20);
  184. R1004.L2.locktime = (unsigned char)sgrab(7);
  185. R1004.L2.CNR = ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  186. }
  187. #undef R1004
  188. unknown = false;
  189. break;
  190. case 1005:
  191. /* Stationary Antenna Reference Point, No Height Information */
  192. #define R1005 rtcm->rtcmtypes.rtcm3_1005
  193. R1005.station_id = (unsigned short)ugrab(12);
  194. ugrab(6); /* reserved */
  195. R1005.system = ugrab(3);
  196. R1005.reference_station = (bool)ugrab(1);
  197. R1005.ecef_x = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
  198. R1005.single_receiver = ugrab(1);
  199. ugrab(1);
  200. R1005.ecef_y = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
  201. ugrab(2);
  202. R1005.ecef_z = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
  203. #undef R1005
  204. unknown = false;
  205. break;
  206. case 1006:
  207. /* Stationary Antenna Reference Point, with Height Information */
  208. #define R1006 rtcm->rtcmtypes.rtcm3_1006
  209. R1006.station_id = (unsigned short)ugrab(12);
  210. (void)ugrab(6); /* reserved */
  211. R1006.system = ugrab(3);
  212. R1006.reference_station = (bool)ugrab(1);
  213. R1006.ecef_x = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
  214. R1006.single_receiver = ugrab(1);
  215. ugrab(1);
  216. R1006.ecef_y = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
  217. ugrab(2);
  218. R1006.ecef_z = sgrab(38) * ANTENNA_POSITION_RESOLUTION;
  219. R1006.height = ugrab(16) * ANTENNA_POSITION_RESOLUTION;
  220. #undef R1006
  221. unknown = false;
  222. break;
  223. case 1007:
  224. /* Antenna Descriptor */
  225. rtcm->rtcmtypes.rtcm3_1007.station_id = (unsigned short)ugrab(12);
  226. n = (unsigned long)ugrab(8);
  227. (void)memcpy(rtcm->rtcmtypes.rtcm3_1007.descriptor, buf + 7, n);
  228. rtcm->rtcmtypes.rtcm3_1007.descriptor[n] = '\0';
  229. bitcount += 8 * n;
  230. rtcm->rtcmtypes.rtcm3_1007.setup_id = ugrab(8);
  231. unknown = false;
  232. break;
  233. case 1008:
  234. /* Antenna Descriptor & Serial Number */
  235. rtcm->rtcmtypes.rtcm3_1008.station_id = (unsigned short)ugrab(12);
  236. n = (unsigned long)ugrab(8);
  237. (void)memcpy(rtcm->rtcmtypes.rtcm3_1008.descriptor, buf + 7, n);
  238. rtcm->rtcmtypes.rtcm3_1008.descriptor[n] = '\0';
  239. bitcount += 8 * n;
  240. rtcm->rtcmtypes.rtcm3_1008.setup_id = ugrab(8);
  241. n2 = (unsigned long)ugrab(8);
  242. (void)memcpy(rtcm->rtcmtypes.rtcm3_1008.serial, buf + 9 + n, n2);
  243. rtcm->rtcmtypes.rtcm3_1008.serial[n2] = '\0';
  244. //bitcount += 8 * n2;
  245. unknown = false;
  246. break;
  247. case 1009:
  248. /* GLONASS Basic RTK, L1 Only */
  249. rtcm->rtcmtypes.rtcm3_1009.header.station_id =
  250. (unsigned short)ugrab(12);
  251. rtcm->rtcmtypes.rtcm3_1009.header.tow = (time_t)ugrab(27);
  252. rtcm->rtcmtypes.rtcm3_1009.header.sync = (bool)ugrab(1);
  253. rtcm->rtcmtypes.rtcm3_1009.header.satcount = (unsigned short)ugrab(5);
  254. rtcm->rtcmtypes.rtcm3_1009.header.smoothing = (bool)ugrab(1);
  255. rtcm->rtcmtypes.rtcm3_1009.header.interval = (unsigned short)ugrab(3);
  256. #define R1009 rtcm->rtcmtypes.rtcm3_1009.rtk_data[i]
  257. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1009.header.satcount; i++) {
  258. R1009.ident = (unsigned short)ugrab(6);
  259. R1009.L1.indicator = (bool)ugrab(1);
  260. R1009.L1.channel = (short)ugrab(5) - GLONASS_CHANNEL_BASE;
  261. R1009.L1.pseudorange = ugrab(25) * GLONASS_PSEUDORANGE_RESOLUTION;
  262. RANGEDIFF(R1009.L1, 20);
  263. R1009.L1.locktime = (unsigned char)sgrab(7);
  264. }
  265. #undef R1009
  266. unknown = false;
  267. break;
  268. case 1010:
  269. /* GLONASS Extended RTK, L1 Only */
  270. rtcm->rtcmtypes.rtcm3_1010.header.station_id =
  271. (unsigned short)ugrab(12);
  272. rtcm->rtcmtypes.rtcm3_1010.header.tow = (time_t)ugrab(27);
  273. rtcm->rtcmtypes.rtcm3_1010.header.sync = (bool)ugrab(1);
  274. rtcm->rtcmtypes.rtcm3_1010.header.satcount = (unsigned short)ugrab(5);
  275. rtcm->rtcmtypes.rtcm3_1010.header.smoothing = (bool)ugrab(1);
  276. rtcm->rtcmtypes.rtcm3_1010.header.interval = (unsigned short)ugrab(3);
  277. #define R1010 rtcm->rtcmtypes.rtcm3_1010.rtk_data[i]
  278. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1010.header.satcount; i++) {
  279. R1010.ident = (unsigned short)ugrab(6);
  280. R1010.L1.indicator = (bool)ugrab(1);
  281. R1010.L1.channel = (short)ugrab(5) - GLONASS_CHANNEL_BASE;
  282. R1010.L1.pseudorange = ugrab(25) * GLONASS_PSEUDORANGE_RESOLUTION;
  283. RANGEDIFF(R1010.L1, 20);
  284. R1010.L1.locktime = (unsigned char)sgrab(7);
  285. R1010.L1.ambiguity = (unsigned char)ugrab(7);
  286. R1010.L1.CNR = ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  287. }
  288. #undef R1010
  289. unknown = false;
  290. break;
  291. case 1011:
  292. /* GLONASS Basic RTK, L1 & L2 */
  293. rtcm->rtcmtypes.rtcm3_1011.header.station_id =
  294. (unsigned short)ugrab(12);
  295. rtcm->rtcmtypes.rtcm3_1011.header.tow = (time_t)ugrab(27);
  296. rtcm->rtcmtypes.rtcm3_1011.header.sync = (bool)ugrab(1);
  297. rtcm->rtcmtypes.rtcm3_1011.header.satcount = (unsigned short)ugrab(5);
  298. rtcm->rtcmtypes.rtcm3_1011.header.smoothing = (bool)ugrab(1);
  299. rtcm->rtcmtypes.rtcm3_1011.header.interval = (unsigned short)ugrab(3);
  300. #define R1011 rtcm->rtcmtypes.rtcm3_1011.rtk_data[i]
  301. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1011.header.satcount; i++) {
  302. R1011.ident = (unsigned short)ugrab(6);
  303. R1011.L1.indicator = (bool)ugrab(1);
  304. R1011.L1.channel = (short)ugrab(5) - GLONASS_CHANNEL_BASE;
  305. R1011.L1.pseudorange = ugrab(25) * GLONASS_PSEUDORANGE_RESOLUTION;
  306. RANGEDIFF(R1011.L1, 20);
  307. R1011.L1.locktime = (unsigned char)sgrab(7);
  308. R1011.L1.ambiguity = (unsigned char)ugrab(7);
  309. R1011.L1.CNR = ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  310. R1011.L2.indicator = (bool)ugrab(1);
  311. R1011.L2.channel = (short)ugrab(5) - GLONASS_CHANNEL_BASE;
  312. R1011.L2.pseudorange = ugrab(25) * GLONASS_PSEUDORANGE_RESOLUTION;
  313. RANGEDIFF(R1011.L2, 20);
  314. R1011.L2.locktime = (unsigned char)sgrab(7);
  315. R1011.L2.ambiguity = (unsigned char)ugrab(7);
  316. R1011.L2.CNR = ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  317. }
  318. #undef R1011
  319. unknown = false;
  320. break;
  321. case 1012:
  322. /* GLONASS Extended RTK, L1 & L2 */
  323. rtcm->rtcmtypes.rtcm3_1012.header.station_id =
  324. (unsigned short)ugrab(12);
  325. rtcm->rtcmtypes.rtcm3_1012.header.tow = (time_t)ugrab(27);
  326. rtcm->rtcmtypes.rtcm3_1012.header.sync = (bool)ugrab(1);
  327. rtcm->rtcmtypes.rtcm3_1012.header.satcount = (unsigned short)ugrab(5);
  328. rtcm->rtcmtypes.rtcm3_1012.header.smoothing = (bool)ugrab(1);
  329. rtcm->rtcmtypes.rtcm3_1012.header.interval = (unsigned short)ugrab(3);
  330. #define R1012 rtcm->rtcmtypes.rtcm3_1012.rtk_data[i]
  331. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1012.header.satcount; i++) {
  332. unsigned int rangeincr;
  333. R1012.ident = (unsigned short)ugrab(6);
  334. R1012.L1.indicator = (bool)ugrab(1);
  335. R1012.L1.channel = (short)ugrab(5) - GLONASS_CHANNEL_BASE;
  336. R1012.L1.pseudorange = ugrab(25) * GLONASS_PSEUDORANGE_RESOLUTION;
  337. RANGEDIFF(R1012.L1, 20);
  338. R1012.L1.locktime = (unsigned char)ugrab(7);
  339. R1012.L1.ambiguity = (unsigned char)ugrab(7);
  340. R1012.L1.CNR = (unsigned char)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  341. R1012.L2.indicator = (bool)ugrab(2);
  342. rangeincr = ugrab(14);
  343. if (rangeincr == GLONASS_INVALID_RANGEINCR)
  344. R1012.L2.pseudorange = 0;
  345. else
  346. R1012.L2.pseudorange = (rangeincr * GLONASS_PSEUDORANGE_RESOLUTION);
  347. RANGEDIFF(R1012.L2, 20);
  348. R1012.L2.locktime = (unsigned char)sgrab(7);
  349. R1012.L2.CNR = (unsigned char)ugrab(8) * CARRIER_NOISE_RATIO_UNITS;
  350. }
  351. #undef R1012
  352. unknown = false;
  353. break;
  354. case 1013:
  355. /* System Parameters */
  356. rtcm->rtcmtypes.rtcm3_1013.station_id = (unsigned short)ugrab(12);
  357. rtcm->rtcmtypes.rtcm3_1013.mjd = (unsigned short)ugrab(16);
  358. rtcm->rtcmtypes.rtcm3_1013.sod = (unsigned short)ugrab(17);
  359. rtcm->rtcmtypes.rtcm3_1013.ncount = (unsigned long)ugrab(5);
  360. rtcm->rtcmtypes.rtcm3_1013.leapsecs = (unsigned char)ugrab(8);
  361. #define R1013 rtcm->rtcmtypes.rtcm3_1013.announcements[i]
  362. for (i = 0; i < rtcm->rtcmtypes.rtcm3_1013.ncount; i++) {
  363. R1013.id = (unsigned short)ugrab(12);
  364. R1013.sync = (bool)ugrab(1);
  365. R1013.interval = (unsigned short)ugrab(16);
  366. }
  367. #undef R1013
  368. unknown = false;
  369. break;
  370. case 1014:
  371. /* Network Auxiliary Station Data
  372. * coordinate difference between one Aux station and the master station
  373. */
  374. rtcm->rtcmtypes.rtcm3_1014.network_id = (int)ugrab(8);
  375. rtcm->rtcmtypes.rtcm3_1014.subnetwork_id = (int)ugrab(4);
  376. rtcm->rtcmtypes.rtcm3_1014.stationcount = (char)ugrab(5);
  377. rtcm->rtcmtypes.rtcm3_1014.master_id = (int)ugrab(12);
  378. rtcm->rtcmtypes.rtcm3_1014.aux_id = (int)ugrab(12);
  379. rtcm->rtcmtypes.rtcm3_1014.d_lat =
  380. (unsigned short)ugrab(20) * ANTENNA_DEGREE_RESOLUTION;
  381. rtcm->rtcmtypes.rtcm3_1014.d_lon =
  382. (unsigned short)ugrab(21) * ANTENNA_DEGREE_RESOLUTION;
  383. rtcm->rtcmtypes.rtcm3_1014.d_alt = (unsigned short)ugrab(23) / 1000;
  384. unknown = false;
  385. break;
  386. case 1017:
  387. /* RTCM 3.1 - 1017
  388. * GPS Combined Geometric and Ionospheric Correction Differences
  389. * for all satellites between one Aux station and the master station
  390. * (same content as both types 1015 and 1016 together, but less size)
  391. */
  392. break;
  393. case 1019:
  394. /* RTCM 3.1 - 1020
  395. * GPS Ephemeris
  396. * length 19
  397. */
  398. /* TODO: rtklib has C code for this one. */
  399. break;
  400. case 1020:
  401. /* RTCM 3.1 - 1020
  402. * GLONASS Ephemeris
  403. * length 45
  404. */
  405. /* TODO: rtklib has C code for this one. */
  406. break;
  407. case 1029:
  408. /* Text in UTF8 format
  409. *(max. 127 multibyte characters and max. 255 bytes)
  410. */
  411. rtcm->rtcmtypes.rtcm3_1029.station_id = (unsigned short)ugrab(12);
  412. rtcm->rtcmtypes.rtcm3_1029.mjd = (unsigned short)ugrab(16);
  413. rtcm->rtcmtypes.rtcm3_1029.sod = (unsigned short)ugrab(17);
  414. rtcm->rtcmtypes.rtcm3_1029.len = (unsigned long)ugrab(7);
  415. rtcm->rtcmtypes.rtcm3_1029.unicode_units = (size_t)ugrab(8);
  416. (void)memcpy(rtcm->rtcmtypes.rtcm3_1029.text,
  417. buf + 12, rtcm->rtcmtypes.rtcm3_1029.unicode_units);
  418. unknown = false;
  419. break;
  420. case 1033: /* see note in header */
  421. /* Receiver and Antenna Descriptor
  422. * Type1033 is a combined Message Types 1007 and 1008
  423. * and hence contains antenna descriptor and serial number
  424. * as well as receiver descriptor and serial number.
  425. */
  426. /* TODO: rtklib has C code for this one. */
  427. rtcm->rtcmtypes.rtcm3_1033.station_id = (unsigned short)ugrab(12);
  428. n = (unsigned long)ugrab(8);
  429. (void)memcpy(rtcm->rtcmtypes.rtcm3_1033.descriptor, buf + 7, n);
  430. rtcm->rtcmtypes.rtcm3_1033.descriptor[n] = '\0';
  431. bitcount += 8 * n;
  432. rtcm->rtcmtypes.rtcm3_1033.setup_id = ugrab(8);
  433. n2 = (unsigned long)ugrab(8);
  434. (void)memcpy(rtcm->rtcmtypes.rtcm3_1033.serial, buf + 9 + n, n2);
  435. rtcm->rtcmtypes.rtcm3_1033.serial[n2] = '\0';
  436. bitcount += 8 * n2;
  437. n3 = (unsigned long)ugrab(8);
  438. (void)memcpy(rtcm->rtcmtypes.rtcm3_1033.receiver, buf + 10+n+n2, n3);
  439. rtcm->rtcmtypes.rtcm3_1033.receiver[n3] = '\0';
  440. bitcount += 8 * n3;
  441. n4 = (unsigned long)ugrab(8);
  442. (void)memcpy(rtcm->rtcmtypes.rtcm3_1033.firmware, buf + 11+n+n2+n3, n3);
  443. rtcm->rtcmtypes.rtcm3_1033.firmware[n4] = '\0';
  444. //bitcount += 8 * n4;
  445. // TODO: next is receiver serial number
  446. unknown = false;
  447. break;
  448. case 1043:
  449. /* RTCM 3.x - 1043
  450. * SBAS Ephemeris
  451. * length 29
  452. */
  453. break;
  454. case 1044:
  455. /* RTCM 3.x - 1044
  456. * QZSS ephemeris
  457. * length 61
  458. */
  459. /* TODO: rtklib has C code for this one. */
  460. break;
  461. case 1045:
  462. /* RTCM 3.x - 1045
  463. * Galileo Ephemeris FNAV data
  464. * length 62
  465. */
  466. /* TODO: rtklib has C code for this one. */
  467. break;
  468. case 1046:
  469. /* RTCM 3.x - 1046
  470. * Galileo Ephemeris INAV data
  471. * length 63
  472. */
  473. /* TODO: rtklib has C code for this one. */
  474. break;
  475. case 1074:
  476. /* RTCM 3.x
  477. * GPS Multi Signal Message
  478. */
  479. break;
  480. case 1077:
  481. /* RTCM 3.x - 1077
  482. * Full GPS pseudo-ranges, carrier phases, Doppler and
  483. * signal strength (high resolution)
  484. * length 438
  485. */
  486. /* TODO: rtklib has C code for this one. */
  487. break;
  488. case 1087:
  489. /* RTCM 3.x - 1087
  490. * Full GLONASS pseudo-ranges, carrier phases, Doppler and
  491. * signal strength (high resolution)
  492. * length 417 or 427
  493. */
  494. /* TODO: rtklib has C code for this one. */
  495. break;
  496. case 1097:
  497. /* RTCM 3.x - 1097
  498. * Full Galileo pseudo-ranges, carrier phases, Doppler and
  499. * signal strength (high resolution)
  500. * length 96
  501. */
  502. /* TODO: rtklib has C code for this one. */
  503. break;
  504. case 1107:
  505. /* RTCM 3.x - 1107
  506. * 'Multiple Signal Message
  507. * Full SBAS pseudo-ranges, carrier phases, Doppler and
  508. * signal strength (high resolution)
  509. * length 96
  510. */
  511. /* TODO: rtklib has C code for this one. */
  512. break;
  513. case 1114:
  514. /* RTCM 3.x
  515. * QZSS Multi Signal Message
  516. */
  517. break;
  518. case 1124:
  519. /* RTCM 3.x
  520. * BeiDou Multi Signal Message
  521. */
  522. break;
  523. default:
  524. break;
  525. }
  526. #undef RANGEDIFF
  527. #undef GPS_PSEUDORANGE
  528. #undef sgrab
  529. #undef ugrab
  530. if ( unknown ) {
  531. /*
  532. * Leader bytes, message length, and checksum won't be copied.
  533. * The first 12 bits of the copied payload will be the type field.
  534. */
  535. memcpy(rtcm->rtcmtypes.data, buf+3, rtcm->length);
  536. GPSD_LOG(LOG_PROG, &context->errout,
  537. "RTCM3: unknown type %d, length %d\n",
  538. rtcm->type, rtcm->length);
  539. }
  540. }
  541. /* *INDENT-ON* */
  542. #endif /* RTCM104V3_ENABLE */