source: ntrip/trunk/BNC/RTCM3/clock_orbit_rtcm.c@ 2088

Last change on this file since 2088 was 2020, checked in by mervart, 15 years ago

* empty log message *

  • Property svn:executable set to *
File size: 34.8 KB
RevLine 
[865]1/* Programheader
2
3 Name: clock_orbit_rtcm.c
4 Project: RTCM3
[2020]5 Version: $Id: clock_orbit_rtcm.c,v 1.17.2.1 2009/11/25 15:11:47 mervart Exp $
[865]6 Authors: Dirk Stöcker
7 Description: state space approach for RTCM3
8*/
9
10#include <stdio.h>
11#include <string.h>
[2020]12#include <sys/types.h>
13
14#ifndef sparc
[865]15#include <stdint.h>
[2020]16#endif
17
[865]18#include "clock_orbit_rtcm.h"
19
20static uint32_t CRC24(long size, const unsigned char *buf)
21{
22 uint32_t crc = 0;
23 int i;
24
25 while(size--)
26 {
27 crc ^= (*buf++) << (16);
28 for(i = 0; i < 8; i++)
29 {
30 crc <<= 1;
31 if(crc & 0x1000000)
32 crc ^= 0x01864cfb;
33 }
34 }
35 return crc;
36}
37
38/* NOTE: These defines are interlinked with below functions and directly modify
39the values. This may not be optimized in terms of final program code size but
40should be optimized in terms of speed.
41
42modified variables are:
43- everything defined in STARTDATA (only use ressize outside of the defines,
44 others are private)
45- buffer
46- size
47*/
48
49#ifndef NOENCODE
50#define STOREBITS \
51 while(numbits >= 8) \
52 { \
53 if(!size) return 0; \
54 *(buffer++) = bitbuffer>>(numbits-8); \
55 numbits -= 8; \
56 ++ressize; \
57 --size; \
58 }
59
60#define ADDBITS(a, b) \
61 { \
62 bitbuffer = (bitbuffer<<(a))|((b)&((1<<a)-1)); \
63 numbits += (a); \
64 STOREBITS \
65 }
66
67#define STARTDATA \
68 size_t ressize=0; \
69 char *blockstart; \
70 int numbits; \
71 uint64_t bitbuffer=0;
72
73#define INITBLOCK \
74 numbits = 0; \
75 blockstart = buffer; \
76 ADDBITS(8, 0xD3) \
77 ADDBITS(6, 0) \
78 ADDBITS(10, 0)
79
80#define ENDBLOCK \
81 if(numbits) { ADDBITS((8-numbits), 0) } \
82 { \
83 int len = buffer-blockstart-3; \
84 blockstart[1] |= len>>8; \
85 blockstart[2] = len; \
[1827]86 if(len > 1023) \
87 return 0; \
[865]88 len = CRC24(len+3, (const unsigned char *) blockstart); \
89 ADDBITS(24, len) \
90 }
91
92#define SCALEADDBITS(a, b, c) ADDBITS(a, (int64_t)(b*c))
93
94/* standard values */
95#define T_MESSAGE_NUMBER(a) ADDBITS(12, a) /* DF002 */
[1664]96#define T_RESERVED5 ADDBITS(5, 0) /* DF001 */
[865]97#define T_GPS_SATELLITE_ID(a) ADDBITS(6, a) /* DF068 */
98#define T_GPS_IODE(a) ADDBITS(8, a) /* DF071 */
99#define T_GLONASS_IOD(a) ADDBITS(8, a) /* DF237 */
100
101/* defined values */
[1809]102#define T_DELTA_RADIAL(a) SCALEADDBITS(22, 10000.0, a)
103#define T_DELTA_ALONG_TRACK(a) SCALEADDBITS(20, 2500.0, a)
104#define T_DELTA_CROSS_TRACK(a) SCALEADDBITS(20, 2500.0, a)
105#define T_DELTA_DOT_RADIAL(a) SCALEADDBITS(21, 1000000.0, a)
106#define T_DELTA_DOT_ALONG_TRACK(a) SCALEADDBITS(19, 250000.0, a)
107#define T_DELTA_DOT_CROSS_TRACK(a) SCALEADDBITS(19, 250000.0, a)
[1664]108#define T_DELTA_DOT_DOT_RADIAL(a) SCALEADDBITS(27, 50000000.0, a)
[1809]109#define T_DELTA_DOT_DOT_ALONG_TRACK(a) SCALEADDBITS(25, 12500000.0, a)
110#define T_DELTA_DOT_DOT_CROSS_TRACK(a) SCALEADDBITS(25, 12500000.0, a)
[865]111#define T_SATELLITE_REFERENCE_POINT(a) ADDBITS(1, a)
[1664]112
[865]113#define T_SATELLITE_REFERENCE_DATUM(a) ADDBITS(1, a)
[1809]114#define T_DELTA_CLOCK_C0(a) SCALEADDBITS(22, 10000.0, a)
115#define T_DELTA_CLOCK_C1(a) SCALEADDBITS(21, 1000000.0, a)
[1664]116#define T_DELTA_CLOCK_C2(a) SCALEADDBITS(27, 50000000.0, a)
[865]117#define T_NO_OF_CODE_BIASES(a) ADDBITS(5, a)
[1664]118#define T_GPS_SIGNAL_IDENTIFIER(a) ADDBITS(5, a)
119#define T_GLONASS_SIGNAL_IDENTIFIER(a) ADDBITS(5, a)
120#define T_GALILEO_SIGNAL_IDENTIFIER(a) ADDBITS(5, a)
[1809]121#define T_CODE_BIAS(a) SCALEADDBITS(14, 100.0, a)
[1664]122#define T_GLONASS_SATELLITE_ID(a) ADDBITS(5, a)
[865]123
[1664]124#define T_GPS_EPOCH_TIME(a) ADDBITS(20, a)
125#define T_GLONASS_EPOCH_TIME(a) ADDBITS(17, a)
126#define T_NO_OF_SATELLITES(a) ADDBITS(6, a)
127#define T_MULTIPLE_MESSAGE_INDICATOR(a) ADDBITS(1, a)
128#define T_SSR_URA(a) ADDBITS(4, a)
[1809]129#define T_HR_CLOCK_CORRECTION(a) SCALEADDBITS(22, 10000.0, a)
[1664]130#define T_SSR_UPDATE_INTERVAL(a) ADDBITS(4, a)
[865]131
132size_t MakeClockOrbit(const struct ClockOrbit *co, enum ClockOrbitType type,
133int moremessagesfollow, char *buffer, size_t size)
134{
[1664]135 int gpshr=0, gpsur=0, gpsor=0, gpscl=0, gpsco=0, glohr=0, glour=0, gloor=0,
136 glocl=0, gloco=0, mmi, i;
[1820]137
[865]138 STARTDATA
139
[1664]140 if(co->NumberOfGPSSat && co->HRDataSupplied
141 && (type == COTYPE_AUTO || type == COTYPE_GPSHR))
142 gpshr = 1;
143 if(co->NumberOfGPSSat && co->URADataSupplied
144 && (type == COTYPE_AUTO || type == COTYPE_GPSURA))
145 gpsur = 1;
[865]146 if(co->NumberOfGPSSat && co->OrbitDataSupplied
147 && (type == COTYPE_AUTO || type == COTYPE_GPSORBIT))
148 gpsor = 1;
149 if(co->NumberOfGPSSat && co->ClockDataSupplied
150 && (type == COTYPE_AUTO || type == COTYPE_GPSCLOCK))
151 gpscl = 1;
152 if(co->NumberOfGPSSat && co->ClockDataSupplied && co->OrbitDataSupplied
[1827]153 && (type == COTYPE_AUTO || type == COTYPE_GPSCOMBINED)
[1841]154 /*&& co->NumberOfGPSSat <= 28*/)
[865]155 {
156 gpsco = 1; gpsor = 0; gpscl = 0;
157 }
[1664]158 if(co->NumberOfGLONASSSat && co->HRDataSupplied
159 && (type == COTYPE_AUTO || type == COTYPE_GLONASSHR))
160 glohr = 1;
161 if(co->NumberOfGLONASSSat && co->URADataSupplied
162 && (type == COTYPE_AUTO || type == COTYPE_GLONASSURA))
163 glour = 1;
[865]164 if(co->NumberOfGLONASSSat && co->OrbitDataSupplied
165 && (type == COTYPE_AUTO || type == COTYPE_GLONASSORBIT))
166 gloor = 1;
167 if(co->NumberOfGLONASSSat && co->ClockDataSupplied
168 && (type == COTYPE_AUTO || type == COTYPE_GLONASSCLOCK))
169 glocl = 1;
170 if(co->NumberOfGLONASSSat && co->ClockDataSupplied && co->OrbitDataSupplied
171 && (type == COTYPE_AUTO || type == COTYPE_GLONASSCOMBINED))
172 {
173 gloco = 1; gloor = 0; glocl = 0;
174 }
175
[1664]176 mmi = gpshr+gpsur+gpsor+gpscl+gpsco+glohr+glour+gloor+glocl+gloco; /* required for multimessage */
[865]177 if(!moremessagesfollow) --mmi;
178
179 if(gpsor)
180 {
181 INITBLOCK
182 T_MESSAGE_NUMBER(COTYPE_GPSORBIT)
183 T_GPS_EPOCH_TIME(co->GPSEpochTime)
[1664]184 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]185 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]186 --mmi;
[1664]187 T_RESERVED5
[865]188 T_NO_OF_SATELLITES(co->NumberOfGPSSat)
189 for(i = 0; i < co->NumberOfGPSSat; ++i)
190 {
191 T_GPS_SATELLITE_ID(co->Sat[i].ID)
192 T_GPS_IODE(co->Sat[i].IOD)
193 T_DELTA_RADIAL(co->Sat[i].Orbit.DeltaRadial)
194 T_DELTA_ALONG_TRACK(co->Sat[i].Orbit.DeltaAlongTrack)
195 T_DELTA_CROSS_TRACK(co->Sat[i].Orbit.DeltaCrossTrack)
196 T_DELTA_DOT_RADIAL(co->Sat[i].Orbit.DotDeltaRadial)
197 T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
198 T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
199 T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
200 T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
201 T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
202 T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
203 T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
204 }
205 ENDBLOCK
206 }
207 if(gpscl)
208 {
209 INITBLOCK
210 T_MESSAGE_NUMBER(COTYPE_GPSCLOCK)
211 T_GPS_EPOCH_TIME(co->GPSEpochTime)
[1664]212 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]213 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]214 --mmi;
[1664]215 T_RESERVED5
[865]216 T_NO_OF_SATELLITES(co->NumberOfGPSSat)
217 for(i = 0; i < co->NumberOfGPSSat; ++i)
218 {
219 T_GPS_SATELLITE_ID(co->Sat[i].ID)
[1664]220 T_DELTA_CLOCK_C0(co->Sat[i].Clock.DeltaA0)
221 T_DELTA_CLOCK_C1(co->Sat[i].Clock.DeltaA1)
222 T_DELTA_CLOCK_C2(co->Sat[i].Clock.DeltaA2)
[865]223 }
224 ENDBLOCK
225 }
226 if(gpsco)
227 {
[1841]228 int nums, left, start = 0;
229 nums = co->NumberOfGPSSat;
230 if(nums > 28) /* split block when more than 28 sats */
[865]231 {
[1841]232 left = nums - 28;
233 nums = 28;
[865]234 }
[1865]235 else {
236 left = 0;
237 }
[1841]238 while(nums)
239 {
240 INITBLOCK
241 T_MESSAGE_NUMBER(COTYPE_GPSCOMBINED)
242 T_GPS_EPOCH_TIME(co->GPSEpochTime)
243 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
244 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi || */ left ? 1 : 0)
245 --mmi;
246 T_RESERVED5
247 T_NO_OF_SATELLITES(nums)
248 for(i = start; i < start+nums; ++i)
249 {
250 T_GPS_SATELLITE_ID(co->Sat[i].ID)
251 T_GPS_IODE(co->Sat[i].IOD)
252 T_DELTA_RADIAL(co->Sat[i].Orbit.DeltaRadial)
253 T_DELTA_ALONG_TRACK(co->Sat[i].Orbit.DeltaAlongTrack)
254 T_DELTA_CROSS_TRACK(co->Sat[i].Orbit.DeltaCrossTrack)
255 T_DELTA_DOT_RADIAL(co->Sat[i].Orbit.DotDeltaRadial)
256 T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
257 T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
258 T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
259 T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
260 T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
261 T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
262 T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
263 T_DELTA_CLOCK_C0(co->Sat[i].Clock.DeltaA0)
264 T_DELTA_CLOCK_C1(co->Sat[i].Clock.DeltaA1)
265 T_DELTA_CLOCK_C2(co->Sat[i].Clock.DeltaA2)
266 }
267 ENDBLOCK
268 start += nums;
269 nums = left;
270 left = 0;
271 }
[865]272 }
[1664]273 if(gpshr)
274 {
275 INITBLOCK
276 T_MESSAGE_NUMBER(COTYPE_GPSHR)
277 T_GPS_EPOCH_TIME(co->GPSEpochTime)
278 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]279 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[1664]280 --mmi;
281 T_RESERVED5
282 T_NO_OF_SATELLITES(co->NumberOfGPSSat)
283 for(i = 0; i < co->NumberOfGPSSat; ++i)
284 {
285 T_GPS_SATELLITE_ID(co->Sat[i].ID)
286 T_HR_CLOCK_CORRECTION(co->Sat[i].hrclock)
287 }
288 ENDBLOCK
289 }
290 if(gpsur)
291 {
292 INITBLOCK
293 T_MESSAGE_NUMBER(COTYPE_GPSURA)
294 T_GPS_EPOCH_TIME(co->GPSEpochTime)
[1841]295 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[1664]296 --mmi;
297 T_RESERVED5
298 T_NO_OF_SATELLITES(co->NumberOfGPSSat)
299 for(i = 0; i < co->NumberOfGPSSat; ++i)
300 {
301 T_GPS_SATELLITE_ID(co->Sat[i].ID)
302 T_SSR_URA(co->Sat[i].URA)
303 }
304 ENDBLOCK
305 }
[865]306 if(gloor)
307 {
308 INITBLOCK
309 T_MESSAGE_NUMBER(COTYPE_GLONASSORBIT)
310 T_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
[1664]311 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]312 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]313 --mmi;
[1664]314 T_RESERVED5
[865]315 T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
316 for(i = CLOCKORBIT_NUMGPS;
317 i < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat; ++i)
318 {
319 T_GLONASS_SATELLITE_ID(co->Sat[i].ID)
320 T_GLONASS_IOD(co->Sat[i].IOD)
321 T_DELTA_RADIAL(co->Sat[i].Orbit.DeltaRadial)
322 T_DELTA_ALONG_TRACK(co->Sat[i].Orbit.DeltaAlongTrack)
323 T_DELTA_CROSS_TRACK(co->Sat[i].Orbit.DeltaCrossTrack)
324 T_DELTA_DOT_RADIAL(co->Sat[i].Orbit.DotDeltaRadial)
325 T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
326 T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
327 T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
328 T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
329 T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
330 T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
331 T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
332 }
333 ENDBLOCK
334 }
335 if(glocl)
336 {
337 INITBLOCK
338 T_MESSAGE_NUMBER(COTYPE_GLONASSCLOCK)
339 T_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
[1664]340 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]341 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]342 --mmi;
[1664]343 T_RESERVED5
[865]344 T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
345 for(i = CLOCKORBIT_NUMGPS;
346 i < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat; ++i)
347 {
348 T_GLONASS_SATELLITE_ID(co->Sat[i].ID)
349 T_GLONASS_IOD(co->Sat[i].IOD)
[1664]350 T_DELTA_CLOCK_C0(co->Sat[i].Clock.DeltaA0)
351 T_DELTA_CLOCK_C1(co->Sat[i].Clock.DeltaA1)
352 T_DELTA_CLOCK_C2(co->Sat[i].Clock.DeltaA2)
[865]353 }
354 ENDBLOCK
355 }
356 if(gloco)
357 {
358 INITBLOCK
359 T_MESSAGE_NUMBER(COTYPE_GLONASSCOMBINED)
360 T_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
[1664]361 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]362 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]363 --mmi;
[1664]364 T_RESERVED5
[865]365 T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
366 for(i = CLOCKORBIT_NUMGPS;
367 i < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat; ++i)
368 {
369 T_GLONASS_SATELLITE_ID(co->Sat[i].ID)
370 T_GLONASS_IOD(co->Sat[i].IOD)
371 T_DELTA_RADIAL(co->Sat[i].Orbit.DeltaRadial)
372 T_DELTA_ALONG_TRACK(co->Sat[i].Orbit.DeltaAlongTrack)
373 T_DELTA_CROSS_TRACK(co->Sat[i].Orbit.DeltaCrossTrack)
374 T_DELTA_DOT_RADIAL(co->Sat[i].Orbit.DotDeltaRadial)
375 T_DELTA_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDeltaAlongTrack)
376 T_DELTA_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDeltaCrossTrack)
377 T_DELTA_DOT_DOT_RADIAL(co->Sat[i].Orbit.DotDotDeltaRadial)
378 T_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[i].Orbit.DotDotDeltaAlongTrack)
379 T_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[i].Orbit.DotDotDeltaCrossTrack)
380 T_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
381 T_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
[1664]382 T_DELTA_CLOCK_C0(co->Sat[i].Clock.DeltaA0)
383 T_DELTA_CLOCK_C1(co->Sat[i].Clock.DeltaA1)
384 T_DELTA_CLOCK_C2(co->Sat[i].Clock.DeltaA2)
[865]385 }
386 ENDBLOCK
387 }
[1664]388 if(glohr)
389 {
390 INITBLOCK
391 T_MESSAGE_NUMBER(COTYPE_GLONASSHR)
392 T_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
393 T_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[1841]394 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[1664]395 --mmi;
396 T_RESERVED5
397 T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
398 for(i = CLOCKORBIT_NUMGPS;
399 i < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat; ++i)
400 {
401 T_GPS_SATELLITE_ID(co->Sat[i].ID)
402 T_HR_CLOCK_CORRECTION(co->Sat[i].hrclock)
403 }
404 ENDBLOCK
405 }
406 if(glour)
407 {
408 INITBLOCK
409 T_MESSAGE_NUMBER(COTYPE_GLONASSURA)
410 T_GLONASS_EPOCH_TIME(co->GLONASSEpochTime)
[1841]411 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[1664]412 --mmi;
413 T_RESERVED5
414 T_NO_OF_SATELLITES(co->NumberOfGLONASSSat)
415 for(i = CLOCKORBIT_NUMGPS;
416 i < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat; ++i)
417 {
418 T_GPS_SATELLITE_ID(co->Sat[i].ID)
419 T_SSR_URA(co->Sat[i].URA)
420 }
421 ENDBLOCK
422 }
[865]423
424 return ressize;
425}
426
427size_t MakeBias(const struct Bias *b, enum BiasType type,
428int moremessagesfollow, char *buffer, size_t size)
429{
[1664]430 int gps, glo, mmi, i, j;
[1820]431
[865]432 STARTDATA
433
434 if(b->NumberOfGPSSat && (type == BTYPE_AUTO || type == BTYPE_GPS))
435 gps = 1;
436 if(b->NumberOfGLONASSSat && (type == BTYPE_AUTO || type == BTYPE_GLONASS))
437 glo = 1;
438
439 mmi = gps+glo; /* required for multimessage */
440 if(!moremessagesfollow) --mmi;
441
442 if(gps)
443 {
444 INITBLOCK
445 T_MESSAGE_NUMBER(BTYPE_GPS)
446 T_GPS_EPOCH_TIME(b->GPSEpochTime)
[1664]447 T_SSR_UPDATE_INTERVAL(b->UpdateInterval)
[1841]448 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]449 --mmi;
[1664]450 T_RESERVED5
[865]451 T_NO_OF_SATELLITES(b->NumberOfGPSSat)
452 for(i = 0; i < b->NumberOfGPSSat; ++i)
453 {
454 T_GPS_SATELLITE_ID(b->Sat[i].ID)
455 T_NO_OF_CODE_BIASES(b->Sat[i].NumberOfCodeBiases)
456 for(j = 0; j < b->Sat[i].NumberOfCodeBiases; ++j)
457 {
[1664]458 T_GPS_SIGNAL_IDENTIFIER(b->Sat[i].Biases[j].Type)
[865]459 T_CODE_BIAS(b->Sat[i].Biases[j].Bias)
460 }
461 }
462 ENDBLOCK
463 }
464 if(glo)
465 {
466 INITBLOCK
467 T_MESSAGE_NUMBER(BTYPE_GLONASS)
468 T_GPS_EPOCH_TIME(b->GLONASSEpochTime)
[1664]469 T_SSR_UPDATE_INTERVAL(b->UpdateInterval)
[1841]470 T_MULTIPLE_MESSAGE_INDICATOR(/*mmi ? 1 :*/0)
[865]471 --mmi;
[1664]472 T_RESERVED5
[865]473 T_NO_OF_SATELLITES(b->NumberOfGLONASSSat)
474 for(i = CLOCKORBIT_NUMGPS;
475 i < CLOCKORBIT_NUMGPS+b->NumberOfGLONASSSat; ++i)
476 {
477 T_GLONASS_SATELLITE_ID(b->Sat[i].ID)
478 T_NO_OF_CODE_BIASES(b->Sat[i].NumberOfCodeBiases)
479 for(j = 0; j < b->Sat[i].NumberOfCodeBiases; ++j)
480 {
[1664]481 T_GLONASS_SIGNAL_IDENTIFIER(b->Sat[i].Biases[j].Type)
[865]482 T_CODE_BIAS(b->Sat[i].Biases[j].Bias)
483 }
484 }
485 ENDBLOCK
486 }
487
488 return ressize;
489}
[1664]490
[865]491#endif /* NOENCODE */
492
493#ifndef NODECODE
494
495#define DECODESTART \
496 int numbits=0; \
497 uint64_t bitbuffer=0;
498
499#define LOADBITS(a) \
500{ \
501 while((a) > numbits) \
502 { \
[1809]503 if(!size--) return GCOBR_SHORTMESSAGE; \
[865]504 bitbuffer = (bitbuffer<<8)|((unsigned char)*(buffer++)); \
505 numbits += 8; \
506 } \
507}
508
509/* extract bits from data stream
510 b = variable to store result, a = number of bits */
511#define GETBITS(b, a) \
512{ \
513 LOADBITS(a) \
514 b = (bitbuffer<<(64-numbits))>>(64-(a)); \
515 numbits -= (a); \
516}
517
518/* extract signed floating value from data stream
519 b = variable to store result, a = number of bits */
520#define GETFLOATSIGN(b, a, c) \
521{ \
522 LOADBITS(a) \
523 b = ((double)(((int64_t)(bitbuffer<<(64-numbits)))>>(64-(a))))*(c); \
524 numbits -= (a); \
525}
526
527#define SKIPBITS(b) { LOADBITS(b) numbits -= (b); }
528
529/* standard values */
[879]530#define G_HEADER(a) GETBITS(a,8)
531#define G_RESERVEDH(a) GETBITS(a,6)
532#define G_SIZE(a) GETBITS(a, 10)
[865]533#define G_MESSAGE_NUMBER(a) GETBITS(a, 12) /* DF002 */
[1664]534#define G_RESERVED5 SKIPBITS(5) /* DF001 */
[1841]535#define G_GPS_SATELLITE_ID(a) GETBITS(a, 6) /* DF068 */
[865]536#define G_GPS_IODE(a) GETBITS(a, 8) /* DF071 */
537#define G_GLONASS_IOD(a) GETBITS(a, 8) /* DF237 */
538
539/* defined values */
[1664]540#define G_DELTA_RADIAL(a) GETFLOATSIGN(a, 22, 1/10000.0)
[1809]541#define G_DELTA_ALONG_TRACK(a) GETFLOATSIGN(a, 20, 1/2500.0)
542#define G_DELTA_CROSS_TRACK(a) GETFLOATSIGN(a, 20, 1/2500.0)
[1664]543#define G_DELTA_DOT_RADIAL(a) GETFLOATSIGN(a, 21, 1/1000000.0)
[1809]544#define G_DELTA_DOT_ALONG_TRACK(a) GETFLOATSIGN(a, 19, 1/250000.0)
545#define G_DELTA_DOT_CROSS_TRACK(a) GETFLOATSIGN(a, 19, 1/250000.0)
[1664]546#define G_DELTA_DOT_DOT_RADIAL(a) GETFLOATSIGN(a, 27, 1/50000000.0)
[1809]547#define G_DELTA_DOT_DOT_ALONG_TRACK(a) GETFLOATSIGN(a, 25, 1/12500000.0)
548#define G_DELTA_DOT_DOT_CROSS_TRACK(a) GETFLOATSIGN(a, 25, 1/12500000.0)
[1664]549#define G_SATELLITE_REFERENCE_POINT(a) GETBITS(a, 1)
550
551#define G_SATELLITE_REFERENCE_DATUM(a) GETBITS(a, 1)
552#define G_DELTA_CLOCK_C0(a) GETFLOATSIGN(a, 22, 1/10000.0)
553#define G_DELTA_CLOCK_C1(a) GETFLOATSIGN(a, 21, 1/1000000.0)
554#define G_DELTA_CLOCK_C2(a) GETFLOATSIGN(a, 27, 1/50000000.0)
555#define G_NO_OF_CODE_BIASES(a) GETBITS(a, 5)
556#define G_GPS_SIGNAL_IDENTIFIER(a) GETBITS(a, 5)
557#define G_GLONASS_SIGNAL_IDENTIFIER(a) GETBITS(a, 5)
558#define G_GALILEO_SIGNAL_IDENTIFIER(a) GETBITS(a, 5)
559#define G_CODE_BIAS(a) GETFLOATSIGN(a, 14, 1/100.0)
[1841]560#define G_GLONASS_SATELLITE_ID(a) GETBITS(a, 5)
[1664]561
[879]562#define G_GPS_EPOCH_TIME(a, b) {int temp; GETBITS(temp, 20) \
563 if(b && a != temp) return GCOBR_TIMEMISMATCH; a = temp;}
564#define G_GLONASS_EPOCH_TIME(a, b) {int temp; GETBITS(temp, 17) \
565 if(b && a != temp) return GCOBR_TIMEMISMATCH; a = temp;}
[1841]566#define G_NO_OF_SATELLITES(a) GETBITS(a, 6)
[1664]567#define G_MULTIPLE_MESSAGE_INDICATOR(a) GETBITS(a, 1)
568#define G_SSR_URA(a) GETBITS(a, 4)
569#define G_HR_CLOCK_CORRECTION(a) GETFLOATSIGN(a, 22, 1/10000.0)
570#define G_SSR_UPDATE_INTERVAL(a) GETBITS(a, 4)
571
[879]572enum GCOB_RETURN GetClockOrbitBias(struct ClockOrbit *co, struct Bias *b,
573const char *buffer, size_t size, int *bytesused)
[865]574{
[1841]575 int type, mmi=0, i, j, h, rs, nums, pos, id;
[1820]576 size_t sizeofrtcmblock;
[879]577 const char *blockstart = buffer;
[865]578 DECODESTART
579
[879]580 if(size < 7)
581 return GCOBR_SHORTBUFFER;
582
[1842]583#ifdef DEBUG
584fprintf(stderr, "GetClockOrbitBias START: size %d, numbits %d\n",size, numbits);
585#endif
586
[879]587 G_HEADER(h)
588 G_RESERVEDH(rs)
589 G_SIZE(sizeofrtcmblock);
590
591 if((unsigned char)h != 0xD3 || rs)
592 return GCOBR_UNKNOWNDATA;
593 if(size < sizeofrtcmblock + 3) /* 3 header bytes already removed */
594 return GCOBR_MESSAGEEXCEEDSBUFFER;
595 if(CRC24(sizeofrtcmblock+3, (const unsigned char *) blockstart) !=
[1820]596 (uint32_t)((((unsigned char)buffer[sizeofrtcmblock])<<16)|
[879]597 (((unsigned char)buffer[sizeofrtcmblock+1])<<8)|
598 (((unsigned char)buffer[sizeofrtcmblock+2]))))
599 return GCOBR_CRCMISMATCH;
[1809]600 size = sizeofrtcmblock; /* reduce size, so overflows are detected */
[879]601
[865]602 G_MESSAGE_NUMBER(type)
[1809]603#ifdef DEBUG
604fprintf(stderr, "type %d size %d\n",type,sizeofrtcmblock);
605#endif
[865]606 switch(type)
607 {
608 case COTYPE_GPSORBIT:
[879]609 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]610 co->messageType = COTYPE_GPSORBIT;
[879]611 G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
[1664]612 co->epochGPS[co->epochSize] = co->GPSEpochTime; /* Weber, for latency */
613 if(co->epochSize < 100) {co->epochSize += 1;} /* Weber, for latency */
614 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[865]615 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]616 G_RESERVED5
[1841]617 G_NO_OF_SATELLITES(nums)
[1829]618 co->OrbitDataSupplied |= 1;
[1809]619#ifdef DEBUG
[1842]620fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GPSEpochTime,
621co->UpdateInterval,mmi,co->NumberOfGPSSat,nums);
[1809]622#endif
[1841]623 for(i = 0; i < nums; ++i)
[865]624 {
[1841]625 G_GPS_SATELLITE_ID(id)
626 for(pos = 0; pos < co->NumberOfGPSSat && co->Sat[pos].ID != id; ++pos)
627 ;
628 if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
629 else if(pos == co->NumberOfGPSSat) ++co->NumberOfGPSSat;
630 co->Sat[pos].ID = id;
631
632 G_GPS_IODE(co->Sat[pos].IOD)
633 G_DELTA_RADIAL(co->Sat[pos].Orbit.DeltaRadial)
634 G_DELTA_ALONG_TRACK(co->Sat[pos].Orbit.DeltaAlongTrack)
635 G_DELTA_CROSS_TRACK(co->Sat[pos].Orbit.DeltaCrossTrack)
636 G_DELTA_DOT_RADIAL(co->Sat[pos].Orbit.DotDeltaRadial)
637 G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
638 G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
639 G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
640 G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
641 G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
[865]642 G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
643 G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
[1809]644#ifdef DEBUG
645fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f rp %d rd %d\n",
[1841]646co->Sat[pos].ID,co->Sat[pos].IOD,co->Sat[pos].Orbit.DeltaRadial,
647co->Sat[pos].Orbit.DeltaAlongTrack,co->Sat[pos].Orbit.DeltaCrossTrack,
648co->Sat[pos].Orbit.DotDeltaRadial,
649co->Sat[pos].Orbit.DotDeltaAlongTrack,
650co->Sat[pos].Orbit.DotDeltaCrossTrack,
651co->Sat[pos].Orbit.DotDotDeltaRadial,
652co->Sat[pos].Orbit.DotDotDeltaAlongTrack,
653co->Sat[pos].Orbit.DotDotDeltaCrossTrack,
[1809]654co->SatRefPoint,
655co->SatRefDatum);
656#endif
[865]657 }
658 break;
659 case COTYPE_GPSCLOCK:
[879]660 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]661 co->messageType = COTYPE_GPSCLOCK;
[879]662 G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
[1664]663 co->epochGPS[co->epochSize] = co->GPSEpochTime; /* Weber, for latency */
664 if(co->epochSize < 100) {co->epochSize += 1;} /* Weber, for latency */
665 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[865]666 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]667 G_RESERVED5
[1841]668 G_NO_OF_SATELLITES(nums)
[1829]669 co->ClockDataSupplied |= 1;
[1842]670#ifdef DEBUG
671fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GPSEpochTime,
672co->UpdateInterval,mmi,co->NumberOfGPSSat,nums);
673#endif
[1841]674 for(i = 0; i < nums; ++i)
[865]675 {
[1841]676 G_GPS_SATELLITE_ID(id)
677 for(pos = 0; pos < co->NumberOfGPSSat && co->Sat[pos].ID != id; ++pos)
678 ;
679 if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
680 else if(pos == co->NumberOfGPSSat) ++co->NumberOfGPSSat;
681 co->Sat[pos].ID = id;
682
683 G_DELTA_CLOCK_C0(co->Sat[pos].Clock.DeltaA0)
684 G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
685 G_DELTA_CLOCK_C2(co->Sat[pos].Clock.DeltaA2)
[1842]686#ifdef DEBUG
687fprintf(stderr, "id %2d c0 %8.3f c1 %8.3f c2 %8.3f\n",
688co->Sat[pos].ID, co->Sat[pos].Clock.DeltaA0, co->Sat[pos].Clock.DeltaA1,
689co->Sat[pos].Clock.DeltaA2);
690#endif
[865]691 }
692 break;
693 case COTYPE_GPSCOMBINED:
694 if(!co) return -5;
[1851]695 co->messageType = COTYPE_GPSCOMBINED;
[879]696 G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
[1664]697 co->epochGPS[co->epochSize] = co->GPSEpochTime; /* Weber, for latency */
698 if(co->epochSize < 100) {co->epochSize += 1;} /* Weber, for latency */
699 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[865]700 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]701 G_RESERVED5
[1841]702 G_NO_OF_SATELLITES(nums)
[1829]703 co->OrbitDataSupplied |= 1;
704 co->ClockDataSupplied |= 1;
[1841]705 for(i = 0; i < nums; ++i)
[865]706 {
[1841]707 G_GPS_SATELLITE_ID(id)
708 for(pos = 0; pos < co->NumberOfGPSSat && co->Sat[pos].ID != id; ++pos)
709 ;
710 if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
711 else if(pos == co->NumberOfGPSSat) ++co->NumberOfGPSSat;
712 co->Sat[pos].ID = id;
713
714 G_GPS_IODE(co->Sat[pos].IOD)
715 G_DELTA_RADIAL(co->Sat[pos].Orbit.DeltaRadial)
716 G_DELTA_ALONG_TRACK(co->Sat[pos].Orbit.DeltaAlongTrack)
717 G_DELTA_CROSS_TRACK(co->Sat[pos].Orbit.DeltaCrossTrack)
718 G_DELTA_DOT_RADIAL(co->Sat[pos].Orbit.DotDeltaRadial)
719 G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
720 G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
721 G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
722 G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
723 G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
[865]724 G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
725 G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
[1841]726 G_DELTA_CLOCK_C0(co->Sat[pos].Clock.DeltaA0)
727 G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
728 G_DELTA_CLOCK_C2(co->Sat[pos].Clock.DeltaA2)
[865]729 }
730 break;
[1664]731 case COTYPE_GPSURA:
732 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]733 co->messageType = COTYPE_GPSURA;
[1664]734 G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
735 co->epochGPS[co->epochSize] = co->GPSEpochTime; /* Weber, for latency */
736 if(co->epochSize < 100) {co->epochSize += 1;} /* Weber, for latency */
737 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
738 G_RESERVED5
[1841]739 G_NO_OF_SATELLITES(nums)
[1829]740 co->URADataSupplied |= 1;
[1841]741 for(i = 0; i < nums; ++i)
[1664]742 {
[1841]743 G_GPS_SATELLITE_ID(id)
744 for(pos = 0; pos < co->NumberOfGPSSat && co->Sat[pos].ID != id; ++pos)
745 ;
746 if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
747 else if(pos == co->NumberOfGPSSat) ++co->NumberOfGPSSat;
748 co->Sat[pos].ID = id;
749
750 G_SSR_URA(co->Sat[pos].URA)
[1664]751 }
752 break;
753 case COTYPE_GPSHR:
754 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]755 co->messageType = COTYPE_GPSHR;
[1664]756 G_GPS_EPOCH_TIME(co->GPSEpochTime, co->NumberOfGPSSat)
757 co->epochGPS[co->epochSize] = co->GPSEpochTime; /* Weber, for latency */
758 if(co->epochSize < 100) {co->epochSize += 1;} /* Weber, for latency */
759 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
760 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
761 G_RESERVED5
[1841]762 G_NO_OF_SATELLITES(nums)
[1829]763 co->HRDataSupplied |= 1;
[1841]764 for(i = 0; i < nums; ++i)
[1664]765 {
[1841]766 G_GPS_SATELLITE_ID(id)
767 for(pos = 0; pos < co->NumberOfGPSSat && co->Sat[pos].ID != id; ++pos)
768 ;
769 if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
770 else if(pos == co->NumberOfGPSSat) ++co->NumberOfGPSSat;
771 co->Sat[pos].ID = id;
772
773 G_HR_CLOCK_CORRECTION(co->Sat[pos].hrclock)
[1664]774 }
775 break;
[865]776 case COTYPE_GLONASSORBIT:
[879]777 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]778 co->messageType = COTYPE_GLONASSORBIT;
[879]779 G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
[1664]780 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[865]781 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]782 G_RESERVED5
[1841]783 G_NO_OF_SATELLITES(nums)
[1829]784 co->OrbitDataSupplied |= 2;
[1842]785#ifdef DEBUG
786fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GLONASSEpochTime,
787co->UpdateInterval,mmi,co->NumberOfGLONASSSat,nums);
788#endif
[1841]789 for(i = 0; i < nums; ++i)
[865]790 {
[1841]791 G_GLONASS_SATELLITE_ID(id)
[1842]792 for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
[1841]793 ;
794 if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
[1842]795 else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
[1841]796 co->Sat[pos].ID = id;
797
798 G_GLONASS_IOD(co->Sat[pos].IOD)
799 G_DELTA_RADIAL(co->Sat[pos].Orbit.DeltaRadial)
800 G_DELTA_ALONG_TRACK(co->Sat[pos].Orbit.DeltaAlongTrack)
801 G_DELTA_CROSS_TRACK(co->Sat[pos].Orbit.DeltaCrossTrack)
802 G_DELTA_DOT_RADIAL(co->Sat[pos].Orbit.DotDeltaRadial)
803 G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
804 G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
805 G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
806 G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
807 G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
[865]808 G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
809 G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
[1842]810#ifdef DEBUG
811fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f rp %d rd %d\n",
812co->Sat[pos].ID,co->Sat[pos].IOD,co->Sat[pos].Orbit.DeltaRadial,
813co->Sat[pos].Orbit.DeltaAlongTrack,co->Sat[pos].Orbit.DeltaCrossTrack,
814co->Sat[pos].Orbit.DotDeltaRadial,
815co->Sat[pos].Orbit.DotDeltaAlongTrack,
816co->Sat[pos].Orbit.DotDeltaCrossTrack,
817co->Sat[pos].Orbit.DotDotDeltaRadial,
818co->Sat[pos].Orbit.DotDotDeltaAlongTrack,
819co->Sat[pos].Orbit.DotDotDeltaCrossTrack,
820co->SatRefPoint,
821co->SatRefDatum);
822#endif
[865]823 }
824 break;
825 case COTYPE_GLONASSCLOCK:
[879]826 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]827 co->messageType = COTYPE_GLONASSCLOCK;
[879]828 G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
[1664]829 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[865]830 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]831 G_RESERVED5
[1841]832 G_NO_OF_SATELLITES(nums)
[1829]833 co->ClockDataSupplied |= 2;
[1842]834#ifdef DEBUG
835fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GLONASSEpochTime,
836co->UpdateInterval,mmi,co->NumberOfGLONASSSat,nums);
837#endif
[1841]838 for(i = 0; i < nums; ++i)
[865]839 {
[1841]840 G_GLONASS_SATELLITE_ID(id)
[1842]841 for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
[1841]842 ;
843 if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
[1842]844 else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
[1841]845 co->Sat[pos].ID = id;
846
847 G_DELTA_CLOCK_C0(co->Sat[pos].Clock.DeltaA0)
848 G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
849 G_DELTA_CLOCK_C2(co->Sat[pos].Clock.DeltaA2)
[1842]850#ifdef DEBUG
851fprintf(stderr, "id %2d c0 %8.3f c1 %8.3f c2 %8.3f\n",
852co->Sat[pos].ID, co->Sat[pos].Clock.DeltaA0, co->Sat[pos].Clock.DeltaA1,
853co->Sat[pos].Clock.DeltaA2);
854#endif
[865]855 }
856 break;
857 case COTYPE_GLONASSCOMBINED:
[879]858 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]859 co->messageType = COTYPE_GLONASSCOMBINED;
[879]860 G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
[1664]861 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
[865]862 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]863 G_RESERVED5
[1841]864 G_NO_OF_SATELLITES(nums)
[1829]865 co->OrbitDataSupplied |= 2;
866 co->ClockDataSupplied |= 2;
[1841]867 for(i = 0; i < nums; ++i)
[865]868 {
[1841]869 G_GLONASS_SATELLITE_ID(id)
[1842]870 for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
[1841]871 ;
872 if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
[1842]873 else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
[1841]874 co->Sat[pos].ID = id;
875
876 G_GLONASS_IOD(co->Sat[pos].IOD)
877 G_DELTA_RADIAL(co->Sat[pos].Orbit.DeltaRadial)
878 G_DELTA_ALONG_TRACK(co->Sat[pos].Orbit.DeltaAlongTrack)
879 G_DELTA_CROSS_TRACK(co->Sat[pos].Orbit.DeltaCrossTrack)
880 G_DELTA_DOT_RADIAL(co->Sat[pos].Orbit.DotDeltaRadial)
881 G_DELTA_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDeltaAlongTrack)
882 G_DELTA_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDeltaCrossTrack)
883 G_DELTA_DOT_DOT_RADIAL(co->Sat[pos].Orbit.DotDotDeltaRadial)
884 G_DELTA_DOT_DOT_ALONG_TRACK(co->Sat[pos].Orbit.DotDotDeltaAlongTrack)
885 G_DELTA_DOT_DOT_CROSS_TRACK(co->Sat[pos].Orbit.DotDotDeltaCrossTrack)
[865]886 G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
887 G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
[1841]888 G_DELTA_CLOCK_C0(co->Sat[pos].Clock.DeltaA0)
889 G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
890 G_DELTA_CLOCK_C2(co->Sat[pos].Clock.DeltaA2)
[865]891 }
892 break;
[1664]893 case COTYPE_GLONASSURA:
894 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]895 co->messageType = COTYPE_GLONASSURA;
[1664]896 G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
897 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
898 G_RESERVED5
[1841]899 G_NO_OF_SATELLITES(nums)
[1829]900 co->URADataSupplied |= 2;
[1841]901 for(i = 0; i < nums; ++i)
[1664]902 {
[1841]903 G_GLONASS_SATELLITE_ID(id)
[1842]904 for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
[1841]905 ;
906 if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
[1842]907 else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
[1841]908 co->Sat[pos].ID = id;
909
910 G_SSR_URA(co->Sat[pos].URA)
[1664]911 }
912 break;
913 case COTYPE_GLONASSHR:
914 if(!co) return GCOBR_NOCLOCKORBITPARAMETER;
[1851]915 co->messageType = COTYPE_GLONASSHR;
[1664]916 G_GLONASS_EPOCH_TIME(co->GLONASSEpochTime, co->NumberOfGLONASSSat)
917 G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
918 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
919 G_RESERVED5
[1841]920 G_NO_OF_SATELLITES(nums)
[1829]921 co->HRDataSupplied |= 2;
[1841]922 for(i = 0; i < nums; ++i)
[1664]923 {
[1841]924 G_GLONASS_SATELLITE_ID(id)
[1842]925 for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
[1841]926 ;
927 if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
[1842]928 else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
[1841]929 co->Sat[pos].ID = id;
930
931 G_HR_CLOCK_CORRECTION(co->Sat[pos].hrclock)
[1664]932 }
933 break;
[865]934 case BTYPE_GPS:
[879]935 if(!b) return GCOBR_NOBIASPARAMETER;
[1851]936 b->messageType = BTYPE_GPS;
[1842]937 G_GPS_EPOCH_TIME(b->GPSEpochTime, b->NumberOfGPSSat)
938 G_SSR_UPDATE_INTERVAL(b->UpdateInterval)
[865]939 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]940 G_RESERVED5
[1841]941 G_NO_OF_SATELLITES(nums)
942 for(i = 0; i < nums; ++i)
[865]943 {
[1841]944 G_GPS_SATELLITE_ID(id)
[1842]945 for(pos = 0; pos < b->NumberOfGPSSat && b->Sat[pos].ID != id; ++pos)
[1841]946 ;
947 if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
[1842]948 else if(pos == b->NumberOfGPSSat) ++b->NumberOfGPSSat;
949 b->Sat[pos].ID = id;
[1841]950
951 G_NO_OF_CODE_BIASES(b->Sat[pos].NumberOfCodeBiases)
952 for(j = 0; j < b->Sat[pos].NumberOfCodeBiases; ++j)
[865]953 {
[1841]954 G_GPS_SIGNAL_IDENTIFIER(b->Sat[pos].Biases[j].Type)
955 G_CODE_BIAS(b->Sat[pos].Biases[j].Bias)
[865]956 }
957 }
958 break;
959 case BTYPE_GLONASS:
[879]960 if(!b) return GCOBR_NOBIASPARAMETER;
[1851]961 b->messageType = BTYPE_GLONASS;
[1842]962 G_GLONASS_EPOCH_TIME(b->GLONASSEpochTime, b->NumberOfGLONASSSat)
963 G_SSR_UPDATE_INTERVAL(b->UpdateInterval)
[865]964 G_MULTIPLE_MESSAGE_INDICATOR(mmi)
[1664]965 G_RESERVED5
[1841]966 G_NO_OF_SATELLITES(nums)
967 for(i = 0; i < nums; ++i)
[865]968 {
[1841]969 G_GLONASS_SATELLITE_ID(id)
[1842]970 for(pos = CLOCKORBIT_NUMGPS; pos < b->NumberOfGLONASSSat && b->Sat[pos].ID != id; ++pos)
[1841]971 ;
972 if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
[1842]973 else if(pos == b->NumberOfGLONASSSat) ++b->NumberOfGLONASSSat;
974 b->Sat[pos].ID = id;
[1841]975
976 G_NO_OF_CODE_BIASES(b->Sat[pos].NumberOfCodeBiases)
977 for(j = 0; j < b->Sat[pos].NumberOfCodeBiases; ++j)
[865]978 {
[1841]979 G_GLONASS_SIGNAL_IDENTIFIER(b->Sat[pos].Biases[j].Type)
980 G_CODE_BIAS(b->Sat[pos].Biases[j].Bias)
[865]981 }
982 }
983 break;
984 default:
[1842]985 if(bytesused)
986 *bytesused = sizeofrtcmblock+6;
[879]987 return GCOBR_UNKNOWNTYPE;
[865]988 }
[1809]989#ifdef DEBUG
[1842]990for(type = 0; type < (int)size && (unsigned char)buffer[type] != 0xD3; ++type)
[1809]991 numbits += 8;
992fprintf(stderr, "numbits left %d\n",numbits);
993#endif
[879]994 if(bytesused)
995 *bytesused = sizeofrtcmblock+6;
996 return mmi ? GCOBR_MESSAGEFOLLOWS : GCOBR_OK;
[865]997}
998#endif /* NODECODE */
Note: See TracBrowser for help on using the repository browser.