Aligned the Messages

This commit is contained in:
Pascal Serrarens 2025-05-01 11:00:08 +02:00
parent 36740cf598
commit e92edbc381
8 changed files with 22 additions and 68 deletions

View File

@ -9,7 +9,7 @@ namespace RoboidControl {
/// </summary>
public const byte Id = 0xB1;
/// <summary>
/// The length of the message, excluding the binary data
/// The length of the message in bytes, excluding the binary data
/// </summary>
/// For the total size of the message this.bytes.Length should be added to this value.
public const byte length = 4;

View File

@ -9,7 +9,7 @@ namespace RoboidControl {
/// </summary>
public const byte Id = 0x20;
/// <summary>
/// The length of the message
/// The length of the message in bytres
/// </summary>
public const byte length = 3;
/// <summary>
@ -41,6 +41,9 @@ namespace RoboidControl {
if (buffer.Length < DestroyMsg.length)
return 0;
#if DEBUG
System.Console.WriteLine($"Send DestroyMsg [{this.networkId}/{this.thingId}]");
#endif
byte ix = 0;
buffer[ix++] = DestroyMsg.Id;
buffer[ix++] = this.networkId;

View File

@ -11,7 +11,6 @@ namespace RoboidControl {
/// </summary>
/// <param name="buffer">The byte array to parse</param>
public IMessage(byte[] buffer) {
//Deserialize(buffer);
}
/// <summary>

View File

@ -9,7 +9,7 @@ namespace RoboidControl {
/// </summary>
public const byte Id = 0x81;
/// <summary>
/// The length of the message
/// /// The length of the message
/// </summary>
public const byte length = 3;
/// <summary>
@ -22,13 +22,13 @@ namespace RoboidControl {
public byte thingId;
/// <summary>
/// Create a new message for sending
/// Create an investigate message
/// </summary>
/// <param name="networkId">The network ID for the thing</param>
/// <param name="thingId">The ID of the thing</param>
public InvestigateMsg(byte networkId, byte thingId) {
/// <param name="thing">The thing for which the details are requested</param>
public InvestigateMsg(byte networkId, Thing thing) {
this.networkId = networkId;
this.thingId = thingId;
this.thingId = thing.id;
}
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
public InvestigateMsg(byte[] buffer) : base(buffer) { }

View File

@ -8,7 +8,6 @@ namespace RoboidControl {
SendAngle8(buffer, ref ix, v.direction.horizontal);
SendAngle8(buffer, ref ix, v.direction.vertical);
}
public static Spherical ReceiveSpherical(byte[] data, ref byte ix) {
float distance = ReceiveFloat16(data, ref ix);
float horizontal = ReceiveAngle8(data, ref ix);
@ -17,11 +16,6 @@ namespace RoboidControl {
return v;
}
public static void SendQuat32(byte[] buffer, ref byte ix, SwingTwist s) {
Quat32 q32 = Quat32.FromSwingTwist(s);
SendQuat32(buffer, ref ix, q32);
}
public static void SendQuat32(byte[] buffer, ref byte ix, Quat32 q) {
int qx = (int)(q.x * 127 + 128);
int qy = (int)(q.y * 127 + 128);
@ -48,6 +42,11 @@ namespace RoboidControl {
return q;
}
public static void SendQuat32(byte[] buffer, ref byte ix, SwingTwist s) {
Quat32 q32 = Quat32.FromSwingTwist(s);
SendQuat32(buffer, ref ix, q32);
}
public static SwingTwist ReceiveSwingTwist(byte[] data, ref byte ix) {
Quat32 q32 = ReceiveQuat32(data, ref ix);
// UnityEngine.Quaternion q = new(q32.x, q32.y, q32.z, q32.w);
@ -66,7 +65,6 @@ namespace RoboidControl {
sbyte value = (sbyte)(angle / 360.0f * 256.0f);
buffer[ix++] = (byte)value;
}
public static float ReceiveAngle8(byte[] data, ref byte ix) {
float value = (data[ix++] * 180) / 128.0F;
return value;
@ -83,7 +81,6 @@ namespace RoboidControl {
data[ix++] = (byte)((binary >> 8) & 0xFF);
data[ix++] = (byte)(binary & 0xFF);
}
public static float ReceiveFloat16(byte[] data, ref byte ix) {
byte msb = data[ix++];
byte lsb = data[ix++];

View File

@ -40,18 +40,6 @@ namespace RoboidControl {
this.urlLength = (byte)thing.modelUrl.Length;
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.urlLength = (byte)url.Length;
// this.url = url;
// }
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
public ModelUrlMsg(byte[] buffer) {
byte ix = 1;

View File

@ -66,28 +66,8 @@ namespace RoboidControl {
/// 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="position">The position of the thing in local space in meters</param>
/// <param name="orientation">The orientation of the thing in local space</param>
public PoseMsg(byte networkId, byte thingId, Spherical position, SwingTwist orientation, Spherical linearVelocity = null, Spherical angularVelocity = null) {
this.networkId = networkId;
this.thingId = thingId;
this.poseType = 0;
if (this.position != null)
this.poseType |= Pose_Position;
if (this.orientation != null)
this.poseType |= Pose_Orientation;
if (this.linearVelocity != null)
this.poseType |= Pose_LinearVelocity;
if (this.angularVelocity != null)
this.poseType |= Pose_AngularVelocity;
this.position = position;
this.orientation = orientation;
this.linearVelocity = linearVelocity;
this.angularVelocity = angularVelocity;
}
/// <param name="thing">The thing for which the pose should be sent</param>
/// <param name="force">If true, position and orientation are always included, even when they are not updated</param>
public PoseMsg(byte networkId, Thing thing, bool force = false) {
this.networkId = networkId;
this.thingId = thing.id;

View File

@ -1,7 +1,7 @@
namespace RoboidControl {
/// <summary>
/// Message providing generic information about a Thing
/// Message providing generic details about a Thing
/// </summary>
public class ThingMsg : IMessage {
/// <summary>
@ -21,11 +21,11 @@ namespace RoboidControl {
/// </summary>
public byte thingId;
/// <summary>
/// The Thing.Type of the thing
/// The type of thing
/// </summary>
public byte thingType;
/// <summary>
/// The parent of the thing in the hierarachy. This is null for root Things
/// The ID of the parent thing in the hierarchy. This is zero for root things
/// </summary>
public byte parentId;
@ -44,19 +44,6 @@ namespace RoboidControl {
this.parentId = 0;
}
/// <summary>
/// Create a 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="thingType">The type of thing</param>
/// <param name="parentId">The parent of the thing</param>
public ThingMsg(byte networkId, byte thingId, byte thingType, byte parentId) {
this.networkId = networkId;
this.thingId = thingId;
this.thingType = thingType;
this.parentId = parentId;
}
/// <summary>
/// Create a message for receiving
/// </summary>
/// <param name="buffer">The byte array to parse</param>