Dependencies:   net lpc1768 crypto clock web log

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

Committer:
andrewboyson
Date:
2019-02-12
Revision:
35:a535b65203a9
Parent:
34:d9586fc921dc
Child:
37:a4e57b7e29dc

File content as of revision 35:a535b65203a9:

#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"
#include "nmea.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 (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
}