model

package
v0.0.0-...-67d91c4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceTopic    = "d:%s:topic"   // 设备订阅的topic   set
	DeviceGroup    = "d:%s:group"   // 设备加入的组      set
	DeviceOnLine   = "d:%s:onlien"  // 0:不在线; 1:在线;  string
	TopicKey       = "topic:%s"     // topic信息   hash
	TopicAllDevice = "topic:%s:all" // 已经订阅过该topic的所有设备

)

Variables

View Source
var (
	AllUdpClient = make(map[string]*UdpClient)
	UDPListener  *net.UDPConn
)
View Source
var AllTcpClient = make(map[string]*TcpClient)
View Source
var AllWsClient = make(map[string]*WsClient)
View Source
var GroupMap = make(map[string]*Group)
View Source
var TopicMap map[string]*Topic

Functions

func CmdDataMsg

func CmdDataMsg(str string) []byte

func GetTopicAllDevice

func GetTopicAllDevice(topicName string) []string

获取topic 被哪些设备订阅

func GetTopicHasDevice

func GetTopicHasDevice(topicName, device string) (bool, error)

查询topic是否被指定device订阅

func TopicDisconnection

func TopicDisconnection(topicName string)

topic断开所有device

Types

type AuthData

type AuthData struct {
	Device string `json:"device"`
}

type Client

type Client interface {
	SendMessage(str string)
	IntoAllClient(device string)
	GetWsConn() *WsClient
	GetTcpConn() *TcpClient
	GetUdpConn() *UdpClient
	Who() string
}

func NewClient

func NewClient(clientType string) Client

type CmdData

type CmdData struct {
	Cmd  string      `json:"cmd"`
	Data interface{} `json:"data"`
}

func (*CmdData) Byte

func (c *CmdData) Byte() []byte

type Device

type Device struct {
	ID string
}

func (*Device) AllTopic

func (d *Device) AllTopic() []string

func (*Device) CancelTopic

func (d *Device) CancelTopic(topicName string) (err error)

取消订阅

func (*Device) Discharge

func (d *Device) Discharge(connType string)

释放连接

func (*Device) GetGroup

func (d *Device) GetGroup(conn Client)

获取组

func (*Device) GetTopic

func (d *Device) GetTopic(conn Client)

获取订阅, 并加入连接

func (*Device) OffLine

func (d *Device) OffLine()

下线

func (*Device) OnLineState

func (d *Device) OnLineState() bool

func (*Device) SetId

func (d *Device) SetId(deviceId string) *Device

func (*Device) SubTopic

func (d *Device) SubTopic(conn Client, topicName string) (err error)

订阅

func (*Device) UpLine

func (d *Device) UpLine()

上线

type Group

type Group struct {
	Name      string                `json:"group_name"`
	ID        string                `json:"group_id"` // 是uuid
	WsClient  map[string]*WsClient  // deviceId : *WsClient
	TcpClient map[string]*TcpClient // deviceId :
	UdpClient map[string]*UdpClient
}

type TcpClient

type TcpClient struct {
	Conn net.Conn
	IP   string
}

func NewTcpClient

func NewTcpClient() *TcpClient

func (*TcpClient) AddConn

func (tcp *TcpClient) AddConn(conn net.Conn) *TcpClient

func (*TcpClient) GetTcpConn

func (tcp *TcpClient) GetTcpConn() *TcpClient

func (*TcpClient) GetUdpConn

func (tcp *TcpClient) GetUdpConn() *UdpClient

func (*TcpClient) GetWsConn

func (tcp *TcpClient) GetWsConn() *WsClient

func (*TcpClient) IntoAllClient

func (tcp *TcpClient) IntoAllClient(device string)

func (*TcpClient) Send

func (tcp *TcpClient) Send(msg CmdData)

func (*TcpClient) SendMessage

func (tcp *TcpClient) SendMessage(str string)

func (*TcpClient) SetIP

func (tcp *TcpClient) SetIP(ip string) *TcpClient

func (*TcpClient) TopicSend

func (tcp *TcpClient) TopicSend(data *mq.MQMsg)

func (*TcpClient) Who

func (tcp *TcpClient) Who() string

type Topic

type Topic struct {
	Name      string                `json:"topic_name"`
	ID        string                `json:"topic_id"` // 是uuid
	WsClient  map[string]*WsClient  // deviceId : *WsClient
	TcpClient map[string]*TcpClient // deviceId :
	UdpClient map[string]*UdpClient
}

func (*Topic) Send

func (t *Topic) Send(msg *mq.MQMsg)

type TopicData

type TopicData struct {
	TopicName string `json:"topic_name"`
	Message   string `json:"message"`
	SendTime  string `json:"send_time"`
}

type UdpClient

type UdpClient struct {
	Conn *net.UDPAddr
	IP   string
}

func NewUdpClient

func NewUdpClient() *UdpClient

func (*UdpClient) AddConn

func (udp *UdpClient) AddConn(conn *net.UDPAddr) *UdpClient

func (*UdpClient) GetTcpConn

func (udp *UdpClient) GetTcpConn() *TcpClient

func (*UdpClient) GetUdpConn

func (udp *UdpClient) GetUdpConn() *UdpClient

func (*UdpClient) GetWsConn

func (udp *UdpClient) GetWsConn() *WsClient

func (*UdpClient) IntoAllClient

func (udp *UdpClient) IntoAllClient(device string)

func (*UdpClient) Send

func (udp *UdpClient) Send(msg CmdData)

func (*UdpClient) SendMessage

func (udp *UdpClient) SendMessage(str string)

func (*UdpClient) SetIP

func (udp *UdpClient) SetIP(ip string) *UdpClient

func (*UdpClient) TopicSend

func (udp *UdpClient) TopicSend(data *mq.MQMsg)

func (*UdpClient) Who

func (udp *UdpClient) Who() string

type WsClient

type WsClient struct {
	Conn *websocket.Conn
	IP   string
}

func NewWsClient

func NewWsClient() *WsClient

func (*WsClient) AddConn

func (ws *WsClient) AddConn(conn *websocket.Conn) *WsClient

func (*WsClient) GetTcpConn

func (ws *WsClient) GetTcpConn() *TcpClient

func (*WsClient) GetUdpConn

func (ws *WsClient) GetUdpConn() *UdpClient

func (*WsClient) GetWsConn

func (ws *WsClient) GetWsConn() *WsClient

func (*WsClient) IntoAllClient

func (ws *WsClient) IntoAllClient(device string)

func (*WsClient) Send

func (ws *WsClient) Send(msg CmdData)

func (*WsClient) SendMessage

func (ws *WsClient) SendMessage(str string)

func (*WsClient) SetIP

func (ws *WsClient) SetIP(ip string) *WsClient

func (*WsClient) TopicSend

func (ws *WsClient) TopicSend(data *mq.MQMsg)

func (*WsClient) Who

func (ws *WsClient) Who() string

Jump to

Keyboard shortcuts

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