Skip to content
Snippets Groups Projects
Commit de9072dd authored by Adam Wujek's avatar Adam Wujek
Browse files

userspace/tools/wr_date: add parameter offset_us


Signed-off-by: default avatarAdam Wujek <dev_public@wujek.eu>
parent a0278400
Branches
Tags
No related merge requests found
......@@ -50,6 +50,7 @@ static struct wr_nmea nmea;
static struct wr_irig wr_irig;
static char *opt_cfgfile = WRDATE_CFG_FILE;
static char *prgname;
static long opt_offset_us = 0;
void help(void)
{
......@@ -66,6 +67,9 @@ void help(void)
" baudrate for NMEA (default %d)\n"
" -m <GPZDA|GPRMC>\n"
" format for NMEA (default %s)\n"
" -o <offset_us>\n"
" for tohost cmd, add an extra offset in us;\n"
" possitive offset means linux time is greater than e.g., WR time\n"
" Supported <source> of Time Of Day:\n"
" irigb use IRIG-B (NOTE: remember to enable it!)\n"
" nmea use NMEA \n"
......@@ -254,6 +258,19 @@ int wrdate_get(volatile struct PPSG_WB *pps, int tohost)
hw.tv_usec = nsec/1000;
}
/* Apply provided offset as parameter */
while (hw.tv_usec + opt_offset_us > 1000000) {
opt_offset_us -= 1000000;
hw.tv_sec++;
}
while (hw.tv_usec + opt_offset_us < 0) {
opt_offset_us += 1000000;
hw.tv_sec--;
}
hw.tv_usec += opt_offset_us;
if (settimeofday(&hw, NULL))
fprintf(stderr, "wr_date: settimeofday(): %s\n",
strerror(errno));
......@@ -710,7 +727,7 @@ int main(int argc, char **argv)
prgname = argv[0];
while ( (c = getopt(argc, argv, "fc:b:m:vn")) != -1) {
while ( (c = getopt(argc, argv, "fc:b:m:vno:")) != -1) {
switch(c) {
case 'f':
opt_force = 1;
......@@ -727,6 +744,9 @@ int main(int argc, char **argv)
case 'v':
opt_verbose = 1;
break;
case 'o':
opt_offset_us = atol(optarg);
break;
case 'n':
opt_not = 1;
printf("Dry run mode: No action will be performed\n");
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment