server

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exist

func Exist(name string) bool

Types

type Attribute

type Attribute struct {
	ID         int         `json:"id"`
	Attribute  string      `json:"attribute"`
	Val        interface{} `json:"val"`
	ValType    string      `json:"val_type"`
	Min        *int        `json:"min,omitempty"`
	Max        *int        `json:"max,omitempty"`
	Permission uint        `json:"permission"`
}

type AuthDevice added in v1.5.0

type AuthDevice interface {
	Device
	// IsAuth 返回设备是否成功认证/配对
	IsAuth() bool
	// Auth 认证/配对
	Auth(params map[string]string) error
	// RemoveAuthorization 取消认证/配对
	RemoveAuthorization(params map[string]string) error
}

AuthDevice 需要认证的设备

type ChildDevice added in v1.9.1

type ChildDevice interface {
	Online() bool
}

ChildDevice 子设备,暂时只需要Online方法

type Device

type Device interface {
	Identity() string
	Info() DeviceInfo
	Setup() error
	Online() bool
	Update() error
	Close() error
	GetChannel() WatchChan
}

type DeviceInfo

type DeviceInfo struct {
	Identity     string
	Model        string
	Manufacturer string
	AuthRequired bool
}

type Instance

type Instance struct {
	Type       string      `json:"type"`
	InstanceId int         `json:"instance_id"`
	Attributes []Attribute `json:"attributes"`
}

func GetDeviceInstances added in v1.9.1

func GetDeviceInstances(device Device) (instances []Instance)

type Manager

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

func NewManager

func NewManager() *Manager

func (*Manager) AddDevice

func (p *Manager) AddDevice(device Device) error

AddDevice 添加设备

func (*Manager) Auth added in v1.5.0

func (p *Manager) Auth(identity string, params map[string]string) (err error)

func (*Manager) Devices

func (p *Manager) Devices() (ds []Device, err error)

func (*Manager) Disconnect added in v1.5.0

func (p *Manager) Disconnect(identity string, params map[string]string) (err error)

func (*Manager) GetAttributes

func (p *Manager) GetAttributes(identity string) (s []Instance, err error)

func (*Manager) HealthCheck

func (p *Manager) HealthCheck(identity string) bool

func (*Manager) Init

func (p *Manager) Init()

func (*Manager) IsOTASupport added in v1.9.1

func (p *Manager) IsOTASupport(identity string) (bool, error)

func (*Manager) Notify

func (p *Manager) Notify(identity string, instanceID int, attr *utils.Attribute) attribute.NotifyFunc

func (*Manager) OTA added in v1.9.1

func (p *Manager) OTA(identity, firmwareURL string) (ch chan OTAResp, err error)

func (*Manager) RemoveDevice

func (p *Manager) RemoveDevice(identity string) error

RemoveDevice 删除设备

func (*Manager) SetAttribute

func (p *Manager) SetAttribute(identity string, instanceID int, attr string, val interface{}) (err error)

func (*Manager) SetAttributeNotify added in v1.9.1

func (p *Manager) SetAttributeNotify(identity string) error

func (*Manager) Subscribe

func (p *Manager) Subscribe(notify chan Notify)

func (*Manager) Unsubscribe

func (p *Manager) Unsubscribe(notify chan Notify)

func (*Manager) WatchNotify

func (p *Manager) WatchNotify(ch WatchChan)

type Notification

type Notification struct {
	Identity   string
	InstanceID int
	Attr       string
	Val        interface{}
}

type Notify

type Notify struct {
	Identity   string    `json:"identity"`
	InstanceID int       `json:"instance_id"`
	Attribute  Attribute `json:"attribute"`
}

type OTADevice added in v1.9.1

type OTADevice interface {
	Device
	OTA(firmwareURL string) (chan OTAResp, error)
}

type OTAProgressState added in v1.9.1

type OTAProgressState int // OTA进度
const (
	OTAFinish OTAProgressState = 100 // OTA成功

	OTAUpgradeFail  OTAProgressState = -1 // 更新失败
	OTADownloadFail OTAProgressState = -2 // 下载失败
	OTAValidateFail OTAProgressState = -3 // 校验失败
	OTABurnFail     OTAProgressState = -4 // 烧写失败
)

func OTAProgress added in v1.9.1

func OTAProgress(i int) OTAProgressState

type OTAResp added in v1.9.1

type OTAResp struct {
	Step OTAProgressState
}

type OptionFunc

type OptionFunc func(s *Server)

func WithConfigFile

func WithConfigFile(configFile string) OptionFunc

func WithDomain added in v1.5.0

func WithDomain(domain string) OptionFunc

func WithStatic

func WithStatic(staticDir string) OptionFunc

type ParentDevice added in v1.9.1

type ParentDevice interface {
	Device
	GetChildDeviceById(instanceId int) ChildDevice
}

ParentDevice 父设备:拥有子设备的设备

type Server

type Server struct {
	Manager   *Manager
	Domain    string
	Router    *gin.Engine
	ApiRouter *gin.RouterGroup
	// contains filtered or unexported fields
}

func NewPluginServer

func NewPluginServer(opts ...OptionFunc) *Server

func (Server) Connect added in v1.5.0

func (p Server) Connect(ctx context.Context, req *proto.AuthReq) (resp *proto.GetAttributesResp, err error)

func (Server) Disconnect added in v1.5.0

func (p Server) Disconnect(ctx context.Context, req *proto.AuthReq) (resp *proto.Empty, err error)

func (Server) Discover

func (p Server) Discover(request *proto.Empty, server proto.Plugin_DiscoverServer) error

func (Server) GetAttributes

func (p Server) GetAttributes(context context.Context, request *proto.GetAttributesReq) (resp *proto.GetAttributesResp, err error)

func (Server) HealthCheck

func (p Server) HealthCheck(context context.Context, req *proto.HealthCheckReq) (resp *proto.HealthCheckResp, err error)

func (*Server) Init

func (p *Server) Init()

func (Server) OTA added in v1.9.1

func (p Server) OTA(req *proto.OTAReq, server proto.Plugin_OTAServer) error

func (Server) SetAttributes

func (p Server) SetAttributes(context context.Context, request *proto.SetAttributesReq) (resp *proto.SetAttributesResp, err error)

func (Server) StateChange

func (p Server) StateChange(request *proto.Empty, server proto.Plugin_StateChangeServer) error

type SetAttribute

type SetAttribute struct {
	InstanceID int         `json:"instance_id"`
	Attribute  string      `json:"attribute"`
	Val        interface{} `json:"val"`
}

type SetRequest

type SetRequest struct {
	Attributes []SetAttribute `json:"attributes"`
}

type WatchChan

type WatchChan chan Notification

Jump to

Keyboard shortcuts

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