[Git][NTPsec/ntpsec][master] 2 commits: Refactor - use conversion function rather than ad-hoc code.
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Jan 2 23:32:19 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
065ff1d1 by Eric S. Raymond at 2017-01-02T16:14:20-05:00
Refactor - use conversion function rather than ad-hoc code.
- - - - -
aa753f78 by Eric S. Raymond at 2017-01-02T18:32:09-05:00
Use __DATE__ rather than a wired-in year of compilation.
- - - - -
1 changed file:
- ntpd/refclock_magnavox.c
Changes:
=====================================
ntpd/refclock_magnavox.c
=====================================
--- a/ntpd/refclock_magnavox.c
+++ b/ntpd/refclock_magnavox.c
@@ -20,6 +20,7 @@
#include "ntp_refclock.h"
#include "ntp_stdlib.h"
#include "ntp_calendar.h"
+#include "timespecops.h"
#include <stdio.h>
#include <ctype.h>
@@ -37,11 +38,6 @@
*/
/*
- * Check this every time you edit the code!
- */
-#define YEAR_LAST_MODIFIED 2000
-
-/*
* GPS Definitions
*/
#define DEVICE "/dev/gps%d" /* device name and unit */
@@ -129,6 +125,7 @@ struct mx4200unit {
};
static char pmvxg[] = "PMVXG";
+static int year_last_modified;
/*
* Function prototypes
@@ -216,6 +213,14 @@ mx4200_start(
pp->clockdesc = DESCRIPTION;
memcpy((char *)&pp->refid, REFID, REFIDLEN);
peer->sstclktype = CTL_SST_TS_LF;
+ /*
+ * __DATE__ is in a format like "Jan 2 2017" or possibly "???
+ * ?? ????". Thus it is guaranteed that there will be a
+ * rightmost space just before the date. It's OK if atoi()
+ * barfs on ???? because this is only used in a sanity check
+ * where that will fail positive.
+ */
+ year_last_modified = atoi(strrchr(__DATE__, ' ') + 1);
/* Ensure the receiver is properly configured */
return mx4200_config(peer);
@@ -991,7 +996,7 @@ mx4200_parse_t(
* (Certainly can't be any year before this code was last altered!)
*/
if (day_of_month > 31 || month > 12 ||
- day_of_month < 1 || month < 1 || year < YEAR_LAST_MODIFIED) {
+ day_of_month < 1 || month < 1 || year < year_last_modified) {
mx4200_debug(peer,
"mx4200_parse_t: bad date (%4d-%02d-%02d)\n",
year, month, day_of_month);
@@ -1519,11 +1524,7 @@ mx4200_pps(
/*
* Return the timestamp in pp->lastrec
*/
-
- setlfpuint(pp->lastrec, up->pps_i.assert_timestamp.tv_sec +
- (uint32_t) JAN_1970);
- setlfpfrac(pp->lastrec, ((double)(up->pps_i.assert_timestamp.tv_nsec) *
- 4.2949672960) + 0.5);
+ pp->lastrec = tspec_stamp_to_lfp(up->pps_i.assert_timestamp);
return false;
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/02a79351f0f7d40b697cdd2be7e118ba8b83c73e...aa753f7869b108e1ee07529f0a6ea78bb119eb7b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170102/cb5ae7ae/attachment.html>
More information about the vc
mailing list