gosdk/device/device.go

43 lines
805 B
Go

package device
import mqtt "github.com/eclipse/paho.mqtt.golang"
var (
BrandUstone = "ustone"
BrandESP8266 = "esp8266"
BrandFushua = "fushua"
BrandZhiheng = "zhiheng"
BrandUsr = "usr"
BrandVzenith = "vzenith"
)
type Message struct {
MsgId string
MsgTime int64
MsgType string
Topic string
DeviceId string
Data map[string]interface{}
}
type Callback func(message *Message)
type Device interface {
KeepAlive() error
Operate(string) error
}
type Voice interface {
Device
Play(string) error
}
func NewVoice(brand, model, deviceId string, client mqtt.Client, callback Callback) Voice {
if brand == BrandZhiheng {
return NewZhihengVoice(deviceId, client, callback)
} else if brand == BrandFushua {
return NewFushuaVoice(deviceId, client, callback)
}
return nil
}