diff --git a/src/LocalParticipant.cs b/src/ParticipantUDP.cs similarity index 93% rename from src/LocalParticipant.cs rename to src/ParticipantUDP.cs index 7dcdde7..bf1db17 100644 --- a/src/LocalParticipant.cs +++ b/src/ParticipantUDP.cs @@ -9,7 +9,7 @@ namespace RoboidControl { /// /// A participant is used for communcation between things /// - public class LocalParticipant : Participant { + public class ParticipantUDP : Participant { public byte[] buffer = new byte[1024]; public ulong publishInterval = 3000; // = 3 seconds @@ -26,7 +26,7 @@ namespace RoboidControl { /// /// Create a porticiapnt /// - public LocalParticipant() { + public ParticipantUDP() { //senders.Add(this); } @@ -34,7 +34,7 @@ namespace RoboidControl { /// Create a participant with the give UDP port /// /// The port number on which to communicate - public LocalParticipant(int port) : this() { + public ParticipantUDP(int port) : this() { this.port = port; } @@ -43,7 +43,7 @@ namespace RoboidControl { /// /// The ip address of the site server /// The port number of the site server - public LocalParticipant(string ipAddress = "0.0.0.0", int port = 7681) : this() { + public ParticipantUDP(string ipAddress = "0.0.0.0", int port = 7681) : this() { this.ipAddress = ipAddress; this.port = port; @@ -61,15 +61,15 @@ namespace RoboidControl { /// /// UDP client to use for communication /// The port number on which to communicate - public LocalParticipant(UdpClient udpClient, int port) : this() { + public ParticipantUDP(UdpClient udpClient, int port) : this() { this.udpClient = udpClient; this.port = port; } - private static LocalParticipant isolatedParticipant = null; - public static LocalParticipant Isolated() { + private static ParticipantUDP isolatedParticipant = null; + public static ParticipantUDP Isolated() { if (isolatedParticipant == null) - isolatedParticipant = new LocalParticipant(0); + isolatedParticipant = new ParticipantUDP(0); return isolatedParticipant; } @@ -182,13 +182,13 @@ namespace RoboidControl { return true; 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); return true; } public void PublishThingInfo(Thing thing) { - //Console.WriteLine("Publish thing info"); + Console.WriteLine("Publish thing info"); this.Publish(new ThingMsg(this.networkId, thing)); this.Publish(new NameMsg(this.networkId, thing)); this.Publish(new ModelUrlMsg(this.networkId, thing)); @@ -275,10 +275,12 @@ namespace RoboidControl { #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}"); + } protected virtual void Process(Participant sender, NetworkIdMsg msg) { - Console.WriteLine($"{this.name} receive network id {this.networkId} {msg.networkId}"); + Console.WriteLine($"{this.name} Process network id {this.networkId} {msg.networkId}"); if (this.networkId != msg.networkId) { this.networkId = msg.networkId; foreach (Thing thing in this.things) //Thing.GetAllThings()) @@ -289,7 +291,7 @@ namespace RoboidControl { protected virtual void Process(Participant sender, InvestigateMsg msg) { } protected virtual void Process(Participant sender, ThingMsg msg) { - //Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]"); + Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]"); } protected virtual void Process(Participant sender, NameMsg msg) { diff --git a/src/SiteServer.cs b/src/SiteServer.cs index 616cada..211e118 100644 --- a/src/SiteServer.cs +++ b/src/SiteServer.cs @@ -7,7 +7,7 @@ namespace RoboidControl { /// /// A site server is a participant which provides a shared simulated environment /// - public class SiteServer : LocalParticipant { + public class SiteServer : ParticipantUDP { public SiteServer(int port = 7681) : this("0.0.0.0", port) { } @@ -42,11 +42,12 @@ namespace RoboidControl { public override void Publish() { } - protected override void Process(Participant remoteParticipant, ParticipantMsg msg) { - if (msg.networkId == 0) { - Console.WriteLine($"{this.name} received New Participant -> {remoteParticipant.networkId}"); - this.Send(remoteParticipant, new NetworkIdMsg(remoteParticipant.networkId)); - } + protected override void Process(Participant sender, ParticipantMsg msg) { + base.Process(sender, msg); + //if (msg.networkId == 0) { + Console.WriteLine($"{this.name} received New Participant -> {sender.networkId}"); + this.Send(sender, new NetworkIdMsg(sender.networkId)); + //} } protected override void Process(Participant sender, NetworkIdMsg msg) { } diff --git a/src/Thing.cs b/src/Thing.cs index 607beec..a39c359 100644 --- a/src/Thing.cs +++ b/src/Thing.cs @@ -65,7 +65,7 @@ namespace RoboidControl { /// Create a new thing without communication abilities /// /// The type of thing - public Thing(byte thingType = (byte)Type.Undetermined, bool invokeEvent = true) : this(LocalParticipant.Isolated(), thingType, invokeEvent) { + public Thing(byte thingType = (byte)Type.Undetermined, bool invokeEvent = true) : this(ParticipantUDP.Isolated(), thingType, invokeEvent) { } /// diff --git a/src/Things/DifferentialDrive.cs b/src/Things/DifferentialDrive.cs index 768ad01..f47ea3a 100644 --- a/src/Things/DifferentialDrive.cs +++ b/src/Things/DifferentialDrive.cs @@ -8,7 +8,7 @@ namespace RoboidControl { public DifferentialDrive() { } /// @brief Create a differential drive with networking support /// @param participant The local participant - public DifferentialDrive(LocalParticipant participant) : base(participant, Type.Undetermined) { } + public DifferentialDrive(ParticipantUDP participant) : base(participant, Type.Undetermined) { } /// @brief Configures the dimensions of the drive /// @param wheelDiameter The diameter of the wheels in meters diff --git a/src/Things/TouchSensor.cs b/src/Things/TouchSensor.cs index 630adea..f85cfd9 100644 --- a/src/Things/TouchSensor.cs +++ b/src/Things/TouchSensor.cs @@ -26,7 +26,7 @@ namespace RoboidControl { public TouchSensor(Thing parent) : base(parent) { } - public LocalParticipant thisParticipant; + public ParticipantUDP thisParticipant; /// /// Value which is true when the sensor is touching something, false otherwise