summaryrefslogtreecommitdiff
path: root/ntpd/refclock_jupiter.c
diff options
context:
space:
mode:
Diffstat (limited to 'ntpd/refclock_jupiter.c')
-rw-r--r--ntpd/refclock_jupiter.c109
1 files changed, 54 insertions, 55 deletions
diff --git a/ntpd/refclock_jupiter.c b/ntpd/refclock_jupiter.c
index 377fc56..02b33df 100644
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -136,8 +136,8 @@ static int jupiter_config (struct instance *);
static void jupiter_debug (struct peer *, const char *,
const char *, ...)
__attribute__ ((format (printf, 3, 4)));
-static char * jupiter_parse_t (struct instance *, u_short *);
-static char * jupiter_parse_gpos (struct instance *, u_short *);
+static const char * jupiter_parse_t (struct instance *, u_short *);
+static const char * jupiter_parse_gpos (struct instance *, u_short *);
static void jupiter_platform (struct instance *, u_int);
static void jupiter_poll (int, struct peer *);
static void jupiter_control (int, const struct refclockstat *,
@@ -275,7 +275,7 @@ jupiter_shutdown(int unit, struct peer *peer)
static int
jupiter_config(struct instance *instance)
{
- jupiter_debug(instance->peer, "jupiter_config", "init receiver");
+ jupiter_debug(instance->peer, __func__, "init receiver");
/*
* Initialize the unit variables
@@ -283,8 +283,7 @@ jupiter_config(struct instance *instance)
instance->sloppyclockflag = instance->peer->procptr->sloppyclockflag;
instance->moving = !!(instance->sloppyclockflag & CLK_FLAG2);
if (instance->moving)
- jupiter_debug(instance->peer, "jupiter_config",
- "mobile platform");
+ jupiter_debug(instance->peer, __func__, "mobile platform");
instance->pollcnt = 2;
instance->polled = 0;
@@ -368,7 +367,7 @@ jupiter_ppsapi(
#if DEBUG
if (debug) {
time_pps_getparams(instance->pps_handle, &instance->pps_params);
- jupiter_debug(instance->peer, "refclock_jupiter",
+ jupiter_debug(instance->peer, __func__,
"pps capability 0x%x version %d mode 0x%x kern %d",
capability, instance->pps_params.api_version,
instance->pps_params.mode, instance->hardpps);
@@ -498,8 +497,7 @@ jupiter_control(
instance->sloppyclockflag = pp->sloppyclockflag;
if ((instance->sloppyclockflag & CLK_FLAG2) !=
(sloppyclockflag & CLK_FLAG2)) {
- jupiter_debug(peer,
- "jupiter_control",
+ jupiter_debug(peer, __func__,
"mode switch: reset receiver");
jupiter_config(instance);
return;
@@ -513,10 +511,11 @@ jupiter_control(
static void
jupiter_receive(struct recvbuf *rbufp)
{
- int bpcnt, cc, size, ppsret;
+ size_t bpcnt;
+ int cc, size, ppsret;
time_t last_timecode;
u_int32 laststime;
- char *cp;
+ const char *cp;
u_char *bp;
u_short *sp;
struct jid *ip;
@@ -535,7 +534,7 @@ jupiter_receive(struct recvbuf *rbufp)
bpcnt = rbufp->recv_length;
/* This shouldn't happen */
- if (bpcnt > (int)sizeof(instance->sbuf) - instance->ssize)
+ if (bpcnt > sizeof(instance->sbuf) - instance->ssize)
bpcnt = sizeof(instance->sbuf) - instance->ssize;
/* Append to input buffer */
@@ -543,7 +542,7 @@ jupiter_receive(struct recvbuf *rbufp)
instance->ssize += bpcnt;
/* While there's at least a header and we parse an intact message */
- while (instance->ssize > sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) {
+ while (instance->ssize > (int)sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) {
instance->pollcnt = 2;
tstamp = rbufp->recv_time;
@@ -554,8 +553,8 @@ jupiter_receive(struct recvbuf *rbufp)
case JUPITER_O_PULSE:
if (size != sizeof(struct jpulse)) {
- jupiter_debug(peer,
- "jupiter_receive", "pulse: len %d != %u",
+ jupiter_debug(peer, __func__,
+ "pulse: len %d != %u",
size, (int)sizeof(struct jpulse));
refclock_report(peer, CEVNT_BADREPLY);
break;
@@ -574,7 +573,7 @@ jupiter_receive(struct recvbuf *rbufp)
laststime = instance->stime;
instance->stime = DS2UI(((struct jpulse *)sp)->stime);
if (laststime != 0 && instance->stime - laststime <= 21) {
- jupiter_debug(peer, "jupiter_receive",
+ jupiter_debug(peer, __func__,
"avoided firmware bug (stime %.2f, laststime %.2f)",
(double)instance->stime * 0.01, (double)laststime * 0.01);
break;
@@ -595,8 +594,8 @@ jupiter_receive(struct recvbuf *rbufp)
/* Parse timecode (even when there's no pps) */
last_timecode = instance->timecode;
if ((cp = jupiter_parse_t(instance, sp)) != NULL) {
- jupiter_debug(peer,
- "jupiter_receive", "pulse: %s", cp);
+ jupiter_debug(peer, __func__,
+ "pulse: %s", cp);
break;
}
@@ -645,24 +644,24 @@ jupiter_receive(struct recvbuf *rbufp)
case JUPITER_O_GPOS:
if (size != sizeof(struct jgpos)) {
- jupiter_debug(peer,
- "jupiter_receive", "gpos: len %d != %u",
+ jupiter_debug(peer, __func__,
+ "gpos: len %d != %u",
size, (int)sizeof(struct jgpos));
refclock_report(peer, CEVNT_BADREPLY);
break;
}
if ((cp = jupiter_parse_gpos(instance, sp)) != NULL) {
- jupiter_debug(peer,
- "jupiter_receive", "gpos: %s", cp);
+ jupiter_debug(peer, __func__,
+ "gpos: %s", cp);
break;
}
break;
case JUPITER_O_ID:
if (size != sizeof(struct jid)) {
- jupiter_debug(peer,
- "jupiter_receive", "id: len %d != %u",
+ jupiter_debug(peer, __func__,
+ "id: len %d != %u",
size, (int)sizeof(struct jid));
refclock_report(peer, CEVNT_BADREPLY);
break;
@@ -672,8 +671,8 @@ jupiter_receive(struct recvbuf *rbufp)
* just powered instance, it needs to be reconfigured.
*/
ip = (struct jid *)sp;
- jupiter_debug(peer,
- "jupiter_receive", "%s chan ver %s, %s (%s)",
+ jupiter_debug(peer, __func__,
+ "%s chan ver %s, %s (%s)",
ip->chans, ip->vers, ip->date, ip->opts);
msyslog(LOG_DEBUG,
"jupiter_receive: %s chan ver %s, %s (%s)",
@@ -681,8 +680,7 @@ jupiter_receive(struct recvbuf *rbufp)
if (instance->wantid)
instance->wantid = 0;
else {
- jupiter_debug(peer,
- "jupiter_receive", "reset receiver");
+ jupiter_debug(peer, __func__, "reset receiver");
jupiter_config(instance);
/*
* Restore since jupiter_config() just
@@ -693,8 +691,7 @@ jupiter_receive(struct recvbuf *rbufp)
break;
default:
- jupiter_debug(peer,
- "jupiter_receive", "unknown message id %d",
+ jupiter_debug(peer, __func__, "unknown message id %d",
getshort(hp->id));
break;
}
@@ -707,7 +704,7 @@ jupiter_receive(struct recvbuf *rbufp)
}
}
-static char *
+static const char *
jupiter_parse_t(struct instance *instance, u_short *sp)
{
struct tm *tm;
@@ -757,8 +754,8 @@ jupiter_parse_t(struct instance *instance, u_short *sp)
}
else if (sweek == 0 && instance->lastsweek == WEEKSECS - 1) {
++instance->gweek;
- jupiter_debug(instance->peer,
- "jupiter_parse_t", "NEW gps week %u", instance->gweek);
+ jupiter_debug(instance->peer, __func__,
+ "NEW gps week %u", instance->gweek);
}
/*
@@ -774,14 +771,14 @@ jupiter_parse_t(struct instance *instance, u_short *sp)
* Then we warped.
*/
if (instance->lastsweek == sweek)
- jupiter_debug(instance->peer,
- "jupiter_parse_t", "gps sweek not incrementing (%d)",
+ jupiter_debug(instance->peer, __func__,
+ "gps sweek not incrementing (%d)",
sweek);
else if (instance->lastsweek != 2 * WEEKSECS &&
instance->lastsweek + 1 != sweek &&
!(sweek == 0 && instance->lastsweek == WEEKSECS - 1))
- jupiter_debug(instance->peer,
- "jupiter_parse_t", "gps sweek jumped (was %d, now %d)",
+ jupiter_debug(instance->peer, __func__,
+ "gps sweek jumped (was %d, now %d)",
instance->lastsweek, sweek);
instance->lastsweek = sweek;
@@ -792,16 +789,16 @@ jupiter_parse_t(struct instance *instance, u_short *sp)
if (last_timecode == 0)
/* XXX debugging */
- jupiter_debug(instance->peer,
- "jupiter_parse_t", "UTC <none> (gweek/sweek %u/%u)",
+ jupiter_debug(instance->peer, __func__,
+ "UTC <none> (gweek/sweek %u/%u)",
instance->gweek, sweek);
else {
/* XXX debugging */
tm = gmtime(&last_timecode);
cp = asctime(tm);
- jupiter_debug(instance->peer,
- "jupiter_parse_t", "UTC %.24s (gweek/sweek %u/%u)",
+ jupiter_debug(instance->peer, __func__,
+ "UTC %.24s (gweek/sweek %u/%u)",
cp, instance->gweek, sweek);
/* Billboard last_timecode (which is now the current time) */
@@ -829,7 +826,7 @@ jupiter_parse_t(struct instance *instance, u_short *sp)
return (NULL);
}
-static char *
+static const char *
jupiter_parse_gpos(struct instance *instance, u_short *sp)
{
struct jgpos *jg;
@@ -861,8 +858,8 @@ jupiter_parse_gpos(struct instance *instance, u_short *sp)
tm = gmtime(&t);
cp = asctime(tm);
- jupiter_debug(instance->peer,
- "jupiter_parse_g", "GPS %.24s (gweek/sweek %u/%u)",
+ jupiter_debug(instance->peer, __func__,
+ "GPS %.24s (gweek/sweek %u/%u)",
cp, instance->gpos_gweek, instance->gpos_sweek);
return (NULL);
}
@@ -903,7 +900,7 @@ static char *
jupiter_send(struct instance *instance, struct jheader *hp)
{
u_int len, size;
- int cc;
+ ssize_t cc;
u_short *sp;
static char errstr[132];
@@ -921,7 +918,7 @@ jupiter_send(struct instance *instance, struct jheader *hp)
msnprintf(errstr, sizeof(errstr), "write: %m");
return (errstr);
} else if (cc != (int)size) {
- snprintf(errstr, sizeof(errstr), "short write (%d != %u)", cc, size);
+ snprintf(errstr, sizeof(errstr), "short write (%zd != %u)", cc, size);
return (errstr);
}
return (NULL);
@@ -954,7 +951,7 @@ jupiter_reqmsg(struct instance *instance, u_int id,
rp->trigger = putshort(interval == 0);
rp->interval = putshort(interval);
if ((cp = jupiter_send(instance, hp)) != NULL)
- jupiter_debug(instance->peer, "jupiter_reqmsg", "%u: %s", id, cp);
+ jupiter_debug(instance->peer, __func__, "%u: %s", id, cp);
}
/* Cancel periodic message output */
@@ -973,7 +970,7 @@ jupiter_canmsg(struct instance *instance, u_int id)
hp = &canmsg;
hp->id = putshort(id);
if ((cp = jupiter_send(instance, hp)) != NULL)
- jupiter_debug(instance->peer, "jupiter_canmsg", "%u: %s", id, cp);
+ jupiter_debug(instance->peer, __func__, "%u: %s", id, cp);
}
/* Request a single message output */
@@ -992,7 +989,7 @@ jupiter_reqonemsg(struct instance *instance, u_int id)
hp = &reqonemsg;
hp->id = putshort(id);
if ((cp = jupiter_send(instance, hp)) != NULL)
- jupiter_debug(instance->peer, "jupiter_reqonemsg", "%u: %s", id, cp);
+ jupiter_debug(instance->peer, __func__, "%u: %s", id, cp);
}
/* Set the platform dynamics */
@@ -1017,7 +1014,7 @@ jupiter_platform(struct instance *instance, u_int platform)
pp = &platmsg.jplat;
pp->platform = putshort(platform);
if ((cp = jupiter_send(instance, hp)) != NULL)
- jupiter_debug(instance->peer, "jupiter_platform", "%u: %s", platform, cp);
+ jupiter_debug(instance->peer, __func__, "%u: %s", platform, cp);
}
/* Checksum "len" shorts */
@@ -1054,13 +1051,14 @@ jupiter_recv(struct instance *instance)
hp = (struct jheader *)sp;
if (getshort(hp->sync) != JUPITER_SYNC) {
/* Wasn't at the front, sync up */
- jupiter_debug(instance->peer, "jupiter_recv", "syncing");
+ jupiter_debug(instance->peer, __func__, "syncing");
bp = (u_char *)sp;
n = size;
while (n >= 2) {
if (bp[0] != (JUPITER_SYNC & 0xff)) {
/*
- jupiter_debug(instance->peer, "{0x%x}", bp[0]);
+ jupiter_debug(instance->peer, __func__,
+ "{0x%x}", bp[0]);
*/
++bp;
--n;
@@ -1069,13 +1067,14 @@ jupiter_recv(struct instance *instance)
if (bp[1] == ((JUPITER_SYNC >> 8) & 0xff))
break;
/*
- jupiter_debug(instance->peer, "{0x%x 0x%x}", bp[0], bp[1]);
+ jupiter_debug(instance->peer, __func__,
+ "{0x%x 0x%x}", bp[0], bp[1]);
*/
bp += 2;
n -= 2;
}
/*
- jupiter_debug(instance->peer, "\n");
+ jupiter_debug(instance->peer, __func__, "\n");
*/
/* Shuffle data to front of input buffer */
if (n > 0)
@@ -1088,7 +1087,7 @@ jupiter_recv(struct instance *instance)
if (jupiter_cksum(sp, (cc / sizeof(u_short) - 1)) !=
getshort(hp->hsum)) {
- jupiter_debug(instance->peer, "jupiter_recv", "bad header checksum!");
+ jupiter_debug(instance->peer, __func__, "bad header checksum!");
/* This is drastic but checksum errors should be rare */
instance->ssize = 0;
return (0);
@@ -1106,7 +1105,7 @@ jupiter_recv(struct instance *instance)
sp = (u_short *)(hp + 1);
if (jupiter_cksum(sp, len) != getshort(sp[len])) {
jupiter_debug(instance->peer,
- "jupiter_recv", "bad payload checksum!");
+ __func__, "bad payload checksum!");
/* This is drastic but checksum errors should be rare */
instance->ssize = 0;
return (0);