2 * $Id: refclock_ripencc.c,v 1.13 2002/06/18 14:20:55 marks Exp marks $
4 * Copyright (c) 2002 RIPE NCC
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted,
10 * provided that the above copyright notice appear in all copies and that
11 * both that copyright notice and this permission notice appear in
12 * supporting documentation, and that the name of the author not be
13 * used in advertising or publicity pertaining to distribution of the
14 * software without specific, written prior permission.
16 * THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
18 * AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
19 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
20 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * This driver was developed for use with the RIPE NCC TTM project.
28 * The initial driver was developed by Daniel Karrenberg <dfk@ripe.net>
29 * using the code made available by Trimble. This was for xntpd-3.x.x
31 * Rewrite of the driver for ntpd-4.x.x by Mark Santcroos <marks@ripe.net>
37 #endif /* HAVE_CONFIG_H */
39 #if defined(REFCLOCK) && defined(CLOCK_RIPENCC)
41 #include "ntp_stdlib.h"
43 #include "ntp_refclock.h"
44 #include "ntp_unixtime.h"
48 # include "ppsapi_timepps.h"
55 /* we are on little endian */
59 * DEBUG statements: uncomment if necessary
61 /* #define DEBUG_NCC */ /* general debug statements */
62 /* #define DEBUG_PPS */ /* debug pps */
63 /* #define DEBUG_RAW */ /* print raw packets */
65 #define TRIMBLE_OUTPUT_FUNC
66 #define TSIP_VERNUM "7.12a"
73 #define GPS_PI (3.1415926535898)
74 #define GPS_C (299792458.)
75 #define D2R (GPS_PI/180.0)
76 #define R2D (180.0/GPS_PI)
77 #define WEEK (604800.)
80 /* control characters for TSIP packets */
84 #define MAX_RPTBUF (256)
86 /* values of TSIPPKT.status */
87 #define TSIP_PARSED_EMPTY 0
88 #define TSIP_PARSED_FULL 1
89 #define TSIP_PARSED_DLE_1 2
90 #define TSIP_PARSED_DATA 3
91 #define TSIP_PARSED_DLE_2 4
93 #define UTCF_UTC_AVAIL (unsigned char) (1) /* UTC available */
94 #define UTCF_LEAP_SCHD (unsigned char) (1<<4) /* Leap scheduled */
95 #define UTCF_LEAP_PNDG (unsigned char) (1<<5) /* Leap pending, will occur at end of day */
97 #define DEVICE "/dev/gps%d" /* name of radio device */
98 #define PRECISION (-9) /* precision assumed (about 2 ms) */
99 #define PPS_PRECISION (-20) /* precision assumed (about 1 us) */
100 #define REFID "GPS\0" /* reference id */
102 #define DESCRIPTION "RIPE NCC GPS (Palisade)" /* Description */
103 #define SPEED232 B9600 /* 9600 baud */
105 #define NSAMPLES 3 /* stages of median filter */
109 /* TSIP packets have the following structure, whether report or command. */
112 counter, /* counter */
113 len; /* size of buf; < MAX_RPTBUF unsigned chars */
115 status, /* TSIP packet format/parse status */
116 code, /* TSIP code */
117 buf[MAX_RPTBUF]; /* report or command string */
120 /* TSIP binary data structures */
125 e, t_oa, i_0, OMEGADOT, sqrt_A,
126 OMEGA_0, omega, M_0, a_f0, a_f1,
127 Axis, n, OMEGA_n, ODOT_n, t_zc;
132 typedef struct { /* Almanac health page (25) parameters */
134 WN_a, SV_health[32], t_oa;
137 typedef struct { /* Universal Coordinated Time (UTC) parms */
147 WN_t, WN_LSF, DN, delta_t_LSF;
150 typedef struct { /* Ionospheric info (float) */
152 alpha_0, alpha_1, alpha_2, alpha_3,
153 beta_0, beta_1, beta_2, beta_3;
156 typedef struct { /* Subframe 1 info (float) */
160 codeL2, L2Pdata, SVacc_raw, SV_health;
164 T_GD, t_oc, a_f2, a_f1, a_f0, SVacc;
167 typedef struct { /* Ephemeris info (float) */
197 Axis, n, r1me2, OMEGA_n, ODOT_n;
200 typedef struct { /* Navigation data structure */
202 sv_number; /* SV number (0 = no entry) */
204 t_ephem; /* time of ephemeris collection */
206 ephclk; /* subframe 1 data */
208 ephorb; /* ephemeris data */
228 #ifdef TRIMBLE_OUTPUT_FUNC
230 *dayname[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},
231 old_baudnum[] = {0, 1, 4, 5, 6, 8, 9, 11, 28, 12},
232 *st_baud_text_app [] = {"", "", " 300", " 600", " 1200", " 2400",
233 " 4800", " 9600", "19200", "38400"},
234 *old_parity_text[] = {"EVEN", "ODD", "", "", "NONE"},
235 *parity_text [] = {"NONE", "ODD", "EVEN"},
236 *old_input_ch[] = { "TSIP", "RTCM (6 of 8 bits)"},
237 *old_output_ch[] = { "TSIP", "No output", "", "", "", "NMEA 0183"},
238 *protocols_in_text[] = { "", "TSIP", "", ""},
239 *protocols_out_text[] = { "", "TSIP", "NMEA"},
240 *rcvr_port_text [] = { "Port A ", "Port B ", "Current Port"},
241 *dyn_text [] = {"Unchanged", "Land", "Sea", "Air", "Static"},
242 *NavModeText0xBB[] = {"automatic", "time only (0-D)", "", "2-D",
243 "3-D", "", "", "OverDetermined Time"},
244 *PPSTimeBaseText[] = {"GPS", "UTC", "USER"},
245 *PPSPolarityText[] = {"Positive", "Negative"},
246 *MaskText[] = { "Almanac ", "Ephemeris", "UTC ", "Iono ",
247 "GPS Msg ", "Alm Hlth ", "Time Fix ", "SV Select",
248 "Ext Event", "Pos Fix ", "Raw Meas "};
250 #endif /* TRIMBLE_OUTPUT_FUNC */
253 * Unit control structure
255 struct ripencc_unit {
256 int unit; /* unit number */
257 int pollcnt; /* poll message counter */
258 int polled; /* Hand in a sample? */
259 char leapdelta; /* delta of next leap event */
260 unsigned char utcflags; /* delta of next leap event */
261 l_fp tstamp; /* timestamp of last poll */
263 struct timespec ts; /* last timestamp */
264 pps_params_t pps_params; /* pps parameters */
265 pps_info_t pps_info; /* last pps data */
266 pps_handle_t handle; /* pps handlebars */
271 /******************* PROTOYPES *****************/
273 /* prototypes for report parsing primitives */
274 short rpt_0x3D (TSIPPKT *rpt, unsigned char *tx_baud_index,
275 unsigned char *rx_baud_index, unsigned char *char_format_index,
276 unsigned char *stop_bits, unsigned char *tx_mode_index,
277 unsigned char *rx_mode_index);
278 short rpt_0x40 (TSIPPKT *rpt, unsigned char *sv_prn, short *week_num,
279 float *t_zc, float *eccentricity, float *t_oa, float *i_0,
280 float *OMEGA_dot, float *sqrt_A, float *OMEGA_0, float *omega,
282 short rpt_0x41 (TSIPPKT *rpt, float *time_of_week, float *UTC_offset,
284 short rpt_0x42 (TSIPPKT *rpt, float ECEF_pos[3], float *time_of_fix);
285 short rpt_0x43 (TSIPPKT *rpt, float ECEF_vel[3], float *freq_offset,
287 short rpt_0x45 (TSIPPKT *rpt, unsigned char *major_nav_version,
288 unsigned char *minor_nav_version, unsigned char *nav_day,
289 unsigned char *nav_month, unsigned char *nav_year,
290 unsigned char *major_dsp_version, unsigned char *minor_dsp_version,
291 unsigned char *dsp_day, unsigned char *dsp_month,
292 unsigned char *dsp_year);
293 short rpt_0x46 (TSIPPKT *rpt, unsigned char *status1, unsigned char *status2);
294 short rpt_0x47 (TSIPPKT *rpt, unsigned char *nsvs, unsigned char *sv_prn,
296 short rpt_0x48 (TSIPPKT *rpt, unsigned char *message);
297 short rpt_0x49 (TSIPPKT *rpt, unsigned char *sv_health);
298 short rpt_0x4A (TSIPPKT *rpt, float *lat, float *lon, float *alt,
299 float *clock_bias, float *time_of_fix);
300 short rpt_0x4A_2 (TSIPPKT *rpt, float *alt, float *dummy,
301 unsigned char *alt_flag);
302 short rpt_0x4B (TSIPPKT *rpt, unsigned char *machine_id,
303 unsigned char *status3, unsigned char *status4);
304 short rpt_0x4C (TSIPPKT *rpt, unsigned char *dyn_code, float *el_mask,
305 float *snr_mask, float *dop_mask, float *dop_switch);
306 short rpt_0x4D (TSIPPKT *rpt, float *osc_offset);
307 short rpt_0x4E (TSIPPKT *rpt, unsigned char *response);
308 short rpt_0x4F (TSIPPKT *rpt, double *a0, float *a1, float *time_of_data,
309 short *dt_ls, short *wn_t, short *wn_lsf, short *dn, short *dt_lsf);
310 short rpt_0x54 (TSIPPKT *rpt, float *clock_bias, float *freq_offset,
312 short rpt_0x55 (TSIPPKT *rpt, unsigned char *pos_code, unsigned char *vel_code,
313 unsigned char *time_code, unsigned char *aux_code);
314 short rpt_0x56 (TSIPPKT *rpt, float vel_ENU[3], float *freq_offset,
316 short rpt_0x57 (TSIPPKT *rpt, unsigned char *source_code,
317 unsigned char *diag_code, short *week_num, float *time_of_fix);
318 short rpt_0x58 (TSIPPKT *rpt, unsigned char *op_code, unsigned char *data_type,
319 unsigned char *sv_prn, unsigned char *data_length,
320 unsigned char *data_packet);
321 short rpt_0x59 (TSIPPKT *rpt, unsigned char *code_type,
322 unsigned char status_code[32]);
323 short rpt_0x5A (TSIPPKT *rpt, unsigned char *sv_prn, float *sample_length,
324 float *signal_level, float *code_phase, float *Doppler,
325 double *time_of_fix);
326 short rpt_0x5B (TSIPPKT *rpt, unsigned char *sv_prn, unsigned char *sv_health,
327 unsigned char *sv_iode, unsigned char *fit_interval_flag,
328 float *time_of_collection, float *time_of_eph, float *sv_accy);
329 short rpt_0x5C (TSIPPKT *rpt, unsigned char *sv_prn, unsigned char *slot,
330 unsigned char *chan, unsigned char *acq_flag, unsigned char *eph_flag,
331 float *signal_level, float *time_of_last_msmt, float *elev,
332 float *azim, unsigned char *old_msmt_flag,
333 unsigned char *integer_msec_flag, unsigned char *bad_data_flag,
334 unsigned char *data_collect_flag);
335 short rpt_0x6D (TSIPPKT *rpt, unsigned char *manual_mode, unsigned char *nsvs,
336 unsigned char *ndim, unsigned char sv_prn[], float *pdop,
337 float *hdop, float *vdop, float *tdop);
338 short rpt_0x82 (TSIPPKT *rpt, unsigned char *diff_mode);
339 short rpt_0x83 (TSIPPKT *rpt, double ECEF_pos[3], double *clock_bias,
341 short rpt_0x84 (TSIPPKT *rpt, double *lat, double *lon, double *alt,
342 double *clock_bias, float *time_of_fix);
343 short rpt_Paly0xBB(TSIPPKT *rpt, TSIP_RCVR_CFG *TsipxBB);
344 short rpt_0xBC (TSIPPKT *rpt, unsigned char *port_num,
345 unsigned char *in_baud, unsigned char *out_baud,
346 unsigned char *data_bits, unsigned char *parity,
347 unsigned char *stop_bits, unsigned char *flow_control,
348 unsigned char *protocols_in, unsigned char *protocols_out,
349 unsigned char *reserved);
351 /* prototypes for superpacket parsers */
353 short rpt_0x8F0B (TSIPPKT *rpt, unsigned short *event, double *tow,
354 unsigned char *date, unsigned char *month, short *year,
355 unsigned char *dim_mode, short *utc_offset, double *bias, double *drift,
356 float *bias_unc, float *dr_unc, double *lat, double *lon, double *alt,
358 short rpt_0x8F14 (TSIPPKT *rpt, short *datum_idx, double datum_coeffs[5]);
359 short rpt_0x8F15 (TSIPPKT *rpt, short *datum_idx, double datum_coeffs[5]);
360 short rpt_0x8F20 (TSIPPKT *rpt, unsigned char *info, double *lat,
361 double *lon, double *alt, double vel_enu[], double *time_of_fix,
362 short *week_num, unsigned char *nsvs, unsigned char sv_prn[],
363 short sv_IODC[], short *datum_index);
364 short rpt_0x8F41 (TSIPPKT *rpt, unsigned char *bSearchRange,
365 unsigned char *bBoardOptions, unsigned long *iiSerialNumber,
366 unsigned char *bBuildYear, unsigned char *bBuildMonth,
367 unsigned char *bBuildDay, unsigned char *bBuildHour,
368 float *fOscOffset, unsigned short *iTestCodeId);
369 short rpt_0x8F42 (TSIPPKT *rpt, unsigned char *bProdOptionsPre,
370 unsigned char *bProdNumberExt, unsigned short *iCaseSerialNumberPre,
371 unsigned long *iiCaseSerialNumber, unsigned long *iiProdNumber,
372 unsigned short *iPremiumOptions, unsigned short *iMachineID,
373 unsigned short *iKey);
374 short rpt_0x8F45 (TSIPPKT *rpt, unsigned char *bSegMask);
375 short rpt_0x8F4A_16 (TSIPPKT *rpt, unsigned char *pps_enabled,
376 unsigned char *pps_timebase, unsigned char *pos_polarity,
377 double *pps_offset, float *bias_unc_threshold);
378 short rpt_0x8F4B (TSIPPKT *rpt, unsigned long *decorr_max);
379 short rpt_0x8F4D (TSIPPKT *rpt, unsigned long *event_mask);
380 short rpt_0x8FA5 (TSIPPKT *rpt, unsigned char *spktmask);
381 short rpt_0x8FAD (TSIPPKT *rpt, unsigned short *COUNT, double *FracSec,
382 unsigned char *Hour, unsigned char *Minute, unsigned char *Second,
383 unsigned char *Day, unsigned char *Month, unsigned short *Year,
384 unsigned char *Status, unsigned char *Flags);
387 /* prototypes for command-encode primitives with suffix convention: */
388 /* c = clear, s = set, q = query, e = enable, d = disable */
389 void cmd_0x1F (TSIPPKT *cmd);
390 void cmd_0x26 (TSIPPKT *cmd);
391 void cmd_0x2F (TSIPPKT *cmd);
392 void cmd_0x35s (TSIPPKT *cmd, unsigned char pos_code, unsigned char vel_code,
393 unsigned char time_code, unsigned char opts_code);
394 void cmd_0x3C (TSIPPKT *cmd, unsigned char sv_prn);
395 void cmd_0x3Ds (TSIPPKT *cmd, unsigned char baud_out, unsigned char baud_inp,
396 unsigned char char_code, unsigned char stopbitcode,
397 unsigned char output_mode, unsigned char input_mode);
398 void cmd_0xBBq (TSIPPKT *cmd, unsigned char subcode) ;
400 /* prototypes 8E commands */
401 void cmd_0x8E0Bq (TSIPPKT *cmd);
402 void cmd_0x8E41q (TSIPPKT *cmd);
403 void cmd_0x8E42q (TSIPPKT *cmd);
404 void cmd_0x8E4Aq (TSIPPKT *cmd);
405 void cmd_0x8E4As (TSIPPKT *cmd, unsigned char PPSOnOff, unsigned char TimeBase,
406 unsigned char Polarity, double PPSOffset, float Uncertainty);
407 void cmd_0x8E4Bq (TSIPPKT *cmd);
408 void cmd_0x8E4Ds (TSIPPKT *cmd, unsigned long AutoOutputMask);
409 void cmd_0x8EADq (TSIPPKT *cmd);
411 /* header/source border XXXXXXXXXXXXXXXXXXXXXXXXXX */
413 /* Trimble parse functions */
414 static int parse0x8FAD (TSIPPKT *, struct peer *);
415 static int parse0x8F0B (TSIPPKT *, struct peer *);
416 #ifdef TRIMBLE_OUTPUT_FUNC
417 static int parseany (TSIPPKT *, struct peer *);
418 static void TranslateTSIPReportToText (TSIPPKT *, char *);
419 #endif /* TRIMBLE_OUTPUT_FUNC */
420 static int parse0x5C (TSIPPKT *, struct peer *);
421 static int parse0x4F (TSIPPKT *, struct peer *);
422 static void tsip_input_proc (TSIPPKT *, int);
424 /* Trimble helper functions */
425 static void bPutFloat (float *, unsigned char *);
426 static void bPutDouble (double *, unsigned char *);
427 static void bPutULong (unsigned long *, unsigned char *);
428 static int print_msg_table_header (int rptcode, char *HdrStr, int force);
429 static char * show_time (float time_of_week);
431 /* RIPE NCC functions */
432 static void ripencc_control (int, const struct refclockstat *,
433 struct refclockstat *, struct peer *);
434 static int ripencc_ppsapi (struct peer *, int, int);
435 static int ripencc_get_pps_ts (struct ripencc_unit *, l_fp *);
436 static int ripencc_start (int, struct peer *);
437 static void ripencc_shutdown (int, struct peer *);
438 static void ripencc_poll (int, struct peer *);
439 static void ripencc_send (struct peer *, TSIPPKT spt);
440 static void ripencc_receive (struct recvbuf *);
442 /* fill in reflock structure for our clock */
443 struct refclock refclock_ripencc = {
444 ripencc_start, /* start up driver */
445 ripencc_shutdown, /* shut down driver */
446 ripencc_poll, /* transmit poll message */
447 ripencc_control, /* control function */
448 noentry, /* initialize driver */
449 noentry, /* debug info */
450 NOFLAGS /* clock flags */
454 * Tables to compute the ddd of year form icky dd/mm timecode. Viva la
457 static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
458 static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
462 * ripencc_start - open the GPS devices and initialize data for processing
465 ripencc_start(int unit, struct peer *peer)
467 register struct ripencc_unit *up;
468 struct refclockproc *pp;
479 (void)snprintf(device, sizeof(device), DEVICE, unit);
480 fd = refclock_open(device, SPEED232, LDISC_RAW);
488 /* from refclock_palisade.c */
489 if (tcgetattr(fd, &tio) < 0) {
490 msyslog(LOG_ERR, "Palisade(%d) tcgetattr(fd, &tio): %m",unit);
497 tio.c_cflag |= (PARENB|PARODD);
498 tio.c_iflag &= ~ICRNL;
499 if (tcsetattr(fd, TCSANOW, &tio) == -1) {
500 msyslog(LOG_ERR, "Palisade(%d) tcsetattr(fd, &tio): %m",unit);
505 * Allocate and initialize unit structure
507 up = emalloc_zero(sizeof(*up));
509 pp->io.clock_recv = ripencc_receive;
510 pp->io.srcclock = peer;
512 if (!io_addclock(&pp->io)) {
521 * Initialize miscellaneous variables
523 peer->precision = PRECISION;
524 pp->clockdesc = DESCRIPTION;
525 memcpy((char *)&pp->refid, REFID, REFID_LEN);
532 * Initialize the Clock
535 /* query software versions */
537 ripencc_send(peer, spt);
539 /* query receiver health */
541 ripencc_send(peer, spt);
543 /* query serial numbers */
545 ripencc_send(peer, spt);
547 /* query manuf params */
549 ripencc_send(peer, spt);
551 /* i/o opts */ /* trimble manual page A30 */
556 0x0a); /* auxilary */
557 ripencc_send(peer, spt);
559 /* turn off port A */
563 0x07, /* char_code */
564 0x07, /* stopbitcode */
565 0x01, /* output_mode */
566 0x00); /* input_mode */
567 ripencc_send(peer, spt);
569 /* set i/o options */
572 0x01, /* Timebase UTC */
573 0x00, /* polarity positive */
574 0., /* 100 ft. cable XXX make flag */
575 1e-6 * GPS_C); /* turn of biasuncert. > (1us) */
576 ripencc_send(peer,spt);
578 /* all outomatic packet output off */
580 0x00000000); /* AutoOutputMask */
581 ripencc_send(peer, spt);
584 0x00); /* query primary configuration */
585 ripencc_send(peer,spt);
588 /* query PPS parameters */
589 cmd_0x8E4Aq (&spt); /* query PPS params */
590 ripencc_send(peer,spt);
592 /* query survey limit */
593 cmd_0x8E4Bq (&spt); /* query survey limit */
594 ripencc_send(peer,spt);
598 printf("ripencc_start: success\n");
599 #endif /* DEBUG_NCC */
602 * Start the PPSAPI interface if it is there. Default to use
603 * the assert edge and do not enable the kernel hardpps.
605 if (time_pps_create(fd, &up->handle) < 0) {
607 msyslog(LOG_ERR, "refclock_ripencc: time_pps_create failed: %m");
611 return(ripencc_ppsapi(peer, 0, 0));
615 * ripencc_control - fudge control
619 int unit, /* unit (not used) */
620 const struct refclockstat *in, /* input parameters (not used) */
621 struct refclockstat *out, /* output parameters (not used) */
622 struct peer *peer /* peer structure pointer */
625 struct refclockproc *pp;
628 msyslog(LOG_INFO,"%s()",__FUNCTION__);
629 #endif /* DEBUG_NCC */
632 ripencc_ppsapi(peer, pp->sloppyclockflag & CLK_FLAG2,
633 pp->sloppyclockflag & CLK_FLAG3);
642 struct peer *peer, /* peer structure pointer */
643 int enb_clear, /* clear enable */
644 int enb_hardpps /* hardpps enable */
647 struct refclockproc *pp;
648 struct ripencc_unit *up;
653 if (time_pps_getcap(up->handle, &capability) < 0) {
655 "refclock_ripencc: time_pps_getcap failed: %m");
658 memset(&up->pps_params, 0, sizeof(pps_params_t));
660 up->pps_params.mode = capability & PPS_CAPTURECLEAR;
662 up->pps_params.mode = capability & PPS_CAPTUREASSERT;
663 if (!up->pps_params.mode) {
665 "refclock_ripencc: invalid capture edge %d",
669 up->pps_params.mode |= PPS_TSFMT_TSPEC;
670 if (time_pps_setparams(up->handle, &up->pps_params) < 0) {
672 "refclock_ripencc: time_pps_setparams failed: %m");
676 if (time_pps_kcbind(up->handle, PPS_KC_HARDPPS,
677 up->pps_params.mode & ~PPS_TSFMT_TSPEC,
678 PPS_TSFMT_TSPEC) < 0) {
680 "refclock_ripencc: time_pps_kcbind failed: %m");
685 peer->precision = PPS_PRECISION;
689 time_pps_getparams(up->handle, &up->pps_params);
691 "refclock_ripencc: capability 0x%x version %d mode 0x%x kern %d\n",
692 capability, up->pps_params.api_version,
693 up->pps_params.mode, enb_hardpps);
695 #endif /* DEBUG_NCC */
701 * This function is called every 64 seconds from ripencc_receive
702 * It will fetch the pps time
704 * Return 0 on failure and 1 on success.
708 struct ripencc_unit *up,
713 struct timespec timeout, ts;
718 msyslog(LOG_INFO,"ripencc_get_pps_ts");
719 #endif /* DEBUG_PPS */
723 * Convert the timespec nanoseconds field to ntp l_fp units.
729 memcpy(&pps_info, &up->pps_info, sizeof(pps_info_t));
730 if (time_pps_fetch(up->handle, PPS_TSFMT_TSPEC, &up->pps_info,
733 if (up->pps_params.mode & PPS_CAPTUREASSERT) {
734 if (pps_info.assert_sequence ==
735 up->pps_info.assert_sequence)
737 ts = up->pps_info.assert_timestamp;
738 } else if (up->pps_params.mode & PPS_CAPTURECLEAR) {
739 if (pps_info.clear_sequence ==
740 up->pps_info.clear_sequence)
742 ts = up->pps_info.clear_timestamp;
746 if ((up->ts.tv_sec == ts.tv_sec) && (up->ts.tv_nsec == ts.tv_nsec))
750 tstmp.l_ui = ts.tv_sec + JAN_1970;
751 dtemp = ts.tv_nsec * FRAC / 1e9;
752 tstmp.l_uf = (u_int32)dtemp;
755 msyslog(LOG_INFO,"ts.tv_sec: %d",(int)ts.tv_sec);
756 msyslog(LOG_INFO,"ts.tv_nsec: %ld",ts.tv_nsec);
757 #endif /* DEBUG_PPS */
764 * ripencc_shutdown - shut down a GPS clock
767 ripencc_shutdown(int unit, struct peer *peer)
769 register struct ripencc_unit *up;
770 struct refclockproc *pp;
777 time_pps_destroy(up->handle);
781 io_closeclock(&pp->io);
787 * ripencc_poll - called by the transmit procedure
790 ripencc_poll(int unit, struct peer *peer)
792 register struct ripencc_unit *up;
793 struct refclockproc *pp;
798 fprintf(stderr, "ripencc_poll(%d)\n", unit);
799 #endif /* DEBUG_NCC */
802 if (up->pollcnt == 0)
803 refclock_report(peer, CEVNT_TIMEOUT);
810 /* poll for UTC superpacket */
812 ripencc_send(peer,spt);
816 * ripencc_send - send message to clock
817 * use the structures being created by the trimble functions!
818 * makes the code more readable/clean
821 ripencc_send(struct peer *peer, TSIPPKT spt)
823 unsigned char *ip, *op;
824 unsigned char obuf[512];
828 register struct ripencc_unit *up;
829 register struct refclockproc *pp;
834 printf("ripencc_send(%d, %02X)\n", up->unit, cmd);
836 #endif /* DEBUG_RAW */
845 if (op-obuf > sizeof(obuf)-5) {
846 msyslog(LOG_ERR, "ripencc_send obuf overflow!");
847 refclock_report(peer, CEVNT_FAULT);
851 if (*ip == 0x10) /* byte stuffing */
860 if (debug) { /* print raw packet */
864 printf("ripencc_send: len %d\n", op-obuf);
865 for (i=1, cp=obuf; cp<op; i++, cp++) {
866 printf(" %02X", *cp);
872 #endif /* DEBUG_RAW */
874 if (write(peer->procptr->io.fd, obuf, op-obuf) == -1) {
875 refclock_report(peer, CEVNT_FAULT);
882 * called when a packet is received on the serial port
883 * takes care of further processing
887 ripencc_receive(struct recvbuf *rbufp)
889 register struct ripencc_unit *up;
890 register struct refclockproc *pp;
892 static TSIPPKT rpt; /* for current incoming TSIP report */
893 TSIPPKT spt; /* send packet */
897 /* these variables hold data until we decide it's worth keeping */
898 char rd_lastcode[BMAX];
902 /* msyslog(LOG_INFO, "%s",__FUNCTION__); */
905 * Initialize pointers and read the timecode and timestamp
907 peer = rbufp->recv_peer;
910 rd_lencode = refclock_gtlin(rbufp, rd_lastcode, BMAX, &rd_tmp);
914 fprintf(stderr, "ripencc_receive(%d)\n", up->unit);
915 #endif /* DEBUG_RAW */
918 if (debug) { /* print raw packet */
922 printf("ripencc_receive: len %d\n", rbufp->recv_length);
923 for (i=1, cp=(char*)&rbufp->recv_space;
924 i <= rbufp->recv_length;
926 printf(" %02X", *cp);
932 #endif /* DEBUG_RAW */
934 cp = (char*) &rbufp->recv_space;
935 i=rbufp->recv_length;
937 while (i--) { /* loop over received chars */
939 tsip_input_proc(&rpt, (unsigned char) *cp++);
941 if (rpt.status != TSIP_PARSED_FULL)
946 case 0x8F: /* superpacket */
948 switch (rpt.buf[0]) {
950 case 0xAD: /* UTC Time */
952 ** When polling on port B the timecode is
953 ** the time of the previous PPS. If we
954 ** completed receiving the packet less than
955 ** 150ms after the turn of the second, it
956 ** may have the code of the previous second.
957 ** We do not trust that and simply poll
958 ** again without even parsing it.
960 ** More elegant would be to re-schedule the
961 ** poll, but I do not know (yet) how to do
965 /* BLA ns_since_pps = ncc_tstmp(rbufp, &trtmp); */
966 /* if (up->polled && ns_since_pps > -1 && ns_since_pps < 150) { */
969 if (up->polled && ns_since_pps < 150) {
970 msyslog(LOG_INFO, "%s(): up->polled",
972 ripencc_poll(up->unit, peer);
977 * Parse primary utc time packet
978 * and fill refclock structure
981 if (parse0x8FAD(&rpt, peer) < 0) {
982 msyslog(LOG_INFO, "%s(): parse0x8FAD < 0",__FUNCTION__);
983 refclock_report(peer, CEVNT_BADREPLY);
987 * If the PPSAPI is working, rather use its
989 * assume that the PPS occurs on the second
992 if (ripencc_get_pps_ts(up, &rd_tmp) == 1) {
993 pp->lastrec = up->tstamp = rd_tmp;
997 msyslog(LOG_INFO, "%s(): ripencc_get_pps_ts returns failure",__FUNCTION__);
1001 msyslog(LOG_INFO, "%s(): unrequested packet",__FUNCTION__);
1002 /* unrequested packet */
1006 /* we have been polled ! */
1010 /* poll for next packet */
1012 ripencc_send(peer,spt);
1014 if (ns_since_pps < 0) { /* no PPS */
1015 msyslog(LOG_INFO, "%s(): ns_since_pps < 0",__FUNCTION__);
1016 refclock_report(peer, CEVNT_BADTIME);
1021 ** Process the new sample in the median
1022 ** filter and determine the reference clock
1023 ** offset and dispersion.
1025 if (!refclock_process(pp)) {
1026 msyslog(LOG_INFO, "%s(): !refclock_process",__FUNCTION__);
1027 refclock_report(peer, CEVNT_BADTIME);
1031 refclock_receive(peer);
1034 case 0x0B: /* comprehensive time packet */
1035 parse0x8F0B(&rpt, peer);
1038 default: /* other superpackets */
1040 msyslog(LOG_INFO, "%s(): calling parseany",
1042 #endif /* DEBUG_NCC */
1043 #ifdef TRIMBLE_OUTPUT_FUNC
1044 parseany(&rpt, peer);
1045 #endif /* TRIMBLE_OUTPUT_FUNC */
1050 case 0x4F: /* UTC parameters, for leap info */
1051 parse0x4F(&rpt, peer);
1054 case 0x5C: /* sat tracking data */
1055 parse0x5C(&rpt, peer);
1058 default: /* other packets */
1059 #ifdef TRIMBLE_OUTPUT_FUNC
1060 parseany(&rpt, peer);
1061 #endif /* TRIMBLE_OUTPUT_FUNC */
1064 rpt.status = TSIP_PARSED_EMPTY;
1069 * All trimble functions that are directly referenced from driver code
1070 * (so not from parseany)
1073 /* request software versions */
1083 /* request receiver health */
1093 /* request UTC params */
1103 /* set serial I/O options */
1107 unsigned char pos_code,
1108 unsigned char vel_code,
1109 unsigned char time_code,
1110 unsigned char opts_code
1113 cmd->buf[0] = pos_code;
1114 cmd->buf[1] = vel_code;
1115 cmd->buf[2] = time_code;
1116 cmd->buf[3] = opts_code;
1121 /* request tracking status */
1125 unsigned char sv_prn
1128 cmd->buf[0] = sv_prn;
1133 /* set Channel A configuration for dual-port operation */
1137 unsigned char baud_out,
1138 unsigned char baud_inp,
1139 unsigned char char_code,
1140 unsigned char stopbitcode,
1141 unsigned char output_mode,
1142 unsigned char input_mode
1145 cmd->buf[0] = baud_out; /* XMT baud rate */
1146 cmd->buf[1] = baud_inp; /* RCV baud rate */
1147 cmd->buf[2] = char_code; /* parity and #bits per byte */
1148 cmd->buf[3] = stopbitcode; /* number of stop bits code */
1149 cmd->buf[4] = output_mode; /* Ch. A transmission mode */
1150 cmd->buf[5] = input_mode; /* Ch. A reception mode */
1156 /* query primary configuration */
1160 unsigned char subcode
1165 cmd->buf[0] = subcode;
1169 /**** Superpackets ****/
1170 /* 8E-0B to query 8F-0B controls */
1182 /* 8F-41 to query board serial number */
1194 /* 8F-42 to query product serial number */
1206 /* 8F-4A to query PPS parameters */
1218 /* set i/o options */
1222 unsigned char PPSOnOff,
1223 unsigned char TimeBase,
1224 unsigned char Polarity,
1232 cmd->buf[1] = PPSOnOff;
1233 cmd->buf[2] = TimeBase;
1234 cmd->buf[3] = Polarity;
1235 bPutDouble (&PPSOffset, &cmd->buf[4]);
1236 bPutFloat (&Uncertainty, &cmd->buf[12]);
1239 /* 8F-4B query survey limit */
1250 /* poll for UTC superpacket */
1251 /* 8E-AD to query 8F-AD controls */
1262 /* all outomatic packet output off */
1266 unsigned long AutoOutputMask
1272 bPutULong (&AutoOutputMask, &cmd->buf[1]);
1277 * for DOS machines, reverse order of bytes as they come through the
1287 unsigned char *optr;
1289 optr = (unsigned char*)&outval + 1;
1295 #ifdef TRIMBLE_OUTPUT_FUNC
1296 static unsigned short
1301 unsigned short outval;
1302 unsigned char *optr;
1304 optr = (unsigned char*)&outval + 1;
1316 unsigned char *optr;
1318 optr = (unsigned char*)&outval + 3;
1326 static unsigned long
1331 unsigned long outval;
1332 unsigned char *optr;
1334 optr = (unsigned char*)&outval + 3;
1341 #endif /* TRIMBLE_OUTPUT_FUNC */
1349 unsigned char *optr;
1351 optr = (unsigned char*)&outval + 3;
1365 unsigned char *optr;
1367 optr = (unsigned char*)&outval + 7;
1379 #else /* not BYTESWAP */
1381 #define bGetShort(bp) (*(short*)(bp))
1382 #define bGetLong(bp) (*(long*)(bp))
1383 #define bGetULong(bp) (*(unsigned long*)(bp))
1384 #define bGetSingle(bp) (*(float*)(bp))
1385 #define bGetDouble(bp) (*(double*)(bp))
1387 #endif /* BYTESWAP */
1389 * Byte-reversal is necessary for little-endian (Intel-based) machines.
1390 * TSIP streams are Big-endian (Motorola-based).
1400 unsigned char *inptr;
1402 inptr = (unsigned char*)in + 3;
1415 unsigned char *inptr;
1417 inptr = (unsigned char*)in + 3;
1430 unsigned char *inptr;
1432 inptr = (unsigned char*)in + 7;
1443 #else /* not BYTESWAP */
1445 void bPutShort (short a, unsigned char *cmdbuf) {*(short*) cmdbuf = a;}
1446 void bPutULong (long a, unsigned char *cmdbuf) {*(long*) cmdbuf = a;}
1447 void bPutFloat (float a, unsigned char *cmdbuf) {*(float*) cmdbuf = a;}
1448 void bPutDouble (double a, unsigned char *cmdbuf){*(double*) cmdbuf = a;}
1450 #endif /* BYTESWAP */
1453 * Parse primary utc time packet
1454 * and fill refclock structure
1467 register struct refclockproc *pp;
1468 register struct ripencc_unit *up;
1470 unsigned day, month, year; /* data derived from received timecode */
1471 unsigned hour, minute, second;
1472 unsigned char trackstat, utcflags;
1474 static char logbuf[1024]; /* logging string buffer */
1484 if (bGetShort(&buf[1]) != 0) {
1487 printf("parse0x8FAD: event count != 0\n");
1488 #endif /* DEBUG_NCC */
1492 if (bGetDouble(&buf[3]) != 0.0) {
1495 printf("parse0x8FAD: fracsecs != 0\n");
1496 #endif /* DEBUG_NCC */
1500 hour = (unsigned int) buf[11];
1501 minute = (unsigned int) buf[12];
1502 second = (unsigned int) buf[13];
1503 day = (unsigned int) buf[14];
1504 month = (unsigned int) buf[15];
1505 year = bGetShort(&buf[16]);
1506 trackstat = buf[18];
1510 sprintf(logbuf, "U1 %d.%d.%d %02d:%02d:%02d %d %02x",
1511 day, month, year, hour, minute, second, trackstat, utcflags);
1516 #endif /* DEBUG_NCC */
1518 record_clock_stats(&peer->srcadr, logbuf);
1520 if (!utcflags & UTCF_UTC_AVAIL)
1523 /* poll for UTC parameters once and then if UTC flag changed */
1524 up = (struct ripencc_unit *) pp->unitptr;
1525 if (utcflags != up->utcflags) {
1526 TSIPPKT spt; /* local structure for send packet */
1527 cmd_0x2F (&spt); /* request UTC params */
1528 ripencc_send(peer,spt);
1529 up->utcflags = utcflags;
1533 * If we hit the leap second, we choose to skip this sample
1534 * rather than rely on other code to be perfectly correct.
1535 * No offense, just defense ;-).
1540 /* now check and convert the time we received */
1543 if (month < 1 || month > 12 || day < 1 || day > 31)
1546 if (pp->year % 4) { /* XXX: use is_leapyear() ? */
1547 if (day > day1tab[month - 1])
1549 for (i = 0; i < month - 1; i++)
1552 if (day > day2tab[month - 1])
1554 for (i = 0; i < month - 1; i++)
1559 pp->minute = minute;
1560 pp-> second = second;
1563 if ((utcflags&UTCF_LEAP_PNDG) && up->leapdelta != 0)
1564 pp-> leap = (up->leapdelta > 0)
1568 pp-> leap = LEAP_NOWARNING;
1574 * Parse comprehensive time packet
1586 register struct refclockproc *pp;
1588 unsigned day, month, year; /* data derived from received timecode */
1589 unsigned hour, minute, second;
1593 float biasunc, rateunc;
1594 double lat, lon, alt;
1595 short lat_deg, lon_deg;
1596 float lat_min, lon_min;
1597 unsigned char north_south, east_west;
1600 static char logbuf[1024]; /* logging string buffer */
1612 if (bGetShort(&buf[1]) != 0)
1615 tow = bGetDouble(&buf[3]);
1620 else if ((tow >= 604800.0) || (tow < 0.0)) {
1625 if (tow < 604799.9) tow = tow + .00000001;
1626 second = (unsigned int) fmod(tow, 60.);
1627 minute = (unsigned int) fmod(tow/60., 60.);
1628 hour = (unsigned int )fmod(tow / 3600., 24.);
1631 day = (unsigned int) buf[11];
1632 month = (unsigned int) buf[12];
1633 year = bGetShort(&buf[13]);
1635 utcoff = bGetShort(&buf[16]);
1636 bias = bGetDouble(&buf[18]) / GPS_C * 1e9; /* ns */
1637 rate = bGetDouble(&buf[26]) / GPS_C * 1e9; /* ppb */
1638 biasunc = bGetSingle(&buf[34]) / GPS_C * 1e9; /* ns */
1639 rateunc = bGetSingle(&buf[38]) / GPS_C * 1e9; /* ppb */
1640 lat = bGetDouble(&buf[42]) * R2D;
1641 lon = bGetDouble(&buf[50]) * R2D;
1642 alt = bGetDouble(&buf[58]);
1651 lat_deg = (short)lat;
1652 lat_min = (lat - lat_deg) * 60.0;
1662 lon_deg = (short)lon;
1663 lon_min = (lon - lon_deg) * 60.0;
1665 for (i=0; i<8; i++) {
1666 sv[i] = buf[i + 66];
1668 TSIPPKT spt; /* local structure for sendpacket */
1669 b = (unsigned char) (sv[i]<0 ? -sv[i] : sv[i]);
1670 /* request tracking status */
1672 ripencc_send(peer,spt);
1677 sprintf(logbuf, "C1 %02d%02d%04d %02d%02d%02d %d %7.0f %.1f %.0f %.1f %d %02d%09.6f %c %02d%09.6f %c %.0f %d %d %d %d %d %d %d %d",
1678 day, month, year, hour, minute, second, mode, bias, biasunc,
1679 rate, rateunc, utcoff, lat_deg, lat_min, north_south, lon_deg,
1680 lon_min, east_west, alt, sv[0], sv[1], sv[2], sv[3], sv[4],
1681 sv[5], sv[6], sv[7]);
1686 #endif /* DEBUG_NCC */
1688 record_clock_stats(&peer->srcadr, logbuf);
1693 #ifdef TRIMBLE_OUTPUT_FUNC
1695 * Parse any packet using Trimble machinery
1703 static char logbuf[1024]; /* logging string buffer */
1705 TranslateTSIPReportToText (rpt, logbuf); /* anything else */
1709 #endif /* DEBUG_NCC */
1710 record_clock_stats(&peer->srcadr, &logbuf[1]);
1713 #endif /* TRIMBLE_OUTPUT_FUNC */
1717 * Parse UTC Parameter Packet
1719 * See the IDE for documentation!
1731 register struct ripencc_unit *up;
1735 int dt_ls, wn_t, wn_lsf, dn, dt_lsf;
1737 static char logbuf[1024]; /* logging string buffer */
1744 a0 = bGetDouble (buf);
1745 a1 = bGetSingle (&buf[8]);
1746 dt_ls = bGetShort (&buf[12]);
1747 tot = bGetSingle (&buf[14]);
1748 wn_t = bGetShort (&buf[18]);
1749 wn_lsf = bGetShort (&buf[20]);
1750 dn = bGetShort (&buf[22]);
1751 dt_lsf = bGetShort (&buf[24]);
1753 sprintf(logbuf, "L1 %d %d %d %g %g %g %d %d %d",
1754 dt_lsf - dt_ls, dt_ls, dt_lsf, a0, a1, tot, wn_t, wn_lsf, dn);
1759 #endif /* DEBUG_NCC */
1761 record_clock_stats(&peer->srcadr, logbuf);
1763 up = (struct ripencc_unit *) peer->procptr->unitptr;
1764 up->leapdelta = dt_lsf - dt_ls;
1770 * Parse Tracking Status packet
1782 unsigned char prn, channel, aqflag, ephstat;
1783 float snr, azinuth, elevation;
1785 static char logbuf[1024]; /* logging string buffer */
1794 channel = (unsigned char)(buf[1] >> 3);
1795 if (channel == 0x10)
1801 snr = bGetSingle(&buf[4]);
1802 elevation = bGetSingle(&buf[12]) * R2D;
1803 azinuth = bGetSingle(&buf[16]) * R2D;
1805 sprintf(logbuf, "S1 %02d %d %d %02x %4.1f %5.1f %4.1f",
1806 prn, channel, aqflag, ephstat, snr, azinuth, elevation);
1811 #endif /* DEBUG_NCC */
1813 record_clock_stats(&peer->srcadr, logbuf);
1818 /******* Code below is from Trimble Tsipchat *************/
1821 * *************************************************************************
1823 * Trimble Navigation, Ltd.
1824 * OEM Products Development Group
1826 * 645 North Mary Avenue
1827 * Sunnyvale, California 94088-3642
1829 * Corporate Headquarter:
1830 * Telephone: (408) 481-8000
1831 * Fax: (408) 481-6005
1833 * Technical Support Center:
1834 * Telephone: (800) 767-4822 (U.S. and Canada)
1835 * (408) 481-6940 (outside U.S. and Canada)
1836 * Fax: (408) 481-6020
1837 * BBS: (408) 481-7800
1838 * e-mail: trimble_support@trimble.com
1839 * ftp://ftp.trimble.com/pub/sct/embedded/bin
1841 * *************************************************************************
1843 * ------- BYTE-SWAPPING -------
1844 * TSIP is big-endian (Motorola) protocol. To use on little-endian (Intel)
1845 * systems, the bytes of all multi-byte types (shorts, floats, doubles, etc.)
1846 * must be reversed. This is controlled by the MACRO BYTESWAP; if defined, it
1847 * assumes little-endian protocol.
1848 * --------------------------------
1850 * T_PARSER.C and T_PARSER.H contains primitive functions that interpret
1851 * reports received from the receiver. A second source file pair,
1852 * T_FORMAT.C and T_FORMAT.H, contin the matching TSIP command formatters.
1854 * The module is in very portable, basic C language. It can be used as is, or
1855 * with minimal changes if a TSIP communications application is needed separate
1856 * from TSIPCHAT. The construction of most argument lists avoid the use of
1857 * structures, but the developer is encouraged to reconstruct them using such
1858 * definitions to meet project requirements. Declarations of T_PARSER.C
1859 * functions are included in T_PARSER.H to provide prototyping definitions.
1861 * There are two types of functions: a serial input processing routine,
1863 * which assembles incoming bytes into a TSIPPKT structure, and the
1864 * report parsers, rpt_0x??().
1866 * 1) The function tsip_input_proc() accumulates bytes from the receiver,
1867 * strips control bytes (DLE), and checks if the report end sequence (DLE ETX)
1868 * has been received. rpt.status is defined as TSIP_PARSED_FULL (== 1)
1869 * if a complete packet is available.
1871 * 2) The functions rpt_0x??() are report string interpreters patterned after
1872 * the document called "Trimble Standard Interface Protocol". It should be
1873 * noted that if the report buffer is sent into the receiver with the wrong
1874 * length (byte count), the rpt_0x??() returns the Boolean equivalence for
1877 * *************************************************************************
1883 * reads bytes until serial buffer is empty or a complete report
1884 * has been received; end of report is signified by DLE ETX.
1892 unsigned char newbyte;
1894 if (inbyte < 0 || inbyte > 0xFF) return;
1896 newbyte = (unsigned char)(inbyte);
1897 switch (rpt->status)
1899 case TSIP_PARSED_DLE_1:
1904 /* illegal TSIP IDs */
1906 rpt->status = TSIP_PARSED_EMPTY;
1909 /* try normal message start again */
1911 rpt->status = TSIP_PARSED_DLE_1;
1914 /* legal TSIP ID; start message */
1915 rpt->code = newbyte;
1917 rpt->status = TSIP_PARSED_DATA;
1921 case TSIP_PARSED_DATA:
1924 /* expect DLE or ETX next */
1925 rpt->status = TSIP_PARSED_DLE_2;
1928 /* normal data byte */
1929 rpt->buf[rpt->len] = newbyte;
1931 /* no change in rpt->status */
1935 case TSIP_PARSED_DLE_2:
1938 /* normal data byte */
1939 rpt->buf[rpt->len] = newbyte;
1941 rpt->status = TSIP_PARSED_DATA;
1944 /* end of message; return TRUE here. */
1945 rpt->status = TSIP_PARSED_FULL;
1948 /* error: treat as TSIP_PARSED_DLE_1; start new report packet */
1949 rpt->code = newbyte;
1951 rpt->status = TSIP_PARSED_DATA;
1954 case TSIP_PARSED_FULL:
1955 case TSIP_PARSED_EMPTY:
1959 /* normal message start */
1961 rpt->status = TSIP_PARSED_DLE_1;
1964 /* error: ignore newbyte */
1966 rpt->status = TSIP_PARSED_EMPTY;
1970 if (rpt->len > MAX_RPTBUF) {
1971 /* error: start new report packet */
1972 rpt->status = TSIP_PARSED_EMPTY;
1977 #ifdef TRIMBLE_OUTPUT_FUNC
1980 /* Channel A configuration for dual port operation */
1984 unsigned char *tx_baud_index,
1985 unsigned char *rx_baud_index,
1986 unsigned char *char_format_index,
1987 unsigned char *stop_bits,
1988 unsigned char *tx_mode_index,
1989 unsigned char *rx_mode_index
1995 if (rpt->len != 6) return TRUE;
1996 *tx_baud_index = buf[0];
1997 *rx_baud_index = buf[1];
1998 *char_format_index = buf[2];
1999 *stop_bits = (unsigned char)((buf[3] == 0x07) ? 1 : 2);
2000 *tx_mode_index = buf[4];
2001 *rx_mode_index = buf[5];
2006 /* almanac data for specified satellite */
2010 unsigned char *sv_prn,
2013 float *eccentricity,
2026 if (rpt->len != 39) return TRUE;
2028 *t_zc = bGetSingle (&buf[1]);
2029 *week_num = bGetShort (&buf[5]);
2030 *eccentricity = bGetSingle (&buf[7]);
2031 *t_oa = bGetSingle (&buf[11]);
2032 *i_0 = bGetSingle (&buf[15]);
2033 *OMEGA_dot = bGetSingle (&buf[19]);
2034 *sqrt_A = bGetSingle (&buf[23]);
2035 *OMEGA_0 = bGetSingle (&buf[27]);
2036 *omega = bGetSingle (&buf[31]);
2037 *M_0 = bGetSingle (&buf[35]);
2045 float *time_of_week,
2053 if (rpt->len != 10) return TRUE;
2054 *time_of_week = bGetSingle (buf);
2055 *week_num = bGetShort (&buf[4]);
2056 *UTC_offset = bGetSingle (&buf[6]);
2060 /* position in ECEF, single precision */
2071 if (rpt->len != 16) return TRUE;
2072 pos_ECEF[0] = bGetSingle (buf);
2073 pos_ECEF[1]= bGetSingle (&buf[4]);
2074 pos_ECEF[2]= bGetSingle (&buf[8]);
2075 *time_of_fix = bGetSingle (&buf[12]);
2079 /* velocity in ECEF, single precision */
2091 if (rpt->len != 20) return TRUE;
2092 ECEF_vel[0] = bGetSingle (buf);
2093 ECEF_vel[1] = bGetSingle (&buf[4]);
2094 ECEF_vel[2] = bGetSingle (&buf[8]);
2095 *freq_offset = bGetSingle (&buf[12]);
2096 *time_of_fix = bGetSingle (&buf[16]);
2100 /* software versions */
2104 unsigned char *major_nav_version,
2105 unsigned char *minor_nav_version,
2106 unsigned char *nav_day,
2107 unsigned char *nav_month,
2108 unsigned char *nav_year,
2109 unsigned char *major_dsp_version,
2110 unsigned char *minor_dsp_version,
2111 unsigned char *dsp_day,
2112 unsigned char *dsp_month,
2113 unsigned char *dsp_year
2119 if (rpt->len != 10) return TRUE;
2120 *major_nav_version = buf[0];
2121 *minor_nav_version = buf[1];
2123 *nav_month = buf[3];
2125 *major_dsp_version = buf[5];
2126 *minor_dsp_version = buf[6];
2128 *dsp_month = buf[8];
2133 /* receiver health and status */
2137 unsigned char *status1,
2138 unsigned char *status2
2144 if (rpt->len != 2) return TRUE;
2150 /* signal levels for all satellites tracked */
2154 unsigned char *nsvs,
2155 unsigned char *sv_prn,
2163 if (rpt->len != 1 + 5*buf[0]) return TRUE;
2165 for (isv = 0; isv < (*nsvs); isv++) {
2166 sv_prn[isv] = buf[5*isv + 1];
2167 snr[isv] = bGetSingle (&buf[5*isv + 2]);
2172 /* GPS system message */
2176 unsigned char *message
2182 if (rpt->len != 22) return TRUE;
2183 memcpy (message, buf, 22);
2188 /* health for all satellites from almanac health page */
2192 unsigned char *sv_health
2199 if (rpt->len != 32) return TRUE;
2200 for (i = 0; i < 32; i++) sv_health [i]= buf[i];
2204 /* position in lat-lon-alt, single precision */
2218 if (rpt->len != 20) return TRUE;
2219 *lat = bGetSingle (buf);
2220 *lon = bGetSingle (&buf[4]);
2221 *alt = bGetSingle (&buf[8]);
2222 *clock_bias = bGetSingle (&buf[12]);
2223 *time_of_fix = bGetSingle (&buf[16]);
2227 /* reference altitude parameters */
2233 unsigned char *alt_flag
2240 if (rpt->len != 9) return TRUE;
2241 *alt = bGetSingle (buf);
2242 *dummy = bGetSingle (&buf[4]);
2247 /* machine ID code, status */
2251 unsigned char *machine_id,
2252 unsigned char *status3,
2253 unsigned char *status4
2259 if (rpt->len != 3) return TRUE;
2260 *machine_id = buf[0];
2266 /* operating parameters and masks */
2270 unsigned char *dyn_code,
2280 if (rpt->len != 17) return TRUE;
2282 *el_mask = bGetSingle (&buf[1]);
2283 *snr_mask = bGetSingle (&buf[5]);
2284 *dop_mask = bGetSingle (&buf[9]);
2285 *dop_switch = bGetSingle (&buf[13]);
2289 /* oscillator offset */
2299 if (rpt->len != 4) return TRUE;
2300 *osc_offset = bGetSingle (buf);
2304 /* yes/no response to command to set GPS time */
2308 unsigned char *response
2314 if (rpt->len != 1) return TRUE;
2325 float *time_of_data,
2336 if (rpt->len != 26) return TRUE;
2337 *a0 = bGetDouble (buf);
2338 *a1 = bGetSingle (&buf[8]);
2339 *dt_ls = bGetShort (&buf[12]);
2340 *time_of_data = bGetSingle (&buf[14]);
2341 *wn_t = bGetShort (&buf[18]);
2342 *wn_lsf = bGetShort (&buf[20]);
2343 *dn = bGetShort (&buf[22]);
2344 *dt_lsf = bGetShort (&buf[24]);
2349 /* clock offset and frequency offset in 1-SV (0-D) mode */
2361 if (rpt->len != 12) return TRUE;
2362 *clock_bias = bGetSingle (buf);
2363 *freq_offset = bGetSingle (&buf[4]);
2364 *time_of_fix = bGetSingle (&buf[8]);
2368 /* I/O serial options */
2372 unsigned char *pos_code,
2373 unsigned char *vel_code,
2374 unsigned char *time_code,
2375 unsigned char *aux_code
2381 if (rpt->len != 4) return TRUE;
2384 *time_code = buf[2];
2389 /* velocity in east-north-up coordinates */
2401 if (rpt->len != 20) return TRUE;
2403 vel_ENU[0] = bGetSingle (buf);
2405 vel_ENU[1] = bGetSingle (&buf[4]);
2407 vel_ENU[2] = bGetSingle (&buf[8]);
2408 *freq_offset = bGetSingle (&buf[12]);
2409 *time_of_fix = bGetSingle (&buf[16]);
2413 /* info about last computed fix */
2417 unsigned char *source_code,
2418 unsigned char *diag_code,
2426 if (rpt->len != 8) return TRUE;
2427 *source_code = buf[0];
2428 *diag_code = buf[1];
2429 *time_of_fix = bGetSingle (&buf[2]);
2430 *week_num = bGetShort (&buf[6]);
2434 /* GPS system data or acknowledgment of GPS system data load */
2438 unsigned char *op_code,
2439 unsigned char *data_type,
2440 unsigned char *sv_prn,
2441 unsigned char *data_length,
2442 unsigned char *data_packet
2445 unsigned char *buf, *buf4;
2455 if (rpt->len < 4) return TRUE;
2456 if (rpt->len != 4+buf[3]) return TRUE;
2458 else if (rpt->len != 3) {
2462 *data_type = buf[1];
2464 if (*op_code == 2) {
2466 *data_length = (unsigned char)dl;
2468 switch (*data_type) {
2471 if (*data_length != sizeof (ALM_INFO)) return TRUE;
2472 alminfo = (ALM_INFO*)data_packet;
2473 alminfo->t_oa_raw = buf4[0];
2474 alminfo->SV_health = buf4[1];
2475 alminfo->e = bGetSingle(&buf4[2]);
2476 alminfo->t_oa = bGetSingle(&buf4[6]);
2477 alminfo->i_0 = bGetSingle(&buf4[10]);
2478 alminfo->OMEGADOT = bGetSingle(&buf4[14]);
2479 alminfo->sqrt_A = bGetSingle(&buf4[18]);
2480 alminfo->OMEGA_0 = bGetSingle(&buf4[22]);
2481 alminfo->omega = bGetSingle(&buf4[26]);
2482 alminfo->M_0 = bGetSingle(&buf4[30]);
2483 alminfo->a_f0 = bGetSingle(&buf4[34]);
2484 alminfo->a_f1 = bGetSingle(&buf4[38]);
2485 alminfo->Axis = bGetSingle(&buf4[42]);
2486 alminfo->n = bGetSingle(&buf4[46]);
2487 alminfo->OMEGA_n = bGetSingle(&buf4[50]);
2488 alminfo->ODOT_n = bGetSingle(&buf4[54]);
2489 alminfo->t_zc = bGetSingle(&buf4[58]);
2490 alminfo->weeknum = bGetShort(&buf4[62]);
2491 alminfo->wn_oa = bGetShort(&buf4[64]);
2495 /* Almanac health page */
2496 if (*data_length != sizeof (ALH_PARMS) + 3) return TRUE;
2498 /* this record is returned raw */
2499 memcpy (data_packet, buf4, dl);
2504 if (*data_length != sizeof (ION_INFO) + 8) return TRUE;
2505 ioninfo = (ION_INFO*)data_packet;
2506 ioninfo->alpha_0 = bGetSingle (&buf4[8]);
2507 ioninfo->alpha_1 = bGetSingle (&buf4[12]);
2508 ioninfo->alpha_2 = bGetSingle (&buf4[16]);
2509 ioninfo->alpha_3 = bGetSingle (&buf4[20]);
2510 ioninfo->beta_0 = bGetSingle (&buf4[24]);
2511 ioninfo->beta_1 = bGetSingle (&buf4[28]);
2512 ioninfo->beta_2 = bGetSingle (&buf4[32]);
2513 ioninfo->beta_3 = bGetSingle (&buf4[36]);
2518 if (*data_length != sizeof (UTC_INFO) + 13) return TRUE;
2519 utcinfo = (UTC_INFO*)data_packet;
2520 utcinfo->A_0 = bGetDouble (&buf4[13]);
2521 utcinfo->A_1 = bGetSingle (&buf4[21]);
2522 utcinfo->delta_t_LS = bGetShort (&buf4[25]);
2523 utcinfo->t_ot = bGetSingle(&buf4[27]);
2524 utcinfo->WN_t = bGetShort (&buf4[31]);
2525 utcinfo->WN_LSF = bGetShort (&buf4[33]);
2526 utcinfo->DN = bGetShort (&buf4[35]);
2527 utcinfo->delta_t_LSF = bGetShort (&buf4[37]);
2532 if (*data_length != sizeof (NAV_INFO) - 1) return TRUE;
2534 navinfo = (NAV_INFO*)data_packet;
2536 navinfo->sv_number = buf4[0];
2537 navinfo->t_ephem = bGetSingle (&buf4[1]);
2538 navinfo->ephclk.weeknum = bGetShort (&buf4[5]);
2540 navinfo->ephclk.codeL2 = buf4[7];
2541 navinfo->ephclk.L2Pdata = buf4[8];
2542 navinfo->ephclk.SVacc_raw = buf4[9];
2543 navinfo->ephclk.SV_health = buf4[10];
2544 navinfo->ephclk.IODC = bGetShort (&buf4[11]);
2545 navinfo->ephclk.T_GD = bGetSingle (&buf4[13]);
2546 navinfo->ephclk.t_oc = bGetSingle (&buf4[17]);
2547 navinfo->ephclk.a_f2 = bGetSingle (&buf4[21]);
2548 navinfo->ephclk.a_f1 = bGetSingle (&buf4[25]);
2549 navinfo->ephclk.a_f0 = bGetSingle (&buf4[29]);
2550 navinfo->ephclk.SVacc = bGetSingle (&buf4[33]);
2552 navinfo->ephorb.IODE = buf4[37];
2553 navinfo->ephorb.fit_interval = buf4[38];
2554 navinfo->ephorb.C_rs = bGetSingle (&buf4[39]);
2555 navinfo->ephorb.delta_n = bGetSingle (&buf4[43]);
2556 navinfo->ephorb.M_0 = bGetDouble (&buf4[47]);
2557 navinfo->ephorb.C_uc = bGetSingle (&buf4[55]);
2558 navinfo->ephorb.e = bGetDouble (&buf4[59]);
2559 navinfo->ephorb.C_us = bGetSingle (&buf4[67]);
2560 navinfo->ephorb.sqrt_A = bGetDouble (&buf4[71]);
2561 navinfo->ephorb.t_oe = bGetSingle (&buf4[79]);
2562 navinfo->ephorb.C_ic = bGetSingle (&buf4[83]);
2563 navinfo->ephorb.OMEGA_0 = bGetDouble (&buf4[87]);
2564 navinfo->ephorb.C_is = bGetSingle (&buf4[95]);
2565 navinfo->ephorb.i_0 = bGetDouble (&buf4[99]);
2566 navinfo->ephorb.C_rc = bGetSingle (&buf4[107]);
2567 navinfo->ephorb.omega = bGetDouble (&buf4[111]);
2568 navinfo->ephorb.OMEGADOT=bGetSingle (&buf4[119]);
2569 navinfo->ephorb.IDOT = bGetSingle (&buf4[123]);
2570 navinfo->ephorb.Axis = bGetDouble (&buf4[127]);
2571 navinfo->ephorb.n = bGetDouble (&buf4[135]);
2572 navinfo->ephorb.r1me2 = bGetDouble (&buf4[143]);
2573 navinfo->ephorb.OMEGA_n=bGetDouble (&buf4[151]);
2574 navinfo->ephorb.ODOT_n = bGetDouble (&buf4[159]);
2581 /* satellite enable/disable or health heed/ignore list */
2585 unsigned char *code_type,
2586 unsigned char status_code[32]
2593 if (rpt->len != 33) return TRUE;
2594 *code_type = buf[0];
2595 for (iprn = 0; iprn < 32; iprn++)
2596 status_code[iprn] = buf[iprn + 1];
2600 /* raw measurement data - code phase/Doppler */
2604 unsigned char *sv_prn,
2605 float *sample_length,
2606 float *signal_level,
2615 if (rpt->len != 25) return TRUE;
2617 *sample_length = bGetSingle (&buf[1]);
2618 *signal_level = bGetSingle (&buf[5]);
2619 *code_phase = bGetSingle (&buf[9]);
2620 *Doppler = bGetSingle (&buf[13]);
2621 *time_of_fix = bGetDouble (&buf[17]);
2625 /* satellite ephorb status */
2629 unsigned char *sv_prn,
2630 unsigned char *sv_health,
2631 unsigned char *sv_iode,
2632 unsigned char *fit_interval_flag,
2633 float *time_of_collection,
2641 if (rpt->len != 16) return TRUE;
2643 *time_of_collection = bGetSingle (&buf[1]);
2644 *sv_health = buf[5];
2646 *time_of_eph = bGetSingle (&buf[7]);
2647 *fit_interval_flag = buf[11];
2648 *sv_accy = bGetSingle (&buf[12]);
2652 /* satellite tracking status */
2656 unsigned char *sv_prn,
2657 unsigned char *slot,
2658 unsigned char *chan,
2659 unsigned char *acq_flag,
2660 unsigned char *eph_flag,
2661 float *signal_level,
2662 float *time_of_last_msmt,
2665 unsigned char *old_msmt_flag,
2666 unsigned char *integer_msec_flag,
2667 unsigned char *bad_data_flag,
2668 unsigned char *data_collect_flag
2674 if (rpt->len != 24) return TRUE;
2676 *slot = (unsigned char)((buf[1] & 0x07) + 1);
2677 *chan = (unsigned char)(buf[1] >> 3);
2678 if (*chan == 0x10) *chan = 2;
2682 *signal_level = bGetSingle (&buf[4]);
2683 *time_of_last_msmt = bGetSingle (&buf[8]);
2684 *elev = bGetSingle (&buf[12]);
2685 *azim = bGetSingle (&buf[16]);
2686 *old_msmt_flag = buf[20];
2687 *integer_msec_flag = buf[21];
2688 *bad_data_flag = buf[22];
2689 *data_collect_flag = buf[23];
2694 /* over-determined satellite selection for position fixes, PDOP, fix mode */
2698 unsigned char *manual_mode,
2699 unsigned char *nsvs,
2700 unsigned char *ndim,
2701 unsigned char sv_prn[],
2712 *nsvs = (unsigned char)((buf[0] & 0xF0) >> 4);
2713 if ((*nsvs)>8) return TRUE;
2714 if (rpt->len != 17 + (*nsvs) ) return TRUE;
2716 *manual_mode = (unsigned char)(buf[0] & 0x08);
2717 *ndim = (unsigned char)((buf[0] & 0x07));
2718 *pdop = bGetSingle (&buf[1]);
2719 *hdop = bGetSingle (&buf[5]);
2720 *vdop = bGetSingle (&buf[9]);
2721 *tdop = bGetSingle (&buf[13]);
2722 for (islot = 0; islot < (*nsvs); islot++)
2723 sv_prn[islot] = buf[islot + 17];
2728 /* differential fix mode */
2732 unsigned char *diff_mode
2738 if (rpt->len != 1) return TRUE;
2739 *diff_mode = buf[0];
2743 /* position, ECEF double precision */
2755 if (rpt->len != 36) return TRUE;
2756 ECEF_pos[0] = bGetDouble (buf);
2757 ECEF_pos[1] = bGetDouble (&buf[8]);
2758 ECEF_pos[2] = bGetDouble (&buf[16]);
2759 *clock_bias = bGetDouble (&buf[24]);
2760 *time_of_fix = bGetSingle (&buf[32]);
2764 /* position, lat-lon-alt double precision */
2778 if (rpt->len != 36) return TRUE;
2779 *lat = bGetDouble (buf);
2780 *lon = bGetDouble (&buf[8]);
2781 *alt = bGetDouble (&buf[16]);
2782 *clock_bias = bGetDouble (&buf[24]);
2783 *time_of_fix = bGetSingle (&buf[32]);
2790 TSIP_RCVR_CFG *TsipxBB
2796 /* Palisade is inconsistent with other TSIP, which has a length of 40 */
2797 /* if (rpt->len != 40) return TRUE; */
2798 if (rpt->len != 43) return TRUE;
2800 TsipxBB->bSubcode = buf[0];
2801 TsipxBB->operating_mode = buf[1];
2802 TsipxBB->dyn_code = buf[3];
2803 TsipxBB->elev_mask = bGetSingle (&buf[5]);
2804 TsipxBB->cno_mask = bGetSingle (&buf[9]);
2805 TsipxBB->dop_mask = bGetSingle (&buf[13]);
2806 TsipxBB->dop_switch = bGetSingle (&buf[17]);
2810 /* Receiver serial port configuration */
2814 unsigned char *port_num,
2815 unsigned char *in_baud,
2816 unsigned char *out_baud,
2817 unsigned char *data_bits,
2818 unsigned char *parity,
2819 unsigned char *stop_bits,
2820 unsigned char *flow_control,
2821 unsigned char *protocols_in,
2822 unsigned char *protocols_out,
2823 unsigned char *reserved
2829 if (rpt->len != 10) return TRUE;
2833 *data_bits = buf[3];
2835 *stop_bits = buf[5];
2836 *flow_control = buf[6];
2837 *protocols_in = buf[7];
2838 *protocols_out = buf[8];
2844 /**** Superpackets ****/
2849 unsigned short *event,
2851 unsigned char *date,
2852 unsigned char *month,
2854 unsigned char *dim_mode,
2870 if (rpt->len != 74) return TRUE;
2871 *event = bGetShort(&buf[1]);
2872 *tow = bGetDouble(&buf[3]);
2875 *year = bGetShort(&buf[13]);
2876 *dim_mode = buf[15];
2877 *utc_offset = bGetShort(&buf[16]);
2878 *bias = bGetDouble(&buf[18]);
2879 *drift = bGetDouble(&buf[26]);
2880 *bias_unc = bGetSingle(&buf[34]);
2881 *dr_unc = bGetSingle(&buf[38]);
2882 *lat = bGetDouble(&buf[42]);
2883 *lon = bGetDouble(&buf[50]);
2884 *alt = bGetDouble(&buf[58]);
2886 for (local_index=0; local_index<8; local_index++) sv_id[local_index] = buf[local_index + 66];
2890 /* datum index and coefficients */
2895 double datum_coeffs[5]
2901 if (rpt->len != 43) return TRUE;
2902 *datum_idx = bGetShort(&buf[1]);
2903 datum_coeffs[0] = bGetDouble (&buf[3]);
2904 datum_coeffs[1] = bGetDouble (&buf[11]);
2905 datum_coeffs[2] = bGetDouble (&buf[19]);
2906 datum_coeffs[3] = bGetDouble (&buf[27]);
2907 datum_coeffs[4] = bGetDouble (&buf[35]);
2912 /* datum index and coefficients */
2917 double datum_coeffs[5]
2923 if (rpt->len != 43) return TRUE;
2924 *datum_idx = bGetShort(&buf[1]);
2925 datum_coeffs[0] = bGetDouble (&buf[3]);
2926 datum_coeffs[1] = bGetDouble (&buf[11]);
2927 datum_coeffs[2] = bGetDouble (&buf[19]);
2928 datum_coeffs[3] = bGetDouble (&buf[27]);
2929 datum_coeffs[4] = bGetDouble (&buf[35]);
2934 #define MAX_LONG (2147483648.) /* 2**31 */
2939 unsigned char *info,
2944 double *time_of_fix,
2946 unsigned char *nsvs,
2947 unsigned char sv_prn[],
2965 if (rpt->len != 56) return TRUE;
2967 vel_scale = (buf[24]&1)? 0.020 : 0.005;
2968 vel_enu[0] = bGetShort (buf+2)*vel_scale;
2969 vel_enu[1] = bGetShort (buf+4)*vel_scale;
2970 vel_enu[2] = bGetShort (buf+6)*vel_scale;
2972 *time_of_fix = bGetULong (buf+8)*.001;
2974 longtemp = bGetLong (buf+12);
2975 *lat = longtemp*(GPS_PI/MAX_LONG);
2977 ulongtemp = bGetULong (buf+16);
2978 *lon = ulongtemp*(GPS_PI/MAX_LONG);
2979 if (*lon > GPS_PI) *lon -= 2.0*GPS_PI;
2981 *alt = bGetLong (buf+20)*.001;
2982 /* 25 blank; 29 = UTC */
2983 (*datum_index) = (short)((short)buf[26]-1);
2986 *week_num = bGetShort (&buf[30]);
2987 for (isv = 0; isv < 8; isv++) {
2988 prnx = buf[32+2*isv];
2989 sv_prn[isv] = (unsigned char)(prnx&0x3F);
2990 iode = buf[33+2*isv];
2991 sv_IODC[isv] = (short)(iode | ((prnx>>6)<<8));
2999 unsigned char *bSearchRange,
3000 unsigned char *bBoardOptions,
3001 unsigned long *iiSerialNumber,
3002 unsigned char *bBuildYear,
3003 unsigned char *bBuildMonth,
3004 unsigned char *bBuildDay,
3005 unsigned char *bBuildHour,
3007 unsigned short *iTestCodeId
3010 if (rpt->len != 17) return FALSE;
3011 *bSearchRange = rpt->buf[1];
3012 *bBoardOptions = rpt->buf[2];
3013 *iiSerialNumber = bGetLong(&rpt->buf[3]);
3014 *bBuildYear = rpt->buf[7];
3015 *bBuildMonth = rpt->buf[8];
3016 *bBuildDay = rpt->buf[9];
3017 *bBuildHour = rpt->buf[10];
3018 *fOscOffset = bGetSingle(&rpt->buf[11]);
3019 *iTestCodeId = bGetShort(&rpt->buf[15]);
3020 /* Tsipx8E41Data = *Tsipx8E41; */
3027 unsigned char *bProdOptionsPre,
3028 unsigned char *bProdNumberExt,
3029 unsigned short *iCaseSerialNumberPre,
3030 unsigned long *iiCaseSerialNumber,
3031 unsigned long *iiProdNumber,
3032 unsigned short *iPremiumOptions,
3033 unsigned short *iMachineID,
3034 unsigned short *iKey
3037 if (rpt->len != 19) return FALSE;
3038 *bProdOptionsPre = rpt->buf[1];
3039 *bProdNumberExt = rpt->buf[2];
3040 *iCaseSerialNumberPre = bGetShort(&rpt->buf[3]);
3041 *iiCaseSerialNumber = bGetLong(&rpt->buf[5]);
3042 *iiProdNumber = bGetLong(&rpt->buf[9]);
3043 *iPremiumOptions = bGetShort(&rpt->buf[13]);
3044 *iMachineID = bGetShort(&rpt->buf[15]);
3045 *iKey = bGetShort(&rpt->buf[17]);
3052 unsigned char *bSegMask
3055 if (rpt->len != 2) return FALSE;
3056 *bSegMask = rpt->buf[1];
3060 /* Stinger PPS definition */
3064 unsigned char *pps_enabled,
3065 unsigned char *pps_timebase,
3066 unsigned char *pos_polarity,
3068 float *bias_unc_threshold
3075 if (rpt->len != 16) return TRUE;
3076 *pps_enabled = buf[1];
3077 *pps_timebase = buf[2];
3078 *pos_polarity = buf[3];
3079 *pps_offset = bGetDouble(&buf[4]);
3080 *bias_unc_threshold = bGetSingle(&buf[12]);
3087 unsigned long *decorr_max
3094 if (rpt->len != 5) return TRUE;
3095 *decorr_max = bGetLong(&buf[1]);
3102 unsigned long *event_mask
3109 if (rpt->len != 5) return TRUE;
3110 *event_mask = bGetULong (&buf[1]);
3117 unsigned char *spktmask
3124 if (rpt->len != 5) return TRUE;
3125 spktmask[0] = buf[1];
3126 spktmask[1] = buf[2];
3127 spktmask[2] = buf[3];
3128 spktmask[3] = buf[4];
3135 unsigned short *COUNT,
3137 unsigned char *Hour,
3138 unsigned char *Minute,
3139 unsigned char *Second,
3141 unsigned char *Month,
3142 unsigned short *Year,
3143 unsigned char *Status,
3144 unsigned char *Flags
3147 if (rpt->len != 22) return TRUE;
3149 *COUNT = bGetUShort(&rpt->buf[1]);
3150 *FracSec = bGetDouble(&rpt->buf[3]);
3151 *Hour = rpt->buf[11];
3152 *Minute = rpt->buf[12];
3153 *Second = rpt->buf[13];
3154 *Day = rpt->buf[14];
3155 *Month = rpt->buf[15];
3156 *Year = bGetUShort(&rpt->buf[16]);
3157 *Status = rpt->buf[18];
3158 *Flags = rpt->buf[19];
3164 * *************************************************************************
3166 * Trimble Navigation, Ltd.
3167 * OEM Products Development Group
3169 * 645 North Mary Avenue
3170 * Sunnyvale, California 94088-3642
3172 * Corporate Headquarter:
3173 * Telephone: (408) 481-8000
3174 * Fax: (408) 481-6005
3176 * Technical Support Center:
3177 * Telephone: (800) 767-4822 (U.S. and Canada)
3178 * (408) 481-6940 (outside U.S. and Canada)
3179 * Fax: (408) 481-6020
3180 * BBS: (408) 481-7800
3181 * e-mail: trimble_support@trimble.com
3182 * ftp://ftp.trimble.com/pub/sct/embedded/bin
3184 * *************************************************************************
3186 * T_REPORT.C consists of a primary function TranslateTSIPReportToText()
3189 * This function takes a character buffer that has been received as a report
3190 * from a TSIP device and interprets it. The character buffer has been
3191 * assembled using tsip_input_proc() in T_PARSER.C.
3193 * A large case statement directs processing to one of many mid-level
3194 * functions. The mid-level functions specific to the current report
3195 * code passes the report buffer to the appropriate report decoder
3196 * rpt_0x?? () in T_PARSER.C, which converts the byte stream in rpt.buf
3197 * to data values approporaite for use.
3199 * *************************************************************************
3204 #define GOOD_PARSE 0
3205 #define BADID_PARSE 1
3206 #define BADLEN_PARSE 2
3207 #define BADDATA_PARSE 3
3213 /* pbuf is the pointer to the current location of the text output */
3217 /* keep track of whether the message has been successfully parsed */
3222 /* convert time of week into day-hour-minute-second and print */
3228 short days, hours, minutes;
3231 static char timestring [80];
3233 if (time_of_week == -1.0)
3235 sprintf(timestring, " <No time yet> ");
3237 else if ((time_of_week >= 604800.0) || (time_of_week < 0.0))
3239 sprintf(timestring, " <Bad time> ");
3243 if (time_of_week < 604799.9)
3244 tow = time_of_week + .00000001;
3245 seconds = (float)fmod(tow, 60.);
3246 minutes = (short) fmod(tow/60., 60.);
3247 hours = (short)fmod(tow / 3600., 24.);
3248 days = (short)(tow / 86400.0);
3249 sprintf(timestring, " %s %02d:%02d:%05.2f ",
3250 dayname[days], hours, minutes, seconds);
3263 tx_baud_index, rx_baud_index,
3264 char_format_index, stop_bits,
3265 tx_mode_index, rx_mode_index,
3272 &tx_baud_index, &rx_baud_index, &char_format_index,
3273 &stop_bits, &tx_mode_index, &rx_mode_index)) {
3274 parsed = BADLEN_PARSE;
3278 pbuf += sprintf(pbuf, "\nChannel A Configuration");
3280 nbaud = sizeof(old_baudnum);
3282 for (i = 0; i < nbaud; ++i) if (tx_baud_index == old_baudnum[i]) break;
3283 pbuf += sprintf(pbuf, "\n Transmit speed: %s at %s",
3284 old_output_ch[tx_mode_index], st_baud_text_app[i]);
3286 for (i = 0; i < nbaud; ++i) if (rx_baud_index == old_baudnum[i]) break;
3287 pbuf += sprintf(pbuf, "\n Receive speed: %s at %s",
3288 old_input_ch[rx_mode_index], st_baud_text_app[i]);
3290 databits = (unsigned char)((char_format_index & 0x03) + 5);
3292 parity = (unsigned char)(char_format_index >> 2);
3293 if (parity > 4) parity = 2;
3295 pbuf += sprintf(pbuf, "\n Character format (bits/char, parity, stop bits): %d-%s-%d",
3296 databits, old_parity_text[parity], stop_bits);
3302 rpt_almanac_data_page(
3323 &sv_prn, &week_num, &t_zc, &eccentricity, &t_oa,
3324 &i_0, &OMEGA_dot, &sqrt_A, &OMEGA_0, &omega, &M_0)) {
3325 parsed = BADLEN_PARSE;
3329 pbuf += sprintf(pbuf, "\nAlmanac for SV %02d", sv_prn);
3330 pbuf += sprintf(pbuf, "\n Captured:%15.0f %s",
3331 t_zc, show_time (t_zc));
3332 pbuf += sprintf(pbuf, "\n week:%15d", week_num);
3333 pbuf += sprintf(pbuf, "\n Eccentricity:%15g", eccentricity);
3334 pbuf += sprintf(pbuf, "\n T_oa:%15.0f %s",
3335 t_oa, show_time (t_oa));
3336 pbuf += sprintf(pbuf, "\n i 0:%15g", i_0);
3337 pbuf += sprintf(pbuf, "\n OMEGA dot:%15g", OMEGA_dot);
3338 pbuf += sprintf(pbuf, "\n sqrt A:%15g", sqrt_A);
3339 pbuf += sprintf(pbuf, "\n OMEGA 0:%15g", OMEGA_0);
3340 pbuf += sprintf(pbuf, "\n omega:%15g", omega);
3341 pbuf += sprintf(pbuf, "\n M 0:%15g", M_0);
3351 time_of_week, UTC_offset;
3356 if (rpt_0x41 (rpt, &time_of_week, &UTC_offset, &week_num)) {
3357 parsed = BADLEN_PARSE;
3361 pbuf += sprintf(pbuf, "\nGPS time:%s GPS week: %d UTC offset %.1f",
3362 show_time(time_of_week), week_num, UTC_offset);
3368 rpt_single_ECEF_position(
3373 ECEF_pos[3], time_of_fix;
3376 if (rpt_0x42 (rpt, ECEF_pos, &time_of_fix)) {
3377 parsed = BADLEN_PARSE;
3381 pbuf += sprintf(pbuf, "\nSXYZ: %15.0f %15.0f %15.0f %s",
3382 ECEF_pos[0], ECEF_pos[1], ECEF_pos[2],
3383 show_time(time_of_fix));
3388 rpt_single_ECEF_velocity(
3394 ECEF_vel[3], freq_offset, time_of_fix;
3397 if (rpt_0x43 (rpt, ECEF_vel, &freq_offset, &time_of_fix)) {
3398 parsed = BADLEN_PARSE;
3402 pbuf += sprintf(pbuf, "\nVelECEF: %11.3f %11.3f %11.3f %12.3f%s",
3403 ECEF_vel[0], ECEF_vel[1], ECEF_vel[2], freq_offset,
3404 show_time(time_of_fix));
3414 major_nav_version, minor_nav_version,
3415 nav_day, nav_month, nav_year,
3416 major_dsp_version, minor_dsp_version,
3417 dsp_day, dsp_month, dsp_year;
3421 &major_nav_version, &minor_nav_version,
3422 &nav_day, &nav_month, &nav_year,
3423 &major_dsp_version, &minor_dsp_version,
3424 &dsp_day, &dsp_month, &dsp_year)) {
3425 parsed = BADLEN_PARSE;
3429 pbuf += sprintf(pbuf,
3430 "\nFW Versions: Nav Proc %2d.%02d %2d/%2d/%2d Sig Proc %2d.%02d %2d/%2d/%2d",
3431 major_nav_version, minor_nav_version, nav_day, nav_month, nav_year,
3432 major_dsp_version, minor_dsp_version, dsp_day, dsp_month, dsp_year);
3445 static const char const
3447 "Doing position fixes",
3448 "Don't have GPS time yet",
3449 "Waiting for almanac collection",
3451 "No satellites available",
3452 "Only 1 satellite available",
3453 "Only 2 satellites available",
3454 "Only 3 satellites available",
3455 "No satellites usable ",
3456 "Only 1 satellite usable",
3457 "Only 2 satellites usable",
3458 "Only 3 satellites usable",
3459 "Chosen satellite unusable"};
3463 if (rpt_0x46 (rpt, &status1, &status2))
3465 parsed = BADLEN_PARSE;
3469 text = (status1 < COUNTOF(sc_text))
3472 pbuf += sprintf(pbuf, "\nRcvr status1: %s (%02Xh); ",
3475 pbuf += sprintf(pbuf, "status2: %s, %s (%02Xh)",
3476 (status2 & 0x01)?"No BBRAM":"BBRAM OK",
3477 (status2 & 0x10)?"No Ant":"Ant OK",
3495 if (rpt_0x47 (rpt, &nsvs, sv_prn, snr))
3497 parsed = BADLEN_PARSE;
3501 pbuf += sprintf(pbuf, "\nSNR for satellites: %d", nsvs);
3502 for (isv = 0; isv < nsvs; isv++)
3504 pbuf += sprintf(pbuf, "\n SV %02d %6.2f",
3505 sv_prn[isv], snr[isv]);
3511 rpt_GPS_system_message(
3519 if (rpt_0x48 (rpt, message))
3521 parsed = BADLEN_PARSE;
3525 pbuf += sprintf(pbuf, "\nGPS message: %s", message);
3530 rpt_almanac_health_page(
3540 if (rpt_0x49 (rpt, sv_health))
3542 parsed = BADLEN_PARSE;
3546 pbuf += sprintf(pbuf, "\nAlmanac health page:");
3547 for (iprn = 0; iprn < 32; iprn++)
3549 if (!(iprn%5)) *pbuf++ = '\n';
3550 pbuf += sprintf(pbuf, " SV%02d %2X",
3551 (iprn+1) , sv_health[iprn]);
3557 rpt_single_lla_position(
3565 alt, clock_bias, time_of_fix;
3566 double lat_min, lon_min;
3568 north_south, east_west;
3571 &lat, &lon, &alt, &clock_bias, &time_of_fix))
3573 parsed = BADLEN_PARSE;
3577 /* convert from radians to degrees */
3585 lat_deg = (short)lat;
3586 lat_min = (lat - lat_deg) * 60.0;
3595 lon_deg = (short)lon;
3596 lon_min = (lon - lon_deg) * 60.0;
3598 pbuf += sprintf(pbuf, "\nSLLA: %4d: %06.3f %c%5d:%06.3f %c%10.2f %12.2f%s",
3599 lat_deg, lat_min, north_south,
3600 lon_deg, lon_min, east_west,
3602 show_time(time_of_fix));
3616 if (rpt_0x4A_2 (rpt, &alt, &dummy, &alt_flag))
3618 parsed = BADLEN_PARSE;
3622 pbuf += sprintf(pbuf, "\nReference Alt: %.1f m; %s",
3623 alt, alt_flag?"ON":"OFF");
3628 rpt_rcvr_id_and_status(
3634 machine_id, status3, status4;
3637 if (rpt_0x4B (rpt, &machine_id, &status3, &status4))
3639 parsed = BADLEN_PARSE;
3643 pbuf += sprintf(pbuf, "\nRcvr Machine ID: %d; Status3 = %s, %s (%02Xh)",
3645 (status3 & 0x02)?"No RTC":"RTC OK",
3646 (status3 & 0x08)?"No Alm":"Alm OK",
3652 rpt_operating_parameters(
3659 el_mask, snr_mask, dop_mask, dop_switch;
3662 if (rpt_0x4C (rpt, &dyn_code, &el_mask,
3663 &snr_mask, &dop_mask, &dop_switch))
3665 parsed = BADLEN_PARSE;
3669 pbuf += sprintf(pbuf, "\nOperating Parameters:");
3670 pbuf += sprintf(pbuf, "\n Dynamics code = %d %s",
3671 dyn_code, dyn_text[dyn_code]);
3672 pbuf += sprintf(pbuf, "\n Elevation mask = %.2f", el_mask * R2D);
3673 pbuf += sprintf(pbuf, "\n SNR mask = %.2f", snr_mask);
3674 pbuf += sprintf(pbuf, "\n DOP mask = %.2f", dop_mask);
3675 pbuf += sprintf(pbuf, "\n DOP switch = %.2f", dop_switch);
3680 rpt_oscillator_offset(
3688 if (rpt_0x4D (rpt, &osc_offset))
3690 parsed = BADLEN_PARSE;
3694 pbuf += sprintf(pbuf, "\nOscillator offset: %.2f Hz = %.3f PPM",
3695 osc_offset, osc_offset/1575.42);
3700 rpt_GPS_time_set_response(
3708 if (rpt_0x4E (rpt, &response))
3710 parsed = BADLEN_PARSE;
3717 pbuf += sprintf(pbuf, "\nTime set accepted");
3721 pbuf += sprintf(pbuf, "\nTime set rejected or not required");
3725 parsed = BADDATA_PARSE;
3740 dt_ls, wn_t, wn_lsf, dn, dt_lsf;
3743 if (rpt_0x4F (rpt, &a0, &a1, &time_of_data,
3744 &dt_ls, &wn_t, &wn_lsf, &dn, &dt_lsf)) {
3745 parsed = BADLEN_PARSE;
3749 pbuf += sprintf(pbuf, "\nUTC Correction Data");
3750 pbuf += sprintf(pbuf, "\n A_0 = %g ", a0);
3751 pbuf += sprintf(pbuf, "\n A_1 = %g ", a1);
3752 pbuf += sprintf(pbuf, "\n delta_t_LS = %d ", dt_ls);
3753 pbuf += sprintf(pbuf, "\n t_ot = %.0f ", time_of_data);
3754 pbuf += sprintf(pbuf, "\n WN_t = %d ", wn_t );
3755 pbuf += sprintf(pbuf, "\n WN_LSF = %d ", wn_lsf );
3756 pbuf += sprintf(pbuf, "\n DN = %d ", dn );
3757 pbuf += sprintf(pbuf, "\n delta_t_LSF = %d ", dt_lsf );
3768 clock_bias, freq_offset, time_of_fix;
3771 if (rpt_0x54 (rpt, &clock_bias, &freq_offset, &time_of_fix)) {
3772 parsed = BADLEN_PARSE;
3776 pbuf += sprintf (pbuf, "\nTime Fix Clock Bias: %6.2f m Freq Bias: %6.2f m/s%s",
3777 clock_bias, freq_offset, show_time (time_of_fix));
3787 pos_code, vel_code, time_code, aux_code;
3791 &pos_code, &vel_code, &time_code, &aux_code)) {
3792 parsed = BADLEN_PARSE;
3795 /* rptbuf unloaded */
3797 pbuf += sprintf(pbuf, "\nI/O Options: %2X %2X %2X %2X",
3798 pos_code, vel_code, time_code, aux_code);
3800 if (pos_code & 0x01) {
3801 pbuf += sprintf(pbuf, "\n ECEF XYZ position output");
3804 if (pos_code & 0x02) {
3805 pbuf += sprintf(pbuf, "\n LLA position output");
3808 pbuf += sprintf(pbuf, (pos_code & 0x04)?
3809 "\n MSL altitude output (Geoid height) ":
3810 "\n WGS-84 altitude output");
3812 pbuf += sprintf(pbuf, (pos_code & 0x08)?
3813 "\n MSL altitude input":
3814 "\n WGS-84 altitude input");
3816 pbuf += sprintf(pbuf, (pos_code & 0x10)?
3817 "\n Double precision":
3818 "\n Single precision");
3820 if (pos_code & 0x20) {
3821 pbuf += sprintf(pbuf, "\n All Enabled Superpackets");
3824 if (vel_code & 0x01) {
3825 pbuf += sprintf(pbuf, "\n ECEF XYZ velocity output");
3828 if (vel_code & 0x02) {
3829 pbuf += sprintf(pbuf, "\n ENU velocity output");
3832 pbuf += sprintf(pbuf, (time_code & 0x01)?
3833 "\n Time tags in UTC":
3834 "\n Time tags in GPS time");
3836 if (time_code & 0x02) {
3837 pbuf += sprintf(pbuf, "\n Fixes delayed to integer seconds");
3840 if (time_code & 0x04) {
3841 pbuf += sprintf(pbuf, "\n Fixes sent only on request");
3844 if (time_code & 0x08) {
3845 pbuf += sprintf(pbuf, "\n Synchronized measurements");
3848 if (time_code & 0x10) {
3849 pbuf += sprintf(pbuf, "\n Minimize measurement propagation");
3852 pbuf += sprintf(pbuf, (time_code & 0x20) ?
3853 "\n PPS output at all times" :
3854 "\n PPS output during fixes");
3856 if (aux_code & 0x01) {
3857 pbuf += sprintf(pbuf, "\n Raw measurement output");
3860 if (aux_code & 0x02) {
3861 pbuf += sprintf(pbuf, "\n Code-phase smoothed before output");
3864 if (aux_code & 0x04) {
3865 pbuf += sprintf(pbuf, "\n Additional fix status");
3868 pbuf += sprintf(pbuf, (aux_code & 0x08)?
3869 "\n Signal Strength Output as dBHz" :
3870 "\n Signal Strength Output as AMU");
3880 vel_ENU[3], freq_offset, time_of_fix;
3883 if (rpt_0x56 (rpt, vel_ENU, &freq_offset, &time_of_fix)) {
3884 parsed = BADLEN_PARSE;
3888 pbuf += sprintf(pbuf, "\nVel ENU: %11.3f %11.3f %11.3f %12.3f%s",
3889 vel_ENU[0], vel_ENU[1], vel_ENU[2], freq_offset,
3890 show_time (time_of_fix));
3900 source_code, diag_code;
3907 if (rpt_0x57 (rpt, &source_code, &diag_code, &week_num, &time_of_fix)) {
3908 parsed = BADLEN_PARSE;
3912 pbuf += sprintf(pbuf, "\n source code %d; diag code: %2Xh",
3913 source_code, diag_code);
3914 pbuf += sprintf(pbuf, "\n Time of last fix:%s", show_time(time_of_fix));
3915 pbuf += sprintf(pbuf, "\n Week of last fix: %d", week_num);
3920 rpt_GPS_system_data(
3926 op_code, data_type, sv_prn,
3927 data_length, data_packet[250];
3948 {"", "", "Almanac Orbit",
3949 "Health Page & Ref Time", "Ionosphere", "UTC ",
3953 if (rpt_0x58 (rpt, &op_code, &data_type, &sv_prn,
3954 &data_length, data_packet))
3956 parsed = BADLEN_PARSE;
3960 pbuf += sprintf(pbuf, "\nSystem data [%d]: %s SV%02d",
3961 data_type, datname[data_type], sv_prn);
3965 pbuf += sprintf(pbuf, " Acknowledgment");
3968 pbuf += sprintf(pbuf, " length = %d bytes", data_length);
3969 switch (data_type) {
3972 if (sv_prn == 0 || sv_prn > 32) {
3973 pbuf += sprintf(pbuf, " Binary PRN invalid");
3976 almanac = (ALM_INFO*)data_packet;
3977 pbuf += sprintf(pbuf, "\n t_oa_raw = % -12d SV_hlth = % -12d ",
3978 almanac->t_oa_raw , almanac->SV_health );
3979 pbuf += sprintf(pbuf, "\n e = % -12g t_oa = % -12g ",
3980 almanac->e , almanac->t_oa );
3981 pbuf += sprintf(pbuf, "\n i_0 = % -12g OMEGADOT = % -12g ",
3982 almanac->i_0 , almanac->OMEGADOT );
3983 pbuf += sprintf(pbuf, "\n sqrt_A = % -12g OMEGA_0 = % -12g ",
3984 almanac->sqrt_A , almanac->OMEGA_0 );
3985 pbuf += sprintf(pbuf, "\n omega = % -12g M_0 = % -12g ",
3986 almanac->omega , almanac->M_0 );
3987 pbuf += sprintf(pbuf, "\n a_f0 = % -12g a_f1 = % -12g ",
3988 almanac->a_f0 , almanac->a_f1 );
3989 pbuf += sprintf(pbuf, "\n Axis = % -12g n = % -12g ",
3990 almanac->Axis , almanac->n );
3991 pbuf += sprintf(pbuf, "\n OMEGA_n = % -12g ODOT_n = % -12g ",
3992 almanac->OMEGA_n , almanac->ODOT_n );
3993 pbuf += sprintf(pbuf, "\n t_zc = % -12g weeknum = % -12d ",
3994 almanac->t_zc , almanac->weeknum );
3995 pbuf += sprintf(pbuf, "\n wn_oa = % -12d", almanac->wn_oa );
3999 /* Almanac health page */
4000 almh = (ALH_PARMS*)data_packet;
4001 pbuf += sprintf(pbuf, "\n t_oa = %d, wn_oa&0xFF = %d ",
4002 almh->t_oa, almh->WN_a);
4003 pbuf += sprintf(pbuf, "\nAlmanac health page:");
4004 for (iprn = 0; iprn < 32; iprn++) {
4005 if (!(iprn%5)) *pbuf++ = '\n';
4006 pbuf += sprintf(pbuf, " SV%02d %2X",
4007 (iprn+1) , almh->SV_health[iprn]);
4009 curr_t_oa = data_packet[34];
4010 curr_wn_oa = (unsigned short)((data_packet[35]<<8) + data_packet[36]);
4011 pbuf += sprintf(pbuf, "\n current t_oa = %d, wn_oa = %d ",
4012 curr_t_oa, curr_wn_oa);
4017 ionosphere = (ION_INFO*)data_packet;
4018 pbuf += sprintf(pbuf, "\n alpha_0 = % -12g alpha_1 = % -12g ",
4019 ionosphere->alpha_0, ionosphere->alpha_1);
4020 pbuf += sprintf(pbuf, "\n alpha_2 = % -12g alpha_3 = % -12g ",
4021 ionosphere->alpha_2, ionosphere->alpha_3);
4022 pbuf += sprintf(pbuf, "\n beta_0 = % -12g beta_1 = % -12g ",
4023 ionosphere->beta_0, ionosphere->beta_1);
4024 pbuf += sprintf(pbuf, "\n beta_2 = % -12g beta_3 = % -12g ",
4025 ionosphere->beta_2, ionosphere->beta_3);
4030 utc = (UTC_INFO*)data_packet;
4031 pbuf += sprintf(pbuf, "\n A_0 = %g ", utc->A_0);
4032 pbuf += sprintf(pbuf, "\n A_1 = %g ", utc->A_1);
4033 pbuf += sprintf(pbuf, "\n delta_t_LS = %d ", utc->delta_t_LS);
4034 pbuf += sprintf(pbuf, "\n t_ot = %.0f ", utc->t_ot );
4035 pbuf += sprintf(pbuf, "\n WN_t = %d ", utc->WN_t );
4036 pbuf += sprintf(pbuf, "\n WN_LSF = %d ", utc->WN_LSF );
4037 pbuf += sprintf(pbuf, "\n DN = %d ", utc->DN );
4038 pbuf += sprintf(pbuf, "\n delta_t_LSF = %d ", utc->delta_t_LSF );
4041 case 6: /* Ephemeris */
4042 if (sv_prn == 0 || sv_prn > 32) {
4043 pbuf += sprintf(pbuf, " Binary PRN invalid");
4046 nav_data = (NAV_INFO*)data_packet;
4048 pbuf += sprintf(pbuf, "\n SV_PRN = % -12d . t_ephem = % -12g . ",
4049 nav_data->sv_number , nav_data->t_ephem );
4050 cdata = &(nav_data->ephclk);
4051 pbuf += sprintf(pbuf,
4052 "\n weeknum = % -12d . codeL2 = % -12d . L2Pdata = % -12d",
4053 cdata->weeknum , cdata->codeL2 , cdata->L2Pdata );
4054 pbuf += sprintf(pbuf,
4055 "\n SVacc_raw = % -12d .SV_health = % -12d . IODC = % -12d",
4056 cdata->SVacc_raw, cdata->SV_health, cdata->IODC );
4057 pbuf += sprintf(pbuf,
4058 "\n T_GD = % -12g . t_oc = % -12g . a_f2 = % -12g",
4059 cdata->T_GD, cdata->t_oc, cdata->a_f2 );
4060 pbuf += sprintf(pbuf,
4061 "\n a_f1 = % -12g . a_f0 = % -12g . SVacc = % -12g",
4062 cdata->a_f1, cdata->a_f0, cdata->SVacc );
4063 edata = &(nav_data->ephorb);
4064 pbuf += sprintf(pbuf,
4065 "\n IODE = % -12d .fit_intvl = % -12d . C_rs = % -12g",
4066 edata->IODE, edata->fit_interval, edata->C_rs );
4067 pbuf += sprintf(pbuf,
4068 "\n delta_n = % -12g . M_0 = % -12g . C_uc = % -12g",
4069 edata->delta_n, edata->M_0, edata->C_uc );
4070 pbuf += sprintf(pbuf,
4071 "\n ecc = % -12g . C_us = % -12g . sqrt_A = % -12g",
4072 edata->e, edata->C_us, edata->sqrt_A );
4073 pbuf += sprintf(pbuf,
4074 "\n t_oe = % -12g . C_ic = % -12g . OMEGA_0 = % -12g",
4075 edata->t_oe, edata->C_ic, edata->OMEGA_0 );
4076 pbuf += sprintf(pbuf,
4077 "\n C_is = % -12g . i_0 = % -12g . C_rc = % -12g",
4078 edata->C_is, edata->i_0, edata->C_rc );
4079 pbuf += sprintf(pbuf,
4080 "\n omega = % -12g . OMEGADOT = % -12g . IDOT = % -12g",
4081 edata->omega, edata->OMEGADOT, edata->IDOT );
4082 pbuf += sprintf(pbuf,
4083 "\n Axis = % -12g . n = % -12g . r1me2 = % -12g",
4084 edata->Axis, edata->n, edata->r1me2 );
4085 pbuf += sprintf(pbuf,
4086 "\n OMEGA_n = % -12g . ODOT_n = % -12g",
4087 edata->OMEGA_n, edata->ODOT_n );
4108 if (rpt_0x59 (rpt, &code_type, status_code))
4110 parsed = BADLEN_PARSE;
4115 case 3: pbuf += sprintf(pbuf, "\nSVs Disabled:\n"); break;
4116 case 6: pbuf += sprintf(pbuf, "\nSVs with Health Ignored:\n"); break;
4120 for (iprn = 0; iprn < 32; iprn++)
4122 if (status_code[iprn])
4124 pbuf += sprintf(pbuf, " %02d", iprn+1);
4128 if (numsvs == 0) pbuf += sprintf(pbuf, "None");
4141 sample_length, signal_level, code_phase, Doppler;
4146 if (rpt_0x5A (rpt, &sv_prn, &sample_length, &signal_level,
4147 &code_phase, &Doppler, &time_of_fix))
4149 parsed = BADLEN_PARSE;
4153 pbuf += sprintf(pbuf, "\n %02d %5.0f %7.1f %10.2f %10.2f %12.3f %s",
4154 sv_prn, sample_length, signal_level, code_phase, Doppler, time_of_fix,
4155 show_time ((float)time_of_fix));
4160 rpt_SV_ephemeris_status(
4165 sv_prn, sv_health, sv_iode, fit_interval_flag;
4167 time_of_collection, time_of_eph, sv_accy;
4170 if (rpt_0x5B (rpt, &sv_prn, &sv_health, &sv_iode, &fit_interval_flag,
4171 &time_of_collection, &time_of_eph, &sv_accy))
4173 parsed = BADLEN_PARSE;
4177 pbuf += sprintf(pbuf, "\n SV%02d %s %2Xh %2Xh ",
4178 sv_prn, show_time (time_of_collection), sv_health, sv_iode);
4179 /* note: cannot use show_time twice in same call */
4180 pbuf += sprintf(pbuf, "%s %1d %4.1f",
4181 show_time (time_of_eph), fit_interval_flag, sv_accy);
4186 rpt_SV_tracking_status(
4191 sv_prn, chan, slot, acq_flag, eph_flag,
4192 old_msmt_flag, integer_msec_flag, bad_data_flag,
4195 signal_level, time_of_last_msmt,
4200 &sv_prn, &slot, &chan, &acq_flag, &eph_flag,
4201 &signal_level, &time_of_last_msmt, &elev, &azim,
4202 &old_msmt_flag, &integer_msec_flag, &bad_data_flag,
4203 &data_collect_flag))
4205 parsed = BADLEN_PARSE;
4209 pbuf += sprintf(pbuf,
4210 "\n SV%2d %1d %1d %1d %4.1f %s %5.1f %5.1f",
4212 acq_flag, eph_flag, signal_level,
4213 show_time(time_of_last_msmt),
4214 elev*R2D, azim*R2D);
4220 rpt_allSV_selection(
4225 manual_mode, nsvs, sv_prn[8], ndim;
4229 pdop, hdop, vdop, tdop;
4233 &manual_mode, &nsvs, &ndim, sv_prn,
4234 &pdop, &hdop, &vdop, &tdop))
4236 parsed = BADLEN_PARSE;
4243 pbuf += sprintf(pbuf, "\nMode: Searching, %d-SV:", nsvs);
4246 pbuf += sprintf(pbuf, "\nMode: One-SV Timing:");
4249 pbuf += sprintf(pbuf, "\nMode: %c-%dD, %d-SV:",
4250 manual_mode ? 'M' : 'A', ndim - 1, nsvs);
4253 pbuf += sprintf(pbuf, "\nMode: Timing, %d-SV:", nsvs);
4256 pbuf += sprintf(pbuf, "\nMode: Unknown = %d:", ndim);
4260 for (islot = 0; islot < nsvs; islot++)
4262 if (sv_prn[islot]) pbuf += sprintf(pbuf, " %02d", sv_prn[islot]);
4264 if (ndim == 3 || ndim == 4)
4266 pbuf += sprintf(pbuf, "; DOPs: P %.1f H %.1f V %.1f T %.1f",
4267 pdop, hdop, vdop, tdop);
4274 rpt_DGPS_position_mode(
4282 if (rpt_0x82 (rpt, &diff_mode)) {
4283 parsed = BADLEN_PARSE;
4287 pbuf += sprintf(pbuf, "\nFix is%s DGPS-corrected (%s mode) (%d)",
4288 (diff_mode&1) ? "" : " not",
4289 (diff_mode&2) ? "auto" : "manual",
4295 rpt_double_ECEF_position(
4300 ECEF_pos[3], clock_bias;
4305 if (rpt_0x83 (rpt, ECEF_pos, &clock_bias, &time_of_fix))
4307 parsed = BADLEN_PARSE;
4311 pbuf += sprintf(pbuf, "\nDXYZ:%12.2f %13.2f %13.2f %12.2f%s",
4312 ECEF_pos[0], ECEF_pos[1], ECEF_pos[2], clock_bias,
4313 show_time(time_of_fix));
4318 rpt_double_lla_position(
4325 lat, lon, lat_min, lon_min,
4330 north_south, east_west;
4334 &lat, &lon, &alt, &clock_bias, &time_of_fix))
4336 parsed = BADLEN_PARSE;
4348 lat_deg = (short)lat;
4349 lat_min = (lat - lat_deg) * 60.0;
4357 lon_deg = (short)lon;
4358 lon_min = (lon - lon_deg) * 60.0;
4359 pbuf += sprintf(pbuf, "\nDLLA: %2d:%08.5f %c; %3d:%08.5f %c; %10.2f %12.2f%s",
4360 lat_deg, lat_min, north_south,
4361 lon_deg, lon_min, east_west,
4363 show_time(time_of_fix));
4368 rpt_complete_rcvr_config(
4372 TSIP_RCVR_CFG TsipxBB ;
4374 if (rpt_Paly0xBB (rpt, &TsipxBB))
4376 parsed = BADLEN_PARSE;
4380 pbuf += sprintf(pbuf, "\n operating mode: %s",
4381 NavModeText0xBB[TsipxBB.operating_mode]);
4382 pbuf += sprintf(pbuf, "\n dynamics: %s",
4383 dyn_text[TsipxBB.dyn_code]);
4384 pbuf += sprintf(pbuf, "\n elev angle mask: %g deg",
4385 TsipxBB.elev_mask * R2D);
4386 pbuf += sprintf(pbuf, "\n SNR mask: %g AMU",
4388 pbuf += sprintf(pbuf, "\n DOP mask: %g",
4390 pbuf += sprintf(pbuf, "\n DOP switch: %g",
4391 TsipxBB.dop_switch);
4397 rpt_rcvr_serial_port_config(
4402 port_num, in_baud, out_baud, data_bits, parity, stop_bits, flow_control,
4403 protocols_in, protocols_out, reserved;
4404 unsigned char known;
4407 if (rpt_0xBC (rpt, &port_num, &in_baud, &out_baud, &data_bits, &parity,
4408 &stop_bits, &flow_control, &protocols_in, &protocols_out, &reserved)) {
4409 parsed = BADLEN_PARSE;
4412 /* rptbuf unloaded */
4414 pbuf += sprintf(pbuf, "\n RECEIVER serial port %s config:",
4415 rcvr_port_text[port_num]);
4417 pbuf += sprintf(pbuf, "\n I/O Baud %s/%s, %d - %s - %d",
4418 st_baud_text_app[in_baud],
4419 st_baud_text_app[out_baud],
4421 parity_text[parity],
4423 pbuf += sprintf(pbuf, "\n Input protocols: ");
4425 if (protocols_in&B_TSIP)
4427 pbuf += sprintf(pbuf, "%s ", protocols_in_text[1]);
4430 if (known == FALSE) pbuf += sprintf(pbuf, "No known");
4432 pbuf += sprintf(pbuf, "\n Output protocols: ");
4434 if (protocols_out&B_TSIP)
4436 pbuf += sprintf(pbuf, "%s ", protocols_out_text[1]);
4439 if (protocols_out&B_NMEA)
4441 pbuf += sprintf(pbuf, "%s ", protocols_out_text[2]);
4444 if (known == FALSE) pbuf += sprintf(pbuf, "No known");
4445 reserved = reserved;
4459 "full position (3-D)",
4460 "single satellite (0-D)",
4464 "overdetermined clock"};
4515 parsed = BADLEN_PARSE;
4521 pbuf += sprintf(pbuf, "\nNew partial+full meas");
4525 pbuf += sprintf(pbuf, "\nEvent count: %5d", event);
4528 pbuf += sprintf(pbuf, "\nGPS time : %s %2d/%2d/%2d (DMY)",
4529 show_time(tow), date, month, year);
4530 pbuf += sprintf(pbuf, "\nMode : %s", oprtng_dim[dim_mode]);
4531 pbuf += sprintf(pbuf, "\nUTC offset: %2d", utc_offset);
4532 pbuf += sprintf(pbuf, "\nClock Bias: %6.2f m", bias);
4533 pbuf += sprintf(pbuf, "\nFreq bias : %6.2f m/s", drift);
4534 pbuf += sprintf(pbuf, "\nBias unc : %6.2f m", bias_unc);
4535 pbuf += sprintf(pbuf, "\nFreq unc : %6.2f m/s", dr_unc);
4537 lat *= R2D; /* convert from radians to degrees */
4549 lat_deg = (short)lat;
4550 lat_min = (lat - lat_deg) * 60.0;
4561 lon_deg = (short)lon;
4562 lon_min = (lon - lon_deg) * 60.0;
4563 pbuf += sprintf(pbuf, "\nPosition :");
4564 pbuf += sprintf(pbuf, " %4d %6.3f %c", lat_deg, lat_min, north_south);
4565 pbuf += sprintf(pbuf, " %5d %6.3f %c", lon_deg, lon_min, east_west);
4566 pbuf += sprintf(pbuf, " %10.2f", alt);
4568 numfix = numnotfix = 0;
4569 for (local_index=0; local_index<8; local_index++)
4571 if (sv_id[local_index] < 0) numnotfix++;
4572 if (sv_id[local_index] > 0) numfix++;
4576 pbuf += sprintf(pbuf, "\nSVs used in fix : ");
4577 for (local_index=0; local_index<8; local_index++)
4579 if (sv_id[local_index] > 0)
4581 pbuf += sprintf(pbuf, "%2d ", sv_id[local_index]);
4587 pbuf += sprintf(pbuf, "\nOther SVs tracked: ");
4588 for (local_index=0; local_index<8; local_index++)
4590 if (sv_id[local_index] < 0)
4592 pbuf += sprintf(pbuf, "%2d ", sv_id[local_index]);
4599 /* Datum parameters */
4611 if (rpt_0x8F14 (rpt, &datum_idx, datum_coeffs))
4613 parsed = BADLEN_PARSE;
4617 if (datum_idx == -1)
4619 pbuf += sprintf(pbuf, "\nUser-Entered Datum:");
4620 pbuf += sprintf(pbuf, "\n dx = %6.1f", datum_coeffs[0]);
4621 pbuf += sprintf(pbuf, "\n dy = %6.1f", datum_coeffs[1]);
4622 pbuf += sprintf(pbuf, "\n dz = %6.1f", datum_coeffs[2]);
4623 pbuf += sprintf(pbuf, "\n a-axis = %10.3f", datum_coeffs[3]);
4624 pbuf += sprintf(pbuf, "\n e-squared = %16.14f", datum_coeffs[4]);
4626 else if (datum_idx == 0)
4628 pbuf += sprintf(pbuf, "\nWGS-84 datum, Index 0 ");
4632 pbuf += sprintf(pbuf, "\nStandard Datum, Index %3d ", datum_idx);
4637 /* Datum parameters */
4649 if (rpt_0x8F15 (rpt, &datum_idx, datum_coeffs)) {
4650 parsed = BADLEN_PARSE;
4654 if (datum_idx == -1)
4656 pbuf += sprintf(pbuf, "\nUser-Entered Datum:");
4657 pbuf += sprintf(pbuf, "\n dx = %6.1f", datum_coeffs[0]);
4658 pbuf += sprintf(pbuf, "\n dy = %6.1f", datum_coeffs[1]);
4659 pbuf += sprintf(pbuf, "\n dz = %6.1f", datum_coeffs[2]);
4660 pbuf += sprintf(pbuf, "\n a-axis = %10.3f", datum_coeffs[3]);
4661 pbuf += sprintf(pbuf, "\n e-squared = %16.14f", datum_coeffs[4]);
4663 else if (datum_idx == 0)
4665 pbuf += sprintf(pbuf, "\nWGS-84 datum, Index 0 ");
4669 pbuf += sprintf(pbuf, "\nStandard Datum, Index %3d ", datum_idx);
4674 #define INFO_DGPS 0x02
4675 #define INFO_2D 0x04
4676 #define INFO_ALTSET 0x08
4677 #define INFO_FILTERED 0x10
4684 info, nsvs, sv_prn[32];
4686 week_num, datum_index, sv_IODC[32];
4688 lat, lon, alt, time_of_fix;
4690 londeg, latdeg, vel[3];
4697 if (rpt_0x8F20 (rpt,
4698 &info, &lat, &lon, &alt, vel,
4700 &week_num, &nsvs, sv_prn, sv_IODC, &datum_index))
4702 parsed = BADLEN_PARSE;
4705 pbuf += sprintf(pbuf,
4706 "\nFix at: %04d:%3s:%02d:%02d:%06.3f GPS (=UTC+%2ds) FixType: %s%s%s",
4708 dayname[(short)(time_of_fix/86400.0)],
4709 (short)fmod(time_of_fix/3600., 24.),
4710 (short)fmod(time_of_fix/60., 60.),
4711 fmod(time_of_fix, 60.),
4712 (char)rpt->buf[29], /* UTC offset */
4713 (info & INFO_DGPS)?"Diff":"",
4714 (info & INFO_2D)?"2D":"3D",
4715 (info & INFO_FILTERED)?"-Filtrd":"");
4717 if (datum_index > 0)
4719 sprintf(datum_string, "Datum%3d", datum_index);
4721 else if (datum_index)
4723 sprintf(datum_string, "Unknown ");
4727 sprintf(datum_string, "WGS-84");
4730 /* convert from radians to degrees */
4731 latdeg = R2D * fabs(lat);
4732 londeg = R2D * fabs(lon);
4733 pbuf += sprintf(pbuf,
4734 "\n Pos: %4d:%09.6f %c %5d:%09.6f %c %10.2f m HAE (%s)",
4735 (short)latdeg, fmod (latdeg, 1.)*60.0,
4737 (short)londeg, fmod (londeg, 1.)*60.0,
4741 pbuf += sprintf(pbuf,
4742 "\n Vel: %9.3f E %9.3f N %9.3f U (m/sec)",
4743 vel[0], vel[1], vel[2]);
4745 pbuf += sprintf(pbuf,
4747 for (isv = 0; isv < nsvs; isv++) {
4748 pbuf += sprintf(pbuf, " %02d", sv_prn[isv]);
4750 pbuf += sprintf(pbuf, " (IODEs:");
4751 for (isv = 0; isv < nsvs; isv++) {
4752 pbuf += sprintf(pbuf, " %02X", sv_IODC[isv]&0xFF);
4754 pbuf += sprintf(pbuf, ")");
4777 if (!rpt_0x8F41(rpt,
4788 parsed = BADLEN_PARSE;
4792 pbuf += sprintf(pbuf, "\n search range: %d",
4794 pbuf += sprintf(pbuf, "\n board options: %d",
4796 pbuf += sprintf(pbuf, "\n board serial #: %ld",
4798 pbuf += sprintf(pbuf, "\n build date/hour: %02d/%02d/%02d %02d:00",
4799 bBuildDay, bBuildMonth, bBuildYear, bBuildHour);
4800 pbuf += sprintf(pbuf, "\n osc offset: %.3f PPM (%.0f Hz)",
4801 fOscOffset/1575.42, fOscOffset);
4802 pbuf += sprintf(pbuf, "\n test code: %d",
4816 iCaseSerialNumberPre,
4824 if (!rpt_0x8F42(rpt,
4827 &iCaseSerialNumberPre,
4828 &iiCaseSerialNumber,
4834 parsed = BADLEN_PARSE;
4838 pbuf += sprintf(pbuf, "\nProduct ID 8F42");
4839 pbuf += sprintf(pbuf, "\n extension: %d", bProdNumberExt);
4840 pbuf += sprintf(pbuf, "\n case serial # prefix: %d", iCaseSerialNumberPre);
4841 pbuf += sprintf(pbuf, "\n case serial #: %ld", iiCaseSerialNumber);
4842 pbuf += sprintf(pbuf, "\n prod. #: %ld", iiProdNumber);
4843 pbuf += sprintf(pbuf, "\n premium options: %Xh", iPremiumOptions);
4844 pbuf += sprintf(pbuf, "\n machine ID: %d", iMachineID);
4845 pbuf += sprintf(pbuf, "\n key: %Xh", iKey);
4854 unsigned char bSegMask;
4856 if (!rpt_0x8F45(rpt,
4859 parsed = BADLEN_PARSE;
4862 pbuf += sprintf(pbuf, "\nCleared Segment Mask: %Xh", bSegMask);
4865 /* Stinger PPS def */
4880 if (rpt_0x8F4A_16 (rpt,
4885 &bias_unc_threshold))
4887 parsed = BADLEN_PARSE;
4891 pbuf += sprintf(pbuf, "\nPPS is %s", pps_enabled?"enabled":"disabled");
4892 pbuf += sprintf(pbuf, "\n timebase: %s", PPSTimeBaseText[pps_timebase]);
4893 pbuf += sprintf(pbuf, "\n polarity: %s", PPSPolarityText[pps_polarity]);
4894 pbuf += sprintf(pbuf, "\n offset: %.1f ns, ", pps_offset*1.e9);
4895 pbuf += sprintf(pbuf, "\n biasunc: %.1f ns", bias_unc_threshold/GPS_C*1.e9);
4898 /* fast-SA decorrolation time for self-survey */
4907 if (rpt_0x8F4B(rpt, &decorr_max))
4909 parsed = BADLEN_PARSE;
4913 pbuf += sprintf(pbuf,
4914 "\nMax # of position fixes for self-survey : %ld",
4927 static unsigned long
4929 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010,
4931 0x00000100L, 0x00000800L, 0x00001000L,
4932 0x40000000L, 0x80000000L};
4937 if (rpt_0x8F4D(rpt, &OutputMask))
4939 parsed = BADLEN_PARSE;
4943 pbuf += sprintf(pbuf, "\nAuto-Report Mask: %02X %02X %02X %02X",
4944 (unsigned char)(OutputMask>>24),
4945 (unsigned char)(OutputMask>>16),
4946 (unsigned char)(OutputMask>>8),
4947 (unsigned char)OutputMask);
4949 numchoices = sizeof(MaskText)/sizeof(char*);
4950 pbuf += sprintf(pbuf, "\nAuto-Reports scheduled for Output:");
4952 for (ichoice = 0; ichoice < numchoices; ichoice++)
4954 if (OutputMask&MaskBit[ichoice])
4956 pbuf += sprintf(pbuf, "%s %s",
4957 (pbuf==linestart)?"\n ":",",
4959 if (pbuf-linestart > 60) linestart = pbuf;
4963 pbuf += sprintf(pbuf, "\nAuto-Reports NOT scheduled for Output:");
4965 for (ichoice = 0; ichoice < numchoices; ichoice++)
4967 if (OutputMask&MaskBit[ichoice]) continue;
4968 pbuf += sprintf(pbuf, "%s %s",
4969 (pbuf==linestart)?"\n ":",",
4971 if (pbuf-linestart > 60) linestart = pbuf;
4983 if (rpt_0x8FA5(rpt, spktmask))
4985 parsed = BADLEN_PARSE;
4989 pbuf += sprintf(pbuf, "\nSuperpacket auto-output mask: %02X %02X %02X %02X",
4990 spktmask[0], spktmask[1], spktmask[2], spktmask[3]);
4992 if (spktmask[0]&0x01) pbuf+= sprintf (pbuf, "\n PPS 8F-0B");
4993 if (spktmask[0]&0x02) pbuf+= sprintf (pbuf, "\n Event 8F-0B");
4994 if (spktmask[0]&0x10) pbuf+= sprintf (pbuf, "\n PPS 8F-AD");
4995 if (spktmask[0]&0x20) pbuf+= sprintf (pbuf, "\n Event 8F-AD");
4996 if (spktmask[2]&0x01) pbuf+= sprintf (pbuf, "\n ppos Fix 8F-20");
5017 static char* Status8FADText[] = {
5022 "CODE_NEED_INITIALIZATION",
5029 "CODE_NO_INTEGRITY",
5033 *LeapStatusText[] = {
5034 " UTC Avail", " ", " ", " ",
5035 " Scheduled", " Pending", " Warning", " In Progress"};
5038 if (rpt_0x8FAD (rpt,
5050 parsed = BADLEN_PARSE;
5054 pbuf += sprintf(pbuf, "\n8FAD Count: %d Status: %s",
5055 Count, Status8FADText[Status]);
5057 pbuf += sprintf(pbuf, "\n Leap Flags:");
5062 if (Flags&(1<<i)) pbuf += sprintf(pbuf, LeapStatusText[i]);
5067 pbuf += sprintf(pbuf, " UTC info not available");
5070 pbuf += sprintf(pbuf, "\n %02d/%02d/%04d (DMY) %02d:%02d:%02d.%09ld UTC",
5071 Day, Month, Year, Hour, Minute, Second, (long)(FracSec*1.e9));
5076 print_msg_table_header(
5082 /* force header is to help auto-output function */
5083 /* last_rptcode is to determine whether to print a header */
5084 /* for the first occurrence of a series of reports */
5091 if (force || rptcode!=last_rptcode)
5093 /* supply a header in console output */
5097 numchars = sprintf(HdrStr, "\nRaw Measurement Data");
5098 numchars += sprintf(HdrStr+numchars,
5099 "\n SV Sample SNR Code Phase Doppler Seconds Time of Meas");
5103 numchars = sprintf(HdrStr, "\nEphemeris Status");
5104 numchars += sprintf(HdrStr+numchars,
5105 "\n SV Time collected Health IODE t oe Fit URA");
5109 numchars = sprintf(HdrStr, "\nTracking Info");
5110 numchars += sprintf(HdrStr+numchars,
5111 "\n SV C Acq Eph SNR Time of Meas Elev Azim ");
5116 last_rptcode = rptcode;
5117 return (short)numchars;
5127 /* app-specific rpt packets */
5128 if (parsed == BADLEN_PARSE)
5130 pbuf += sprintf(pbuf, "\nTSIP report packet ID %2Xh, length %d: Bad length",
5131 rpt->code, rpt->len);
5133 if (parsed == BADID_PARSE)
5135 pbuf += sprintf(pbuf,
5136 "\nTSIP report packet ID %2Xh, length %d: translation not supported",
5137 rpt->code, rpt->len);
5140 if (parsed == BADDATA_PARSE)
5142 pbuf += sprintf(pbuf,
5143 "\nTSIP report packet ID %2Xh, length %d: data content incorrect",
5144 rpt->code, rpt->len);
5147 for (i = 0; i < rpt->len; i++) {
5148 if ((i % 20) == 0) *pbuf++ = '\n';
5149 pbuf += sprintf(pbuf, " %02X", rpt->buf[i]);
5155 ** main subroutine, called from ProcessInputBytesWhileWaitingForKBHit()
5158 TranslateTSIPReportToText(
5160 char *TextOutputBuffer
5164 /* pbuf is the pointer to the current location of the text output */
5165 pbuf = TextOutputBuffer;
5167 /* keep track of whether the message has been successfully parsed */
5168 parsed = GOOD_PARSE;
5170 /* print a header if this is the first of a series of messages */
5171 pbuf += print_msg_table_header (rpt->code, pbuf, FALSE);
5173 /* process incoming TSIP report according to code */
5176 case 0x3D: rpt_chan_A_config (rpt); break;
5177 case 0x40: rpt_almanac_data_page (rpt); break;
5178 case 0x41: rpt_GPS_time (rpt); break;
5179 case 0x42: rpt_single_ECEF_position (rpt); break;
5180 case 0x43: rpt_single_ECEF_velocity (rpt); break;
5181 case 0x45: rpt_SW_version (rpt); break;
5182 case 0x46: rpt_rcvr_health (rpt); break;
5183 case 0x47: rpt_SNR_all_SVs (rpt); break;
5184 case 0x48: rpt_GPS_system_message (rpt); break;
5185 case 0x49: rpt_almanac_health_page (rpt); break;
5186 case 0x4A: switch (rpt->len) {
5188 ** special case (=slip-up) in the TSIP protocol;
5189 ** parsing method depends on length
5191 case 20: rpt_single_lla_position (rpt); break;
5192 case 9: rpt_ref_alt (rpt); break;
5194 case 0x4B: rpt_rcvr_id_and_status (rpt);break;
5195 case 0x4C: rpt_operating_parameters (rpt); break;
5196 case 0x4D: rpt_oscillator_offset (rpt); break;
5197 case 0x4E: rpt_GPS_time_set_response (rpt); break;
5198 case 0x4F: rpt_UTC_offset (rpt); break;
5199 case 0x54: rpt_1SV_bias (rpt); break;
5200 case 0x55: rpt_io_opt (rpt); break;
5201 case 0x56: rpt_ENU_velocity (rpt); break;
5202 case 0x57: rpt_last_fix_info (rpt); break;
5203 case 0x58: rpt_GPS_system_data (rpt); break;
5204 case 0x59: rpt_SVs_enabled (rpt); break;
5205 case 0x5A: rpt_raw_msmt (rpt); break;
5206 case 0x5B: rpt_SV_ephemeris_status (rpt); break;
5207 case 0x5C: rpt_SV_tracking_status (rpt); break;
5208 case 0x6D: rpt_allSV_selection (rpt); break;
5209 case 0x82: rpt_DGPS_position_mode (rpt); break;
5210 case 0x83: rpt_double_ECEF_position (rpt); break;
5211 case 0x84: rpt_double_lla_position (rpt); break;
5212 case 0xBB: rpt_complete_rcvr_config (rpt); break;
5213 case 0xBC: rpt_rcvr_serial_port_config (rpt); break;
5215 case 0x8F: switch (rpt->buf[0])
5217 /* superpackets; parsed according to subcodes */
5218 case 0x0B: rpt_8F0B(rpt); break;
5219 case 0x14: rpt_8F14(rpt); break;
5220 case 0x15: rpt_8F15(rpt); break;
5221 case 0x20: rpt_8F20(rpt); break;
5222 case 0x41: rpt_8F41(rpt); break;
5223 case 0x42: rpt_8F42(rpt); break;
5224 case 0x45: rpt_8F45(rpt); break;
5225 case 0x4A: rpt_8F4A(rpt); break;
5226 case 0x4B: rpt_8F4B(rpt); break;
5227 case 0x4D: rpt_8F4D(rpt); break;
5228 case 0xA5: rpt_8FA5(rpt); break;
5229 case 0xAD: rpt_8FAD(rpt); break;
5230 default: parsed = BADID_PARSE; break;
5234 default: parsed = BADID_PARSE; break;
5237 if (parsed != GOOD_PARSE)
5240 **The message has TSIP structure (DLEs, etc.)
5241 ** but could not be parsed by above routines
5246 /* close TextOutputBuffer */
5250 #endif /* TRIMBLE_OUTPUT_FUNC */
5252 #else /* defined(REFCLOCK) && defined(CLOCK_RIPENCC) */
5253 int refclock_ripencc_bs;
5254 #endif /* defined(REFCLOCK) && defined(CLOCK_RIPENCC) */