diff --git a/backend/pkg/logger/data/logger.go b/backend/pkg/logger/data/logger.go index 4198b18c7..7bbd3fcb5 100644 --- a/backend/pkg/logger/data/logger.go +++ b/backend/pkg/logger/data/logger.go @@ -5,6 +5,7 @@ import ( "os" "path" "strconv" + "strings" "sync" "sync/atomic" "time" @@ -95,7 +96,7 @@ func (sublogger *Logger) PushRecord(record abstraction.LoggerRecord) error { valueRepresentation = string(value.Variant()) } - saveFile, err := sublogger.getFile(valueName) + saveFile, err := sublogger.getFile(valueName, dataRecord.From) if err != nil { return err } @@ -120,7 +121,7 @@ func (sublogger *Logger) PushRecord(record abstraction.LoggerRecord) error { return writeErr } -func (sublogger *Logger) getFile(valueName data.ValueName) (*file.CSV, error) { +func (sublogger *Logger) getFile(valueName data.ValueName, board string) (*file.CSV, error) { sublogger.fileLock.Lock() defer sublogger.fileLock.Unlock() @@ -129,17 +130,18 @@ func (sublogger *Logger) getFile(valueName data.ValueName) (*file.CSV, error) { return valueFile, nil } - valueFileRaw, err := sublogger.createFile(valueName) + valueFileRaw, err := sublogger.createFile(valueName, board) sublogger.saveFiles[valueName] = file.NewCSV(valueFileRaw) return sublogger.saveFiles[valueName], err } -func (sublogger *Logger) createFile(valueName data.ValueName) (*os.File, error) { +func (sublogger *Logger) createFile(valueName data.ValueName, board string) (*os.File, error) { filename := path.Join( "logger", loggerHandler.Timestamp.Format(loggerHandler.TimestampFormat), "data", + strings.ToUpper(board), fmt.Sprintf("%s.csv", valueName), ) diff --git a/backend/pkg/vehicle/notification.go b/backend/pkg/vehicle/notification.go index 7fcbd016b..164b4147a 100644 --- a/backend/pkg/vehicle/notification.go +++ b/backend/pkg/vehicle/notification.go @@ -43,7 +43,6 @@ func (vehicle *Vehicle) Notification(notification abstraction.TransportNotificat } func (vehicle *Vehicle) handlePacketNotification(notification transport.PacketNotification) error { - var from string var to string switch p := notification.Packet.(type) { @@ -55,19 +54,20 @@ func (vehicle *Vehicle) handlePacketNotification(notification transport.PacketNo return errors.Join(fmt.Errorf("update data to frontend (data with id %d from %s to %s)", p.Id(), notification.From, notification.To), err) } - from_ip := strings.Split(notification.From, ":")[0] - to_ip := strings.Split(notification.To, ":")[0] - - if from_ip == "192.168.0.9" { - from = "backend" - } else { - from = vehicle.idToBoardName[uint16(vehicle.ipToBoardId[from_ip])] + from, exists := vehicle.idToBoardName[uint16(notification.Packet.Id())] + if !exists { + from = notification.From } - if to_ip == "192.168.0.9" { + to_ip := strings.Split(notification.To, ":")[0] + + if to_ip == "192.168.0.9" || to_ip == "127.0.0.9" { to = "backend" } else { - to = vehicle.idToBoardName[uint16(vehicle.ipToBoardId[to_ip])] + to, exists = vehicle.idToBoardName[uint16(notification.Packet.Id())] + if !exists { + to = notification.From + } } err = vehicle.logger.PushRecord(&data_logger.Record{