|
|
|
@ -2,12 +2,33 @@
|
|
|
|
|
|
|
|
|
|
namespace PixelHub
|
|
|
|
|
{
|
|
|
|
|
public enum PixelWheel
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The type of message that you are sending.
|
|
|
|
|
/// </summary>
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -16,60 +37,25 @@ namespace PixelHub
|
|
|
|
|
public class PixelCommand
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The wheel(s) that should be operated upon.
|
|
|
|
|
/// The protocol version that this message is written in.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public PixelWheel Wheel { get; set; }
|
|
|
|
|
public readonly ushort ProtocolVersion = 1;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The duration, in milliseconds, that the left wheel should turn for.
|
|
|
|
|
/// The type of this message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int DurationLeft { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The duration, in milliseconds, that the right wheel should turn for.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The duration right.</value>
|
|
|
|
|
public int DurationRight { get; set; }
|
|
|
|
|
/// <value>The type of the message.</value>
|
|
|
|
|
public ushort MessageType { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
/// <description>
|
|
|
|
|
/// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public uint MessageId;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new <see cref="PixelCommand" /> instance.
|
|
|
|
|
/// The length of the containing message.
|
|
|
|
|
/// </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;
|
|
|
|
|
}
|
|
|
|
|
public uint MessageLength = 0;
|
|
|
|
|
|
|
|
|
|
/// <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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|