summaryrefslogtreecommitdiff
path: root/main.lua
diff options
context:
space:
mode:
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index 103a18c..1df9730 100644
--- a/main.lua
+++ b/main.lua
@@ -1,6 +1,7 @@
local cqueues = require'cqueues'
local signal = require'cqueues.signal'
local class = require'r.class'
+local rtable = require'r.table'
local pprint = require'pprint'
local config = require'config'
@@ -57,6 +58,41 @@ function Wilson.add_channels_for(self, pylon)
pylon:add_channel(channel)
end end end end
+function Wilson.load_config(self, conf)
+ local pneed,phave = rtable.keydiff(conf.pylon, self.pylons)
+ if next(phave) then error"don't know how to remove pylons yet" end
+
+ for pname,p in pairs(conf.pylons) do if self.pylons[pname] then
+ for k,v in pairs(p) do if v ~= self.pylons[pname][k] then
+ error("different field "..k.." on "..pname) end end end end
+
+ -- loop thru buses, form list of channels we need to care about
+ -- don't know how to remove channels yet
+ -- then for pylons need to be constructed, pass them the list of channels to connect to
+ -- verify pylon names are valid here too
+ local ch4p = {} for k in pairs(conf.pylon) do ch4p[k] = {} end
+ for busname,b in pairs(conf.bus) do for i,item in ipairs(b) do
+ local pname,cid = item[1],item[2]
+ if not ch4p[pname] then error("no such pylon "..pname) end
+ table.insert(ch4p[pname], cid) end end
+
+ for pname,p in pairs(conf.pylon) do
+ p.name = pname
+ if self.pylons[pname] then
+ self.pylons[pname]:sync_channels(ch4p[pname])
+ else
+ local cls = assert(pylon_class[p.type], "no such pylon type "..p.type)
+ self.pylon[name] = cls(self, p, ch4p[pname])
+ end
+ end
+
+end
+
+
+
+
+
+-- find bus containing given channel
function Wilson._find_bus(self, channel)
for name, bus in pairs(self.busses) do
for _, q in ipairs(bus) do if q == channel then return bus end end