Compare commits

..

No commits in common. "f90e689097a457ca8833ddb66963fc39080acfdd" and "de6a5b47986954061ce215eb3e36c4fc38923dfe" have entirely different histories.

2 changed files with 51 additions and 37 deletions

View file

@ -177,8 +177,8 @@ Type | Name | Description
-------:|-------------------|------------- -------:|-------------------|-------------
0 | Reset | Hard-resets the PixelBot. Useful if something has gone wrong, or to reset it's internal state. 0 | Reset | Hard-resets the PixelBot. Useful if something has gone wrong, or to reset it's internal state.
1 | Error | May be sent by either party. Indicates that one or the other doesn't like a message that was sent by the other party. 1 | Error | May be sent by either party. Indicates that one or the other doesn't like a message that was sent by the other party.
5 | HandshakeRequest | Sent by a PixelBot upon connection. 1 | HandshakeRequest | Sent by a PixelBot upon connection.
6 | HandshakeResponse | Sent by the server in response to a `HandshakeRequest`. 2 | HandshakeResponse | Sent by the server in response to a `HandshakeRequest`.
11 | Move | Instructs a PixelBot to perform a movement. 11 | Move | Instructs a PixelBot to perform a movement.
12 | CommandOk | Sent by a pixelbot to indicate that the command sent by the server is ok, and that it will proceed to execute it. 12 | CommandOk | Sent by a pixelbot to indicate that the command sent by the server is ok, and that it will proceed to execute it.
13 | CommandComplete | Sent by a pixelbot to indicate that it has completed executing the command sent previously. 13 | CommandComplete | Sent by a pixelbot to indicate that it has completed executing the command sent previously.

View file

@ -2,33 +2,12 @@
namespace PixelHub namespace PixelHub
{ {
/// <summary> public enum PixelWheel
/// The type of message that you are sending.
/// </summary>
public enum MessageType
{ {
// No command. This is not a valid message type. None,
None = -1, Left,
// Hard-resets the PixelBot. Useful if something has gone wrong, or to reset it's internal state. Right,
Reset = 0, Both
// 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
} }
/// <summary> /// <summary>
@ -37,25 +16,60 @@ namespace PixelHub
public class PixelCommand public class PixelCommand
{ {
/// <summary> /// <summary>
/// The protocol version that this message is written in. /// The wheel(s) that should be operated upon.
/// </summary> /// </summary>
public readonly ushort ProtocolVersion = 1; public PixelWheel Wheel { get; set; }
/// <summary> /// <summary>
/// The type of this message. /// The duration, in milliseconds, that the left wheel should turn for.
/// </summary> /// </summary>
/// <value>The type of the message.</value> public int DurationLeft { get; set; }
public ushort MessageType { get; private set; } = 0; /// <summary>
/// The duration, in milliseconds, that the right wheel should turn for.
/// </summary>
/// <value>The duration right.</value>
public int DurationRight { get; set; }
/// <summary> /// <summary>
/// The id of this message, or the message that this message is in direct response to. /// The duration, in milliseconds, that the wheels should turn for.
/// </summary> /// </summary>
public uint MessageId; /// <description>
/// This property sets both the <see cref="DurationLeft" /> and <see cref="DurationRight" /> properties.
/// <summary> /// The getter returns the maximum of the two durations.
/// The length of the containing message. /// </description>
/// </summary> public int Duration {
public uint MessageLength = 0; get {
return Math.Max(DurationLeft, DurationRight);
}
set {
DurationLeft = value;
DurationRight = value;
}
}
/// <summary>
/// Creates a new <see cref="PixelCommand" /> instance.
/// </summary>
/// <param name="inWheel">The wheel to turn.</param>
/// <param name="inDuration">The duration , in milliseconds, to turn the wheels for.</param>
public PixelCommand(PixelWheel inWheel, int inDuration)
{
Wheel = inWheel;
Duration = inDuration;
}
/// <summary>
/// Compiles the PixelCommand into a raw command string that cna be understood by the PixelBot.
/// </summary>
/// <returns>The compiled command, ready to be sent over the wire to the PixelBot.</returns>
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);
}
} }
} }