diff options
Diffstat (limited to 'contrib/ntp/libparse/clk_trimtsip.c')
-rw-r--r-- | contrib/ntp/libparse/clk_trimtsip.c | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/contrib/ntp/libparse/clk_trimtsip.c b/contrib/ntp/libparse/clk_trimtsip.c index 743e39c..6c71d75 100644 --- a/contrib/ntp/libparse/clk_trimtsip.c +++ b/contrib/ntp/libparse/clk_trimtsip.c @@ -7,7 +7,7 @@ * Thanks to Sven Dietrich for providing test hardware * * Copyright (c) 1995-2009 by Frank Kardel <kardel <AT> ntp.org> - * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany + * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universitaet Erlangen-Nuernberg, Germany * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -116,7 +116,7 @@ struct trimble #define STATUS_UNSAFE 1 /* not enough receivers for full precision */ #define STATUS_SYNC 2 /* enough information for good operation */ -static unsigned long inp_tsip (parse_t *, unsigned int, timestamp_t *); +static unsigned long inp_tsip (parse_t *, char, timestamp_t *); static unsigned long cvt_trimtsip (unsigned char *, int, struct format *, clocktime_t *, void *); struct clockformat clock_trimtsip = @@ -136,7 +136,7 @@ struct clockformat clock_trimtsip = static unsigned long inp_tsip( parse_t *parseio, - unsigned int ch, + char ch, timestamp_t *tstamp ) { @@ -183,7 +183,7 @@ inp_tsip( /* DLE,ETX -> end of packet */ parseio->parse_data[parseio->parse_index++] = DLE; parseio->parse_data[parseio->parse_index] = ch; - parseio->parse_ldsize = parseio->parse_index+1; + parseio->parse_ldsize = (u_short) (parseio->parse_index + 1); memcpy(parseio->parse_ldata, parseio->parse_data, parseio->parse_ldsize); parseio->parse_dtime.parse_msg[parseio->parse_dtime.parse_msglen++] = DLE; parseio->parse_dtime.parse_msg[parseio->parse_dtime.parse_msglen++] = ch; @@ -200,13 +200,13 @@ inp_tsip( return PARSE_INP_SKIP; } - -static int + +static short getshort( unsigned char *p ) { - return get_msb_short(&p); + return (short) get_msb_short(&p); } /* @@ -245,7 +245,7 @@ cvt_trimtsip( { unsigned char *bp; cmd = buffer[1]; - + switch(cmd) { case CMD_RCURTIME: @@ -258,15 +258,15 @@ cvt_trimtsip( bp = &mb(0); if (fetch_ieee754(&bp, IEEE_SINGLE, &secs, trim_offsets) != IEEE_OK) return CVT_FAIL|CVT_BADFMT; - + if ((secs.l_i <= 0) || (t->t_utcknown == 0)) { clock_time->flags = PARSEB_POWERUP; return CVT_OK; } - if (week < 990) { - week += 1024; + if (week < GPSWRAP) { + week += GPSWEEKS; } /* time OK */ @@ -275,7 +275,7 @@ cvt_trimtsip( bp = &mb(6); if (fetch_ieee754(&bp, IEEE_SINGLE, &utcoffset, trim_offsets) != IEEE_OK) return CVT_FAIL|CVT_BADFMT; - + L_SUB(&secs, &utcoffset); /* adjust GPS time to UTC time */ gpstolfp((unsigned short)week, (unsigned short)0, @@ -289,10 +289,10 @@ cvt_trimtsip( if (t->t_leap == ADDSECOND) clock_time->flags |= PARSEB_LEAPADD; - + if (t->t_leap == DELSECOND) clock_time->flags |= PARSEB_LEAPDEL; - + switch (t->t_operable) { case STATUS_SYNC: @@ -307,12 +307,12 @@ cvt_trimtsip( clock_time->flags |= PARSEB_NOSYNC|PARSEB_POWERUP; break; } - + if (t->t_mode == 0) clock_time->flags |= PARSEB_POSITION; - + clock_time->flags |= PARSEB_S_LEAP|PARSEB_S_POSITION; - + return CVT_OK; } /* case 0x41 */ @@ -346,26 +346,26 @@ cvt_trimtsip( { l_fp t0t; unsigned char *lbp; - + /* UTC correction data - derive a leap warning */ - int tls = t->t_gpsutc = getshort((unsigned char *)&mb(12)); /* current leap correction (GPS-UTC) */ - int tlsf = t->t_gpsutcleap = getshort((unsigned char *)&mb(24)); /* new leap correction */ - - t->t_weekleap = getshort((unsigned char *)&mb(20)); /* week no of leap correction */ - if (t->t_weekleap < 990) - t->t_weekleap += 1024; - - t->t_dayleap = getshort((unsigned char *)&mb(22)); /* day in week of leap correction */ - t->t_week = getshort((unsigned char *)&mb(18)); /* current week no */ - if (t->t_week < 990) - t->t_week += 1024; - + int tls = t->t_gpsutc = (u_short) getshort((unsigned char *)&mb(12)); /* current leap correction (GPS-UTC) */ + int tlsf = t->t_gpsutcleap = (u_short) getshort((unsigned char *)&mb(24)); /* new leap correction */ + + t->t_weekleap = (u_short) getshort((unsigned char *)&mb(20)); /* week no of leap correction */ + if (t->t_weekleap < GPSWRAP) + t->t_weekleap = (u_short)(t->t_weekleap + GPSWEEKS); + + t->t_dayleap = (u_short) getshort((unsigned char *)&mb(22)); /* day in week of leap correction */ + t->t_week = (u_short) getshort((unsigned char *)&mb(18)); /* current week no */ + if (t->t_week < GPSWRAP) + t->t_week = (u_short)(t->t_weekleap + GPSWEEKS); + lbp = (unsigned char *)&mb(14); /* last update time */ if (fetch_ieee754(&lbp, IEEE_SINGLE, &t0t, trim_offsets) != IEEE_OK) return CVT_FAIL|CVT_BADFMT; t->t_utcknown = t0t.l_ui != 0; - + if ((t->t_utcknown) && /* got UTC information */ (tlsf != tls) && /* something will change */ ((t->t_weekleap - t->t_week) < 5)) /* and close in the future */ |