1c0b746e5SOllivier Robert /*
2ea906c41SOllivier Robert * /src/NTP/REPOSITORY/ntp4-dev/libparse/data_mbg.c,v 4.8 2006/06/22 18:40:01 kardel RELEASE_20060622_A
3ea906c41SOllivier Robert *
4ea906c41SOllivier Robert * data_mbg.c,v 4.8 2006/06/22 18:40:01 kardel RELEASE_20060622_A
5c0b746e5SOllivier Robert *
6c0b746e5SOllivier Robert * $Created: Sun Jul 20 12:08:14 1997 $
7c0b746e5SOllivier Robert *
8ea906c41SOllivier Robert * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
9ea906c41SOllivier Robert *
10ea906c41SOllivier Robert * Redistribution and use in source and binary forms, with or without
11ea906c41SOllivier Robert * modification, are permitted provided that the following conditions
12ea906c41SOllivier Robert * are met:
13ea906c41SOllivier Robert * 1. Redistributions of source code must retain the above copyright
14ea906c41SOllivier Robert * notice, this list of conditions and the following disclaimer.
15ea906c41SOllivier Robert * 2. Redistributions in binary form must reproduce the above copyright
16ea906c41SOllivier Robert * notice, this list of conditions and the following disclaimer in the
17ea906c41SOllivier Robert * documentation and/or other materials provided with the distribution.
18ea906c41SOllivier Robert * 3. Neither the name of the author nor the names of its contributors
19ea906c41SOllivier Robert * may be used to endorse or promote products derived from this software
20ea906c41SOllivier Robert * without specific prior written permission.
21ea906c41SOllivier Robert *
22ea906c41SOllivier Robert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23ea906c41SOllivier Robert * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ea906c41SOllivier Robert * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ea906c41SOllivier Robert * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26ea906c41SOllivier Robert * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ea906c41SOllivier Robert * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ea906c41SOllivier Robert * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ea906c41SOllivier Robert * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ea906c41SOllivier Robert * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ea906c41SOllivier Robert * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ea906c41SOllivier Robert * SUCH DAMAGE.
33ea906c41SOllivier Robert *
34c0b746e5SOllivier Robert */
35c0b746e5SOllivier Robert
362b15cb3dSCy Schubert #include <config.h>
37c0b746e5SOllivier Robert #ifdef PARSESTREAM
38c0b746e5SOllivier Robert #define NEED_BOPS
39c0b746e5SOllivier Robert #include "ntp_string.h"
40c0b746e5SOllivier Robert #else
41c0b746e5SOllivier Robert #include <stdio.h>
42c0b746e5SOllivier Robert #endif
43c0b746e5SOllivier Robert #include "ntp_types.h"
44c0b746e5SOllivier Robert #include "ntp_stdlib.h"
45c0b746e5SOllivier Robert #include "ntp_fp.h"
46*a25439b6SCy Schubert #include "ntp_calendar.h"
47c0b746e5SOllivier Robert #include "mbg_gps166.h"
48c0b746e5SOllivier Robert #include "binio.h"
49c0b746e5SOllivier Robert #include "ieee754io.h"
50c0b746e5SOllivier Robert
512b15cb3dSCy Schubert static void get_mbg_tzname (unsigned char **, char *);
522b15cb3dSCy Schubert static void mbg_time_status_str (char **, unsigned int, int);
53c0b746e5SOllivier Robert
54c0b746e5SOllivier Robert #if 0 /* no actual floats on Meinberg binary interface */
55c0b746e5SOllivier Robert static offsets_t mbg_float = { 1, 0, 3, 2, 0, 0, 0, 0 }; /* byte order for meinberg floats */
56c0b746e5SOllivier Robert #endif
57c0b746e5SOllivier Robert static offsets_t mbg_double = { 1, 0, 3, 2, 5, 4, 7, 6 }; /* byte order for meinberg doubles */
58c0b746e5SOllivier Robert static int32 rad2deg_i = 57;
59c0b746e5SOllivier Robert static u_int32 rad2deg_f = 0x4BB834C7; /* 57.2957795131 == 180/PI */
60c0b746e5SOllivier Robert
61c0b746e5SOllivier Robert void
put_mbg_header(unsigned char ** bufpp,GPS_MSG_HDR * headerp)62c0b746e5SOllivier Robert put_mbg_header(
63c0b746e5SOllivier Robert unsigned char **bufpp,
64c0b746e5SOllivier Robert GPS_MSG_HDR *headerp
65c0b746e5SOllivier Robert )
66c0b746e5SOllivier Robert {
67*a25439b6SCy Schubert put_lsb_short(bufpp, headerp->cmd);
68*a25439b6SCy Schubert put_lsb_short(bufpp, headerp->len);
69*a25439b6SCy Schubert put_lsb_short(bufpp, headerp->data_csum);
70*a25439b6SCy Schubert put_lsb_short(bufpp, headerp->hdr_csum);
71c0b746e5SOllivier Robert }
72c0b746e5SOllivier Robert
73c0b746e5SOllivier Robert void
get_mbg_sw_rev(unsigned char ** bufpp,SW_REV * sw_revp)74c0b746e5SOllivier Robert get_mbg_sw_rev(
75c0b746e5SOllivier Robert unsigned char **bufpp,
76c0b746e5SOllivier Robert SW_REV *sw_revp
77c0b746e5SOllivier Robert )
78c0b746e5SOllivier Robert {
79*a25439b6SCy Schubert sw_revp->code = get_lsb_uint16(bufpp);
80c0b746e5SOllivier Robert memcpy(sw_revp->name, *bufpp, sizeof(sw_revp->name));
81c0b746e5SOllivier Robert *bufpp += sizeof(sw_revp->name);
82c0b746e5SOllivier Robert }
83c0b746e5SOllivier Robert
84c0b746e5SOllivier Robert void
get_mbg_ascii_msg(unsigned char ** bufpp,ASCII_MSG * ascii_msgp)85c0b746e5SOllivier Robert get_mbg_ascii_msg(
86c0b746e5SOllivier Robert unsigned char **bufpp,
87c0b746e5SOllivier Robert ASCII_MSG *ascii_msgp
88c0b746e5SOllivier Robert )
89c0b746e5SOllivier Robert {
90*a25439b6SCy Schubert ascii_msgp->csum = (CSUM) get_lsb_short(bufpp);
91*a25439b6SCy Schubert ascii_msgp->valid = get_lsb_int16(bufpp);
92c0b746e5SOllivier Robert memcpy(ascii_msgp->s, *bufpp, sizeof(ascii_msgp->s));
93c0b746e5SOllivier Robert *bufpp += sizeof(ascii_msgp->s);
94c0b746e5SOllivier Robert }
95c0b746e5SOllivier Robert
96c0b746e5SOllivier Robert void
get_mbg_svno(unsigned char ** bufpp,SVNO * svnop)97c0b746e5SOllivier Robert get_mbg_svno(
98c0b746e5SOllivier Robert unsigned char **bufpp,
99c0b746e5SOllivier Robert SVNO *svnop
100c0b746e5SOllivier Robert )
101c0b746e5SOllivier Robert {
102*a25439b6SCy Schubert *svnop = (SVNO) get_lsb_short(bufpp);
103c0b746e5SOllivier Robert }
104c0b746e5SOllivier Robert
105c0b746e5SOllivier Robert void
get_mbg_health(unsigned char ** bufpp,HEALTH * healthp)106c0b746e5SOllivier Robert get_mbg_health(
107c0b746e5SOllivier Robert unsigned char **bufpp,
108c0b746e5SOllivier Robert HEALTH *healthp
109c0b746e5SOllivier Robert )
110c0b746e5SOllivier Robert {
111*a25439b6SCy Schubert *healthp = (HEALTH) get_lsb_short(bufpp);
112c0b746e5SOllivier Robert }
113c0b746e5SOllivier Robert
114c0b746e5SOllivier Robert void
get_mbg_cfg(unsigned char ** bufpp,CFG * cfgp)115c0b746e5SOllivier Robert get_mbg_cfg(
116c0b746e5SOllivier Robert unsigned char **bufpp,
117c0b746e5SOllivier Robert CFG *cfgp
118c0b746e5SOllivier Robert )
119c0b746e5SOllivier Robert {
120*a25439b6SCy Schubert *cfgp = (CFG) get_lsb_short(bufpp);
121c0b746e5SOllivier Robert }
122c0b746e5SOllivier Robert
123c0b746e5SOllivier Robert void
get_mbg_tgps(unsigned char ** bufpp,T_GPS * tgpsp)124c0b746e5SOllivier Robert get_mbg_tgps(
125c0b746e5SOllivier Robert unsigned char **bufpp,
126c0b746e5SOllivier Robert T_GPS *tgpsp
127c0b746e5SOllivier Robert )
128c0b746e5SOllivier Robert {
129*a25439b6SCy Schubert tgpsp->wn = get_lsb_uint16(bufpp);
130c0b746e5SOllivier Robert tgpsp->sec = get_lsb_long(bufpp);
131c0b746e5SOllivier Robert tgpsp->tick = get_lsb_long(bufpp);
132c0b746e5SOllivier Robert }
133c0b746e5SOllivier Robert
134c0b746e5SOllivier Robert void
get_mbg_tm(unsigned char ** buffpp,TM_GPS * tmp)135c0b746e5SOllivier Robert get_mbg_tm(
136c0b746e5SOllivier Robert unsigned char **buffpp,
137*a25439b6SCy Schubert TM_GPS *tmp
138c0b746e5SOllivier Robert )
139c0b746e5SOllivier Robert {
140*a25439b6SCy Schubert tmp->year = get_lsb_int16(buffpp);
141c0b746e5SOllivier Robert tmp->month = *(*buffpp)++;
142c0b746e5SOllivier Robert tmp->mday = *(*buffpp)++;
143*a25439b6SCy Schubert tmp->yday = get_lsb_int16(buffpp);
144c0b746e5SOllivier Robert tmp->wday = *(*buffpp)++;
145c0b746e5SOllivier Robert tmp->hour = *(*buffpp)++;
146*a25439b6SCy Schubert tmp->min = *(*buffpp)++;
147*a25439b6SCy Schubert tmp->sec = *(*buffpp)++;
148c0b746e5SOllivier Robert tmp->frac = get_lsb_long(buffpp);
149c0b746e5SOllivier Robert tmp->offs_from_utc = get_lsb_long(buffpp);
150*a25439b6SCy Schubert tmp->status = get_lsb_uint16(buffpp);
151c0b746e5SOllivier Robert }
152c0b746e5SOllivier Robert
153c0b746e5SOllivier Robert void
get_mbg_ttm(unsigned char ** buffpp,TTM * ttmp)154c0b746e5SOllivier Robert get_mbg_ttm(
155c0b746e5SOllivier Robert unsigned char **buffpp,
156c0b746e5SOllivier Robert TTM *ttmp
157c0b746e5SOllivier Robert )
158c0b746e5SOllivier Robert {
159*a25439b6SCy Schubert ttmp->channel = get_lsb_int16(buffpp);
160c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &ttmp->t);
161c0b746e5SOllivier Robert get_mbg_tm(buffpp, &ttmp->tm);
162c0b746e5SOllivier Robert }
163c0b746e5SOllivier Robert
164c0b746e5SOllivier Robert void
get_mbg_synth(unsigned char ** buffpp,SYNTH * synthp)165c0b746e5SOllivier Robert get_mbg_synth(
166c0b746e5SOllivier Robert unsigned char **buffpp,
167c0b746e5SOllivier Robert SYNTH *synthp
168c0b746e5SOllivier Robert )
169c0b746e5SOllivier Robert {
170*a25439b6SCy Schubert synthp->freq = get_lsb_int16(buffpp);
171*a25439b6SCy Schubert synthp->range = get_lsb_int16(buffpp);
172*a25439b6SCy Schubert synthp->phase = get_lsb_int16(buffpp);
173c0b746e5SOllivier Robert }
174c0b746e5SOllivier Robert
175c0b746e5SOllivier Robert static void
get_mbg_tzname(unsigned char ** buffpp,char * tznamep)176c0b746e5SOllivier Robert get_mbg_tzname(
177c0b746e5SOllivier Robert unsigned char **buffpp,
178c0b746e5SOllivier Robert char *tznamep
179c0b746e5SOllivier Robert )
180c0b746e5SOllivier Robert {
1812b15cb3dSCy Schubert strlcpy(tznamep, (char *)*buffpp, sizeof(TZ_NAME));
182c0b746e5SOllivier Robert *buffpp += sizeof(TZ_NAME);
183c0b746e5SOllivier Robert }
184c0b746e5SOllivier Robert
185c0b746e5SOllivier Robert void
get_mbg_tzdl(unsigned char ** buffpp,TZDL * tzdlp)186c0b746e5SOllivier Robert get_mbg_tzdl(
187c0b746e5SOllivier Robert unsigned char **buffpp,
188c0b746e5SOllivier Robert TZDL *tzdlp
189c0b746e5SOllivier Robert )
190c0b746e5SOllivier Robert {
191c0b746e5SOllivier Robert tzdlp->offs = get_lsb_long(buffpp);
192c0b746e5SOllivier Robert tzdlp->offs_dl = get_lsb_long(buffpp);
193c0b746e5SOllivier Robert get_mbg_tm(buffpp, &tzdlp->tm_on);
194c0b746e5SOllivier Robert get_mbg_tm(buffpp, &tzdlp->tm_off);
195c0b746e5SOllivier Robert get_mbg_tzname(buffpp, (char *)tzdlp->name[0]);
196c0b746e5SOllivier Robert get_mbg_tzname(buffpp, (char *)tzdlp->name[1]);
197c0b746e5SOllivier Robert }
198c0b746e5SOllivier Robert
199c0b746e5SOllivier Robert void
get_mbg_antinfo(unsigned char ** buffpp,ANT_INFO * antinfop)200c0b746e5SOllivier Robert get_mbg_antinfo(
201c0b746e5SOllivier Robert unsigned char **buffpp,
202c0b746e5SOllivier Robert ANT_INFO *antinfop
203c0b746e5SOllivier Robert )
204c0b746e5SOllivier Robert {
205*a25439b6SCy Schubert antinfop->status = get_lsb_int16(buffpp);
206c0b746e5SOllivier Robert get_mbg_tm(buffpp, &antinfop->tm_disconn);
207c0b746e5SOllivier Robert get_mbg_tm(buffpp, &antinfop->tm_reconn);
208c0b746e5SOllivier Robert antinfop->delta_t = get_lsb_long(buffpp);
209c0b746e5SOllivier Robert }
210c0b746e5SOllivier Robert
211c0b746e5SOllivier Robert static void
mbg_time_status_str(char ** buffpp,unsigned int status,int size)212c0b746e5SOllivier Robert mbg_time_status_str(
213ea906c41SOllivier Robert char **buffpp,
214ea906c41SOllivier Robert unsigned int status,
215ea906c41SOllivier Robert int size
216c0b746e5SOllivier Robert )
217c0b746e5SOllivier Robert {
218c0b746e5SOllivier Robert static struct state
219c0b746e5SOllivier Robert {
220c0b746e5SOllivier Robert int flag; /* bit flag */
221c0b746e5SOllivier Robert const char *string; /* bit name */
222c0b746e5SOllivier Robert } states[] =
223c0b746e5SOllivier Robert {
224c0b746e5SOllivier Robert { TM_UTC, "UTC CORR" },
225c0b746e5SOllivier Robert { TM_LOCAL, "LOCAL TIME" },
226c0b746e5SOllivier Robert { TM_DL_ANN, "DST WARN" },
227c0b746e5SOllivier Robert { TM_DL_ENB, "DST" },
228c0b746e5SOllivier Robert { TM_LS_ANN, "LEAP WARN" },
229c0b746e5SOllivier Robert { TM_LS_ENB, "LEAP SEC" },
230c0b746e5SOllivier Robert { 0, "" }
231c0b746e5SOllivier Robert };
232c0b746e5SOllivier Robert
233c0b746e5SOllivier Robert if (status)
234c0b746e5SOllivier Robert {
235ea906c41SOllivier Robert char *start, *p;
236c0b746e5SOllivier Robert struct state *s;
237c0b746e5SOllivier Robert
238ea906c41SOllivier Robert start = p = *buffpp;
239c0b746e5SOllivier Robert
240c0b746e5SOllivier Robert for (s = states; s->flag; s++)
241c0b746e5SOllivier Robert {
242c0b746e5SOllivier Robert if (s->flag & status)
243c0b746e5SOllivier Robert {
244c0b746e5SOllivier Robert if (p != *buffpp)
245c0b746e5SOllivier Robert {
2462b15cb3dSCy Schubert strlcpy(p, ", ", size - (p - start));
247ea906c41SOllivier Robert p += 2;
248c0b746e5SOllivier Robert }
2492b15cb3dSCy Schubert strlcpy(p, s->string, size - (p - start));
250ea906c41SOllivier Robert p += strlen(p);
251c0b746e5SOllivier Robert }
252c0b746e5SOllivier Robert }
253c0b746e5SOllivier Robert *buffpp = p;
254c0b746e5SOllivier Robert }
255c0b746e5SOllivier Robert }
256c0b746e5SOllivier Robert
257c0b746e5SOllivier Robert void
mbg_tm_str(char ** buffpp,TM_GPS * tmp,int size,int print_status)258c0b746e5SOllivier Robert mbg_tm_str(
259ea906c41SOllivier Robert char **buffpp,
260*a25439b6SCy Schubert TM_GPS *tmp,
261*a25439b6SCy Schubert int size,
262*a25439b6SCy Schubert int print_status
263c0b746e5SOllivier Robert )
264c0b746e5SOllivier Robert {
265ea906c41SOllivier Robert char *s = *buffpp;
266ea906c41SOllivier Robert
267ea906c41SOllivier Robert snprintf(*buffpp, size, "%04d-%02d-%02d %02d:%02d:%02d.%07ld (%c%02d%02d) ",
268c0b746e5SOllivier Robert tmp->year, tmp->month, tmp->mday,
269*a25439b6SCy Schubert tmp->hour, tmp->min, tmp->sec, (long) tmp->frac,
270c0b746e5SOllivier Robert (tmp->offs_from_utc < 0) ? '-' : '+',
2712b15cb3dSCy Schubert abs((int)tmp->offs_from_utc) / 3600,
2722b15cb3dSCy Schubert (abs((int)tmp->offs_from_utc) / 60) % 60);
273ea906c41SOllivier Robert *buffpp += strlen(*buffpp);
274ea906c41SOllivier Robert
275*a25439b6SCy Schubert if (print_status)
276ea906c41SOllivier Robert mbg_time_status_str(buffpp, tmp->status, size - (*buffpp - s));
277c0b746e5SOllivier Robert }
278c0b746e5SOllivier Robert
279c0b746e5SOllivier Robert void
mbg_tgps_str(char ** buffpp,T_GPS * tgpsp,int size)280c0b746e5SOllivier Robert mbg_tgps_str(
281ea906c41SOllivier Robert char **buffpp,
282ea906c41SOllivier Robert T_GPS *tgpsp,
283ea906c41SOllivier Robert int size
284c0b746e5SOllivier Robert )
285c0b746e5SOllivier Robert {
286ea906c41SOllivier Robert snprintf(*buffpp, size, "week %d + %ld days + %ld.%07ld sec",
287*a25439b6SCy Schubert tgpsp->wn, (long) tgpsp->sec / SECSPERDAY,
288*a25439b6SCy Schubert (long) tgpsp->sec % SECSPERDAY, (long) tgpsp->tick);
289ea906c41SOllivier Robert *buffpp += strlen(*buffpp);
290c0b746e5SOllivier Robert }
291c0b746e5SOllivier Robert
292c0b746e5SOllivier Robert void
get_mbg_cfgh(unsigned char ** buffpp,CFGH * cfghp)293c0b746e5SOllivier Robert get_mbg_cfgh(
294c0b746e5SOllivier Robert unsigned char **buffpp,
295c0b746e5SOllivier Robert CFGH *cfghp
296c0b746e5SOllivier Robert )
297c0b746e5SOllivier Robert {
298c0b746e5SOllivier Robert int i;
299c0b746e5SOllivier Robert
300*a25439b6SCy Schubert cfghp->csum = (CSUM) get_lsb_short(buffpp);
301*a25439b6SCy Schubert cfghp->valid = get_lsb_int16(buffpp);
302c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &cfghp->tot_51);
303c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &cfghp->tot_63);
304c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &cfghp->t0a);
305c0b746e5SOllivier Robert
306*a25439b6SCy Schubert for (i = 0; i < N_SVNO_GPS; i++)
307c0b746e5SOllivier Robert {
308c0b746e5SOllivier Robert get_mbg_cfg(buffpp, &cfghp->cfg[i]);
309c0b746e5SOllivier Robert }
310c0b746e5SOllivier Robert
311*a25439b6SCy Schubert for (i = 0; i < N_SVNO_GPS; i++)
312c0b746e5SOllivier Robert {
313c0b746e5SOllivier Robert get_mbg_health(buffpp, &cfghp->health[i]);
314c0b746e5SOllivier Robert }
315c0b746e5SOllivier Robert }
316c0b746e5SOllivier Robert
317c0b746e5SOllivier Robert void
get_mbg_utc(unsigned char ** buffpp,UTC * utcp)318c0b746e5SOllivier Robert get_mbg_utc(
319c0b746e5SOllivier Robert unsigned char **buffpp,
320c0b746e5SOllivier Robert UTC *utcp
321c0b746e5SOllivier Robert )
322c0b746e5SOllivier Robert {
323*a25439b6SCy Schubert utcp->csum = (CSUM) get_lsb_short(buffpp);
324*a25439b6SCy Schubert utcp->valid = get_lsb_int16(buffpp);
325c0b746e5SOllivier Robert
326c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &utcp->t0t);
327c0b746e5SOllivier Robert
328c0b746e5SOllivier Robert if (fetch_ieee754(buffpp, IEEE_DOUBLE, &utcp->A0, mbg_double) != IEEE_OK)
329c0b746e5SOllivier Robert {
330c0b746e5SOllivier Robert L_CLR(&utcp->A0);
331c0b746e5SOllivier Robert }
332c0b746e5SOllivier Robert
333c0b746e5SOllivier Robert if (fetch_ieee754(buffpp, IEEE_DOUBLE, &utcp->A1, mbg_double) != IEEE_OK)
334c0b746e5SOllivier Robert {
335c0b746e5SOllivier Robert L_CLR(&utcp->A1);
336c0b746e5SOllivier Robert }
337c0b746e5SOllivier Robert
338*a25439b6SCy Schubert utcp->WNlsf = get_lsb_uint16(buffpp);
339*a25439b6SCy Schubert utcp->DNt = get_lsb_int16(buffpp);
340c0b746e5SOllivier Robert utcp->delta_tls = *(*buffpp)++;
341c0b746e5SOllivier Robert utcp->delta_tlsf = *(*buffpp)++;
342c0b746e5SOllivier Robert }
343c0b746e5SOllivier Robert
344c0b746e5SOllivier Robert void
get_mbg_lla(unsigned char ** buffpp,LLA lla)345c0b746e5SOllivier Robert get_mbg_lla(
346c0b746e5SOllivier Robert unsigned char **buffpp,
347c0b746e5SOllivier Robert LLA lla
348c0b746e5SOllivier Robert )
349c0b746e5SOllivier Robert {
350c0b746e5SOllivier Robert int i;
351c0b746e5SOllivier Robert
352c0b746e5SOllivier Robert for (i = LAT; i <= ALT; i++)
353c0b746e5SOllivier Robert {
354c0b746e5SOllivier Robert if (fetch_ieee754(buffpp, IEEE_DOUBLE, &lla[i], mbg_double) != IEEE_OK)
355c0b746e5SOllivier Robert {
356c0b746e5SOllivier Robert L_CLR(&lla[i]);
357c0b746e5SOllivier Robert }
358c0b746e5SOllivier Robert else
359c0b746e5SOllivier Robert if (i != ALT)
360c0b746e5SOllivier Robert { /* convert to degrees (* 180/PI) */
361c0b746e5SOllivier Robert mfp_mul(&lla[i].l_i, &lla[i].l_uf, lla[i].l_i, lla[i].l_uf, rad2deg_i, rad2deg_f);
362c0b746e5SOllivier Robert }
363c0b746e5SOllivier Robert }
364c0b746e5SOllivier Robert }
365c0b746e5SOllivier Robert
366c0b746e5SOllivier Robert void
get_mbg_xyz(unsigned char ** buffpp,XYZ xyz)367c0b746e5SOllivier Robert get_mbg_xyz(
368c0b746e5SOllivier Robert unsigned char **buffpp,
369c0b746e5SOllivier Robert XYZ xyz
370c0b746e5SOllivier Robert )
371c0b746e5SOllivier Robert {
372c0b746e5SOllivier Robert int i;
373c0b746e5SOllivier Robert
374c0b746e5SOllivier Robert for (i = XP; i <= ZP; i++)
375c0b746e5SOllivier Robert {
376c0b746e5SOllivier Robert if (fetch_ieee754(buffpp, IEEE_DOUBLE, &xyz[i], mbg_double) != IEEE_OK)
377c0b746e5SOllivier Robert {
378c0b746e5SOllivier Robert L_CLR(&xyz[i]);
379c0b746e5SOllivier Robert }
380c0b746e5SOllivier Robert }
381c0b746e5SOllivier Robert }
382c0b746e5SOllivier Robert
383c0b746e5SOllivier Robert static void
get_mbg_comparam(unsigned char ** buffpp,COM_PARM * comparamp)384c0b746e5SOllivier Robert get_mbg_comparam(
385c0b746e5SOllivier Robert unsigned char **buffpp,
386c0b746e5SOllivier Robert COM_PARM *comparamp
387c0b746e5SOllivier Robert )
388c0b746e5SOllivier Robert {
3892b15cb3dSCy Schubert size_t i;
390c0b746e5SOllivier Robert
391c0b746e5SOllivier Robert comparamp->baud_rate = get_lsb_long(buffpp);
392c0b746e5SOllivier Robert for (i = 0; i < sizeof(comparamp->framing); i++)
393c0b746e5SOllivier Robert {
394c0b746e5SOllivier Robert comparamp->framing[i] = *(*buffpp)++;
395c0b746e5SOllivier Robert }
396*a25439b6SCy Schubert comparamp->handshake = get_lsb_int16(buffpp);
397c0b746e5SOllivier Robert }
398c0b746e5SOllivier Robert
399c0b746e5SOllivier Robert void
get_mbg_portparam(unsigned char ** buffpp,PORT_PARM * portparamp)400c0b746e5SOllivier Robert get_mbg_portparam(
401c0b746e5SOllivier Robert unsigned char **buffpp,
402c0b746e5SOllivier Robert PORT_PARM *portparamp
403c0b746e5SOllivier Robert )
404c0b746e5SOllivier Robert {
405c0b746e5SOllivier Robert int i;
406c0b746e5SOllivier Robert
407*a25439b6SCy Schubert for (i = 0; i < DEFAULT_N_COM; i++)
408c0b746e5SOllivier Robert {
409c0b746e5SOllivier Robert get_mbg_comparam(buffpp, &portparamp->com[i]);
410c0b746e5SOllivier Robert }
411*a25439b6SCy Schubert for (i = 0; i < DEFAULT_N_COM; i++)
412c0b746e5SOllivier Robert {
413c0b746e5SOllivier Robert portparamp->mode[i] = *(*buffpp)++;
414c0b746e5SOllivier Robert }
415c0b746e5SOllivier Robert }
416c0b746e5SOllivier Robert
417c0b746e5SOllivier Robert #define FETCH_DOUBLE(src, addr) \
418c0b746e5SOllivier Robert if (fetch_ieee754(src, IEEE_DOUBLE, addr, mbg_double) != IEEE_OK) \
419c0b746e5SOllivier Robert { \
420c0b746e5SOllivier Robert L_CLR(addr); \
421c0b746e5SOllivier Robert }
422c0b746e5SOllivier Robert
423c0b746e5SOllivier Robert void
get_mbg_eph(unsigned char ** buffpp,EPH * ephp)424c0b746e5SOllivier Robert get_mbg_eph(
425c0b746e5SOllivier Robert unsigned char ** buffpp,
426c0b746e5SOllivier Robert EPH *ephp
427c0b746e5SOllivier Robert )
428c0b746e5SOllivier Robert {
429*a25439b6SCy Schubert ephp->csum = (CSUM) get_lsb_short(buffpp);
430*a25439b6SCy Schubert ephp->valid = get_lsb_int16(buffpp);
431c0b746e5SOllivier Robert
432*a25439b6SCy Schubert ephp->health = (HEALTH) get_lsb_short(buffpp);
433*a25439b6SCy Schubert ephp->IODC = (IOD) get_lsb_short(buffpp);
434*a25439b6SCy Schubert ephp->IODE2 = (IOD) get_lsb_short(buffpp);
435*a25439b6SCy Schubert ephp->IODE3 = (IOD) get_lsb_short(buffpp);
436c0b746e5SOllivier Robert
437c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &ephp->tt);
438c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &ephp->t0c);
439c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &ephp->t0e);
440c0b746e5SOllivier Robert
441c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->sqrt_A);
442c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->e);
443c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->M0);
444c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->omega);
445c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->OMEGA0);
446c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->OMEGADOT);
447c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->deltan);
448c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->i0);
449c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->idot);
450c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->crc);
451c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->crs);
452c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->cuc);
453c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->cus);
454c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->cic);
455c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->cis);
456c0b746e5SOllivier Robert
457c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->af0);
458c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->af1);
459c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->af2);
460c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ephp->tgd);
461c0b746e5SOllivier Robert
462*a25439b6SCy Schubert ephp->URA = get_lsb_uint16(buffpp);
463c0b746e5SOllivier Robert
464c0b746e5SOllivier Robert ephp->L2code = *(*buffpp)++;
465c0b746e5SOllivier Robert ephp->L2flag = *(*buffpp)++;
466c0b746e5SOllivier Robert }
467c0b746e5SOllivier Robert
468c0b746e5SOllivier Robert void
get_mbg_alm(unsigned char ** buffpp,ALM * almp)469c0b746e5SOllivier Robert get_mbg_alm(
470c0b746e5SOllivier Robert unsigned char **buffpp,
471c0b746e5SOllivier Robert ALM *almp
472c0b746e5SOllivier Robert )
473c0b746e5SOllivier Robert {
474*a25439b6SCy Schubert almp->csum = (CSUM) get_lsb_short(buffpp);
475*a25439b6SCy Schubert almp->valid = get_lsb_int16(buffpp);
476c0b746e5SOllivier Robert
477*a25439b6SCy Schubert almp->health = (HEALTH) get_lsb_short(buffpp);
478c0b746e5SOllivier Robert get_mbg_tgps(buffpp, &almp->t0a);
479c0b746e5SOllivier Robert
480c0b746e5SOllivier Robert
481c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->sqrt_A);
482c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->e);
483c0b746e5SOllivier Robert
484c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->M0);
485c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->omega);
486c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->OMEGA0);
487c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->OMEGADOT);
488c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->deltai);
489c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->af0);
490c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &almp->af1);
491c0b746e5SOllivier Robert }
492c0b746e5SOllivier Robert
493c0b746e5SOllivier Robert void
get_mbg_iono(unsigned char ** buffpp,IONO * ionop)494c0b746e5SOllivier Robert get_mbg_iono(
495c0b746e5SOllivier Robert unsigned char **buffpp,
496c0b746e5SOllivier Robert IONO *ionop
497c0b746e5SOllivier Robert )
498c0b746e5SOllivier Robert {
499*a25439b6SCy Schubert ionop->csum = (CSUM) get_lsb_short(buffpp);
500*a25439b6SCy Schubert ionop->valid = get_lsb_int16(buffpp);
501c0b746e5SOllivier Robert
502c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->alpha_0);
503c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->alpha_1);
504c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->alpha_2);
505c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->alpha_3);
506c0b746e5SOllivier Robert
507c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->beta_0);
508c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->beta_1);
509c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->beta_2);
510c0b746e5SOllivier Robert FETCH_DOUBLE(buffpp, &ionop->beta_3);
511c0b746e5SOllivier Robert }
512c0b746e5SOllivier Robert
513c0b746e5SOllivier Robert /*
514c0b746e5SOllivier Robert * data_mbg.c,v
515ea906c41SOllivier Robert * Revision 4.8 2006/06/22 18:40:01 kardel
516ea906c41SOllivier Robert * clean up signedness (gcc 4)
517ea906c41SOllivier Robert *
518ea906c41SOllivier Robert * Revision 4.7 2005/10/07 22:11:10 kardel
519ea906c41SOllivier Robert * bounded buffer implementation
520ea906c41SOllivier Robert *
521ea906c41SOllivier Robert * Revision 4.6.2.1 2005/09/25 10:23:06 kardel
522ea906c41SOllivier Robert * support bounded buffers
523ea906c41SOllivier Robert *
524ea906c41SOllivier Robert * Revision 4.6 2005/04/16 17:32:10 kardel
525ea906c41SOllivier Robert * update copyright
526ea906c41SOllivier Robert *
527ea906c41SOllivier Robert * Revision 4.5 2004/11/14 15:29:41 kardel
528ea906c41SOllivier Robert * support PPSAPI, upgrade Copyright to Berkeley style
529ea906c41SOllivier Robert *
530c0b746e5SOllivier Robert * Revision 4.3 1999/02/21 12:17:42 kardel
531c0b746e5SOllivier Robert * 4.91f reconcilation
532c0b746e5SOllivier Robert *
533c0b746e5SOllivier Robert * Revision 4.2 1998/06/14 21:09:39 kardel
534c0b746e5SOllivier Robert * Sun acc cleanup
535c0b746e5SOllivier Robert *
536c0b746e5SOllivier Robert * Revision 4.1 1998/05/24 08:02:06 kardel
537c0b746e5SOllivier Robert * trimmed version log
538c0b746e5SOllivier Robert *
539c0b746e5SOllivier Robert * Revision 4.0 1998/04/10 19:45:33 kardel
540c0b746e5SOllivier Robert * Start 4.0 release version numbering
541c0b746e5SOllivier Robert */
542c0b746e5SOllivier Robert
543