sensorconnect_plugin

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const BadgeSize = 50

BadgeSize is Maximum possible size of the "/getdatamulti" request, determined for AL1352 and EIO404 Devices.

View Source
const CONNECTION_TIMEOUT_SECONDS = 10

Variables

This section is empty.

Functions

func ConfigSpec

func ConfigSpec() *service.ConfigSpec

ConfigSpec defines the plugin's configuration spec

func GetBackoffTime

func GetBackoffTime(attempt int64, min, max time.Duration) time.Duration

GetBackoffTime calculates the backoff duration based on the attempt number. It uses exponential backoff with jitter, bounded by min and max durations.

func GetDiagnosticMessage

func GetDiagnosticMessage(code int) string

GetDiagnosticMessage returns a diagnostic message based on the code

func NewSensorConnectInput

func NewSensorConnectInput(conf *service.ParsedConfig, mgr *service.Resources) (service.BatchInput, error)

NewSensorConnectInput creates a new instance of SensorConnectInput

Types

type ConnectedDeviceInfo

type ConnectedDeviceInfo struct {
	Uri         string
	Mode        uint
	Connected   bool
	DeviceID    uint
	VendorID    uint
	ProductName string
	Serial      string
	Port        string
	UseRawData  bool // If true, the raw data will be used instead of the parsed data. This flag is automatically set if there is no IODD file available
	BtAdapter   string
}

ConnectedDeviceInfo represents information about a connected device on a port

type Content

type Content struct {
	ProductName        string `json:"productName"`
	IndicationOfSource string `json:"indicationOfSource"`
	IoLinkRev          string `json:"ioLinkRev"`
	VersionString      string `json:"versionString"`
	IoddStatus         string `json:"ioddStatus"`
	ProductID          string `json:"productId"`
	VendorName         string `json:"vendorName"`
	ProductVariantID   int64  `json:"productVariantId"`
	UploadDate         int64  `json:"uploadDate"`
	VendorID           int64  `json:"vendorId"`
	IoddID             int64  `json:"ioddId"`
	DeviceID           int64  `json:"deviceId"`
	HasMoreVersions    bool   `json:"hasMoreVersions"`
}

type Data

type Data struct {
	DeviceInfoSerialnumber StringDataPoint `json:"/deviceinfo/serialnumber/"`
	DeviceInfoProductCode  StringDataPoint `json:"/deviceinfo/productcode/"`
}

type Datatype

type Datatype struct {
	Type             string        `xml:"type,attr"`
	Id               string        `xml:"id,attr"`
	RecordItemArray  []RecordItem  `xml:"RecordItem"`
	SingleValueArray []SingleValue `xml:"SingleValue"`
	ValueRangeArray  []ValueRange  `xml:"ValueRange"`
	BitLength        uint          `xml:"bitLength,attr"`
	FixedLength      uint          `xml:"fixedLength,attr"`
}

type DatatypeCollection

type DatatypeCollection struct {
	DatatypeArray []Datatype `xml:"Datatype"`
}

type DatatypeRef

type DatatypeRef struct {
	DatatypeId string `xml:"datatypeId,attr"`
}

type DeviceConfig added in v0.4.1

type DeviceConfig struct {
	DeviceID int    `json:"device_id"`
	VendorID int    `json:"vendor_id"`
	IoddURL  string `json:"iodd_url"`
}

type DeviceFunction

type DeviceFunction struct {
	DatatypeCollection    DatatypeCollection    `xml:"DatatypeCollection"`
	ProcessDataCollection ProcessDataCollection `xml:"ProcessDataCollection"`
}

type DeviceIdentity

type DeviceIdentity struct {
	VendorName string `xml:"vendorName,attr"`
	DeviceId   int    `xml:"deviceId,attr"` // Id of type of a device, given by device vendor
	VendorId   int64  `xml:"vendorId,attr"`
}

type DeviceInformation

type DeviceInformation struct {
	ProductCode     string
	SerialNumber    string
	URL             string
	FirmwareVersion string
	BuggedFirmware  bool // This indicates if the firmware is known to have crash issues if one does too many requests. Set to true if the firmware version is not known.
}

DeviceInformation holds relevant information about discovered devices

type DiscoverResponseFromDevice

type DiscoverResponseFromDevice struct {
	Data Data `json:"data"`
	Cid  int  `json:"cid"`
}

DiscoverResponseFromDevice structures for parsing device responses

type DocumentInfo

type DocumentInfo struct {
	ReleaseDate string `xml:"releaseDate,attr"`
}

type ExternalTextCollection

type ExternalTextCollection struct {
	PrimaryLanguage PrimaryLanguage `xml:"PrimaryLanguage"`
}

type IoDDFile

type IoDDFile struct {
	Name    string
	File    []byte
	Context Content
}

IoDDFile is a helper structure with the name, file and additional context of the iodd file

type IoDevice

type IoDevice struct {
	DocumentInfo           DocumentInfo           `xml:"DocumentInfo"`
	ExternalTextCollection ExternalTextCollection `xml:"ExternalTextCollection"`
	ProfileBody            ProfileBody            `xml:"ProfileBody"`
}

IoDevice Parsing of IODD File content

type IoddFilemapKey

type IoddFilemapKey struct {
	VendorId int64
	DeviceId int
}

IoddFilemapKey represents the key for the IODD file map

type Ioddfinder

type Ioddfinder struct {
	Content          []Content     `json:"content"`
	Sort             []interface{} `json:"sort"`
	Number           int64         `json:"number"`
	Size             int64         `json:"size"`
	NumberOfElements int64         `json:"numberOfElements"`
	TotalPages       int64         `json:"totalPages"`
	TotalElements    int64         `json:"totalElements"`
	First            bool          `json:"first"`
	Last             bool          `json:"last"`
}

func UnmarshalIoddfinder

func UnmarshalIoddfinder(data []byte) (Ioddfinder, error)

func (*Ioddfinder) Marshal

func (r *Ioddfinder) Marshal() ([]byte, error)

type Name

type Name struct {
	TextId string `xml:"textId,attr"`
}

type PrimaryLanguage

type PrimaryLanguage struct {
	Text []Text `xml:"Text"`
}

type ProcessData

type ProcessData struct {
	ProcessDataIn ProcessDataIn `xml:"ProcessDataIn"`
}

type ProcessDataCollection

type ProcessDataCollection struct {
	ProcessData ProcessData `xml:"ProcessData"`
}

type ProcessDataIn

type ProcessDataIn struct {
	DatatypeRef DatatypeRef `xml:"DatatypeRef"`
	Name        Name        `xml:"Name"`
	Datatype    Datatype    `xml:"Datatype"`
}

type ProfileBody

type ProfileBody struct {
	DeviceIdentity DeviceIdentity `xml:"DeviceIdentity"`
	DeviceFunction DeviceFunction `xml:"DeviceFunction"`
}

type RawUsedPortsAndMode

type RawUsedPortsAndMode struct {
	Data map[string]UPAMDatum `json:"data"`
	Cid  int                  `json:"cid"`
	Code int                  `json:"code"`
}

RawUsedPortsAndMode represents the raw response from the device for used ports and modes

type RecordItem

type RecordItem struct {
	Name           Name           `xml:"Name"`
	DatatypeRef    DatatypeRef    `xml:"DatatypeRef"`
	SimpleDatatype SimpleDatatype `xml:"SimpleDatatype"`
	BitOffset      int            `xml:"bitOffset,attr"`
}

type SensorConnectInput

type SensorConnectInput struct {
	// Configuration fields
	DeviceAddress string
	IODDAPI       string

	// Internal fields
	DeviceInfo       DeviceInformation
	ConnectedDevices []ConnectedDeviceInfo

	CurrentCid     int16
	UseOnlyRawData bool // Use only raw data for sensor data. This is used for testing purposes and skips the iodd download

	IoDeviceMap sync.Map // IoDeviceMap to store IoDevices
	// contains filtered or unexported fields
}

func (*SensorConnectInput) AddNewDeviceToIoddFilesAndMap

func (s *SensorConnectInput) AddNewDeviceToIoddFilesAndMap(ctx context.Context,
	ioddFilemapKey IoddFilemapKey) error

AddNewDeviceToIoddFilesAndMap uses ioddFilemapKey to download new IODD file (if key not already in IoDevice map).

func (*SensorConnectInput) BinToHex

func (s *SensorConnectInput) BinToHex(bin string) (string, error)

BinToHex converts a binary string to its hexadecimal representation. It preserves leading zeros based on the length of the input binary string. Returns an error if the binary string is invalid.

func (*SensorConnectInput) Close

func (s *SensorConnectInput) Close(ctx context.Context) error

Close cleans up resources

func (*SensorConnectInput) Connect

func (s *SensorConnectInput) Connect(ctx context.Context) error

Connect establishes connections and starts background processes

func (*SensorConnectInput) ConvertBinaryValue

func (s *SensorConnectInput) ConvertBinaryValue(binaryValue string, datatype string) (interface{}, error)

ConvertBinaryValue converts a binary string to its corresponding value based on the datatype. It handles both string and numeric data types and logs errors using the Benthos logger.

func (*SensorConnectInput) DetermineValueBitLength added in v0.4.5

func (s *SensorConnectInput) DetermineValueBitLength(datatype string, bitLength uint, fixedLength uint) uint

DetermineValueBitLength returns the bit length of a value based on its datatype.

func (*SensorConnectInput) FetchAndStoreIoDDFile

func (s *SensorConnectInput) FetchAndStoreIoDDFile(ctx context.Context, vendorId int64, deviceId int) (err error)

func (*SensorConnectInput) FetchAndStoreIoddFromURL added in v0.4.1

func (s *SensorConnectInput) FetchAndStoreIoddFromURL(ctx context.Context, device DeviceConfig) error

FetchAndStoreIoddFromURL fetches the IODD file from the custom URL and stores it.

func (*SensorConnectInput) GetConnectedDevices added in v0.4.3

func (s *SensorConnectInput) GetConnectedDevices(ctx context.Context) ([]ConnectedDeviceInfo, error)

GetConnectedDevices returns a map of the IO-Link Master's ports with port numbers as keys and ConnectedDeviceInfo as values

func (*SensorConnectInput) GetDeviceInformation

func (s *SensorConnectInput) GetDeviceInformation(ctx context.Context) (DeviceInformation, error)

GetDeviceInformation connects to the device and retrieves its information

func (*SensorConnectInput) GetIoddFile

func (s *SensorConnectInput) GetIoddFile(ctx context.Context, vendorId int64, deviceId int) (files []IoDDFile, err error)

GetIoddFile downloads a ioddfiles from ioddfinder and returns a list of valid files for the request (This can be multiple, if the vendor has multiple languages or versions published)

func (*SensorConnectInput) GetProcessedSensorDataFromRawSensorOutput

func (s *SensorConnectInput) GetProcessedSensorDataFromRawSensorOutput(rawSensorOutput string, portMode ConnectedDeviceInfo) (map[string]interface{}, error)

func (*SensorConnectInput) GetSensorDataMap

func (s *SensorConnectInput) GetSensorDataMap(ctx context.Context) (map[string]interface{}, error)

GetSensorDataMap retrieves sensor data from the connected devices

func (*SensorConnectInput) GetUrl

func (s *SensorConnectInput) GetUrl(ctx context.Context, url string) ([]byte, error, int)

GetUrl executes a GET request to the specified URL and returns the response body and status code.

func (*SensorConnectInput) GetUrlWithRetry

func (s *SensorConnectInput) GetUrlWithRetry(ctx context.Context, url string) ([]byte, error)

GetUrlWithRetry attempts to GET the specified URL up to maxRetries times with exponential backoff.

func (*SensorConnectInput) HexToBin

func (s *SensorConnectInput) HexToBin(hex string) (string, error)

HexToBin converts a hexadecimal string to its binary representation. It preserves leading zeros based on the length of the input hexadecimal string. Returns an error if the hexadecimal string is invalid.

func (*SensorConnectInput) IsDeviceBluetoothMeshCompatible added in v0.4.3

func (s *SensorConnectInput) IsDeviceBluetoothMeshCompatible() bool

func (*SensorConnectInput) ProcessSensorData

func (s *SensorConnectInput) ProcessSensorData(ctx context.Context, connectedDevices []ConnectedDeviceInfo, sensorDataMap map[string]interface{}) (service.MessageBatch, error)

ProcessSensorData processes the downloaded information from one IO-Link master and returns a message batch with one message per sensor (active port).

func (*SensorConnectInput) ProcessSimpleDatatype added in v0.4.5

func (s *SensorConnectInput) ProcessSimpleDatatype(
	simpleDatatype SimpleDatatype,
	outputBitLength int,
	rawSensorOutputBinaryPadded string,
	bitOffset int,
	nameTextId string,
	primLangExternalTextCollection []Text) (map[string]interface{}, error)

ProcessSimpleDatatype processes the given SimpleDatatype and returns the payload.

func (*SensorConnectInput) ReadBatch

ReadBatch reads data from sensors and returns it as a batch of messages

func (*SensorConnectInput) RequestSaveIoddFile

func (s *SensorConnectInput) RequestSaveIoddFile(ctx context.Context, ioddFilemapKey IoddFilemapKey) error

RequestSaveIoddFile will download the IODD file if the ioddFilemapKey is not already in IoDeviceMap

func (*SensorConnectInput) SendRequestToDevice

func (s *SensorConnectInput) SendRequestToDevice(ctx context.Context, requestData map[string]interface{}) (map[string]interface{}, error)

SendRequestToDevice sends a request to the device and checks the response CID

func (*SensorConnectInput) UnmarshalIoddFile

func (s *SensorConnectInput) UnmarshalIoddFile(ioddFile []byte, absoluteFilePath string) (IoDevice, error)

UnmarshalIoddFile unmarshals the IODD XML file into an IoDevice struct

func (*SensorConnectInput) ZeroPadding

func (s *SensorConnectInput) ZeroPadding(input string, desiredLength int) string

ZeroPadding pads the input string with leading zeros until it reaches the desired length.

type SensorDataInformation

type SensorDataInformation struct {
	Data map[string]interface{} `json:"data"`
	Cid  int                    `json:"cid"`
}

SensorDataInformation represents the response structure for sensor data

type SimpleDatatype

type SimpleDatatype struct {
	ValueRange  ValueRange  `xml:"ValueRange"`
	SingleValue SingleValue `xml:"SingleValue"`
	Type        string      `xml:"type,attr"`
	BitLength   uint        `xml:"bitLength,attr"`
	FixedLength uint        `xml:"fixedLength,attr"`
}

type SingleValue

type SingleValue struct {
	Value string `xml:"value,attr"` // can be any kind of type depending on Type of item -> determine later
	Name  Name   `xml:"Name"`
}

type StringDataPoint

type StringDataPoint struct {
	Data string `json:"data"`
	Code int    `json:"code"`
}

type Text

type Text struct {
	Id    string `xml:"id,attr"`
	Value string `xml:"value,attr"`
}

type UPAMDatum

type UPAMDatum struct {
	Data interface{} `json:"data,omitempty"`
	Code int         `json:"code"`
}

UPAMDatum represents a data point in the RawUsedPortsAndMode response

type ValueRange

type ValueRange struct {
	LowerValue string `xml:"lowerValue,attr"` // can be any kind of type depending on Type of item -> determine later
	UpperValue string `xml:"upperValue,attr"` // can be any kind of type depending on Type of item -> determine later
	Name       Name   `xml:"Name"`
}

Jump to

Keyboard shortcuts

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