修改:修改设备接口参数配置模版
This commit is contained in:
parent
4957d0ab4f
commit
129cb6f80c
|
@ -0,0 +1 @@
|
||||||
|
goAdapter
|
|
@ -45,10 +45,22 @@ type DeviceInterfaceTemplate struct{
|
||||||
DeviceNodeTypeMap []string `json:"DeviceTypeMap"` //节点类型
|
DeviceNodeTypeMap []string `json:"DeviceTypeMap"` //节点类型
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceInterfaceManageTemplate struct{
|
//配置参数
|
||||||
InterfaceManage [MaxDeviceInterfaceManage]DeviceInterfaceTemplate
|
type DeviceInterfaceParamTemplate struct{
|
||||||
|
InterfaceID int `json:"InterfaceID"` //通信接口
|
||||||
|
PollPeriod int `json:"PollPeriod"` //采集周期
|
||||||
|
OfflinePeriod int `json:"OfflinePeriod"` //离线超时周期
|
||||||
|
DeviceNodeCnt int `json:"DeviceNodeCnt"` //设备数量
|
||||||
|
DeviceNodeAddrMap []string `json:"DeviceAddrMap"` //节点地址
|
||||||
|
DeviceNodeTypeMap []string `json:"DeviceTypeMap"` //节点类型
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//配置参数
|
||||||
|
type DeviceInterfaceParamMapTemplate struct {
|
||||||
|
DeviceInterfaceParam [MaxDeviceInterfaceManage]DeviceInterfaceParamTemplate
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MaxDeviceInterfaceManage int = 2
|
MaxDeviceInterfaceManage int = 2
|
||||||
|
|
||||||
|
@ -66,14 +78,14 @@ const (
|
||||||
|
|
||||||
|
|
||||||
var DeviceInterfaceMap [MaxDeviceInterfaceManage]*DeviceInterfaceTemplate
|
var DeviceInterfaceMap [MaxDeviceInterfaceManage]*DeviceInterfaceTemplate
|
||||||
var deviceInterfaceManage DeviceInterfaceManageTemplate
|
var DeviceInterfaceParamMap DeviceInterfaceParamMapTemplate
|
||||||
|
|
||||||
func DeviceNodeManageInit(){
|
func DeviceNodeManageInit(){
|
||||||
|
|
||||||
if ReadDeviceInterfaceManageFromJson() == true{
|
if ReadDeviceInterfaceManageFromJson() == true{
|
||||||
log.Println("read interface json ok")
|
log.Println("read interface json ok")
|
||||||
|
|
||||||
for k,v := range deviceInterfaceManage.InterfaceManage{
|
for k,v := range DeviceInterfaceParamMap.DeviceInterfaceParam{
|
||||||
|
|
||||||
//创建接口实例
|
//创建接口实例
|
||||||
DeviceInterfaceMap[k] = NewDeviceInterface(k,
|
DeviceInterfaceMap[k] = NewDeviceInterface(k,
|
||||||
|
@ -81,9 +93,8 @@ func DeviceNodeManageInit(){
|
||||||
v.OfflinePeriod,
|
v.OfflinePeriod,
|
||||||
v.DeviceNodeCnt)
|
v.DeviceNodeCnt)
|
||||||
|
|
||||||
//DeviceInterfaceMap[k].DeviceNodeMap = make([]DeviceNodeInterface,0)
|
DeviceInterfaceMap[k].DeviceNodeAddrMap = v.DeviceNodeAddrMap
|
||||||
//DeviceInterfaceMap[k].DeviceNodeAddrMap = make([]string,0)
|
DeviceInterfaceMap[k].DeviceNodeTypeMap = v.DeviceNodeTypeMap
|
||||||
//DeviceInterfaceMap[k].DeviceNodeTypeMap = make([]string,0)
|
|
||||||
|
|
||||||
//创建设备实例
|
//创建设备实例
|
||||||
for i:=0;i<v.DeviceNodeCnt;i++{
|
for i:=0;i<v.DeviceNodeCnt;i++{
|
||||||
|
@ -99,10 +110,6 @@ func DeviceNodeManageInit(){
|
||||||
60,
|
60,
|
||||||
180,
|
180,
|
||||||
0)
|
0)
|
||||||
|
|
||||||
//DeviceInterfaceMap[i].DeviceNodeMap = make([]DeviceNodeInterface,0)
|
|
||||||
//DeviceInterfaceMap[i].DeviceNodeAddrMap = make([]string,0)
|
|
||||||
//DeviceInterfaceMap[i].DeviceNodeTypeMap = make([]string,0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,12 +167,17 @@ func WriteDeviceInterfaceManageToJson(){
|
||||||
defer fp.Close()
|
defer fp.Close()
|
||||||
|
|
||||||
for k,v := range DeviceInterfaceMap{
|
for k,v := range DeviceInterfaceMap{
|
||||||
|
DeviceInterfaceParamMap.DeviceInterfaceParam[k].InterfaceID = v.InterfaceID
|
||||||
|
DeviceInterfaceParamMap.DeviceInterfaceParam[k].PollPeriod = v.PollPeriod
|
||||||
|
DeviceInterfaceParamMap.DeviceInterfaceParam[k].OfflinePeriod = v.OfflinePeriod
|
||||||
|
DeviceInterfaceParamMap.DeviceInterfaceParam[k].DeviceNodeCnt = v.DeviceNodeCnt
|
||||||
|
DeviceInterfaceParamMap.DeviceInterfaceParam[k].DeviceNodeAddrMap = v.DeviceNodeAddrMap
|
||||||
|
DeviceInterfaceParamMap.DeviceInterfaceParam[k].DeviceNodeTypeMap = v.DeviceNodeTypeMap
|
||||||
|
|
||||||
|
|
||||||
deviceInterfaceManage.InterfaceManage[k] = *v
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sJson,_ := json.Marshal(DeviceInterfaceParamMap)
|
||||||
sJson,_ := json.Marshal(deviceInterfaceManage)
|
|
||||||
|
|
||||||
_, err = fp.Write(sJson)
|
_, err = fp.Write(sJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -189,14 +201,14 @@ func ReadDeviceInterfaceManageFromJson() bool{
|
||||||
data := make([]byte, 20480)
|
data := make([]byte, 20480)
|
||||||
dataCnt, err := fp.Read(data)
|
dataCnt, err := fp.Read(data)
|
||||||
|
|
||||||
err = json.Unmarshal(data[:dataCnt],&deviceInterfaceManage)
|
err = json.Unmarshal(data[:dataCnt],&DeviceInterfaceParamMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("deviceNodeManage unmarshal err", err)
|
log.Println("deviceNodeManage unmarshal err", err)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("%+v\n",deviceInterfaceManage)
|
log.Printf("%+v\n",DeviceInterfaceParamMap)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}else{
|
}else{
|
||||||
|
|
18
main.go
18
main.go
|
@ -75,12 +75,12 @@ func main(){
|
||||||
/**************httpserver初始化****************/
|
/**************httpserver初始化****************/
|
||||||
// 默认启动方式,包含 Logger、Recovery 中间件
|
// 默认启动方式,包含 Logger、Recovery 中间件
|
||||||
|
|
||||||
serverCommon := &http.Server{
|
//serverCommon := &http.Server{
|
||||||
Addr: ":8091",
|
// Addr: ":8091",
|
||||||
Handler: routerCommon(),
|
// Handler: routerCommon(),
|
||||||
ReadTimeout: 5 * time.Second,
|
// ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 10 * time.Second,
|
// WriteTimeout: 10 * time.Second,
|
||||||
}
|
//}
|
||||||
|
|
||||||
serverWeb := &http.Server{
|
serverWeb := &http.Server{
|
||||||
Addr: ":8090",
|
Addr: ":8090",
|
||||||
|
@ -89,9 +89,9 @@ func main(){
|
||||||
WriteTimeout: 10 * time.Second,
|
WriteTimeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
g.Go(func() error {
|
//g.Go(func() error {
|
||||||
return serverCommon.ListenAndServe()
|
// return serverCommon.ListenAndServe()
|
||||||
})
|
//})
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return serverWeb.ListenAndServe()
|
return serverWeb.ListenAndServe()
|
||||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
||||||
{"InterfaceManage":[{"InterfaceID":0,"PollPeriod":60,"OfflinePeriod":180,"DeviceNodeCnt":2,"DeviceNodeMap":[{"Index":0,"Addr":"2","Type":"modbus2","LastCommRTC":"","CommTotalCnt":0,"CommSuccessCnt":0,"CommStatus":"","TemplateName":"","TemplateType":"","TemplateID":"","TemplateMessage":""},{"Index":0,"Addr":"1","Type":"modbus","LastCommRTC":"","CommTotalCnt":0,"CommSuccessCnt":0,"CommStatus":"","TemplateName":"","TemplateType":"","TemplateID":"","TemplateMessage":""}],"DeviceAddrMap":["2","1"],"DeviceTypeMap":["modbus2","modbus"]},{"InterfaceID":1,"PollPeriod":60,"OfflinePeriod":180,"DeviceNodeCnt":0,"DeviceNodeMap":[],"DeviceAddrMap":[],"DeviceTypeMap":[]}]}
|
{"DeviceInterfaceParam":[{"InterfaceID":0,"PollPeriod":60,"OfflinePeriod":180,"DeviceNodeCnt":1,"DeviceAddrMap":["1"],"DeviceTypeMap":["modbus"]},{"InterfaceID":1,"PollPeriod":60,"OfflinePeriod":180,"DeviceNodeCnt":0,"DeviceAddrMap":[],"DeviceTypeMap":[]}]}
|
Loading…
Reference in New Issue