-- file: SetTime.mesa -- edited by Levin, August 11, 1980 5:55 PM -- edited by Brotz, August 11, 1980 5:56 PM DIRECTORY DMSTimeDefs: FROM "DMSTimeDefs", inD: FROM "InteractorDefs", intCommon: FROM "IntCommon", ProcessDefs: FROM "ProcessDefs", PupDefs: FROM "PupDefs", PupTypes: FROM "PupTypes", TimeDefs: FROM "TimeDefs"; SetTime: PROGRAM IMPORTS DMSTimeDefs, intC: intCommon, ProcessDefs, PupDefs, TimeDefs EXPORTS DMSTimeDefs, inD = BEGIN OPEN PupDefs, PupTypes; -- Purpose: determines correct time by probing the network. Msec: TYPE = CARDINAL; timeCheckIntervalMs: Msec = 1000; timeTries: CARDINAL = 5; SetTime: PUBLIC PROCEDURE = BEGIN ProcessDefs.Detach[FORK DoSetTime]; END; -- of SetTime SetLaurelTime: PUBLIC PROCEDURE = BEGIN pt: DMSTimeDefs.PackedTime; nSlopSeconds: CARDINAL; pt.lc _ TimeDefs.CurrentDayTime[]; nSlopSeconds _ TimeDefs.UnpackDT[pt.lc].second; -- Set intC.lastMinuteSeconds so that DMSTime will not be called for at least 15 -- seconds; This may cause the time to not be updated for a whole minute + 14 -- seconds. intC.secondsLastChecked _ intC.lastMinuteSeconds _ pt.lowbits - nSlopSeconds + (IF nSlopSeconds > 45 THEN 60 ELSE 0); DMSTimeDefs.MapPackedTimeToTimeZoneString[pt, intC.timeHouse.text]; intC.timeHouse.houseRefresher[intC.timeHouse]; END; -- of SetLaurelTime -- DoSetTime: PROCEDURE = BEGIN timeSocket: PupSocket; garbageAddress: PupAddress = fillInPupAddress; timeSocket _ PupSocketMake[local: UniqueLocalPupSocketID[], remote: garbageAddress, ticks: MsToTocks[timeCheckIntervalMs]]; THROUGH [0..timeTries) DO IF TryTime[timeSocket] THEN EXIT; ENDLOOP; SetLaurelTime[]; PupSocketDestroy[timeSocket]; END; -- of DoSetTime TryTime: PROCEDURE [timeSocket: PupSocket] RETURNS[responseReceived: BOOLEAN] = BEGIN packet: PupBuffer _ GetFreePupBuffer[]; ResponsePacketData: TYPE = MACHINE DEPENDENT RECORD[ gmtSeconds: DMSTimeDefs.HardwareTime, direction: DMSTimeDefs.WestEast, zoneHours: [0..177B], zoneMinutes: [0..377B], beginDST: WORD, endDST: WORD]; timeInfo: POINTER TO ResponsePacketData; responseReceived _ FALSE; packet.pupType _ dateAltoRequest; SetPupContentsBytes[packet,0]; packet.dest.socket _ miscSrvSoc; packet.source _ timeSocket.getLocalAddress[]; PupRouterBroadcastThis[packet]; -- packet has been handed off, now wait for response. UNTIL responseReceived OR (packet _ timeSocket.get[]) = NIL DO IF packet.pupType = dateAltoIs THEN BEGIN OPEN timeInfo; timeInfo _ LOOPHOLE[@packet.pupBody]; TimeDefs.currentParameters^ _ [direction, zoneHours, 0, beginDST, 0, zoneMinutes, endDST]; TimeDefs.currentTime^ _ gmtSeconds; responseReceived _ TRUE; END; ReturnFreePupBuffer[packet]; ENDLOOP; END; -- of TryTime END. -- of SetTime --z20461(529)\f1