Hi,
I am encountering some speed problem with OSCBundle sent through SLIPserial. It seems to be quite slow and I would like to know if I am doing something wrong with my code?
Here's a simple speedtest I have made to measure the time taken to build and send OSCBundles.
Here's the timing measured:
As you can see, building an OSCBundle takes time, but sending through SLIPserial is very long too.
Thank you for your help !
I am encountering some speed problem with OSCBundle sent through SLIPserial. It seems to be quite slow and I would like to know if I am doing something wrong with my code?
Here's a simple speedtest I have made to measure the time taken to build and send OSCBundles.
Code:
#include <OSCBundle.h>
#include <OSCTiming.h>
#ifdef BOARD_HAS_USB_SERIAL
#include <SLIPEncodedUSBSerial.h>
SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
#else
#include <SLIPEncodedSerial.h>
SLIPEncodedSerial SLIPSerial(Serial);
#endif
// Global variables
uint16_t timetagSent;
long timestamp;
void setup()
{
//begin SLIPSerial just like Serial
SLIPSerial.begin(38400); // set this as high as you can reliably run on your platform
Serial.begin(38400);
#if ARDUINO >= 100
while(!Serial)
; // Leonardo bug
#endif
}
void loop()
{
OSCBundle bndl;
// Prepare the OSC Bundle
timestamp = micros();
bndl.add("/i").add((int16_t) 1).add((int16_t)1).add((int16_t)1).add((int16_t)1);
timetagSent = micros() - timestamp;
Serial.print("Add a long OSC Message: ");
Serial.println(timetagSent);
timestamp = micros();
bndl.add("/f").add((int16_t) 1);
timetagSent = micros() - timestamp;
Serial.print("Add a simple OSC Message: ");
Serial.println(timetagSent);
Serial.println("");
Serial.println("");
timestamp = micros();
// Send the OSC Bundle through the Serial Port
SLIPSerial.beginPacket();
bndl.send(SLIPSerial); // send the bytes to the SLIP stream
SLIPSerial.endPacket(); // mark the end of the OSC Packet
bndl.empty(); // empty the bundle to free room for a new one
timetagSent = micros() - timestamp;
Serial.println("");
Serial.println("");
Serial.print("Send the bundle through SLIPserial: ");
Serial.println(timetagSent);
}
Here's the timing measured:
- Sending an OSC Bundle with 5 items : 216 µs
- Adding 4 items in the same OSC Message : 41 µs
- Adding 1 OSC Message : 18 µs
As you can see, building an OSCBundle takes time, but sending through SLIPserial is very long too.
Thank you for your help !