Skip to content

Commit 381bcba

Browse files
authored
Merge pull request #254 from HyperloopUPV-H8/backend/logger-qol
[Backend] Logger QOL updates
2 parents 948ae7c + efe7b7c commit 381bcba

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

backend/pkg/logger/data/logger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ func (sublogger *Logger) getFile(valueName data.ValueName) (*file.CSV, error) {
137137

138138
func (sublogger *Logger) createFile(valueName data.ValueName) (*os.File, error) {
139139
filename := path.Join(
140-
"logger", "data",
140+
"logger",
141141
loggerHandler.Timestamp.Format(loggerHandler.TimestampFormat),
142+
"data",
142143
fmt.Sprintf("%s.csv", valueName),
143144
)
144145

backend/pkg/logger/order/logger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ func (sublogger *Logger) Start() error {
5959

6060
func (sublogger *Logger) createFile() (*os.File, error) {
6161
filename := path.Join(
62-
"logger", "order",
62+
"logger",
6363
logger.Timestamp.Format(logger.TimestampFormat),
64+
"order",
6465
"order.csv",
6566
)
6667

backend/pkg/logger/protection/logger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ func (sublogger *Logger) createFile(boardId abstraction.BoardId) (*os.File, erro
118118
}
119119

120120
filename := path.Join(
121-
"logger", "protections",
121+
"logger",
122122
logger.Timestamp.Format(logger.TimestampFormat),
123+
"protections",
123124
fmt.Sprintf("%s.csv", boardName),
124125
)
125126

backend/pkg/logger/state/logger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ func (sublogger *Logger) PushRecord(record abstraction.LoggerRecord) error {
9494

9595
func (sublogger *Logger) createFile(timestamp time.Time) (*file.CSV, error) {
9696
filename := path.Join(
97-
"logger", "state",
97+
"logger",
9898
logger.Timestamp.Format(logger.TimestampFormat),
99+
"state",
99100
fmt.Sprintf("%s.csv", timestamp.Format(logger.TimestampFormat)),
100101
)
101102

backend/pkg/vehicle/notification.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func (vehicle *Vehicle) Notification(notification abstraction.TransportNotificat
4343
}
4444

4545
func (vehicle *Vehicle) handlePacketNotification(notification transport.PacketNotification) error {
46+
var from string
47+
var to string
4648

4749
switch p := notification.Packet.(type) {
4850
case *data.Packet:
@@ -53,10 +55,25 @@ func (vehicle *Vehicle) handlePacketNotification(notification transport.PacketNo
5355
return errors.Join(fmt.Errorf("update data to frontend (data with id %d from %s to %s)", p.Id(), notification.From, notification.To), err)
5456
}
5557

58+
from_ip := strings.Split(notification.From, ":")[0]
59+
to_ip := strings.Split(notification.To, ":")[0]
60+
61+
if from_ip == "192.168.0.9" {
62+
from = "backend"
63+
} else {
64+
from = vehicle.idToBoardName[uint16(vehicle.ipToBoardId[from_ip])]
65+
}
66+
67+
if to_ip == "192.168.0.9" {
68+
to = "backend"
69+
} else {
70+
to = vehicle.idToBoardName[uint16(vehicle.ipToBoardId[to_ip])]
71+
}
72+
5673
err = vehicle.logger.PushRecord(&data_logger.Record{
5774
Packet: p,
58-
From: notification.From,
59-
To: notification.To,
75+
From: from,
76+
To: to,
6077
Timestamp: notification.Timestamp,
6178
})
6279

0 commit comments

Comments
 (0)