11.05.2018, 13:08
here is the Artnet integration script:
Code:
require("socket")
artnet_id = "Art-net" .. string.char(0) --8 byte
op_codes = {
ARTNET_POLL = 0x2000,
ARTNET_REPLY = 0x2100,
ARTNET_DMX = 0x5000,
ARTNET_ADDRESS = 0x6000,
ARTNET_INPUT = 0x7000,
ARTNET_TODREQUEST = 0x8000,
ARTNET_TODDATA = 0x8100,
ARTNET_TODCONTROL = 0x8200,
ARTNET_RDM = 0x8300,
ARTNET_VIDEOSTEUP = 0xa010,
ARTNET_VIDEOPALETTE = 0xa020,
ARTNET_VIDEODATA = 0xa040,
ARTNET_MACMASTER = 0xf000,
ARTNET_MACSLAVE = 0xf100,
ARTNET_FIRMWAREMASTER = 0xf200,
ARTNET_FIRMWAREREPLY = 0xf300,
ARTNET_IPPROG = 0xf800,
ARTNET_IPREPLY = 0xf900,
ARTNET_MEDIA = 0x9000,
ARTNET_MEDIAPATCH = 0x9200,
ARTNET_MEDIACONTROLREPLY = 0x9300
}
protocol_version = {
high = 0,
low = 14
}
priority_codes = {
DpLow = 0x10,
DpMed = 0x40,
DpHigh = 0x80,
DpCritical = 0xE0,
DpVolatile = 0xF0
}
function op_code(name)
local code = op_codes[name]
local low = bit.band(code, 0x00FF)
local high = bit.rshift(code, 8)
return low, high
end
function artnet_poll(address, port, talk_to_me, priority)
local command = {}
local opCodeLow, opCodeHigh = op_code("ARTNET_POLL")
table.insert(command, opCodeLow)
table.insert(command, opCodeHigh)
table.insert(command, protocol_version.low)
table.insert(command, protocol_version.high)
table.insert(command, talk_to_me)
table.insert(command, priority_codes[priority])
command = artnet_id .. string.char(unpack(command))
local s = socket.udp()
s:sendto(command, address, port)
s:close()
end
function artnet_dmx(address, port, sequence, in_port_physical, in_port_address, data)
local command = {}
local opCodeLow, opCodeHigh = op_code("ARTNET_DMX")
table.insert(command, opCodeLow)
table.insert(command, opCodeHigh)
table.insert(command, protocol_version.low)
table.insert(command, protocol_version.high)
--[[
The sequence number is used to ensure that ArtDmx packets are used in the correct order.
When Art-Net is carried over a medium such as the Internet, it is possible that ArtDmx packets will reach the receiver out of order.
This field is incremented in the range 0x01 to 0xff to allow the receiving node to resequence packets.
The Sequence field is set to 0x00 to disable this feature
]]
sequence = bit.band(sequence, 0xFF)
table.insert(command, sequence)
--[[
The physical input port from which DMX512 data was input.
This field is for information only. Use Universe for data routing.
]]
table.insert(command, in_port_physical)
--15 bit Port-Address (universe)
local address_hi = bit.rshift(in_port_address, 8)
local address_low = bit.band(in_port_address, 0x00FF)
table.insert(command, address_hi)
table.insert(command, address_low)
--Length
local l = #data --2 byte
local LengthHi = bit.rshift(l, 8)
local LengthLow = bit.band(l, 0x00FF)
table.insert(command, LengthHi)
table.insert(command, LengthLow)
command = artnet_id .. string.char(unpack(command)) .. string.char(unpack(data))
local s = socket.udp()
s:sendto(command, address, port)
s:close()
end
artnet_dmx(ip, port, 0, 0x12, 0x93, {0xA, 0x12, 0xFF})