Skip to content

Commit

Permalink
Add body-controller-state command
Browse files Browse the repository at this point in the history
New command fetchs limited information about body controller states. The
advantage of this command over the more comprehensive vehicle data
endpoint is that it works over BLE.
  • Loading branch information
Seth Terashima authored and sethterashima committed Jul 1, 2024
1 parent 26fa60b commit 05bc5dd
Show file tree
Hide file tree
Showing 8 changed files with 1,038 additions and 333 deletions.
21 changes: 21 additions & 0 deletions cmd/tesla-control/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/teslamotors/vehicle-command/pkg/protocol/protobuf/keys"
"github.com/teslamotors/vehicle-command/pkg/protocol/protobuf/vcsec"
"github.com/teslamotors/vehicle-command/pkg/vehicle"
"google.golang.org/protobuf/encoding/protojson"
)

var ErrCommandLineArgs = errors.New("invalid command line arguments")
Expand Down Expand Up @@ -798,4 +799,24 @@ var commands = map[string]*Command{
return car.CloseWindows(ctx)
},
},
"body-controller-state": &Command{
help: "Fetch limited vehicle state information. Works over BLE when infotainment is asleep.",
domain: protocol.DomainVCSEC,
requiresAuth: false,
requiresFleetAPI: false,
handler: func(ctx context.Context, acct *account.Account, car *vehicle.Vehicle, args map[string]string) error {
info, err := car.BodyControllerState(ctx)
if err != nil {
return err
}
options := protojson.MarshalOptions{
Indent: "\t",
UseEnumNumbers: false,
EmitUnpopulated: false,
EmitDefaultValues: true,
}
fmt.Println(options.Format(info))
return nil
},
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-ble/ble v0.0.0-20220207185428-60d1eecf2633
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
golang.org/x/term v0.5.0
google.golang.org/protobuf v1.28.1
google.golang.org/protobuf v1.34.2
)

require (
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ github.com/go-ble/ble v0.0.0-20220207185428-60d1eecf2633 h1:ZrzoZQz1CF33SPHLkjRp
github.com/go-ble/ble v0.0.0-20220207185428-60d1eecf2633/go.mod h1:fFJl/jD/uyILGBeD5iQ8tYHrPlJafyqCJzAyTHNJ1Uk=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
Expand Down Expand Up @@ -66,10 +64,8 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
54 changes: 54 additions & 0 deletions pkg/protocol/protobuf/vcsec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,63 @@ message UnsignedMessage {
}
}

enum ClosureState_E {
CLOSURESTATE_CLOSED = 0;
CLOSURESTATE_OPEN = 1;
CLOSURESTATE_AJAR = 2;
CLOSURESTATE_UNKNOWN = 3;
CLOSURESTATE_FAILED_UNLATCH = 4;
CLOSURESTATE_OPENING = 5;
CLOSURESTATE_CLOSING = 6;
}

enum VehicleLockState_E {
VEHICLELOCKSTATE_UNLOCKED = 0;
VEHICLELOCKSTATE_LOCKED = 1;
VEHICLELOCKSTATE_INTERNAL_LOCKED = 2;
VEHICLELOCKSTATE_SELECTIVE_UNLOCKED = 3;
}

message ClosureStatuses
{
ClosureState_E frontDriverDoor = 1;
ClosureState_E frontPassengerDoor = 2;
ClosureState_E rearDriverDoor = 3;
ClosureState_E rearPassengerDoor = 4;
ClosureState_E rearTrunk = 5;
ClosureState_E frontTrunk = 6;
ClosureState_E chargePort = 7;
ClosureState_E tonneau = 8;
}

enum VehicleSleepStatus_E {
VEHICLE_SLEEP_STATUS_UNKNOWN = 0;
VEHICLE_SLEEP_STATUS_AWAKE = 1;
VEHICLE_SLEEP_STATUS_ASLEEP = 2;
}

message DetailedClosureStatus {
uint32 tonneauPercentOpen = 1;
}

enum UserPresence_E {
VEHICLE_USER_PRESENCE_UNKNOWN = 0;
VEHICLE_USER_PRESENCE_NOT_PRESENT = 1;
VEHICLE_USER_PRESENCE_PRESENT = 2;
}

message VehicleStatus {
ClosureStatuses closureStatuses = 1;
VehicleLockState_E vehicleLockState = 2;
VehicleSleepStatus_E vehicleSleepStatus = 3;
UserPresence_E userPresence = 4;
DetailedClosureStatus detailedClosureStatus = 5;
}

message FromVCSECMessage {
reserved 6 to 10;
oneof sub_message {
VehicleStatus vehicleStatus = 1;
CommandStatus commandStatus = 4;
WhitelistInfo whitelistInfo = 16;
WhitelistEntryInfo whitelistEntryInfo = 17;
Expand Down
Loading

0 comments on commit 05bc5dd

Please sign in to comment.