Skip to content

Commit efe7b7c

Browse files
committed
Check for backend address on data
1 parent e26cab9 commit efe7b7c

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

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: vehicle.idToBoardName[uint16(vehicle.ipToBoardId[strings.Split(notification.From, ":")[0]])],
59-
To: vehicle.idToBoardName[uint16(vehicle.ipToBoardId[strings.Split(notification.To, ":")[0]])],
75+
From: from,
76+
To: to,
6077
Timestamp: notification.Timestamp,
6178
})
6279

0 commit comments

Comments
 (0)