2 * /src/NTP/ntp-4/libparse/data_mbg.c,v 4.3 1999/02/21 12:17:42 kardel RELEASE_19991128_A
4 * $Created: Sun Jul 20 12:08:14 1997 $
6 * Copyright (C) 1997, 1998 by Frank Kardel
11 #include "ntp_string.h"
15 #include "ntp_types.h"
16 #include "ntp_stdlib.h"
18 #include "mbg_gps166.h"
20 #include "ieee754io.h"
22 static void get_mbg_tzname P((unsigned char **, char *));
23 static void mbg_time_status_str P((unsigned char **, unsigned int));
25 #if 0 /* no actual floats on Meinberg binary interface */
26 static offsets_t mbg_float = { 1, 0, 3, 2, 0, 0, 0, 0 }; /* byte order for meinberg floats */
28 static offsets_t mbg_double = { 1, 0, 3, 2, 5, 4, 7, 6 }; /* byte order for meinberg doubles */
29 static int32 rad2deg_i = 57;
30 static u_int32 rad2deg_f = 0x4BB834C7; /* 57.2957795131 == 180/PI */
34 unsigned char **bufpp,
38 put_lsb_short(bufpp, headerp->gps_cmd);
39 put_lsb_short(bufpp, headerp->gps_len);
40 put_lsb_short(bufpp, headerp->gps_data_csum);
41 put_lsb_short(bufpp, headerp->gps_hdr_csum);
46 unsigned char **bufpp,
50 sw_revp->code = get_lsb_short(bufpp);
51 memcpy(sw_revp->name, *bufpp, sizeof(sw_revp->name));
52 *bufpp += sizeof(sw_revp->name);
57 unsigned char **bufpp,
61 ascii_msgp->csum = get_lsb_short(bufpp);
62 ascii_msgp->valid = get_lsb_short(bufpp);
63 memcpy(ascii_msgp->s, *bufpp, sizeof(ascii_msgp->s));
64 *bufpp += sizeof(ascii_msgp->s);
69 unsigned char **bufpp,
73 *svnop = get_lsb_short(bufpp);
78 unsigned char **bufpp,
82 *healthp = get_lsb_short(bufpp);
87 unsigned char **bufpp,
91 *cfgp = get_lsb_short(bufpp);
96 unsigned char **bufpp,
100 tgpsp->wn = get_lsb_short(bufpp);
101 tgpsp->sec = get_lsb_long(bufpp);
102 tgpsp->tick = get_lsb_long(bufpp);
107 unsigned char **buffpp,
111 tmp->year = get_lsb_short(buffpp);
112 tmp->month = *(*buffpp)++;
113 tmp->mday = *(*buffpp)++;
114 tmp->yday = get_lsb_short(buffpp);
115 tmp->wday = *(*buffpp)++;
116 tmp->hour = *(*buffpp)++;
117 tmp->minute = *(*buffpp)++;
118 tmp->second = *(*buffpp)++;
119 tmp->frac = get_lsb_long(buffpp);
120 tmp->offs_from_utc = get_lsb_long(buffpp);
121 tmp->status= get_lsb_short(buffpp);
126 unsigned char **buffpp,
130 ttmp->channel = get_lsb_short(buffpp);
131 get_mbg_tgps(buffpp, &ttmp->t);
132 get_mbg_tm(buffpp, &ttmp->tm);
137 unsigned char **buffpp,
141 synthp->freq = get_lsb_short(buffpp);
142 synthp->range = get_lsb_short(buffpp);
143 synthp->phase = get_lsb_short(buffpp);
148 unsigned char **buffpp,
152 strncpy(tznamep, (char *)*buffpp, sizeof(TZ_NAME));
153 *buffpp += sizeof(TZ_NAME);
158 unsigned char **buffpp,
162 tzdlp->offs = get_lsb_long(buffpp);
163 tzdlp->offs_dl = get_lsb_long(buffpp);
164 get_mbg_tm(buffpp, &tzdlp->tm_on);
165 get_mbg_tm(buffpp, &tzdlp->tm_off);
166 get_mbg_tzname(buffpp, (char *)tzdlp->name[0]);
167 get_mbg_tzname(buffpp, (char *)tzdlp->name[1]);
172 unsigned char **buffpp,
176 antinfop->status = get_lsb_short(buffpp);
177 get_mbg_tm(buffpp, &antinfop->tm_disconn);
178 get_mbg_tm(buffpp, &antinfop->tm_reconn);
179 antinfop->delta_t = get_lsb_long(buffpp);
184 unsigned char **buffpp,
190 int flag; /* bit flag */
191 const char *string; /* bit name */
194 { TM_UTC, "UTC CORR" },
195 { TM_LOCAL, "LOCAL TIME" },
196 { TM_DL_ANN, "DST WARN" },
197 { TM_DL_ENB, "DST" },
198 { TM_LS_ANN, "LEAP WARN" },
199 { TM_LS_ENB, "LEAP SEC" },
210 for (s = states; s->flag; s++)
212 if (s->flag & status)
219 strcpy((char *)p, s->string);
220 p += strlen((char *)p);
229 unsigned char **buffpp,
233 sprintf((char *)*buffpp, "%04d-%02d-%02d %02d:%02d:%02d.%07ld (%c%02d%02d) ",
234 tmp->year, tmp->month, tmp->mday,
235 tmp->hour, tmp->minute, tmp->second, tmp->frac,
236 (tmp->offs_from_utc < 0) ? '-' : '+',
237 abs(tmp->offs_from_utc) / 3600,
238 (abs(tmp->offs_from_utc) / 60) % 60);
239 *buffpp += strlen((char *)*buffpp);
240 mbg_time_status_str(buffpp, tmp->status);
245 unsigned char **buffpp,
249 sprintf((char *)*buffpp, "week %d + %ld days + %ld.%07ld sec",
250 tgpsp->wn, tgpsp->sec / 86400,
251 tgpsp->sec % 86400, tgpsp->tick);
252 *buffpp += strlen((char *)*buffpp);
257 unsigned char **buffpp,
263 cfghp->csum = get_lsb_short(buffpp);
264 cfghp->valid = get_lsb_short(buffpp);
265 get_mbg_tgps(buffpp, &cfghp->tot_51);
266 get_mbg_tgps(buffpp, &cfghp->tot_63);
267 get_mbg_tgps(buffpp, &cfghp->t0a);
269 for (i = MIN_SVNO; i <= MAX_SVNO; i++)
271 get_mbg_cfg(buffpp, &cfghp->cfg[i]);
274 for (i = MIN_SVNO; i <= MAX_SVNO; i++)
276 get_mbg_health(buffpp, &cfghp->health[i]);
282 unsigned char **buffpp,
286 utcp->csum = get_lsb_short(buffpp);
287 utcp->valid = get_lsb_short(buffpp);
289 get_mbg_tgps(buffpp, &utcp->t0t);
291 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &utcp->A0, mbg_double) != IEEE_OK)
296 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &utcp->A1, mbg_double) != IEEE_OK)
301 utcp->WNlsf = get_lsb_short(buffpp);
302 utcp->DNt = get_lsb_short(buffpp);
303 utcp->delta_tls = *(*buffpp)++;
304 utcp->delta_tlsf = *(*buffpp)++;
309 unsigned char **buffpp,
315 for (i = LAT; i <= ALT; i++)
317 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &lla[i], mbg_double) != IEEE_OK)
323 { /* convert to degrees (* 180/PI) */
324 mfp_mul(&lla[i].l_i, &lla[i].l_uf, lla[i].l_i, lla[i].l_uf, rad2deg_i, rad2deg_f);
331 unsigned char **buffpp,
337 for (i = XP; i <= ZP; i++)
339 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &xyz[i], mbg_double) != IEEE_OK)
348 unsigned char **buffpp,
354 comparamp->baud_rate = get_lsb_long(buffpp);
355 for (i = 0; i < sizeof(comparamp->framing); i++)
357 comparamp->framing[i] = *(*buffpp)++;
359 comparamp->handshake = get_lsb_short(buffpp);
364 unsigned char **buffpp,
365 PORT_PARM *portparamp
370 for (i = 0; i < N_COM; i++)
372 get_mbg_comparam(buffpp, &portparamp->com[i]);
374 for (i = 0; i < N_COM; i++)
376 portparamp->mode[i] = *(*buffpp)++;
380 #define FETCH_DOUBLE(src, addr) \
381 if (fetch_ieee754(src, IEEE_DOUBLE, addr, mbg_double) != IEEE_OK) \
388 unsigned char ** buffpp,
392 ephp->csum = get_lsb_short(buffpp);
393 ephp->valid = get_lsb_short(buffpp);
395 ephp->health = get_lsb_short(buffpp);
396 ephp->IODC = get_lsb_short(buffpp);
397 ephp->IODE2 = get_lsb_short(buffpp);
398 ephp->IODE3 = get_lsb_short(buffpp);
400 get_mbg_tgps(buffpp, &ephp->tt);
401 get_mbg_tgps(buffpp, &ephp->t0c);
402 get_mbg_tgps(buffpp, &ephp->t0e);
404 FETCH_DOUBLE(buffpp, &ephp->sqrt_A);
405 FETCH_DOUBLE(buffpp, &ephp->e);
406 FETCH_DOUBLE(buffpp, &ephp->M0);
407 FETCH_DOUBLE(buffpp, &ephp->omega);
408 FETCH_DOUBLE(buffpp, &ephp->OMEGA0);
409 FETCH_DOUBLE(buffpp, &ephp->OMEGADOT);
410 FETCH_DOUBLE(buffpp, &ephp->deltan);
411 FETCH_DOUBLE(buffpp, &ephp->i0);
412 FETCH_DOUBLE(buffpp, &ephp->idot);
413 FETCH_DOUBLE(buffpp, &ephp->crc);
414 FETCH_DOUBLE(buffpp, &ephp->crs);
415 FETCH_DOUBLE(buffpp, &ephp->cuc);
416 FETCH_DOUBLE(buffpp, &ephp->cus);
417 FETCH_DOUBLE(buffpp, &ephp->cic);
418 FETCH_DOUBLE(buffpp, &ephp->cis);
420 FETCH_DOUBLE(buffpp, &ephp->af0);
421 FETCH_DOUBLE(buffpp, &ephp->af1);
422 FETCH_DOUBLE(buffpp, &ephp->af2);
423 FETCH_DOUBLE(buffpp, &ephp->tgd);
425 ephp->URA = get_lsb_short(buffpp);
427 ephp->L2code = *(*buffpp)++;
428 ephp->L2flag = *(*buffpp)++;
433 unsigned char **buffpp,
437 almp->csum = get_lsb_short(buffpp);
438 almp->valid = get_lsb_short(buffpp);
440 almp->health = get_lsb_short(buffpp);
441 get_mbg_tgps(buffpp, &almp->t0a);
444 FETCH_DOUBLE(buffpp, &almp->sqrt_A);
445 FETCH_DOUBLE(buffpp, &almp->e);
447 FETCH_DOUBLE(buffpp, &almp->M0);
448 FETCH_DOUBLE(buffpp, &almp->omega);
449 FETCH_DOUBLE(buffpp, &almp->OMEGA0);
450 FETCH_DOUBLE(buffpp, &almp->OMEGADOT);
451 FETCH_DOUBLE(buffpp, &almp->deltai);
452 FETCH_DOUBLE(buffpp, &almp->af0);
453 FETCH_DOUBLE(buffpp, &almp->af1);
458 unsigned char **buffpp,
462 ionop->csum = get_lsb_short(buffpp);
463 ionop->valid = get_lsb_short(buffpp);
465 FETCH_DOUBLE(buffpp, &ionop->alpha_0);
466 FETCH_DOUBLE(buffpp, &ionop->alpha_1);
467 FETCH_DOUBLE(buffpp, &ionop->alpha_2);
468 FETCH_DOUBLE(buffpp, &ionop->alpha_3);
470 FETCH_DOUBLE(buffpp, &ionop->beta_0);
471 FETCH_DOUBLE(buffpp, &ionop->beta_1);
472 FETCH_DOUBLE(buffpp, &ionop->beta_2);
473 FETCH_DOUBLE(buffpp, &ionop->beta_3);
478 * Revision 4.3 1999/02/21 12:17:42 kardel
479 * 4.91f reconcilation
481 * Revision 4.2 1998/06/14 21:09:39 kardel
484 * Revision 4.1 1998/05/24 08:02:06 kardel
485 * trimmed version log
487 * Revision 4.0 1998/04/10 19:45:33 kardel
488 * Start 4.0 release version numbering