summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@ka-ata-killa.ourano.james.local>2021-03-20 18:48:43 +0000
committerroot <root@ka-ata-killa.ourano.james.local>2021-03-20 19:01:35 +0000
commitf211fe6461aae73f5ffdbe58961dbe3dd1309854 (patch)
treea4b698a5146f1ec2584f09db5b7f73f263d6bc4a
parent5b8f47a70a57765ba04a4d75dfa31a2f55f75029 (diff)
downloadclock-f211fe6461aae73f5ffdbe58961dbe3dd1309854.tar.gz
clock-f211fe6461aae73f5ffdbe58961dbe3dd1309854.tar.bz2
clock-f211fe6461aae73f5ffdbe58961dbe3dd1309854.zip
make the interval bisection work properly for events in the next hour, add an alarm output
-rw-r--r--app/Makefile2
-rw-r--r--app/alarm.c35
-rw-r--r--app/httpd.c1
-rw-r--r--app/led.c7
-rw-r--r--app/main.c2
-rw-r--r--app/prototypes.h7
-rw-r--r--app/time_fn.c30
7 files changed, 72 insertions, 12 deletions
diff --git a/app/Makefile b/app/Makefile
index e11bbfc..50ac75f 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -29,7 +29,7 @@ default: ${PROG}.elf
CSRCS=led.c ticker.c ring.c usart.c stdio.c lwip_glue.c steth.c msf.c abs.c \
pll.c main.c time_fn.c ntp.c dcf77.c util.c stats.c gps.c hexdump.c bits.c \
max7219.c report.c sysclk.c cdcacm.c usb.c dfu.c adc.c dummy_kb.c ref.c \
- ptp.c display.c httpd.c
+ ptp.c display.c httpd.c alarm.c
HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h
diff --git a/app/alarm.c b/app/alarm.c
new file mode 100644
index 0000000..ed503db
--- /dev/null
+++ b/app/alarm.c
@@ -0,0 +1,35 @@
+#include "project.h"
+
+#define ALARM_LENGTH 30
+
+EPOCH alarm;
+
+static void alarm_off (void)
+{
+ led5_set (0);
+}
+
+
+static void alarm_on (void)
+{
+ led5_set (1);
+}
+
+
+
+void alarm_dispatch (void)
+{
+ uint64_t abs = ref_get();
+ EPOCH d, e = ref_decompose (abs);
+
+ d = time_epoch_sub (e, alarm);
+
+ if ((d.s < 0) || (d.s > ALARM_LENGTH)) alarm_off();
+ else alarm_on();
+}
+
+
+
+
+
+
diff --git a/app/httpd.c b/app/httpd.c
index 5c96c44..3fdea93 100644
--- a/app/httpd.c
+++ b/app/httpd.c
@@ -10,7 +10,6 @@
static char html_buf[8192];
-EPOCH alarm;
static uint32_t make_alarm (void)
{
diff --git a/app/led.c b/app/led.c
index 2dc285b..bc3853d 100644
--- a/app/led.c
+++ b/app/led.c
@@ -68,6 +68,13 @@ void led3_set (int v)
else CLEAR (LED3);
}
+void led5_set (int v)
+{
+ if (!v) SET (LED5);
+ else CLEAR (LED5);
+}
+
+
void
led_clear (void)
{
diff --git a/app/main.c b/app/main.c
index e874aac..7c36f32 100644
--- a/app/main.c
+++ b/app/main.c
@@ -373,10 +373,12 @@ main (void)
display_dispatch();
adc_dispatch();
+ alarm_dispatch();
pll_check();
+
}
return 0;
diff --git a/app/prototypes.h b/app/prototypes.h
index 66f6586..e1164bf 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -3,6 +3,7 @@ extern void led_init(void);
extern void led1_set(int v);
extern void led2_set(int v);
extern void led3_set(int v);
+extern void led5_set(int v);
extern void led_clear(void);
extern void led_set(void);
extern void led_blink(unsigned ms);
@@ -80,9 +81,9 @@ extern void utc_to_str(char *dst, UTC *u);
extern void time_print_utc(const char *p, UTC *u, const char *t);
extern void time_print_epoch(const char *p, EPOCH e, const char *t);
extern double time_utc_to_tjd(UTC u);
+extern double ra_normalize(double ra);
extern double time_utc_to_ra(UTC u);
extern double time_st_to_ra(ST st);
-extern double ra_normalize(double ra);
extern ST time_ra_to_st(double ra);
extern ST time_utc_to_lst(UTC u, double lon);
extern int time_ra_cmp(double a, double b);
@@ -199,7 +200,9 @@ extern void display_report_fix(char fix, char fix2);
extern void display_report_svin(int valid, int active);
extern void display_dispatch(void);
/* httpd.c */
-extern EPOCH alarm;
extern int fs_open_custom(struct fs_file *file, const char *name);
extern void fs_close_custom(struct fs_file *file);
extern void cgi_init(void);
+/* alarm.c */
+extern EPOCH alarm;
+extern void alarm_dispatch(void);
diff --git a/app/time_fn.c b/app/time_fn.c
index 64a92ff..75b69d3 100644
--- a/app/time_fn.c
+++ b/app/time_fn.c
@@ -417,12 +417,25 @@ int time_ra_cmp (double a, double b)
/*Find the next occuring time for RA tra */
+static int test_side (EPOCH m, double tra)
+{
+
+ double ra;
+ UTC u;
+
+ u = time_epoch_to_utc (m);
+ ra = time_utc_to_ra (u);
+
+ return time_ra_cmp (ra, tra);
+}
+
+
EPOCH time_ra_to_next_epoch (EPOCH l, double tra)
{
EPOCH r, m;
unsigned n;
- UTC u;
- double ra;
+
+ int dog = 48;
printf ("time_ra_to_next_epoch %.9f\n", tra);
@@ -432,8 +445,13 @@ EPOCH time_ra_to_next_epoch (EPOCH l, double tra)
/* So IB works better */
+ while ((test_side (l, tra) != 1) && dog--)
+ l.s += 3600;
+
r = l;
- r.s += 86400.;
+
+ while ((test_side (r, tra) != -1) && dog--)
+ r.s += 3600;
for (n = 0; n < 64; ++n) {
@@ -453,12 +471,8 @@ EPOCH time_ra_to_next_epoch (EPOCH l, double tra)
m = time_epoch_add (l, m);
- u = time_epoch_to_utc (m);
- ra = time_utc_to_ra (u);
-
- if (time_ra_cmp (ra, tra) < 0)
+ if (test_side (m, tra) < 0)
r = m;
-
else
l = m;
}