修改:1、commManage中开启设备在线和离线上报

This commit is contained in:
pengwang 2021-07-01 17:43:24 +08:00
parent bda0bdb93f
commit 9439617806
2 changed files with 26 additions and 11 deletions

View File

@ -61,8 +61,8 @@ func (c *CommunicationManageTemplate) AnalysisRx() {
//阻塞读 //阻塞读
rxBufCnt = c.CollInterface.CommInterface.ReadData(rxBuf) rxBufCnt = c.CollInterface.CommInterface.ReadData(rxBuf)
if rxBufCnt > 0 { if rxBufCnt > 0 {
//setting.Logger.Debugf("curRxBufCnt %v,", rxBufCnt) //setting.Logger.Debugf("%s:curRxBufCnt %v", c.CollInterface.CollInterfaceName, rxBufCnt)
//setting.Logger.Debugf("CurRxBuf %X\n", rxBuf[:rxBufCnt]) //setting.Logger.Debugf("%s:CurRxBuf %X", c.CollInterface.CollInterfaceName, rxBuf[:rxBufCnt])
//rxTotalBufCnt += rxBufCnt //rxTotalBufCnt += rxBufCnt
//追加接收的数据到接收缓冲区 //追加接收的数据到接收缓冲区
@ -73,7 +73,7 @@ func (c *CommunicationManageTemplate) AnalysisRx() {
//清除本次接收数据 //清除本次接收数据
rxBufCnt = 0 rxBufCnt = 0
} }
time.Sleep(10 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} }
} }
@ -84,7 +84,7 @@ func (c *CommunicationManageTemplate) CommunicationStateMachine(cmd Communicatio
startT := time.Now() //计算当前时间 startT := time.Now() //计算当前时间
for _, v := range c.CollInterface.DeviceNodeMap { for _, v := range c.CollInterface.DeviceNodeMap {
if v.Name == cmd.DeviceName { if v.Name == cmd.DeviceName {
setting.Logger.Debugf("%v:name %v\n", c.CollInterface.CollInterfaceName, v.Name) setting.Logger.Debugf("%v:name %v", c.CollInterface.CollInterfaceName, v.Name)
step := 0 step := 0
for { for {
//--------------组包--------------------------- //--------------组包---------------------------
@ -106,7 +106,7 @@ func (c *CommunicationManageTemplate) CommunicationStateMachine(cmd Communicatio
} }
step++ step++
setting.Logger.Debugf("%v:txbuf %X\n", c.CollInterface.CollInterfaceName, txBuf) setting.Logger.Debugf("%v:txbuf %X", c.CollInterface.CollInterfaceName, txBuf)
CommunicationMessage := CommunicationMessageTemplate{ CommunicationMessage := CommunicationMessageTemplate{
CollName: c.CollInterface.CollInterfaceName, CollName: c.CollInterface.CollInterfaceName,
@ -164,6 +164,12 @@ func (c *CommunicationManageTemplate) CommunicationStateMachine(cmd Communicatio
if v.CurCommFailCnt >= c.CollInterface.OfflinePeriod { if v.CurCommFailCnt >= c.CollInterface.OfflinePeriod {
v.CurCommFailCnt = 0 v.CurCommFailCnt = 0
//设备从上线变成离线 //设备从上线变成离线
if v.CommStatus == "onLine" {
if len(c.CollInterface.OfflineReportChan) == 100 {
<-c.CollInterface.OfflineReportChan
}
c.CollInterface.OfflineReportChan <- v.Name
}
v.CommStatus = "offLine" v.CommStatus = "offLine"
} }
rxTotalBufCnt = 0 rxTotalBufCnt = 0
@ -191,6 +197,14 @@ func (c *CommunicationManageTemplate) CommunicationStateMachine(cmd Communicatio
c.CollInterface.CommMessage = append(c.CollInterface.CommMessage, CommunicationMessage) c.CollInterface.CommMessage = append(c.CollInterface.CommMessage, CommunicationMessage)
} }
//设备从离线变成上线
if v.CommStatus == "offLine" {
if len(c.CollInterface.OnlineReportChan) == 100 {
<-c.CollInterface.OnlineReportChan
}
c.CollInterface.OnlineReportChan <- v.Name
}
//防止Chan阻塞 //防止Chan阻塞
if len(c.CollInterface.PropertyReportChan) >= 100 { if len(c.CollInterface.PropertyReportChan) >= 100 {
<-c.CollInterface.PropertyReportChan <-c.CollInterface.PropertyReportChan
@ -333,7 +347,7 @@ func (c *CommunicationManageTemplate) CommunicationManagePoll() {
cmd.FunName = "GetDeviceRealVariables" cmd.FunName = "GetDeviceRealVariables"
c.CommunicationManageAddCommon(cmd) c.CommunicationManageAddCommon(cmd)
} }
setting.Logger.Debugf("commChanTotalLen %v\n", len(c.CommonRequestChan)) setting.Logger.Debugf("%s,commChanTotalLen %v", coll.CollInterfaceName, len(c.CommonRequestChan))
} }
} }
} }

View File

@ -63,7 +63,7 @@ func (d *DeviceNodeTemplate) NewVariables() []VariableTemplate {
for k, v := range DeviceNodeTypeMap.DeviceNodeType { for k, v := range DeviceNodeTypeMap.DeviceNodeType {
if d.Type == v.TemplateType { if d.Type == v.TemplateType {
//调用NewVariables //调用NewVariables
setting.Logger.Debugf("TemplateType %v", v.TemplateType) //setting.Logger.Debugf("TemplateType %v", v.TemplateType)
err := DeviceTypePluginMap[k].CallByParam(lua.P{ err := DeviceTypePluginMap[k].CallByParam(lua.P{
Fn: DeviceTypePluginMap[k].GetGlobal("NewVariables"), Fn: DeviceTypePluginMap[k].GetGlobal("NewVariables"),
NRet: 1, NRet: 1,
@ -76,6 +76,7 @@ func (d *DeviceNodeTemplate) NewVariables() []VariableTemplate {
//获取返回结果 //获取返回结果
ret := DeviceTypePluginMap[k].Get(-1) ret := DeviceTypePluginMap[k].Get(-1)
DeviceTypePluginMap[k].Pop(1) DeviceTypePluginMap[k].Pop(1)
//setting.Logger.Debugf("DeviceTypePluginMap Get,%v", ret)
LuaVariableMap := LuaVariableMapTemplate{} LuaVariableMap := LuaVariableMapTemplate{}
@ -141,10 +142,10 @@ func (d *DeviceNodeTemplate) GenerateGetRealVariables(sAddr string, step int) ([
for _, v := range LuaVariableMap.Variable { for _, v := range LuaVariableMap.Variable {
nBytes = append(nBytes, *v) nBytes = append(nBytes, *v)
} }
if LuaVariableMap.Status == "1" { if LuaVariableMap.Status == "0" {
con = true
} else {
con = false con = false
} else {
con = true
} }
} else { } else {
ok = true ok = true
@ -199,7 +200,7 @@ func (d *DeviceNodeTemplate) DeviceCustomCmd(sAddr string, cmdName string, cmdPa
ok := false ok := false
con := false //后续是否有报文 con := false //后续是否有报文
if LuaVariableMap.Status == "1" { if LuaVariableMap.Status == "0" {
con = false con = false
} else { } else {
con = true con = true