Compare commits

...

2 commits

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