|
@@ -4,7 +4,6 @@ package main
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
- "github.com/sirupsen/logrus"
|
|
|
|
|
"lc/common/mqtt"
|
|
"lc/common/mqtt"
|
|
|
"lc/common/protocol"
|
|
"lc/common/protocol"
|
|
|
"lc/common/util"
|
|
"lc/common/util"
|
|
@@ -79,14 +78,12 @@ func (l *LedDevice) Handle() {
|
|
|
for {
|
|
for {
|
|
|
select {
|
|
select {
|
|
|
case <-l.ctx.Done():
|
|
case <-l.ctx.Done():
|
|
|
- logrus.Errorf("设备[%s]的LedDevice.Handle退出,原因:%v", l.LedInfo.SN, l.ctx.Err())
|
|
|
|
|
return
|
|
return
|
|
|
case <-timer.C: //心跳,检查在线状态, 每隔1分钟执行一次
|
|
case <-timer.C: //心跳,检查在线状态, 每隔1分钟执行一次
|
|
|
url := l.GetCltUrl(clt_client.POWERS_TATUS)
|
|
url := l.GetCltUrl(clt_client.POWERS_TATUS)
|
|
|
_, err := clt_client.GetClient().CommonGet(url)
|
|
_, err := clt_client.GetClient().CommonGet(url)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
l.CheckOnline(l, uint8(1))
|
|
l.CheckOnline(l, uint8(1))
|
|
|
- logrus.Errorf(" error: %v", err)
|
|
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
l.CheckOnline(l, uint8(0))
|
|
l.CheckOnline(l, uint8(0))
|
|
@@ -97,8 +94,6 @@ func (l *LedDevice) Handle() {
|
|
|
action := strings.Split(mm.Topic(), "/")[4]
|
|
action := strings.Split(mm.Topic(), "/")[4]
|
|
|
if fn, ok := l.mapTopicHandle[action]; ok {
|
|
if fn, ok := l.mapTopicHandle[action]; ok {
|
|
|
fn(mm)
|
|
fn(mm)
|
|
|
- } else {
|
|
|
|
|
- logrus.Errorf("LcDevice.Handle:不支持的主题:%s", mm.Topic())
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -108,7 +103,7 @@ func (l *LedDevice) Handle() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (o *LedDevice) CheckOnline(dev *LedDevice, online uint8) {
|
|
|
|
|
|
|
+func (l *LedDevice) CheckOnline(dev *LedDevice, online uint8) {
|
|
|
var obj protocol.Pack_LedState
|
|
var obj protocol.Pack_LedState
|
|
|
if str, err := obj.EnCode(dev.SN, appConfig.GID, GetNextUint64(), util.MlNow(), online); err == nil {
|
|
if str, err := obj.EnCode(dev.SN, appConfig.GID, GetNextUint64(), util.MlNow(), online); err == nil {
|
|
|
topic := appConfig.Tenant + "/cltled/" + dev.SN + "/up/" + protocol.TP_LED_STATE + "/" + strconv.Itoa(int(GetNextUint64()))
|
|
topic := appConfig.Tenant + "/cltled/" + dev.SN + "/up/" + protocol.TP_LED_STATE + "/" + strconv.Itoa(int(GetNextUint64()))
|
|
@@ -118,26 +113,26 @@ func (o *LedDevice) CheckOnline(dev *LedDevice, online uint8) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// LedData 上报信息屏详细信息
|
|
// LedData 上报信息屏详细信息
|
|
|
-func (o *LedDevice) LedData(dev *LedDevice) {
|
|
|
|
|
|
|
+func (l *LedDevice) LedData(dev *LedDevice) {
|
|
|
var data protocol.CltledData
|
|
var data protocol.CltledData
|
|
|
//电源状态
|
|
//电源状态
|
|
|
- res, _ := clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.POWERS_TATUS))
|
|
|
|
|
|
|
+ res, _ := clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.POWERS_TATUS))
|
|
|
json.Unmarshal(res, &data)
|
|
json.Unmarshal(res, &data)
|
|
|
//音量
|
|
//音量
|
|
|
- res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.GET_VOLUME))
|
|
|
|
|
|
|
+ res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.GET_VOLUME))
|
|
|
json.Unmarshal(res, &data)
|
|
json.Unmarshal(res, &data)
|
|
|
//亮度色温
|
|
//亮度色温
|
|
|
- res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.GET_BRIGHTCOLOR))
|
|
|
|
|
|
|
+ res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.GET_BRIGHTCOLOR))
|
|
|
json.Unmarshal(res, &data)
|
|
json.Unmarshal(res, &data)
|
|
|
//开关机时间
|
|
//开关机时间
|
|
|
- res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.GET_SCHEDULE))
|
|
|
|
|
|
|
+ res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.GET_SCHEDULE))
|
|
|
json.Unmarshal(res, &data)
|
|
json.Unmarshal(res, &data)
|
|
|
//分辨率
|
|
//分辨率
|
|
|
- res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.RESOLUTION))
|
|
|
|
|
|
|
+ res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.RESOLUTION))
|
|
|
json.Unmarshal(res, &data)
|
|
json.Unmarshal(res, &data)
|
|
|
|
|
|
|
|
//当前节目
|
|
//当前节目
|
|
|
- res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.LIST_PROGRAMS))
|
|
|
|
|
|
|
+ res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.LIST_PROGRAMS))
|
|
|
resMap := make(map[string]map[string]interface{})
|
|
resMap := make(map[string]map[string]interface{})
|
|
|
json.Unmarshal(res, &resMap)
|
|
json.Unmarshal(res, &resMap)
|
|
|
payingName, ok := resMap["playing"]["name"]
|
|
payingName, ok := resMap["playing"]["name"]
|
|
@@ -166,13 +161,6 @@ func (l *LedDevice) PublishProgram(m mqtt.Message) {
|
|
|
clt_client.GetClient().PublishProgram(m, l.BaseURL)
|
|
clt_client.GetClient().PublishProgram(m, l.BaseURL)
|
|
|
//获取结果 并 响应云端
|
|
//获取结果 并 响应云端
|
|
|
l.ListPrograms(m)
|
|
l.ListPrograms(m)
|
|
|
- //发布成功
|
|
|
|
|
- //if resp.Playing.Name == pro.Name+".vsn" {
|
|
|
|
|
- // l.playing = resp.Playing.Name
|
|
|
|
|
- // logrus.Infof("%s发布成功!耗时:%v", pro.Name, (later - now))
|
|
|
|
|
- //} else {
|
|
|
|
|
- // logrus.Infof("%s发布失败!耗时:%v", pro.Name, (later - now))
|
|
|
|
|
- //}
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (l *LedDevice) SetSchedule(m mqtt.Message) {
|
|
func (l *LedDevice) SetSchedule(m mqtt.Message) {
|
|
@@ -188,11 +176,8 @@ func (l *LedDevice) ControlPower(m mqtt.Message) {
|
|
|
l.PowerStatus(m)
|
|
l.PowerStatus(m)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (l *LedDevice) DoCommonPost(url, funcname string, m mqtt.Message) {
|
|
|
|
|
- err := clt_client.GetClient().CommonPost(m.Payload(), url)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logrus.Errorf(funcname+" error: %v", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+func (l *LedDevice) DoCommonPost(url, funcName string, m mqtt.Message) {
|
|
|
|
|
+ clt_client.GetClient().CommonPost(m.Payload(), url)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//==========================GET==================================GET
|
|
//==========================GET==================================GET
|
|
@@ -246,11 +231,8 @@ func (l *LedDevice) SnapShot(m mqtt.Message) {
|
|
|
GetMQTTMgr().Publish(getUpTopic(m.Topic()), shot, mqtt.AtMostOnce, ToCloud)
|
|
GetMQTTMgr().Publish(getUpTopic(m.Topic()), shot, mqtt.AtMostOnce, ToCloud)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (l *LedDevice) DoCommonGet(url, funcname string, m mqtt.Message) {
|
|
|
|
|
- resp, err := clt_client.GetClient().CommonGet(url)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logrus.Errorf(funcname+" error: %v", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+func (l *LedDevice) DoCommonGet(url, funcName string, m mqtt.Message) {
|
|
|
|
|
+ resp, _ := clt_client.GetClient().CommonGet(url)
|
|
|
GetMQTTMgr().Publish(getUpTopic(m.Topic()), resp, mqtt.AtMostOnce, ToCloud)
|
|
GetMQTTMgr().Publish(getUpTopic(m.Topic()), resp, mqtt.AtMostOnce, ToCloud)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -265,20 +247,14 @@ func (l *LedDevice) SwitchProgram(m mqtt.Message) {
|
|
|
// SetBright 调节屏幕亮度
|
|
// SetBright 调节屏幕亮度
|
|
|
func (l *LedDevice) SetBright(m mqtt.Message) {
|
|
func (l *LedDevice) SetBright(m mqtt.Message) {
|
|
|
url := l.GetCltUrl(clt_client.SET_BRIGHT)
|
|
url := l.GetCltUrl(clt_client.SET_BRIGHT)
|
|
|
- err := clt_client.GetClient().CommonPut(m.Payload(), url)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logrus.Errorf("set bright error: %v", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ clt_client.GetClient().CommonPut(m.Payload(), url)
|
|
|
l.GetBrightColor(m)
|
|
l.GetBrightColor(m)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// SetVolume 设置音量
|
|
// SetVolume 设置音量
|
|
|
func (l *LedDevice) SetVolume(m mqtt.Message) {
|
|
func (l *LedDevice) SetVolume(m mqtt.Message) {
|
|
|
url := l.GetCltUrl(clt_client.SET_VOLUME)
|
|
url := l.GetCltUrl(clt_client.SET_VOLUME)
|
|
|
- err := clt_client.GetClient().CommonPut(m.Payload(), url)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logrus.Errorf("set volume error: %v", err)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ clt_client.GetClient().CommonPut(m.Payload(), url)
|
|
|
l.GetVolume(m)
|
|
l.GetVolume(m)
|
|
|
}
|
|
}
|
|
|
|
|
|