-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_generator.go
115 lines (100 loc) · 2.89 KB
/
message_generator.go
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"math/rand"
vehicle_models "github.com/HyperloopUPV-H8/Backend-H8/vehicle/models"
)
type MessageGenerator struct {
boardIds map[string]uint16
kinds map[string]uint16
}
func NewMessageGenerator(kinds, boardIds map[string]uint16) MessageGenerator {
return MessageGenerator{
boardIds: boardIds,
kinds: kinds,
}
}
func (generator MessageGenerator) New() Message {
kind := RandKey(generator.kinds)
if kind == "info" {
return generator.getInfoMessage()
}
return generator.getProtectionMessage(kind)
}
func (generator MessageGenerator) getInfoMessage() InfoMessageAdapter {
return InfoMessageAdapter{
id: generator.kinds["info"],
BoardId: RandVal(generator.boardIds),
Timestamp: randomTimestamp(),
Msg: "We are about to win, if you are a member of the femenine genere, please be aware of Juan. You have been informed.",
}
}
func (generator MessageGenerator) getProtectionMessage(kind string) ProtectionMessageAdapter {
protection := generator.randomProtection(kind)
return ProtectionMessageAdapter{
id: generator.kinds[kind],
BoardId: RandVal(generator.boardIds),
Timestamp: randomTimestamp(),
Protection: protection,
}
}
var protectionKinds = []string{"OUT_OF_BOUNDS", "LOWER_BOUND", "UPPER_BOUND", "NOT_EQUALS", "EQUALS", "TIME_ACCUMULATION", "ERROR_HANDLER"}
func (generator MessageGenerator) randomProtection(kind string) ProtectionAdapter {
protectionKind := protectionKinds[RandInt(len(protectionKinds))]
return ProtectionAdapter{
Name: "VCELL1",
Type: protectionKind,
Data: randomProtectionData(protectionKind),
}
}
func randomProtectionData(kind string) any {
switch kind {
case "OUT_OF_BOUNDS":
return vehicle_models.OutOfBounds{
Value: rand.Float64() * 100,
Bounds: [2]float64{rand.Float64() * 100, rand.Float64() * 100},
}
case "LOWER_BOUND":
return vehicle_models.LowerBound{
Value: rand.Float64() * 100,
Bound: rand.Float64() * 100,
}
case "UPPER_BOUND":
return vehicle_models.UpperBound{
Value: rand.Float64() * 100,
Bound: rand.Float64() * 100,
}
case "EQUALS":
return vehicle_models.Equals{
Value: rand.Float64() * 100,
}
case "NOT_EQUALS":
return vehicle_models.NotEquals{
Value: rand.Float64() * 100,
Want: rand.Float64() * 100,
}
case "TIME_ACCUMULATION":
return vehicle_models.TimeLimit{
Value: rand.Float64() * 100,
Bound: rand.Float64() * 100,
TimeLimit: rand.Float64() * 100,
}
case "ERROR_HANDLER":
return "Starting booster!"
default:
return vehicle_models.NotEquals{
Value: rand.Float64() * 100,
Want: rand.Float64() * 100,
}
}
}
func randomTimestamp() vehicle_models.Timestamp {
return vehicle_models.Timestamp{
Counter: uint16(rand.Int()),
Second: uint8(rand.Int()),
Minute: uint8(rand.Int()),
Hour: uint8(rand.Int()),
Day: uint8(rand.Int()),
Month: uint8(rand.Int()),
Year: uint16(rand.Int()),
}
}