[CommandHipc(300)] // 4.0.0+ // CalculateMonotonicSystemClockBaseTimePoint(nn::time::SystemClockContext) -> s64 public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context) { SteadyClockCore steadyClock = _timeManager.StandardSteadyClock; if (!steadyClock.IsInitialized()) { return(ResultCode.UninitializedClock); } ITickSource tickSource = context.Device.System.TickSource; SystemClockContext otherContext = context.RequestData.ReadStruct <SystemClockContext>(); SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(tickSource); ResultCode result = ResultCode.TimeMismatch; if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId) { TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency); long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds(); context.ResponseData.Write(baseTimePoint); result = ResultCode.Success; } return(result); }
// SetCurrentTime(nn::time::PosixTime) public ResultCode SetCurrentTime(ServiceCtx context) { if (!_writePermission) { return(ResultCode.PermissionDenied); } long posixTime = context.RequestData.ReadInt64(); SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore(); SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(context.Thread); SystemClockContext clockContext = new SystemClockContext() { Offset = posixTime - currentTimePoint.TimePoint, SteadyTimePoint = currentTimePoint }; ResultCode result = _clockCore.SetSystemClockContext(clockContext); if (result == ResultCode.Success) { result = _clockCore.Flush(clockContext); } return(result); }
private ResultCode GetClockSnapshotFromSystemClockContextInternal(ITickSource tickSource, SystemClockContext userContext, SystemClockContext networkContext, byte type, out ClockSnapshot clockSnapshot) { clockSnapshot = new ClockSnapshot(); SteadyClockCore steadyClockCore = _timeManager.StandardSteadyClock; SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(tickSource); clockSnapshot.IsAutomaticCorrectionEnabled = _timeManager.StandardUserSystemClock.IsAutomaticCorrectionEnabled(); clockSnapshot.UserContext = userContext; clockSnapshot.NetworkContext = networkContext; clockSnapshot.SteadyClockTimePoint = currentTimePoint; ResultCode result = _timeManager.TimeZone.Manager.GetDeviceLocationName(out string deviceLocationName); if (result != ResultCode.Success) { return(result); } char[] tzName = deviceLocationName.ToCharArray(); char[] locationName = new char[0x24]; Array.Copy(tzName, locationName, tzName.Length); clockSnapshot.LocationName = locationName; result = ClockSnapshot.GetCurrentTime(out clockSnapshot.UserTime, currentTimePoint, clockSnapshot.UserContext); if (result == ResultCode.Success) { result = _timeManager.TimeZone.Manager.ToCalendarTimeWithMyRules(clockSnapshot.UserTime, out CalendarInfo userCalendarInfo); if (result == ResultCode.Success) { clockSnapshot.UserCalendarTime = userCalendarInfo.Time; clockSnapshot.UserCalendarAdditionalTime = userCalendarInfo.AdditionalInfo; if (ClockSnapshot.GetCurrentTime(out clockSnapshot.NetworkTime, currentTimePoint, clockSnapshot.NetworkContext) != ResultCode.Success) { clockSnapshot.NetworkTime = 0; } result = _timeManager.TimeZone.Manager.ToCalendarTimeWithMyRules(clockSnapshot.NetworkTime, out CalendarInfo networkCalendarInfo); if (result == ResultCode.Success) { clockSnapshot.NetworkCalendarTime = networkCalendarInfo.Time; clockSnapshot.NetworkCalendarAdditionalTime = networkCalendarInfo.AdditionalInfo; clockSnapshot.Type = type; // Probably a version field? clockSnapshot.Unknown = 0; } } } return(result); }
// GetCurrentTimePoint() -> nn::time::SteadyClockTimePoint public ResultCode GetCurrentTimePoint(ServiceCtx context) { if (!_bypassUninitializedClock && !_steadyClock.IsInitialized()) { return(ResultCode.UninitializedClock); } SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(context.Thread); context.ResponseData.WriteStruct(currentTimePoint); return(ResultCode.Success); }
// GetCurrentTimePoint() -> nn::time::SteadyClockTimePoint public ResultCode GetCurrentTimePoint(ServiceCtx context) { if (!_bypassUninitializedClock && !_steadyClock.IsInitialized()) { return(ResultCode.UninitializedClock); } ITickSource tickSource = context.Device.System.TickSource; SteadyClockTimePoint currentTimePoint = _steadyClock.GetCurrentTimePoint(tickSource); context.ResponseData.WriteStruct(currentTimePoint); return(ResultCode.Success); }
// GetCurrentTime() -> nn::time::PosixTime public ResultCode GetCurrentTime(ServiceCtx context) { SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore(); SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(context.Thread); ResultCode result = _clockCore.GetSystemClockContext(context.Thread, out SystemClockContext clockContext); if (result == ResultCode.Success) { result = ResultCode.TimeMismatch; if (currentTimePoint.ClockSourceId == clockContext.SteadyTimePoint.ClockSourceId) { long posixTime = clockContext.Offset + currentTimePoint.TimePoint; context.ResponseData.Write(posixTime); result = 0; } } return(result); }