source: ntrip/trunk/clock_and_orbit/clock_orbit_rtcm.c@ 1826

Last change on this file since 1826 was 1826, checked in by stoecker, 13 years ago

fixed long data blocks

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