2 * /src/NTP/REPOSITORY/ntp4-dev/libparse/data_mbg.c,v 4.8 2006/06/22 18:40:01 kardel RELEASE_20060622_A
4 * data_mbg.c,v 4.8 2006/06/22 18:40:01 kardel RELEASE_20060622_A
6 * $Created: Sun Jul 20 12:08:14 1997 $
8 * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the author nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include "ntp_string.h"
43 #include "ntp_types.h"
44 #include "ntp_stdlib.h"
46 #include "mbg_gps166.h"
48 #include "ieee754io.h"
50 static void get_mbg_tzname (unsigned char **, char *);
51 static void mbg_time_status_str (char **, unsigned int, int);
53 #if 0 /* no actual floats on Meinberg binary interface */
54 static offsets_t mbg_float = { 1, 0, 3, 2, 0, 0, 0, 0 }; /* byte order for meinberg floats */
56 static offsets_t mbg_double = { 1, 0, 3, 2, 5, 4, 7, 6 }; /* byte order for meinberg doubles */
57 static int32 rad2deg_i = 57;
58 static u_int32 rad2deg_f = 0x4BB834C7; /* 57.2957795131 == 180/PI */
62 unsigned char **bufpp,
66 put_lsb_short(bufpp, headerp->gps_cmd);
67 put_lsb_short(bufpp, headerp->gps_len);
68 put_lsb_short(bufpp, headerp->gps_data_csum);
69 put_lsb_short(bufpp, headerp->gps_hdr_csum);
74 unsigned char **bufpp,
78 sw_revp->code = get_lsb_short(bufpp);
79 memcpy(sw_revp->name, *bufpp, sizeof(sw_revp->name));
80 *bufpp += sizeof(sw_revp->name);
85 unsigned char **bufpp,
89 ascii_msgp->csum = get_lsb_short(bufpp);
90 ascii_msgp->valid = get_lsb_short(bufpp);
91 memcpy(ascii_msgp->s, *bufpp, sizeof(ascii_msgp->s));
92 *bufpp += sizeof(ascii_msgp->s);
97 unsigned char **bufpp,
101 *svnop = get_lsb_short(bufpp);
106 unsigned char **bufpp,
110 *healthp = get_lsb_short(bufpp);
115 unsigned char **bufpp,
119 *cfgp = get_lsb_short(bufpp);
124 unsigned char **bufpp,
128 tgpsp->wn = get_lsb_short(bufpp);
129 tgpsp->sec = get_lsb_long(bufpp);
130 tgpsp->tick = get_lsb_long(bufpp);
135 unsigned char **buffpp,
139 tmp->year = get_lsb_short(buffpp);
140 tmp->month = *(*buffpp)++;
141 tmp->mday = *(*buffpp)++;
142 tmp->yday = get_lsb_short(buffpp);
143 tmp->wday = *(*buffpp)++;
144 tmp->hour = *(*buffpp)++;
145 tmp->minute = *(*buffpp)++;
146 tmp->second = *(*buffpp)++;
147 tmp->frac = get_lsb_long(buffpp);
148 tmp->offs_from_utc = get_lsb_long(buffpp);
149 tmp->status= get_lsb_short(buffpp);
154 unsigned char **buffpp,
158 ttmp->channel = get_lsb_short(buffpp);
159 get_mbg_tgps(buffpp, &ttmp->t);
160 get_mbg_tm(buffpp, &ttmp->tm);
165 unsigned char **buffpp,
169 synthp->freq = get_lsb_short(buffpp);
170 synthp->range = get_lsb_short(buffpp);
171 synthp->phase = get_lsb_short(buffpp);
176 unsigned char **buffpp,
180 strlcpy(tznamep, (char *)*buffpp, sizeof(TZ_NAME));
181 *buffpp += sizeof(TZ_NAME);
186 unsigned char **buffpp,
190 tzdlp->offs = get_lsb_long(buffpp);
191 tzdlp->offs_dl = get_lsb_long(buffpp);
192 get_mbg_tm(buffpp, &tzdlp->tm_on);
193 get_mbg_tm(buffpp, &tzdlp->tm_off);
194 get_mbg_tzname(buffpp, (char *)tzdlp->name[0]);
195 get_mbg_tzname(buffpp, (char *)tzdlp->name[1]);
200 unsigned char **buffpp,
204 antinfop->status = get_lsb_short(buffpp);
205 get_mbg_tm(buffpp, &antinfop->tm_disconn);
206 get_mbg_tm(buffpp, &antinfop->tm_reconn);
207 antinfop->delta_t = get_lsb_long(buffpp);
219 int flag; /* bit flag */
220 const char *string; /* bit name */
223 { TM_UTC, "UTC CORR" },
224 { TM_LOCAL, "LOCAL TIME" },
225 { TM_DL_ANN, "DST WARN" },
226 { TM_DL_ENB, "DST" },
227 { TM_LS_ANN, "LEAP WARN" },
228 { TM_LS_ENB, "LEAP SEC" },
239 for (s = states; s->flag; s++)
241 if (s->flag & status)
245 strlcpy(p, ", ", size - (p - start));
248 strlcpy(p, s->string, size - (p - start));
265 snprintf(*buffpp, size, "%04d-%02d-%02d %02d:%02d:%02d.%07ld (%c%02d%02d) ",
266 tmp->year, tmp->month, tmp->mday,
267 tmp->hour, tmp->minute, tmp->second, tmp->frac,
268 (tmp->offs_from_utc < 0) ? '-' : '+',
269 abs((int)tmp->offs_from_utc) / 3600,
270 (abs((int)tmp->offs_from_utc) / 60) % 60);
271 *buffpp += strlen(*buffpp);
273 mbg_time_status_str(buffpp, tmp->status, size - (*buffpp - s));
283 snprintf(*buffpp, size, "week %d + %ld days + %ld.%07ld sec",
284 tgpsp->wn, tgpsp->sec / 86400,
285 tgpsp->sec % 86400, tgpsp->tick);
286 *buffpp += strlen(*buffpp);
291 unsigned char **buffpp,
297 cfghp->csum = get_lsb_short(buffpp);
298 cfghp->valid = get_lsb_short(buffpp);
299 get_mbg_tgps(buffpp, &cfghp->tot_51);
300 get_mbg_tgps(buffpp, &cfghp->tot_63);
301 get_mbg_tgps(buffpp, &cfghp->t0a);
303 for (i = MIN_SVNO; i <= MAX_SVNO; i++)
305 get_mbg_cfg(buffpp, &cfghp->cfg[i]);
308 for (i = MIN_SVNO; i <= MAX_SVNO; i++)
310 get_mbg_health(buffpp, &cfghp->health[i]);
316 unsigned char **buffpp,
320 utcp->csum = get_lsb_short(buffpp);
321 utcp->valid = get_lsb_short(buffpp);
323 get_mbg_tgps(buffpp, &utcp->t0t);
325 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &utcp->A0, mbg_double) != IEEE_OK)
330 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &utcp->A1, mbg_double) != IEEE_OK)
335 utcp->WNlsf = get_lsb_short(buffpp);
336 utcp->DNt = get_lsb_short(buffpp);
337 utcp->delta_tls = *(*buffpp)++;
338 utcp->delta_tlsf = *(*buffpp)++;
343 unsigned char **buffpp,
349 for (i = LAT; i <= ALT; i++)
351 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &lla[i], mbg_double) != IEEE_OK)
357 { /* convert to degrees (* 180/PI) */
358 mfp_mul(&lla[i].l_i, &lla[i].l_uf, lla[i].l_i, lla[i].l_uf, rad2deg_i, rad2deg_f);
365 unsigned char **buffpp,
371 for (i = XP; i <= ZP; i++)
373 if (fetch_ieee754(buffpp, IEEE_DOUBLE, &xyz[i], mbg_double) != IEEE_OK)
382 unsigned char **buffpp,
388 comparamp->baud_rate = get_lsb_long(buffpp);
389 for (i = 0; i < sizeof(comparamp->framing); i++)
391 comparamp->framing[i] = *(*buffpp)++;
393 comparamp->handshake = get_lsb_short(buffpp);
398 unsigned char **buffpp,
399 PORT_PARM *portparamp
404 for (i = 0; i < N_COM; i++)
406 get_mbg_comparam(buffpp, &portparamp->com[i]);
408 for (i = 0; i < N_COM; i++)
410 portparamp->mode[i] = *(*buffpp)++;
414 #define FETCH_DOUBLE(src, addr) \
415 if (fetch_ieee754(src, IEEE_DOUBLE, addr, mbg_double) != IEEE_OK) \
422 unsigned char ** buffpp,
426 ephp->csum = get_lsb_short(buffpp);
427 ephp->valid = get_lsb_short(buffpp);
429 ephp->health = get_lsb_short(buffpp);
430 ephp->IODC = get_lsb_short(buffpp);
431 ephp->IODE2 = get_lsb_short(buffpp);
432 ephp->IODE3 = get_lsb_short(buffpp);
434 get_mbg_tgps(buffpp, &ephp->tt);
435 get_mbg_tgps(buffpp, &ephp->t0c);
436 get_mbg_tgps(buffpp, &ephp->t0e);
438 FETCH_DOUBLE(buffpp, &ephp->sqrt_A);
439 FETCH_DOUBLE(buffpp, &ephp->e);
440 FETCH_DOUBLE(buffpp, &ephp->M0);
441 FETCH_DOUBLE(buffpp, &ephp->omega);
442 FETCH_DOUBLE(buffpp, &ephp->OMEGA0);
443 FETCH_DOUBLE(buffpp, &ephp->OMEGADOT);
444 FETCH_DOUBLE(buffpp, &ephp->deltan);
445 FETCH_DOUBLE(buffpp, &ephp->i0);
446 FETCH_DOUBLE(buffpp, &ephp->idot);
447 FETCH_DOUBLE(buffpp, &ephp->crc);
448 FETCH_DOUBLE(buffpp, &ephp->crs);
449 FETCH_DOUBLE(buffpp, &ephp->cuc);
450 FETCH_DOUBLE(buffpp, &ephp->cus);
451 FETCH_DOUBLE(buffpp, &ephp->cic);
452 FETCH_DOUBLE(buffpp, &ephp->cis);
454 FETCH_DOUBLE(buffpp, &ephp->af0);
455 FETCH_DOUBLE(buffpp, &ephp->af1);
456 FETCH_DOUBLE(buffpp, &ephp->af2);
457 FETCH_DOUBLE(buffpp, &ephp->tgd);
459 ephp->URA = get_lsb_short(buffpp);
461 ephp->L2code = *(*buffpp)++;
462 ephp->L2flag = *(*buffpp)++;
467 unsigned char **buffpp,
471 almp->csum = get_lsb_short(buffpp);
472 almp->valid = get_lsb_short(buffpp);
474 almp->health = get_lsb_short(buffpp);
475 get_mbg_tgps(buffpp, &almp->t0a);
478 FETCH_DOUBLE(buffpp, &almp->sqrt_A);
479 FETCH_DOUBLE(buffpp, &almp->e);
481 FETCH_DOUBLE(buffpp, &almp->M0);
482 FETCH_DOUBLE(buffpp, &almp->omega);
483 FETCH_DOUBLE(buffpp, &almp->OMEGA0);
484 FETCH_DOUBLE(buffpp, &almp->OMEGADOT);
485 FETCH_DOUBLE(buffpp, &almp->deltai);
486 FETCH_DOUBLE(buffpp, &almp->af0);
487 FETCH_DOUBLE(buffpp, &almp->af1);
492 unsigned char **buffpp,
496 ionop->csum = get_lsb_short(buffpp);
497 ionop->valid = get_lsb_short(buffpp);
499 FETCH_DOUBLE(buffpp, &ionop->alpha_0);
500 FETCH_DOUBLE(buffpp, &ionop->alpha_1);
501 FETCH_DOUBLE(buffpp, &ionop->alpha_2);
502 FETCH_DOUBLE(buffpp, &ionop->alpha_3);
504 FETCH_DOUBLE(buffpp, &ionop->beta_0);
505 FETCH_DOUBLE(buffpp, &ionop->beta_1);
506 FETCH_DOUBLE(buffpp, &ionop->beta_2);
507 FETCH_DOUBLE(buffpp, &ionop->beta_3);
512 * Revision 4.8 2006/06/22 18:40:01 kardel
513 * clean up signedness (gcc 4)
515 * Revision 4.7 2005/10/07 22:11:10 kardel
516 * bounded buffer implementation
518 * Revision 4.6.2.1 2005/09/25 10:23:06 kardel
519 * support bounded buffers
521 * Revision 4.6 2005/04/16 17:32:10 kardel
524 * Revision 4.5 2004/11/14 15:29:41 kardel
525 * support PPSAPI, upgrade Copyright to Berkeley style
527 * Revision 4.3 1999/02/21 12:17:42 kardel
528 * 4.91f reconcilation
530 * Revision 4.2 1998/06/14 21:09:39 kardel
533 * Revision 4.1 1998/05/24 08:02:06 kardel
534 * trimmed version log
536 * Revision 4.0 1998/04/10 19:45:33 kardel
537 * Start 4.0 release version numbering