io.write("\n\n----------------------------------\n") io.write("RAPIDA Redirector v2.0:\n") listen_from = {} send_to = {} dofile("throne-server.ini") -- -------------------------------------- -- Example of "throne-server.ini" file: -- -------------------------------------- -- listen_from = {101, 205, 307} -- send_to[101] = {102, 203, 306, 307, 308} -- send_to[205] = {501, 503, 506} -- send_to[307] = {701} -- -------------------------------------- -- It determines next forwarding rules: -- 1.1 -> 1.2 2.3 3.6 3.7 3.8 -- 2.5 -> 5.1 5.3 5.6 -- 3.7 -> 7.1 -- -------------------------------------- -- Each number is (MODULE*100 + CHANNEL) -- MODULE is 1..31 -- CHANNEL is 1..8 -- -------------------------------------- io.write("Config (from -> to):\n") for i=1,table.getn(listen_from) do listen_channel = listen_from[i] % 100 listen_module = (listen_from[i] - listen_channel) / 100 io.write(" ", listen_module, ".", listen_channel, " ->") for j=1,table.getn(send_to[listen_from[i]]) do send_channel = send_to[listen_from[i]][j] % 100 send_module = (send_to[listen_from[i]][j] - send_channel) / 100 io.write(" ", send_module, ".", send_channel) end io.write("\n") end io.write("----------------------------------\n") io.flush() count = 1 while true do can_line = io.read() if can_line == nil then break end io.write(string.format("\n%d:\n", count), can_line, "\n") can_dump = {} i = 1 for w in string.gmatch(can_line, "[n%x]+") do can_dump[i] = w i = i + 1 end can_len = table.getn(can_dump) can_id = tonumber(can_dump[2],16) can_to = can_id % 32 can_from = ((can_id - can_to) / 32 ) % 32 can_data = "" for i=4,can_len do can_data = can_data .. can_dump[i] end io.write(" CAN_ID: MODULE ", can_from, " -> MODULE ", can_to, "\n") if can_len > 3 then can_byte0 = tonumber(can_dump[4],16) can_class = can_byte0 % 32 can_cmd = (can_byte0 - can_class) / 128 io.write(" BYTE 0: ", "CMD=", can_cmd, " CLASS=", can_class, "\n") end if can_to == 31 and can_len == 7 and can_cmd == 0 and can_class == 1 then can_byte1 = tonumber(can_dump[5],16) can_byte2 = tonumber(can_dump[6],16) can_byte3 = tonumber(can_dump[7],16) can_channel = can_byte1 % 8 + 1 can_framelen = ((can_byte1 - can_channel + 1) / 8 ) % 4 can_dali1 = tonumber(can_dump[6],16) can_dali2 = tonumber(can_dump[7],16) io.write(" BYTE 1: ", "CHANNEL=", can_channel, " FRAMELEN=", can_framelen, "\n DALI DATA: ", can_dali1, " ", can_dali2, "\n") -- Redirects only DARP commands if can_dali1 == 254 then has_listener = 0 for i=1,table.getn(listen_from) do listen_channel = listen_from[i] % 100 listen_module = (listen_from[i] - listen_channel) / 100 -- io.write(" ?? ", can_from, ".", can_channel, "==", listen_module, ".", listen_channel, "\n") if can_from == listen_module and can_channel == listen_channel then has_listener = 1 io.write(" HAS LISTENER FOR ", listen_module, ".", listen_channel, "\n FORWARD COMMAND TO:\n") for j=1,table.getn(send_to[listen_from[i]]) do send_channel = send_to[listen_from[i]][j] % 100 send_module = (send_to[listen_from[i]][j] - send_channel) / 100 send_id = 31 * 32 + send_module send_byte0 = 1 send_byte1 = 0 send_byte2 = 2 ^ (send_channel - 1) send_byte3 = can_dali1 send_byte4 = can_dali2 send_data = string.format("%03X#%02X%02X%02X%02X%02X", send_id, send_byte0, send_byte1, send_byte2, send_byte3, send_byte4) io.write(" -> ", send_module, ".", send_channel, " DATA: ", send_data, "\n") if send_module == listen_module and send_channel == listen_channel then io.write(" SAME module.channel, SKIPPED\n") else os.execute("cansend can0 "..send_data) io.write(" cansend can0 "..send_data) io.write(", Ok\n") end end end end if has_listener == 0 then io.write(" NO LISTENERS, SKIPPED\n") end else io.write(" COMMAND SKIPPED\n") end else io.write(" FRAME SKIPPED\n") end count = count + 1 io.flush() end