goiio

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

goiio is a pure golang client for IIO (industrial I/O)

Introduction

go-iio was written to access remote iiod instanced, since libiio does not seem to have golang bindings by itself. It's main use case is connecting with remote IIOd instances: local IIO access is out of scope, you'll need to run iiod.

See https://github.com/analogdevicesinc/libiio

Example

The following example shows an example on how to use this library

c, err := goiio.New("my-sensor.home.lan:30431")
if err != nil {
  panic(err)
}

// Populate the values in attributes
if err = c.FetchAttributes(); err != nil {
  panic(err)
}

//
for _, dev := range c.Context.Devices {
  log.Infof("Device: id=%s, name=%s", dev.ID, dev.Name)
  for _, ch := range dev.Channels {
    log.Infof("  Channel: id=%s", ch.ID)
    for _, attr := range ch.Attributes {
      log.Infof("    Attribute: %s, value: %0.3f", attr.Name, attr.Value)
    }
  }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ID         string              `xml:"id,attr"`   // ID of the channel, e.g. "temp"
	Type       string              `xml:"type,attr"` // Type of the channel, e.g. "input"
	Attributes []*ChannelAttribute `xml:"attribute"` // List of attributes of the channel
}

Channels holds all information related to a channel in a IIO device

func (*Channel) GetAttrByName

func (c *Channel) GetAttrByName(name string) *ChannelAttribute

GetAttrByName fetches the first attribute with given name

func (*Channel) GetAttribute

func (c *Channel) GetAttribute(comp CompareChannelAttribute) *ChannelAttribute

GetAttribute fetches the first attribute from the channel satisfying the comparison function

func (*Channel) GetValue

func (c *Channel) GetValue() float64

type ChannelAttribute

type ChannelAttribute struct {
	Name     string  `xml:"name,attr"`            // Name of the attribute, e.g. "oversampling_ratio"
	Filename string  `xml:"filename,attr"`        // Filename of the attribute in sysfs, e.g. "in_pressure_oversampling_ratio"
	Value    float64 `xml:"value,attr,omitempty"` // Value of the attribute
}

ChannelAttribute is the data structure describing an attribute of a channel

type CompareChannel

type CompareChannel func(*Channel) bool

CompareChannel is a type passed to Device.GetChannel implementing some kind of comparison function

type CompareChannelAttribute

type CompareChannelAttribute func(*ChannelAttribute) bool

CompareChannelAttribute is a type passed to Channel.GetAttribute implementing some kind of comparison function

type CompareContextAttribute

type CompareContextAttribute func(*ContextAttribute) bool

CompareContextAttribute is a type passed to Context.GetAttribute implementing some kind of comparison function

type CompareDevice

type CompareDevice func(*Device) bool

CompareDevice is a type passed to Context.GetDevice implementing some kind of comparison function

type Context

type Context struct {
	XMLName           xml.Name            `xml:"context"`           // Not sure where this is for
	Name              string              `xml:"name,attr"`         // The name of the context
	Description       string              `xml:"description,attr"`  // Description of the context
	ContextAttributes []*ContextAttribute `xml:"context-attribute"` // Attributes that apply to the context
	Devices           []*Device           `xml:"device"`            // Devices connected. This is probably what you need
}

Context holds the context of the remote IIOd

func (*Context) GetAttribute

func (c *Context) GetAttribute(comp CompareContextAttribute) *ContextAttribute

GetAttribute fetches the first attribute from the context satisfying the comparison function

func (*Context) GetAttributeByName

func (c *Context) GetAttributeByName(name string) *ContextAttribute

GetAttributeByName fetches the first attribute with given name

func (*Context) GetDevice

func (h *Context) GetDevice(comp CompareDevice) *Device

GetDevice fetches the first device from the context satisfying the comparison function

func (*Context) GetDeviceByID

func (c *Context) GetDeviceByID(id string) *Device

GetDeviceByID fetches the first device with given name

func (*Context) GetDeviceByName

func (c *Context) GetDeviceByName(name string) *Device

GetDeviceByName fetches the first device with given name

func (*Context) GetDeviceByNameOrID

func (c *Context) GetDeviceByNameOrID(name, id *string) *Device

GetDeviceByNameOrID fetches the first device that does not mismatch given name or id. If only name is given, it behaves like GetDeviceByName and when only id is given like GetDeviceByID. When both are given, it matches on both attributes and when none are given, it matches any first device.

type ContextAttribute

type ContextAttribute struct {
	Name  string `xml:"name,attr"`  // Name of the attribute, e.g. "local,kernel"
	Value string `xml:"value,attr"` // Value of the attribute, e.g. "5.11.0-40-generic"
}

ContextAttribute is the data structure containing attributes relating to the context

type Device

type Device struct {
	ID       string     `xml:"id,attr"`   // Identifier, e.g. "iio:device0"
	Name     string     `xml:"name,attr"` // Name of the device, e.g. "bme280"
	Channels []*Channel `xml:"channel"`   // List of channels in the device
}

Device holds information regarding IIO device

func (*Device) GetChannel

func (d *Device) GetChannel(comp CompareChannel) *Channel

GetChannel fetches the first channel from the device satisfying the comparison function

func (*Device) GetChannelByID

func (d *Device) GetChannelByID(id string) *Channel

GetChannelByID fetches the first attribute with given ID

type IIO

type IIO struct {
	Context *Context // contains the context of the remote iiod instance
	// contains filtered or unexported fields
}

IIO is the client connecting to a (remote) iiod

func New

func New(remote string) (*IIO, error)

Creates a new IIO client

func (*IIO) Close

func (i *IIO) Close() error

func (*IIO) CreateBuffer

func (i *IIO) CreateBuffer(dev_name string, buf_size int, chan_mask string) error

func (*IIO) DestroyBuffer

func (i *IIO) DestroyBuffer(dev_name string) error

func (*IIO) DumpBuffer

func (i *IIO) DumpBuffer(dev_name string, buf_size int) ([]uint8, error)

func (*IIO) FetchAttributes

func (i *IIO) FetchAttributes() error

Fetch all attributes for all devices

Jump to

Keyboard shortcuts

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