ipconnection

package
v0.0.0-...-8a98e63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2022 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Overview

The IP Connection manages the communication between the API bindings and the Brick Daemon or a WIFI/Ethernet Extension. Before Bricks and Bricklets can be controlled using their API an IP Connection has to be created and its TCP/IP connection has to be established.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectReason

type ConnectReason = uint8

This enum specifies the reason of a successful connection. It is generated by the connect callback.

const (
	// Connection established after request from user.
	ConnectReasonRequest ConnectReason = iota
	// Connection after auto-reconnect.
	ConnectReasonAutoReconnect
)

type ConnectionState

type ConnectionState = uint8

State of the connection to the Brick Daemon or the WIFI/Ethernet Extension.

const (
	// No connection is established.
	ConnectionStateDisconnected ConnectionState = iota
	// A connection to the Brick Daemon or the WIFI/Ethernet Extension is established.
	ConnectionStateConnected
	// IP Connection is currently trying to connect.
	ConnectionStatePending
)

type DisconnectReason

type DisconnectReason = uint8

This enum specifies the reason of a connections termination. It is generated by the disconnect callback.

const (
	// Disconnect was requested by user.
	DisconnectReasonRequest DisconnectReason = iota
	// Disconnect because of an unresolvable error.
	DisconnectReasonError
	// Disconnect initiated by Brick Daemon or WIFI/Ethernet Extension.
	DisconnectReasonShutdown
)

type EnumerationType

type EnumerationType = uint8

Type of enumeration of a device.

const (
	// Device is available (enumeration triggered by user).
	// This enumeration type can occur multiple times for the same device.
	EnumerationTypeAvailable EnumerationType = iota
	// Device is newly connected (automatically send by Brick after establishing a communication connection).
	// This indicates that the device has potentially lost its previous configuration and needs to be reconfigured.
	EnumerationTypeConnected
	// Device is disconnected (only possible for USB connection). In this case only uid and enumerationType are valid.
	EnumerationTypeDisconnected
)

type IPConnection

type IPConnection struct {
	// contains filtered or unexported fields
}

The IP Connection manages the communication between the API bindings and the Brick Daemon or a WIFI/Ethernet Extension. Before Bricks and Bricklets can be controlled using their API an IP Connection has to be created and its TCP/IP connection has to be established.

func New

func New() IPConnection

Creates an IP Connection object that can be used to enumerate the available devices. It is also required for the constructor of Bricks and Bricklets.

func (*IPConnection) Authenticate

func (ipcon *IPConnection) Authenticate(secret string) error

Performs an authentication handshake with the connected Brick Daemon or WIFI/Ethernet Extension. If the handshake succeeds the connection switches from non-authenticated to authenticated state and communication can continue as normal. If the handshake fails then the connection gets closed. Authentication can fail if the wrong secret was used or if authentication is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension.

See the authentication tutorial for more information.

func (*IPConnection) Close

func (ipcon *IPConnection) Close()

Stops the IP Connection's goroutines.

func (*IPConnection) Connect

func (ipcon *IPConnection) Connect(addr string) error

Creates a TCP/IP connection to the given `addr` with the form "host:port", as described here: https://golang.org/pkg/net/#Dial . The host and port can refer to a Brick Daemon or to a WIFI/Ethernet Extension.

Devices can only be controlled when the connection was established successfully.

func (*IPConnection) DeregisterConnectCallback

func (ipcon *IPConnection) DeregisterConnectCallback(registrationID uint64)

Deregisters the connect callback with the given registration ID.

func (*IPConnection) DeregisterDisconnectCallback

func (ipcon *IPConnection) DeregisterDisconnectCallback(registrationID uint64)

Deregisters the disconnect callback with the given registration ID.

func (*IPConnection) DeregisterEnumerateCallback

func (ipcon *IPConnection) DeregisterEnumerateCallback(registrationID uint64)

Deregisters the enumerate callback with the given registration ID.

func (*IPConnection) Disconnect

func (ipcon *IPConnection) Disconnect()

Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet Extension.

func (*IPConnection) Enumerate

func (ipcon *IPConnection) Enumerate()

Broadcasts an enumerate request. All devices will respond with an enumerate event.

func (*IPConnection) GetAutoReconnect

func (ipcon *IPConnection) GetAutoReconnect() bool

Returns true if auto-reconnect is enabled, false otherwise.

func (*IPConnection) GetConnectionState

func (ipcon *IPConnection) GetConnectionState() ConnectionState

Queries the current connection state.

func (*IPConnection) GetInternalHandle

func (ipcon *IPConnection) GetInternalHandle() interface{}

For internal use only.

func (*IPConnection) GetTimeout

func (ipcon *IPConnection) GetTimeout() time.Duration

Returns the timeout as set by SetTimeout

func (*IPConnection) RegisterConnectCallback

func (ipcon *IPConnection) RegisterConnectCallback(fn func(ConnectReason)) uint64

Callbacks registered to this event are called whenever the IP Connection got connected to a Brick Daemon or to a WIFI/Ethernet Extension. This function returns a registration ID which is used to deregister the callback when it should not be called anymore.

func (*IPConnection) RegisterDisconnectCallback

func (ipcon *IPConnection) RegisterDisconnectCallback(fn func(DisconnectReason)) uint64

Callbacks registered to this event are called whenever the IP Connection got disconnected from a Brick Daemon or to a WIFI/Ethernet Extension. This function returns a registration ID which is used to deregister the callback when it should not be called anymore.

func (*IPConnection) RegisterEnumerateCallback

func (ipcon *IPConnection) RegisterEnumerateCallback(fn func(uid string, connectedUID string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, enumerationType EnumerationType)) uint64

Callbacks registered to this event are called whenever a enumerate event is received. This function returns a registration ID which is used to deregister the callback when it should not be called anymore. Parameters of the callback are:

* uid string - The UID of the device.

  • connectedUID string - UID where the device is connected to. For a Bricklet this is the UID of the Brick or Bricklet it is connected to. For a Brick it is the UID of the bottommost Brick in the stack. For the bottommost Brick in a stack it is "0". With this information it is possible to reconstruct the complete network topology.

* position rune - For Bricks: '0' - '8' (position in stack). For Bricklets: 'a' - 'd' (position on Brick).

* hardwareVersion [3]uint8 - Major, minor and release number for hardware version.

* firmwareVersion [3]uint8 - Major, minor and release number for firmware version.

  • deviceIdentifier uint16 - A number that represents the device. The device identifier numbers can be found here: https://www.tinkerforge.com/en/doc/Software/Device_Identifier.html There are also constants for these numbers named following this pattern: <device-package>.DeviceIdentifier For example: master_brick.DeviceIdentifier or ambient_light_bricklet.DeviceIdentifier.

* enumerationType EnumerationType - Type of enumeration.

func (*IPConnection) SetAutoReconnect

func (ipcon *IPConnection) SetAutoReconnect(autoReconnectEnabled bool)

Enables or disables auto-reconnect. If auto-reconnect is enabled, the IP Connection will try to reconnect to the previously given host and port, if the currently existing connection is lost. Therefore, auto-reconnect only does something after a successful connect call.

Default value is true.

func (*IPConnection) SetTimeout

func (ipcon *IPConnection) SetTimeout(timeout time.Duration)

Sets the timeout for getters and for setters for which the response expected flag is activated.

Default timeout is 2,5s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL