77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
namespace RoboidControl {
|
|
|
|
/// <summary>
|
|
/// Message for communicating the URL for a model of the thing
|
|
/// </summary>
|
|
public class ModelUrlMsg : IMessage {
|
|
/// <summary>
|
|
/// The message ID
|
|
/// </summary>
|
|
public const byte Id = 0x90; // (144) Model URL
|
|
/// <summary>
|
|
/// The length of the message without th URL itself
|
|
/// </summary>
|
|
public const byte length = 4;
|
|
/// <summary>
|
|
/// The network ID of the thing
|
|
/// </summary>
|
|
public byte networkId;
|
|
/// <summary>
|
|
/// The ID of the thing
|
|
/// </summary>
|
|
public byte thingId;
|
|
/// <summary>
|
|
/// The URL of the model
|
|
/// </summary>
|
|
public string url = null;
|
|
|
|
/// <summary>
|
|
/// Create a new message for sending
|
|
/// </summary>
|
|
/// <param name="networkId">The network ID of the thing</param>
|
|
/// <param name="thing">The thing for which to send the model URL</param>
|
|
public ModelUrlMsg(byte networkId, Thing thing) {
|
|
this.networkId = networkId;
|
|
this.thingId = thing.id;
|
|
this.url = thing.modelUrl;
|
|
}
|
|
/// <summary>
|
|
/// Create a new message for sending
|
|
/// </summary>
|
|
/// <param name="networkId">The network ID of the thing</param>
|
|
/// <param name="thingId">The ID of the thing</param>
|
|
/// <param name="url">The URL to send</param>
|
|
public ModelUrlMsg(byte networkId, byte thingId, string url) {
|
|
this.networkId = networkId;
|
|
this.thingId = thingId;
|
|
this.url = url;
|
|
}
|
|
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
|
|
public ModelUrlMsg(byte[] buffer) {
|
|
byte ix = 1;
|
|
this.networkId = buffer[ix++];
|
|
this.thingId = buffer[ix++];
|
|
|
|
int strlen = buffer[ix++];
|
|
url = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
|
}
|
|
|
|
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
|
public override byte Serialize(ref byte[] buffer) {
|
|
if (this.url == null)
|
|
return 0;
|
|
|
|
byte ix = 0;
|
|
buffer[ix++] = ModelUrlMsg.Id;
|
|
buffer[ix++] = this.networkId;
|
|
buffer[ix++] = this.thingId; // Thing Id
|
|
|
|
buffer[ix++] = (byte)this.url.Length;
|
|
for (int urlIx = 0; urlIx < this.url.Length; urlIx++)
|
|
buffer[ix++] = (byte)url[urlIx];
|
|
return ix;
|
|
}
|
|
|
|
}
|
|
|
|
} |