From f90e689097a457ca8833ddb66963fc39080acfdd Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 26 Feb 2017 19:57:06 +0000 Subject: [PATCH] Rewrite PixelCommand to start implementing PixelHub protocol --- PixelHub-Server/PixelHub/PixelCommand.cs | 84 ++++++++++-------------- 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/PixelHub-Server/PixelHub/PixelCommand.cs b/PixelHub-Server/PixelHub/PixelCommand.cs index 26a0241..719be9e 100644 --- a/PixelHub-Server/PixelHub/PixelCommand.cs +++ b/PixelHub-Server/PixelHub/PixelCommand.cs @@ -2,12 +2,33 @@ namespace PixelHub { - public enum PixelWheel + /// + /// The type of message that you are sending. + /// + public enum MessageType { - None, - Left, - Right, - Both + // No command. This is not a valid message type. + None = -1, + // Hard-resets the PixelBot. Useful if something has gone wrong, or to reset it's internal state. + Reset = 0, + // May be sent by either party. Indicates that one or the other doesn't like a message that was sent by the other party. + Error = 1, + // Sent by a PixelBot upon connection. + HandshakeRequest = 5, + // Sent by the server in response to a `HandshakeRequest`. + HandshakeResponse = 6, + // Instructs a PixelBot to perform a movement. + Move = 11, + // Sent by a pixelbot to indicate that the command sent by the server is ok, and that it will proceed to execute it. + CommandOk = 12, + // Sent by a pixelbot to indicate that it has completed executing the command sent previously. + CommandComplete = 13, + // Sent by a pixelbot to indicate that it has failed to complete the execution of a command it received previously. + CommandFailed = 14, + // Sent by the server to request information from a PixelBot. This could be from sensors, configuration, statistics, etc. + InfoRequest = 20, + // Sent by a PixelBot in response to an `InfoRequest` message. + InfoResponse = 21 } /// @@ -16,60 +37,25 @@ namespace PixelHub public class PixelCommand { /// - /// The wheel(s) that should be operated upon. + /// The protocol version that this message is written in. /// - public PixelWheel Wheel { get; set; } + public readonly ushort ProtocolVersion = 1; /// - /// The duration, in milliseconds, that the left wheel should turn for. + /// The type of this message. /// - public int DurationLeft { get; set; } - /// - /// The duration, in milliseconds, that the right wheel should turn for. - /// - /// The duration right. - public int DurationRight { get; set; } + /// The type of the message. + public ushort MessageType { get; private set; } = 0; /// - /// The duration, in milliseconds, that the wheels should turn for. + /// The id of this message, or the message that this message is in direct response to. /// - /// - /// This property sets both the and properties. - /// The getter returns the maximum of the two durations. - /// - public int Duration { - get { - return Math.Max(DurationLeft, DurationRight); - } - set { - DurationLeft = value; - DurationRight = value; - } - } + public uint MessageId; /// - /// Creates a new instance. + /// The length of the containing message. /// - /// The wheel to turn. - /// The duration , in milliseconds, to turn the wheels for. - public PixelCommand(PixelWheel inWheel, int inDuration) - { - Wheel = inWheel; - Duration = inDuration; - } + public uint MessageLength = 0; - /// - /// Compiles the PixelCommand into a raw command string that cna be understood by the PixelBot. - /// - /// The compiled command, ready to be sent over the wire to the PixelBot. - public string AsCompiledCommand() - { - return $"Move:L={DurationLeft},Right={DurationRight}"; - } - - public override string ToString() - { - return string.Format("PixelCommand: Targets Wheel={0} for Duration={1}ms", Wheel, Duration); - } } } \ No newline at end of file