package anki import "fmt" const ( stateFullBattery = 1 << 4 stateLowBattery = 1 << 5 stateOnCharger = 1 << 6 ) type VehicleAdvInfo struct { VehicleAdvState uint8 // Battery level bits Version uint16 Reserved [5]uint8 Name [13]byte // UTF8: 12 bytes + NULL } func (v VehicleAdvInfo) String() string { b := "unknown" if v.FullBattery() { b = "full" } if v.LowBattery() { b = "low" } if v.OnCharger() { b = "charging" } return fmt.Sprintf("Battery: %v, Version %v, Name: %v", b, v.Version, string(v.Name[:12])) } func (v VehicleAdvInfo) FullBattery() bool { return v.VehicleAdvState&stateFullBattery != 0 } func (v VehicleAdvInfo) LowBattery() bool { return v.VehicleAdvState&stateLowBattery != 0 } func (v VehicleAdvInfo) OnCharger() bool { return v.VehicleAdvState&stateOnCharger != 0 } type VehicleAdvMfg struct { Identifier uint32 ModelID uint8 Reserved uint8 ProductID uint16 } type VehicleAdv struct { Flags uint8 TXPower uint8 MfgData VehicleAdvMfg LocalName VehicleAdvInfo UUID UUID }