hub

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 9 Imported by: 0

README

hub

intelligent home hub

Documentation

Index

Constants

View Source
const (
	// ReceiveTopic 设置设备主题, 需要提供设备编号
	ReceiveTopicFormat = "/receive/%s"
	// SendDevices 上报主题
	SendDevicesTopic = "/send/devices"
)

Variables

View Source
var (
	// MQTTSecretEnable 是否启用 mqtt 消息加密
	MQTTSecretEnable = false
	// MQTTMsgSecretKey  mqtt 消息加密 key, 如果使用3DES 必须保证 24 字节
	MQTTSecretKey = ""
	// MQTTServer mqtt 服务地址
	MQTTServer = "localhost:1883"
	// MQTTUser mqtt 服务连接用户名
	MQTTUser = ""
	// MQTTPassword mqtt 服务连接密码
	MQTTPassword = ""
	// DeviceNo 网关设备编号
	DeviceNo = ""
	// Pannel Address 控制面板地址
	DevicePannelAddress = ""
	// ReceiveTopic 设置设备主题
	ReceiveTopic = ""

	// MQTTClient mqtt client
	MQTTClient   mqtt.Client
	MQTTClientID = fmt.Sprintf("controller-%d", time.Now().UnixMilli())
)

Functions

func Decrypt

func Decrypt(cipherText []byte) ([]byte, error)

Decrypt mqtt 消息解码

func Encrypt

func Encrypt(plainText []byte) ([]byte, error)

Encrypt mqtt 消息编码 使用 3DES 加密输入字符串,然后用base64编码,返回字符串

func Init

func Init() error

Init will initialize device

func Publish

func Publish(cmd Command) error

Publish send mqtt command msg

Types

type Command

type Command interface {
	// Name command name
	Name() string
	// Msg command mqtt message
	Msg() ([]byte, error)
}

Command mqtt command

type CommandResult

type CommandResult struct {
	// Command 指令名称
	Command string `json:"command"`
	// Serial 序列号, 用于反馈于指定请求判断
	Serial string `json:"serial"`
	// DeviceNo 设备编号
	DeviceNo string `json:"device_no"`
	// Result 执行结果, 1:成功, 0:失败
	Result string `json:"result"`
}

CommandResult 指令执行结果

type Device

type Device map[string]string

Device 设备

func DeviceStatus

func DeviceStatus(channel string) (Device, bool)

DeviceStatus get device previous status

type Panel

type Panel struct {
	// Address 控制面板地址
	Address string `json:"address" jsonschema:"description=控制面板地址"`
	// ChildDev 子设备列表
	ChildDev []Device `json:"child_dev" josnschema:"description=子设备列表"`
}

type ReadStatusCommand

type ReadStatusCommand struct {
	Timestamp string `json:"time_stamp"`
	Command   string `json:"command"`
	Serial    string `json:"serial"`
}

ReadStatusCommand 读取设备状态指令

func NewReadStatusCommand

func NewReadStatusCommand() *ReadStatusCommand

NewReadStatusCommand 创建读取设备指令

func (*ReadStatusCommand) Msg

func (c *ReadStatusCommand) Msg() ([]byte, error)

Msg 指令 mqtt 消息

func (*ReadStatusCommand) Name

func (c *ReadStatusCommand) Name() string

Name command name

type ReadStatusResult

type ReadStatusResult struct {
	Timestamp string `json:"time_stamp"`
	// Command 指令名称
	Command string `json:"command"`
	// Serial 序列号, 用于反馈于指定请求判断
	Serial string `json:"serial"`
	// DeviceNo 设备编号
	DeviceNo string `json:"device_no"`
	// Panels 控制面板列表
	Panels []Panel `json:"panels"`
}

ReadStatusResult 读取网关设备状态结果

func NewReadStatusResult

func NewReadStatusResult(deviceNo string) *ReadStatusResult

NewReadStatusResult 创建设备状态结果

func (*ReadStatusResult) Device

func (r *ReadStatusResult) Device(addr string, channel string) (Device, bool)

Device 查找指定设备, addr 为 panel 地址, channel 为管道号

type SetPanelsCommand

type SetPanelsCommand struct {
	// Command 指令名称, 如 set_panels
	Command string `json:"command" jsonschema:"description=指令名称"`
	// Serial 序列号
	Serial string `json:"serial" jsonschema:"description=序列号"`
	// DeviceNo 设备编号, 如 c49878f1e235
	DeviceNo string `json:"device_no" jsonschema:"description=设备编号"`
	// Panels 控制面板列表
	Panels []Panel `json:"panels" jsonschema:"description=控制面板列表"`
	// TimeStamp 时间戳
	Timestamp string `json:"time_stamp" jsonschema:"description=时间戳"`
}

SetPanelsCommand 设置面板指令

func NewSetPanelsCommand

func NewSetPanelsCommand() *SetPanelsCommand

NewSetPanelsCommand 创建设置面板指令

func NewSetPanelsCommandWithDevice

func NewSetPanelsCommandWithDevice(device Device) *SetPanelsCommand

NewSetPanelsCommandWithDevice create a set panels command with device

func (*SetPanelsCommand) Msg

func (c *SetPanelsCommand) Msg() ([]byte, error)

Msg 设置面板 mqtt 消息

func (*SetPanelsCommand) Name

func (c *SetPanelsCommand) Name() string

Name the command name

Jump to

Keyboard shortcuts

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