On Thu, Jan 12, 2012 at 12:06 PM, Adrian Freed
Post by Adrian FreedHi,
What are the advantages of using SLIP OSC over a serial/virtual serial port when communicating with an embedded device rather than just sending out straight OSC formatted strings? Will the framing make it more effecient? Does it not simply add an unnecessary overhead?
The OSC encoding needs framing of some kind over streaming transports because it is packet oriented and intrinsically doesn't define its boundaries.
If you are using an error free transport (TCP) you can use the count prefix framing (as in OSC 1.0 spec.). We use SLIP for unreliable streaming protocols like USB serial and physical serial.
But SLIP doesn't add reliability, only framing, no? (SLIP doesn't
include any error checking, does it?) Of course OSC needs framing one
way or another. The advantages / disadvantages of SLIP vs. count
prefix seem to be:
- SLIP, pro: stateless, con: unknown buffer size needed for message
- count prefix, pro: known length ahead of time (allocation), con:
stateful, no standard for count representation
Anything else? On a microcontroller presumably the unknown buffer
size will not be a problem since the decoder will simply support a
maximum message size and reject the rest of the message when the
buffer fills up. The statefulness on the other hand is problematic
since a serial line receiver is more likely to "jump in" in the middle
of a stream, and with count prefix there is no way to know when the
packet begins. With TCP this is not a problem.
On the other hand a "serious" serial line implementation may use its
own lower-level packetization just to include error
checking/correction, making SLIP an unnecessary overhead.
That there is no standard for count representation is also an issue.
We have used a signed 32-bit integer in liblo TCP, (this should really
be unsigned I guess). But since OSC doesn't define a maximum message
size, theoretically the count prefix should be in some "big int"
expandable format. In practice of course 32-bit is more than enough,
and in fact wasteful in most cases.
One nice thing about count-prefix is that the message is represented
as-is, which means a memcpy from the buffer is all that is needed to
"parse" the message, while SLIP encoding requires stepping through
every byte of the message. On the other hand, this is usually needed
regardless to do pattern matching, so maybe it makes no difference.
I don't really know how much the TCP code in liblo is really used, but
I would not be adverse to switching to SLIP encoding if it would
increase interoperability and not break too badly many people's
applications. Unfortunately I'm not sure how to determine this other
than asking on the mailing list, but not everyone who uses liblo is on
the mailing list. The joys of library maintenance ;)
Steve