Skip to content

Commit

Permalink
Merge pull request #190 from WildernessLabs/feature/ntp-sync
Browse files Browse the repository at this point in the history
add ability to manually sync with NTP
  • Loading branch information
adrianstevens committed Feb 7, 2024
2 parents d606b64 + e000260 commit 14ddc98
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
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; }
}
}

0 comments on commit 14ddc98

Please sign in to comment.