-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize visualization service and update documentation.
- Loading branch information
Showing
29 changed files
with
68 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
software/digital_twin/visualization/scripts/RBConnection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Godot; | ||
using System; | ||
using RabbitMQ.Client; | ||
using RabbitMQ.Client.Events; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
|
||
public partial class RBConnection : Node3D { | ||
private ConnectionFactory factory = new ConnectionFactory() { | ||
Uri = new Uri("amqp://incubator:incubator@localhost:5672") | ||
}; | ||
private IConnection connection; | ||
private IModel channel; | ||
|
||
private string localQueue; | ||
private string exchangeName = "Incubator_AMQP"; | ||
private string ROUTING_KEY_KF_PLANT_STATE = "incubator.record.kalmanfilter.plant.state"; | ||
private string ROUTING_KEY_STATE = "incubator.record.driver.state"; | ||
private List<string> messages = new(); | ||
|
||
[Signal] | ||
public delegate void MessageEventHandler(string message); | ||
|
||
public override void _Ready() { | ||
connection = factory.CreateConnection(); | ||
channel = connection.CreateModel(); | ||
GD.Print("Connection created"); | ||
|
||
localQueue = channel.QueueDeclare(autoDelete: true, exclusive: true); | ||
channel.QueueBind(queue: localQueue, exchange: exchangeName, routingKey: ROUTING_KEY_KF_PLANT_STATE); | ||
channel.QueueBind(queue: localQueue, exchange: exchangeName, routingKey: ROUTING_KEY_STATE); | ||
ReceiveMessage(); | ||
} | ||
|
||
public override void _Process(double delta) { | ||
for (int i = 0; i < messages.Count; i++) { | ||
EmitSignal(SignalName.Message, messages[i]); | ||
} | ||
messages.Clear(); | ||
} | ||
|
||
private void ReceiveMessage() { | ||
GD.Print("Waiting for messages"); | ||
var consumer = new EventingBasicConsumer(channel); | ||
|
||
consumer.Received += (model, ea) => { | ||
var body = ea.Body.ToArray(); | ||
var message = Encoding.ASCII.GetString(body); | ||
messages.Add(message); | ||
}; | ||
|
||
channel.BasicConsume(queue: localQueue, autoAck: true, consumer: consumer); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.