Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package state
type CANMessage struct {
CANID int
Length int
Signals []CANSignal
}
type CANSignal struct {
Name string
Position int
}

View File

@@ -0,0 +1,28 @@
package state
const (
AMBIENT_TEMP string = "ambient_temperature"
CELL_TEMP = "cell_temperature"
BATTERY = "battery"
STATE_OF_CHARGE = "state_of_charge"
MAX_RANGE = "max_range"
CABIN_CLIMATE = "cabin_climate"
DBC_VERSION = "dbc_version"
DEFROST_REAR = "rear_defrost"
DOORS = "doors"
DOOR_LOCKS = "door_locks"
GPS_ALTITUDE = "gps_altitude"
LOCATION = "location"
SEAT_HEAT_DRIVER = "driver_seat_heat"
SEAT_HEAT_PASSENGER = "passenger_seat_heat"
STEERING_WHEEL_HEAT = "steering_wheel_heat"
SUNROOF = "sunroof"
TREX_VERSION = "trex_version"
TREX_IP = "ip"
VCU0x260 = "vcu0x260"
ICC0x531 = "icc0x531"
CHARGING_METRICS = "charging_metrics"
WINDOWS = "windows"
WINDOWS_MISC = "misc_windows"
UPDATED_AT = "updated"
)

17
pkg/dbc/state/errors.go Normal file
View File

@@ -0,0 +1,17 @@
package state
import (
"github.com/pkg/errors"
)
func IncorrectSignalsLength(expected int, received int) error {
return errors.Errorf("incorrect number of signals in message expected %d received %d", expected, received)
}
func IncorrectSignalError(expected string, received string) error {
return errors.Errorf("wrong signal in message expected %s received %s", expected, received)
}
func IncorrectSignalValue(expected interface{}, received interface{}) error {
return errors.Errorf("wrong value in message expected one of %v received %v", expected, received)
}

49
pkg/dbc/state/helpers.go Normal file
View File

@@ -0,0 +1,49 @@
package state
import (
"fmt"
"math"
"time"
)
const redisObjectExpire = 604800
const errInvalidValue = "invalid value %f"
func FloatToBool(input float64) interface{} {
return int(input) != 0
}
func RoundMilli(input float64) interface{} {
return math.Round(input*1000) / 1000
}
func RoundGPS(input float64) interface{} {
return math.Round(input*100000) / 100000
}
func IntCeil(input float64) interface{} {
return int(math.Ceil(input))
}
func IntFloor(input float64) interface{} {
return int(math.Floor(input))
}
func Int(input float64) interface{} {
return int(input)
}
// WHy does this return an array of bytes instead of a string, or a time.Time
func SerializeTimestampUSec(timestampUSec int) ([]byte, error) {
return time.UnixMicro(int64(timestampUSec)).UTC().MarshalJSON()
}
func GetMappedStrValues(valueMap map[float64]string) func(float64) interface{} {
return func(input float64) interface{} {
if value, ok := valueMap[input]; ok {
return value
}
return fmt.Sprintf(errInvalidValue, input)
}
}

View File

@@ -0,0 +1,100 @@
package state
const (
BCM_AP_FL_LeFrntWinPosnInfo = "BCM_AP_FL_LeFrntWinPosnInfo"
BCM_AP_FL_RiFrntWinPosnInfo = "BCM_AP_FL_RiFrntWinPosnInfo"
BCM_AP_FL_LeReWinPosnInfo = "BCM_AP_FL_LeReWinPosnInfo"
BCM_AP_FL_RiReWinPosnInfo = "BCM_AP_FL_RiReWinPosnInfo"
BCM_AP_TL_LeReWinPosnInfo = "BCM_AP_TL_LeReWinPosnInfo"
BCM_AP_TL_RiReWinPosnInfo = "BCM_AP_TL_RiReWinPosnInfo"
BCM_AP_RW_WinPosnInfo = "BCM_AP_RW_WinPosnInfo"
BMS_Bat_SoC_usable = "BMS_Bat_SoC_usable"
BMS_Bat_SOH = "BMS_Bat_SOH"
BMS_BattAvrgT = "BMS_BattAvrgT"
BCM_FrntDrDoorLockSts = "BCM_FrntDrDoorLockSts"
BCM_CenLockSwtSts = "BCM_CenLockSwtSts"
BCM_FrntHoodLidSts = "BCM_FrntHoodLidSts"
BCM_DrFrntDoorSts = "BCM_DrFrntDoorSts"
BCM_PasFrntDoorSts = "BCM_PasFrntDoorSts"
BCM_RiReDoorSts = "BCM_RiReDoorSts"
BCM_LeReDoorSts = "BCM_LeReDoorSts"
BCM_SunroofPosnInfo = "BCM_SunroofPosnInfo"
PLGM_TrSts = "PLGM_TrSts"
ECC_RemTSetSts = "ECC_RemTSetSts"
BCM_ReDefrstHeatgCmd = "BCM_ReDefrstHeatgCmd"
DSMC_DrvrSeatHeatgSts = "DSMC_DrvrSeatHeatgSts"
PSM_PassSeatHeatgSts = "PSM_PassSeatHeatgSts"
BCM_HeatedSteerWhlSt = "BCM_HeatedSteerWhlSt"
ECC_OutdT = "ECC_OutdT"
ECC_InsdT = "ECC_InsdT"
BMS_PwrBattRmngCpSOC = "BMS_PwrBattRmngCpSOC"
ESP_VehSpd = "ESP_VehSpd"
VCU_DrvgMilg = "VCU_DrvgMilg"
VCU_VehChrgDchgMod = "VCU_VehChrgDchgMod"
VCU_DCChrgRmngTi = "VCU_DCChrgRmngTi"
IBS_BatteryVoltage = "IBS_BatteryVoltage"
VCU_GearSig = "VCU_GearSig"
ICC_TotMilg_ODO = "ICC_TotMilg_ODO"
TBOX_GPSHei = "TBOX_GPSHei"
TBOX_GPSLongi = "TBOX_GPSLongi"
TBOX_GPSLati = "TBOX_GPSLati"
BMS_RmChrgTi_FullChrg = "BMS_RmChrgTi_FullChrg"
BMS_RmChrgTi_TrgtSoC = "BMS_RmChrgTi_TrgtSoC"
VCU_VehSt = "VCU_VehSt"
VCU_VcuState = "VCU_VcuState"
MCU_F_ActSafeSt = "MCU_F_ActSafeSt"
MCU_R_ActSafeSt = "MCU_R_ActSafeSt"
MCU_R_Decoup_State = "MCU_R_Decoup_State"
MCU_F_CrtMod = "MCU_F_CrtMod"
MCU_R_CrtMod = "MCU_R_CrtMod"
ACU_Drvr_Occpt_St = "ACU_Drvr_Occpt_St"
BCM_PwrMod = "BCM_PwrMod"
PWC_ChrgSts = "PWC_ChrgSts"
VCU_RdyLamp = "VCU_RdyLamp"
// New signals for Michael Fischer and Igor Lastrić
IBS_SOCUpperTolerance = "IBS_SOCUpperTolerance"
IBS_SOCLowerTolerance = "IBS_SOCLowerTolerance"
IBS_StateOfCharge = "IBS_StateOfCharge"
IBS_StateOfHealth = "IBS_StateOfHealth"
IBS_NominalCapacity = "IBS_NominalCapacity"
IBS_AvailableCapacity = "IBS_AvailableCapacity"
BCM_TotMilg_ODO = "BCM_TotMilg_ODO"
BMS_SwVersS = "BMS_SwVersS"
BMS_SwVersM = "BMS_SwVersM"
BMS_SwVers = "BMS_SwVers"
BMS_AccueDchaTotAh = "BMS_AccueDchaTotAh"
BMS_AccueChrgTotAh = "BMS_AccueChrgTotAh"
//Attempting to add the bearing direction of the car
TBOX_Heading = "TBOX_Heading"
PKC_IMMO_AuthSts = "PKC_IMMO_AuthSts"
VCU_IMMO_Sts = "VCU_IMMO_Sts"
TBOX_RemCtrlCmdFb = "TBOX_RemCtrlCmdFb"
PKC_AuthFailPromt = "PKC_AuthFailPromt"
PKC_StrtFailTyp = "PKC_StrtFailTyp"
PKC_KeyStsMod = "PKC_KeyStsMod"
TBOX_RemCtrlLockCmd = "TBOX_RemCtrlLockCmd"
)
// safe state constants
const (
VCU_VehSt_Safestate = "11"
VCU_VcuState_Safestate = "18"
MCU_F_ActSafeSt_AS0 = "1"
MCU_F_ActSafeSt_ASC = "2"
MCU_F_ActSafeSt_ASC_Emergency = "3"
MCU_R_ActSafeSt_AS0 = "1"
MCU_R_ActSafeSt_ASC = "2"
MCU_R_ActSafeSt_ASC_Emergency = "3"
MCU_R_Decoup_State_Connected = "4"
MCU_F_CrtMod_Internal_inverter_error = "7"
MCU_F_CrtMod_Invalid = "15"
MCU_R_CrtMod_Internal_inverter_error = "7"
MCU_R_CrtMod_Invalid = "15"
)

View File

@@ -0,0 +1,20 @@
package state
// Converting these values to strings is bad for memory performance,
// but it is what it is for now
const (
PKC_KeyStsMod_disabled = "disabled"
PKC_KeyStsMod_enabled = "enabled"
)
// const (
// PKC_StrtFailTyp_"No_error" = "No_error"
// PKC_StrtFailTyp_"Reserved" = "Reserved"
// PKC_StrtFailTyp_"VCU_Authentication_Failure" = "VCU_Authentication_Failure"
// PKC_StrtFailTyp_"Time_Out_(Crank_Off_Time)" = "Time_Out_(Crank_Off_Time)"
// PKC_StrtFailTyp_"Auth_Pass" = "Auth_Pass"
// PKC_StrtFailTyp_"Remote Immo Enabled" = "Remote Immo Enabled"
// PKC_StrtFailTyp_"No Key detected inside the vehicle" = "No Key detected inside the vehicle"
// PKC_StrtFailTyp_"Alcointerlock Enabled" = "Alcointerlock Enabled"
// PKC_StrtFailTyp_"Initial value" = "Initial value"
// )

View File

@@ -0,0 +1,8 @@
package state
import (
"fiskerinc.com/modules/common"
"fiskerinc.com/modules/redis"
)
type StateFunc func(*redis.RedisBatchCommands, string, int, []common.CANSignal) error