Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
40
pkg/cachev2/vehicle_state_towman.go
Normal file
40
pkg/cachev2/vehicle_state_towman.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cachev2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"fiskerinc.com/modules/common"
|
||||
redis "fiskerinc.com/modules/redisv2"
|
||||
"fiskerinc.com/modules/utils/elptr"
|
||||
)
|
||||
|
||||
func GetTowManDigitalTwin(vin string, redisClient *redis.Connection)(tdt common.TowmanDigitalTwin, err error){
|
||||
// TODO: Make this more efficient with specific gets
|
||||
dTwins, errorList := GetVINListDigitalTwin([]string{vin}, redisClient)
|
||||
if len(errorList) > 0 {
|
||||
err = errorList[0]
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
digitalTwin, ok := dTwins[vin]
|
||||
if !ok {
|
||||
err = errors.New("digital twin not found")
|
||||
return
|
||||
}
|
||||
|
||||
tdt.Gear = digitalTwin.GetGear()
|
||||
tdt.Location = digitalTwin.GetLocation()
|
||||
tdt.Online = digitalTwin.Online
|
||||
tdt.Charging = elptr.ElPtr((digitalTwin.GetVCU0x260().ChargeType != "initial_value") && (digitalTwin.GetVCU0x260().ChargeType != ""))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetVehicleLocation(vin string, redisClient *redis.Connection)(location common.Location, err error){
|
||||
res := redisClient.HGet(context.Background(), redis.CarLocationsKey(), vin)
|
||||
err = res.Scan(&location)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user