Improved debug logging
This commit is contained in:
parent
6699200195
commit
8357c5d623
@ -60,7 +60,9 @@ namespace RoboidControl {
|
|||||||
if (buffer.Length < BinaryMsg.length + this.data.Length || this.data.Length == 0)
|
if (buffer.Length < BinaryMsg.length + this.data.Length || this.data.Length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
System.Console.Write($"sending Binary [{this.networkId}/{this.thingId}]");
|
#if DEBUG
|
||||||
|
System.Console.WriteLine($"Send BinaryMsg [{this.networkId}/{this.thingId}] {this.dataLength}");
|
||||||
|
#endif
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = BinaryMsg.Id;
|
buffer[ix++] = BinaryMsg.Id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
|
@ -21,6 +21,10 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public byte thingId;
|
public byte thingId;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The length of the url string, excluding the null terminator
|
||||||
|
/// </summary>
|
||||||
|
public byte urlLength;
|
||||||
|
/// <summary>
|
||||||
/// The URL of the model
|
/// The URL of the model
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string url = null;
|
public string url = null;
|
||||||
@ -33,6 +37,7 @@ namespace RoboidControl {
|
|||||||
public ModelUrlMsg(byte networkId, Thing thing) {
|
public ModelUrlMsg(byte networkId, Thing thing) {
|
||||||
this.networkId = networkId;
|
this.networkId = networkId;
|
||||||
this.thingId = thing.id;
|
this.thingId = thing.id;
|
||||||
|
this.urlLength = (byte)thing.modelUrl.Length;
|
||||||
this.url = thing.modelUrl;
|
this.url = thing.modelUrl;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -41,19 +46,20 @@ namespace RoboidControl {
|
|||||||
/// <param name="networkId">The network ID of the thing</param>
|
/// <param name="networkId">The network ID of the thing</param>
|
||||||
/// <param name="thingId">The ID of the thing</param>
|
/// <param name="thingId">The ID of the thing</param>
|
||||||
/// <param name="url">The URL to send</param>
|
/// <param name="url">The URL to send</param>
|
||||||
public ModelUrlMsg(byte networkId, byte thingId, string url) {
|
// public ModelUrlMsg(byte networkId, byte thingId, string url) {
|
||||||
this.networkId = networkId;
|
// this.networkId = networkId;
|
||||||
this.thingId = thingId;
|
// this.thingId = thingId;
|
||||||
this.url = url;
|
// this.urlLength = (byte)url.Length;
|
||||||
}
|
// this.url = url;
|
||||||
|
// }
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
|
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
|
||||||
public ModelUrlMsg(byte[] buffer) {
|
public ModelUrlMsg(byte[] buffer) {
|
||||||
byte ix = 1;
|
byte ix = 1;
|
||||||
this.networkId = buffer[ix++];
|
this.networkId = buffer[ix++];
|
||||||
this.thingId = buffer[ix++];
|
this.thingId = buffer[ix++];
|
||||||
|
|
||||||
int strlen = buffer[ix++];
|
this.urlLength = buffer[ix++];
|
||||||
url = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, strlen);
|
this.url = System.Text.Encoding.UTF8.GetString(buffer, (int)ix, this.urlLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
||||||
@ -61,6 +67,9 @@ namespace RoboidControl {
|
|||||||
if (string.IsNullOrEmpty(this.url))
|
if (string.IsNullOrEmpty(this.url))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine($"Send ModelUrlMsg [{this.networkId}/{this.thingId}] {this.urlLength} {this.url}");
|
||||||
|
#endif
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = ModelUrlMsg.Id;
|
buffer[ix++] = ModelUrlMsg.Id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
|
@ -66,6 +66,9 @@ namespace RoboidControl {
|
|||||||
if (buffer.Length < NameMsg.length + this.name.Length || string.IsNullOrEmpty(this.name))
|
if (buffer.Length < NameMsg.length + this.name.Length || string.IsNullOrEmpty(this.name))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine($"Send NameMsg [{this.networkId}/{this.thingId}] {this.nameLength} {this.name}");
|
||||||
|
#endif
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = NameMsg.Id;
|
buffer[ix++] = NameMsg.Id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
|
@ -34,6 +34,9 @@ namespace RoboidControl {
|
|||||||
if (buffer.Length < NetworkIdMsg.length)
|
if (buffer.Length < NetworkIdMsg.length)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine($"Send NetworkIdMsg {this.networkId}");
|
||||||
|
#endif
|
||||||
buffer[0] = NetworkIdMsg.Id;
|
buffer[0] = NetworkIdMsg.Id;
|
||||||
buffer[1] = this.networkId;
|
buffer[1] = this.networkId;
|
||||||
return NetworkIdMsg.length;
|
return NetworkIdMsg.length;
|
||||||
|
@ -13,6 +13,10 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const byte length = 2;
|
public const byte length = 2;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The length of the text without the null terminator
|
||||||
|
/// </summary>
|
||||||
|
public byte textLength;
|
||||||
|
/// <summary>
|
||||||
/// The text
|
/// The text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string text = "";
|
public string text = "";
|
||||||
@ -22,20 +26,27 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The text to send</param>
|
/// <param name="text">The text to send</param>
|
||||||
public TextMsg(string text) {
|
public TextMsg(string text) {
|
||||||
|
this.textLength = (byte)text.Length;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
|
/// @copydoc Passer::RoboidControl::IMessage::IMessage(byte[] buffer)
|
||||||
public TextMsg(byte[] buffer) : base(buffer) { }
|
public TextMsg(byte[] buffer) : base(buffer) {
|
||||||
|
this.textLength = buffer[0];
|
||||||
|
this.text = System.Text.Encoding.UTF8.GetString(buffer, 1, this.textLength);
|
||||||
|
}
|
||||||
|
|
||||||
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
/// @copydoc Passer::RoboidControl::IMessage::Serialize
|
||||||
public override byte Serialize(ref byte[] buffer) {
|
public override byte Serialize(ref byte[] buffer) {
|
||||||
if (buffer.Length < TextMsg.length + this.text.Length || this.text.Length == 0)
|
if (buffer.Length < TextMsg.length + this.text.Length || this.text.Length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine($"Send TextMsg {this.textLength} {this.text}");
|
||||||
|
#endif
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = TextMsg.Id;
|
buffer[ix++] = TextMsg.Id;
|
||||||
buffer[ix++] = (byte)this.text.Length;
|
buffer[ix++] = this.textLength;
|
||||||
for (int textIx = 0; textIx < this.text.Length; textIx++)
|
for (int textIx = 0; textIx < this.text.Length; textIx++)
|
||||||
buffer[ix++] = (byte)this.text[textIx];
|
buffer[ix++] = (byte)this.text[textIx];
|
||||||
return ix;
|
return ix;
|
||||||
|
@ -77,6 +77,9 @@ namespace RoboidControl {
|
|||||||
if (buffer.Length < ThingMsg.length)
|
if (buffer.Length < ThingMsg.length)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
System.Console.WriteLine($"Send ThingMsg [{this.networkId}/{this.thingId}] {this.thingType} {this.parentId}");
|
||||||
|
#endif
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
buffer[ix++] = ThingMsg.id;
|
buffer[ix++] = ThingMsg.id;
|
||||||
buffer[ix++] = this.networkId;
|
buffer[ix++] = this.networkId;
|
||||||
|
@ -189,7 +189,7 @@ namespace RoboidControl {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
IPEndPoint participantEndpoint = new IPEndPoint(IPAddress.Parse(owner.ipAddress), owner.port);
|
IPEndPoint participantEndpoint = new IPEndPoint(IPAddress.Parse(owner.ipAddress), owner.port);
|
||||||
Console.WriteLine($"msg to {participantEndpoint.Address.ToString()} {participantEndpoint.Port}");
|
// Console.WriteLine($"msg to {participantEndpoint.Address.ToString()} {participantEndpoint.Port}");
|
||||||
this.udpClient?.Send(this.buffer, bufferSize, participantEndpoint);
|
this.udpClient?.Send(this.buffer, bufferSize, participantEndpoint);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -241,7 +241,6 @@ namespace RoboidControl {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.Console.Write($"Receive msg {msgId}");
|
|
||||||
switch (msgId) {
|
switch (msgId) {
|
||||||
case ParticipantMsg.Id: // 0xA0 / 160
|
case ParticipantMsg.Id: // 0xA0 / 160
|
||||||
this.Process(sender, new ParticipantMsg(data));
|
this.Process(sender, new ParticipantMsg(data));
|
||||||
@ -284,11 +283,16 @@ namespace RoboidControl {
|
|||||||
#region Process
|
#region Process
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, ParticipantMsg msg) {
|
protected virtual void Process(Participant sender, ParticipantMsg msg) {
|
||||||
Console.WriteLine($"{this.name} Process participant {msg.networkId}");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"{this.name} Process participantMsg {msg.networkId}");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, NetworkIdMsg msg) {
|
protected virtual void Process(Participant sender, NetworkIdMsg msg) {
|
||||||
Console.WriteLine($"{this.name} Process network id {this.networkId} {msg.networkId}");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"{this.name} Process SiteMsg {this.networkId} -> {msg.networkId}");
|
||||||
|
#endif
|
||||||
|
|
||||||
if (this.networkId != msg.networkId) {
|
if (this.networkId != msg.networkId) {
|
||||||
this.networkId = msg.networkId;
|
this.networkId = msg.networkId;
|
||||||
foreach (Thing thing in this.things) //Thing.GetAllThings())
|
foreach (Thing thing in this.things) //Thing.GetAllThings())
|
||||||
@ -296,28 +300,42 @@ namespace RoboidControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, InvestigateMsg msg) { }
|
protected virtual void Process(Participant sender, InvestigateMsg msg) {
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: InvestigateMsg [{msg.networkId}/{msg.thingId}]");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, ThingMsg msg) {
|
protected virtual void Process(Participant sender, ThingMsg msg) {
|
||||||
Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process ThingMsg [{msg.networkId}/{msg.thingId}] {msg.thingType} {msg.parentId}");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, NameMsg msg) {
|
protected virtual void Process(Participant sender, NameMsg msg) {
|
||||||
Console.WriteLine($"Participant: Process name [{msg.networkId}/{msg.thingId}] {msg.name}");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process NameMsg [{msg.networkId}/{msg.thingId}] {msg.nameLength} {msg.name}");
|
||||||
|
#endif
|
||||||
|
|
||||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null)
|
if (thing != null)
|
||||||
thing.name = msg.name;
|
thing.name = msg.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, ModelUrlMsg msg) {
|
protected virtual void Process(Participant sender, ModelUrlMsg msg) {
|
||||||
Console.WriteLine($"Participant: Process model [{msg.networkId}/{msg.thingId}] {msg.url}");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process ModelUrlMsg [{msg.networkId}/{msg.thingId}] {msg.urlLength} {msg.url}");
|
||||||
|
#endif
|
||||||
|
|
||||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null)
|
if (thing != null)
|
||||||
thing.modelUrl = msg.url;
|
thing.modelUrl = msg.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, PoseMsg msg) {
|
protected virtual void Process(Participant sender, PoseMsg msg) {
|
||||||
// Console.WriteLine($"Participant: Process pose [{msg.networkId}/{msg.thingId}] {msg.poseType}");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}");
|
||||||
|
#endif
|
||||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null) {
|
if (thing != null) {
|
||||||
if ((msg.poseType & PoseMsg.Pose_Position) != 0)
|
if ((msg.poseType & PoseMsg.Pose_Position) != 0)
|
||||||
@ -332,14 +350,26 @@ namespace RoboidControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, BinaryMsg msg) {
|
protected virtual void Process(Participant sender, BinaryMsg msg) {
|
||||||
Console.WriteLine($"Participant: Process binary [{msg.networkId}/{msg.thingId}]");
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||||
|
#endif
|
||||||
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
thing?.ProcessBinary(msg.data);
|
thing?.ProcessBinary(msg.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, TextMsg temsgxt) { }
|
protected virtual void Process(Participant sender, TextMsg msg) {
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process TextMsg {msg.textLength} {msg.text}");
|
||||||
|
#endif
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, DestroyMsg msg) { }
|
}
|
||||||
|
|
||||||
|
protected virtual void Process(Participant sender, DestroyMsg msg) {
|
||||||
|
#if DEBUG
|
||||||
|
Console.WriteLine($"Participant: Process ThingMsg [{msg.networkId}/{msg.thingId}]");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void ForwardMessage(IMessage msg) {
|
private void ForwardMessage(IMessage msg) {
|
||||||
// foreach (Participant client in senders) {
|
// foreach (Participant client in senders) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user