A GPS disciplined clock

Dependencies:   net lpc1768 crypto clock web log

http-derived/home/http-home-ajax.c

Committer:
andrewboyson
Date:
2019-01-18
Revision:
28:7fb6b4e9ab80
Parent:
27:eb5728b9052b
Child:
34:d9586fc921dc

File content as of revision 28:7fb6b4e9ab80:

#include  <stdint.h>
#include   <stdio.h>

#include "http.h"
#include "http-server.h"
#include "rtc.h"
#include "clk.h"
#include "clktime.h"
#include "clkgov.h"
#include "clkutc.h"
#include "pps.h"

void HttpHomeAjax()
{
    HttpOk("text/plain; charset=UTF-8", "no-cache", NULL, NULL);
    
    int64_t now = ClkNowTime();
    int64_t fraction = now & ((1UL << CLK_TIME_ONE_SECOND_SHIFT) - 1);
    int64_t ms = (fraction * 1000) >> CLK_TIME_ONE_SECOND_SHIFT;
    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 (ClkGovRateIsSynced   ) nibble |= 8; //4
    HttpAddNibbleAsHex(nibble);
    
    nibble = 0;
    if (ClkGovTimeIsSynced        ) nibble |= 1; //5
    if (ClkUtcGetNextLeapEnable() ) nibble |= 2; //5
    if (ClkUtcGetNextLeapForward()) nibble |= 4; //5
    HttpAddNibbleAsHex(nibble);
    
    HttpAddInt12AsHex(ClkUtcGetNextEpochMonth1970()); //6, 7, 8
    HttpAddInt16AsHex(ClkUtcGetEpochOffset());        //9, 10, 11, 12
}