tinkerforge

package module
v0.0.0-...-5790aad Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: BSD-2-Clause Imports: 9 Imported by: 0

README

tinkerforge

GoDoc

A go implementation of the tinkerforge protocol.

Install

go get github.com/noxer/tinkerforge

Example

The tinkerforge package can be used directly:

package main

import (
    "github.com/noxer/tinkerforge"
)
  
func main() {
    // Open a new connection to brickd (we ignore the error)
    t, _ := tinkerforge.New("localhost:4223")
    defer t.Close()

    // Call function 1 of brick(let) 123456, don't expect an answer and send three integers (again we ignore the error)
    p, _ := tinkerforge.NewPacket(123456, 1, false, int32(42), int32(43), int32(44))

    // Send the packet
    t.Send(p)
}

There are high level functions in the "ledstrip"package:

package main

import (
    "github.com/noxer/tinkerforge"
    "github.com/noxer/tinkerforge/ledstrip"
)
  
func main() {
    // Open a new connection to brickd (we ignore the error)
    t, _ := tinkerforge.New("localhost:4223")
    defer t.Close()

    // Wrap with the ledstrip controller and set the bricklet ID to 123456 (error ignored)
    l, _ := ledstrip.New(t, 123456)

    // Set the color of the first LED to red (if it appears in blue you need to set the color mapping)
    l.SetRGBValues(0, []ledstrip.Color{ledstrip.Color{255, 0, 0}})
}

Documentation

Overview

Package tinkerforge implements the tinkerforge protocol Author: Tim Scheuermann (https://github.com/noxer)

Index

Constants

View Source
const (
	// ECOkay says no errors occurred
	ECOkay ErrorCode = 0
	// ECInvalidParam says you sent an invalid parameter in the packet
	ECInvalidParam = 1
	// ECFuncNotSupported says the function number you sent is not available
	ECFuncNotSupported = 2
)

Variables

View Source
var (
	// ErrInvalidParam represents ECInvalidParam in Go
	ErrInvalidParam = errors.New("Invalid Parameter")
	// ErrFuncNotSupported represents ECFuncNotSupported in Go
	ErrFuncNotSupported = errors.New("Function is not supported")
)
View Source
var (
	// ErrTimeout represents a timeout while waiting for a callback
	ErrTimeout = errors.New("Timeout while waiting for callback")
)

Functions

This section is empty.

Types

type ErrorCode

type ErrorCode uint8

ErrorCode represents the error value returned by the brick(let)s

type Handler

type Handler interface {
	Handle(packet *Packet)
}

Handler to get callbacks

type Packet

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

Packet holds all information about a sent or received packet

func NewPacket

func NewPacket(uid uint32, funcID uint8, respExp bool, params ...interface{}) (*Packet, error)

NewPacket creates a new packet to be sent to the TinkerForge daemon

func (*Packet) Callback

func (p *Packet) Callback() bool

Callback indicates if this packet is a callback

func (*Packet) Decode

func (p *Packet) Decode(vars ...interface{}) error

Decode decodes the payload of a packet into a number of variables

func (*Packet) Error

func (p *Packet) Error() error

Error returns the corresponding error for the error ID

func (*Packet) ErrorID

func (p *Packet) ErrorID() ErrorCode

ErrorID returns the ID of the error (or ECOkay)

func (*Packet) FunctionID

func (p *Packet) FunctionID() uint8

FunctionID returns the function ID of the packet

func (*Packet) Length

func (p *Packet) Length() uint8

Length returns the overall length (header + payload) of the packet

func (*Packet) Payload

func (p *Packet) Payload() []byte

Payload returns the payload of the packet

func (*Packet) ResponseExpected

func (p *Packet) ResponseExpected() bool

ResponseExpected returns wether the caller expects an answer

func (*Packet) SequenceNum

func (p *Packet) SequenceNum() uint8

SequenceNum returns the 4-bit sequence number of the packet.

func (*Packet) Serialize

func (p *Packet) Serialize(wr io.Writer, seqNum byte) error

Serialize converts the packet into a byte slice for sending

func (*Packet) UID

func (p *Packet) UID() uint32

UID returns the UID of the packet source / destination

type Tinkerforge

type Tinkerforge interface {
	io.Closer
	Handler(uid uint32, funcID uint8, handler Handler)
	Send(packet *Packet) (*Packet, error)
}

Tinkerforge interface

func New

func New(host string) (Tinkerforge, error)

New creates a new tinkerforge client

Directories

Path Synopsis
Package helpers has helper routines for tinkerforge Author: Tim Scheuermann (https://github.com/noxer)
Package helpers has helper routines for tinkerforge Author: Tim Scheuermann (https://github.com/noxer)
Package ledstrip has control routines for LED strips Author: Tim Scheuermann (https://github.com/noxer)
Package ledstrip has control routines for LED strips Author: Tim Scheuermann (https://github.com/noxer)

Jump to

Keyboard shortcuts

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