common

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: AGPL-3.0 Imports: 1 Imported by: 0

README

公共结构体库

考虑到很多配置项其实是公用的。所以此目录存放一公共配置相关的结构体等,从0.3以后的版本,每个资源、设备、目标配置都全部存放在这里。比如modbus或者西门子等的配置。

版本

从0.3以后开始使用,之前的暂时沿用旧的。

Documentation

Index

Constants

View Source
const (
	READ_COIL                        = 1  //  Read Coil
	READ_DISCRETE_INPUT              = 2  //  Read Discrete Input
	READ_HOLDING_REGISTERS           = 3  //  Read Holding Registers
	READ_INPUT_REGISTERS             = 4  //  Read Input Registers
	WRITE_SINGLE_COIL                = 5  //  Write Single Coil
	WRITE_SINGLE_HOLDING_REGISTER    = 6  //  Write Single Holding Register
	WRITE_MULTIPLE_COILS             = 15 //  Write Multiple Coils
	WRITE_MULTIPLE_HOLDING_REGISTERS = 16 //  Write Multiple Holding Registers
)
View Source
const (
	T_1KB   int = 1 * 1024
	T_2KB   int = 2 * 1024
	T_4KB   int = 4 * 1024
	T_64KB  int = 64 * 1024
	T_128KB int = 128 * 1024
	T_1MB   int = 1024 * 1024
)

* * 定义一些常见的块大小 *

Variables

This section is empty.

Functions

func BitStringToBytes

func BitStringToBytes(s string) ([]byte, error)

* * 字符串转字节 *

func BitToBool

func BitToBool(data byte, index uint8) bool

* * 字节上某个位转逻辑值 *

func BitToUint8

func BitToUint8(data byte, index uint8) uint8

func ByteToBool

func ByteToBool(data byte) bool

* * 字节转布尔值 本质上是判断是否等于0 or 1 *

func GetABitOnByte

func GetABitOnByte(b byte, position uint8) (v uint8)

* * 取某个字节上的位 *

func SetABitOnByte

func SetABitOnByte(b *byte, position uint8, value bool) (byte, error)

* * 设置字节上的某个位 *

Types

type Coils

type Coils struct {
	Address  uint16 `json:"address" validate:"required" title:"寄存器地址"`
	Quantity uint16 `json:"quantity" validate:"required" title:"写入数量"`
	Values   []byte `json:"values" validate:"required" title:"写入的值"` // 如果是单个写 取 Values[0]
}

* * coilParams 1 *

type CommonUartConfig

type CommonUartConfig struct {
	Timeout  int    `json:"timeout" validate:"required"`
	Uart     string `json:"uart" validate:"required"`
	BaudRate int    `json:"baudRate" validate:"required"`
	DataBits int    `json:"dataBits" validate:"required"`
	Parity   string `json:"parity" validate:"required"`
	StopBits int    `json:"stopBits" validate:"required"`
}

* * 4.19重构 *

type GenericIoTHUBMqttConfig added in v0.5.2

type GenericIoTHUBMqttConfig struct {
	Mode       string `json:"mode" validate:"required" title:"模式:GW(网关)|DC(直连)"`
	ProductId  string `json:"productId" validate:"required" title:"产品名"`
	DeviceName string `json:"deviceName" validate:"required" title:"设备名"`
	//
	Host string `json:"host" validate:"required" title:"服务地址"`
	Port int    `json:"port" validate:"required" title:"服务端口"`
	//
	ClientId string `json:"clientId" validate:"required" title:"客户端ID"`
	Username string `json:"username" validate:"required" title:"连接账户"`
	Password string `json:"password" validate:"required" title:"连接密码"`
}

type GenericSnmpConfig

type GenericSnmpConfig struct {
	// Target is an ipv4 address.
	Target string `json:"target" validate:"required" title:"Target" info:"Target"`
	// Port is a port.
	Port uint16 `json:"port" validate:"required" title:"Port" info:"Port"`
	// Transport is the transport protocol to use ("udp" or "tcp"); if unset "udp" will be used.
	Transport string `json:"transport" validate:"required" title:"Transport" info:"Transport"`
	// Community is an SNMP Community string.
	Community string `json:"community" validate:"required" title:"Community" info:"Community"`
}

* * SNMP 配置 *

type GrpcConfig

type GrpcConfig struct {
	Host string `json:"host" validate:"required" title:"地址"`
	Port int    `json:"port" validate:"required" title:"端口"`
	Type string `json:"type" title:"类型"`
}

* * *

type HTTPConfig

type HTTPConfig struct {
	Url     string            `json:"url" validate:"required" title:"URL"`
	Headers map[string]string `json:"headers" validate:"required" title:"HTTP Headers"`
}

* * HTTP *

type HostConfig

type HostConfig struct {
	Host    string `json:"host" validate:"required" title:"服务地址"`
	Port    int    `json:"port" validate:"required" title:"服务端口"`
	Timeout int    `json:"timeout,omitempty" title:"连接超时"`
}

* * 通用的含有主机:端口的这类配置 *

type IcmpConfig

type IcmpConfig struct {
	Timeout int `json:"timeout" validate:"required" title:"连接超时"`
	// ["127.0.0.1", "127.0.0.2", "127.0.0.3"]
	Hosts []string `json:"hosts" validate:"required" title:"服务地址"`
}

* * IP 地址 *

type ModBusConfig

type ModBusConfig struct {
	Mode        string       `json:"mode" title:"工作模式" info:"UART/TCP"`
	Timeout     *int         `json:"timeout" validate:"required" title:"连接超时"`
	AutoRequest *bool        `json:"autoRequest" validate:"required"`
	Frequency   *int64       `json:"frequency" validate:"required" title:"采集频率"`
	Config      interface{}  `json:"config" validate:"required" title:"工作模式"`
	Registers   []RegisterRW `json:"registers" validate:"required" title:"寄存器配置"`
}

type MongoConfig

type MongoConfig struct {
	MongoUrl   string `json:"mongoUrl" validate:"required" title:"URL"`
	Database   string `json:"database" validate:"required" title:"数据库"`
	Collection string `json:"collection" validate:"required" title:"集合"`
}

* * Mongodb 配置 *

type MqttConfig

type MqttConfig struct {
	Host     string `json:"host" validate:"required" title:"服务地址"`
	Port     int    `json:"port" validate:"required" title:"服务端口"`
	ClientId string `json:"clientId" validate:"required" title:"客户端ID"`
	Username string `json:"username" validate:"required" title:"连接账户"`
	Password string `json:"password" validate:"required" title:"连接密码"`
	PubTopic string `json:"pubTopic" title:"上报TOPIC" info:"上报TOPIC"` // 上报数据的 Topic
	SubTopic string `json:"subTopic" title:"订阅TOPIC" info:"订阅TOPIC"` // 上报数据的 Topic
}

* * MQTT 连接配置 *

type NatsConfig

type NatsConfig struct {
	Username string `json:"username" validate:"required" title:"用户"`
	Password string `json:"password" validate:"required" title:"密码"`
	Host     string `json:"host" validate:"required" title:"地址"`
	Port     int    `json:"port" validate:"required" title:"端口"`
	Topic    string `json:"topic" validate:"required" title:"转发Topic"`
}

type RULEXUdpConfig

type RULEXUdpConfig struct {
	Host          string `json:"host" validate:"required" title:"服务地址"`
	Port          int    `json:"port" validate:"required" title:"服务端口"`
	MaxDataLength int    `json:"maxDataLength" title:"最大数据包"`
}

type RegisterRW

type RegisterRW struct {
	Tag       string `json:"tag" validate:"required" title:"数据Tag"`         // 数据Tag
	Alias     string `json:"alias" validate:"required" title:"别名"`          // 别名
	Function  int    `json:"function" validate:"required" title:"Modbus功能"` // Function
	SlaverId  byte   `json:"slaverId" validate:"required" title:"从机ID"`     // 从机ID
	Address   uint16 `json:"address" validate:"required" title:"地址"`        // Address
	Frequency int64  `json:"frequency" validate:"required" title:"采集频率"`    // 间隔
	Quantity  uint16 `json:"quantity" validate:"required" title:"数量"`       // Quantity
	Value     string `json:"value"`                                         // 运行时数据
}

* * 采集到的数据 *

type RegisterW added in v0.6.1

type RegisterW struct {
	Function int    `json:"function"` // Function
	SlaverId byte   `json:"slaverId"` // 从机ID
	Address  uint16 `json:"address"`  // Address
	Quantity uint16 `json:"quantity"` // Quantity
	Values   []byte `json:"values"`   // Value
}

* * 写入的数据 *

type Registers

type Registers struct {
	Address  uint16 `json:"address" validate:"required" title:"寄存器地址"`
	Quantity uint16 `json:"quantity" validate:"required" title:"写入数量"`
	Values   []byte `json:"values" validate:"required" title:"写入的值"` // 如果是单个写 取 Values[0]
}

* * 4 *

type S1200Block

type S1200Block struct {
	Tag       string `json:"tag" validate:"required" title:"数据tag"` // 数据tag
	Type      string `json:"type" validate:"required" title:"地址"`   // MB | DB |FB
	Frequency int64  `json:"frequency" validate:"required" title:"采集频率"`
	Address   int    `json:"address" validate:"required" title:"地址"`            // 地址
	Start     int    `json:"start" validate:"required" title:"起始地址"`            // 起始地址
	Size      int    `json:"size" validate:"required" title:"服务地址"`             // 数据长度
	Value     string `json:"value,omitempty" validate:"required" title:"数据Hex"` // 值
}

type S1200Config

type S1200Config struct {
	Host        string       `json:"host" validate:"required" title:"IP地址:端口号"`      // 127.0.0.1
	Model       string       `json:"model" validate:"required" title:"型号"`           // s7-200 s7 1500
	Rack        *int         `json:"rack" validate:"required" title:"架号"`            // 0
	Slot        *int         `json:"slot" validate:"required" title:"槽号"`            // 1
	Timeout     *int         `json:"timeout" validate:"required" title:"连接超时时间"`     // 5s
	IdleTimeout *int         `json:"idleTimeout" validate:"required" title:"心跳超时时间"` // 5s
	AutoRequest *bool        `json:"autoRequest" title:"启动轮询"`
	Blocks      []S1200Block `json:"blocks" validate:"required" title:"采集配置"` // Db
}

* * 西门子PLC的一些配置 *

type SqliteConfig

type SqliteConfig struct {
	// 本地数据库名称
	DbName string `json:"dbName" validate:"required"`
	// 数据表名
	CreateTbSql string `json:"createTbSql" validate:"required"`
	// 插入语句, 变量用 ? 替代,会被替换成实际值
	// Eg: insert into db1.tb1 value(v1, v2, v3)
	InsertSql string `json:"insertSql" validate:"required"`
}

* * Sqlite 配置 *

type TDEngineConfig

type TDEngineConfig struct {
	Fqdn     string `json:"fqdn" validate:"required" title:"地址"`     // 服务地址
	Port     int    `json:"port" validate:"required" title:"端口"`     // 服务端口
	Username string `json:"username" validate:"required" title:"用户"` // 用户
	Password string `json:"password" validate:"required" title:"密码"` // 密码
	DbName   string `json:"dbName" validate:"required" title:"数据库名"` // 数据库名
}

http://<fqdn>:<port>/rest/sql/[db_name] fqnd: 集群中的任一台主机 FQDN 或 IP 地址 port: 配置文件中 httpPort 配置项,缺省为 6041 db_name: 可选参数,指定本次所执行的 SQL 语句的默认数据库库名 curl -u root:taosdata -d 'show databases;' 106.15.225.172:6041/rest/sql

Jump to

Keyboard shortcuts

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