module("irtxnode", package.seeall) require("xap.bsc") jeenode = require("xap.jeenode") Nodule = jeenode.Nodule class = require("pl.class") require("pl") class.IRTxNode(Nodule) -- create BSC endpoints function IRTxNode:build(...) Nodule.build(self, ...) self:add {key="IRTxdata", direction=bsc.OUTPUT, type=bsc.STREAM, cmdCB=function(e) self:irdataCmd(e) end} self:add {key="temp", direction=bsc.INPUT, type=bsc.STREAM} end function IRTxNode:irdataCmd(e) local protocol = tonumber(string.byte(e.text,1)) --split hexstring and convert to decimal local codebyte1 = tonumber(string.sub(e.text, 2, 3), 16) local codebyte2 = tonumber(string.sub(e.text, 4, 5), 16) local codebyte3 = tonumber(string.sub(e.text, 6, 7), 16) local codebyte4 = tonumber(string.sub(e.text, 8, 9), 16) self:sender(protocol..","..codebyte1..","..codebyte2..","..codebyte3..","..codebyte4) end function IRTxNode:process(data) --[[ -- From the irtxnode.pde Sketch struct { int temp :10; // temperature: -500..+500 (tenths) } payload; --]] local te = jeenode.bitslicer(data,-10) te = te / 10 -- Add the temperature offset if one has been supplied if self.cfg.toff then te = te + self.cfg.toff end -- The keys here must match the key values from the self:add{key=x} Nodule.process(self,{temp=te}) end