82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System;
|
|
|
|
namespace PixelHub
|
|
{
|
|
/// <summary>
|
|
/// The type of message that you are sending.
|
|
/// </summary>
|
|
public enum MessageType
|
|
{
|
|
// 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>
|
|
/// Specifies a single command that is to be sent to a PixelBot.
|
|
/// </summary>
|
|
public abstract class PixelCommand
|
|
{
|
|
/// <summary>
|
|
/// A random number generator. Useful for generating default message ids.
|
|
/// </summary>
|
|
private static Random rand = new Random();
|
|
|
|
/// <summary>
|
|
/// The protocol version that this message is written in.
|
|
/// </summary>
|
|
public readonly ushort ProtocolVersion = 1;
|
|
|
|
/// <summary>
|
|
/// The type of this message.
|
|
/// </summary>
|
|
/// <value>The type of the message.</value>
|
|
public ushort MessageType { get; private set; } = 0;
|
|
|
|
/// <summary>
|
|
/// The id of this message, or the message that this message is in direct response to.
|
|
/// </summary>
|
|
public uint MessageId;
|
|
|
|
/// <summary>
|
|
/// The length of the containing message.
|
|
/// </summary>
|
|
public uint MessageLength = 0;
|
|
|
|
/// <summary>
|
|
/// The payload of the message.
|
|
/// </summary>
|
|
public abstract byte[] Payload { get; protected set; }
|
|
|
|
public PixelCommand()
|
|
{
|
|
byte[] rawMessageId = new byte[sizeof(uint)];
|
|
rand.NextBytes(rawMessageId);
|
|
MessageId = BitConverter.ToUInt32(rawMessageId, 0);
|
|
}
|
|
|
|
public byte[] AsCompiledCommand()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |