function helper:initialize(sys_api, conf, templates_ext, templates_dir, templates_node, devices_node)
end
function api:fetch(async)
end
function api:templates()
end
function api:devices()
end
local config = self._conf or {}
--[[
config.devs = config.devs or {
{ unit = 1, name = 'bms01', sn = 'xxx-xx-1', tpl = 'bms' },
{ unit = 2, name = 'bms02', sn = 'xxx-xx-2', tpl = 'bms2' }
}
]]--
--- 获取云配置
if not config.devs or config.cnf then
if not config.cnf then
config = 'CNF000000002.1' -- loading cloud configuration CNF000000002 version 1
else
config = config.cnf .. '.' .. config.ver
end
end
local helper = conf_helper:new(self._sys, config)
helper:fetch()
self._devs = {}
for _, v in ipairs(helper:devices()) do
-- initialize your devices
end
--- 获取配置
local conf = helper:config()
conf.channel_type = conf.channel_type or 'socket'
if conf.channel_type == 'socket' then
conf.opt = conf.opt or {
host = "127.0.0.1",
port = 1503,
nodelay = true
}
else
conf.opt = conf.opt or {
port = "/dev/ttymxc1",
baudrate = 115200
}
end
if conf.channel_type == 'socket' then
client = sm_client(socketchannel, conf.opt, modbus.apdu_tcp, 1)
tpl/
├── CNF000000001_1.cnf
├── TPL000000001_1.csv
├── tpl1.csv
└── tpl2.csv
{
"opt": {
"port": "/dev/ttymxc1",
"baudrate": 19200
},
"tpls": [{
"id": "TPL000000001",
"name": "tpl1",
"ver": 1
},
{
"id": "TPL000000001",
"name": "tpl2",
"ver": 1
}
],
"devs": [{
"addr": 991122334455,
"name": "s01",
"sn": "xxx-xx-xx-1",
"tpl": "tpl1"
},
{
"addr": 112233445566,
"name": "s02",
"sn": "xxx-xx-xx-2",
"tpl": "tpl2"
}
],
"loop_gap": 3000
}