forked from hootrhino/rulex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package core | ||
|
||
import "github.com/i4de/rulex/typex" | ||
|
||
type deviceTypeManager struct { | ||
// K: 资源类型 | ||
// V: 伪构造函数 | ||
registry map[typex.DeviceType]*typex.XConfig | ||
} | ||
|
||
func NewDeviceTypeManager() typex.DeviceRegistry { | ||
return &deviceTypeManager{ | ||
registry: map[typex.DeviceType]*typex.XConfig{}, | ||
} | ||
|
||
} | ||
func (rm *deviceTypeManager) Register(name typex.DeviceType, f *typex.XConfig) { | ||
rm.registry[name] = f | ||
} | ||
|
||
func (rm *deviceTypeManager) Find(name typex.DeviceType) *typex.XConfig { | ||
|
||
return rm.registry[name] | ||
} | ||
func (rm *deviceTypeManager) All() []*typex.XConfig { | ||
data := make([]*typex.XConfig, 0) | ||
for _, v := range rm.registry { | ||
data = append(data, v) | ||
} | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package device | ||
|
||
import ( | ||
"github.com/i4de/rulex/common" | ||
"github.com/i4de/rulex/core" | ||
"github.com/i4de/rulex/typex" | ||
) | ||
|
||
var DM typex.DeviceRegistry | ||
|
||
/* | ||
* | ||
* 加载系统内支持的设备类型 | ||
* | ||
*/ | ||
func LoadDt() { | ||
DM = core.NewDeviceTypeManager() | ||
DM.Register(typex.TSS200V02, core.GenInConfig(typex.COAP, "About TSS200V02", common.ModBusConfig{})) | ||
DM.Register(typex.RTU485_THER, core.GenInConfig(typex.COAP, "About RTU485_THER", common.ModBusConfig{})) | ||
DM.Register(typex.YK08_RELAY, core.GenInConfig(typex.COAP, "About YK08_RELAY", common.ModBusConfig{})) | ||
DM.Register(typex.S1200PLC, core.GenInConfig(typex.COAP, "About S1200PLC", common.ModBusConfig{})) | ||
DM.Register(typex.GENERIC_MODBUS, core.GenInConfig(typex.COAP, "About GENERIC_MODBUS", common.ModBusConfig{})) | ||
DM.Register(typex.GENERIC_UART, core.GenInConfig(typex.COAP, "About GENERIC_UART", common.GenericUartConfig{})) | ||
DM.Register(typex.GENERIC_SNMP, core.GenInConfig(typex.COAP, "About GENERIC_SNMP", common.GenericSnmpConfig{})) | ||
DM.Register(typex.USER_G776, core.GenInConfig(typex.COAP, "About USER_G776", common.ModBusConfig{})) | ||
DM.Register(typex.ICMP_SENDER, core.GenInConfig(typex.COAP, "About ICMP_SENDER", common.HostConfig{})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package typex | ||
|
||
type DeviceRegistry interface { | ||
Register(DeviceType, *XConfig) | ||
Find(DeviceType) *XConfig | ||
All() []*XConfig | ||
} |