This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Beacon.cs
89 lines (74 loc) · 2.52 KB
/
Beacon.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Godot;
using System;
namespace Telraam_sim
{
public class Beacon : PathFollow2D
{
private Area2D area2D;
private float time;
[Export()] public VBoxContainer LogPanel;
private Random rand = new Random();
// The chance that the beacon receives the transmission of a passing baton
[Export()] public double reliability;
[Export()]
public int BeaconId
{
get { return beaconId; }
set
{
beaconId = value;
label.Text = value.ToString();
}
}
[Export()] public NodePath LabelPath;
private Label label;
private int beaconId;
public override void _Ready()
{
area2D = (Area2D) FindNode("Area2D");
label = GetNode<Label>(LabelPath);
reliability = rand.NextDouble();
UnitOffset = (float) rand.NextDouble();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(float delta)
{
time += delta;
var areas = area2D.GetOverlappingAreas();
if (areas.Count <= 0) return;
foreach (Area2D area in areas)
{
var batonId = area.GetOwner<Baton>().batonId;
var detection = new Detection(batonId, BeaconId, (int) (time * 1000));
// Log to the logpane on the screen
_AddLogToPanel("Detection");
if (JsonLogger.GetInstance().Recording)
{
// Log to file
JsonLogger.GetInstance().LogDetection(detection);
_AddLogToPanel("Log to json file");
}
if (LiveStreamer.GetInstance().Streaming)
{
// Log to tcp socket of telraam
var message = $"{beaconId},{(int) (time * 1000)},{batonId},IGNORE\n";
LiveStreamer.GetInstance().SendString(message);
_AddLogToPanel("Send to tcp stream");
}
}
}
public void _OnPositionChange(float val)
{
UnitOffset = val;
}
private void _AddLogToPanel(string text)
{
Label l = new Label();
// TODO Add date: [2022-02-28 21:04:12]
l.Text = text;
LogPanel.AddChild(l);
// Add to the top
LogPanel.MoveChild(l, 0);
}
}
}