Merge branch 'develop' into mqtt

This commit is contained in:
pengwang 2020-08-13 21:59:03 +08:00
commit a80973902c
5 changed files with 21 additions and 3 deletions

View File

@ -3,4 +3,4 @@ AppMode = debug
HttpPort = :8080 HttpPort = :8080
[serial] [serial]
Name = /dev/tty.usbserial-1410,/dev/ttyS1 Name = /dev/tty.usbserial-1410,/dev/ttyS1,/dev/tty.SLAB_USBtoUART

View File

@ -159,7 +159,7 @@ func (c *CommunicationManageTemplate)CommunicationManageDel() {
//--------------组包--------------------------- //--------------组包---------------------------
txBuf,ok := v.GenerateGetRealVariables(v.Addr,step) txBuf,ok := v.GenerateGetRealVariables(v.Addr,step)
if ok == false{ if ok == false{
//log.Printf("getVariables false\n") log.Printf("getVariables finish\n")
goto LoopCommon goto LoopCommon
} }
step++ step++
@ -238,6 +238,12 @@ func (c *CommunicationManageTemplate)CommunicationManageDel() {
LoopCommon: LoopCommon:
} }
} }
c.DeviceNodeOnlineCnt = 0
for _,v := range c.DeviceNodeMap{
if v.CommStatus == "onLine"{
c.DeviceNodeOnlineCnt++
}
}
} }
} }
} }

View File

@ -84,6 +84,11 @@ func (c *CommunicationSerialTemplate)WriteData(data []byte) int{
log.Printf("len is %d\n",len(data)) log.Printf("len is %d\n",len(data))
//log.Printf("c %+v\n",c) //log.Printf("c %+v\n",c)
if c.Port == nil{
log.Println("serial writeData err")
return 0
}
cnt,err := c.Port.Write(data) cnt,err := c.Port.Write(data)
if err != nil{ if err != nil{
log.Println(err) log.Println(err)
@ -94,6 +99,10 @@ func (c *CommunicationSerialTemplate)WriteData(data []byte) int{
func (c *CommunicationSerialTemplate)ReadData(data []byte) int{ func (c *CommunicationSerialTemplate)ReadData(data []byte) int{
if c.Port == nil{
return 0
}
cnt,_ := c.Port.Read(data) cnt,_ := c.Port.Read(data)
return cnt return cnt

View File

@ -570,6 +570,7 @@ func apiGetNodeVariableFromCache(context *gin.Context) {
Name string `json:"name"` //变量名 Name string `json:"name"` //变量名
Lable string `json:"lable"` //变量标签 Lable string `json:"lable"` //变量标签
Value interface{} `json:"value"` //变量值 Value interface{} `json:"value"` //变量值
Explain interface{} `json:"explain"`
TimeStamp string `json:"timestamp"` //变量时间戳 TimeStamp string `json:"timestamp"` //变量时间戳
Type string `json:"type"` //变量类型 Type string `json:"type"` //变量类型
} }
@ -601,9 +602,11 @@ func apiGetNodeVariableFromCache(context *gin.Context) {
if len(v.Value) > 0{ if len(v.Value) > 0{
index = len(v.Value)-1 index = len(v.Value)-1
variable.Value = v.Value[index].Value variable.Value = v.Value[index].Value
variable.Explain = v.Value[index].Explain
variable.TimeStamp = v.Value[index].TimeStamp variable.TimeStamp = v.Value[index].TimeStamp
}else{ }else{
variable.Value = "" variable.Value = ""
variable.Explain = ""
variable.TimeStamp = "" variable.TimeStamp = ""
} }
variable.Type = v.Type variable.Type = v.Type

View File

@ -63,7 +63,7 @@ func main() {
str := fmt.Sprintf("/%d */%d * * * ?",v.PollPeriod%60,v.PollPeriod/60) str := fmt.Sprintf("/%d */%d * * * ?",v.PollPeriod%60,v.PollPeriod/60)
log.Printf("str %+v\n",str) log.Printf("str %+v\n",str)
cronGetNetStatus.AddFunc("* */1 * * * *", CommunicationManage.CommunicationManagePoll) cronGetNetStatus.AddFunc("*/60 * * * * *", CommunicationManage.CommunicationManagePoll)
go CommunicationManage.CommunicationManageDel() go CommunicationManage.CommunicationManageDel()
} }