修改:1、修改Aliyun上报服务中处理采集事件
This commit is contained in:
parent
f35af4be92
commit
0f96911738
|
@ -7,8 +7,10 @@ import (
|
|||
"goAdapter/device/eventBus"
|
||||
"goAdapter/setting"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -299,7 +301,108 @@ func (r *ReportServiceParamAliyunTemplate) ProcessCollEvent(sub eventBus.Sub) {
|
|||
|
||||
for {
|
||||
msg := sub.Out().(device.CollectInterfaceEventTemplate)
|
||||
setting.Logger.Debugf("Aliyun collEvent ReceiveMsgTopic %v ReceiveMsgContent %v", msg.Topic, msg.Content)
|
||||
setting.Logger.Debugf("Aliyun collEvent ReceiveMsg %v", msg)
|
||||
switch msg.Topic {
|
||||
case "onLine":
|
||||
{
|
||||
|
||||
}
|
||||
case "offLine":
|
||||
{
|
||||
|
||||
}
|
||||
case "update":
|
||||
{
|
||||
nodeName := make([]string, 0)
|
||||
index := -1
|
||||
for k, v := range device.CollectInterfaceMap {
|
||||
if v.CollInterfaceName == msg.CollName {
|
||||
index = k
|
||||
}
|
||||
}
|
||||
if index == -1 {
|
||||
continue
|
||||
}
|
||||
nodeIndex := -1
|
||||
for k, v := range device.CollectInterfaceMap[index].DeviceNodeMap {
|
||||
if v.Name == msg.NodeName {
|
||||
nodeIndex = k
|
||||
}
|
||||
}
|
||||
if nodeIndex == -1 {
|
||||
continue
|
||||
}
|
||||
|
||||
reportStatus := false
|
||||
for _, v := range device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Properties {
|
||||
if v.Params.StepAlarm == true {
|
||||
valueCnt := len(v.Value)
|
||||
if valueCnt >= 2 { //阶跃报警必须是2个值
|
||||
if v.Type == device.PropertyTypeInt32 {
|
||||
pValueCur := v.Value[valueCnt-1].Value.(int32)
|
||||
pValuePre := v.Value[valueCnt-2].Value.(int32)
|
||||
step, _ := strconv.Atoi(v.Params.Step)
|
||||
if math.Abs(float64(pValueCur-pValuePre)) > float64(step) {
|
||||
reportStatus = true //满足报警条件,上报
|
||||
nodeName = append(nodeName, device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Name)
|
||||
}
|
||||
} else if v.Type == device.PropertyTypeUInt32 {
|
||||
pValueCur := v.Value[valueCnt-1].Value.(uint32)
|
||||
pValuePre := v.Value[valueCnt-2].Value.(uint32)
|
||||
step, _ := strconv.Atoi(v.Params.Step)
|
||||
if math.Abs(float64(pValueCur-pValuePre)) > float64(step) {
|
||||
reportStatus = true //满足报警条件,上报
|
||||
nodeName = append(nodeName, device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Name)
|
||||
}
|
||||
} else if v.Type == device.PropertyTypeDouble {
|
||||
pValueCur := v.Value[valueCnt-1].Value.(float64)
|
||||
pValuePre := v.Value[valueCnt-2].Value.(float64)
|
||||
step, _ := strconv.Atoi(v.Params.Step)
|
||||
if math.Abs(pValueCur-pValuePre) > float64(step) {
|
||||
reportStatus = true //满足报警条件,上报
|
||||
nodeName = append(nodeName, device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if v.Params.MinMaxAlarm == true {
|
||||
valueCnt := len(v.Value)
|
||||
if v.Type == device.PropertyTypeInt32 {
|
||||
pValueCur := v.Value[valueCnt-1].Value.(int32)
|
||||
min, _ := strconv.Atoi(v.Params.Min)
|
||||
max, _ := strconv.Atoi(v.Params.Max)
|
||||
if pValueCur < int32(min) || pValueCur > int32(max) {
|
||||
reportStatus = true //满足报警条件,上报
|
||||
nodeName = append(nodeName, device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Name)
|
||||
}
|
||||
} else if v.Type == device.PropertyTypeUInt32 {
|
||||
pValueCur := v.Value[valueCnt-1].Value.(uint32)
|
||||
min, _ := strconv.Atoi(v.Params.Min)
|
||||
max, _ := strconv.Atoi(v.Params.Max)
|
||||
if pValueCur < uint32(min) || pValueCur > uint32(max) {
|
||||
reportStatus = true //满足报警条件,上报
|
||||
nodeName = append(nodeName, device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Name)
|
||||
}
|
||||
} else if v.Type == device.PropertyTypeDouble {
|
||||
pValueCur := v.Value[valueCnt-1].Value.(float64)
|
||||
min, _ := strconv.Atoi(v.Params.Min)
|
||||
max, _ := strconv.Atoi(v.Params.Max)
|
||||
if pValueCur < float64(min) || pValueCur > float64(max) {
|
||||
reportStatus = true //满足报警条件,上报
|
||||
nodeName = append(nodeName, device.CollectInterfaceMap[index].DeviceNodeMap[nodeIndex].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if reportStatus == true {
|
||||
reportNodeProperty := MQTTAliyunReportPropertyTemplate{
|
||||
DeviceType: "node",
|
||||
DeviceName: nodeName,
|
||||
}
|
||||
r.ReportPropertyRequestFrameChan <- reportNodeProperty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue