From 65f896b2916dd1fbbb0086c8e40c03bf5f9e4e1b Mon Sep 17 00:00:00 2001 From: 20kdc Date: Thu, 23 Mar 2017 17:51:54 +0000 Subject: [PATCH] Store hostname of EEPROM light-nodes as the EEPROM label. --- oc/ecomponents/app-rsctrl | 4 ++-- oc/ecomponents/base | 6 ++++-- oc/uc-rsctl.lua | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/oc/ecomponents/app-rsctrl b/oc/ecomponents/app-rsctrl index 3e30aed..cc88d93 100644 --- a/oc/ecomponents/app-rsctrl +++ b/oc/ecomponents/app-rsctrl @@ -2,7 +2,7 @@ -- No warranty is provided, implied or otherwise. %-- EXAMPLE IoT Redstone Top Controller -- -UR=C.proxy(C.list("redstone")()) +UR=CG("redstone") function UT(p) US=p if#p>0then @@ -19,7 +19,7 @@ N={ [0]=UG, [1]=function(f)RS(f,4,"\xC1"..US)end, [0x41]=function(_,p)UT(p)end, - [0x82]=function(_,p)if#p>0then TH=p end end, + [0x82]=function(_,p)if#p>0then CG("eeprom").setLabel(p)TH=p end end, } function UI(f,t,p,d) local m=t==TH diff --git a/oc/ecomponents/base b/oc/ecomponents/base index 5ec1cd2..fed8307 100644 --- a/oc/ecomponents/base +++ b/oc/ecomponents/base @@ -14,13 +14,15 @@ -- C (short for 'component') -- Functions: +-- CG: Get Component -- TN: Decode Name -- TR: Receive Message handling (returns s/d/m rather than using a callback) -- TS: Send Message (notably, this has no 'from') -- TB: The TX.broadcast function -TH,S,C,TC="hostname",string,component,"copper" -TX=C.proxy(C.list("modem")()) +S,C,TC=string,component,"copper" +function CG(n)return C.proxy(C.list(n)())end +TH,TX=CG("eeprom").getLabel(),CG("modem") TX.open(4957) TB=TX.broadcast function TN(m) diff --git a/oc/uc-rsctl.lua b/oc/uc-rsctl.lua index e585290..36bc45a 100644 --- a/oc/uc-rsctl.lua +++ b/oc/uc-rsctl.lua @@ -1,5 +1,6 @@ -TH,S,C,TC="hostname",string,component,"copper" -TX=C.proxy(C.list("modem")())TX.open(4957)TB=TX.broadcast +S,C,TC=string,component,"copper" +function CG(n)return C.proxy(C.list(n)())end +TH,TX=CG("eeprom").getLabel(),CG("modem")TX.open(4957)TB=TX.broadcast function TN(m)if#m<2then return end local n=m:byte(1)+2return m:sub(2,n),m:sub(n+1)end function TR(m)local h,s,m,d=m:byte(),TN(m:sub(2))if s then @@ -52,7 +53,7 @@ TS(t,g..S.char(a,1)..d)x=RP(j,R4)end RN[t..g]=x end j()end -- EXAMPLE IoT Redstone Top Controller -- -UR=C.proxy(C.list("redstone")())function UT(p)US=p +UR=CG("redstone")function UT(p)US=p if#p>0then UR.setOutput(1,15)else UR.setOutput(1,0)end @@ -61,7 +62,7 @@ UT("")function UG(t)RS(t,4,"\xC0\x42active.\x81setName")end N={[0]=UG, [1]=function(f)RS(f,4,"\xC1"..US)end, [0x41]=function(_,p)UT(p)end, -[0x82]=function(_,p)if#p>0then TH=p end end, +[0x82]=function(_,p)if#p>0then CG("eeprom").setLabel(p)TH=p end end, } function UI(f,t,p,d)local m=t==TH if p==1 and(t=="*"or m)then