Common stuff for all my devices' web server pages: css, login, log, ipv4, ipv6, firmware update, clock, reset info etc.

Dependents:   oldheating gps motorhome heating

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers web-clock-ajax.c Source File

web-clock-ajax.c

00001 #include  <stdint.h>
00002 #include   <stdio.h>
00003 
00004 #include "http.h"
00005 #include "rtc.h"
00006 #include "clk.h"
00007 #include "clktime.h"
00008 #include "clkgov.h"
00009 #include "clkutc.h"
00010 #include "ntpclient.h"
00011 #include "scan.h"
00012 
00013 void WebClockAjax()
00014 {
00015     HttpOk("text/plain; charset=UTF-8", "no-cache", NULL, NULL);
00016     
00017     //Time and UTC
00018     clktime now = ClkNowTai();
00019     clktime fraction = now & ((1UL << CLK_TIME_ONE_SECOND_SHIFT) - 1);
00020     clktime ms = (fraction * 1000) >> CLK_TIME_ONE_SECOND_SHIFT;
00021     HttpAddInt16AsHex(ms                           ); HttpAddChar('\n');
00022     char byte = 0;
00023     if (RtcIsSet()                ) byte |= 0x01;
00024     if (ClkTimeIsSet()            ) byte |= 0x02;
00025     if (ClkGovIsReceivingTime     ) byte |= 0x04;
00026     if (ClkGovRateIsSynced        ) byte |= 0x08;
00027     if (ClkGovTimeIsSynced        ) byte |= 0x10;
00028     if (ClkUtcGetNextLeapEnable() ) byte |= 0x20;
00029     if (ClkUtcGetNextLeapForward()) byte |= 0x40;
00030     if (ClkGovTrace)                byte |= 0x80;
00031     HttpAddByteAsHex (byte                         ); HttpAddChar('\n');
00032     HttpAddInt12AsHex(ClkUtcGetNextEpochMonth1970()); HttpAddChar('\n');
00033     HttpAddInt16AsHex(ClkUtcGetEpochOffset()       ); HttpAddChar('\n');
00034     HttpAddChar('\f');
00035     
00036     //Governer
00037     HttpAddInt32AsHex(ClkGovGetPpb()               ); HttpAddChar('\n');
00038     HttpAddInt32AsHex(ClkGovFreqDivisor            ); HttpAddChar('\n');
00039     HttpAddInt32AsHex(ClkGovFreqChangeMaxPpb       ); HttpAddChar('\n');
00040     HttpAddInt32AsHex(ClkGovFreqSyncedLimPpb       ); HttpAddChar('\n');
00041     HttpAddInt32AsHex(ClkGovFreqSyncedHysPpb       ); HttpAddChar('\n');
00042     HttpAddInt32AsHex(ClkGovSlewDivisor            ); HttpAddChar('\n');
00043     HttpAddInt32AsHex(ClkGovSlewChangeMaxMs        ); HttpAddChar('\n');
00044     HttpAddInt32AsHex(ClkGovSlewSyncedLimNs        ); HttpAddChar('\n');
00045     HttpAddInt32AsHex(ClkGovSlewSyncedHysNs        ); HttpAddChar('\n');
00046     HttpAddInt32AsHex(ClkGovSlewOffsetMaxSecs      ); HttpAddChar('\n');
00047     HttpAddChar('\f');
00048     
00049     //NTP
00050     HttpAddText      (NtpClientQueryServerName     ); HttpAddChar('\n');
00051     HttpAddInt32AsHex(NtpClientQueryInitialInterval); HttpAddChar('\n');
00052     HttpAddInt32AsHex(NtpClientQueryNormalInterval ); HttpAddChar('\n');
00053     HttpAddInt32AsHex(NtpClientQueryRetryInterval  ); HttpAddChar('\n');
00054     HttpAddInt32AsHex(NtpClientReplyOffsetMs       ); HttpAddChar('\n');
00055     HttpAddInt32AsHex(NtpClientReplyMaxDelayMs     ); HttpAddChar('\n');
00056     HttpAddChar('\f');
00057     
00058     //Scan
00059     HttpAddInt32AsHex(ScanAverage                  ); HttpAddChar('\n');
00060     HttpAddInt32AsHex(ScanMaximum                  ); HttpAddChar('\n');
00061     HttpAddInt32AsHex(ScanMinimum                  ); HttpAddChar('\n');
00062     HttpAddChar('\f');
00063 }
00064