Compare commits
3 commits
b9eaad375a
...
5073fc7a0f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5073fc7a0f | ||
|
|
f2cf3e949f | ||
|
|
eea7fdf883 |
2 changed files with 37 additions and 33 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
irena pres/inj
|
irena pres/inj
|
||||||
irena uart/base=85
|
irena uart/base=85
|
||||||
irena var uart_size = -1
|
irena var uart_size = -1
|
||||||
irena var rtc_drift[3] = 0x20f04
|
|
||||||
clock_sync 3600
|
clock_sync 3600
|
||||||
set_clock fudge config
|
set_clock fudge config
|
||||||
set_clock
|
set_clock sleep
|
||||||
|
set_clock fudge
|
||||||
|
|
|
||||||
72
irena.c
72
irena.c
|
|
@ -2407,36 +2407,40 @@ int send_file(const char *fn, const char *cfmt, unsigned int drop)
|
||||||
|
|
||||||
int set_clock(int do_sleep)
|
int set_clock(int do_sleep)
|
||||||
{
|
{
|
||||||
time_t t = 0;
|
struct timespec ts;
|
||||||
if (do_sleep) {
|
if (clock_gettime(CLOCK_REALTIME, &ts)) {
|
||||||
struct timespec ts;
|
merror("clock_gettime(CLOCK_REALTIME)");
|
||||||
poll_uart(1);
|
return 0;
|
||||||
if (!clock_gettime(CLOCK_REALTIME, &ts)) {
|
|
||||||
while (ts.tv_nsec < 900000000) {
|
|
||||||
ts.tv_nsec += 50000000;
|
|
||||||
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, 0);
|
|
||||||
if (verbose(3))
|
|
||||||
fprintf(mout, "slept 50ms ns=%lu\n", ts.tv_nsec);
|
|
||||||
poll_uart(1);
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
}
|
|
||||||
ts.tv_sec++;
|
|
||||||
t = ts.tv_sec;
|
|
||||||
ts.tv_nsec=0;
|
|
||||||
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
if (do_sleep & 1) {
|
||||||
t = time(0);
|
poll_uart(1);
|
||||||
struct tm gm;
|
while (ts.tv_nsec < 900000000) {
|
||||||
gmtime_r(&t, &gm);
|
ts.tv_nsec += 50000000;
|
||||||
|
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, 0);
|
||||||
|
if (verbose(3))
|
||||||
|
fprintf(mout, "slept 50ms ns=%lu\n", ts.tv_nsec);
|
||||||
|
poll_uart(1);
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
}
|
||||||
|
ts.tv_sec++;
|
||||||
|
ts.tv_nsec=0;
|
||||||
|
clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, 0);
|
||||||
|
}
|
||||||
|
|
||||||
char utc[64];
|
char utc[64];
|
||||||
char *cmd = "clock %Y-%m-%d %H:%M:%S";
|
if (do_sleep == 2) {
|
||||||
if (do_sleep == 2)
|
unsigned int q = (ts.tv_nsec/(1000000000>>15));
|
||||||
cmd = "cl/dr %Y-%m-%d %H:%M:%S";
|
if (q > 0x7fff) q = 0x7fff;
|
||||||
if (do_sleep == 3)
|
snprintf(utc, sizeof(utc), "cl/fu 0x%08lx 0x%04x", ts.tv_sec, q);
|
||||||
cmd = "cl/fu %Y-%m-%d %H:%M:%S";
|
}
|
||||||
strftime(utc, sizeof(utc), cmd, &gm);
|
else {
|
||||||
|
char *cmd = "clock %Y-%m-%d %H:%M:%S";
|
||||||
|
if (do_sleep == 3)
|
||||||
|
cmd = "cl/dr %Y-%m-%d %H:%M:%S";
|
||||||
|
struct tm gm;
|
||||||
|
gmtime_r(&ts.tv_sec, &gm);
|
||||||
|
strftime(utc, sizeof(utc), cmd, &gm);
|
||||||
|
}
|
||||||
return send_irena_command(utc);
|
return send_irena_command(utc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2762,7 +2766,7 @@ struct numbers {
|
||||||
{.name="fct_packets", .doc="packets", .i=&fct_packets, .flags=NU_INT},
|
{.name="fct_packets", .doc="packets", .i=&fct_packets, .flags=NU_INT},
|
||||||
{.name="clock_sync", .doc="seconds", .u=&clock_cadence, .flags=NU_INT},
|
{.name="clock_sync", .doc="seconds", .u=&clock_cadence, .flags=NU_INT},
|
||||||
{.name="clock_mod", .doc="seconds", .u=&clock_modulus, .flags=NU_INT},
|
{.name="clock_mod", .doc="seconds", .u=&clock_modulus, .flags=NU_INT},
|
||||||
{.name="clock_sleep", .doc="(1:sleep,2:drift,3:fudge)", .i=&clock_sleep, .flags=NU_INT},
|
{.name="clock_sleep", .doc="(1:sleep,2:fudge,3:drift)", .i=&clock_sleep, .flags=NU_INT},
|
||||||
{.name="reset_cadence", .doc="seconds", .i=&status_reset_cadence, .flags=NU_INT},
|
{.name="reset_cadence", .doc="seconds", .i=&status_reset_cadence, .flags=NU_INT},
|
||||||
{.name="last_reset", .doc="time", .t=&last_status_reset, .flags=NU_TIME},
|
{.name="last_reset", .doc="time", .t=&last_status_reset, .flags=NU_TIME},
|
||||||
{.name="init_time", .doc="time", .t=&init_time, .flags=NU_TIME},
|
{.name="init_time", .doc="time", .t=&init_time, .flags=NU_TIME},
|
||||||
|
|
@ -2891,7 +2895,7 @@ int process_cmd(char *l)
|
||||||
"\tirena «commandline»\n"
|
"\tirena «commandline»\n"
|
||||||
"\tvar «irena variable command»\n"
|
"\tvar «irena variable command»\n"
|
||||||
"\tfct «lines»\n"
|
"\tfct «lines»\n"
|
||||||
"\tset_clock [sleep|drift|fudge] [config]\n"
|
"\tset_clock [sleep|fudge|drift] [config]\n"
|
||||||
"\tdatafile [«fn» [«rotate» [«rotate-modulus» [«flags»]]]] [close|rotate]\n"
|
"\tdatafile [«fn» [«rotate» [«rotate-modulus» [«flags»]]]] [close|rotate]\n"
|
||||||
"\tcounterfile [«fn» [«rotate» [«rotate-modulus» [«flags»]]]] [close|rotate]\n"
|
"\tcounterfile [«fn» [«rotate» [«rotate-modulus» [«flags»]]]] [close|rotate]\n"
|
||||||
"\tstatusfile [«fn» [ «rotate» [ «rotate-modulus» [«flags»]]]] [close|rotate]\n"
|
"\tstatusfile [«fn» [ «rotate» [ «rotate-modulus» [«flags»]]]] [close|rotate]\n"
|
||||||
|
|
@ -3085,8 +3089,8 @@ int process_cmd(char *l)
|
||||||
int config = !strcmp(av[na-1], "config");
|
int config = !strcmp(av[na-1], "config");
|
||||||
if ( !strcmp(av[1], "nosleep")) do_sleep = 0;
|
if ( !strcmp(av[1], "nosleep")) do_sleep = 0;
|
||||||
else if (!strcmp(av[1], "sleep")) do_sleep = 1;
|
else if (!strcmp(av[1], "sleep")) do_sleep = 1;
|
||||||
else if (!strcmp(av[1], "drift")) do_sleep = 2;
|
else if (!strcmp(av[1], "fudge")) do_sleep = 2;
|
||||||
else if (!strcmp(av[1], "fudge")) do_sleep = 3;
|
else if (!strcmp(av[1], "drift")) do_sleep = 3;
|
||||||
else if (!config || na>2) do_sleep = -1;
|
else if (!config || na>2) do_sleep = -1;
|
||||||
if (na>3 || na>2 && !config)
|
if (na>3 || na>2 && !config)
|
||||||
do_sleep = -1;
|
do_sleep = -1;
|
||||||
|
|
@ -3096,8 +3100,8 @@ int process_cmd(char *l)
|
||||||
"- set the µC RTC to the current host time.\n"
|
"- set the µC RTC to the current host time.\n"
|
||||||
"option `sleep`: Wait until the end of the current second.\n"
|
"option `sleep`: Wait until the end of the current second.\n"
|
||||||
"option `drift`: Sleep, set clock and ask the µC to adjust the clock speed.\n"
|
"option `drift`: Sleep, set clock and ask the µC to adjust the clock speed.\n"
|
||||||
"option `fudge`: Sleep, and ask the µC to adjust the clock speed.\n"
|
"option `fudge`: Ask the µC to adjust the clock speed.\n"
|
||||||
"option `config`: configure the sleep mode of the periodic clock setting,\n"
|
"option `config`: Configure the sleep mode of the periodic clock setting,\n"
|
||||||
" (does not set the µC clock).\n"
|
" (does not set the µC clock).\n"
|
||||||
);
|
);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue