修改:1、设备节点类型需要从物模型中获取 2、去掉之前从lua脚本中获取变量的函数
This commit is contained in:
parent
e78632353c
commit
bbfdd2b16f
|
@ -151,7 +151,7 @@ func ReadCollectInterfaceManageFromJson() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
setting.Logger.Debugf("CollectInterfaceParamMap %+v\n", CollectInterfaceParamMap)
|
||||
setting.Logger.Debugf("CollectInterfaceParamMap %+v", CollectInterfaceParamMap)
|
||||
for k, v := range CollectInterfaceParamMap.CollectInterfaceParam {
|
||||
//创建接口实例
|
||||
CollectInterfaceMap = append(CollectInterfaceMap, NewCollectInterface(v.CollInterfaceName,
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yuin/gluamapper"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
|
@ -26,29 +24,10 @@ type DeviceNodeTypeMapStruct struct {
|
|||
DeviceNodeType []DeviceNodeTypeTemplate
|
||||
}
|
||||
|
||||
type DeviceNodeTypeLuaState struct {
|
||||
LuaState *lua.LState
|
||||
TypeName string
|
||||
CollName string
|
||||
}
|
||||
|
||||
type DeviceNodeTypeVariableTemplate struct {
|
||||
Index int
|
||||
Name string
|
||||
Label string
|
||||
Type string
|
||||
}
|
||||
|
||||
type DeviceNodeTypeVariableMapTemplate struct {
|
||||
TemplateType string
|
||||
Variable []DeviceNodeTypeVariableTemplate
|
||||
}
|
||||
|
||||
var DeviceNodeTypeMap = DeviceNodeTypeMapStruct{
|
||||
DeviceNodeType: make([]DeviceNodeTypeTemplate, 0),
|
||||
}
|
||||
var DeviceTypePluginMap = make(map[int]*lua.LState)
|
||||
var DeviceNodeTypeVariableMap = make([]DeviceNodeTypeVariableMapTemplate, 0)
|
||||
|
||||
func ReadDeviceNodeTypeMap() bool {
|
||||
|
||||
|
@ -151,63 +130,8 @@ func ReadDeviceNodeTypeMap() bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, f := range fileMap {
|
||||
if strings.Contains(f.Name(), ".lua") {
|
||||
if strings.Contains(f.Name(), v.Name()) == false { //lua文件和设备模版名字不一样
|
||||
//获取设备模板中的变量
|
||||
ReadDeviceNodeTypeVariableMap(v.Name(), DeviceTypePluginMap[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func ReadDeviceNodeTypeVariableMap(templateType string, l *lua.LState) {
|
||||
|
||||
type LuaVariableTemplate struct {
|
||||
Index int
|
||||
Name string
|
||||
Label string
|
||||
Type string
|
||||
}
|
||||
|
||||
type LuaVariableMapTemplate struct {
|
||||
Variable []*LuaVariableTemplate
|
||||
}
|
||||
|
||||
//调用NewVariables
|
||||
err := l.CallByParam(lua.P{
|
||||
Fn: l.GetGlobal("NewVariables"),
|
||||
NRet: 1,
|
||||
Protect: true,
|
||||
})
|
||||
if err != nil {
|
||||
setting.Logger.Warning("NewVariables err,", err)
|
||||
}
|
||||
|
||||
//获取返回结果
|
||||
ret := l.Get(-1)
|
||||
l.Pop(1)
|
||||
|
||||
LuaVariableMap := DeviceNodeTypeVariableMapTemplate{}
|
||||
|
||||
if err := gluamapper.Map(ret.(*lua.LTable), &LuaVariableMap); err != nil {
|
||||
setting.Logger.Warning("NewVariables gluamapper.Map err,", err)
|
||||
}
|
||||
|
||||
TypeVariableMap := DeviceNodeTypeVariableMapTemplate{}
|
||||
TypeVariableMap.TemplateType = templateType
|
||||
for _, v := range LuaVariableMap.Variable {
|
||||
variable := DeviceNodeTypeVariableTemplate{}
|
||||
variable.Index = v.Index
|
||||
variable.Name = v.Name
|
||||
variable.Label = v.Label
|
||||
variable.Type = v.Type
|
||||
TypeVariableMap.Variable = append(TypeVariableMap.Variable, variable)
|
||||
}
|
||||
DeviceNodeTypeVariableMap = append(DeviceNodeTypeVariableMap, TypeVariableMap)
|
||||
}
|
||||
|
|
|
@ -859,35 +859,6 @@ func apiGetTemplate(context *gin.Context) {
|
|||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiGetTemplateVariable(context *gin.Context) {
|
||||
|
||||
templateType := context.Query("TemplateType")
|
||||
|
||||
aParam := &struct {
|
||||
Code string
|
||||
Message string
|
||||
Data device.DeviceNodeTypeVariableMapTemplate
|
||||
}{}
|
||||
|
||||
for _, v := range device.DeviceNodeTypeVariableMap {
|
||||
if v.TemplateType == templateType {
|
||||
aParam.Code = "0"
|
||||
aParam.Message = ""
|
||||
aParam.Data = v
|
||||
|
||||
sJson, _ := json.Marshal(aParam)
|
||||
context.String(http.StatusOK, string(sJson))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
aParam.Code = "1"
|
||||
aParam.Message = "TemplateType is not exist"
|
||||
aParam.Data = device.DeviceNodeTypeVariableMapTemplate{}
|
||||
sJson, _ := json.Marshal(aParam)
|
||||
context.String(http.StatusOK, string(sJson))
|
||||
}
|
||||
|
||||
func apiAddDeviceTSL(context *gin.Context) {
|
||||
|
||||
aParam := struct {
|
||||
|
|
|
@ -187,9 +187,6 @@ func RouterWeb() {
|
|||
//删除设备物模型服务
|
||||
deviceRouter.DELETE("/tsl/services", apiDeleteDeviceTSLServices)
|
||||
|
||||
//获取设备模板变量
|
||||
deviceRouter.GET("/templateVariable", apiGetTemplateVariable)
|
||||
|
||||
//获取通信接口
|
||||
deviceRouter.GET("/commInterface", apiGetCommInterface)
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue