Author Topic: digix and OSC  (Read 3635 times)

crx091081gb

  • Newbie
  • *
  • Posts: 7
digix and OSC
« on: March 19, 2014, 01:55:11 pm »
I've got basic OSC receiving working on a digix but only if I stick a big delay in the main loop to give the uart buffer time to get a whole message. If I let the main loop run as fast as it can then from looking at the data received (by echoing it down the serial port) it gets each char in the OSC bundle during separate loops. I'm trying to let the buffer fill till a valid message is received but because of the way the OSCuino libraries are coded a bundle won't report any error on a bundle with no messages (check the source it just iterates over messages but if there are zero messages it skips the error detect and reports no error) so it tries to route an empty bundle then flushes it - which is not great.

So I changed the source so a zero message bundle would return hasError() true, but even letting the buffer fill up over several loops doesn't seem to work, it never detects the bundle as valid (or it detects the first one as valid then drops the rest). I'm wondering if some extra cruft is getting intermingled with the data its reading in - perhaps termination stuff - I don't know.

Right now the only thing I can think of is to keep reading data into a buffer over a number of loops until there's a pause for a few ms and then test to see if it's valid but if there's a way to get it to act on data as soon as the last byte of a message comes in then that's how I'd prefer to do it.

Here's what I have it - it responds to the messages /led 0 and /led 1 and turns pin 13 high or low. It's on port 6669. It works fine till you drop the delay ms at the top of the main loop down, if I drop it to 10ms then about a quarter of my OSC messages get split between loops and lost. To get the code to work set the digix wifi uart to 380400 with flow control turned on and put it into UDP mode on port 6669.

It requires the OSCuino library from here https://github.com/CNMAT/OSC

I get the feeling this should not be so hard and there's got to be something I'm missing, any ideas?
« Last Edit: March 19, 2014, 02:17:20 pm by crx091081gb »

dgarcia42

  • Newbie
  • *
  • Posts: 3
Re: digix and OSC
« Reply #1 on: March 28, 2014, 01:49:29 pm »
I have a function that I wrote to hide all this.  Basically, while there's data available, I read it all in.  Then, wait 1ms, check to see if there's still more data, and if there is, continue reading, and I do this until I go for 1ms without any data coming in.  This seems to be working pretty well for my setup.  Then, I call this function from loop() on every cycle through.

My only issue now is that sending OSC data back to TouchOSC isn't working, and i'd like to be able to report the state of various things in my digix controlled environment back to TouchOSC.

(Also - the arduino OSC code appears to have a bug in it where if you read in a bundle that's really a single message, it will strip the leading / off of the path - I have it fixed locally, but I'm still shaking it out before I submit a pull request back to the maintainers for it).

Code: [Select]
void loopOSC() {
int size;
bool data = false;
OSCBundle bundleIn;
while( (size=wifi.available()) > 0) {
data =true;
while(size--) {
int x = wifi.read();
bundleIn.fill(x);
}
delay(1);
}

if(!bundleIn.hasError() && bundleIn.size() > 0) {
bundleIn.route("/1", routeAnalog);
}

if(bundleOut.size() > 0) {
bundleOut.send(wifi);
bundleOut.empty();
}
}

tsaG

  • Newbie
  • *
  • Posts: 2
Re: digix and OSC
« Reply #2 on: June 04, 2014, 12:29:32 pm »
Im looking for exact this thing. Could you please share your code? =)

Thank you!