summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libparse/clk_hopf6021.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libparse/clk_hopf6021.c')
-rw-r--r--contrib/ntp/libparse/clk_hopf6021.c68
1 files changed, 43 insertions, 25 deletions
diff --git a/contrib/ntp/libparse/clk_hopf6021.c b/contrib/ntp/libparse/clk_hopf6021.c
index 2359628..c5980ef 100644
--- a/contrib/ntp/libparse/clk_hopf6021.c
+++ b/contrib/ntp/libparse/clk_hopf6021.c
@@ -113,13 +113,10 @@ static struct format hopf6021_fmt =
#define OFFS(x) format->field_offsets[(x)].offset
#define STOI(x, y) Stoi(&buffer[OFFS(x)], y, format->field_offsets[(x)].length)
-#define hexval(x) (('0' <= (x) && (x) <= '9') ? (x) - '0' : \
- ('a' <= (x) && (x) <= 'f') ? (x) - 'a' + 10 : \
- ('A' <= (x) && (x) <= 'F') ? (x) - 'A' + 10 : \
- -1)
static parse_cvt_fnc_t cvt_hopf6021;
static parse_inp_fnc_t inp_hopf6021;
+static unsigned char hexval(unsigned char);
clockformat_t clock_hopf6021 =
{
@@ -160,40 +157,40 @@ cvt_hopf6021(
return CVT_FAIL|CVT_BADFMT;
}
- clock_time->usecond = 0;
- clock_time->utcoffset = 0;
+ clock_time->usecond = 0;
+ clock_time->flags = 0;
- status = (u_char) hexval(buffer[OFFS(O_FLAGS)]);
- weekday= (u_char) hexval(buffer[OFFS(O_WDAY)]);
+ status = hexval(buffer[OFFS(O_FLAGS)]);
+ weekday = hexval(buffer[OFFS(O_WDAY)]);
if ((status == 0xFF) || (weekday == 0xFF))
{
return CVT_FAIL|CVT_BADFMT;
}
- clock_time->flags = 0;
-
if (weekday & HOPF_UTC)
{
- clock_time->flags |= PARSEB_UTC;
+ clock_time->flags |= PARSEB_UTC;
+ clock_time->utcoffset = 0;
+ }
+ else if (status & HOPF_DST)
+ {
+ clock_time->flags |= PARSEB_DST;
+ clock_time->utcoffset = -2*60*60; /* MET DST */
}
else
{
- if (status & HOPF_DST)
- {
- clock_time->flags |= PARSEB_DST;
- clock_time->utcoffset = -2*60*60; /* MET DST */
- }
- else
- {
- clock_time->utcoffset = -1*60*60; /* MET */
- }
+ clock_time->utcoffset = -1*60*60; /* MET */
}
- clock_time->flags |= (status & HOPF_DSTWARN) ? PARSEB_ANNOUNCE : 0;
-
+ if (status & HOPF_DSTWARN)
+ {
+ clock_time->flags |= PARSEB_ANNOUNCE;
+ }
+
switch (status & HOPF_MODE)
{
+ default: /* dummy: we cover all 4 cases. */
case HOPF_INVALID: /* Time/Date invalid */
clock_time->flags |= PARSEB_POWERUP;
break;
@@ -205,9 +202,6 @@ cvt_hopf6021(
case HOPF_RADIO: /* Radio clock */
case HOPF_RADIOHP: /* Radio clock high precision */
break;
-
- default:
- return CVT_FAIL|CVT_BADFMT;
}
return CVT_OK;
@@ -244,6 +238,30 @@ inp_hopf6021(
}
}
+/*
+ * convert a hex-digit to numeric value
+ */
+static unsigned char
+hexval(
+ unsigned char ch
+ )
+{
+ unsigned int dv;
+
+ if ((dv = ch - '0') >= 10u)
+ {
+ if ((dv -= 'A'-'0') < 6u || (dv -= 'a'-'A') < 6u)
+ {
+ dv += 10;
+ }
+ else
+ {
+ dv = 0xFF;
+ }
+ }
+ return (unsigned char)dv;
+}
+
#else /* not (REFCLOCK && CLOCK_PARSE && CLOCK_HOPF6021) */
int clk_hopf6021_bs;
#endif /* not (REFCLOCK && CLOCK_PARSE && CLOCK_HOPF6021) */
OpenPOWER on IntegriCloud