1ef64b99roberto/*
27a6072eroberto * /src/NTP/REPOSITORY/ntp4-dev/include/mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
37a6072eroberto *
47a6072eroberto * mbg_gps166.h,v 4.7 2006/06/22 18:41:43 kardel RELEASE_20060622_A
5ef64b99roberto *
6ef64b99roberto * $Created: Sun Jul 20 09:20:50 1997 $
7ef64b99roberto *
87a6072eroberto * File GPSSERIO.H Copyright (c) by Meinberg Funkuhren (www.meinberg.de)
97a6072eroberto *
107a6072eroberto * Linkage to PARSE:
117a6072eroberto * Copyright (c) 1997-2005 by Frank Kardel <kardel <AT> ntp.org>
127a6072eroberto *
137a6072eroberto * Redistribution and use in source and binary forms, with or without
147a6072eroberto * modification, are permitted provided that the following conditions
157a6072eroberto * are met:
167a6072eroberto * 1. Redistributions of source code must retain the above copyright
177a6072eroberto *    notice, this list of conditions and the following disclaimer.
187a6072eroberto * 2. Redistributions in binary form must reproduce the above copyright
197a6072eroberto *    notice, this list of conditions and the following disclaimer in the
207a6072eroberto *    documentation and/or other materials provided with the distribution.
217a6072eroberto * 3. Neither the name of the author nor the names of its contributors
227a6072eroberto *    may be used to endorse or promote products derived from this software
237a6072eroberto *    without specific prior written permission.
247a6072eroberto *
257a6072eroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
267a6072eroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
277a6072eroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
287a6072eroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
297a6072eroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
307a6072eroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
317a6072eroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
327a6072eroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
337a6072eroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
347a6072eroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
357a6072eroberto * SUCH DAMAGE.
367a6072eroberto *
37ef64b99roberto */
38ef64b99roberto#ifndef MBG_GPS166_H
39ef64b99roberto#define MBG_GPS166_H
40ef64b99roberto
41ef64b99roberto
42f63afe2cy/***************************************************************************
43f63afe2cy *
44f63afe2cy *  Definitions taken from Meinberg's gpsserio.h and gpsdefs.h files.
45f63afe2cy *
46f63afe2cy *  Author:  Martin Burnicki, Meinberg Funkuhren
47f63afe2cy *
48f63afe2cy *  Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
49f63afe2cy *
50f63afe2cy *  Description:
51f63afe2cy *    Structures and codes to be used to access Meinberg GPS clocks via
52f63afe2cy *    their serial interface COM0. COM0 should be set to a high baud rate,
53f63afe2cy *    default is 19200.
54f63afe2cy *
55f63afe2cy *    Standard Meinberg GPS serial operation is to send the Meinberg
56f63afe2cy *    standard time string automatically once per second, once per
57f63afe2cy *    minute, or on request per ASCII '?'.
58f63afe2cy *
59f63afe2cy *    GPS parameter setup or parameter readout uses blocks of binary
60f63afe2cy *    data which have to be isolated from the standard string. A block
61f63afe2cy *    of data starts with a SOH code (ASCII Start Of Header, 0x01)
62f63afe2cy *    followed by a message header with constant length and a block of
63f63afe2cy *    data with variable length.
64f63afe2cy *
65f63afe2cy *    The first field (cmd) of the message header holds the command
66f63afe2cy *    code resp. the type of data to be transmitted. The next field (len)
67f63afe2cy *    gives the number of data bytes that follow the header. This number
68f63afe2cy *    ranges from 0 to sizeof( MSG_DATA ). The third field (data_csum)
69f63afe2cy *    holds a checksum of all data bytes and the last field of the header
70f63afe2cy *    finally holds the checksum of the header itself.
71f63afe2cy *
72f63afe2cy ***************************************************************************/
73f63afe2cy
74f63afe2cy/**
75f63afe2cy * @brief GPS epoch bias from ordinary time_t epoch
76f63afe2cy *
77f63afe2cy * The Unix time_t epoch is usually 1970-01-01 00:00 whereas
78f63afe2cy * the GPS epoch is 1980-01-06 00:00, so the difference is 10 years,
79f63afe2cy * plus 2 days due to leap years (1972 and 1976), plus the difference
80f63afe2cy * of the day-of-month (6 - 1), so:<br>
81f63afe2cy *
82f63afe2cy * time_t t = ( gps_week * ::SECS_PER_WEEK ) + sec_of_week + ::GPS_SEC_BIAS
83f63afe2cy */
84f63afe2cy#define GPS_SEC_BIAS   315964800UL     // ( ( ( 10UL * 365UL ) + 2 + 5 ) * SECS_PER_DAY )
85f63afe2cy
86f63afe2cy
87f63afe2cy#ifndef _COM_HS_DEFINED
88f63afe2cy  /**
89f63afe2cy   * @brief Enumeration of handshake modes
90f63afe2cy   */
91f63afe2cy  enum COM_HANSHAKE_MODES { HS_NONE, HS_XONXOFF, HS_RTSCTS, N_COM_HS };
92f63afe2cy  #define _COM_HS_DEFINED
93f63afe2cy#endif
94f63afe2cy
95f63afe2cy#ifndef _COM_PARM_DEFINED
96f63afe2cy  /**
97f63afe2cy   * @brief A data type to configure a serial port's baud rate
98f63afe2cy   *
99f63afe2cy   * @see ::MBG_BAUD_RATES
100f63afe2cy   */
101f63afe2cy  typedef int32_t BAUD_RATE;
102f63afe2cy
103f63afe2cy  /**
104f63afe2cy   * @brief Indices used to identify a parameter in the framing string
105f63afe2cy   *
106f63afe2cy   * @see ::MBG_FRAMING_STRS
107f63afe2cy   */
108f63afe2cy  enum MBG_FRAMING_STR_IDXS { F_DBITS, F_PRTY, F_STBITS };
109f63afe2cy
110f63afe2cy  /**
111f63afe2cy   * @brief A structure to store the configuration of a serial port
112f63afe2cy   */
113f63afe2cy  typedef struct
114f63afe2cy  {
115f63afe2cy    BAUD_RATE baud_rate;  ///< transmission speed, e.g. 19200L, see ::MBG_BAUD_RATES
116f63afe2cy    char framing[4];      ///< ASCIIZ framing string, e.g. "8N1" or "7E2", see ::MBG_FRAMING_STRS
117f63afe2cy    int16_t handshake;    ///< handshake mode, yet only ::HS_NONE supported
118f63afe2cy
119f63afe2cy  } COM_PARM;
120f63afe2cy
121f63afe2cy  #define _COM_PARM_DEFINED
122f63afe2cy#endif
123f63afe2cy
124f63afe2cy
125f63afe2cy/**
126f63afe2cy * @brief Enumeration of modes supported for time string transmission
127f63afe2cy *
128f63afe2cy * This determines e.g. at which point in time a string starts
129f63afe2cy * to be transmitted via the serial port.
130f63afe2cy * Used with ::PORT_SETTINGS::mode.
131f63afe2cy *
132f63afe2cy * @see ::STR_MODE_MASKS
133f63afe2cy */
134f63afe2cyenum STR_MODES
135f63afe2cy{
136f63afe2cy  STR_ON_REQ,     ///< transmission on request by received '?' character only
137f63afe2cy  STR_PER_SEC,    ///< transmission automatically if second changes
138f63afe2cy  STR_PER_MIN,    ///< transmission automatically if minute changes
139f63afe2cy  STR_AUTO,       ///< transmission automatically if required, e.g. on capture event
140f63afe2cy  STR_ON_REQ_SEC, ///< transmission if second changes and a request has been received before
141f63afe2cy  N_STR_MODE      ///< the number of known modes
142f63afe2cy};
143f63afe2cy
144f63afe2cy
145f63afe2cy/**
146f63afe2cy * The number of serial ports which are at least available
147f63afe2cy * even with very old GPS receiver models. For devices providing
148f63afe2cy * a ::RECEIVER_INFO structure the number of provided COM ports
149f63afe2cy * is available in ::RECEIVER_INFO::n_com_ports.
150f63afe2cy */
151f63afe2cy#define DEFAULT_N_COM   2
152f63afe2cy
153f63afe2cy
154f63afe2cy/**
155f63afe2cy * @brief A The structure used to store the configuration of two serial ports
156f63afe2cy *
157f63afe2cy * @deprecated This structure is deprecated, ::PORT_SETTINGS and related structures
158f63afe2cy * should be used instead, if supported by the device.
159f63afe2cy */
160f63afe2cytypedef struct
161f63afe2cy{
162f63afe2cy  COM_PARM com[DEFAULT_N_COM];    ///< COM0 and COM1 settings
163f63afe2cy  uint8_t mode[DEFAULT_N_COM];    ///< COM0 and COM1 output mode
164f63afe2cy
165f63afe2cy} PORT_PARM;
166f63afe2cy
167f63afe2cy
168f63afe2cy/**
169f63afe2cy * @brief The type of a GPS command code
170f63afe2cy *
171f63afe2cy * @see ::GPS_CMD_CODES
172f63afe2cy */
173f63afe2cytypedef uint16_t GPS_CMD;
174f63afe2cy
175f63afe2cy
176f63afe2cy/**
177f63afe2cy * @brief Control codes to be or'ed with a particular command/type code
178f63afe2cy */
179f63afe2cyenum GPS_CMD_CTRL_CODES
180f63afe2cy{
181f63afe2cy  GPS_REQACK = 0x8000,   ///< to device: request acknowledge
182f63afe2cy  GPS_ACK    = 0x4000,   ///< from device: acknowledge a command
183f63afe2cy  GPS_NACK   = 0x2000,   ///< from device: error evaluating a command
184f63afe2cy};
185f63afe2cy
186f63afe2cy#define GPS_CTRL_MSK  0xF000   ///< bit mask of all ::GPS_CMD_CTRL_CODES
187f63afe2cy
188f63afe2cy
189f63afe2cy/**
190f63afe2cy * @brief Command codes for the binary protocol
191f63afe2cy *
192f63afe2cy * These codes specify commands and associated data types used by Meinberg's
193f63afe2cy * binary protocol to exchange data with a device via serial port, direct USB,
194f63afe2cy * or socket I/O.
195f63afe2cy *
196f63afe2cy * Some commands and associated data structures can be read (r) from a device, others
197f63afe2cy * can be written (w) to the device, and some can also be sent automatically (a) by
198f63afe2cy * a device after a ::GPS_AUTO_ON command has been sent to the device.
199f63afe2cy * The individual command codes are marked with (rwa) accordingly, where '-' is used
200f63afe2cy * to indicate that a particular mode is not supported.
201f63afe2cy *
202f63afe2cy * @note Not all command code are supported by all devices.
203f63afe2cy * See the hints for a particular command.
204f63afe2cy *
205f63afe2cy * @note If ::GPS_ALM, ::GPS_EPH or a code named ..._IDX is sent to retrieve
206f63afe2cy * some data from a device then an uint16_t parameter must be also supplied
207f63afe2cy * in order to specify the index number of the data set to be returned.
208f63afe2cy * The valid index range depends on the command code.
209f63afe2cy * For ::GPS_ALM and ::GPS_EPH the index is the SV number which may be 0 or
210f63afe2cy * ::MIN_SVNO_GPS to ::MAX_SVNO_GPS. If the number is 0 then all ::N_SVNO_GPS
211f63afe2cy * almanacs or ephemeris data structures are returned.
212f63afe2cy *
213f63afe2cy * @see ::GPS_CMD_CODES_TABLE
214f63afe2cy */
215f63afe2cyenum GPS_CMD_CODES
216f63afe2cy{ /* system data */
217f63afe2cy  GPS_AUTO_ON = 0x000,  ///< (-w-) no data, enable auto-msgs from device
218f63afe2cy  GPS_AUTO_OFF,         ///< (-w-) no data, disable auto-msgs from device
219f63afe2cy  GPS_SW_REV,           ///< (r--) deprecated, ::SW_REV, software revision, use only if ::GPS_RECEIVER_INFO not supp.
220f63afe2cy  GPS_BVAR_STAT,        ///< (r--) ::BVAR_STAT, status of buffered variables, only if ::GPS_MODEL_HAS_BVAR_STAT
221f63afe2cy  GPS_TIME,             ///< (-wa) ::TTM, current time or capture, or init board time
222f63afe2cy  GPS_POS_XYZ,          ///< (rw-) ::XYZ, current position in ECEF coordinates, only if ::GPS_MODEL_HAS_POS_XYZ
223f63afe2cy  GPS_POS_LLA,          ///< (rw-) ::LLA, current position in geographic coordinates, only if ::GPS_MODEL_HAS_POS_LLA
224f63afe2cy  GPS_TZDL,             ///< (rw-) ::TZDL, time zone / daylight saving, only if ::GPS_MODEL_HAS_TZDL
225f63afe2cy  GPS_PORT_PARM,        ///< (rw-) deprecated, ::PORT_PARM, use ::PORT_SETTINGS etc. if ::GPS_RECEIVER_INFO supported
226f63afe2cy  GPS_SYNTH,            ///< (rw-) ::SYNTH, synthesizer settings, only if ::GPS_HAS_SYNTH
227f63afe2cy  GPS_ANT_INFO,         ///< (r-a) ::ANT_INFO, time diff after antenna disconnect, only if ::GPS_MODEL_HAS_ANT_INFO
228f63afe2cy  GPS_UCAP,             ///< (r-a) ::TTM, user capture events, only if ::RECEIVER_INFO::n_ucaps > 0
229ef64b99roberto
230ef64b99roberto  /* GPS data */
231f63afe2cy  GPS_CFGH = 0x100,     ///< (rw-) ::CFGH, SVs' configuration and health codes
232f63afe2cy  GPS_ALM,              ///< (rw-) req: uint16_t SV num, ::SV_ALM, one SV's almanac
233f63afe2cy  GPS_EPH,              ///< (rw-) req: uint16_t SV num, ::SV_EPH, one SV's ephemeris
234f63afe2cy  GPS_UTC,              ///< (rw-) ::UTC, GPS %UTC correction parameters
235f63afe2cy  GPS_IONO,             ///< (rw-) ::IONO, GPS ionospheric correction parameters
236f63afe2cy  GPS_ASCII_MSG         ///< (r--) ::ASCII_MSG, the GPS ASCII message
237ef64b99roberto};
238ef64b99roberto
239ef64b99roberto
240ef64b99roberto#ifndef _CSUM_DEFINED
241f63afe2cy  typedef uint16_t CSUM;  /* checksum used by some structures stored in non-volatile memory */
242f63afe2cy  #define _CSUM_DEFINED
243ef64b99roberto#endif
244ef64b99roberto
245ef64b99roberto
246f63afe2cy/**
247f63afe2cy * @brief The header of a binary message.
248f63afe2cy */
249f63afe2cytypedef struct
250f63afe2cy{
251f63afe2cy  GPS_CMD cmd;      ///< see ::GPS_CMD_CODES
252f63afe2cy  uint16_t len;     ///< length of the data portion appended after the header
253f63afe2cy  CSUM data_csum;   ///< checksum of the data portion appended after the header
254f63afe2cy  CSUM hdr_csum;    ///< checksum of the preceding header bytes
255f63afe2cy
256ef64b99roberto} GPS_MSG_HDR;
257ef64b99roberto
258ef64b99roberto
259f63afe2cy#define GPS_ID_STR_LEN      16
260f63afe2cy#define GPS_ID_STR_SIZE     ( GPS_ID_STR_LEN + 1 )
261f63afe2cy
262f63afe2cy/**
263f63afe2cy * @brief Software revision information
264f63afe2cy *
265f63afe2cy * Contains a software revision code, plus an optional
266f63afe2cy * identifier for a customized version.
267f63afe2cy */
268f63afe2cytypedef struct
269f63afe2cy{
270f63afe2cy  uint16_t code;               ///< Version number, e.g. 0x0120 means v1.20
271f63afe2cy  char name[GPS_ID_STR_SIZE];  ///< Optional string identifying a customized version
272f63afe2cy  uint8_t reserved;            ///< Reserved field to yield even structure size
273f63afe2cy
274ef64b99roberto} SW_REV;
275ef64b99roberto
276ef64b99roberto
277f63afe2cy/**
278f63afe2cy * @brief GNSS satellite numbers
279f63afe2cy *
280f63afe2cy * @todo: Check if MAX_SVNO_GLN is 94 instead of 95, and thus
281f63afe2cy *        N_SVNO_GLN is 30 instead of 31, as reported by Wikipedia.
282f63afe2cy */
283f63afe2cyenum GNSS_SVNOS
284f63afe2cy{
285f63afe2cy  MIN_SVNO_GPS = 1,       ///< min. GPS satellite PRN number
286f63afe2cy  MAX_SVNO_GPS = 32,      ///< max. GPS satellite PRN number
287f63afe2cy  N_SVNO_GPS = 32,        ///< max. number of active GPS satellites
288f63afe2cy
289f63afe2cy  MIN_SVNO_WAAS = 33,     ///< min. WAAS satellite number
290f63afe2cy  MAX_SVNO_WAAS = 64,     ///< max. WAAS satellite number
291f63afe2cy  N_SVNO_WAAS = 32,       ///< max. number of active WAAS satellites
292f63afe2cy
293f63afe2cy  MIN_SVNO_GLONASS = 65,  ///< min. Glonass satellite number (64 + sat slot ID)
294f63afe2cy  MAX_SVNO_GLONASS = 95,  ///< max. Glonass satellite number (64 + sat slot ID)
295f63afe2cy  N_SVNO_GLONASS = 31     ///< max. number of active Glonass satellites
296f63afe2cy};
297f63afe2cy
298f63afe2cy
299f63afe2cytypedef uint16_t SVNO;    ///< the number of an SV (Space Vehicle, i.e. satellite)
300f63afe2cytypedef uint16_t HEALTH;  ///< an SV's 6 bit health code
301f63afe2cytypedef uint16_t CFG;     ///< an SV's 4 bit configuration code
302f63afe2cytypedef uint16_t IOD;     ///< Issue-Of-Data code
303f63afe2cy
304f63afe2cy
305f63afe2cy/**
306f63afe2cy * @brief Status flags of battery buffered data
307f63afe2cy *
308f63afe2cy * Related to data received from the satellites, or data derived thereof.
309f63afe2cy *
310f63afe2cy * All '0' means OK, single bits set to '1' indicate
311f63afe2cy * the associated type of GPS data is not available.
312f63afe2cy *
313f63afe2cy * @see ::BVAR_FLAGS
314f63afe2cy */
315f63afe2cytypedef uint16_t BVAR_STAT;
316f63afe2cy
317f63afe2cy#define _mbg_swab_bvar_stat( _p )  _mbg_swab16( (_p) )
318ef64b99roberto
319ef64b99roberto
320f63afe2cy/**
321f63afe2cy * @brief Enumeration of flag bits used to define ::BVAR_FLAGS
322f63afe2cy *
323f63afe2cy * For each bit which is set this means the associated data set in
324f63afe2cy * non-volatile memory is not available, or incomplete.
325f63afe2cy * Most data sets will just be re-collected from the data streams sent
326f63afe2cy * by the satellites. However, the receiver position has usually been
327f63afe2cy * computed earlier during normal operation, and will be re-computed
328f63afe2cy * when a sufficient number of satellites can be received.
329f63afe2cy *
330f63afe2cy * @see ::BVAR_STAT
331f63afe2cy * @see ::BVAR_FLAGS
332f63afe2cy * @see ::BVAR_FLAG_NAMES
333f63afe2cy */
334f63afe2cyenum BVAR_FLAG_BITS
335f63afe2cy{
336f63afe2cy  BVAR_BIT_CFGH_INVALID,      ///< Satellite configuration and health parameters incomplete
337f63afe2cy  BVAR_BIT_ALM_NOT_COMPLETE,  ///< Almanac parameters incomplete
338f63afe2cy  BVAR_BIT_UTC_INVALID,       ///< %UTC offset parameters incomplete
339f63afe2cy  BVAR_BIT_IONO_INVALID,      ///< Ionospheric correction parameters incomplete
340f63afe2cy  BVAR_BIT_RCVR_POS_INVALID,  ///< No valid receiver position available
341f63afe2cy  N_BVAR_BIT                  ///< number of defined ::BVAR_STAT bits
342f63afe2cy};
343f63afe2cy
344f63afe2cy
345f63afe2cy/**
346f63afe2cy * @brief Bit masks associated with ::BVAR_FLAG_BITS
347f63afe2cy *
348f63afe2cy * Used with ::BVAR_STAT.
349f63afe2cy *
350f63afe2cy * @see ::BVAR_STAT
351f63afe2cy * @see ::BVAR_FLAG_BITS
352f63afe2cy * @see ::BVAR_FLAG_NAMES
353f63afe2cy */
354f63afe2cyenum BVAR_FLAGS
355f63afe2cy{
356f63afe2cy  BVAR_CFGH_INVALID     = ( 1UL << BVAR_BIT_CFGH_INVALID ),      ///< see ::BVAR_BIT_CFGH_INVALID
357f63afe2cy  BVAR_ALM_NOT_COMPLETE = ( 1UL << BVAR_BIT_ALM_NOT_COMPLETE ),  ///< see ::BVAR_BIT_ALM_NOT_COMPLETE
358f63afe2cy  BVAR_UTC_INVALID      = ( 1UL << BVAR_BIT_UTC_INVALID ),       ///< see ::BVAR_BIT_UTC_INVALID
359f63afe2cy  BVAR_IONO_INVALID     = ( 1UL << BVAR_BIT_IONO_INVALID ),      ///< see ::BVAR_BIT_IONO_INVALID
360f63afe2cy  BVAR_RCVR_POS_INVALID = ( 1UL << BVAR_BIT_RCVR_POS_INVALID ),  ///< see ::BVAR_BIT_RCVR_POS_INVALID
361f63afe2cy};
362ef64b99roberto
363ef64b99roberto
364f63afe2cy/**
365f63afe2cy * @brief A structure used to hold time in GPS format
366f63afe2cy *
367f63afe2cy * Date and time refer to the linear time scale defined by GPS, with
368f63afe2cy * the epoch starting at %UTC midnight at the beginning of January 6, 1980.
369f63afe2cy *
370f63afe2cy * GPS time is counted by the week numbers since the epoch, plus second
371f63afe2cy * of the week, plus fraction of the second. The week number transmitted
372f63afe2cy * by the satellites rolls over from 1023 to 0, but Meinberg devices
373f63afe2cy * just continue to count the weeks beyond the 1024 week limit to keep
374f63afe2cy * the receiver's internal time.
375f63afe2cy *
376f63afe2cy * %UTC time differs from GPS time since a number of leap seconds have
377f63afe2cy * been inserted in the %UTC time scale after the GPS epoche. The number
378f63afe2cy * of leap seconds is disseminated by the satellites using the ::UTC
379f63afe2cy * parameter set, which also provides info on pending leap seconds.
380f63afe2cy */
381f63afe2cytypedef struct
382f63afe2cy{
383f63afe2cy  uint16_t wn;     ///< the week number since GPS has been installed
384f63afe2cy  uint32_t sec;    ///< the second of that week
385f63afe2cy  uint32_t tick;   ///< fractions of a second, 1/::RECEIVER_INFO::ticks_per_sec units
386ef64b99roberto
387ef64b99roberto} T_GPS;
388ef64b99roberto
389ef64b99roberto
390f63afe2cy/**
391f63afe2cy * @brief Local date and time computed from GPS time
392f63afe2cy *
393f63afe2cy * The current number of leap seconds have to be added to get %UTC
394f63afe2cy * from GPS time. Additional corrections could have been made according
395f63afe2cy * to the time zone/daylight saving parameters ::TZDL defined by the user.
396f63afe2cy * The status field can be checked to see which corrections
397f63afe2cy * have actually been applied.
398f63afe2cy *
399f63afe2cy * @note Conversion from GPS time to %UTC and/or local time can only be
400f63afe2cy * done if some valid ::UTC correction parameters are available in the
401f63afe2cy * receiver's non-volatile memory.
402f63afe2cy */
403f63afe2cytypedef struct
404f63afe2cy{
405f63afe2cy  int16_t year;           ///< year number, 0..9999
406f63afe2cy  int8_t month;           ///< month, 1..12
407f63afe2cy  int8_t mday;            ///< day of month, 1..31
408f63afe2cy  int16_t yday;           ///< day of year, 1..365, or 366 in case of leap year
409f63afe2cy  int8_t wday;            ///< day of week, 0..6 == Sun..Sat
410f63afe2cy  int8_t hour;            ///< hours, 0..23
411f63afe2cy  int8_t min;             ///< minutes, 0..59
412f63afe2cy  int8_t sec;             ///< seconds, 0..59, or 60 in case of inserted leap second
413f63afe2cy  int32_t frac;           ///< fractions of a second, 1/::RECEIVER_INFO::ticks_per_sec units
414f63afe2cy  int32_t offs_from_utc;  ///< local time offset from %UTC [sec]
415f63afe2cy  uint16_t status;        ///< status flags, see ::TM_GPS_STATUS_BIT_MASKS
416f63afe2cy
417f63afe2cy} TM_GPS;
418f63afe2cy
419f63afe2cy
420f63afe2cy
421f63afe2cy/**
422f63afe2cy * @brief Status flag bits used to define ::TM_GPS_STATUS_BIT_MASKS
423f63afe2cy *
424f63afe2cy * These bits report info on the time conversion from GPS time to %UTC
425f63afe2cy * and/or local time as well as device status info.
426f63afe2cy *
427f63afe2cy * @see ::TM_GPS_STATUS_BIT_MASKS
428f63afe2cy */
429f63afe2cyenum TM_GPS_STATUS_BITS
430f63afe2cy{
431f63afe2cy  TM_BIT_UTC,          ///< %UTC correction has been made
432f63afe2cy  TM_BIT_LOCAL,        ///< %UTC has been converted to local time according to ::TZDL settings
433f63afe2cy  TM_BIT_DL_ANN,       ///< state of daylight saving is going to change
434f63afe2cy  TM_BIT_DL_ENB,       ///< daylight saving is in effect
435f63afe2cy  TM_BIT_LS_ANN,       ///< leap second pending
436f63afe2cy  TM_BIT_LS_ENB,       ///< current second is leap second
437f63afe2cy  TM_BIT_LS_ANN_NEG,   ///< set in addition to ::TM_BIT_LS_ANN if leap sec is negative
438f63afe2cy  TM_BIT_INVT,         ///< invalid time, e.g. if RTC battery bas been empty
439f63afe2cy
440f63afe2cy  TM_BIT_EXT_SYNC,     ///< synchronized externally
441f63afe2cy  TM_BIT_HOLDOVER,     ///< in holdover mode after previous synchronization
442f63afe2cy  TM_BIT_ANT_SHORT,    ///< antenna cable short circuited
443f63afe2cy  TM_BIT_NO_WARM,      ///< OCXO has not warmed up
444f63afe2cy  TM_BIT_ANT_DISCONN,  ///< antenna currently disconnected
445f63afe2cy  TM_BIT_SYN_FLAG,     ///< TIME_SYN output is low
446f63afe2cy  TM_BIT_NO_SYNC,      ///< time sync actually not verified
447f63afe2cy  TM_BIT_NO_POS        ///< position actually not verified, LOCK LED off
448f63afe2cy};
449ef64b99roberto
450ef64b99roberto
451f63afe2cy/**
452f63afe2cy * @brief Status flag masks used with ::TM_GPS::status
453f63afe2cy *
454f63afe2cy * These bits report info on the time conversion from GPS time to %UTC
455f63afe2cy * and/or local time as well as device status info.
456f63afe2cy *
457f63afe2cy * @see ::TM_GPS_STATUS_BITS
458f63afe2cy */
459f63afe2cyenum TM_GPS_STATUS_BIT_MASKS
460f63afe2cy{
461f63afe2cy  TM_UTC         = ( 1UL << TM_BIT_UTC ),          ///< see ::TM_BIT_UTC
462f63afe2cy  TM_LOCAL       = ( 1UL << TM_BIT_LOCAL ),        ///< see ::TM_BIT_LOCAL
463f63afe2cy  TM_DL_ANN      = ( 1UL << TM_BIT_DL_ANN ),       ///< see ::TM_BIT_DL_ANN
464f63afe2cy  TM_DL_ENB      = ( 1UL << TM_BIT_DL_ENB ),       ///< see ::TM_BIT_DL_ENB
465f63afe2cy  TM_LS_ANN      = ( 1UL << TM_BIT_LS_ANN ),       ///< see ::TM_BIT_LS_ANN
466f63afe2cy  TM_LS_ENB      = ( 1UL << TM_BIT_LS_ENB ),       ///< see ::TM_BIT_LS_ENB
467f63afe2cy  TM_LS_ANN_NEG  = ( 1UL << TM_BIT_LS_ANN_NEG ),   ///< see ::TM_BIT_LS_ANN_NEG
468f63afe2cy  TM_INVT        = ( 1UL << TM_BIT_INVT ),         ///< see ::TM_BIT_INVT
469f63afe2cy
470f63afe2cy  TM_EXT_SYNC    = ( 1UL << TM_BIT_EXT_SYNC ),     ///< see ::TM_BIT_EXT_SYNC
471f63afe2cy  TM_HOLDOVER    = ( 1UL << TM_BIT_HOLDOVER ),     ///< see ::TM_BIT_HOLDOVER
472f63afe2cy  TM_ANT_SHORT   = ( 1UL << TM_BIT_ANT_SHORT ),    ///< see ::TM_BIT_ANT_SHORT
473f63afe2cy  TM_NO_WARM     = ( 1UL << TM_BIT_NO_WARM ),      ///< see ::TM_BIT_NO_WARM
474f63afe2cy  TM_ANT_DISCONN = ( 1UL << TM_BIT_ANT_DISCONN ),  ///< see ::TM_BIT_ANT_DISCONN
475f63afe2cy  TM_SYN_FLAG    = ( 1UL << TM_BIT_SYN_FLAG ),     ///< see ::TM_BIT_SYN_FLAG
476f63afe2cy  TM_NO_SYNC     = ( 1UL << TM_BIT_NO_SYNC ),      ///< see ::TM_BIT_NO_SYNC
477f63afe2cy  TM_NO_POS      = ( 1UL << TM_BIT_NO_POS )        ///< see ::TM_BIT_NO_POS
478f63afe2cy};
479ef64b99roberto
480ef64b99roberto
481f63afe2cy/**
482f63afe2cy * @brief A structure used to transmit information on date and time
483f63afe2cy *
484f63afe2cy * This structure can be used to transfer the current time, in which
485f63afe2cy * case the channel field has to be set to -1, or an event capture time
486f63afe2cy * retrieved from the on-board FIFO, in which case the channel field
487f63afe2cy * contains the index of the time capture input, e.g. 0 or 1.
488f63afe2cy */
489f63afe2cytypedef struct
490f63afe2cy{
491f63afe2cy  int16_t channel;  ///< -1: the current on-board time; >= 0 the capture channel number
492f63afe2cy  T_GPS t;          ///< time in GPS scale and format
493f63afe2cy  TM_GPS tm;        ///< time converted to %UTC and/or local time according to ::TZDL settings
494ef64b99roberto
495ef64b99roberto} TTM;
496ef64b99roberto
497ef64b99roberto
498ef64b99roberto
499ef64b99roberto/* Two types of variables used to store a position. Type XYZ is */
500ef64b99roberto/* used with a position in earth centered, earth fixed (ECEF) */
501ef64b99roberto/* coordinates whereas type LLA holds such a position converted */
502ef64b99roberto/* to geographic coordinates as defined by WGS84 (World Geodetic */
503ef64b99roberto/* System from 1984). */
504ef64b99roberto
505f63afe2cy/**
506f63afe2cy * @brief Sequence and number of components of a cartesian position
507f63afe2cy */
508f63afe2cyenum XYZ_FIELDS { XP, YP, ZP, N_XYZ };  // x, y, z
509f63afe2cy
510f63afe2cy/**
511f63afe2cy * @brief A position in cartesian coordinates
512f63afe2cy *
513f63afe2cy * Usually earth centered, earth fixed (ECEF) coordinates,
514f63afe2cy * in [m].
515f63afe2cy *
516f63afe2cy * @note In the original code this is an array of double.
517f63afe2cy *
518f63afe2cy * @see ::XYZ_FIELDS
519f63afe2cy */
520f63afe2cytypedef l_fp XYZ[N_XYZ];
521ef64b99roberto
522ef64b99roberto
523f63afe2cy/**
524f63afe2cy * @brief Sequence and number of components of a geographic position
525f63afe2cy */
526f63afe2cyenum LLA_FIELDS { LAT, LON, ALT, N_LLA };  /* latitude, longitude, altitude */
527ef64b99roberto
528f63afe2cy/**
529f63afe2cy * @brief A geographic position based on latitude, longitude, and altitude
530f63afe2cy *
531f63afe2cy * The geographic position associated to specific cartesian coordinates
532f63afe2cy * depends on the characteristics of the ellipsoid used for the computation,
533f63afe2cy * the so-called geographic datum. GPS uses the WGS84 (World Geodetic System
534f63afe2cy * from 1984) ellipsoid by default.
535f63afe2cy *
536f63afe2cy * lon, lat in [rad], alt in [m]
537f63afe2cy *
538f63afe2cy * @note In the original code this is an array of double.
539f63afe2cy *
540f63afe2cy * @see ::LLA_FIELDS
541f63afe2cy */
542f63afe2cytypedef l_fp LLA[N_LLA];
543ef64b99roberto
544ef64b99roberto
545f63afe2cy/**
546f63afe2cy * @defgroup group_synth Synthesizer parameters
547f63afe2cy *
548f63afe2cy * Synthesizer frequency is expressed as a
549f63afe2cy * four digit decimal number (freq) to be multiplied by 0.1 Hz and an
550f63afe2cy * base 10 exponent (range). If the effective frequency is less than
551f63afe2cy * 10 kHz its phase is synchronized corresponding to the variable phase.
552f63afe2cy * Phase may be in a range from -360 deg to +360 deg with a resolution
553f63afe2cy * of 0.1 deg, so the resulting numbers to be stored are in a range of
554f63afe2cy * -3600 to +3600.
555f63afe2cy *
556f63afe2cy * Example:<br>
557f63afe2cy * Assume the value of freq is 2345 (decimal) and the value of phase is 900.
558f63afe2cy * If range == 0 the effective frequency is 234.5 Hz with a phase of +90 deg.
559f63afe2cy * If range == 1 the synthesizer will generate a 2345 Hz output frequency
560f63afe2cy * and so on.
561f63afe2cy *
562f63afe2cy * Limitations:<br>
563f63afe2cy * If freq == 0 the synthesizer is disabled. If range == 0 the least
564f63afe2cy * significant digit of freq is limited to 0, 3, 5 or 6. The resulting
565f63afe2cy * frequency is shown in the examples below:
566f63afe2cy *    - freq == 1230  -->  123.0 Hz
567f63afe2cy *    - freq == 1233  -->  123 1/3 Hz (real 1/3 Hz, NOT 123.3 Hz)
568f63afe2cy *    - freq == 1235  -->  123.5 Hz
569f63afe2cy *    - freq == 1236  -->  123 2/3 Hz (real 2/3 Hz, NOT 123.6 Hz)
570f63afe2cy *
571f63afe2cy * If range == ::MAX_SYNTH_RANGE the value of freq must not exceed 1000, so
572f63afe2cy * the output frequency is limited to 10 MHz (see ::MAX_SYNTH_FREQ_VAL).
573f63afe2cy *
574f63afe2cy * @{ */
575ef64b99roberto
576f63afe2cy#define N_SYNTH_FREQ_DIGIT  4    ///< number of digits to edit
577f63afe2cy#define MAX_SYNTH_FREQ   1000    ///< if range == ::MAX_SYNTH_RANGE
578ef64b99roberto
579ef64b99roberto#define MIN_SYNTH_RANGE     0
580ef64b99roberto#define MAX_SYNTH_RANGE     5
581f63afe2cy#define N_SYNTH_RANGE       ( MAX_SYNTH_RANGE - MIN_SYNTH_RANGE + 1 )
582ef64b99roberto
583f63afe2cy#define N_SYNTH_PHASE_DIGIT  4
584f63afe2cy#define MAX_SYNTH_PHASE      3600
585ef64b99roberto
586ef64b99roberto
587f63afe2cy#define MAX_SYNTH_FREQ_EDIT  9999  ///< max sequence of digits when editing
588ef64b99roberto
589ef64b99roberto
590f63afe2cy/**
591f63afe2cy * @brief The maximum frequency that can be configured for the synthesizer
592f63afe2cy */
593f63afe2cy#define MAX_SYNTH_FREQ_VAL   10000000UL     ///< 10 MHz
594f63afe2cy/*   == MAX_SYNTH_FREQ * 10^(MAX_SYNTH_RANGE-1) */
595ef64b99roberto
596f63afe2cy/**
597f63afe2cy * @brief The synthesizer's phase is only be synchronized if the frequency is below this limit
598f63afe2cy */
599f63afe2cy#define SYNTH_PHASE_SYNC_LIMIT   10000UL    ///< 10 kHz
600ef64b99roberto
601f63afe2cy/**
602f63afe2cy * A Macro used to determine the position of the decimal point
603f63afe2cy * when printing the synthesizer frequency as 4 digit value
604f63afe2cy */
605f63afe2cy#define _synth_dp_pos_from_range( _r ) \
606f63afe2cy  ( ( ( N_SYNTH_RANGE - (_r) ) % ( N_SYNTH_FREQ_DIGIT - 1 ) ) + 1 )
607f63afe2cy
608f63afe2cy/**
609f63afe2cy * @brief Synthesizer frequency units
610f63afe2cy *
611f63afe2cy * An initializer for commonly displayed synthesizer frequency units
612f63afe2cy * (::N_SYNTH_RANGE strings)
613f63afe2cy */
614f63afe2cy#define DEFAULT_FREQ_RANGES \
615f63afe2cy{                           \
616f63afe2cy  "Hz",                     \
617f63afe2cy  "kHz",                    \
618f63afe2cy  "kHz",                    \
619f63afe2cy  "kHz",                    \
620f63afe2cy  "MHz",                    \
621f63afe2cy  "MHz",                    \
622f63afe2cy}
623ef64b99roberto
624ef64b99roberto
625ef64b99roberto
626f63afe2cy/**
627f63afe2cy * @brief Synthesizer configuration parameters
628f63afe2cy */
629f63afe2cytypedef struct
630f63afe2cy{
631f63afe2cy  int16_t freq;    ///< four digits used; scale: 0.1 Hz; e.g. 1234 -> 123.4 Hz
632f63afe2cy  int16_t range;   ///< scale factor for freq; 0..::MAX_SYNTH_RANGE
633f63afe2cy  int16_t phase;   ///< -::MAX_SYNTH_PHASE..+::MAX_SYNTH_PHASE; >0 -> pulses later
634ef64b99roberto
635f63afe2cy} SYNTH;
636ef64b99roberto
637f63afe2cy#define _mbg_swab_synth( _p )   \
638f63afe2cy{                               \
639f63afe2cy  _mbg_swab16( &(_p)->freq );   \
640f63afe2cy  _mbg_swab16( &(_p)->range );  \
641f63afe2cy  _mbg_swab16( &(_p)->phase );  \
642f63afe2cy}
643ef64b99roberto
644ef64b99roberto
645f63afe2cy/**
646f63afe2cy * @brief Enumeration of synthesizer states
647f63afe2cy */
648f63afe2cyenum SYNTH_STATES
649f63afe2cy{
650f63afe2cy  SYNTH_DISABLED,   ///< disbled by cfg, i.e. freq == 0.0
651f63afe2cy  SYNTH_OFF,        ///< not enabled after power-up
652f63afe2cy  SYNTH_FREE,       ///< enabled, but not synchronized
653f63afe2cy  SYNTH_DRIFTING,   ///< has initially been sync'd, but now running free
654f63afe2cy  SYNTH_SYNC,       ///< fully synchronized
655f63afe2cy  N_SYNTH_STATE     ///< the number of known states
656f63afe2cy};
657f63afe2cy
658ef64b99roberto
659f63afe2cy/**
660f63afe2cy * @brief A structure used to report the synthesizer state
661f63afe2cy */
662f63afe2cytypedef struct
663f63afe2cy{
664f63afe2cy  uint8_t state;     ///< state code as enumerated in ::SYNTH_STATES
665f63afe2cy  uint8_t flags;     ///< reserved, currently always 0
666ef64b99roberto
667f63afe2cy} SYNTH_STATE;
668ef64b99roberto
669f63afe2cy#define _mbg_swab_synth_state( _p )  _nop_macro_fnc()
670ef64b99roberto
671f63afe2cy#define SYNTH_FLAG_PHASE_IGNORED  0x01
672ef64b99roberto
673f63afe2cy/** @} defgroup group_synth */
674ef64b99roberto
675ef64b99roberto
676ef64b99roberto
677f63afe2cy/**
678f63afe2cy * @defgroup group_tzdl Time zone / daylight saving parameters
679f63afe2cy *
680f63afe2cy * Example: <br>
681f63afe2cy * For automatic daylight saving enable/disable in Central Europe,
682f63afe2cy * the variables are to be set as shown below: <br>
683f63afe2cy *   - offs = 3600L           one hour from %UTC
684f63afe2cy *   - offs_dl = 3600L        one additional hour if daylight saving enabled
685f63afe2cy *   - tm_on = first Sunday from March 25, 02:00:00h ( year |= ::DL_AUTO_FLAG )
686f63afe2cy *   - tm_off = first Sunday from October 25, 03:00:00h ( year |= ::DL_AUTO_FLAG )
687f63afe2cy *   - name[0] == "CET  "     name if daylight saving not enabled
688f63afe2cy *   - name[1] == "CEST "     name if daylight saving is enabled
689f63afe2cy *
690f63afe2cy * @{ */
691f63afe2cy
692f63afe2cy/**
693f63afe2cy * @brief The name of a time zone
694f63afe2cy *
695f63afe2cy * @note Up to 5 printable characters, plus trailing zero
696f63afe2cy */
697f63afe2cytypedef char TZ_NAME[6];
698ef64b99roberto
699f63afe2cy/**
700f63afe2cy * @brief Time zone / daylight saving parameters
701f63afe2cy *
702f63afe2cy * This structure is used to specify how a device converts on-board %UTC
703f63afe2cy * to local time, including computation of beginning and end of daylight
704f63afe2cy * saving time (DST), if required.
705f63afe2cy *
706f63afe2cy * @note The ::TZDL structure contains members of type ::TM_GPS to specify
707f63afe2cy * the times for beginning and end of DST. However, the ::TM_GPS::frac,
708f63afe2cy * ::TM_GPS::offs_from_utc, and ::TM_GPS::status fields of these ::TZDL::tm_on
709f63afe2cy * and ::TZDL::tm_off members are ignored for the conversion to local time,
710f63afe2cy * and thus should be 0.
711f63afe2cy */
712f63afe2cytypedef struct
713f63afe2cy{
714f63afe2cy  int32_t offs;      ///< standard offset from %UTC to local time [sec]
715f63afe2cy  int32_t offs_dl;   ///< additional offset if daylight saving enabled [sec]
716f63afe2cy  TM_GPS tm_on;      ///< date/time when daylight saving starts
717f63afe2cy  TM_GPS tm_off;     ///< date/time when daylight saving ends
718f63afe2cy  TZ_NAME name[2];   ///< names without and with daylight saving enabled
719ef64b99roberto
720f63afe2cy} TZDL;
721f63afe2cy
722f63afe2cy/**
723f63afe2cy * @brief A flag indicating automatic computation of DST
724f63afe2cy *
725f63afe2cy * If this flag is or'ed to the year numbers in ::TZDL::tm_on and ::TZDL::tm_off
726f63afe2cy * then daylight saving is computed automatically year by year.
727f63afe2cy */
728f63afe2cy#define DL_AUTO_FLAG  0x8000
729ef64b99roberto
730f63afe2cy/** @} defgroup group_tzdl */
731ef64b99roberto
732ef64b99roberto
733ef64b99roberto
734f63afe2cy/**
735f63afe2cy * @brief Antenna status and error at reconnect information
736f63afe2cy *
737f63afe2cy * The structure below reflects the status of the antenna,
738f63afe2cy * the times of last disconnect/reconnect, and the board's
739f63afe2cy * clock offset when it has synchronized again after the
740f63afe2cy * disconnection interval.
741f63afe2cy *
742f63afe2cy * @note ::ANT_INFO::status changes back to ::ANT_RECONN only
743f63afe2cy * after the antenna has been reconnected <b>and</b> the
744f63afe2cy * receiver has re-synchronized to the satellite signal.
745f63afe2cy * In this case ::ANT_INFO::delta_t reports the time offset
746f63afe2cy * before resynchronization, i.e. how much the internal
747f63afe2cy * time has drifted while the antenna was disconnected.
748f63afe2cy */
749f63afe2cytypedef struct
750f63afe2cy{
751f63afe2cy  int16_t status;      ///< current status of antenna, see ::ANT_STATUS_CODES
752f63afe2cy  TM_GPS tm_disconn;   ///< time of antenna disconnect
753f63afe2cy  TM_GPS tm_reconn;    ///< time of antenna reconnect
754f63afe2cy  int32_t delta_t;     ///< clock offs at reconn. time in 1/::RECEIVER_INFO::ticks_per_sec units
755ef64b99roberto
756f63afe2cy} ANT_INFO;
757ef64b99roberto
758ef64b99roberto
759f63afe2cy/**
760f63afe2cy * @brief Status code used with ::ANT_INFO::status
761f63afe2cy */
762f63afe2cyenum ANT_STATUS_CODES
763f63afe2cy{
764f63afe2cy  ANT_INVALID,   ///< No other fields valid since antenna has not yet been disconnected
765f63afe2cy  ANT_DISCONN,   ///< Antenna is disconnected, tm_reconn and delta_t not yet set
766f63afe2cy  ANT_RECONN,    ///< Antenna has been disconnect, and receiver sync. after reconnect, so all fields valid
767f63afe2cy  N_ANT_STATUS_CODES  ///< the number of known status codes
768f63afe2cy};
769ef64b99roberto
770ef64b99roberto
771ef64b99roberto
772f63afe2cy/**
773f63afe2cy * @brief Summary of configuration and health data of all satellites
774f63afe2cy */
775f63afe2cytypedef struct
776f63afe2cy{
777f63afe2cy  CSUM csum;                  ///< checksum of the remaining bytes
778f63afe2cy  int16_t valid;              ///< flag data are valid
779f63afe2cy
780f63afe2cy  T_GPS tot_51;               ///< time of transmission, page 51
781f63afe2cy  T_GPS tot_63;               ///< time of transmission, page 63
782f63afe2cy  T_GPS t0a;                  ///< complete reference time almanac
783f63afe2cy
784f63afe2cy  CFG cfg[N_SVNO_GPS];        ///< 4 bit SV configuration code from page 63
785f63afe2cy  HEALTH health[N_SVNO_GPS];  ///< 6 bit SV health codes from pages 51, 63
786f63afe2cy
787f63afe2cy} CFGH;
788f63afe2cy
789ef64b99roberto
790ef64b99roberto
791f63afe2cy/**
792f63afe2cy * @brief GPS %UTC correction parameters
793f63afe2cy *
794f63afe2cy * %UTC correction parameters basically as sent by the GPS satellites.
795f63afe2cy *
796f63afe2cy * The csum field is only used by the card's firmware to check the
797f63afe2cy * consistency of the structure in non-volatile memory.
798f63afe2cy *
799f63afe2cy * The field labeled valid indicates if the parameter set is valid, i.e.
800f63afe2cy * if it contains data received from the satellites.
801f63afe2cy *
802f63afe2cy * t0t, A0 and A1 contain fractional correction parameters for the current
803f63afe2cy * GPS-%UTC time offset in addition to the whole seconds. This is evaluated
804f63afe2cy * by the receivers' firmware to convert GPS time to %UTC time.
805f63afe2cy *
806f63afe2cy * The delta_tls field contains the current full seconds offset between
807f63afe2cy * GPS time and %UTC, which corresponds to the number of leap seconds inserted
808f63afe2cy * into the %UTC time scale since GPS was put into operation in January 1980.
809f63afe2cy *
810f63afe2cy * delta_tlfs holds the number of "future" leap seconds, i.e. the %UTC offset
811f63afe2cy * after the next leap second event defined by WNlsf and DNt.
812f63afe2cy *
813f63afe2cy * The fields WNlsf and DNt specify the GPS week number and the day number
814f63afe2cy * in that week for the end of which a leap second has been scheduled.
815f63afe2cy *
816f63afe2cy * @note: The satellites transmit WNlsf only as a signed 8 bit value, so it
817f63afe2cy * can only define a point in time which is +/- 127 weeks off the current time.
818f63afe2cy * The firmware tries to expand this based on the current week number, but
819f63afe2cy * the result is ambiguous if the leap second occurs or occurred more
820f63afe2cy * than 127 weeks in the future or past.
821f63afe2cy *
822f63afe2cy * So the leap second date should <b>only</b> be evaluated and displayed
823f63afe2cy * in a user interface if the fields delta_tls and delta_tlsf have
824f63afe2cy * different values, in which case there is indeed a leap second announcement
825f63afe2cy * inside the +/- 127 week range.
826f63afe2cy *
827f63afe2cy * @note In the original code the type of A0 and A1 is double.
828f63afe2cy */
829f63afe2cytypedef struct
830f63afe2cy{
831f63afe2cy  CSUM csum;          ///<  Checksum of the remaining bytes
832f63afe2cy  int16_t valid;      ///<  Flag indicating %UTC parameters are valid
833ef64b99roberto
834f63afe2cy  T_GPS t0t;          ///<  Reference Time %UTC Parameters [wn|sec]
835f63afe2cy  l_fp A0;            ///<  +- Clock Correction Coefficient 0 [sec]
836f63afe2cy  l_fp A1;            ///<  +- Clock Correction Coefficient 1 [sec/sec]
837ef64b99roberto
838f63afe2cy  uint16_t WNlsf;     ///<  Week number of nearest leap second
839f63afe2cy  int16_t DNt;        ///<  The day number at the end of which a leap second occurs
840f63afe2cy  int8_t delta_tls;   ///<  Current %UTC offset to GPS system time [sec]
841f63afe2cy  int8_t delta_tlsf;  ///<  Future %UTC offset to GPS system time after next leap second transition [sec]
842ef64b99roberto
843f63afe2cy} UTC;
844ef64b99roberto
845ef64b99roberto
846f63afe2cy/**
847f63afe2cy * @brief GPS ASCII message
848f63afe2cy */
849f63afe2cytypedef struct
850f63afe2cy{
851f63afe2cy  CSUM csum;       ///< checksum of the remaining bytes */
852f63afe2cy  int16_t valid;   ///< flag data are valid
853f63afe2cy  char s[23];      ///< 22 chars GPS ASCII message plus trailing zero
854ef64b99roberto
855f63afe2cy} ASCII_MSG;
856ef64b99roberto
857ef64b99roberto
858f63afe2cy/**
859f63afe2cy * @brief Ephemeris parameters of one specific satellite
860f63afe2cy *
861f63afe2cy * Needed to compute the position of a satellite at a given time with
862f63afe2cy * high precision. Valid for an interval of 4 to 6 hours from start
863f63afe2cy * of transmission.
864f63afe2cy */
865f63afe2cytypedef struct
866f63afe2cy{
867f63afe2cy  CSUM csum;       ///<    checksum of the remaining bytes
868f63afe2cy  int16_t valid;   ///<    flag data are valid
869f63afe2cy
870f63afe2cy  HEALTH health;   ///<    health indication of transmitting SV      [---]
871f63afe2cy  IOD IODC;        ///<    Issue Of Data, Clock
872f63afe2cy  IOD IODE2;       ///<    Issue of Data, Ephemeris (Subframe 2)
873f63afe2cy  IOD IODE3;       ///<    Issue of Data, Ephemeris (Subframe 3)
874f63afe2cy  T_GPS tt;        ///<    time of transmission
875f63afe2cy  T_GPS t0c;       ///<    Reference Time Clock                      [---]
876f63afe2cy  T_GPS t0e;       ///<    Reference Time Ephemeris                  [---]
877f63afe2cy
878f63afe2cy  l_fp sqrt_A;     ///<    Square Root of semi-major Axis        [sqrt(m)]
879f63afe2cy  l_fp e;          ///<    Eccentricity                              [---]
880f63afe2cy  l_fp M0;         ///< +- Mean Anomaly at Ref. Time                 [rad]
881f63afe2cy  l_fp omega;      ///< +- Argument of Perigee                       [rad]
882f63afe2cy  l_fp OMEGA0;     ///< +- Longit. of Asc. Node of orbit plane       [rad]
883f63afe2cy  l_fp OMEGADOT;   ///< +- Rate of Right Ascension               [rad/sec]
884f63afe2cy  l_fp deltan;     ///< +- Mean Motion Diff. from computed value [rad/sec]
885f63afe2cy  l_fp i0;         ///< +- Inclination Angle                         [rad]
886f63afe2cy  l_fp idot;       ///< +- Rate of Inclination Angle             [rad/sec]
887f63afe2cy  l_fp crc;        ///< +- Cosine Corr. Term to Orbit Radius           [m]
888f63afe2cy  l_fp crs;        ///< +- Sine Corr. Term to Orbit Radius             [m]
889f63afe2cy  l_fp cuc;        ///< +- Cosine Corr. Term to Arg. of Latitude     [rad]
890f63afe2cy  l_fp cus;        ///< +- Sine Corr. Term to Arg. of Latitude       [rad]
891f63afe2cy  l_fp cic;        ///< +- Cosine Corr. Term to Inclination Angle    [rad]
892f63afe2cy  l_fp cis;        ///< +- Sine Corr. Term to Inclination Angle      [rad]
893f63afe2cy
894f63afe2cy  l_fp af0;        ///< +- Clock Correction Coefficient 0            [sec]
895f63afe2cy  l_fp af1;        ///< +- Clock Correction Coefficient 1        [sec/sec]
896f63afe2cy  l_fp af2;        ///< +- Clock Correction Coefficient 2      [sec/sec^2]
897f63afe2cy  l_fp tgd;        ///< +- estimated group delay differential        [sec]
898f63afe2cy
899f63afe2cy  uint16_t URA;    ///<    predicted User Range Accuracy
900f63afe2cy
901f63afe2cy  uint8_t L2code;  ///<    code on L2 channel                         [---]
902f63afe2cy  uint8_t L2flag;  ///<    L2 P data flag                             [---]
903ef64b99roberto
904ef64b99roberto} EPH;
905ef64b99roberto
906ef64b99roberto
907ef64b99roberto
908f63afe2cy/**
909f63afe2cy * @brief Almanac parameters of one specific satellite
910f63afe2cy *
911f63afe2cy * A reduced precision set of parameters used to check if a satellite
912f63afe2cy * is in view at a given time. Valid for an interval of more than 7 days
913f63afe2cy * from start of transmission.
914f63afe2cy */
915f63afe2cytypedef struct
916f63afe2cy{
917f63afe2cy  CSUM csum;       ///<    checksum of the remaining bytes
918f63afe2cy  int16_t valid;   ///<    flag data are valid
919f63afe2cy
920f63afe2cy  HEALTH health;   ///<                                               [---]
921f63afe2cy  T_GPS t0a;       ///<    Reference Time Almanac                     [sec]
922f63afe2cy
923f63afe2cy  l_fp sqrt_A;     ///<    Square Root of semi-major Axis         [sqrt(m)]
924f63afe2cy  l_fp e;          ///<    Eccentricity                               [---]
925ef64b99roberto
926f63afe2cy  l_fp M0;         ///< +- Mean Anomaly at Ref. Time                  [rad]
927f63afe2cy  l_fp omega;      ///< +- Argument of Perigee                        [rad]
928f63afe2cy  l_fp OMEGA0;     ///< +- Longit. of Asc. Node of orbit plane        [rad]
929f63afe2cy  l_fp OMEGADOT;   ///< +- Rate of Right Ascension                [rad/sec]
930f63afe2cy  l_fp deltai;     ///< +-                                            [rad]
931f63afe2cy  l_fp af0;        ///< +- Clock Correction Coefficient 0             [sec]
932f63afe2cy  l_fp af1;        ///< +- Clock Correction Coefficient 1         [sec/sec]
933ef64b99roberto
934ef64b99roberto} ALM;
935ef64b99roberto
936ef64b99roberto
937ef64b99roberto
938f63afe2cy/**
939f63afe2cy * @brief Ionospheric correction parameters
940f63afe2cy */
941f63afe2cytypedef struct
942f63afe2cy{
943f63afe2cy  CSUM csum;       ///<    checksum of the remaining bytes
944f63afe2cy  int16_t valid;   ///<    flag data are valid
945ef64b99roberto
946f63afe2cy  l_fp alpha_0;    ///<    Ionosph. Corr. Coeff. Alpha 0              [sec]
947f63afe2cy  l_fp alpha_1;    ///<    Ionosph. Corr. Coeff. Alpha 1          [sec/deg]
948f63afe2cy  l_fp alpha_2;    ///<    Ionosph. Corr. Coeff. Alpha 2        [sec/deg^2]
949f63afe2cy  l_fp alpha_3;    ///<    Ionosph. Corr. Coeff. Alpha 3        [sec/deg^3]
950ef64b99roberto
951f63afe2cy  l_fp beta_0;     ///<    Ionosph. Corr. Coeff. Beta 0               [sec]
952f63afe2cy  l_fp beta_1;     ///<    Ionosph. Corr. Coeff. Beta 1           [sec/deg]
953f63afe2cy  l_fp beta_2;     ///<    Ionosph. Corr. Coeff. Beta 2         [sec/deg^2]
954f63afe2cy  l_fp beta_3;     ///<    Ionosph. Corr. Coeff. Beta 3         [sec/deg^3]
955ef64b99roberto
956ef64b99roberto} IONO;
957ef64b99roberto
958f63afe2cy
959f63afe2cy
960f63afe2cyvoid mbg_tm_str (char **, TM_GPS *, int, int);
961d54cfbdrobertovoid mbg_tgps_str (char **, T_GPS *, int);
962d54cfbdrobertovoid get_mbg_header (unsigned char **, GPS_MSG_HDR *);
963d54cfbdrobertovoid put_mbg_header (unsigned char **, GPS_MSG_HDR *);
964d54cfbdrobertovoid get_mbg_sw_rev (unsigned char **, SW_REV *);
965d54cfbdrobertovoid get_mbg_ascii_msg (unsigned char **, ASCII_MSG *);
966d54cfbdrobertovoid get_mbg_svno (unsigned char **, SVNO *);
967d54cfbdrobertovoid get_mbg_health (unsigned char **, HEALTH *);
968d54cfbdrobertovoid get_mbg_cfg (unsigned char **, CFG *);
969d54cfbdrobertovoid get_mbg_tgps (unsigned char **, T_GPS *);
970f63afe2cyvoid get_mbg_tm (unsigned char **, TM_GPS *);
971d54cfbdrobertovoid get_mbg_ttm (unsigned char **, TTM *);
972d54cfbdrobertovoid get_mbg_synth (unsigned char **, SYNTH *);
973d54cfbdrobertovoid get_mbg_tzdl (unsigned char **, TZDL *);
974d54cfbdrobertovoid get_mbg_antinfo (unsigned char **, ANT_INFO *);
975d54cfbdrobertovoid get_mbg_cfgh (unsigned char **, CFGH *);
976d54cfbdrobertovoid get_mbg_utc (unsigned char **, UTC *);
977d54cfbdrobertovoid get_mbg_lla (unsigned char **, LLA);
978d54cfbdrobertovoid get_mbg_xyz (unsigned char **, XYZ);
979d54cfbdrobertovoid get_mbg_portparam (unsigned char **, PORT_PARM *);
980d54cfbdrobertovoid get_mbg_eph (unsigned char **, EPH *);
981d54cfbdrobertovoid get_mbg_alm (unsigned char **, ALM *);
982d54cfbdrobertovoid get_mbg_iono (unsigned char **, IONO *);
983d54cfbdroberto
984f63afe2cyCSUM mbg_csum (unsigned char *, unsigned int);
985ef64b99roberto
986ef64b99roberto#endif
987ef64b99roberto/*
9887a6072eroberto * History:
9897a6072eroberto *
990ef64b99roberto * mbg_gps166.h,v
9917a6072eroberto * Revision 4.7  2006/06/22 18:41:43  kardel
9927a6072eroberto * clean up signedness (gcc 4)
9937a6072eroberto *
9947a6072eroberto * Revision 4.6  2005/10/07 22:11:56  kardel
9957a6072eroberto * bounded buffer implementation
9967a6072eroberto *
9977a6072eroberto * Revision 4.5.2.1  2005/09/25 10:23:48  kardel
9987a6072eroberto * support bounded buffers
9997a6072eroberto *
10007a6072eroberto * Revision 4.5  2005/06/25 10:58:45  kardel
10017a6072eroberto * add missing log keywords
10027a6072eroberto *
1003ef64b99roberto * Revision 4.1  1998/06/12 15:07:30  kardel
1004ef64b99roberto * fixed prototyping
1005ef64b99roberto *
1006ef64b99roberto * Revision 4.0  1998/04/10 19:50:42  kardel
1007ef64b99roberto * Start 4.0 release version numbering
1008ef64b99roberto *
1009ef64b99roberto * Revision 1.1  1998/04/10 19:27:34  kardel
1010ef64b99roberto * initial NTP VERSION 4 integration of PARSE with GPS166 binary support
1011ef64b99roberto *
1012ef64b99roberto * Revision 1.1  1997/10/06 20:55:38  kardel
1013ef64b99roberto * new parse structure
1014ef64b99roberto *
1015ef64b99roberto */
1016