-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mark Lanning
authored and
Mark Lanning
committed
Aug 24, 2024
1 parent
8391c57
commit c714b04
Showing
5 changed files
with
81 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using ThingsLibrary.Schema.Library.Extensions; | ||
|
||
namespace ThingsLibrary.DataType | ||
{ | ||
public class TelemetryEntry | ||
{ | ||
[JsonPropertyName("date")] | ||
public DateTimeOffset Timestamp { get; set; } = DateTime.UtcNow; | ||
|
||
[JsonPropertyName("type")] | ||
public string Type { get; set; } = string.Empty; | ||
|
||
[JsonPropertyName("tags")] | ||
public Dictionary<string, string> Attributes { get; set; } = []; | ||
|
||
public TelemetryEntry() | ||
{ | ||
//nothing | ||
} | ||
|
||
public TelemetryEntry(string type, DateTimeOffset timestamp) | ||
{ | ||
this.Type = type; | ||
this.Timestamp = timestamp; | ||
} | ||
|
||
|
||
|
||
/// <summary> | ||
/// Generate the telemetry sentence | ||
/// </summary> | ||
/// <returns>Telemetry Sentence.. IE: $1724387849602|PA|r:1|s:143|p:PPE Mask|q:1|p:000*79</returns> | ||
public override string ToString() | ||
{ | ||
var sentence = new StringBuilder($"${this.Timestamp.ToUnixTimeMilliseconds()}|{this.Type}"); | ||
sentence.Append(string.Join(string.Empty, this.Attributes.Select(x => $"|{x.Key}:{x.Value}"))); | ||
|
||
sentence.AppendChecksum(); | ||
|
||
return sentence.ToString(); | ||
} | ||
|
||
#region --- Static --- | ||
|
||
public static TelemetryEntry Parse(string telemetrySentence) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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,26 @@ | ||
using ThingsLibrary.DataType; | ||
|
||
namespace ThingsLibrary.Tests.DataType | ||
{ | ||
[TestClass, ExcludeFromCodeCoverage] | ||
public class TelemetryTests | ||
{ | ||
[TestMethod] | ||
public void Basic() | ||
{ | ||
var telem = new TelemetryEntry("sens", DateTime.UtcNow); | ||
|
||
telem.Attributes.Add("gn", "Mark"); | ||
telem.Attributes.Add("cp", "Starlight"); | ||
telem.Attributes.Add("r", "1"); | ||
|
||
var sentence = telem.ToString(); | ||
|
||
var expectedPrefix = $"${telem.Timestamp.ToUnixTimeMilliseconds()}|{telem.Type}|"; | ||
|
||
Assert.IsTrue(sentence.StartsWith(expectedPrefix)); | ||
Assert.IsTrue(sentence.Contains('*')); | ||
} | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tion/ThingsLibrary.Entity.Tests.Integration/ThingsLibrary.Entity.Tests.Integration.csproj
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