diff --git a/README.md b/README.md index 3022c05..58c18c0 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,28 @@ local message = osc.new_message { osc:send(message) ``` +## Command line utilities + +`losc` provides two command line tools, `loscsend`/`loscrecv` that can be used +to send and receive OSC data via UDP. + +Note that both tools requires [`lua-socket`](https://luarocks.org/modules/luasocket/luasocket). + +```shell +loscsend - Send an OSC message via UDP. + +usage: loscsend ip port address [types [args]] +supported types: b, d, f, h, i, s, t +example: loscsend localhost 57120 /test ifs 1 2.3 "hi" +``` + +```shell +loscrecv - Dump incoming OSC data. + +usage: loscsend port +example: loscrecv 9000 +``` + ## API The API is divided into two parts: diff --git a/bin/loscrecv b/bin/loscrecv index c9c9fec..6c274c3 100755 --- a/bin/loscrecv +++ b/bin/loscrecv @@ -34,12 +34,30 @@ local osc = losc.new {plugin = plugin.new()} osc:add_handler('*', function(data) local tt = Timetag.new_from_timestamp(data.timestamp) - local time = string.format('%04x.%04x', tt:seconds(), tt:fractions()) + local time = string.format('%08x.%08x', tt:seconds(), tt:fractions()) + local ok, message = pcall(osc.new_message, data.message) + if not ok then + print(message) + return + end io.write(time .. ' ') - io.write(data.message.address .. ' ') - io.write(data.message.types .. ' ') - for _, a in ipairs(data.message) do - io.write(tostring(a) .. ' ') + io.write(message:address() .. ' ') + io.write(message:types() .. ' ') + for i, type_, arg_ in message:iter() do + if type_ == 's' then + io.write(string.format('"%s" ', arg_)) + elseif type_ == 'b' then + io.write(string.format('[%d byte blob] ', #arg_)) + elseif type_ == 'f' or type_ == 'd' then + io.write(string.format('%06f ', arg_)) + elseif type_ == 'i' or type_ 'h' then + io.write(string.format('%d ', arg_)) + elseif type_ == 't' then + local tmp = Timetag.new_from_timestamp(arg_) + string.format('%08x.%08x', tmp:seconds(), tmp:fractions()) + else + io.write(tostring(arg_) .. ' ') + end end io.write('\n') end) diff --git a/src/losc/init.lua b/src/losc/init.lua index abfd687..bd77ec5 100644 --- a/src/losc/init.lua +++ b/src/losc/init.lua @@ -39,7 +39,7 @@ local Timetag = require(relpath .. '.timetag') local Pattern = require(relpath .. '.pattern') local losc = { - _VERSION = 'losc v1.0.0', + _VERSION = 'losc v1.0.1', _URL = 'https://github.com/davidgranstrom/losc', _DESCRIPTION = 'Open Sound Control (OSC) library for lua/luajit.', _LICENSE = [[ diff --git a/src/losc/plugins/udp-libuv.lua b/src/losc/plugins/udp-libuv.lua index 40d46cc..2acf15c 100644 --- a/src/losc/plugins/udp-libuv.lua +++ b/src/losc/plugins/udp-libuv.lua @@ -128,7 +128,7 @@ function M:send(packet, address, port) address = address or self.options.sendAddr port = port or self.options.sendPort packet = assert(Packet.pack(packet)) - self.handle:udp_try_send(packet, address, port) + self.handle:try_send(packet, address, port) end return M