diff --git a/PlantBox.Shared/Communication/Command.cs b/PlantBox.Shared/Communication/Command.cs index 7744d63..7e531bc 100644 --- a/PlantBox.Shared/Communication/Command.cs +++ b/PlantBox.Shared/Communication/Command.cs @@ -4,6 +4,9 @@ using System.Text; namespace PlantBox.Shared.Communication { + /// + /// All valid commands as described in the Wiki > Commands + /// public enum Command { Captors, diff --git a/PlantBox.Shared/Communication/CommandPacket.cs b/PlantBox.Shared/Communication/CommandPacket.cs index 37b8187..830ed29 100644 --- a/PlantBox.Shared/Communication/CommandPacket.cs +++ b/PlantBox.Shared/Communication/CommandPacket.cs @@ -6,18 +6,41 @@ using System.Text; namespace PlantBox.Shared.Communication { + /// + /// Represent a Packet as described in the Wiki > Protocol + /// public class CommandPacket { + /// + /// A valid packet command, see the Wiki > Commands + /// public Command Command { get; } + /// + /// A valid id + /// public ulong ID { get; } + /// + /// Any arguments, see the Wiki page of a command for more infos + /// public string[] Arguments { get; } + /// + /// Create a + /// + /// + /// + /// public CommandPacket(Command command, ulong id, string[] arguments) { Command = command; ID = id; Arguments = arguments ?? Array.Empty(); } + /// + /// Create a + /// + /// + /// public CommandPacket(Command command, params string[] arguments) { Command = command; @@ -25,6 +48,10 @@ namespace PlantBox.Shared.Communication Arguments = arguments != null && arguments.Length > 1 ? arguments.Skip(1).ToArray() : Array.Empty(); } + /// + /// Convert a to a valid text representation of a packet, see Wiki > Protocol + /// + /// A valid packet text representation, ready to be sent public override string ToString() { return $"{Command.ToString().ToUpperInvariant()}\n{ID}{(Arguments.Length > 0 ? $";{string.Join(";", Arguments)}" : string.Empty)}\n"; diff --git a/PlantBox.Shared/Communication/CommandStream.cs b/PlantBox.Shared/Communication/CommandStream.cs index cd39b39..92b225f 100644 --- a/PlantBox.Shared/Communication/CommandStream.cs +++ b/PlantBox.Shared/Communication/CommandStream.cs @@ -6,15 +6,26 @@ using System.Threading.Tasks; namespace PlantBox.Shared.Communication { + /// + /// Wrap a to send easily, see Wiki > Protocol + /// public class CommandStream { private NetworkStream _stream; + /// + /// Create a new + /// + /// A connected and valid public CommandStream(NetworkStream networkStream) { _stream = networkStream; } + /// + /// Read a from the stream + /// + /// public CommandPacket Receive() { // Length @@ -37,6 +48,10 @@ namespace PlantBox.Shared.Communication return new CommandPacket(command, packet[1].Split(';')); } + /// + /// Read a from the stream asynchronously + /// + /// public async Task ReceiveAsync() { // Length @@ -59,6 +74,10 @@ namespace PlantBox.Shared.Communication return new CommandPacket(command, packet[1].Split(';')); } + /// + /// Write a in the stream + /// + /// public void Send(CommandPacket command) { string packet = command.ToString(); @@ -68,6 +87,11 @@ namespace PlantBox.Shared.Communication _stream.Write(data, 0, data.Length); } + /// + /// Write a in the stream asynchronously + /// + /// + /// public async Task SendAsync(CommandPacket command) { string packet = command.ToString(); diff --git a/PlantBox.Shared/Communication/Commands/CommandSerializable.cs b/PlantBox.Shared/Communication/Commands/CommandSerializable.cs index b9002e9..e521a47 100644 --- a/PlantBox.Shared/Communication/Commands/CommandSerializable.cs +++ b/PlantBox.Shared/Communication/Commands/CommandSerializable.cs @@ -4,11 +4,32 @@ using System.Text; namespace PlantBox.Shared.Communication.Commands { + /// + /// A class serializable to a + /// + /// public abstract class CommandSerializable { + /// + /// Serialize all the values in a string , + /// should contains everything to deserialize + /// + /// Valid arguments for a public abstract string[] Serialize(); + + /// + /// Create an instance of the class from a string + /// + /// Arguments from the method + /// initilized accordingly public abstract T Deserialize(string[] arguments); + /// + /// Convert a to a + /// + /// Command type + /// A valid id + /// public CommandPacket ToCommandPacket(Command command, ulong id) { return new CommandPacket(command, id, Serialize()); diff --git a/PlantBox.Shared/Communication/Connection.cs b/PlantBox.Shared/Communication/Connection.cs index d74b471..10641c9 100644 --- a/PlantBox.Shared/Communication/Connection.cs +++ b/PlantBox.Shared/Communication/Connection.cs @@ -4,14 +4,29 @@ using System.Text; namespace PlantBox.Shared.Communication { + /// + /// Contains all informations used to communicate + /// public static class Connection { // UDP + /// + /// Port used by broadcast discovery + /// public const int UDP_PORT = 1401; + /// + /// Request sent for a discovery + /// public static readonly byte[] UDP_REQUEST = { 102, 210, 48, 255 }; + /// + /// Reply sent for a discovery + /// public static readonly byte[] UDP_REPLY = { 102, 210, 48, 0 }; // TCP + /// + /// Port used by the broker to accept clients + /// public const int TCP_PORT = 1402; } }