This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from dnp3/dnptimesource
Provide IDnpTimeSource in Java and C# bindings.
- Loading branch information
Showing
53 changed files
with
390 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2013-2019 Automatak, LLC | ||
// | ||
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Automatak | ||
// LLC (www.automatak.com) under one or more contributor license agreements. | ||
// See the NOTICE file distributed with this work for additional information | ||
// regarding copyright ownership. Green Energy Corp and Automatak LLC license | ||
// this file to you under the Apache License, Version 2.0 (the "License"); you | ||
// may not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
|
||
namespace Automatak.DNP3.Interface | ||
{ | ||
public class DNPTime | ||
{ | ||
public static DNPTime Unset = new DNPTime(DateTime.MinValue, TimestampQuality.INVALID); | ||
public static DNPTime Now = new DNPTime(DateTime.Now, TimestampQuality.INVALID); | ||
|
||
private static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
public static DNPTime FromEpoch(Int64 epochTime, TimestampQuality quality) | ||
{ | ||
var ms = TimeSpan.FromMilliseconds(epochTime); | ||
if (ms > DateTime.MaxValue - Epoch) | ||
{ | ||
return new DNPTime(DateTime.MaxValue, quality); | ||
} | ||
else | ||
{ | ||
return new DNPTime(Epoch.Add(ms), quality); | ||
} | ||
} | ||
|
||
public DNPTime(DateTime time) | ||
{ | ||
new DNPTime(time, TimestampQuality.INVALID); | ||
} | ||
|
||
public DNPTime(DateTime time, TimestampQuality quality) | ||
{ | ||
this.value = time; | ||
this.quality = quality; | ||
} | ||
|
||
public DateTime Value | ||
{ | ||
get { return this.value; } | ||
} | ||
|
||
public TimestampQuality Quality | ||
{ | ||
get { return this.quality; } | ||
} | ||
|
||
public UInt64 ToEpoch() | ||
{ | ||
var ticks = (UInt64)this.value.ToUniversalTime().Subtract(Epoch).Ticks; | ||
return ticks / TimeSpan.TicksPerMillisecond; | ||
} | ||
|
||
private DateTime value; | ||
private TimestampQuality quality; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2013-2019 Automatak, LLC | ||
// | ||
// Licensed to Green Energy Corp (www.greenenergycorp.com) and Automatak | ||
// LLC (www.automatak.com) under one or more contributor license agreements. | ||
// See the NOTICE file distributed with this work for additional information | ||
// regarding copyright ownership. Green Energy Corp and Automatak LLC license | ||
// this file to you under the Apache License, Version 2.0 (the "License"); you | ||
// may not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Automatak.DNP3.Interface | ||
{ | ||
/// <summary> | ||
/// Interface that defines a method to get DNPTime source | ||
/// </summary> | ||
public interface IDnpTimeSource | ||
{ | ||
/// <summary> | ||
/// Returns a DNPTime of the current time. | ||
/// This value is used when freezing counters. | ||
/// </summary> | ||
DNPTime Now(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.