SNTP V2.01 code problem today?
MJHanagan
Posts: 189
in Accessories
Is anyone else having a problem with SNP V2.01 today? Mine has been working just foie for the past 6 months then this morning i tried syncing and got this as the "human time": 00/227/2016 214:242:255 (GMT -5:00).
This is the "human time" SNTP code in V2.01:
This is the "human time" SNTP code in V2.01:
OBJ {{ ****************************************************************** * SNTP Simple Network Time Protocol v2.01 * * Author: Beau Schwabe * * * * Recognition: Benjamin Yaroch, A.G.Schmidt * * * * Copyright (c) 2011 Parallax * * See end of file for terms of use. * ****************************************************************** Revision History: v1 04-07-2011 - File created v1.01 09-08-2011 - Minor code update to correct days in Month rendering - and replace bytefill with bytemove for the 'ref-id' string v2 01-29-2013 - Fixed an illusive bug that caused problems around the first of the year v2.01 02-02-2013 - Logic order error with previous bug fix Buffer bytes 0-3 contain the IP address of thre SNTP server 1 2 3 Buffer bytes 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |LI | VN |Mode | Stratum | Poll | Precision | 4-7 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Delay | 8-11 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Dispersion | 12-15 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reference Identifier | 16-19 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | 20-23 | Reference Timestamp (64) | | | 24-27 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | 28-31 | Originate Timestamp (64) | | | 32-35 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | 36-39 | Receive Timestamp (64) | | | 40-43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | 48-51 | Transmit Timestamp (64) | | | 52-55 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Key Identifier (optional) (32) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | | Message Digest (optional) (128) | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ }} PUB HumanTime(Offset,TimeStampAddress)|i,Seconds,Days,Years,LYrs,DW,DD,HH,MM,SS,Month,Date,Year ' The NTP timestamp is GMT so add the UTC offset (-4 for EDT and -5 fro EST) Seconds := long[TimeStampAddress] + Offset * 3600 'Local epoch time in seconds Days := ((Seconds >>= 7)/675) + 1 '<- Days since Jan 1, 1900 ... divide by 86,400 and add 1 ' 1-Jan-1900 was a Monday (i.e. Day=1 is Monday, Day=2 is Tuesday, etc ' Days//7 is 0 for Sunday, 1 for Monday, 2 for Tuesday... 6 for Saturday. ' DW := (Days-1) // 7 DW := Days // 7 '<-- Day of the week ranges from 0 (Sunday) to 6 (Saturday) ' DW := ((Days+1) // 7 ) '<-- Changed addind one after // makes the day range 1-7 Years := Days / 365 ' Number of Days THIS year and Days -= (Years * 365) ' number of years since 1900. LYrs := Years / 4 '<- Leap years since 1900 Year := Years + 1900 '<- Current Year Days -= LYrs '<- Leap year Days correction ' for THIS year repeat repeat i from 1 to 12 '<- Calculate number of days Month := 30 ' in each month. Stop if if i&1 <> (i&8)>>3 ' Month has been reached Month += 1 if i == 2 Month := 28 if Days =< Month '<- When done, Days will contain quit ' the number of days so far this if Days > Month ' month. In other words, the Date. Days -= Month { if Days > Month '<- When done, Days will contain Days -= Month ' the number of days so far this if Days =< Month ' month. In other words, the Date. quit } until Days =< Month Month := i '<- Current Month Date := Days '<- Current Date SS := long[TimeStampAddress] + Offset * 3600 SS := SS -(((Years*365)*675)<<7) '<- seconds this year MM := SS / 60 '<- minutes this year SS := SS - (MM * 60) '<- current seconds HH := MM / 60 '<- hours this year MM := MM - (HH * 60) '<- current minutes DD := HH / 24 '<- days this year HH := HH - (DD * 24) '<- current hour DD -= LYrs '<- Leap year Days correction ' for THIS year long[TimeStampAddress][2] := Month<<24+Date<<16+Year long[TimeStampAddress][3] := DW<<24+HH<<16+MM<<8+SS ' DD is redundant but I included it for completion... ' If you subtract the number of days so far this year from ' DD and add one, you should get today's date. This is calculated ' from another angle above from Days
Comments
This is his updated code dated 12-08-2013: