A GPS disciplined clock

Dependencies:   net lpc1768 crypto clock web log

Revision:
59:d2d25c2265f8
Parent:
58:3f3e000151cc
Child:
60:7cab896b0fd4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web-this/home/web-home-ajax.c	Wed May 01 10:14:26 2019 +0000
@@ -0,0 +1,40 @@
+#include  <stdint.h>
+#include   <stdio.h>
+
+#include "http.h"
+#include "rtc.h"
+#include "clk.h"
+#include "clktime.h"
+#include "clkgov.h"
+#include "clkutc.h"
+#include "pps.h"
+#include "nmea.h"
+
+void WebHomeAjax()
+{
+    HttpOk("text/plain; charset=UTF-8", "no-cache", NULL, NULL);
+    
+    clktime now = ClkNowTai();
+    int32_t fraction = now & ((1UL << CLK_TIME_ONE_SECOND_SHIFT) - 1); //fraction is 30 bit so fits into 32 bits
+    int32_t ms = (fraction * 1000LL) >> CLK_TIME_ONE_SECOND_SHIFT; //fraction time in ms needs 40 bits so use 1000LL to promote to 64bit
+    HttpAddInt16AsHex(ms); //0, 1, 2, 3
+    
+    char nibble;
+    nibble = 0;
+    if (RtcIsSet()           ) nibble |= 1; //4
+    if (ClkTimeIsSet()       ) nibble |= 2; //4
+    if (PpsIsStable()        ) nibble |= 4; //4
+    if (NmeaTimeIsStable()   ) nibble |= 8; //4
+    HttpAddNibbleAsHex(nibble);
+    
+    nibble = 0;
+    if (ClkGovRateIsSynced        ) nibble |= 1; //5
+    if (ClkGovTimeIsSynced        ) nibble |= 2; //5
+    if (ClkUtcGetNextLeapEnable() ) nibble |= 4; //5
+    if (ClkUtcGetNextLeapForward()) nibble |= 8; //5
+    HttpAddNibbleAsHex(nibble);
+    
+    HttpAddInt12AsHex(ClkUtcGetNextEpochMonth1970()); //6, 7, 8
+    HttpAddInt16AsHex(ClkUtcGetEpochOffset());        //9, 10, 11, 12
+}
+