Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to manually sync with NTP #190

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions Source/Meadow.Contracts/Hardware/INtpClient.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
using System;
using System.Threading.Tasks;

namespace Meadow
namespace Meadow;

/// <summary>
/// Delegate representing a time changed event handler.
/// </summary>
/// <param name="utcTime">The updated UTC time.</param>
public delegate void TimeChangedEventHandler(DateTime utcTime);

/// <summary>
/// Interface for a Network Time Protocol (NTP) client object.
/// </summary>
public interface INtpClient
{
/// <summary>
/// Delegate representing a time changed event handler.
/// Event called when the time is changed.
/// </summary>
/// <param name="utcTime">The updated UTC time.</param>
public delegate void TimeChangedEventHandler(DateTime utcTime);
event TimeChangedEventHandler TimeChanged;

/// <summary>
/// Interface for a Network Time Protocol (NTP) client object.
/// Gets a value indicating whether the NTP client is enabled.
/// </summary>
public interface INtpClient
{
/// <summary>
/// Event called when the time is changed.
/// </summary>
event TimeChangedEventHandler TimeChanged;
bool Enabled { get; }

/// <summary>
/// Gets a value indicating whether the NTP client is enabled.
/// </summary>
bool Enabled { get; }
/// <summary>
/// Gets or sets the poll period for NTP synchronization.
/// </summary>
TimeSpan PollPeriod { get; set; }

/// <summary>
/// Gets or sets the poll period for NTP synchronization.
/// </summary>
TimeSpan PollPeriod { get; set; }
}
/// <summary>
/// Start an NTP time synchronization
/// </summary>
/// <param name="ntpServer">An optional NTP server address. If null, the device will use the platform-configured NTP server address</param>
/// <returns><b>true</b> if successful, otherwise <b>false</b></returns>
Task<bool> Synchronize(string? ntpServer = null);
}
2 changes: 0 additions & 2 deletions Source/Meadow.Contracts/ISleepAwarePeripheral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ public interface ISleepAwarePeripheral
/// Called before the platform goes into Sleep state
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task BeforeSleep(CancellationToken cancellationToken);

/// <summary>
/// Called after the platform returns to Wake state
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task AfterWake(CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,10 @@ public enum NetworkConnectionType
/// </summary>
/// <remarks>This should be a semicolon list of pin names that will be reserved for OS use.</remarks>
public string ReservedPins { get; }

/// <summary>
/// Gets a list of NTP servers used for time synchronization
/// </summary>
public string[] NtpServers { get; }
}
}
Loading