internal

package
v0.0.0-...-368b749 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: CC0-1.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ChannelSize uint64 = 1 << 16
View Source
const PacketHeaderSeqNumOffset = 6
View Source
const PacketHeaderSize = 8

Variables

This section is empty.

Functions

func Base58ToU32

func Base58ToU32(str string) (uint32, error)

func BoolSliceToByteSlice

func BoolSliceToByteSlice(b []bool) []byte

func ByteSliceToBoolSlice

func ByteSliceToBoolSlice(b []byte) []bool

func ByteSliceToFloat32Slice

func ByteSliceToFloat32Slice(slice []byte) []float32

func ByteSliceToFloat64Slice

func ByteSliceToFloat64Slice(slice []byte) []float64

func ByteSliceToInt16Slice

func ByteSliceToInt16Slice(slice []byte) []int16

func ByteSliceToInt32Slice

func ByteSliceToInt32Slice(slice []byte) []int32

func ByteSliceToInt64Slice

func ByteSliceToInt64Slice(slice []byte) []int64

func ByteSliceToInt8Slice

func ByteSliceToInt8Slice(slice []byte) []int8

func ByteSliceToRuneSlice

func ByteSliceToRuneSlice(slice []byte) []rune

func ByteSliceToString

func ByteSliceToString(slice []byte) string

func ByteSliceToUint16Slice

func ByteSliceToUint16Slice(slice []byte) []uint16

func ByteSliceToUint32Slice

func ByteSliceToUint32Slice(slice []byte) []uint32

func ByteSliceToUint64Slice

func ByteSliceToUint64Slice(slice []byte) []uint64

func ByteSliceToUint8Slice

func ByteSliceToUint8Slice(slice []byte) []uint8

func Connect

func Connect(addr string) (net.Conn, error)

func FixedSliceToByteSlice

func FixedSliceToByteSlice(slice []interface{}) []byte

func Int16SliceToByteSlice

func Int16SliceToByteSlice(slice []int16) []byte

func Int8SliceToByteSlice

func Int8SliceToByteSlice(slice []int8) []byte

func Min

func Min(left, right int64) int64

func MinU

func MinU(left, right uint64) uint64

func ReqWithTimeout

func ReqWithTimeout(packet []byte, reqTX chan<- Request) ([]byte, error)

func RuneSliceToByteSlice

func RuneSliceToByteSlice(slice []rune) []byte

func StringToByteSlice

func StringToByteSlice(str string, maxLen uint64) ([]byte, error)

func Uint16SliceToByteSlice

func Uint16SliceToByteSlice(slice []uint16) []byte

func Uint64SliceToByteSlice

func Uint64SliceToByteSlice(slice []uint64) []byte

func Uint8SliceToByteSlice

func Uint8SliceToByteSlice(slice []uint8) []byte

Types

type BrickletError deprecated

type BrickletError = DeviceError

Deprecated: BrickletError exists for historical compatibility. Use DeviceError instead.

type CallbackContainer

type CallbackContainer struct {
	RegID    uint64
	Callback func([]byte)
}

type CallbackDeregistration

type CallbackDeregistration struct {
	UID            uint32
	FunctionID     uint8
	RegistrationID uint64
}

type CallbackRegistration

type CallbackRegistration struct {
	UID        uint32
	FunctionID uint8
	Callback   func([]byte)
	RegIDTX    chan<- uint64
}

type ConnectCallbackContainer

type ConnectCallbackContainer struct {
	RegID    uint64
	Callback func(uint8)
}

type ConnectCallbackRegistration

type ConnectCallbackRegistration struct {
	Callback func(uint8)
	RegIDTX  chan<- uint64
}

type ConnectReason

type ConnectReason = uint8
const (
	ConnectReasonRequest ConnectReason = iota
	ConnectReasonAutoReconnect
)

type ConnectionState

type ConnectionState = uint8
const (
	ConnectionStateDisconnected ConnectionState = iota
	ConnectionStateConnected
	ConnectionStatePending
)

type Device

type Device struct {
	ResponseExpected [256]ResponseExpectedFlag

	UID string
	// contains filtered or unexported fields
}

func NewDevice

func NewDevice(apiVersion [3]uint8, uid string, ipcon *IPConnection, highLevelFunctionCount uint8, deviceIdentifier uint16, deviceDisplayName string) (Device, error)

func (*Device) DeregisterCallback

func (device *Device) DeregisterCallback(functionID uint8, registrationID uint64)

func (*Device) Get

func (device *Device) Get(functionID uint8, payload []byte) ([]byte, error)

func (*Device) GetAPIVersion

func (device *Device) GetAPIVersion() [3]uint8

func (*Device) GetHighLevel

func (device *Device) GetHighLevel(lowLevelClosure func() (LowLevelResult, error), highLevelFunctionIdx uint8, elementSizeInBit uint64) ([]byte, []byte, error)

func (*Device) GetResponseExpected

func (device *Device) GetResponseExpected(functionID uint8) (bool, error)

func (*Device) RegisterCallback

func (device *Device) RegisterCallback(functionID uint8, fn func([]byte)) uint64

func (*Device) Set

func (device *Device) Set(functionID uint8, payload []byte) ([]byte, error)

func (*Device) SetHighLevel

func (device *Device) SetHighLevel(lowLevelClosure func(uint64, uint64, []byte) (LowLevelWriteResult, error), highLevelFunctionIdx uint8, elementSizeInBit uint64, chunkLenInBit uint64, payload []byte) (LowLevelWriteResult, error)

func (*Device) SetResponseExpected

func (device *Device) SetResponseExpected(functionID uint8, responseExpected bool) error

func (*Device) SetResponseExpectedAll

func (device *Device) SetResponseExpectedAll(responseExpected bool)

type DeviceError

type DeviceError uint8
const (
	//Deprecated: BrickletErrorSuccess exists for historical compatibility. Use DeviceErrorSuccess instead.
	BrickletErrorSuccess DeviceError = 0
	//Deprecated: BrickletErrorInvalidParameter exists for historical compatibility. Use DeviceErrorInvalidParameter instead.
	BrickletErrorInvalidParameter DeviceError = 1
	//Deprecated: BrickletErrorFunctionNotSupported exists for historical compatibility. Use DeviceErrorFunctionNotSupported instead.
	BrickletErrorFunctionNotSupported DeviceError = 2
	//Deprecated: BrickletErrorUnknownError exists for historical compatibility. Use DeviceErrorUnknownError instead.
	BrickletErrorUnknownError       DeviceError = 3
	DeviceErrorSuccess              DeviceError = 0
	DeviceErrorInvalidParameter     DeviceError = 1
	DeviceErrorFunctionNotSupported DeviceError = 2
	DeviceErrorUnknownError         DeviceError = 3
)

func (DeviceError) Error

func (e DeviceError) Error() string

type DisconnectCallbackContainer

type DisconnectCallbackContainer struct {
	RegID    uint64
	Callback func(uint8)
}

type DisconnectCallbackRegistration

type DisconnectCallbackRegistration struct {
	Callback func(uint8)
	RegIDTX  chan<- uint64
}

type DisconnectReason

type DisconnectReason = uint8
const (
	DisconnectReasonRequest DisconnectReason = iota
	DisconnectReasonError
	DisconnectReasonShutdown
)

type EnumerationType

type EnumerationType = uint8
const (
	EnumerationTypeAvailable EnumerationType = iota
	EnumerationTypeConnected
	EnumerationTypeDisconnected
)

type IPConCallbackDeregistration

type IPConCallbackDeregistration struct {
	RegistrationID uint64
}

type IPConnection

type IPConnection struct {
	Req           chan Request
	CallbackReg   chan CallbackRegistration
	CallbackDereg chan CallbackDeregistration
	// contains filtered or unexported fields
}

func NewIPConnection

func NewIPConnection() IPConnection

func (*IPConnection) Authenticate

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

func (*IPConnection) Close

func (ipcon *IPConnection) Close()

func (*IPConnection) Connect

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

func (*IPConnection) DeregisterConnectCallback

func (ipcon *IPConnection) DeregisterConnectCallback(registrationID uint64)

func (*IPConnection) DeregisterDisconnectCallback

func (ipcon *IPConnection) DeregisterDisconnectCallback(registrationID uint64)

func (*IPConnection) DeregisterEnumerateCallback

func (ipcon *IPConnection) DeregisterEnumerateCallback(registrationID uint64)

func (*IPConnection) Disconnect

func (ipcon *IPConnection) Disconnect()

func (*IPConnection) Enumerate

func (ipcon *IPConnection) Enumerate()

func (*IPConnection) GetAutoReconnect

func (ipcon *IPConnection) GetAutoReconnect() bool

func (*IPConnection) GetConnectionState

func (ipcon *IPConnection) GetConnectionState() ConnectionState

func (*IPConnection) GetTimeout

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

func (*IPConnection) RegisterConnectCallback

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

func (*IPConnection) RegisterDisconnectCallback

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

func (*IPConnection) RegisterEnumerateCallback

func (ipcon *IPConnection) RegisterEnumerateCallback(fn func([]byte)) uint64

func (*IPConnection) SetAutoReconnect

func (ipcon *IPConnection) SetAutoReconnect(autoReconnectEnabled bool)

func (*IPConnection) SetTimeout

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

type LowLevelResult

type LowLevelResult struct {
	Length      uint64
	ChunkOffset uint64
	ChunkData   []byte
	Result      []byte
}

type LowLevelWriteResult

type LowLevelWriteResult struct {
	Written uint64
	Result  []byte
}

type PacketHeader

type PacketHeader struct {
	UID              uint32
	Length           uint8
	FunctionID       uint8
	SequenceNumber   uint8
	ResponseExpected bool
	ErrorCode        uint8
}

func (*PacketHeader) FillFromBytes

func (header *PacketHeader) FillFromBytes(bytes []byte)

func (PacketHeader) ToLeBytes

func (header PacketHeader) ToLeBytes() []byte

type Request

type Request struct {
	Packet     []byte
	TimeoutTx  chan<- time.Duration
	ResponseTx chan<- []byte
}

type ResponseExpectedFlag

type ResponseExpectedFlag = uint8
const (
	ResponseExpectedFlagInvalidFunctionID ResponseExpectedFlag = iota
	ResponseExpectedFlagFalse
	ResponseExpectedFlagTrue
	ResponseExpectedFlagAlwaysTrue
)

type TimeoutStruct

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

The IPConnection gets moved when returning from NewIPConnection(), so it only stores pointers to timeout and autoReconnect, as they are also shared to the socket thread. To ensure that the timeout is 64 bit aligned on 32 bit systems, allocate it in a separate struct.

Jump to

Keyboard shortcuts

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