Documentation
¶
Index ¶
- Variables
- func ParseAddress(s string) (bluetooth.Address, error)
- type Connection
- func (c *Connection) Connect(ctx context.Context, address bluetooth.Address) error
- func (c *Connection) Disconnect() error
- func (c *Connection) IsConnected() bool
- func (c *Connection) ReadFrame(ctx context.Context, timeout time.Duration) ([]byte, error)
- func (c *Connection) Request(ctx context.Context, frame []byte, timeout time.Duration) ([]byte, error)
- func (c *Connection) Scan(ctx context.Context, duration time.Duration) ([]bluetooth.ScanResult, error)
- func (c *Connection) WriteFrame(_ context.Context, frame []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotConnected = errors.New("not connected to device") ErrNoDevice = errors.New("no device found") ErrTimeout = errors.New("operation timeout") ErrNoService = errors.New("service not found") ErrNoCharacteristic = errors.New("characteristic not found") ErrFrameTooLarge = errors.New("frame exceeds device buffer") )
var ( // ServiceUUID is the primary BLE service UUID for battery communication ServiceUUID = bluetooth.NewUUID([16]byte{ 0x00, 0x00, 0x10, 0x06, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, }) // 00001006-0000-1000-8000-00805f9b34fb // WriteCharacteristicUUID is the characteristic for writing commands to the battery WriteCharacteristicUUID = bluetooth.NewUUID([16]byte{ 0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, }) // 00001008-0000-1000-8000-00805f9b34fb // NotifyCharacteristicUUID is the characteristic for receiving notifications from the battery NotifyCharacteristicUUID = bluetooth.NewUUID([16]byte{ 0x00, 0x00, 0x10, 0x07, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, }) // 00001007-0000-1000-8000-00805f9b34fb // CCCDescriptorUUID is the Client Characteristic Configuration descriptor CCCDescriptorUUID = bluetooth.NewUUID([16]byte{ 0x00, 0x00, 0x29, 0x02, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, }) // 00002902-0000-1000-8000-00805f9b34fb )
UUIDs for Voltgo BLE protocol (compatible with Enerwatt, TCED Worldwide, and other brands)
Functions ¶
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a BLE connection to a battery
func NewConnection ¶
func NewConnection() (*Connection, error)
NewConnection creates a new BLE connection handler
func (*Connection) Connect ¶
Connect connects to a BLE device by address and prepares the battery's write and notify characteristics.
A link the battery accepts and then aborts is retried rather than returned on the first failure; see peerAbortReasons for why that failure is treated differently from every other connect error.
func (*Connection) Disconnect ¶
func (c *Connection) Disconnect() error
Disconnect disconnects from the device
func (*Connection) IsConnected ¶
func (c *Connection) IsConnected() bool
IsConnected returns whether the connection is active
func (*Connection) Request ¶
func (c *Connection) Request(ctx context.Context, frame []byte, timeout time.Duration) ([]byte, error)
Request writes a frame and waits for the response notification. Any stale notifications queued before the write are discarded.
func (*Connection) Scan ¶
func (c *Connection) Scan(ctx context.Context, duration time.Duration) ([]bluetooth.ScanResult, error)
Scan scans for nearby battery devices
func (*Connection) WriteFrame ¶
func (c *Connection) WriteFrame(_ context.Context, frame []byte) error
WriteFrame writes a raw frame to the device's write characteristic.