initial ESP32 tracker support
This commit is contained in:
parent
64864afcb4
commit
e51159bd1b
@ -9,7 +9,7 @@ namespace RoboidControl {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A participant is used for communcation between things
|
/// A participant is used for communcation between things
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocalParticipant : Participant {
|
public class ParticipantUDP : Participant {
|
||||||
public byte[] buffer = new byte[1024];
|
public byte[] buffer = new byte[1024];
|
||||||
public ulong publishInterval = 3000; // = 3 seconds
|
public ulong publishInterval = 3000; // = 3 seconds
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ namespace RoboidControl {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a porticiapnt
|
/// Create a porticiapnt
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LocalParticipant() {
|
public ParticipantUDP() {
|
||||||
//senders.Add(this);
|
//senders.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace RoboidControl {
|
|||||||
/// Create a participant with the give UDP port
|
/// Create a participant with the give UDP port
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="port">The port number on which to communicate</param>
|
/// <param name="port">The port number on which to communicate</param>
|
||||||
public LocalParticipant(int port) : this() {
|
public ParticipantUDP(int port) : this() {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ipAddress">The ip address of the site server</param>
|
/// <param name="ipAddress">The ip address of the site server</param>
|
||||||
/// <param name="port">The port number of the site server</param>
|
/// <param name="port">The port number of the site server</param>
|
||||||
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.ipAddress = ipAddress;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
|
|
||||||
@ -61,15 +61,15 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="udpClient">UDP client to use for communication</param>
|
/// <param name="udpClient">UDP client to use for communication</param>
|
||||||
/// <param name="port">The port number on which to communicate</param>
|
/// <param name="port">The port number on which to communicate</param>
|
||||||
public LocalParticipant(UdpClient udpClient, int port) : this() {
|
public ParticipantUDP(UdpClient udpClient, int port) : this() {
|
||||||
this.udpClient = udpClient;
|
this.udpClient = udpClient;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LocalParticipant isolatedParticipant = null;
|
private static ParticipantUDP isolatedParticipant = null;
|
||||||
public static LocalParticipant Isolated() {
|
public static ParticipantUDP Isolated() {
|
||||||
if (isolatedParticipant == null)
|
if (isolatedParticipant == null)
|
||||||
isolatedParticipant = new LocalParticipant(0);
|
isolatedParticipant = new ParticipantUDP(0);
|
||||||
return isolatedParticipant;
|
return isolatedParticipant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,13 +182,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PublishThingInfo(Thing thing) {
|
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 ThingMsg(this.networkId, thing));
|
||||||
this.Publish(new NameMsg(this.networkId, thing));
|
this.Publish(new NameMsg(this.networkId, thing));
|
||||||
this.Publish(new ModelUrlMsg(this.networkId, thing));
|
this.Publish(new ModelUrlMsg(this.networkId, thing));
|
||||||
@ -275,10 +275,12 @@ 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}");
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, NetworkIdMsg msg) {
|
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) {
|
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())
|
||||||
@ -289,7 +291,7 @@ namespace RoboidControl {
|
|||||||
protected virtual void Process(Participant sender, InvestigateMsg msg) { }
|
protected virtual void Process(Participant sender, InvestigateMsg msg) { }
|
||||||
|
|
||||||
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}]");
|
Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Process(Participant sender, NameMsg msg) {
|
protected virtual void Process(Participant sender, NameMsg msg) {
|
@ -7,7 +7,7 @@ namespace RoboidControl {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A site server is a participant which provides a shared simulated environment
|
/// A site server is a participant which provides a shared simulated environment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SiteServer : LocalParticipant {
|
public class SiteServer : ParticipantUDP {
|
||||||
|
|
||||||
public SiteServer(int port = 7681) : this("0.0.0.0", port) { }
|
public SiteServer(int port = 7681) : this("0.0.0.0", port) { }
|
||||||
|
|
||||||
@ -42,11 +42,12 @@ namespace RoboidControl {
|
|||||||
public override void Publish() {
|
public override void Publish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Process(Participant remoteParticipant, ParticipantMsg msg) {
|
protected override void Process(Participant sender, ParticipantMsg msg) {
|
||||||
if (msg.networkId == 0) {
|
base.Process(sender, msg);
|
||||||
Console.WriteLine($"{this.name} received New Participant -> {remoteParticipant.networkId}");
|
//if (msg.networkId == 0) {
|
||||||
this.Send(remoteParticipant, new NetworkIdMsg(remoteParticipant.networkId));
|
Console.WriteLine($"{this.name} received New Participant -> {sender.networkId}");
|
||||||
}
|
this.Send(sender, new NetworkIdMsg(sender.networkId));
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Process(Participant sender, NetworkIdMsg msg) { }
|
protected override void Process(Participant sender, NetworkIdMsg msg) { }
|
||||||
|
@ -65,7 +65,7 @@ namespace RoboidControl {
|
|||||||
/// Create a new thing without communication abilities
|
/// Create a new thing without communication abilities
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="thingType">The type of thing</param>
|
/// <param name="thingType">The type of thing</param>
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -8,7 +8,7 @@ namespace RoboidControl {
|
|||||||
public DifferentialDrive() { }
|
public DifferentialDrive() { }
|
||||||
/// @brief Create a differential drive with networking support
|
/// @brief Create a differential drive with networking support
|
||||||
/// @param participant The local participant
|
/// @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
|
/// @brief Configures the dimensions of the drive
|
||||||
/// @param wheelDiameter The diameter of the wheels in meters
|
/// @param wheelDiameter The diameter of the wheels in meters
|
||||||
|
@ -26,7 +26,7 @@ namespace RoboidControl {
|
|||||||
|
|
||||||
public TouchSensor(Thing parent) : base(parent) { }
|
public TouchSensor(Thing parent) : base(parent) { }
|
||||||
|
|
||||||
public LocalParticipant thisParticipant;
|
public ParticipantUDP thisParticipant;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Value which is true when the sensor is touching something, false otherwise
|
/// Value which is true when the sensor is touching something, false otherwise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user