gotag

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gotag Build Status

GoTag is a Go pakcage for ThingsPro. It integrates mqtt client and protobuffer which makes data exchanging become easily and narrow down the transmission bandwidth.

Installation

Since Gotag is a golang version wrapper of libmx-dx, you will also need to install the necessary dynamic libraries from the 3rd-party directory:

libparson1
libmosquitto1
libmx-dx1
Apt Install
apt-get update
apt-get install -y -f ./*.deb
Docker Image

If you are a docker user, downsizing the image could be the one of tough issues. We provide the following sample for you to easily copy the necessary libraries in a Dockerfile.

RUN mkdir -p /usr/include/libmx-dx
COPY --from=build-env \
		/usr/include/libmx-dx \
		/usr/include/libmx-dx

COPY --from=build-env \
		/usr/include/parson.h \
		/usr/include/mosquitto.h \
		/usr/include/

COPY --from=build-env \
        /usr/lib/arm-linux-gnueabihf/libmx* \
        /usr/lib/arm-linux-gnueabihf/libparson.so* \
        /usr/lib/arm-linux-gnueabihf/libssl.so* \
        /usr/lib/arm-linux-gnueabihf/libcrypto.so* \
        /usr/lib/arm-linux-gnueabihf/libprotobuf-c* \
        /usr/lib/arm-linux-gnueabihf/libmosquitto* \
        /usr/lib/arm-linux-gnueabihf/

Once you have finished the prerequisite, run the command to install Gotag:

    go get github.com/MOXA-ISD/gotag

Build a gotag client

import (
    gotag github.com/MOXA-ISD/gotag
)

func main() {   
    client, err := gotag.NewClient()
    if err != nil {
        log.Fatal(err)
    }
    defer client.Delete()

    //...
}

Run data pub/sub

As mentioned, gotag use a mqtt client to do the transmission which means it has to pub/sub topics to send/receive data.

Publish data
func Publish(client *gotag.Tagf) {
    value := gotag.NewValue(1.414)
    client.Publish(
        "moduleName"
        "sourceName",
        "tagName",
        value,
        t.TAG_VALUE_TYPE_DOUBLE,
        1546920188000)
}

Subscribe data
func Subscribe(client *gotag.Tagf) {
    client.SubscribeCallback(Handler)
    client.Subscribe("moduleName", "sourceName", "tagName")
}
SubscribeCallback

Gotag needs to register a callback function for subscribed topics.

func Handler(module, source, tag string, val *t.Value, valtype uint16, ts uint64) {
    fmt.Printf("Module: %v,", module)
    fmt.Printf("Source: %v,", source)
    fmt.Printf("Tag: %v,", tag)
    fmt.Printf("Value: %v,", val.GetDouble())
    fmt.Printf("ValueType: %v,", valtype)
    fmt.Printf("At: %v,", ts)
}

Documentation

Index

Constants

View Source
const (
	ERR_SUCESS        = 0
	ERR_FAILED        = 1
	ERR_INVALID_INPUT = 2
	ERR_NULL_ACCESS   = 3
)
View Source
const (
	TAG_VALUE_TYPE_BOOLEAN   = 0
	TAG_VALUE_TYPE_INT8      = 1
	TAG_VALUE_TYPE_INT16     = 2
	TAG_VALUE_TYPE_INT32     = 3
	TAG_VALUE_TYPE_INT64     = 4
	TAG_VALUE_TYPE_INT       = 5
	TAG_VALUE_TYPE_UINT8     = 6
	TAG_VALUE_TYPE_UINT16    = 7
	TAG_VALUE_TYPE_UINT32    = 8
	TAG_VALUE_TYPE_UINT64    = 9
	TAG_VALUE_TYPE_UINT      = 10
	TAG_VALUE_TYPE_FLOAT     = 11
	TAG_VALUE_TYPE_DOUBLE    = 12
	TAG_VALUE_TYPE_STRING    = 13
	TAG_VALUE_TYPE_BYTEARRAY = 14
	TAG_VALUE_TYPE_RAW       = 0xFF
)

Variables

This section is empty.

Functions

func DecodeDxValue added in v1.0.0

func DecodeDxValue(val *Value, v *C.DX_TAG_VALUE, valType uint16)

func DecodeTopic

func DecodeTopic(topic string) (string, string, string)

func EncodeDxValue added in v1.0.0

func EncodeDxValue(val *Value, v *C.DX_TAG_VALUE, valType uint16)

func EncodeTopic

func EncodeTopic(module, source, tag string) string

func FreeAlloc added in v1.0.0

func FreeAlloc(val *C.DX_TAG_VALUE, valType uint16)

func GetTimestamp added in v1.1.0

func GetTimestamp() int64

Types

type DataExchange added in v1.0.0

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

func NewDataExchange added in v1.0.0

func NewDataExchange() *DataExchange

func (*DataExchange) Close added in v1.0.0

func (d *DataExchange) Close() error

func (*DataExchange) Publish added in v1.0.0

func (d *DataExchange) Publish(topic string, valType uint16, val *Value, ts uint64) error

func (*DataExchange) Subscribe added in v1.0.0

func (d *DataExchange) Subscribe(topic string) error

func (*DataExchange) SubscribeCallback added in v1.0.0

func (d *DataExchange) SubscribeCallback(hnd OnTagCallback) error

func (*DataExchange) UnSubscribe added in v1.0.0

func (d *DataExchange) UnSubscribe(topic string) error

type MQConfig

type MQConfig struct {
	Id       string
	Host     string
	Port     string
	Debug    string
	Qos      byte
	Retained bool
}

type OnTagCallback

type OnTagCallback func(
	moduleName string,
	sourceName string,
	tagName string,
	value *Value,
	valueType uint16,
	timestamp uint64)

type Tag

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

type Tagf

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

func NewClient

func NewClient() (*Tagf, error)

func (*Tagf) Delete

func (self *Tagf) Delete() error

func (*Tagf) Get added in v1.0.0

func (self *Tagf) Get(module, source, tag string) *Tag

func (*Tagf) Publish

func (self *Tagf) Publish(modName, srcName, tagName string, val *Value, valType uint16, timestamp uint64) error

func (*Tagf) Subscribe

func (self *Tagf) Subscribe(modName, sourceName, tagName string) error

func (*Tagf) SubscribeCallback

func (self *Tagf) SubscribeCallback(ontag OnTagCallback) error

func (*Tagf) TagList added in v1.0.0

func (self *Tagf) TagList() []Tag

func (*Tagf) UnSubscribe

func (self *Tagf) UnSubscribe(modName, sourceName, tagName string) error

type Value

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

func NewValue

func NewValue(value interface{}) *Value

func (*Value) GetBool added in v1.1.1

func (m *Value) GetBool() bool

func (*Value) GetBytes

func (m *Value) GetBytes() []byte

func (*Value) GetDouble

func (m *Value) GetDouble() float64

func (*Value) GetFloat

func (m *Value) GetFloat() float32

func (*Value) GetInt

func (m *Value) GetInt() int64

func (*Value) GetRaw added in v1.0.1

func (m *Value) GetRaw() []byte

func (*Value) GetStr

func (m *Value) GetStr() string

func (*Value) GetUint

func (m *Value) GetUint() uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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