修改:1、支持在一个文件夹中放入其他lua文件,从而可以支持一些标准的lua文件库 2、修改deviceType关于con字段的判断问题

This commit is contained in:
pengwang 2021-06-01 11:10:23 +08:00
parent 45518397e6
commit 07479da7b9
3 changed files with 37 additions and 26 deletions

View File

@ -134,17 +134,17 @@ func (d *DeviceNodeTemplate) GenerateGetRealVariables(sAddr string, step int) ([
ok := false
con := false //后续是否有报文
if LuaVariableMap.Status == "0" {
con = false
} else {
con = true
}
nBytes := make([]byte, 0)
if len(LuaVariableMap.Variable) > 0 {
ok = true
for _, v := range LuaVariableMap.Variable {
nBytes = append(nBytes, *v)
}
if LuaVariableMap.Status == "1" {
con = true
} else {
con = false
}
} else {
ok = true
}
@ -198,7 +198,7 @@ func (d *DeviceNodeTemplate) DeviceCustomCmd(sAddr string, cmdName string, cmdPa
ok := false
con := false //后续是否有报文
if LuaVariableMap.Status == "0" {
if LuaVariableMap.Status == "1" {
con = false
} else {
con = true

View File

@ -92,7 +92,6 @@ func ReadDeviceNodeTypeMap() bool {
return false
}
for _, v := range fileInfoMap {
status := false
//文件夹
if v.IsDir() == true {
setting.Logger.Debugf("fileDirInfo %v", v.Name())
@ -102,8 +101,8 @@ func ReadDeviceNodeTypeMap() bool {
log.Println("readDir err,", err)
return false
}
for _, f := range fileMap {
setting.Logger.Debugf("fileName %v", f.Name())
fileFullName := fileDirName + "/" + f.Name()
if strings.Contains(f.Name(), ".json") {
fp, err := os.OpenFile(fileFullName, os.O_RDONLY, 0777)
@ -129,7 +128,14 @@ func ReadDeviceNodeTypeMap() bool {
nodeType.TemplateMessage = deviceTypeTemplate.TemplateMessage
DeviceNodeTypeMap.DeviceNodeType = append(DeviceNodeTypeMap.DeviceNodeType, nodeType)
setting.Logger.Debugf("DeviceNodeType %v", DeviceNodeTypeMap.DeviceNodeType)
} else if strings.Contains(f.Name(), ".lua") {
}
}
index := -1
for _, f := range fileMap {
setting.Logger.Debugf("fileName %v", f.Name())
fileFullName := fileDirName + "/" + f.Name()
if strings.Contains(f.Name(), ".lua") {
if strings.Contains(f.Name(), v.Name()) == true { //lua文件和设备模版名字一样
template, err := setting.LuaOpenFile(fileFullName)
if err != nil {
@ -138,27 +144,32 @@ func ReadDeviceNodeTypeMap() bool {
setting.Logger.Debugf("openPlug %s ok\n", f.Name())
}
for k, d := range DeviceNodeTypeMap.DeviceNodeType {
if d.TemplateType == v.Name() {
if d.TemplateType == d.TemplateType {
index = k
DeviceTypePluginMap[k] = template
DeviceTypePluginMap[k].SetGlobal("GetCRCModbus", DeviceTypePluginMap[k].NewFunction(setting.GetCRCModbus))
DeviceTypePluginMap[k].SetGlobal("CheckCRCModbus", DeviceTypePluginMap[k].NewFunction(setting.CheckCRCModbus))
}
}
status = true
} else {
if status == true {
for k, d := range DeviceNodeTypeMap.DeviceNodeType {
//setting.Logger.Debugf("type %v,name %v", d.TemplateType, v.Name())
if d.TemplateType == v.Name() {
err = DeviceTypePluginMap[k].DoFile(fileFullName)
if err != nil {
setting.Logger.Errorf("%s Lua DoFile err, %v", fileFullName, err)
return false
} else {
setting.Logger.Debugf("%s Lua DoFile ok", f.Name())
}
}
}
break
}
}
}
if index == -1 {
continue
}
for _, f := range fileMap {
setting.Logger.Debugf("fileName %v", f.Name())
fileFullName := fileDirName + "/" + f.Name()
if strings.Contains(f.Name(), ".lua") {
if strings.Contains(f.Name(), v.Name()) == false { //lua文件和设备模版名字不一样
err = DeviceTypePluginMap[index].DoFile(fileFullName)
if err != nil {
setting.Logger.Errorf("%s Lua DoFile err, %v", fileFullName, err)
return false
} else {
setting.Logger.Debugf("%s Lua DoFile ok", f.Name())
}
}
}

View File

@ -179,7 +179,7 @@ func RouterWeb() {
}
}
if err := router.Run(":9000"); err != nil {
if err := router.Run(":8080"); err != nil {
setting.Logger.Errorf("gin run err,%v", err)
}
}