Posted 04 May 2013 - 08:43 PM
I am using FTB (Direwolf20 Pack) and We use rednet quite a bit for remote control of resource points. However I have noticed large amounts of CPU usage. This seems to me related to rednet. If I delete the computers folder (so nothing boots) cpu usage drops to next to nothing. Profiling the jar shows a lot of CPU time spent in dan200 classes.
The question is two fold. First, what can you recommend from a listener standpoint, to reduce CPU usage. The listeners all listen like so:
ryetoc.from string return true if string == "1" else returns false. Simple. The stringStarts is:
and ryetoc.split is: (this is something I found online)
Any help would be appreciated. I would like to keep the listeners listening to all rednet, and not just specific machines.
The question is two fold. First, what can you recommend from a listener standpoint, to reduce CPU usage. The listeners all listen like so:
function remoteControl()
while true do
--main listening for commands loop
event, senderId, message, distance = os.pullEvent("rednet_message")
if ryetoc.stringStarts(message, "CONTROL") then --filter out noise
values = ryetoc.split(message, "|")
if table.getn(values)== 3 then -- it's a control message
if values[2] == name then --it's for me
term.setCursorPos(1, 5)
ryetoc.setColor(colors.orange, colors.black)
print("Received Message...")
running = ryetoc.fromString(values[3])
end
end
end
end
end
ryetoc.from string return true if string == "1" else returns false. Simple. The stringStarts is:
function stringStarts(String , Start)
return string.sub(String,1,string.len(Start))==Start
end
and ryetoc.split is: (this is something I found online)
function split(string, divider)
local function find(string, match, startIndex)
if not match then return nil end
_ = startIndex or 1
local _s = nil
local _e = nil
_len = match:len()
while true do
_t = string:sub( _ , _len + _ - 1)
if _t == match then
_s = _
_e = _ + _len - 1
break
end
_ = _ + 1
if _ > string:len() then break end
end
if _s == nil then return nil else return _s, _e end
end
if not divider then return nil end
local start = {}
local endS = {}
local n=1
repeat
if n==1 then
start[n], endS[n] = find(string, divider)
else
start[n], endS[n] = find(string, divider, endS[n-1]+1)
end
n=n+1
until start[n-1]==nil
local subs = {}
for n=1, #start+1 do
if n==1 then
subs[n] = string:sub(1, start[n]-1)
elseif n==#start+1 then
subs[n] = string:sub(endS[n-1]+1)
else
subs[n] = string:sub(endS[n-1]+1, start[n]-1)
end
end
return subs
end
Any help would be appreciated. I would like to keep the listeners listening to all rednet, and not just specific machines.