Skip to content

Commit

Permalink
set vehicle token id, tweaks to should use scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Sep 13, 2024
1 parent ddfd03a commit 30c4a4c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
5 changes: 4 additions & 1 deletion internal/loggers/dbc_passive_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
//go:generate mockgen -source dbc_passive_logger.go -destination mocks/dbc_passive_logger_mock.go
type DBCPassiveLogger interface {
StartScanning(ch chan<- models.SignalData) error
// UseNativeScanLogger uses a variety of logic to decide if we should enable DBC file support as well as native Request/Response scanning (they go hand in hand)
// ShouldNativeScanLogger uses a variety of logic to decide if we should enable DBC file support as well as native Request/Response scanning (they go hand in hand)
ShouldNativeScanLogger() bool
SendCANQuery(header uint32, mode uint32, pid uint32) error
StopScanning() error
Expand Down Expand Up @@ -165,6 +165,9 @@ func (dpl *dbcPassiveLogger) ShouldNativeScanLogger() bool {
break
}
}
dpl.logger.Info().Msgf("hardware support: %v, dbc file not nil: %v, pids with python formula: %v",
dpl.hardwareSupport, dpl.dbcFile != nil, pidsPython)

return dpl.hardwareSupport && dpl.dbcFile != nil && !pidsPython
}

Expand Down
73 changes: 37 additions & 36 deletions internal/network/data_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ func (ds *dataSender) SendFingerprintData(data models.FingerprintData) error {
data.Timestamp = time.Now().UTC().UnixMilli()
}
ce := shared.CloudEvent[models.FingerprintData]{
ID: ksuid.New().String(),
Source: "aftermarket/device/fingerprint",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "zone.dimo.aftermarket.device.fingerprint",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
ID: ksuid.New().String(),
Source: "aftermarket/device/fingerprint",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "zone.dimo.aftermarket.device.fingerprint",
DataSchema: "dimo.zone.status/v2.0",
VehicleTokenID: uint32(ds.vehicleInfo.TokenID),
Data: data,
}
payload, err := json.Marshal(ce)
if err != nil {
Expand All @@ -171,22 +172,20 @@ func (ds *dataSender) SendFingerprintData(data models.FingerprintData) error {

func (ds *dataSender) SendDeviceStatusData(data any) error {
ce := models.DeviceDataStatusCloudEvent[any]{
TokenID: ds.vehicleInfo.TokenID,
CloudEvent: shared.CloudEvent[any]{
ID: ksuid.New().String(),
Source: "dimo/integration/27qftVRWQYpVDcO5DltO5Ojbjxk",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "com.dimo.device.status.v2",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
ID: ksuid.New().String(),
Source: "dimo/integration/27qftVRWQYpVDcO5DltO5Ojbjxk",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "com.dimo.device.status.v2",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
VehicleTokenID: uint32(ds.vehicleInfo.TokenID),
},
}

if ds.vehicleInfo.TokenID != 0 {
ce.TokenID = ds.vehicleInfo.TokenID
}

payload, err := json.Marshal(ce)
if err != nil {
return errors.Wrap(err, "failed to marshall cloudevent")
Expand All @@ -207,14 +206,15 @@ func (ds *dataSender) SendDeviceNetworkData(data models.DeviceNetworkData) error
}

ce := shared.CloudEvent[models.DeviceNetworkData]{
ID: ksuid.New().String(),
Source: "aftermarket/device/network",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "com.dimo.device.network",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
ID: ksuid.New().String(),
Source: "aftermarket/device/network",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "com.dimo.device.network",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
VehicleTokenID: uint32(ds.vehicleInfo.TokenID),
}
payload, err := json.Marshal(ce)
if err != nil {
Expand All @@ -233,14 +233,15 @@ func (ds *dataSender) SendDeviceNetworkData(data models.DeviceNetworkData) error
// SendCanDumpData sends a byte array, compressed, to mqtt candump topic
func (ds *dataSender) SendCanDumpData(data json.RawMessage) error {
ce := shared.CloudEvent[json.RawMessage]{
ID: ksuid.New().String(),
Source: "aftermarket/device/canbus/dump",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "zone.dimo.aftermarket.canbus.dump",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
ID: ksuid.New().String(),
Source: "aftermarket/device/canbus/dump",
SpecVersion: "1.0",
Subject: ds.ethAddr.Hex(),
Time: time.Now().UTC(),
Type: "zone.dimo.aftermarket.canbus.dump",
DataSchema: "dimo.zone.status/v2.0",
Data: data,
VehicleTokenID: uint32(ds.vehicleInfo.TokenID),
}
ds.logger.Info().Msgf("Sending can dump data: %+v", ce)
payload, err := json.Marshal(ce)
Expand Down

0 comments on commit 30c4a4c

Please sign in to comment.