diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-11-02 15:33:14 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-11-02 15:33:14 +0200 |
| commit | 099c62acdbbf1d8f615a899e23a45e9685c58575 (patch) | |
| tree | 2410674f47904f7849fa01bcd57eef6929ee378c /Software | |
| parent | 0c15fca17f46886b698cf41c09fec827211c235a (diff) | |
| download | Tango-099c62acdbbf1d8f615a899e23a45e9685c58575.tar.gz Tango-099c62acdbbf1d8f615a899e23a45e9685c58575.zip | |
Implemented PRM message factory.
Implemented Tango message wrapper.
Added message types.
Implemented unit test for reading writing and validating a message.
Diffstat (limited to 'Software')
20 files changed, 1111 insertions, 4 deletions
diff --git a/Software/PMR/Messages/.settings/com.google.eclipse.protobuf.Protobuf.prefs b/Software/PMR/Messages/.settings/com.google.eclipse.protobuf.Protobuf.prefs index ae5e40a11..620e6ef0b 100644 --- a/Software/PMR/Messages/.settings/com.google.eclipse.protobuf.Protobuf.prefs +++ b/Software/PMR/Messages/.settings/com.google.eclipse.protobuf.Protobuf.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -paths.directoryPaths=${workspace_loc\:/${project}/Common},${workspace_loc\:/${project}/Job},${workspace_loc\:/${project}} +paths.directoryPaths=${workspace_loc\:/${project}/Jobs},${workspace_loc\:/${project}/Common},${workspace_loc\:/${project}} paths.filesInMultipleDirectories=true paths.filesInOneDirectoryOnly=false diff --git a/Software/PMR/Messages/Common/MessageContainer.proto b/Software/PMR/Messages/Common/MessageContainer.proto new file mode 100644 index 000000000..319f3fd8f --- /dev/null +++ b/Software/PMR/Messages/Common/MessageContainer.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package Tango.PMR.Common; + +import "MessageType.proto"; + +message MessageContainer +{ + MessageType Type = 1; + bytes Data = 2; +} + diff --git a/Software/PMR/Messages/Common/MessageType.proto b/Software/PMR/Messages/Common/MessageType.proto new file mode 100644 index 000000000..a4e84b9b1 --- /dev/null +++ b/Software/PMR/Messages/Common/MessageType.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package Tango.PMR.Common; + +enum MessageType +{ + RGB = 0; + Job = 1; + Segment = 2; +} diff --git a/Software/PMR/Messages/Common/RGB.proto b/Software/PMR/Messages/Common/RGB.proto index 95919f79c..827c362c4 100644 --- a/Software/PMR/Messages/Common/RGB.proto +++ b/Software/PMR/Messages/Common/RGB.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package PMR.Common; +package Tango.PMR.Common; message RGB { diff --git a/Software/PMR/Messages/Job/Job.proto b/Software/PMR/Messages/Jobs/Job.proto index dd127ea89..13e5a91aa 100644 --- a/Software/PMR/Messages/Job/Job.proto +++ b/Software/PMR/Messages/Jobs/Job.proto @@ -2,7 +2,7 @@ syntax = "proto3"; import "Segment.proto"; -package PMR.Job; +package Tango.PMR.Jobs; message Job { diff --git a/Software/PMR/Messages/Job/Segment.proto b/Software/PMR/Messages/Jobs/Segment.proto index 7ad58da7d..14986170f 100644 --- a/Software/PMR/Messages/Job/Segment.proto +++ b/Software/PMR/Messages/Jobs/Segment.proto @@ -2,7 +2,7 @@ syntax = "proto3"; import "RGB.proto"; -package PMR.Job; +package Tango.PMR.Jobs; message Segment diff --git a/Software/Visual Studio/Tango.PMR/Common/MessageContainer.cs b/Software/Visual Studio/Tango.PMR/Common/MessageContainer.cs new file mode 100644 index 000000000..c887da2f4 --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Common/MessageContainer.cs @@ -0,0 +1,188 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: MessageContainer.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Common { + + /// <summary>Holder for reflection information generated from MessageContainer.proto</summary> + public static partial class MessageContainerReflection { + + #region Descriptor + /// <summary>File descriptor for MessageContainer.proto</summary> + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static MessageContainerReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChZNZXNzYWdlQ29udGFpbmVyLnByb3RvEhBUYW5nby5QTVIuQ29tbW9uGhFN", + "ZXNzYWdlVHlwZS5wcm90byJNChBNZXNzYWdlQ29udGFpbmVyEisKBFR5cGUY", + "ASABKA4yHS5UYW5nby5QTVIuQ29tbW9uLk1lc3NhZ2VUeXBlEgwKBERhdGEY", + "AiABKAxiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Tango.PMR.Common.MessageTypeReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Common.MessageContainer), global::Tango.PMR.Common.MessageContainer.Parser, new[]{ "Type", "Data" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class MessageContainer : pb::IMessage<MessageContainer> { + private static readonly pb::MessageParser<MessageContainer> _parser = new pb::MessageParser<MessageContainer>(() => new MessageContainer()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser<MessageContainer> Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.Common.MessageContainerReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MessageContainer() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MessageContainer(MessageContainer other) : this() { + type_ = other.type_; + data_ = other.data_; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MessageContainer Clone() { + return new MessageContainer(this); + } + + /// <summary>Field number for the "Type" field.</summary> + public const int TypeFieldNumber = 1; + private global::Tango.PMR.Common.MessageType type_ = 0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Tango.PMR.Common.MessageType Type { + get { return type_; } + set { + type_ = value; + } + } + + /// <summary>Field number for the "Data" field.</summary> + public const int DataFieldNumber = 2; + private pb::ByteString data_ = pb::ByteString.Empty; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString Data { + get { return data_; } + set { + data_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as MessageContainer); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(MessageContainer other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Type != other.Type) return false; + if (Data != other.Data) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Type != 0) hash ^= Type.GetHashCode(); + if (Data.Length != 0) hash ^= Data.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Type != 0) { + output.WriteRawTag(8); + output.WriteEnum((int) Type); + } + if (Data.Length != 0) { + output.WriteRawTag(18); + output.WriteBytes(Data); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Type != 0) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type); + } + if (Data.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(MessageContainer other) { + if (other == null) { + return; + } + if (other.Type != 0) { + Type = other.Type; + } + if (other.Data.Length != 0) { + Data = other.Data; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 8: { + type_ = (global::Tango.PMR.Common.MessageType) input.ReadEnum(); + break; + } + case 18: { + Data = input.ReadBytes(); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual Studio/Tango.PMR/Common/MessageType.cs b/Software/Visual Studio/Tango.PMR/Common/MessageType.cs new file mode 100644 index 000000000..667453399 --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Common/MessageType.cs @@ -0,0 +1,46 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: MessageType.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Common { + + /// <summary>Holder for reflection information generated from MessageType.proto</summary> + public static partial class MessageTypeReflection { + + #region Descriptor + /// <summary>File descriptor for MessageType.proto</summary> + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static MessageTypeReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChFNZXNzYWdlVHlwZS5wcm90bxIQVGFuZ28uUE1SLkNvbW1vbiosCgtNZXNz", + "YWdlVHlwZRIHCgNSR0IQABIHCgNKb2IQARILCgdTZWdtZW50EAJiBnByb3Rv", + "Mw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Tango.PMR.Common.MessageType), }, null)); + } + #endregion + + } + #region Enums + public enum MessageType { + [pbr::OriginalName("RGB")] Rgb = 0, + [pbr::OriginalName("Job")] Job = 1, + [pbr::OriginalName("Segment")] Segment = 2, + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual Studio/Tango.PMR/Common/RGB.cs b/Software/Visual Studio/Tango.PMR/Common/RGB.cs new file mode 100644 index 000000000..3e69cf66c --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Common/RGB.cs @@ -0,0 +1,214 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: RGB.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Common { + + /// <summary>Holder for reflection information generated from RGB.proto</summary> + public static partial class RGBReflection { + + #region Descriptor + /// <summary>File descriptor for RGB.proto</summary> + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static RGBReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "CglSR0IucHJvdG8SEFRhbmdvLlBNUi5Db21tb24iJgoDUkdCEgkKAVIYASAB", + "KAUSCQoBRxgCIAEoBRIJCgFCGAMgASgFYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Common.RGB), global::Tango.PMR.Common.RGB.Parser, new[]{ "R", "G", "B" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class RGB : pb::IMessage<RGB> { + private static readonly pb::MessageParser<RGB> _parser = new pb::MessageParser<RGB>(() => new RGB()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser<RGB> Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.Common.RGBReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RGB() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RGB(RGB other) : this() { + r_ = other.r_; + g_ = other.g_; + b_ = other.b_; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RGB Clone() { + return new RGB(this); + } + + /// <summary>Field number for the "R" field.</summary> + public const int RFieldNumber = 1; + private int r_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int R { + get { return r_; } + set { + r_ = value; + } + } + + /// <summary>Field number for the "G" field.</summary> + public const int GFieldNumber = 2; + private int g_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int G { + get { return g_; } + set { + g_ = value; + } + } + + /// <summary>Field number for the "B" field.</summary> + public const int BFieldNumber = 3; + private int b_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int B { + get { return b_; } + set { + b_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as RGB); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(RGB other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (R != other.R) return false; + if (G != other.G) return false; + if (B != other.B) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (R != 0) hash ^= R.GetHashCode(); + if (G != 0) hash ^= G.GetHashCode(); + if (B != 0) hash ^= B.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (R != 0) { + output.WriteRawTag(8); + output.WriteInt32(R); + } + if (G != 0) { + output.WriteRawTag(16); + output.WriteInt32(G); + } + if (B != 0) { + output.WriteRawTag(24); + output.WriteInt32(B); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (R != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(R); + } + if (G != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(G); + } + if (B != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(B); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(RGB other) { + if (other == null) { + return; + } + if (other.R != 0) { + R = other.R; + } + if (other.G != 0) { + G = other.G; + } + if (other.B != 0) { + B = other.B; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 8: { + R = input.ReadInt32(); + break; + } + case 16: { + G = input.ReadInt32(); + break; + } + case 24: { + B = input.ReadInt32(); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual Studio/Tango.PMR/Jobs/Job.cs b/Software/Visual Studio/Tango.PMR/Jobs/Job.cs new file mode 100644 index 000000000..543bc1e43 --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Jobs/Job.cs @@ -0,0 +1,179 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: Job.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Jobs { + + /// <summary>Holder for reflection information generated from Job.proto</summary> + public static partial class JobReflection { + + #region Descriptor + /// <summary>File descriptor for Job.proto</summary> + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static JobReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "CglKb2IucHJvdG8SDlRhbmdvLlBNUi5Kb2JzGg1TZWdtZW50LnByb3RvIj4K", + "A0pvYhIMCgROYW1lGAEgASgJEikKCFNlZ21lbnRzGAIgAygLMhcuVGFuZ28u", + "UE1SLkpvYnMuU2VnbWVudGIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Tango.PMR.Jobs.SegmentReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Jobs.Job), global::Tango.PMR.Jobs.Job.Parser, new[]{ "Name", "Segments" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class Job : pb::IMessage<Job> { + private static readonly pb::MessageParser<Job> _parser = new pb::MessageParser<Job>(() => new Job()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser<Job> Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.Jobs.JobReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Job() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Job(Job other) : this() { + name_ = other.name_; + segments_ = other.segments_.Clone(); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Job Clone() { + return new Job(this); + } + + /// <summary>Field number for the "Name" field.</summary> + public const int NameFieldNumber = 1; + private string name_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// <summary>Field number for the "Segments" field.</summary> + public const int SegmentsFieldNumber = 2; + private static readonly pb::FieldCodec<global::Tango.PMR.Jobs.Segment> _repeated_segments_codec + = pb::FieldCodec.ForMessage(18, global::Tango.PMR.Jobs.Segment.Parser); + private readonly pbc::RepeatedField<global::Tango.PMR.Jobs.Segment> segments_ = new pbc::RepeatedField<global::Tango.PMR.Jobs.Segment>(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField<global::Tango.PMR.Jobs.Segment> Segments { + get { return segments_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Job); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Job other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if(!segments_.Equals(other.segments_)) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + hash ^= segments_.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + segments_.WriteTo(output, _repeated_segments_codec); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + size += segments_.CalculateSize(_repeated_segments_codec); + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Job other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + segments_.Add(other.segments_); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + segments_.AddEntriesFrom(input, _repeated_segments_codec); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual Studio/Tango.PMR/Jobs/Segment.cs b/Software/Visual Studio/Tango.PMR/Jobs/Segment.cs new file mode 100644 index 000000000..2b2aa04de --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Jobs/Segment.cs @@ -0,0 +1,221 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: Segment.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.Jobs { + + /// <summary>Holder for reflection information generated from Segment.proto</summary> + public static partial class SegmentReflection { + + #region Descriptor + /// <summary>File descriptor for Segment.proto</summary> + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static SegmentReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Cg1TZWdtZW50LnByb3RvEg5UYW5nby5QTVIuSm9icxoJUkdCLnByb3RvIk0K", + "B1NlZ21lbnQSDAoETmFtZRgBIAEoCRIOCgZMZW5ndGgYAiABKAUSJAoFQ29s", + "b3IYAyABKAsyFS5UYW5nby5QTVIuQ29tbW9uLlJHQmIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Tango.PMR.Common.RGBReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Jobs.Segment), global::Tango.PMR.Jobs.Segment.Parser, new[]{ "Name", "Length", "Color" }, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class Segment : pb::IMessage<Segment> { + private static readonly pb::MessageParser<Segment> _parser = new pb::MessageParser<Segment>(() => new Segment()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser<Segment> Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Tango.PMR.Jobs.SegmentReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Segment() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Segment(Segment other) : this() { + name_ = other.name_; + length_ = other.length_; + Color = other.color_ != null ? other.Color.Clone() : null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Segment Clone() { + return new Segment(this); + } + + /// <summary>Field number for the "Name" field.</summary> + public const int NameFieldNumber = 1; + private string name_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// <summary>Field number for the "Length" field.</summary> + public const int LengthFieldNumber = 2; + private int length_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Length { + get { return length_; } + set { + length_ = value; + } + } + + /// <summary>Field number for the "Color" field.</summary> + public const int ColorFieldNumber = 3; + private global::Tango.PMR.Common.RGB color_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Tango.PMR.Common.RGB Color { + get { return color_; } + set { + color_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Segment); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Segment other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Length != other.Length) return false; + if (!object.Equals(Color, other.Color)) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (Length != 0) hash ^= Length.GetHashCode(); + if (color_ != null) hash ^= Color.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Length != 0) { + output.WriteRawTag(16); + output.WriteInt32(Length); + } + if (color_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Color); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Length); + } + if (color_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Color); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Segment other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.Length != 0) { + Length = other.Length; + } + if (other.color_ != null) { + if (color_ == null) { + color_ = new global::Tango.PMR.Common.RGB(); + } + Color.MergeFrom(other.Color); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Length = input.ReadInt32(); + break; + } + case 26: { + if (color_ == null) { + color_ = new global::Tango.PMR.Common.RGB(); + } + input.ReadMessage(color_); + break; + } + } + } + } + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual Studio/Tango.PMR/MessageFactory.cs b/Software/Visual Studio/Tango.PMR/MessageFactory.cs new file mode 100644 index 000000000..9dc8643ee --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/MessageFactory.cs @@ -0,0 +1,41 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Common; + +namespace Tango.PMR +{ + /// <summary> + /// Contains helper class for encoding and decoding PMR messages. + /// </summary> + public static class MessageFactory + { + /// <summary> + /// Creates a new <see cref="TangoMessage{T}"/>. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public static TangoMessage<T> CreateContainer<T>() where T : IMessage<T> + { + TangoMessage<T> message = new TangoMessage<T>(Activator.CreateInstance<T>(), (MessageType)Enum.Parse(typeof(MessageType), typeof(T).Name)); + return message; + } + + /// <summary> + /// Parses the specified <see cref="MessageContainer"/> bytes to <see cref="TangoMessage{T}"/>. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="data">The data.</param> + /// <returns></returns> + public static TangoMessage<T> ParseContainer<T>(byte[] data) where T : IMessage<T> + { + MessageContainer container = MessageContainer.Parser.ParseFrom(data); + MessageParser<T> parser = new MessageParser<T>(() => Activator.CreateInstance<T>()); + TangoMessage<T> tangoMessage = new TangoMessage<T>(parser.ParseFrom(container.Data), container.Type); + return tangoMessage; + } + } +} diff --git a/Software/Visual Studio/Tango.PMR/Properties/AssemblyInfo.cs b/Software/Visual Studio/Tango.PMR/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..e795a8874 --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Twine - Protobuf Message Repository")] +[assembly: ComVisible(false)]
\ No newline at end of file diff --git a/Software/Visual Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual Studio/Tango.PMR/Tango.PMR.csproj new file mode 100644 index 000000000..93f2f41d8 --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/Tango.PMR.csproj @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{E4927038-348D-4295-AAF4-861C58CB3943}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Tango.PMR</RootNamespace> + <AssemblyName>Tango.PMR</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\Build\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> + <HintPath>..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\Versioning\GlobalVersionInfo.cs"> + <Link>GlobalVersionInfo.cs</Link> + </Compile> + <Compile Include="Common\MessageContainer.cs" /> + <Compile Include="Common\MessageType.cs" /> + <Compile Include="Common\RGB.cs" /> + <Compile Include="Jobs\Job.cs" /> + <Compile Include="Jobs\Segment.cs" /> + <Compile Include="MessageFactory.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="TangoMessage.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <PropertyGroup> + <PreBuildEvent>"$(TargetDir)proto-tc.exe" -i "$(SolutionDir)..\PMR\Messages" -o "$(SolutionDir)Tango.PMR" -l CSharp</PreBuildEvent> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/Software/Visual Studio/Tango.PMR/TangoMessage.cs b/Software/Visual Studio/Tango.PMR/TangoMessage.cs new file mode 100644 index 000000000..98cfdebe5 --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/TangoMessage.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR.Common; +using Google.Protobuf; +using System.IO; + +namespace Tango.PMR +{ + /// <summary> + /// Represents a wrapper class for PRM messages. + /// </summary> + /// <typeparam name="T"></typeparam> + public class TangoMessage<T> where T : IMessage<T> + { + /// <summary> + /// Gets or sets the message. + /// </summary> + public T Message { get; set; } + + /// <summary> + /// Gets or sets the message type. + /// </summary> + public MessageType Type { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="TangoMessage{T}"/> class. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="type">The type.</param> + public TangoMessage(T message, MessageType type) + { + Message = message; + Type = type; + } + + /// <summary> + /// Generates a new <see cref="MessageContainer"/> containing the message of type <see cref="T"/> and returns a byte array. + /// </summary> + /// <returns></returns> + public byte[] ToBytes() + { + MessageContainer container = new MessageContainer(); + container.Type = Type; + container.Data = Message.ToByteString(); + + using (MemoryStream ms = new MemoryStream()) + { + container.WriteTo(ms); + return ms.ToArray(); + } + } + } +} diff --git a/Software/Visual Studio/Tango.PMR/packages.config b/Software/Visual Studio/Tango.PMR/packages.config new file mode 100644 index 000000000..e7e6cbade --- /dev/null +++ b/Software/Visual Studio/Tango.PMR/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Google.Protobuf" version="3.4.1" targetFramework="net45" /> +</packages>
\ No newline at end of file diff --git a/Software/Visual Studio/Tango.UnitTesting/Protobuf_TST.cs b/Software/Visual Studio/Tango.UnitTesting/Protobuf_TST.cs index dbb4ac7e8..cefc22714 100644 --- a/Software/Visual Studio/Tango.UnitTesting/Protobuf_TST.cs +++ b/Software/Visual Studio/Tango.UnitTesting/Protobuf_TST.cs @@ -5,6 +5,12 @@ using System.Threading; using System.Collections.Generic; using System.Linq; using System.IO; +using Google.Protobuf; +using Tango.PMR.Jobs; +using Tango.PMR.Common; +using Tango.PMR; +using Tango.Logging; +using Newtonsoft.Json; namespace Tango.UnitTesting { @@ -41,5 +47,46 @@ namespace Tango.UnitTesting Helper.TryDeleteFolder(folder); } } + + /// <summary> + /// Writes and reads a proto message then compares. + /// </summary> + [TestMethod] + public void Read_Write_Message() + { + var console = Helper.InitializeLogging(true); + + TangoMessage<Job> container = MessageFactory.CreateContainer<Job>(); + + container.Message.Name = "Test Job"; + + container.Message.Segments.Add(new Segment() + { + Color = new RGB() { R = 1, G = 2, B = 3 }, + Length = 10, + Name = "Segment 1" + }); + + container.Message.Segments.Add(new Segment() + { + Color = new RGB() { R = 10, G = 20, B = 30 }, + Length = 100, + Name = "Segment 2" + }); + + LogManager.Log("Write Message:" + Environment.NewLine + JsonConvert.SerializeObject(container.Message, Formatting.Indented)); + + var bytes = container.ToBytes(); + + var parsed = MessageFactory.ParseContainer<Job>(bytes); + + LogManager.Log("Read Message:" + Environment.NewLine + JsonConvert.SerializeObject(parsed.Message, Formatting.Indented)); + + Assert.AreEqual(container.Message, parsed.Message); + + LogManager.Log("Test Passed!"); + + console.WaitForConsoleExit().Wait(); + } } } diff --git a/Software/Visual Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 7d3cd3d6b..10b9fad60 100644 --- a/Software/Visual Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -38,12 +38,18 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> + <HintPath>..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> + </Reference> <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> </Reference> <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath> </Reference> + <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> </ItemGroup> @@ -67,6 +73,10 @@ <Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project> <Name>Tango.Logging</Name> </ProjectReference> + <ProjectReference Include="..\Tango.PMR\Tango.PMR.csproj"> + <Project>{e4927038-348d-4295-aaf4-861c58cb3943}</Project> + <Name>Tango.PMR</Name> + </ProjectReference> <ProjectReference Include="..\Tango.Protobuf\Tango.Protobuf.csproj"> <Project>{40073806-914e-4e78-97ab-fa9639308ebe}</Project> <Name>Tango.Protobuf</Name> diff --git a/Software/Visual Studio/Tango.UnitTesting/packages.config b/Software/Visual Studio/Tango.UnitTesting/packages.config index a21677b8f..d3cd9d043 100644 --- a/Software/Visual Studio/Tango.UnitTesting/packages.config +++ b/Software/Visual Studio/Tango.UnitTesting/packages.config @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> + <package id="Google.Protobuf" version="3.4.1" targetFramework="net45" /> <package id="MSTest.TestAdapter" version="1.1.11" targetFramework="net45" /> <package id="MSTest.TestFramework" version="1.1.11" targetFramework="net45" /> + <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/Software/Visual Studio/Tango.sln b/Software/Visual Studio/Tango.sln index 58845d35d..3013eef96 100644 --- a/Software/Visual Studio/Tango.sln +++ b/Software/Visual Studio/Tango.sln @@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Resources", "Resources", "{ Resources\dummyFile.txt = Resources\dummyFile.txt EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.PMR", "Tango.PMR\Tango.PMR.csproj", "{E4927038-348D-4295-AAF4-861C58CB3943}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,6 +65,10 @@ Global {FB82AA6B-1652-452C-8235-4FB2E524FBC0}.Debug|Any CPU.Build.0 = Debug|Any CPU {FB82AA6B-1652-452C-8235-4FB2E524FBC0}.Release|Any CPU.ActiveCfg = Release|Any CPU {FB82AA6B-1652-452C-8235-4FB2E524FBC0}.Release|Any CPU.Build.0 = Release|Any CPU + {E4927038-348D-4295-AAF4-861C58CB3943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4927038-348D-4295-AAF4-861C58CB3943}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4927038-348D-4295-AAF4-861C58CB3943}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4927038-348D-4295-AAF4-861C58CB3943}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE |
